[DebianGIS-dev] r2716 - in packages: . saga saga/branches saga/branches/upstream saga/branches/upstream/current saga/branches/upstream/current/src saga/branches/upstream/current/src/modules saga/branches/upstream/current/src/modules/grid saga/branches/upstream/current/src/modules/grid/grid_analysis saga/branches/upstream/current/src/modules/grid/grid_calculus saga/branches/upstream/current/src/modules/grid/grid_discretisation saga/branches/upstream/current/src/modules/grid/grid_filter saga/branches/upstream/current/src/modules/grid/grid_gridding saga/branches/upstream/current/src/modules/grid/grid_spline saga/branches/upstream/current/src/modules/grid/grid_tools saga/branches/upstream/current/src/modules/grid/grid_visualisation saga/branches/upstream/current/src/modules/pointcloud saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer saga/branches/upstream/current/src/modules/shapes saga/branches/upstream/current/src/modules/shapes/shapes_grid saga/branches/upstream/current/src/modules/shapes/shapes_lines saga/branches/upstream/current/src/modules/shapes/shapes_points saga/branches/upstream/current/src/modules/shapes/shapes_polygons saga/branches/upstream/current/src/modules/shapes/shapes_tools saga/branches/upstream/current/src/modules/table saga/branches/upstream/current/src/modules/table/table_calculus saga/branches/upstream/current/src/modules/table/table_tools saga/branches/upstream/current/src/modules/tin saga/branches/upstream/current/src/modules/tin/tin_tools saga/branches/upstream/current/src/modules_geostatistics saga/branches/upstream/current/src/modules_geostatistics/geostatistics saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points saga/branches/upstream/current/src/modules_io saga/branches/upstream/current/src/modules_io/esri_e00 saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00 saga/branches/upstream/current/src/modules_io/gdal saga/branches/upstream/current/src/modules_io/gdal/io_gdal saga/branches/upstream/current/src/modules_io/gps saga/branches/upstream/current/src/modules_io/gps/io_gps saga/branches/upstream/current/src/modules_io/grid saga/branches/upstream/current/src/modules_io/grid/io_grid saga/branches/upstream/current/src/modules_io/grid/io_grid_image saga/branches/upstream/current/src/modules_io/shapes saga/branches/upstream/current/src/modules_io/shapes/io_shapes saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf saga/branches/upstream/current/src/modules_io/table saga/branches/upstream/current/src/modules_io/table/io_table saga/branches/upstream/current/src/modules_lectures saga/branches/upstream/current/src/modules_lectures/lectures saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction saga/branches/upstream/current/src/modules_projection saga/branches/upstream/current/src/modules_projection/pj_georeference saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference saga/branches/upstream/current/src/modules_projection/pj_proj4 saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4 saga/branches/upstream/current/src/modules_recreations saga/branches/upstream/current/src/modules_recreations/recreations saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games saga/branches/upstream/current/src/modules_simulation saga/branches/upstream/current/src/modules_simulation/cellular_automata saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata saga/branches/upstream/current/src/modules_simulation/ecosystems saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget saga/branches/upstream/current/src/modules_simulation/fire saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading saga/branches/upstream/current/src/modules_simulation/hydrology saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology saga/branches/upstream/current/src/modules_terrain_analysis saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles saga/branches/upstream/current/src/saga_core saga/branches/upstream/current/src/saga_core/saga_api saga/branches/upstream/current/src/saga_core/saga_cmd saga/branches/upstream/current/src/saga_core/saga_gdi saga/branches/upstream/current/src/saga_core/saga_gui

frankie at alioth.debian.org frankie at alioth.debian.org
Thu Feb 18 10:21:35 UTC 2010


Author: frankie
Date: 2010-02-18 10:21:33 +0000 (Thu, 18 Feb 2010)
New Revision: 2716

Added:
   packages/saga/
   packages/saga/branches/
   packages/saga/branches/upstream/
   packages/saga/branches/upstream/current/
   packages/saga/branches/upstream/current/src/
   packages/saga/branches/upstream/current/src/modules/
   packages/saga/branches/upstream/current/src/modules/grid/
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shepard.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.h
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.h
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.cpp
   packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.h
   packages/saga/branches/upstream/current/src/modules/shapes/
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Clipper.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Polygon_Clipper.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.h
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.cpp
   packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.h
   packages/saga/branches/upstream/current/src/modules/table/
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.h
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.h
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.h
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.h
   packages/saga/branches/upstream/current/src/modules/table/table_tools/
   packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.h
   packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.h
   packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.cpp
   packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.h
   packages/saga/branches/upstream/current/src/modules/tin/
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.h
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.cpp
   packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.h
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/
   packages/saga/branches/upstream/current/src/modules_io/esri_e00/
   packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/
   packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.cpp
   packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.h
   packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.h
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.cpp
   packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.h
   packages/saga/branches/upstream/current/src/modules_io/gps/
   packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/
   packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/grid/
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.h
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.cpp
   packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.cpp
   packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.h
   packages/saga/branches/upstream/current/src/modules_io/table/
   packages/saga/branches/upstream/current/src/modules_io/table/io_table/
   packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.cpp
   packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.h
   packages/saga/branches/upstream/current/src/modules_lectures/
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.h
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_projection/
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.h
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.cpp
   packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.h
   packages/saga/branches/upstream/current/src/modules_recreations/
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.cpp
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.h
   packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Sudoku.h
   packages/saga/branches/upstream/current/src/modules_simulation/
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.h
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.h
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.h
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.h
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.h
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_simulation/fire/
   packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/
   packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.h
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.h
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.h
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.cpp
   packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_BRM.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFloodInteractive.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL_XXL.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.cpp
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.h
   packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Polygon_Clipper.h
   packages/saga/branches/upstream/current/src/saga_core/
   packages/saga/branches/upstream/current/src/saga_core/saga_api/
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_callback.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_colors.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_file.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_memory.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_string.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/api_translator.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_classes.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_functions.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_tools.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_io.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_memory.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_operation.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_system.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_formula.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_grid_radius.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_indexing.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_matrix.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression_multiple.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_spline.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_trend.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid_interactive.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive_base.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library_interface.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter_data.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/projections.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/quadtree.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shape.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_line.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_part.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_point.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_points.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_polygon.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_io.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_search.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_selection.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table_io.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table_record.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table_selection.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/table_value.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.h
   packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_elements.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_triangulation.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_cmd/
   packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.h
   packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.h
   packages/saga/branches/upstream/current/src/saga_core/saga_cmd/saga_cmd.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.am
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.in
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_edit.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.h
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.cpp
   packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.h
Log:
[svn-inject] Installing original source of saga

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,163 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 contrib_boggia_massei                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     FuzzyAND.cpp                      //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//           Antonio Boggia and Gianluca Massei          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     boggia at unipg.it						 //
+//				  g_massa at libero.it				     	 //
+//                                                       //
+//    contact:    Antonio Boggia                         //
+//                Gianluca Massei                        //
+//                Department of Economics and Appraisal  //
+//                University of Perugia - Italy			 //
+//                www.unipg.it                           //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "FuzzyAND.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFuzzyAND::CFuzzyAND(void)
+{
+	Set_Name		(_TL("Fuzzy intersection grid"));
+
+	Set_Author		(_TL("Copyrights (c) 2004 by Antonio Boggia and Gianluca Massei"));
+
+	Set_Description	(_TW(
+		"Calculates the intersection (min operator) for each grid cell of the selected grids.\n "
+		"e-mail Gianluca Massei: g_massa at libero.it \n"
+		"e-mail Antonio Boggia: boggia at unipg.it \n"
+	));
+
+	Parameters.Add_Grid_List(
+		NULL, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "AND"		, _TL("Intersection"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CFuzzyAND::~CFuzzyAND(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFuzzyAND::On_Execute(void)
+{
+	int				iGrid, nGrids, x, y;//id Grid, cellsnumber , ,
+	double			zMin, ValTemp; // variabile per costrire il grid, variabile temp di confronto
+	CSG_Grid			*pAND;
+	CSG_Parameter_Grid_List	*pParm_Grids;
+
+	//-----------------------------------------------------
+	// Get user inputs from the 'Parameters' object...
+
+	pParm_Grids	= Parameters("GRIDS")	->asGridList();
+	pAND		= Parameters("AND")		->asGrid();
+	nGrids		= pParm_Grids			->Get_Count();
+
+	//-----------------------------------------------------
+	if( nGrids > 1 )
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				//zMin = ValTemp	=  0;
+				zMin	= pParm_Grids->asGrid(0)->asDouble(0, 0);// set initial value of zMin
+
+				for(iGrid=0; iGrid<nGrids; iGrid++)
+				{
+					ValTemp	= pParm_Grids->asGrid(iGrid)->asDouble(x, y);
+					
+					if  (zMin > ValTemp)
+					{
+						zMin = ValTemp; //intersection loop
+					}
+					else zMin=zMin ;
+				}
+
+				pAND->Set_Value(x, y, zMin); 
+			}
+		}
+	}
+	else if( nGrids > 0 )
+	{
+		pAND->Assign(pParm_Grids->asGrid(0));
+	}
+
+	//-----------------------------------------------------
+	return( nGrids > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyAND.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,86 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 contrib_boggia_massei                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//						FuzzyAND.h						 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//           Antonio Boggia and Gianluca Massei          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     boggia at unipg.it						 //
+//				  g_massa at libero.it				     	 //
+//                                                       //
+//    contact:    Antonio Boggia                         //
+//                Gianluca Massei                        //
+//                Department of Economics and Appraisal  //
+//                University of Perugia - Italy			 //
+//                www.unipg.it                           //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //												
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#if !defined(AFX_FuzzyAND_H__4147D540_3A5F_11D6_92B0_0050BA1B4192__INCLUDED_)
+#define AFX_FuzzyAND_H__4147D540_3A5F_11D6_92B0_0050BA1B4192__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CFuzzyAND : public CSG_Module_Grid  
+{
+public:
+	CFuzzyAND(void);
+	virtual ~CFuzzyAND(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Fuzzy Logic") );	}
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // !defined(AFX_FuzzyAND_H__4147D540_3A5F_11D6_92B0_0050BA1B4192__INCLUDED_)

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,163 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 contrib_boggia_massei                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     FuzzyOR.cpp                       //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//           Antonio Boggia and Gianluca Massei          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     boggia at unipg.it						 //
+//				  g_massa at libero.it				     	 //
+//                                                       //
+//    contact:    Antonio Boggia                         //
+//                Gianluca Massei                        //
+//                Department of Economics and Appraisal  //
+//                University of Perugia - Italy			 //
+//                www.unipg.it                           //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "FuzzyOR.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFuzzyOR::CFuzzyOR(void)
+{
+	Set_Name		(_TL("Fuzzy union grid"));
+
+	Set_Author		(_TL("Copyrights (c) 2004 by Antonio Boggia and Gianluca Massei"));
+
+	Set_Description	(_TW(
+		"Calculates the union (max operator) for each grid cell of the selected grids.\n "
+		"e-mail Gianluca Massei: g_massa at libero.it \n"
+		"e-mail Antonio Boggia: boggia at unipg.it \n")
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "OR"		, _TL("Union"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CFuzzyOR::~CFuzzyOR(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFuzzyOR::On_Execute(void)
+{
+	int				iGrid, nGrids, x, y;//id Grid, cellsnumber , ,
+	double			zMax, ValTemp; // variabile per costrire il grid, variabile temp di confronto
+	CSG_Grid			*pOR;
+	CSG_Parameter_Grid_List	*pParm_Grids;
+
+	//-----------------------------------------------------
+	// Get user inputs from the 'Parameters' object...
+
+	pParm_Grids	= (CSG_Parameter_Grid_List *)Parameters("GRIDS")->Get_Data();
+	pOR			= Parameters("OR")->asGrid();
+	nGrids		= pParm_Grids->Get_Count();
+
+	//-----------------------------------------------------
+	if( nGrids > 1 )
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				//zMax = ValTemp	=  0;
+				zMax	= pParm_Grids->asGrid(0)->asDouble(0, 0);// set initial value of zMax
+
+				for(iGrid=0; iGrid<nGrids; iGrid++)
+				{
+					ValTemp	= pParm_Grids->asGrid(iGrid)->asDouble(x, y);
+					
+					if  (zMax < ValTemp)
+					{
+						zMax = ValTemp; //union loop
+					}
+					else zMax=zMax ;
+				}
+
+				pOR->Set_Value(x, y, zMax);
+			}
+		}
+	}
+	else if( nGrids > 0 )
+	{
+		pOR->Assign(pParm_Grids->asGrid(0));
+	}
+
+	//-----------------------------------------------------
+	return( nGrids > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/FuzzyOR.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,87 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 contrib_boggia_massei                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//						FuzzyOR.h						 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//           Antonio Boggia and Gianluca Massei          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     boggia at unipg.it						 //
+//				  g_massa at libero.it				     	 //
+//                                                       //
+//    contact:    Antonio Boggia                         //
+//                Gianluca Massei                        //
+//                Department of Economics and Appraisal  //
+//                University of Perugia - Italy			 //
+//                www.unipg.it                           //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //												
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#if !defined(AFX_FuzzyOR_H__4147D540_3A5F_11D6_92B0_0050BA1B4192__INCLUDED_)
+#define AFX_FuzzyOR_H__4147D540_3A5F_11D6_92B0_0050BA1B4192__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CFuzzyOR : public CSG_Module_Grid  
+{
+public:
+	CFuzzyOR(void);
+	virtual ~CFuzzyOR(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Fuzzy Logic") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // !defined(AFX_FuzzyOR_H__4147D540_3A5F_11D6_92B0_0050BA1B4192__INCLUDED_)

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,316 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cost Analysis                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              LeastCostPathProfile.cpp                 //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//               Olaf Conrad & Victor Olaya              //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "LeastCostPathProfile.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define VALUE_OFFSET	5
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CLeastCostPathProfile::CLeastCostPathProfile(void)
+{
+	Parameters.Set_Name(_TL("Least Cost Path"));
+	Parameters.Set_Description(_TW(
+		"Creates a least cost past profile using an accumulated cost surface."
+		"\n(c) 2004 Victor Olaya, Goettingen.\nemail: oconrad at gwdg.de\n")
+	);
+
+	Parameters.Add_Grid(
+		NULL, "DEM"		, 
+		_TL("Accumulated cost"),
+		_TL("Accumulated cost"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, 
+		"VALUES", 
+		_TL("Values"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL, 
+		"POINTS", 
+		_TL("Profile (points)"),
+		_TL(""),
+		PARAMETER_OUTPUT, 
+		SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL, 
+		"LINE", 
+		_TL("Profile (lines)"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+}
+
+//---------------------------------------------------------
+CLeastCostPathProfile::~CLeastCostPathProfile(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLeastCostPathProfile::On_Execute(void)
+{
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	m_pValues	= Parameters("VALUES")	->asGridList();
+	m_pPoints	= Parameters("POINTS")	->asShapes();
+	m_pLine		= Parameters("LINE")	->asShapes();
+
+	DataObject_Update(m_pDEM, true);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLeastCostPathProfile::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	switch( Mode )
+	{
+	case MODULE_INTERACTIVE_LDOWN:
+		Set_Profile(Get_System()->Fit_to_Grid_System(ptWorld));
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLeastCostPathProfile::Set_Profile(TSG_Point ptWorld)
+{
+	int			x, y, i;
+
+	//-----------------------------------------------------
+	if( Get_System()->Get_World_to_Grid(x, y, ptWorld) && m_pDEM->is_InGrid(x, y) )
+	{
+		m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name()));
+
+		m_pPoints->Add_Field("ID"	, SG_DATATYPE_Int);
+		m_pPoints->Add_Field("D"	, SG_DATATYPE_Double);
+		m_pPoints->Add_Field("X"	, SG_DATATYPE_Double);
+		m_pPoints->Add_Field("Y"	, SG_DATATYPE_Double);
+		m_pPoints->Add_Field("Z"	, SG_DATATYPE_Double);
+
+		for(i=0; i<m_pValues->Get_Count(); i++)
+		{
+			m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+		}
+
+		//-----------------------------------------------------
+		m_pLine->Create(SHAPE_TYPE_Line, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name()));
+		m_pLine->Add_Field("ID", SG_DATATYPE_Int);
+		m_pLine->Add_Shape()->Set_Value(0, 1);
+
+		//-----------------------------------------------------
+		Set_Profile(x, y);
+
+		//-----------------------------------------------------
+		DataObject_Update(m_pLine	, false);
+		DataObject_Update(m_pPoints	, false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CLeastCostPathProfile::Set_Profile(int iX, int iY)
+{
+	int iNextX, iNextY;
+
+	iNextX = iX;
+	iNextY = iY;
+	do {
+		iX = iNextX;
+		iY = iNextY;
+		getNextCell(m_pDEM, iX, iY, iNextX, iNextY);
+	
+	}while (Add_Point(iX, iY) 
+			&& (iX != iNextX || iY != iNextY));
+	
+}
+
+
+void CLeastCostPathProfile::getNextCell(CSG_Grid *g,
+										int iX,
+										int iY,
+										int &iNextX,
+										int &iNextY) {
+
+    float fMaxSlope;
+    float fSlope;
+
+    fMaxSlope = 0;
+    fSlope = 0;
+
+    if (iX < 1 || iX >= g->Get_NX()-1 || iY < 1 || iY >= g->Get_NY()-1
+            || g->is_NoData(iX,iY)) {
+        iNextX = iX;
+		iNextY = iY;
+		return;
+    }// if
+
+    for (int i = -1; i < 2; i++) {
+        for (int j = -1; j < 2; j++) {                	
+            if (!g->is_NoData(iX+i,iY+j)){
+                fSlope = (g->asFloat(iX+i,iY+j)
+                         - g->asFloat(iX,iY));                                				
+                if (fSlope <= fMaxSlope) {
+                    iNextX = iX+i;
+					iNextY = iY+j;                        
+                    fMaxSlope = fSlope;
+                }// if
+            }//if                    
+        }// for
+    }// for
+
+}// method
+
+//---------------------------------------------------------
+bool CLeastCostPathProfile::Add_Point(int x, int y)
+{
+	int			i;
+	double		Distance;
+	TSG_Point	Point;
+	CSG_Shape		*pPoint, *pLast;
+
+	if( m_pDEM->is_InGrid(x, y) )
+	{
+		Point	= Get_System()->Get_Grid_to_World(x, y);
+
+		if( m_pPoints->Get_Count() == 0 )
+		{
+			Distance	= 0.0;
+		}
+		else
+		{
+			pLast		= m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1);
+			Distance	= SG_Get_Distance(Point, pLast->Get_Point(0));
+			Distance	+= pLast->asDouble(1);
+		}
+
+		pPoint	= m_pPoints->Add_Shape();
+		pPoint->Add_Point(Point);
+
+		pPoint->Set_Value(0, m_pPoints->Get_Count());
+		pPoint->Set_Value(1, Distance);
+		pPoint->Set_Value(2, Point.x);
+		pPoint->Set_Value(3, Point.y);
+		pPoint->Set_Value(4, m_pDEM->asDouble(x, y));
+
+		for(i=0; i<m_pValues->Get_Count(); i++)
+		{
+			pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y, true));
+		}
+
+		m_pLine->Get_Shape(0)->Add_Point(Point);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
\ No newline at end of file

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/LeastCostPathProfile.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,114 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Terrain_Analysis                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 LeastCostPathProfile.h                //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__LeastCostPathProfile_H
+#define HEADER_INCLUDED__LeastCostPathProfile_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CLeastCostPathProfile : public CSG_Module_Grid_Interactive
+{
+public:
+	CLeastCostPathProfile(void);
+	virtual ~CLeastCostPathProfile(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Cost Analysis") );	}
+
+protected:
+
+	virtual bool				On_Execute(void);
+	virtual bool				On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	CSG_Shapes						*m_pPoints, *m_pLine;
+
+	CSG_Grid						*m_pDEM;
+
+	CSG_Parameter_Grid_List		*m_pValues;
+
+
+	bool						Set_Profile(TSG_Point ptWorld);
+	void						Set_Profile(int x, int y);
+
+	bool						Add_Point(int x, int y);
+
+	void						getNextCell(CSG_Grid *g, int iX, int iY, int &iNextX, int &iNextY);
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__LeastCostPathProfile_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,164 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      grid analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                     Victor Olaya                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volaya at ya.com                          //
+//                                                       //
+//    contact:    Victor Olaya Ferrero                   //
+//                Madrid                                 //
+//                Spain                                  //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Analysis") );
+
+	case MLB_INFO_Author:
+		return( _TL("Various authors.") );
+
+	case MLB_INFO_Description:
+		return( _TL("Some Grid Analysis Tools.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Analysis") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Grid_CVA.h"
+#include "CoveredDistance.h"
+#include "Grid_Pattern.h"
+#include "CrossClassification.h"
+#include "Grid_LayerOfMaximumValue.h"
+#include "Grid_AggregationIndex.h"
+#include "Grid_AHP.h"
+#include "owa.h"
+
+#include "Cost_Isotropic.h"
+#include "Cost_Anisotropic.h"
+#include "Cost_PolarToRect.h"
+#include "Cost_RectToPolar.h"
+#include "LeastCostPathProfile.h"
+
+#include "Image_VI_Distance.h"
+#include "Image_VI_Slope.h"
+
+#include "FuzzyAND.h"
+#include "FuzzyOR.h"
+#include "Fuzzify.h"
+
+#include "Soil_Texture.h"
+
+#include "fragmentation_standard.h"
+#include "fragmentation_resampling.h"
+#include "fragmentation_classify.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CCost_Isotropic );
+	case 1:		return( new CCost_Anisotropic );
+	case 2:		return( new CCost_PolarToRect );
+	case 3:		return( new CCost_RectToPolar );
+	case 4:		return( new CLeastCostPathProfile );
+	case 5:		return( new CImage_VI_Distance );
+	case 6:		return( new CImage_VI_Slope );
+	case 7:		return( new CFuzzyAND );
+	case 8:		return( new CFuzzyOR );
+	case 9:		return( new CFuzzify );
+	case 10:	return( new CGrid_CVA );
+	case 11:	return( new CCoveredDistance );
+	case 12:	return( new CGrid_Pattern );
+	case 13:	return( new CLayerOfMaximumValue );
+	case 14:	return( new CAHP );
+	case 15:	return( new COWA );
+	case 16:	return( new CAggregationIndex );
+	case 17:	return( new CCrossClassification );
+	case 18:	return( new CSoil_Texture );
+	case 19:	return( new CFragmentation_Standard );
+	case 20:	return( new CFragmentation_Resampling );
+	case 21:	return( new CFragmentation_Classify );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,77 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                     Victor Olaya                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volaya at ya.com                          //
+//                                                       //
+//    contact:    Victor Olaya Ferrero                   //
+//                Madrid                                 //
+//                Spain                                  //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_analysis_H
+#define HEADER_INCLUDED__grid_analysis_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_analysis_EXPORTS
+	#define	grid_analysis_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_analysis_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_analysis_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,557 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                    grid_analysis                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Soil_Texture.cpp                   //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                    Gianluca Massei                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     g_massa at libero.it				     	 //
+//                                                       //
+//    contact:    Gianluca Massei                        //
+//                Department of Economics and Appraisal  //
+//                University of Perugia - Italy			 //
+//                www.unipg.it                           //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Soil_Texture.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char	*TEXTURE_NAMES[12]	=
+{
+	_TL("Clay"),
+	_TL("Silty Clay"),
+	_TL("Silty Clay-Loam"),
+	_TL("Sandy Clay"),
+	_TL("Sandy Clay-Loam"),
+	_TL("Clay-Loam"),
+	_TL("Silt"),
+	_TL("Silt-Loam"),
+	_TL("Loam"),
+	_TL("Sand"),
+	_TL("Loamy Sand"),
+	_TL("Sandy Loam")
+};
+
+//---------------------------------------------------------
+long			TEXTURE_COLOR[12]	=
+{
+	SG_GET_RGB(000, 000, 255),	// clay
+	SG_GET_RGB(000, 200, 255),	// silty clay
+	SG_GET_RGB(000, 200, 200),	// silty clay-loam
+	SG_GET_RGB(200, 000, 255),	// sandy clay
+	SG_GET_RGB(200, 200, 200),	// sandy clay-loam
+	SG_GET_RGB(127, 127, 200),	// clay-loam
+	SG_GET_RGB(000, 255, 000),	// silt
+	SG_GET_RGB(127, 255, 127),	// silt-loam
+	SG_GET_RGB(127, 127, 127),	// loam
+	SG_GET_RGB(255, 000, 000),	// sand
+	SG_GET_RGB(255, 000, 127),	// loamy sand
+	SG_GET_RGB(200, 127, 127)	// sandy loam
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSoil_Texture::CSoil_Texture(void)
+{
+	Set_Name		(_TL("Soil Texture Classification"));
+
+	Set_Author		(_TL("Copyrights (c) 2007 by Gianluca Massei"));
+
+	Set_Description	(_TW(
+		"Define soil texture with USDA scheme from sand and clay contents (grids).\n\n"
+		"  1 - Clay soils\n"
+		"  2 - SiltyClay soils\n"
+		"  3 - SiltyClayLoam soils\n"
+		"  4 - SandyClay soils\n"
+		"  5 - SandyClayLoam soils\n"
+		"  6 - ClayLoam soils\n"
+		"  7 - Silt soils\n"
+		"  8 - SiltLoam soils\n"
+		"  9 - Loam soils\n"
+		" 10 - Sand soils\n"
+		" 11 - LoamySand soils\n"
+		" 12 - SandyLoam\n"
+		"\nG. Massei (g_massa at libero.it)"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL, "SAND"	, _TL("Sand"),
+		_TL("sand content"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "CLAY"	, _TL("Clay"),
+		_TL("clay content"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "TEXTURE"	, _TL("Soil Texture"),
+		_TL("Soil texture"),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Byte
+	);
+}
+
+//---------------------------------------------------------
+CSoil_Texture::~CSoil_Texture(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSoil_Texture::On_Execute(void)
+{
+	int			x,y,intSoilType, MaxX, MaxY;
+	float		Sand_Input,Clay_Input;
+	CSG_Grid	*pSandInput, *pClayInput, *pOutTexture;
+
+
+	pSandInput	= Parameters("SAND")->asGrid();
+	pClayInput	= Parameters("CLAY")->asGrid();
+	pOutTexture	= Parameters("TEXTURE")->asGrid();
+
+
+
+	if(pSandInput->Get_NX()==pClayInput->Get_NX() 
+		&& pSandInput->Get_NY()==pSandInput->Get_NY() )
+	{
+		MaxX= pSandInput->Get_NX();
+		MaxY= pSandInput->Get_NY();
+	}
+	else
+	{
+		MaxX= 0;
+		MaxY= 0;
+
+	}
+
+	
+	for(y=0;y<MaxY;y++)
+	{
+		for(x=0;x<MaxX;x++)
+		{
+			Sand_Input	= pSandInput->asFloat(x, y); 
+			Clay_Input	= pClayInput->asFloat(x, y);
+			intSoilType	= OutTexture(Sand_Input, Clay_Input);
+
+			if (intSoilType<0 || intSoilType>12)//verify range validity
+				pOutTexture->Set_NoData(x, y);
+			else
+				pOutTexture->Set_Value(x, y, intSoilType);
+		
+		}
+	}
+
+
+	//-------------------------------------------------
+	if( 1 )
+	{
+		CSG_Parameters	Parms;
+
+		if( DataObject_Get_Parameters(pOutTexture, Parms) && Parms("COLORS_TYPE") && Parms("LUT") )
+		{
+			CSG_Table	*pLUT	= Parms("LUT")->asTable();
+
+			for(int iClass=0; iClass<12; iClass++)
+			{
+				CSG_Table_Record	*pClass;
+
+				if( (pClass = pLUT->Get_Record(iClass)) == NULL )
+				{
+					pClass	= pLUT->Add_Record();
+				}
+
+				pClass->Set_Value(0, TEXTURE_COLOR[iClass]);
+				pClass->Set_Value(1, TEXTURE_NAMES[iClass]);
+				pClass->Set_Value(2, TEXTURE_NAMES[iClass]);
+				pClass->Set_Value(3, iClass + 1);
+				pClass->Set_Value(4, iClass + 1);
+			}
+
+			while( pLUT->Get_Record_Count() > 12 )
+			{
+				pLUT->Del_Record(pLUT->Get_Record_Count() - 1);
+			}
+
+			Parms("COLORS_TYPE")->Set_Value(1);	// Color Classification Type: Lookup Table
+
+			DataObject_Set_Parameters(pOutTexture, Parms);
+		}
+	}
+
+
+	//-------------------------------------------------
+	Message_Add(_TL("Hello by G. Massei"));
+	
+	return( true );
+}
+
+
+/////////////////////////////////////////
+//   Define specific texture function  //
+/////////////////////////////////////////
+
+int CSoil_Texture::OutTexture(float pSand, float pClay)
+{    
+  int i, SoilTexture;
+  
+  
+  int texture[13]; //store the output of txture function
+ 
+        texture[0]=Clay_Texture(pSand, pClay);                   // 1 define Clay soils function
+        texture[1]=SiltyClay_Texture(pSand, pClay);              // 2 define SiltyClay soils function
+        texture[2]=SiltyClayLoam_Texture(pSand, pClay);          // 3 define SiltyClayLoam soils function
+        texture[3]=SandyClay_Texture(pSand, pClay);              // 4 define SandyClay soils function
+        texture[4]=SandyClayLoam_Texture(pSand, pClay);          // 5 define SandyClayLoam soils function
+        texture[5]=ClayLoam_Texture(pSand, pClay);               // 6 define ClayLoam soils function
+        texture[6]=Silt_Texture(pSand, pClay);                   // 7 define Silt soils function
+        texture[7]=SiltLoam_Texture(pSand, pClay);               // 8 define SiltLoam soils function
+        texture[8]=Loam_Texture(pSand, pClay);                   // 9 define Loam soils function
+        texture[9]=Sand_Texture(pSand, pClay);                   // 10 define Sand soils function
+        texture[10]=LoamySand_Texture(pSand, pClay);             // 11 define LoamySand soils function
+        texture[11]=SandyLoam_Texture(pSand, pClay); 
+
+ 
+        for(i=0;i<12;i=i+1)
+        {
+                    if (texture[i]>0)
+                    {
+                    SoilTexture = texture[i];  
+                    }
+                    
+	
+         }
+
+  return SoilTexture;
+  
+}
+
+int CSoil_Texture::Clay_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;//variabile locale contenente la tessitura
+    int xSand[6]={0,0,20,45,45,0}; //coord. X of polygon points
+    int yClay[6]={100,60,40,40,55,100}; //coord Y of polygon points
+    int nPoint = 6; //n° of polygon points
+    // Value of determinant A
+    //int texture=1;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture = !texture;
+      }
+      if (texture == 1)
+         {
+                 texture=1;
+                 }
+      return texture;
+}
+
+
+int CSoil_Texture::SiltyClay_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[4]={0,0,20,0}; //coord. X of polygon points
+    int yClay[4]={60,40,40,60}; //coord Y of polygon points
+    int nPoint = 4; //n° of polygon points
+     
+    //int texture=2;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture =!texture;
+      }
+            if (texture == 1)
+         {
+                 texture=2;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::SiltyClayLoam_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[5]={0,0,20,20,0}; //coord. X of polygon points
+    int yClay[5]={40,27,27,40,40}; //coord Y of polygon points
+    int nPoint = 5; //n° of polygon points
+     
+    //int texture=3;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture = !texture;
+      }
+      if (texture == 1)
+         {
+                 texture=3;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::SandyClay_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[4]={45,45,65,45}; //coord. X of polygon points
+    int yClay[4]={55,35,35,55}; //coord Y of polygon points
+    int nPoint = 4; //n° of polygon points
+     
+    //int texture=4;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture =!texture;
+      }
+      if (texture == 1)
+         {
+                 texture=4;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::SandyClayLoam_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[6]={45,45,52,80,65,45}; //coord. X of polygon points
+    int yClay[6]={35,27,20,20,35,35}; //coord Y of polygon points
+    int nPoint = 6; //n° of polygon points
+     
+    //int texture=5;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture = !texture;
+      }
+      if (texture == 1)
+         {
+                 texture=5;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::ClayLoam_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[5]={20,20,45,45,20}; //coord. X of polygon points
+    int yClay[5]={40,27,27,40,40}; //coord Y of polygon points
+    int nPoint = 5; //n° of polygon points
+     
+    //int texture=6;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture = !texture;
+      }
+      if (texture == 1)
+         {
+                 texture=6;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::Silt_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[5]={0,0,20,8,0}; //coord. X of polygon points
+    int yClay[5]={12,0,0,12,12}; //coord Y of polygon points
+    int nPoint = 5; //n° of polygon points
+     
+    //int texture=7;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture =!texture;
+      }
+      if (texture == 1)
+         {
+                 texture=7;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::SiltLoam_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[7]={8,20,50,23,0,0,8}; //coord. X of polygon points
+    int yClay[7]={12,0,0,27,27,12,12}; //coord Y of polygon points
+    int nPoint = 7; //n° of polygon points
+     
+    //int texture=8;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture =!texture;
+      }
+      if (texture == 1)
+         {
+                 texture=8;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::Loam_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[6]={23,43,52,52,45,23}; //coord. X of polygon points
+    int yClay[6]={27,7,7,20,27,27}; //coord Y of polygon points
+    int nPoint = 6; //n° of polygon points
+     
+    //int texture=9;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture = !texture;
+      }
+      if (texture == 1)
+         {
+                 texture=9;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::Sand_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[4]={85,100,90,85}; //coord. X of polygon points
+    int yClay[4]={0,0,10,0}; //coord Y of polygon points
+    int nPoint = 4; //n° of polygon points
+     
+    //int texture=10;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture = !texture;
+      }
+      if (texture == 1)
+         {
+                 texture=10;
+                 }
+      return texture;
+}
+
+int CSoil_Texture::LoamySand_Texture (float pSand, float pClay)   
+{
+    int i, j, texture = 0;
+    int xSand[5]={70,85,90,85,70}; //coord. X of polygon points
+    int yClay[5]={0,0,10,15,0}; //coord Y of polygon points
+    int nPoint = 5; //n° of polygon points
+     
+    //int texture=11;
+    
+      for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+        if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+             ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+            (pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+          texture =!texture;
+      }
+      if (texture == 1)
+         {
+                 texture=11;
+                 }
+      return texture;
+}
+
+
+int CSoil_Texture::SandyLoam_Texture(float pSand, float pClay)
+{
+	int i, j, texture = 0;
+	int xSand[8]={43,50,70,85,80,52,52,43}; //coord. pSand of polygon points
+	int yClay[8]={7,0,0,15,20,20,7,7}; //coord pClay of polygon points
+	int nPoint = 8; //n° of polygon points  
+
+	for (i = 0, j = nPoint-1; i < nPoint; j = i++) {
+	if ((((yClay[i] <= pClay) && (pClay < yClay[j])) ||
+		 ((yClay[j] <= pClay) && (pClay < yClay[i]))) &&
+		(pSand < (xSand[j] - xSand[i]) * (pClay - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
+	  texture = !texture;
+	}
+	if (texture == 1)
+	 {
+			 texture=12;
+			 }
+  return texture;
+}
+	
+	

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/Soil_Texture.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                    grid_analysis                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Soil_Texture.h                     //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                   Gianluca Massei                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     g_massa at libero.it				     	 //
+//                                                       //
+//    contact:    Gianluca Massei                        //
+//                Department of Economics and Appraisal  //
+//                University of Perugia - Italy			 //
+//                www.unipg.it                           //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Soil_Texture_H
+#define HEADER_INCLUDED__Soil_Texture_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSoil_Texture : public CSG_Module_Grid
+{
+public:
+	CSoil_Texture(void);
+	virtual ~CSoil_Texture(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Soil Analysis") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+
+	///////////////////////////////////////
+	/* Declare specific texture function */
+	///////////////////////////////////////
+
+	int Clay_Texture(float, float);                   // 1 define Clay soils function
+	int SiltyClay_Texture(float, float);              // 2 define SiltyClay soils function
+	int SiltyClayLoam_Texture(float, float);          // 3 define SiltyClayLoam soils function
+	int SandyClay_Texture(float, float);              // 4 define SandyClay soils function
+	int SandyClayLoam_Texture(float, float);          // 5 define SandyClayLoam soils function
+	int ClayLoam_Texture(float, float);               // 6 define ClayLoam soils function
+	int Silt_Texture(float, float);                   // 7 define Silt soils function
+	int SiltLoam_Texture(float, float);               // 8 define SiltLoam soils function
+	int Loam_Texture(float, float);                   // 9 define Loam soils function
+	int Sand_Texture(float, float);                   // 10 define Sand soils function
+	int LoamySand_Texture(float, float);              // 11 define LoamySand soils function
+	int SandyLoam_Texture(float, float);              // 12 define SandyLoam soils function
+	int OutTexture(float, float);                     //function output   
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Soil_Texture_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,451 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Fragmentation_Base.cpp                //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "fragmentation_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define LUT_ADD(i, color, id, name)	m_LUT.Add_Record(); m_LUT[i][0] = color; m_LUT[i][1] = name; m_LUT[i][3] = id; m_LUT[i][4] = id;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFragmentation_Base::CFragmentation_Base(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Fragmentation"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+		"(1) interior, if Density = 1.0\n"
+		"(2) undetermined, if Density > 0.6 and Density = Connectivity\n"
+		"(3) perforated, if Density > 0.6 and Density - Connectivity > 0\n"
+		"(4) edge, if Density > 0.6 and Density - Connectivity < 0\n"
+		"(5) transitional, if 0.4 < Density < 0.6\n"
+		"(6) patch, if Density < 0.4\n"
+		"\n"
+		"\n"
+		"References:\n"
+		"Riitters, K., Wickham, J., O'Neill, R., Jones, B., Smith, E. (2000): \n"
+		"Global-scale patterns of forest fragmentation. Conservation Ecology 4(2): 3\n"
+		"<a href=\"http://www.ecologyandsociety.org/vol4/iss2/art3/\">http://www.ecologyandsociety.org/vol4/iss2/art3/</a>\n"
+	));
+
+	//-----------------------------------------------------
+	m_LUT.Add_Field(SG_T("COLOR")		, SG_DATATYPE_Color);
+	m_LUT.Add_Field(SG_T("NAME")		, SG_DATATYPE_String);
+	m_LUT.Add_Field(SG_T("DECRIPTION")	, SG_DATATYPE_String);
+	m_LUT.Add_Field(SG_T("MIN")			, SG_DATATYPE_Double);
+	m_LUT.Add_Field(SG_T("MAX")			, SG_DATATYPE_Double);
+
+	LUT_ADD(0, SG_GET_RGB(  0, 127,   0), CLASS_CORE		, _TL("Core"))
+	LUT_ADD(1, SG_GET_RGB( 34, 255,  34), CLASS_INTERIOR	, _TL("Interior"))
+	LUT_ADD(2, SG_GET_RGB(129, 255, 129), CLASS_UNDETERMINED, _TL("Undetermined"))
+	LUT_ADD(3, SG_GET_RGB(255, 110,   0), CLASS_PERFORATED	, _TL("Perforated"))
+	LUT_ADD(4, SG_GET_RGB(255, 255,   0), CLASS_EDGE		, _TL("Edge"))
+	LUT_ADD(5, SG_GET_RGB(162, 162, 255), CLASS_TRANSITIONAL, _TL("Transitional"))
+	LUT_ADD(6, SG_GET_RGB( 56,  56, 255), CLASS_PATCH		, _TL("Patch"))
+	LUT_ADD(7, SG_GET_RGB(200, 200, 200), CLASS_NONE		, _TL("None"))
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "CLASSES"			, _TL("Classification"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "DENSITY"			, _TL("Density [Percent]"),
+		_TL("Density Index (Pf)."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CONNECTIVITY"	, _TL("Connectivity [Percent]"),
+		_TL("Connectivity Index (Pff)."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "FRAGMENTATION"	, _TL("Fragmentation"),
+		_TL("Fragmentation Index"),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Byte
+	);
+
+	Parameters.Add_Table(
+		NULL	, "FRAGSTATS"		, _TL("Summary"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CLASS"			, _TL("Class Identifier"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 1
+	);
+
+	Parameters.Add_Range(
+		NULL	, "NEIGHBORHOOD"	, _TL("Neighborhood"),
+		_TL("Moving window size = 1 + 2 * Neighborhood."),
+		3, 3, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "AGGREGATION"		, _TL("Level Aggregation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("average"),
+			_TL("multiplicative")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BORDER"			, _TL("Add Border"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "WEIGHT"			, _TL("Connectivity Weighting"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DENSITY_MIN"		, _TL("Minimum Density [Percent]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 10.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DENSITY_INT"		, _TL("Minimum Density for Interior Forest [Percent]"),
+		_TL("if less than 100, it is distinguished between interior and core forest"),
+		PARAMETER_TYPE_Double		, 99.0, 0.0, true, 100.0, true
+	);
+}
+
+//---------------------------------------------------------
+CFragmentation_Base::~CFragmentation_Base(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Base::On_Execute(void)
+{
+	int			Class;
+	CSG_Grid	*pClasses, *pDensity, *pConnectivity, *pFragmentation;
+
+	//-----------------------------------------------------
+	pClasses			= Parameters("CLASSES")			->asGrid();
+	pDensity			= Parameters("DENSITY")			->asGrid();
+	pConnectivity		= Parameters("CONNECTIVITY")	->asGrid();
+	pFragmentation		= Parameters("FRAGMENTATION")	->asGrid();
+
+	Class				= Parameters("CLASS")			->asInt();
+	m_Radius_Min		= Parameters("NEIGHBORHOOD")	->asRange()->Get_LoParm()->asDouble();
+	m_Radius_Max		= Parameters("NEIGHBORHOOD")	->asRange()->Get_HiParm()->asDouble();
+	m_Aggregation		= Parameters("AGGREGATION")		->asInt();
+	m_Weight			= Parameters("WEIGHT")			->asDouble();
+	m_Density_Min		= Parameters("DENSITY_MIN")		->asDouble() / 100.0;
+	m_Density_Interior	= Parameters("DENSITY_INT")		->asDouble() / 100.0;
+
+	m_Radius_iMin		= (int)(0.5 + m_Radius_Min);
+	m_Radius_iMax		= (int)(0.5 + m_Radius_Max);
+
+	//-----------------------------------------------------
+	CSG_Parameters	Parms;
+
+	DataObject_Set_Colors(pDensity		, 100, SG_COLORS_WHITE_GREEN);
+	DataObject_Set_Colors(pConnectivity	, 100, SG_COLORS_WHITE_GREEN);
+	DataObject_Set_Colors(pFragmentation, 100, SG_COLORS_WHITE_GREEN, true);
+
+	if( DataObject_Get_Parameters(pFragmentation, Parms) && Parms("COLORS_TYPE") && Parms("LUT") )
+	{
+		Parms("LUT")->asTable()->Assign_Values(&m_LUT);	// Lookup Table
+		Parms("COLORS_TYPE")->Set_Value(1);				// Color Classification Type: Lookup Table
+
+		DataObject_Set_Parameters(pFragmentation, Parms);
+	}
+
+//	pFragmentation->Set_NoData_Value(CLASS_NONE);
+
+	//-----------------------------------------------------
+	if( Initialise(pClasses, Class) )
+	{
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				double	Density, Connectivity;
+
+				if( Get_Fragmentation(x, y, Density, Connectivity) )
+				{
+					pDensity		->Set_Value (x, y, 100.0 * Density);
+					pConnectivity	->Set_Value (x, y, 100.0 * Connectivity);
+				//	pFragmentation	->Set_Value (x, y, 100.0 * Density * Connectivity);
+					pFragmentation	->Set_Value (x, y, Get_Classification(Density, Connectivity));
+				}
+				else
+				{
+					pDensity		->Set_NoData(x, y);
+					pConnectivity	->Set_NoData(x, y);
+					pFragmentation	->Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( Parameters("BORDER")->asBool() )
+		{
+			Add_Border(pFragmentation);
+		}
+
+		Get_Statistics(pFragmentation, *Parameters("FRAGSTATS")->asTable());
+
+		Finalise();
+
+		return( true );
+	}
+
+	Finalise();
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CFragmentation_Base::Get_Classification(double Density, double Connectivity)
+{
+	if( Density >= 0.999 )					// (7) core, if Density = 1.0
+	{
+		if( m_Density_Interior < 0.999 )
+		{
+			return( CLASS_CORE );
+		}
+		else
+		{
+			return( CLASS_INTERIOR );
+		}
+	}
+	if( Density >= m_Density_Interior )		// (4) interior, if Density = 1.0
+	{
+		return( CLASS_INTERIOR );
+	}
+	else if( Density > 0.6 )
+	{
+		Connectivity	*= m_Weight;
+
+		if( Density < Connectivity )		// (1) edge, if Density > 0.6 and Density - Connectivity < 0
+		{
+			return( CLASS_EDGE );
+		}
+		else if( Density > Connectivity )	// (3) perforated, if Density > 0.6 and Density - Connectivity > 0
+		{
+			return( CLASS_PERFORATED );
+		}
+		else								// (2) undetermined, if Density > 0.6 and Density = Connectivity
+		{
+			return( CLASS_UNDETERMINED );
+		}
+	}
+	else if( Density >= 0.4 )				// (6) transitional, if 0.4 < Density < 0.6
+	{
+		return( CLASS_TRANSITIONAL );
+	}
+	else if( Density >= m_Density_Min )		// (5) patch, if Density < 0.4
+	{
+		return( CLASS_PATCH );
+	}
+	else
+	{
+		return( CLASS_NONE );
+	}
+}
+
+//---------------------------------------------------------
+void CFragmentation_Base::Add_Border(CSG_Grid *pFragmentation)
+{
+	int			x, y;
+	CSG_Grid	Tmp(pFragmentation, SG_DATATYPE_Byte);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pFragmentation->asInt(x, y) == CLASS_INTERIOR )
+			{
+				int		i, ix, iy;
+
+				for(i=0; i<8; i++)
+				{
+					if( pFragmentation->Get_System().Get_Neighbor_Pos(i, x, y, ix, iy)
+					&&	pFragmentation->asInt(ix, iy) != CLASS_INTERIOR
+					&&	pFragmentation->asInt(ix, iy) != CLASS_CORE )
+					{
+						Tmp.Set_Value(ix, iy, 1);
+					}
+				}
+			}
+		}
+	}
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( Tmp.asInt(x, y) )
+			{
+				pFragmentation->Set_Value(x, y, CLASS_INTERIOR);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+#define STATISTICS_ADD(i, id, name)	Statistics.Add_Record();\
+	Statistics[i][0] = id;\
+	Statistics[i][1] = name;\
+	Statistics[i][2] = s[i];\
+	Statistics[i][3] = s[i] * Get_Cellsize();\
+	Statistics[i][4] = 100.0 * s[i] / (double)n;
+
+//---------------------------------------------------------
+void CFragmentation_Base::Get_Statistics(CSG_Grid *pFragmentation, CSG_Table &Statistics)
+{
+	if( pFragmentation != NULL && &Statistics != NULL )
+	{
+		int		i, n, s[8];
+
+		for(i=0, n=0; i<8; i++)
+		{
+			s[i]	= 0;
+		}
+
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				switch( pFragmentation->asInt(x, y) )
+				{
+				case CLASS_CORE:			s[0]++; n++;	break;
+				case CLASS_INTERIOR:		s[1]++; n++;	break;
+				case CLASS_UNDETERMINED:	s[2]++; n++;	break;
+				case CLASS_PERFORATED:		s[3]++; n++;	break;
+				case CLASS_EDGE:			s[4]++; n++;	break;
+				case CLASS_TRANSITIONAL:	s[5]++; n++;	break;
+				case CLASS_PATCH:			s[6]++; n++;	break;
+				case CLASS_NONE:			s[7]++; n++;	break;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		Statistics.Destroy();
+
+		Statistics.Add_Field(SG_T("CLASS_ID")	, SG_DATATYPE_Int);
+		Statistics.Add_Field(SG_T("CLASS_NAME")	, SG_DATATYPE_String);
+		Statistics.Add_Field(SG_T("N_CELLS")	, SG_DATATYPE_Int);
+		Statistics.Add_Field(SG_T("AREA_ABS")	, SG_DATATYPE_Double);
+		Statistics.Add_Field(SG_T("AREA_REL")	, SG_DATATYPE_Double);
+
+		STATISTICS_ADD(0, CLASS_CORE		, _TL("Core"))
+		STATISTICS_ADD(1, CLASS_INTERIOR	, _TL("Interior"))
+		STATISTICS_ADD(2, CLASS_UNDETERMINED, _TL("Undetermined"))
+		STATISTICS_ADD(3, CLASS_PERFORATED	, _TL("Perforated"))
+		STATISTICS_ADD(4, CLASS_EDGE		, _TL("Edge"))
+		STATISTICS_ADD(5, CLASS_TRANSITIONAL, _TL("Transitional"))
+		STATISTICS_ADD(6, CLASS_PATCH		, _TL("Patch"))
+		STATISTICS_ADD(7, CLASS_NONE		, _TL("None"))
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,160 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Fragmentation.h                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Fragmentation_Base_H
+#define HEADER_INCLUDED__Fragmentation_Base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// #define CLASS_ORIGINAL
+
+#ifdef CLASS_ORIGINAL
+	enum
+	{
+		CLASS_CORE			= 7,
+		CLASS_INTERIOR		= 4,
+		CLASS_UNDETERMINED	= 2,
+		CLASS_PERFORATED	= 3,
+		CLASS_EDGE			= 1,
+		CLASS_TRANSITIONAL	= 6,
+		CLASS_PATCH			= 5,
+		CLASS_NONE			= 0
+	};
+#else
+	enum
+	{
+		CLASS_CORE			= 1,
+		CLASS_INTERIOR,
+		CLASS_UNDETERMINED,
+		CLASS_PERFORATED,
+		CLASS_EDGE,
+		CLASS_TRANSITIONAL,
+		CLASS_PATCH,
+		CLASS_NONE
+	};
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFragmentation_Base : public CSG_Module_Grid
+{
+public:
+	CFragmentation_Base(void);
+	virtual ~CFragmentation_Base(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Fragmentation Analysis") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+	virtual bool			Initialise			(CSG_Grid *pClasses, int Class)	{	return( true );	}
+	virtual bool			Finalise			(void)							{	return( true );	}
+
+	virtual bool			Get_Fragmentation	(int x, int y, double &Density, double &Connectivity)	= 0;
+
+
+	int						m_Aggregation, m_Radius_iMin, m_Radius_iMax;
+
+	double					m_Density_Min, m_Density_Interior, m_Weight, m_Radius_Min, m_Radius_Max;
+
+	CSG_Table				m_LUT;
+
+
+	int						Get_Classification	(double Density, double Connectivity);
+
+	void					Add_Border			(CSG_Grid *pFragmentation);
+
+	void					Get_Statistics		(CSG_Grid *pFragmentation, CSG_Table &Statistics);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Fragmentation_Base_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,220 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Fragmentation_Classify.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "fragmentation_classify.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFragmentation_Classify::CFragmentation_Classify(void)
+{
+	Parameters.Create(this, SG_T(""), SG_T(""), SG_T(""), true);
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Fragmentation Classes from Density and Connectivity"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+		"(1) interior, if Density = 1.0\n"
+		"(2) undetermined, if Density > 0.6 and Density = Connectivity\n"
+		"(3) perforated, if Density > 0.6 and Density - Connectivity > 0\n"
+		"(4) edge, if Density > 0.6 and Density - Connectivity < 0\n"
+		"(5) transitional, if 0.4 < Density < 0.6\n"
+		"(6) patch, if Density < 0.4\n"
+		"\n"
+		"\n"
+		"References:\n"
+		"Riitters, K., Wickham, J., O'Neill, R., Jones, B., Smith, E. (2000): \n"
+		"Global-scale patterns of forest fragmentation. Conservation Ecology 4(2): 3\n"
+		"<a href=\"http://www.ecologyandsociety.org/vol4/iss2/art3/\">http://www.ecologyandsociety.org/vol4/iss2/art3/</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DENSITY"			, _TL("Density [Percent]"),
+		_TL("Density Index (Pf)."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CONNECTIVITY"	, _TL("Connectivity [Percent]"),
+		_TL("Connectivity Index (Pff)."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "FRAGMENTATION"	, _TL("Fragmentation"),
+		_TL("Fragmentation Index"),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Byte
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BORDER"			, _TL("Add Border"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "WEIGHT"			, _TL("Connectivity Weighting"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DENSITY_MIN"		, _TL("Minimum Density [Percent]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 10.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DENSITY_INT"		, _TL("Minimum Density for Interior Forest [Percent]"),
+		_TL("if less than 100, it is distinguished between interior and core forest"),
+		PARAMETER_TYPE_Double		, 99.0, 0.0, true, 100.0, true
+	);
+}
+
+//---------------------------------------------------------
+CFragmentation_Classify::~CFragmentation_Classify(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Classify::On_Execute(void)
+{
+	CSG_Grid	*pDensity, *pConnectivity, *pFragmentation;
+
+	pDensity			= Parameters("DENSITY")			->asGrid();
+	pConnectivity		= Parameters("CONNECTIVITY")	->asGrid();
+	pFragmentation		= Parameters("FRAGMENTATION")	->asGrid();
+
+	m_Weight			= Parameters("WEIGHT")			->asDouble();
+	m_Density_Min		= Parameters("DENSITY_MIN")		->asDouble() / 100.0;
+	m_Density_Interior	= Parameters("DENSITY_INT")		->asDouble() / 100.0;
+
+	//-----------------------------------------------------
+	CSG_Parameters	Parms;
+
+	DataObject_Set_Colors(pFragmentation, 100, SG_COLORS_WHITE_GREEN, true);
+
+	if( DataObject_Get_Parameters(pFragmentation, Parms) && Parms("COLORS_TYPE") && Parms("LUT") )
+	{
+		Parms("LUT")->asTable()->Assign_Values(&m_LUT);	// Lookup Table
+		Parms("COLORS_TYPE")->Set_Value(1);				// Color Classification Type: Lookup Table
+
+		DataObject_Set_Parameters(pFragmentation, Parms);
+	}
+
+//	pFragmentation->Set_NoData_Value(CLASS_NONE);
+
+	//-----------------------------------------------------
+	if( 1 )
+	{
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( !pDensity->is_NoData(x, y) && !pConnectivity->is_NoData(x, y) )
+				{
+					double	Density			= pDensity		->asDouble(x, y) / 100.0;
+					double	Connectivity	= pConnectivity	->asDouble(x, y) / 100.0;
+
+				//	pFragmentation	->Set_Value (x, y, 100.0 * Density * Connectivity);
+					pFragmentation	->Set_Value (x, y, Get_Classification(Density, Connectivity));
+				}
+				else
+				{
+					pFragmentation	->Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( Parameters("BORDER")->asBool() )
+		{
+			Add_Border(pFragmentation);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_classify.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Fragmentation_Classify.h               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Fragmentation_Classify_H
+#define HEADER_INCLUDED__Fragmentation_Classify_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "fragmentation_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFragmentation_Classify : public CFragmentation_Base
+{
+public:
+	CFragmentation_Classify(void);
+	virtual ~CFragmentation_Classify(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+	virtual bool			Get_Fragmentation	(int x, int y, double &Density, double &Connectivity)	{	return( false );	}
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Fragmentation_Classify_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,321 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Fragmentation_Resampling.cpp             //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "fragmentation_resampling.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFragmentation_Resampling::CFragmentation_Resampling(void)
+	: CFragmentation_Base()
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Fragmentation (Alternative)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+		"(1) interior, if Density = 1.0\n"
+		"(2) undetermined, if Density > 0.6 and Density = Connectivity\n"
+		"(3) perforated, if Density > 0.6 and Density - Connectivity > 0\n"
+		"(4) edge, if Density > 0.6 and Density - Connectivity < 0\n"
+		"(5) transitional, if 0.4 < Density < 0.6\n"
+		"(6) patch, if Density < 0.4\n"
+		"\n"
+		"\n"
+		"References:\n"
+		"Riitters, K., Wickham, J., O'Neill, R., Jones, B., Smith, E. (2000): \n"
+		"Global-scale patterns of forest fragmentation. Conservation Ecology 4(2): 3\n"
+		"<a href=\"http://www.ecologyandsociety.org/vol4/iss2/art3/\">http://www.ecologyandsociety.org/vol4/iss2/art3/</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "LEVEL_GROW"		, _TL("Search Distance Increment"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DENSITY_MEAN"	, _TL("Density from Neighbourhood"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, true
+	);
+}
+
+//---------------------------------------------------------
+CFragmentation_Resampling::~CFragmentation_Resampling(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Resampling::Initialise(CSG_Grid *pClasses, int Class)
+{
+	int			x, y, Level_Count;
+	double		Level_Grow, Level_Start, Density, Connectivity;
+	CSG_Grid	*pDensity, *pConnectivity;
+
+	pDensity		= Parameters("DENSITY")			->asGrid();
+	pConnectivity	= Parameters("CONNECTIVITY")	->asGrid();
+
+	Level_Grow		= Parameters("LEVEL_GROW")		->asDouble();
+
+	m_bDensityMean	= Parameters("DENSITY_MEAN")	->asBool();
+
+	//-----------------------------------------------------
+	if( Level_Grow > 0.0 )
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( Get_Connectivity(x, y, pClasses, Class, Density, Connectivity) )
+				{
+					pDensity		->Set_Value (x, y, Density);
+					pConnectivity	->Set_Value (x, y, Connectivity);
+				}
+				else
+				{
+					pDensity		->Set_NoData(x, y);
+					pConnectivity	->Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+	//	Level_Grow	*= Get_Cellsize();
+	//	Level_Start	= 0.0;
+	//	Level_Count	= m_Radius_iMax;
+	//	m_Radius_iMin--;
+	//	m_Radius_iMax--;
+
+		Level_Count	= 1 + (int)((m_Radius_Max - m_Radius_Min) / Level_Grow);
+		Level_Grow	*= Get_Cellsize();
+		Level_Start	= Level_Grow * (1.0 + 2.0 * m_Radius_Min);
+
+		if(	m_Density		.Create(pDensity		, Level_Grow, Level_Start, Level_Count, GRID_PYRAMID_Mean, GRID_PYRAMID_Arithmetic)
+		&&	m_Connectivity	.Create(pConnectivity	, Level_Grow, Level_Start, Level_Count, GRID_PYRAMID_Mean, GRID_PYRAMID_Arithmetic) )
+		{
+			for(int iGrid=0; iGrid<m_Density.Get_Count(); iGrid++)
+			{
+				Message_Add(CSG_String::Format(SG_T("%s %d: %f (%f)"), _TL("Scale"), 1 + iGrid, m_Density.Get_Grid(iGrid)->Get_Cellsize(), m_Density.Get_Grid(iGrid)->Get_Cellsize() / Get_Cellsize()));
+			//	DataObject_Add(SG_Create_Grid(*m_Density		.Get_Grid(iGrid)));
+			//	DataObject_Add(SG_Create_Grid(*m_Connectivity	.Get_Grid(iGrid)));
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CFragmentation_Resampling::Finalise(void)
+{
+	m_Density		.Destroy();
+	m_Connectivity	.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Resampling::Get_Fragmentation(int x, int y, double &Density, double &Connectivity)
+{
+	if( m_Density.Get_Grid(-1)->is_InGrid(x, y) )
+	{
+		TSG_Point	p	= Get_System()->Get_Grid_to_World(x, y);
+
+	//	Density			= 0.0;	m_Density		.Get_Grid(m_Radius_iMin)->Get_Value(p, Density);
+	//	Connectivity	= 0.0;	m_Connectivity	.Get_Grid(m_Radius_iMin)->Get_Value(p, Connectivity);
+
+	//	for(int iGrid=m_Radius_iMin+1; iGrid<m_Density.Get_Count(); iGrid++)
+
+		Density			= 0.0;	m_Density		.Get_Grid(0)->Get_Value(p, Density);
+		Connectivity	= 0.0;	m_Connectivity	.Get_Grid(0)->Get_Value(p, Connectivity);
+
+		for(int iGrid=1; iGrid<m_Density.Get_Count(); iGrid++)
+		{
+			double		d, c;
+
+			if( m_Density.Get_Grid(iGrid)->Get_Value(p, d) && m_Connectivity.Get_Grid(iGrid)->Get_Value(p, c) )
+			{
+				switch( m_Aggregation )
+				{
+				case 0:	default:
+					Density			= 0.5 * (d + Density);
+					Connectivity	= 0.5 * (c + Connectivity);
+					break;
+
+				case 1:
+					Density			*= d;
+					Connectivity	*= c;
+					break;
+				}
+			}
+		}
+
+		if( Density < 0.0 || Connectivity < 0.0 )
+			return( false );
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Resampling::Get_Connectivity(int x, int y, CSG_Grid *pClasses, int Class, double &Density, double &Connectivity)
+{
+	if( pClasses && pClasses->is_InGrid(x, y) )
+	{
+		bool	bClass;
+		int		i, j, nDensity, nConnectivity, ix, iy;
+
+		//-------------------------------------------------
+		bClass			= pClasses->asInt(x, y) == Class;
+		Density			= bClass ? 1.0 : 0.0;
+		Connectivity	= 0.0;
+
+		for(i=0, j=7, nDensity=1, nConnectivity=0; i<8; j=i++)
+		{
+			if( Get_System()->Get_Neighbor_Pos(i, x, y, ix, iy) && !pClasses->is_NoData(ix, iy) )
+			{
+				nDensity++;
+
+				if( pClasses->asInt(ix, iy) == Class )
+				{
+					if( m_bDensityMean )
+						Density++;
+
+					nConnectivity++;
+
+					if( bClass )
+						Connectivity++;
+
+					if( Get_System()->Get_Neighbor_Pos(j, x, y, ix, iy) && !pClasses->is_NoData(ix, iy) )
+					{
+						nConnectivity++;
+
+						if( pClasses->asInt(ix, iy) == Class )
+							Connectivity++;
+					}
+				}
+				else
+				{
+					if( bClass )
+						nConnectivity++;
+
+					if( Get_System()->Get_Neighbor_Pos(j, x, y, ix, iy) && !pClasses->is_NoData(ix, iy) && pClasses->asInt(ix, iy) == Class )
+						nConnectivity++;
+				}
+			}
+		}
+
+		if( nDensity > 1 && m_bDensityMean )
+		{
+			Density			/= nDensity;
+		}
+
+		if( nConnectivity > 1 )
+		{
+			Connectivity	/= nConnectivity;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_resampling.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,109 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Fragmentation_Resampling.h              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Fragmentation_Resampling_H
+#define HEADER_INCLUDED__Fragmentation_Resampling_H
+
+//---------------------------------------------------------
+#include "fragmentation_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFragmentation_Resampling : public CFragmentation_Base
+{
+public:
+	CFragmentation_Resampling(void);
+	virtual ~CFragmentation_Resampling(void);
+
+
+protected:
+
+	virtual bool			Initialise			(CSG_Grid *pClasses, int Class);
+	virtual bool			Finalise			(void);
+
+	virtual bool			Get_Fragmentation	(int x, int y, double &Density, double &Connectivity);
+
+
+private:
+
+	bool					m_bDensityMean;
+
+	CSG_Grid_Pyramid		m_Density, m_Connectivity;
+
+
+	bool					Get_Connectivity	(int x, int y, CSG_Grid *pClasses, int Class, double &Density, double &Connectivity);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Fragmentation_Resampling_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,394 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Fragmentation_Standard.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "fragmentation_standard.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define VAL_NODATA		-1
+#define VAL_NO			 0
+#define VAL_YES			 1
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFragmentation_Standard::CFragmentation_Standard(void)
+	: CFragmentation_Base()
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Fragmentation (Standard)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Grid based fragmentation analysis after Riitters et al. (2000).\n"
+		"\n"
+		"(1) interior, if Density = 1.0\n"
+		"(2) undetermined, if Density > 0.6 and Density = Connectivity\n"
+		"(3) perforated, if Density > 0.6 and Density - Connectivity > 0\n"
+		"(4) edge, if Density > 0.6 and Density - Connectivity < 0\n"
+		"(5) transitional, if 0.4 < Density < 0.6\n"
+		"(6) patch, if Density < 0.4\n"
+		"\n"
+		"\n"
+		"References:\n"
+		"Riitters, K., Wickham, J., O'Neill, R., Jones, B., Smith, E. (2000): \n"
+		"Global-scale patterns of forest fragmentation. Conservation Ecology 4(2): 3\n"
+		"<a href=\"http://www.ecologyandsociety.org/vol4/iss2/art3/\">http://www.ecologyandsociety.org/vol4/iss2/art3/</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "CIRCULAR"		, _TL("Neighborhood Type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("square"),
+			_TL("circle")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DIAGONAL"		, _TL("Include diagonal neighbour relations"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, true
+	);
+}
+
+//---------------------------------------------------------
+CFragmentation_Standard::~CFragmentation_Standard(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Standard::Initialise(CSG_Grid *pClasses, int Class)
+{
+	int		x, y;
+
+	m_bCircular		= Parameters("CIRCULAR")->asInt() == 1;
+	m_bDiagonal		= Parameters("DIAGONAL")->asBool();
+
+	//-----------------------------------------------------
+	m_Grid.Create(*Get_System(), SG_DATATYPE_Char);
+	m_Grid.Set_NoData_Value(VAL_NODATA);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			m_Grid.Set_Value(x, y, pClasses->is_NoData(x, y) ? VAL_NODATA : pClasses->asInt(x, y) == Class ? VAL_YES : VAL_NO);
+		}
+	}
+
+	//-----------------------------------------------------
+	m_Radius.Create(SG_DATATYPE_Int, 1 + 2 * m_Radius_iMax, 1 + 2 * m_Radius_iMax);
+
+	for(y=0; y<m_Radius.Get_NY(); y++)
+	{
+		for(x=0; x<m_Radius.Get_NX(); x++)
+		{
+			m_Radius.Set_Value(x, y, (int)(0.5 + M_GET_LENGTH(x - m_Radius_iMax, y - m_Radius_iMax)));
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=m_Radius_iMin; y<=m_Radius_iMax; y++)
+	{
+		Message_Add(CSG_String::Format(SG_T("%s %d: %f (%f)"), _TL("Scale"), 1 + y - m_Radius_iMin, (1.0 + 2.0 * y) * Get_Cellsize(), 1.0 + 2.0 * y));
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CFragmentation_Standard::Finalise(void)
+{
+	m_Grid  .Destroy();
+	m_Radius.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Standard::Get_Fragmentation(int x, int y, double &Density, double &Connectivity)
+{
+	if( !m_Grid.is_NoData(x, y) )
+	{
+		int		i, n;
+		double	d, c;
+
+		Density			= 0.0;
+		Connectivity	= 0.0;
+
+		for(i=m_Radius_iMin, n=0; i<=m_Radius_iMax; i++)
+		{
+			if( Get_Fragmentation(x, y, d, c, i) )
+			{
+				if( n == 0 )
+				{
+					Density			= d;
+					Connectivity	= c;
+				}
+				else
+				{
+					switch( m_Aggregation )
+					{
+					case 0:	default:
+						Density			= 0.5 * (d + Density);
+						Connectivity	= 0.5 * (c + Connectivity);
+						break;
+
+					case 1:
+						Density			*= d;
+						Connectivity	*= c;
+						break;
+					}
+				}
+
+				n++;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFragmentation_Standard::Get_Fragmentation(int x, int y, double &Density, double &Connectivity, int Radius)
+{
+	if( m_Grid.is_InGrid(x, y) )
+	{
+		int		Value, dx, dy, nDensity, nConnectivity;
+
+		Density			= 0.0;
+		nDensity		= 0;
+
+		Connectivity	= 0.0;
+		nConnectivity	= 0;
+
+		for(dy=-Radius; dy<=Radius; dy++)
+		{
+			for(dx=-Radius; dx<=Radius; dx++)
+			{
+				if( Get_Value(x, y, dx, dy, Radius, Value) )
+				{
+					nDensity++;
+
+					if( Value == VAL_YES )
+					{
+						Density++;
+
+						if( Get_Value(x, y, dx + 0, dy + 1, Radius, Value) )		// up
+						{
+							nConnectivity++;
+
+							if( Value == VAL_YES )
+								Connectivity++;
+						}
+
+						if( Get_Value(x, y, dx + 1, dy + 0, Radius, Value) )		// right
+						{
+							nConnectivity++;
+
+							if( Value == VAL_YES )
+								Connectivity++;
+						}
+
+						if( m_bDiagonal )
+						{
+							if( Get_Value(x, y, dx + 1, dy + 1, Radius, Value) )	// right-up
+							{
+								nConnectivity++;
+
+								if( Value == VAL_YES )
+									Connectivity++;
+							}
+
+							if( Get_Value(x, y, dx + 1, dy - 1, Radius, Value) )	// right-down
+							{
+								nConnectivity++;
+
+								if( Value == VAL_YES )
+									Connectivity++;
+							}
+						}
+					}
+					else
+					{
+						if( Get_Value(x, y, dx + 0, dy + 1, Radius, Value) && Value == VAL_YES )		// up
+							nConnectivity++;
+
+						if( Get_Value(x, y, dx + 1, dy + 0, Radius, Value) && Value == VAL_YES )		// right
+							nConnectivity++;
+
+						if( m_bDiagonal )
+						{
+							if( Get_Value(x, y, dx + 1, dy + 1, Radius, Value) && Value == VAL_YES )	// right-up
+								nConnectivity++;
+
+							if( Get_Value(x, y, dx + 1, dy - 1, Radius, Value) && Value == VAL_YES )	// right-down
+								nConnectivity++;
+						}
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( nDensity > 0 )
+		{
+			Density			/= nDensity;
+		}
+
+		if( nConnectivity > 0 )
+		{
+			Connectivity	/= nConnectivity;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CFragmentation_Standard::in_Radius(int x, int y, int Radius)
+{
+	if( m_bCircular )
+	{
+		x	+= m_Radius_iMax;
+		y	+= m_Radius_iMax;
+
+		if( !m_Radius.is_InGrid(x, y) || m_Radius.asInt(x, y) > Radius )
+		{
+			return( false );
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CFragmentation_Standard::Get_Value(int x, int y, int dx, int dy, int Radius, int &Value)
+{
+	if( in_Radius(dx, dy, Radius) )
+	{
+		x	+= dx;
+		y	+= dy;
+
+		if( m_Grid.is_InGrid(x, y) )
+		{
+			Value	= m_Grid.asInt(x, y);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_analysis/fragmentation_standard.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_analysis                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Fragmentation_Standard.h               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Fragmentation_Standard_H
+#define HEADER_INCLUDED__Fragmentation_Standard_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "fragmentation_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFragmentation_Standard : public CFragmentation_Base
+{
+public:
+	CFragmentation_Standard(void);
+	virtual ~CFragmentation_Standard(void);
+
+
+protected:
+
+	virtual bool			Initialise			(CSG_Grid *pClasses, int Class);
+	virtual bool			Finalise			(void);
+
+	virtual bool			Get_Fragmentation	(int x, int y, double &Density, double &Connectivity);
+
+
+private:
+
+	bool					m_bCircular, m_bDiagonal;
+
+	CSG_Grid				m_Grid, m_Radius;
+
+
+	bool					Get_Fragmentation	(int x, int y, double &Density, double &Connectivity, int Radius);
+	bool					in_Radius			(int x, int y, int Radius);
+	bool					Get_Value			(int x, int y, int dx, int dy, int Radius, int &Value);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Fragmentation_Standard_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,206 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Calculator.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+#include "Grid_Calculator.h"
+
+#include <float.h>
+
+CGrid_Calculator::CGrid_Calculator(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Grid Calculator"));
+
+	Set_Author(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+
+	CSG_String	s(_TW(
+		"The Grid Calculator calculates a new grid based on existing grids and a mathematical formula. "
+		"The grid variables are single characters a which correspond in alphabetical order to the grid list order "
+		"('a' = first grid, 'b' = second grid, ...)\n"
+		"Example with three grids: sin(a) * b + c\n\n"
+		"The following operators are available for the formula definition:\n"
+	));
+
+	s	+= CSG_Formula::Get_Help_Operators();
+
+	Set_Description(s);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL, "INPUT"	, _TL("Grids"),
+		_TL(""), PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"	, _TL("Result"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+	
+	Parameters.Add_String(
+		NULL, "FORMUL"	, _TL("Formula"),
+		_TL(""),
+		SG_T("(a - b) / (a + b)")
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Calculator::~CGrid_Calculator(void)
+{}
+
+//---------------------------------------------------------
+#if defined(_SAGA_LINUX)
+bool _finite(double val)
+{
+	return( true );
+}
+#endif
+
+//---------------------------------------------------------
+bool CGrid_Calculator::On_Execute(void)
+{
+	char			vars[27];
+	bool			bContinue;
+	
+	int				i, x, y;
+
+	if (Parameters("INPUT")->asInt() <= 0)	// Gr� von O.C...
+	{
+		Error_Set(_TL("No grid in list - Cannot execute calculator"));
+		return (false);
+	}
+	
+	pResult		= Parameters("RESULT")->asGrid();
+	pResult->Set_Name(Parameters("FORMUL")->asString());
+	
+	nGrids		= Parameters("INPUT")->asInt();
+	Grids		=(CSG_Grid **)Parameters("INPUT")->asPointer();
+	
+	for (i = 0, bContinue = true; i < nGrids - 1 && bContinue; i++)
+	{
+		if( (Grids[i]->Get_System() == Grids[i + 1]->Get_System()) == false )
+		{
+			bContinue	= false;
+		}
+	}
+	
+	CSG_Grid MissingMap(Grids[0], SG_DATATYPE_Byte);
+	
+	for (y = 0; y < Get_NY() && Set_Progress(y); y++)
+		for (x = 0; x < Get_NX(); x++)
+		{
+			int missing = 1;
+			for (i = 0;  i < nGrids; i++)
+			{
+				//if (fabs(Grids[i]->asFloat(x, y) - Grids[0]->Get_NoData_Value()) < 0.0001)
+				// this was not a very robust way of cheking nodata values, was it?
+				if (Grids[i]->is_NoData(x,y))
+				{
+				//I think this works better, specially if you use a range of nodata values, not a single value
+					missing = 0;
+				}
+			}
+			MissingMap.Set_Value(x, y, missing);
+		}
+		
+		pResult->Set_NoData_Value(Grids[0]->Get_NoData_Value());
+		for (char c = 'a'; c<'a'+(char) nGrids; c++)
+			
+			vars[c - 'a'] = c;
+		
+		CSG_Formula Formel;
+		
+		Formel.Set_Formula(Parameters("FORMUL")->asString());
+		
+		int Pos;
+		CSG_String Msg;
+		if (Formel.Get_Error(&Pos, &Msg))
+		{
+			CSG_String	msg;
+
+			msg.Printf(_TL("Error at character #%d of the function: \n%s\n"), Pos, Parameters("FORMUL")->asString());
+			
+			Message_Add(msg);
+			
+			msg.Printf(SG_T("\n%s\n"), Msg.c_str());
+			
+			Message_Add(msg);
+			
+			return false;
+		}
+		
+		double *Grid_Vals= new double[nGrids];
+		double val;
+		
+		for (y = 0; y < Get_NY() && Set_Progress(y); y++)
+			for (x = 0; x < Get_NX(); x++)
+			{
+				for (i = 0; i < nGrids; i++)
+				{
+					Grid_Vals[i]=Grids[i]->asDouble(x,y);
+				}
+				
+				val = Formel.Get_Value(Grid_Vals, nGrids);	
+
+				if (_finite(val) && MissingMap.asByte(x, y))
+					pResult->Set_Value(x, y, val);
+				else
+					pResult->Set_Value(x, y, Grids[0]->Get_NoData_Value());
+			}
+
+		delete[] Grid_Vals;	
+		return (true);
+}
+
+// MinGW ERROR:
+// Grid_Calculator.cpp: In member function `virtual bool CGrid_Calculator::On_Execute()':
+// Grid_Calculator.cpp:187: error: name lookup of `y' changed for new ISO `for' scoping
+// Grid_Calculator.cpp:145: error:   using obsolete binding at `y'

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Calculator.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,89 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Calculator.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Calculator_H
+#define HEADER_INCLUDED__Grid_Calculator_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+class CGrid_Calculator : public CSG_Module_Grid
+{
+public:
+	CGrid_Calculator(void);
+	virtual ~CGrid_Calculator(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	int						nGrids;
+
+	CSG_Grid					**Grids, *pResult;
+
+	
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Calculator_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,246 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Geometric_Figures.cpp              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Geometric_Figures.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Geometric_Figures::CGrid_Geometric_Figures(void)
+{
+	Set_Name	(_TL("Geometric Figures"));
+
+	Set_Author	(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description(_TW(
+		"Construct grids from geometric figures (planes, cones).\n"
+		"(c) 2001 by Olaf Conrad, Goettingen\nemail: oconrad at gwdg.de")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL, "RESULT"		, _TL("Result"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, false
+	);
+
+	Parameters.Add_Value(
+		NULL, "CELL_COUNT"	, _TL("Cell Count"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 2.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "CELL_SIZE"	, _TL("Cell Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL, "FIGURE"		, _TL("Figure"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"), _TL("Cone (up)"), _TL("Cone (down)"), _TL("Plane")), 
+		0
+	);
+
+	Parameters.Add_Value(
+		NULL, "PLANE"		, _TL("Direction of Plane [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 22.5
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Geometric_Figures::~CGrid_Geometric_Figures(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Geometric_Figures::On_Execute(void)
+{
+	int		NXY;
+	double	DXY;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	NXY		= Parameters("CELL_COUNT")	->asInt();
+	DXY		= Parameters("CELL_SIZE")	->asDouble();
+
+	Parameters("RESULT")->asGridList()->Add_Item(
+		pGrid	= SG_Create_Grid(SG_DATATYPE_Float, NXY, NXY, DXY)
+	);
+
+	//-----------------------------------------------------
+	switch( Parameters("FIGURE")->asInt() )
+	{
+	case 0:	default:
+		Create_Cone		(pGrid, true);
+		break;
+
+	case 1:
+		Create_Cone		(pGrid, false);
+		break;
+
+	case 2:
+		Create_Plane	(pGrid, Parameters("PLANE")->asDouble());
+		break;
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Geometric_Figures::Create_Cone(CSG_Grid *pGrid, bool bUp)
+{
+	int		x, y;
+	double	nx_2, ny_2, dx, dy, d;
+
+	//-----------------------------------------------------
+	pGrid->Set_Name(bUp ? _TL("Cone (Up)") : _TL("Cone (Down)"));
+
+	nx_2	= pGrid->Get_Cellsize() * (double)pGrid->Get_NX() / 2.0;
+	ny_2	= pGrid->Get_Cellsize() * (double)pGrid->Get_NY() / 2.0;
+
+	//-----------------------------------------------------
+	for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
+	{
+		for(x=0; x<pGrid->Get_NX(); x++)
+		{
+			dx	= 0.5 + x * pGrid->Get_Cellsize() - nx_2;
+			dy	= 0.5 + y * pGrid->Get_Cellsize() - ny_2;
+			d	= sqrt(dx*dx + dy*dy);
+
+			if( d < nx_2 )
+			{
+				pGrid->Set_Value(x, y, bUp ? d : -d);
+			}
+			else
+			{
+				pGrid->Set_NoData(x, y);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CGrid_Geometric_Figures::Create_Plane(CSG_Grid *pGrid, double Direction)
+{
+	int		x, y;
+	double	xPos, yPos, z, dSin, dCos, Max;
+
+	//-----------------------------------------------------
+	pGrid->Set_Name(CSG_String::Format(_TL("Plane (%.2fDegree)"), Direction));
+
+	Max		= sqrt(2.0) * pGrid->Get_Cellsize() * pGrid->Get_Cellsize() / 4.0;
+
+	dSin	= sin(M_DEG_TO_RAD * Direction);
+	dCos	= cos(M_DEG_TO_RAD * Direction);
+
+	//-----------------------------------------------------
+	for(y=0, yPos=0.5-pGrid->Get_Cellsize()*pGrid->Get_NY()/2.0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, yPos+=pGrid->Get_Cellsize())
+	{
+		for(x=0, xPos=0.5-pGrid->Get_Cellsize()*pGrid->Get_NX()/2.0; x<pGrid->Get_NX(); x++, xPos+=pGrid->Get_Cellsize())
+		{
+		//	pGrid->Set_NoData(x, y);
+
+		//	z	= dCos * xPos - dSin * yPos;
+
+		//	if( z >= -Max && z <= Max )
+			{
+		//		z	= dSin * xPos + dCos * yPos;
+
+		//		if( z >= -Max && z <= Max )
+				{
+					z	= xPos * dSin + yPos * dCos;
+
+					pGrid->Set_Value(x, y, z);
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Geometric_Figures.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,104 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Geometric_Figures.h               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Geometric_Figures_H
+#define HEADER_INCLUDED__Grid_Geometric_Figures_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Geometric_Figures : public CSG_Module
+{
+public:
+	CGrid_Geometric_Figures(void);
+	virtual ~CGrid_Geometric_Figures(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Grid Generation") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	void					Create_Cone		(CSG_Grid *pGrid, bool bUp);
+	void					Create_Plane	(CSG_Grid *pPlane, double Direction);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Geometric_Figures_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,155 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Normalise.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Normalise.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Normalise::CGrid_Normalise(void)
+{
+	Set_Name(_TL("Grid Normalisation"));
+
+	Set_Author	(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(_TW(
+		"Normalise the values of a grid. "
+		"The arithmetic mean and the standard deviation is calculated based on "
+		"all grid cell values to create a grid with normalised values. ")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "INPUT"	,_TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "OUTPUT"	, _TL("Normalised Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"), _TL("Standard Deviation"), _TL("(0.0 < x < 1.0)"))
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Normalise::~CGrid_Normalise(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Normalise::On_Execute(void)
+{
+	int		x, y;
+	double	Minimum, Range;
+	CSG_Grid	*pInput, *pOutput;
+
+	//-----------------------------------------------------
+	pInput	= Parameters("INPUT")	->asGrid();
+	pOutput	= Parameters("OUTPUT")	->asGrid();
+
+	if( pInput != pOutput )
+	{
+		pOutput->Assign(pInput);
+	}
+
+	pOutput->Set_Name(CSG_String::Format(SG_T("%s (%s)"), pInput->Get_Name(), _TL("Grid_Normalised")));
+
+	//-----------------------------------------------------
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:
+		pOutput->Normalise();
+		break;
+
+	case 1:
+		if( (Minimum = pInput->Get_ZMin()) < (Range = pInput->Get_ZMax()) )
+		{
+			Range	= 1.0 / (Range - Minimum);
+
+			for(y=0; y<Get_NY() && Set_Progress(y); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					pOutput->Set_Value(x, y, (pInput->asDouble(x, y) - Minimum) * Range);
+				}
+			}
+		}
+		break;
+	}
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Normalise.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,85 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Normalise.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Normalise_H
+#define HEADER_INCLUDED__Grid_Normalise_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Normalise : public CSG_Module_Grid  
+{
+public:
+	CGrid_Normalise(void);
+	virtual ~CGrid_Normalise(void);
+
+//	virtual const SG_Char *	Get_MenuPath(void)		{	return( NULL );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Normalise_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,140 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Plotter.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+#include "Grid_Plotter.h"
+
+CGrid_Plotter::CGrid_Plotter(void)
+{
+	Set_Name(_TL("Function"));
+	Set_Author(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+	Set_Description(_TW(
+		"Generate a grid based on a functional expression.\n"
+		"The function interpreter uses an expression parser "
+		"that offers the folowing operators:\n\n"
+		"+ Addition\n"
+		"- Subtraction\n"
+		"* Multiplication\n"
+		"/ Division\n"
+		"^ power\n"
+		"sin(a)\n"
+		"cos(a)\n"
+		"tan(a)\n"
+		"asin(a)\n"
+		"acos(a)\n"
+		"atan(a)\n"
+		"atan2(a,b)\n"
+		"abs(a)\n"
+		"int(a)\n"
+		"sqrt(a)\n"
+		"int(a)\n"
+		"mod(a,b)\n"
+		"gt(a,b) returns 1 if a greater b\n"
+		"lt(a,b) returns 1 if a lower b\n"
+		"eq(a,b) returns 1 if a equal b\n"
+		"The Variablen are x and y\n"
+		"Example: sin(x*x+y*y)/(x*x+y*y)\n")
+	);
+
+	Parameters.Add_Grid(	NULL, "RESULT"	, _TL("Function"), _TL(""), PARAMETER_OUTPUT);
+
+	Parameters.Add_Value(	NULL, "XMIN"	, _TL("xmin")	, _TL(""), PARAMETER_TYPE_Double,-5);
+	Parameters.Add_Value(	NULL, "XMAX"	, _TL("xmax")	, _TL(""), PARAMETER_TYPE_Double,5);
+	Parameters.Add_Value(	NULL, "YMIN"	, _TL("ymin")	, _TL(""), PARAMETER_TYPE_Double,-5);
+	Parameters.Add_Value(	NULL, "YMAX"	, _TL("ymax")	, _TL(""), PARAMETER_TYPE_Double,5);
+	Parameters.Add_String(	NULL, "FORMUL"	, _TL("Formula")	, _TL(""), _TL("sin(x*x + y*y)"));
+}
+
+//---------------------------------------------------------
+CGrid_Plotter::~CGrid_Plotter(void)
+{}
+
+//---------------------------------------------------------
+bool CGrid_Plotter::On_Execute(void)
+{
+	pResult		= Parameters("RESULT")->asGrid();
+
+	double xmin	= Parameters("XMIN")->asDouble();
+	double ymin	= Parameters("YMIN")->asDouble();
+	double xmax	= Parameters("XMAX")->asDouble();
+	double ymax	= Parameters("YMAX")->asDouble();
+
+	const SG_Char *formel  = Parameters("FORMUL")->asString();
+
+	CSG_Formula Formel;
+
+	Formel.Set_Formula(formel);
+
+	int Pos;
+	CSG_String Msg;
+	if (Formel.Get_Error(&Pos,&Msg))
+	{
+		CSG_String	msg;
+		msg.Printf(_TL("Error at character #%d of the function: \n%s\n"), Pos, formel);
+		
+		Message_Add(msg);
+		
+		msg.Printf(SG_T("\n%s\n"), Msg.c_str());
+		
+		Message_Add(msg);
+
+		return false;
+	}
+
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	for(int x=0; x<Get_NX(); x++)
+	{
+		pResult->Set_Value(x,y,Formel.Get_Value(SG_T("xy"),(xmax-xmin)*((double)x/Get_NX())+xmin,(ymax-ymin)*((double)y/Get_NY())+ymin)); 
+	}
+	return( true );
+}
+
+

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Plotter.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Plotter.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Plotter_H
+#define HEADER_INCLUDED__Grid_Plotter_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Plotter : public CSG_Module_Grid
+{
+public:
+	CGrid_Plotter(void);
+	virtual ~CGrid_Plotter(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Grid Generation") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+	
+	CSG_Grid					*pInput, *pResult;
+	
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Plotter_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,297 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Random_Field.cpp                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <time.h>
+
+#include "Grid_Random_Field.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Random_Field::CGrid_Random_Field(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Random Field"));
+
+	Set_Author	(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description(
+		_TL("Create a grid with pseudo-random numbers as grid cell values. ")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "OUTPUT"		, _TL("Random Field"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_GRID"	, _TL("Grid Properties"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NX"			, _TL("Width (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NY"			, _TL("Height (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "CELLSIZE"	, _TL("Cellsize"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "XMIN"		, _TL("West"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "YMIN"		, _TL("South"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),_TL("Uniform"), _TL("Gaussian")), 
+		1
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_UNIFORM", _TL("Uniform"),
+		_TL("")
+	);
+
+	Parameters.Add_Range(
+		pNode	, "RANGE"		, _TL("Range"),
+		_TL(""),
+		0.0, 1.0
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_GAUSS"	, _TL("Gaussian"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "MEAN"		, _TL("Arithmetic Mean"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "STDDEV"		, _TL("Standard Deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Random_Field::~CGrid_Random_Field(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Random_Field::On_Execute(void)
+{
+	int		x, y, method;
+	double	min, max, mean, stddev;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	pGrid	= SG_Create_Grid(
+		SG_DATATYPE_Float,
+		Parameters("NX")		->asInt(),
+		Parameters("NY")		->asInt(),
+		Parameters("CELLSIZE")	->asDouble(),
+		Parameters("XMIN")		->asDouble(),
+		Parameters("YMIN")		->asDouble()
+	);
+
+	pGrid->Set_Name(_TL("Random Field"));
+	Parameters("OUTPUT")->Set_Value(pGrid);
+
+	//-----------------------------------------------------
+	method	= Parameters("METHOD")	->asInt();
+
+	min		= Parameters("RANGE")	->asRange()->Get_LoVal();
+	max		= Parameters("RANGE")	->asRange()->Get_HiVal();
+
+	mean	= Parameters("MEAN")	->asDouble();
+	stddev	= Parameters("STDDEV")	->asDouble();
+
+	srand((unsigned)time(NULL));
+
+	//-----------------------------------------------------
+	for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
+	{
+		for(x=0; x<pGrid->Get_NX(); x++)
+		{
+			switch( method )
+			{
+			case 0:	// uniform...
+				pGrid->Set_Value(x, y, Get_Random_Uniform	(min, max));
+				break;
+
+			case 1:	// uniform...
+				pGrid->Set_Value(x, y, Get_Random_Gaussian	(mean, stddev));
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// Uniform distributed pseudo-random numbers in the arbitrary range.
+//
+inline double CGrid_Random_Field::Get_Random_Uniform(double min, double max)
+{
+	return( min + (max - min) * rand() / (double)RAND_MAX );
+}
+
+//---------------------------------------------------------
+// Uniform distributed pseudo-random numbers in the range from 0 to 1.
+//
+inline double CGrid_Random_Field::Get_Random_Uniform(void)
+{
+	return( 1.0 * rand() / (double)RAND_MAX );
+}
+
+//---------------------------------------------------------
+// Generating Gaussian pseudo-random numbers using
+// the polar form of the Box-Muller transformation.
+//
+// Box, G.E.P, Muller, M.E. (1958):
+//   'A note on the generation of random normal deviates',
+//    Annals Math. Stat, V. 29, pp. 610-611
+//
+// Link: http://www.taygeta.com/random/gaussian.html
+//
+double CGrid_Random_Field::Get_Random_Gaussian(double mean, double stddev)
+{
+	static bool		bCalculate	= true;
+	static double	y2			= 0.0;
+	double			x1, x2, w, y1;
+ 
+	if( bCalculate )
+	{
+		do
+		{
+			x1	= 2.0 * Get_Random_Uniform() - 1.0;
+			x2	= 2.0 * Get_Random_Uniform() - 1.0;
+
+			w	= x1 * x1 + x2 * x2;
+		}
+		while( w >= 1.0 );
+
+		w	= sqrt((-2.0 * log(w)) / w);
+
+		y1	= x1 * w;
+		y2	= x2 * w;
+
+		return( mean + stddev * y1 );
+	}
+
+	return( mean + stddev * y2 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Random_Field.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Random_Field.h                  //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Random_Field_H
+#define HEADER_INCLUDED__Grid_Random_Field_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Random_Field : public CSG_Module
+{
+public:
+	CGrid_Random_Field(void);
+	virtual ~CGrid_Random_Field(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Grid Generation") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	double					Get_Random_Uniform	(double min, double max);
+	double					Get_Random_Uniform	(void);
+	double					Get_Random_Gaussian	(double mean, double stddev);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Random_Field_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,185 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Volume.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Volume.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Volume::CGrid_Volume(void)
+{
+	Set_Name(_TL("Grid Volume"));
+
+	Set_Author	(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description(
+		_TL("Calculate the volume under the grid's surface. This is mainly useful for Digital Elevation Models (DEM).")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"), 
+			_TL("Count Only Above Base Level"), 
+			_TL("Count Only Below Base Level"),
+			_TL("Subtract Volumes Below Base Level"),
+			_TL("Add Volumes Below Base Level")
+		)
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LEVEL"	, _TL("Base Level"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Volume::~CGrid_Volume(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Volume::On_Execute(void)
+{
+	int			x, y, Method;
+	double		Level, Volume, z;
+	CSG_Grid		*pGrid;
+	CSG_String	s;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")	->asGrid();
+	Level	= Parameters("LEVEL")	->asDouble();
+	Method	= Parameters("METHOD")	->asInt();
+
+	//-----------------------------------------------------
+	for(y=0, Volume=0.0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pGrid->is_NoData(x, y) )
+			{
+				z	= pGrid->asDouble(x, y) - Level;
+
+				switch( Method )
+				{
+				case 0:	// Count Only Above Base Level
+					if( z > 0.0 )
+					{
+						Volume	+= z;
+					}
+					break;
+
+				case 1:	// Count Only Below Base Level
+					if( z < 0.0 )
+					{
+						Volume	-= z;
+					}
+					break;
+
+				case 2:	// Subtract Volumes Below Base Level
+					Volume	+= z;
+					break;
+
+				case 3:	// Add Volumes Below Base Level
+					Volume	+= fabs(z);
+					break;
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	Volume	*= pGrid->Get_Cellarea();
+
+	s.Printf(_TL("Volume: %f"), Volume);
+
+	Message_Add(s);
+	Message_Dlg(s, _TL("Grid Volume"));
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/Grid_Volume.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Volume.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Volume_H
+#define HEADER_INCLUDED__Grid_Volume_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Volume : public CSG_Module_Grid  
+{
+public:
+	CGrid_Volume(void);
+	virtual ~CGrid_Volume(void);
+
+
+protected:
+
+	virtual bool			On_Execute	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Volume_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,136 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//               SAGA User Group Associaton              //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Calculus") );
+
+	case MLB_INFO_Author:
+		return( _TL("O. Conrad, A. Ringeler, V. Olaya (c) 2001-4") );
+
+	case MLB_INFO_Description:
+		return( _TL("Grid based or related calculations.") );
+
+	case MLB_INFO_Version:
+		return( _TL("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Calculus" ));
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Grid_Normalise.h"
+#include "Grid_Calculator.h"
+#include "Grid_Volume.h"
+#include "grid_difference.h"
+#include "Grid_Plotter.h"
+#include "Grid_Geometric_Figures.h"
+#include "Grid_Random_Terrain.h"
+#include "Grid_Random_Field.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CGrid_Normalise );
+	case 1:		return( new CGrid_Calculator );
+	case 2:		return( new CGrid_Volume );
+	case 3:		return( new CGrid_Difference );
+	case 4:		return( new CGrid_Plotter );
+	case 5:		return( new CGrid_Geometric_Figures );
+	case 6:		return( new CGrid_Random_Terrain );
+	case 7:		return( new CGrid_Random_Field );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_calculus_H
+#define HEADER_INCLUDED__grid_calculus_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_calculus_EXPORTS
+	#define	grid_calculus_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_calculus_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_calculus_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,144 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Difference.cpp                  //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid_difference.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Difference::CGrid_Difference(void)
+{
+	Set_Name		(_TL("Grid Difference"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "A"	, _TL("A"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "B"	, _TL("B"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "C"	, _TL("Difference A - B"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Difference::On_Execute(void)
+{
+	CSG_Grid	*pA, *pB, *pC;
+
+	//-----------------------------------------------------
+	pA	= Parameters("A")->asGrid();
+	pB	= Parameters("B")->asGrid();
+	pC	= Parameters("C")->asGrid();
+
+	DataObject_Set_Colors(pC, 100, SG_COLORS_RED_GREY_BLUE);
+
+	//-----------------------------------------------------
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( pA->is_NoData(x, y) || pB->is_NoData(x, y) )
+			{
+				pC->Set_NoData(x, y);
+			}
+			else
+			{
+				pC->Set_Value(x, y, pA->asDouble(x, y) - pB->asDouble(x, y));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_calculus/grid_difference.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Difference.h                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Difference_H
+#define HEADER_INCLUDED__Grid_Difference_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Difference : public CSG_Module_Grid  
+{
+public:
+	CGrid_Difference(void);
+
+
+protected:
+
+	virtual bool			On_Execute	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Difference_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,593 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Grid_Classify_Supervised.cpp             //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "Grid_Classify_Supervised.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	CLASS_NR			= 0,
+	CLASS_ID,
+	CLASS_N,
+	CLASS_M,
+	CLASS_S
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_GRID_VALUE(x, y, i)	(m_bNormalise ? (m_pGrids->asGrid(i)->asDouble(x, y) - m_pGrids->asGrid(i)->Get_ArithMean()) / sqrt(m_pGrids->asGrid(i)->Get_Variance()) : m_pGrids->asGrid(i)->asDouble(x, y))
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Classify_Supervised::CGrid_Classify_Supervised(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Supervised Classification"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Supervised Classification: Minimum Distance, Maximum Likelihood.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"			, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POLYGONS"		, _TL("Training Areas"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"			, _TL("Class Identifier"),
+		_TL("")
+	);
+
+	Parameters.Add_Table(
+		NULL	, "CLASSES"			, _TL("Class Information"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"			, _TL("Classification"),
+		_TL(""),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Char
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ML_PROB"			, _TL("Distance/Probability"),
+		_TL("Dependent on chosen method, these are the calculated minimum distances or the maximum probabilities."),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"			, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Minimum Distance"),
+			_TL("Maximum Likelihood")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NORMALISE"		, _TL("Normalise"),
+		_TL("Automatically normalise grids before classifying. Useful for minimum distance classification."),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ML_THRESHOLD"	, _TL("Probability Threshold (Percent)"),
+		_TL("Let pixel stay unclassified, if maximum likelihood probability is less than threshold."),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true, 100.0, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Classify_Supervised::~CGrid_Classify_Supervised(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classify_Supervised::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	//-------------------------------------------------
+	m_pClasses		= Parameters("CLASSES")		->asTable();
+	m_pGrids		= Parameters("GRIDS")		->asGridList();
+ 	m_pResult		= Parameters("RESULT")		->asGrid();
+	m_bNormalise	= Parameters("NORMALISE")	->asBool();
+	m_pProbability	= Parameters("ML_PROB")		->asGrid();
+	m_ML_Threshold	= Parameters("ML_THRESHOLD")->asDouble();
+
+	//-------------------------------------------------
+	if( Initialise() )
+	{
+		switch( Parameters("METHOD")->asInt() )
+		{
+		case 0:	default:	bResult	= Set_Minimum_Distance();		break;
+		case 1:				bResult	= Set_Maximum_Likelihood();		break;
+		}
+
+		Finalise();
+	}
+
+	//-------------------------------------------------
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classify_Supervised::Initialise(void)
+{
+	int					x, y, iGrid, iClass, iPolygon, iField;
+	double				d, n;
+	TSG_Point			p;
+	CSG_Table_Record	*pClass;
+	CSG_Shapes			*pPolygons;
+	CSG_Shape_Polygon	*pPolygon;
+
+	//-----------------------------------------------------
+	for(iGrid=m_pGrids->Get_Count()-1; iGrid>=0; iGrid--)
+	{
+		if( m_pGrids->asGrid(iGrid)->Get_Variance() == 0.0 )
+		{
+			m_pGrids->Del_Item(iGrid);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_pGrids->Get_Count() > 0 )
+	{
+		iField		= Parameters("FIELD")		->asInt();
+		pPolygons	= Parameters("POLYGONS")	->asShapes();
+
+		m_pClasses->Destroy();
+		m_pClasses->Set_Name(_TL("Class Information"));
+
+		m_pClasses->Add_Field(_TL("NR")			, SG_DATATYPE_Int);
+		m_pClasses->Add_Field(_TL("IDENTIFIER")	, SG_DATATYPE_String);
+		m_pClasses->Add_Field(_TL("ELEMENTS")	, SG_DATATYPE_Int);
+
+		for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+		{
+			m_pClasses->Add_Field(CSG_String::Format(_TL("MEAN_%02d")  , iGrid + 1), SG_DATATYPE_Double);
+			m_pClasses->Add_Field(CSG_String::Format(_TL("STDDEV_%02d"), iGrid + 1), SG_DATATYPE_Double);
+		}
+
+		//-------------------------------------------------
+		for(y=0, p.y=Get_YMin(); y<Get_NY() && Set_Progress(y); y++, p.y+=Get_Cellsize())
+		{
+			for(x=0, p.x=Get_XMin(); x<Get_NX(); x++, p.x+=Get_Cellsize())
+			{
+				bool	bNoData;
+
+				for(iGrid=0, bNoData=false; iGrid<m_pGrids->Get_Count() && !bNoData; iGrid++)
+				{
+					if( m_pGrids->asGrid(iGrid)->is_NoData(x, y) )
+					{
+						bNoData	= true;
+					}
+				}
+
+				//-----------------------------------------
+				if( bNoData )
+				{
+					m_pResult->Set_NoData(x, y);
+				}
+				else
+				{
+					m_pResult->Set_Value(x, y, 0.0);
+
+					for(iPolygon=0; iPolygon<pPolygons->Get_Count(); iPolygon++)
+					{
+						pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon);
+
+						if( pPolygon->is_Containing(p) && (pClass = Get_Class(pPolygon->asString(iField))) != NULL )
+						{
+							pClass->Add_Value(CLASS_N, 1.0);
+
+							for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+							{
+								d	= GET_GRID_VALUE(x, y, iGrid);
+
+								pClass->Add_Value(CLASS_M + 2 * iGrid, d);
+								pClass->Add_Value(CLASS_S + 2 * iGrid, d * d);
+							}
+						}
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		for(iClass=0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+		{
+			pClass	= m_pClasses->Get_Record(iClass);
+			n		= pClass->asDouble(CLASS_N);
+
+			for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+			{
+				d	= pClass->asDouble	(CLASS_M + 2 * iGrid) / n;			// arithmetic mean
+				pClass->Set_Value		(CLASS_M + 2 * iGrid, d);
+
+				d	= pClass->asDouble	(CLASS_S + 2 * iGrid) / n - d * d;	// variance
+				pClass->Set_Value		(CLASS_S + 2 * iGrid, sqrt(d));		// standard deviation
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_pClasses->Get_Record_Count() > 1 )
+		{
+			CSG_Parameters	Parms;
+
+			if( DataObject_Get_Parameters(m_pResult, Parms) && Parms("COLORS_TYPE") && Parms("LUT") )
+			{
+				CSG_Table	*pLUT	= Parms("LUT")->asTable();
+
+				for(iClass=0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+				{
+					if( (pClass = pLUT->Get_Record(iClass)) == NULL )
+					{
+						pClass	= pLUT->Add_Record();
+						pClass->Set_Value(0, SG_GET_RGB(rand() * 255.0 / RAND_MAX, rand() * 255.0 / RAND_MAX, rand() * 255.0 / RAND_MAX));
+					}
+
+					pClass->Set_Value(1, m_pClasses->Get_Record(iClass)->asString(CLASS_ID));
+					pClass->Set_Value(2, m_pClasses->Get_Record(iClass)->asString(CLASS_ID));
+					pClass->Set_Value(3, iClass + 1);
+					pClass->Set_Value(4, iClass + 1);
+				}
+
+				while( pLUT->Get_Record_Count() > m_pClasses->Get_Record_Count() )
+				{
+					pLUT->Del_Record(pLUT->Get_Record_Count() - 1);
+				}
+
+				Parms("COLORS_TYPE")->Set_Value(1);	// Color Classification Type: Lookup Table
+
+				DataObject_Set_Parameters(m_pResult, Parms);
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Classify_Supervised::Finalise(void)
+{
+	if( m_bNormalise )
+	{
+		for(int iClass=0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+		{
+			CSG_Table_Record	*pClass	= m_pClasses->Get_Record(iClass);
+
+			for(int iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+			{
+				double	d,
+					s	= sqrt(m_pGrids->asGrid(iGrid)->Get_Variance()),
+					m	=      m_pGrids->asGrid(iGrid)->Get_ArithMean();
+
+				d	= pClass->asDouble	(CLASS_M + 2 * iGrid);
+				pClass->Set_Value		(CLASS_M + 2 * iGrid, s * d + m);
+
+				d	= pClass->asDouble	(CLASS_S + 2 * iGrid);
+				pClass->Set_Value		(CLASS_S + 2 * iGrid, s * d);
+			}
+		}
+	}
+
+	if( m_pProbability )
+	{
+		DataObject_Set_Colors(m_pProbability, 100, SG_COLORS_WHITE_GREEN);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table_Record * CGrid_Classify_Supervised::Get_Class(const SG_Char *Identifier)
+{
+	CSG_Table_Record	*pClass	= NULL;
+
+	if( m_pClasses && Identifier )
+	{
+		int		i;
+
+		for(i=0; i<m_pClasses->Get_Record_Count(); i++)
+		{
+			pClass	= m_pClasses->Get_Record(i);
+
+			if( !SG_STR_CMP(pClass->asString(CLASS_ID), Identifier) )
+			{
+				return( pClass );
+			}
+		}
+
+		//-------------------------------------------------
+		pClass	= m_pClasses->Add_Record();
+
+		pClass->Set_Value(CLASS_NR	, m_pClasses->Get_Record_Count());
+		pClass->Set_Value(CLASS_ID	, Identifier);
+		pClass->Set_Value(CLASS_N	, 0.0);
+
+		for(i=CLASS_M; i<m_pClasses->Get_Field_Count(); i++)
+		{
+			pClass->Set_Value(i, 0.0);
+		}
+	}
+
+	return( pClass );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classify_Supervised::Set_Minimum_Distance(void)
+{
+	int		x, y, iClass, iGrid, iMin;
+	double	dMin, d, e, **m;
+
+	//-----------------------------------------------------
+	m		= (double **)SG_Malloc(sizeof(double *) * m_pClasses->Get_Record_Count());
+	m[0]	= (double  *)SG_Malloc(sizeof(double  ) * m_pClasses->Get_Record_Count() * m_pGrids->Get_Count());
+
+	for(iClass=0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+	{
+		m[iClass]	= m[0] + iClass * m_pGrids->Get_Count();
+
+		for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+		{
+			m[iClass][iGrid]	= m_pClasses->Get_Record(iClass)->asDouble(CLASS_M + 2 * iGrid);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !m_pResult->is_NoData(x, y) )
+			{
+				for(iClass=0, dMin=-1.0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+				{
+					for(iGrid=0, d=0.0; iGrid<m_pGrids->Get_Count(); iGrid++)
+					{
+						e	= GET_GRID_VALUE(x, y, iGrid) - m[iClass][iGrid];
+						d	+= e*e;
+					}
+
+					if( dMin < 0.0 || dMin > d )
+					{
+						dMin	= d;
+						iMin	= iClass;
+					}
+				}
+
+				if( dMin >= 0.0 )
+				{
+					m_pResult->Set_Value(x, y, iMin + 1);
+
+					if( m_pProbability )
+					{
+						m_pProbability->Set_Value(x, y, sqrt(dMin));
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(m[0]);
+	SG_Free(m);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classify_Supervised::Set_Maximum_Likelihood(void)
+{
+	int		x, y, iClass, iGrid, iMax;
+	double	dMax, d, e, **a, **b, **m;
+
+	//-----------------------------------------------------
+	a		= (double **)SG_Malloc(sizeof(double *) * m_pClasses->Get_Record_Count());
+	a[0]	= (double  *)SG_Malloc(sizeof(double  ) * m_pClasses->Get_Record_Count() * m_pGrids->Get_Count());
+	b		= (double **)SG_Malloc(sizeof(double *) * m_pClasses->Get_Record_Count());
+	b[0]	= (double  *)SG_Malloc(sizeof(double  ) * m_pClasses->Get_Record_Count() * m_pGrids->Get_Count());
+	m		= (double **)SG_Malloc(sizeof(double *) * m_pClasses->Get_Record_Count());
+	m[0]	= (double  *)SG_Malloc(sizeof(double  ) * m_pClasses->Get_Record_Count() * m_pGrids->Get_Count());
+
+	for(iClass=0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+	{
+		a[iClass]	= a[0] + iClass * m_pGrids->Get_Count();
+		b[iClass]	= b[0] + iClass * m_pGrids->Get_Count();
+		m[iClass]	= m[0] + iClass * m_pGrids->Get_Count();
+
+		for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+		{
+			d					= m_pClasses->Get_Record(iClass)->asDouble(CLASS_S + 2 * iGrid);	// standard deviation
+			a[iClass][iGrid]	=  1.0 / sqrt(d*d * 2.0 * M_PI);
+			b[iClass][iGrid]	= -1.0 /     (d*d * 2.0);
+			m[iClass][iGrid]	= m_pClasses->Get_Record(iClass)->asDouble(CLASS_M + 2 * iGrid);	// arithmetic mean
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !m_pResult->is_NoData(x, y) )
+			{
+				for(iClass=0, dMax=0.0; iClass<m_pClasses->Get_Record_Count(); iClass++)
+				{
+					for(iGrid=0, d=1.0; iGrid<m_pGrids->Get_Count(); iGrid++)
+					{
+						e	 = GET_GRID_VALUE(x, y, iGrid) - m[iClass][iGrid];
+						d	*= a[iClass][iGrid] * exp(b[iClass][iGrid] * e*e);
+					}
+
+					if( dMax < d )
+					{
+						dMax	= d;
+						iMax	= iClass;
+					}
+				}
+
+				if( (dMax = 100.0 * pow(dMax, 1.0 / m_pGrids->Get_Count())) < m_ML_Threshold )
+				{
+					m_pResult->Set_Value(x, y, 0.0);
+				}
+				else
+				{
+					m_pResult->Set_Value(x, y, iMax + 1);
+				}
+
+				if( m_pProbability )
+				{
+					m_pProbability->Set_Value(x, y, dMax);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(a[0]);
+	SG_Free(a);
+	SG_Free(b[0]);
+	SG_Free(b);
+	SG_Free(m[0]);
+	SG_Free(m);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Classify_Supervised.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,127 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Classify_Supervised.h              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Classify_Supervised_H
+#define HEADER_INCLUDED__Grid_Classify_Supervised_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Classify_Supervised : public CSG_Module_Grid
+{
+public:
+	CGrid_Classify_Supervised(void);
+	virtual ~CGrid_Classify_Supervised(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("R:Classification") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	bool						m_bNormalise;
+
+	double						m_ML_Threshold;
+
+	CSG_Table					*m_pClasses;
+
+	CSG_Grid					*m_pResult, *m_pProbability;
+
+	CSG_Parameter_Grid_List		*m_pGrids;
+
+
+	bool						Initialise				(void);
+	bool						Finalise				(void);
+
+	CSG_Table_Record *			Get_Class				(const SG_Char *Identifier);
+
+	bool						Set_Minimum_Distance	(void);
+	bool						Set_Maximum_Likelihood	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Classify_Supervised_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,755 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Cluster_Analysis.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Cluster_Analysis.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Cluster_Analysis::CGrid_Cluster_Analysis(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Cluster Analysis for Grids"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(		
+		"Cluster Analysis for grids.\n\nReferences:\n\n"
+
+		"Iterative Minimum Distance:\n"
+		"- Forgy, E. (1965):\n"
+		"  'Cluster Analysis of multivariate data: efficiency vs. interpretability of classifications',\n"
+		"  Biometrics 21:768\n\n"
+
+		"Hill-Climbing:"
+		"- Rubin, J. (1967):\n"
+		"  'Optimal Classification into Groups: An Approach for Solving the Taxonomy Problem',\n"
+		"  J. Theoretical Biology, 15:103-144\n\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid_List(
+		NULL	, "INPUT"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Clusters"),
+		_TL(""),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Int
+	);
+
+	Parameters.Add_Table(
+		NULL	, "STATISTICS"	, _TL("Statistics"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// 3. General Parameters...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Iterative Minimum Distance (Forgy 1965)"),
+			_TL("Hill-Climbing (Rubin 1967)"),
+			_TL("Combined Minimum Distance / Hillclimbing") 
+		),1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NCLUSTER"	, _TL("Clusters"),
+		_TL("Number of clusters"),
+		PARAMETER_TYPE_Int, 10, 2, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NORMALISE"	, _TL("Normalise"),
+		_TL("Automatically normalise grids by standard deviation before clustering."),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "UPDATEVIEW"	, _TL("Update View"),
+		_TL("Update cluster view while clustering."),
+		PARAMETER_TYPE_Bool, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Cluster_Analysis::~CGrid_Cluster_Analysis(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Cluster_Analysis::On_Execute(void)
+{
+	int						i, j, nCluster;
+	long					nElements;
+	double					SP;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("INPUT")	->asGridList();
+	nGrids		= pGrids->Get_Count();
+
+	pCluster	= Parameters("RESULT")	->asGrid();
+	nCluster	= Parameters("NCLUSTER")->asInt();
+
+	//-----------------------------------------------------
+	if( nGrids > 0 )
+	{
+		Grids		= (CSG_Grid **)SG_Malloc(nGrids * sizeof(CSG_Grid *));
+
+		if( Parameters("NORMALISE")->asBool() )
+		{
+			for(i=0; i<nGrids; i++)
+			{
+				Grids[i]	= SG_Create_Grid(pGrids->asGrid(i), SG_DATATYPE_Float);
+				Grids[i]->Assign(pGrids->asGrid(i));
+				Grids[i]->Normalise();
+			}
+		}
+		else
+		{
+			for(i=0; i<nGrids; i++)
+			{
+				Grids[i]	= pGrids->asGrid(i);
+			}
+		}
+
+		pCluster->Set_NoData_Value(-1.0);
+		pCluster->Assign_NoData();
+
+		nMembers	= (int     *)SG_Malloc(nCluster * sizeof(int));
+		Variances	= (double  *)SG_Malloc(nCluster * sizeof(double));
+		Centroids	= (double **)SG_Malloc(nCluster * sizeof(double *));
+
+		for(i=0; i<nCluster; i++)
+		{
+			Centroids[i]	= (double  *)SG_Malloc(nGrids * sizeof(double));
+		}
+
+		//-------------------------------------------------
+		nElements	= Get_NCells();
+
+		switch( Parameters("METHOD")->asInt() )
+		{
+		case 0:
+			SP	= MinimumDistance	(nElements, nCluster);
+			break;
+
+		case 1:
+			SP	= HillClimbing		(nElements, nCluster);
+			break;
+
+		case 2:
+			SP	= MinimumDistance	(nElements, nCluster);
+
+			nElements	= Get_NCells();	// may have been diminished because of no data values...
+
+			SP	= HillClimbing		(nElements, nCluster);
+			break;
+		}
+
+		//-------------------------------------------------
+		if( Parameters("NORMALISE")->asBool() )
+		{
+			for(i=0; i<nGrids; i++)
+			{
+				delete(Grids[i]);
+
+				Grids[i]	= pGrids->asGrid(i);
+			}
+
+			for(i=0; i<nGrids; i++)
+			{
+				for(j=0; j<nCluster; j++)
+				{
+					Centroids[j][i]	= sqrt(Grids[i]->Get_Variance()) * Centroids[j][i] + Grids[i]->Get_ArithMean();
+				}
+			}
+		}
+
+		Write_Result(Parameters("STATISTICS")->asTable(), nElements, nCluster, SP);
+
+		//-------------------------------------------------
+		CSG_Parameters	Parms;
+
+		if( DataObject_Get_Parameters(pCluster, Parms) && Parms("COLORS_TYPE") && Parms("LUT") )
+		{
+			CSG_Table_Record	*pClass;
+			CSG_Table			*pLUT	= Parms("LUT")->asTable();
+
+			for(i=0; i<nCluster; i++)
+			{
+				if( (pClass = pLUT->Get_Record(i)) == NULL )
+				{
+					pClass	= pLUT->Add_Record();
+					pClass->Set_Value(0, SG_GET_RGB(rand() * 255.0 / RAND_MAX, rand() * 255.0 / RAND_MAX, rand() * 255.0 / RAND_MAX));
+				}
+
+				pClass->Set_Value(1, CSG_String::Format(SG_T("%s %d"), _TL("Class"), i + 1));
+				pClass->Set_Value(2, CSG_String::Format(SG_T("%s %d"), _TL("Class"), i + 1));
+				pClass->Set_Value(3, i + 1);
+				pClass->Set_Value(4, i + 1);
+			}
+
+			while( pLUT->Get_Record_Count() > nCluster )
+			{
+				pLUT->Del_Record(pLUT->Get_Record_Count() - 1);
+			}
+
+			Parms("COLORS_TYPE")->Set_Value(1);	// Color Classification Type: Lookup Table
+
+			DataObject_Set_Parameters(pCluster, Parms);
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<nCluster; i++)
+		{
+			SG_Free(Centroids[i]);
+		}
+
+		SG_Free(Centroids);
+		SG_Free(Variances);
+		SG_Free(nMembers);
+
+		SG_Free(Grids);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Cluster_Analysis::Write_Result(CSG_Table *pTable, long nElements, int nCluster, double SP)
+{
+	int				i, j;
+	CSG_String		s;
+	CSG_Table_Record	*pRecord;
+
+	pTable->Destroy();
+	pTable->Set_Name(_TL("Cluster Analysis"));
+
+	pTable->Add_Field(_TL("ClusterID")	, SG_DATATYPE_Int);
+	pTable->Add_Field(_TL("Elements")	, SG_DATATYPE_Int);
+	pTable->Add_Field(_TL("Variance")	, SG_DATATYPE_Double);
+
+	s.Printf(SG_T("\n%s:\t%ld \n%s:\t%d \n%s:\t%d \n%s:\t%f"),
+		_TL("Number of Elements")			, nElements,
+		_TL("\nNumber of Variables")		, nGrids,
+		_TL("\nNumber of Clusters")			, nCluster,
+		_TL("\nValue of Target Function")	, SP
+	);
+
+	s.Append(CSG_String::Format(SG_T("%s\t%s\t%s"), _TL("Cluster"), _TL("Elements"), _TL("Variance")));
+
+	for(j=0; j<nGrids; j++)
+	{
+		s.Append(CSG_String::Format(SG_T("\t%02d_%s"), j + 1, Grids[j]->Get_Name()));
+		pTable->Add_Field(Grids[j]->Get_Name(), SG_DATATYPE_Double);
+	}
+
+	Message_Add(s);
+
+	for(i=0; i<nCluster; i++)
+	{
+		s.Printf(SG_T("%d\t%d\t%f"), i, nMembers[i], Variances[i]);
+
+		pRecord	= pTable->Add_Record();
+		pRecord->Set_Value(0, i);
+		pRecord->Set_Value(1, nMembers[i]);
+		pRecord->Set_Value(2, Variances[i]);
+
+		for(j=0; j<nGrids; j++)
+		{
+			s.Append(CSG_String::Format(SG_T("\t%f"), Centroids[i][j]));
+
+			pRecord->Set_Value(j + 3, Centroids[i][j]);
+		}
+
+		Message_Add(s);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Minimum Distance					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// (nElements)-Array -> Bei Eingabe Startgruppierung oder 0.
+// Bei Ausgabe Gruppierung: >Das ite Element ist im Cluster Cluster(i).
+
+double CGrid_Cluster_Analysis::MinimumDistance(long &nElements, int nCluster)
+{
+	//-----------------------------------------------------
+	// Variablen...
+
+	bool	bContinue;
+	int		iElement, iGrid, iCluster, nClusterElements, nShifts, minCluster, nPasses;
+	double	d, Variance, minVariance, SP, SP_Last	= -1;
+
+
+	//-----------------------------------------------------
+	// Anfangspartition (Standard falls nicht vorgegeben
+
+	for(iElement=0, nClusterElements=0; iElement<nElements; iElement++)
+	{
+		for(iGrid=0, bContinue=true; iGrid<nGrids && bContinue; iGrid++)
+		{
+			if( Grids[iGrid]->is_NoData(iElement) )
+			{
+				bContinue	= false;
+			}
+		}
+
+		if( bContinue )
+		{
+			if( pCluster->asInt(iElement) < 0 || pCluster->asInt(iElement) >= nCluster )
+			{
+				pCluster->Set_Value(iElement, iElement % nCluster);
+			}
+
+			nClusterElements++;
+		}
+		else
+		{
+			pCluster->Set_Value(iElement, -1);
+		}
+	}
+
+	if( Parameters("UPDATEVIEW")->asBool() )
+	{
+		DataObject_Update(pCluster, 0, nCluster, true);
+	}
+
+
+	//-----------------------------------------------------
+	// Hauptschleife der Iteration
+
+	for(nPasses=1, bContinue=true; bContinue && Process_Get_Okay(false); nPasses++)
+	{
+		//-------------------------------------------------
+		for(iCluster=0; iCluster<nCluster; iCluster++)
+		{
+			Variances[iCluster]	= 0;
+			nMembers [iCluster]	= 0;
+
+			for(iGrid=0; iGrid<nGrids; iGrid++)
+			{
+				Centroids[iCluster][iGrid]	= 0;
+			}
+		}
+
+		//-------------------------------------------------
+		for(iElement=0; iElement<nElements; iElement++)
+		{
+			if( pCluster->asInt(iElement) >= 0 )
+			{
+				iCluster	= pCluster->asInt(iElement);
+				nMembers[iCluster]++;
+
+				for(iGrid=0; iGrid<nGrids; iGrid++)
+				{
+					Centroids[iCluster][iGrid]	+= Grids[iGrid]->asDouble(iElement);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		for(iCluster=0; iCluster<nCluster; iCluster++)
+		{
+			d		= nMembers[iCluster] > 0 ? 1.0 / (double)nMembers[iCluster] : 0;
+
+			for(iGrid=0; iGrid<nGrids; iGrid++)
+			{
+				Centroids[iCluster][iGrid]	*= d;
+			}
+		}
+
+
+		//-------------------------------------------------
+		// Sift and Shift..
+
+		SP		= 0;
+		nShifts	= 0;
+
+		for(iElement=0; iElement<nElements && bContinue; iElement++)
+		{
+			if( !(iElement % (nElements / 100)) && !Set_Progress(iElement, nElements) )
+			{
+				bContinue	= false;
+			}
+
+			if( pCluster->asInt(iElement) >= 0 )
+			{
+				minVariance	= -1;
+
+				for(iCluster=0; iCluster<nCluster; iCluster++)
+				{
+					Variance	= 0;
+
+					for(iGrid=0; iGrid<nGrids; iGrid++)
+					{
+						d			= Centroids[iCluster][iGrid] - Grids[iGrid]->asDouble(iElement);
+						Variance	+= d * d;
+					}
+
+					if( minVariance<0 || Variance<minVariance )
+					{
+						minVariance	= Variance;
+						minCluster	= iCluster;
+					}
+				}
+
+				if( pCluster->asInt(iElement) != minCluster )
+				{
+					pCluster->Set_Value(iElement, minCluster);
+					nShifts++;
+				}
+
+				SP						+= minVariance;
+				Variances[minCluster]	+= minVariance;
+			}
+		}
+
+
+		//-------------------------------------------------
+
+		if( nShifts == 0 || (SP_Last >= 0 && SP >= SP_Last) )
+		{
+			bContinue	= false;
+		}
+
+		Process_Set_Text(CSG_String::Format(SG_T("%s: %d >> %s %f"),
+			_TL("pass")		, nPasses,
+			_TL("change")	, SP_Last < 0.0 ? SP : SP_Last - SP
+		));
+
+		SP_Last		= SP;
+
+		if( Parameters("UPDATEVIEW")->asBool() )
+		{
+			DataObject_Update(pCluster, 0, nCluster);	// Update_Output();
+		}
+	}
+
+	nElements	= nClusterElements;
+
+	return( SP );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Hill-Climbing						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CGrid_Cluster_Analysis::HillClimbing(long &nElements, int nCluster)
+{
+	//-----------------------------------------------------
+	// Variablen...
+
+	bool	bContinue;
+	int		iElement, iGrid, iCluster, jCluster, kCluster, nClusterElements, noShift, nPasses;
+	double	d, e, n_iK, n_jK, V, VMin, V1, V2, SP, SP_Last	= -1;
+
+
+	//-----------------------------------------------------
+
+	for(iCluster=0; iCluster<nCluster; iCluster++)
+	{
+		Variances[iCluster]	= 0;
+		nMembers [iCluster]	= 0;
+
+		for(iGrid=0; iGrid<nGrids; iGrid++)
+		{
+			Centroids[iCluster][iGrid]	= 0;
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Anfangspartition (Standard falls nicht vorgegeben)
+
+	for(iElement=0, nClusterElements=0; iElement<nElements; iElement++)
+	{
+		for(iGrid=0, bContinue=true; iGrid<nGrids && bContinue; iGrid++)
+		{
+			if( Grids[iGrid]->is_NoData(iElement) )
+			{
+				bContinue	= false;
+			}
+		}
+
+		if( bContinue )
+		{
+			if( pCluster->asInt(iElement) < 0 || pCluster->asInt(iElement) >= nCluster )
+			{
+				pCluster->Set_Value(iElement, iElement % nCluster);
+			}
+
+			nClusterElements++;
+
+			iCluster	= pCluster->asInt(iElement);
+
+			nMembers[iCluster]++;
+
+			V			= 0.0;
+
+			for(iGrid=0; iGrid<nGrids; iGrid++)
+			{
+				d							 = Grids[iGrid]->asDouble(iElement);
+				Centroids[iCluster][iGrid]	+= d;
+				V							+= d * d;
+			}
+
+			Variances[iCluster]	+= V;
+		}
+		else
+		{
+			pCluster->Set_Value(iElement, -1);
+		}
+	}
+
+
+	//-----------------------------------------------------
+
+	SP	= 0.0;
+
+	for(iCluster=0; iCluster<nCluster; iCluster++)
+	{
+		d	= nMembers[iCluster] != 0 ? 1.0 / (double)nMembers[iCluster] : 0;
+		V	= 0.0;
+
+		for(iGrid=0; iGrid<nGrids; iGrid++)
+		{
+			Centroids[iCluster][iGrid]	*= d;
+			e							 = Centroids[iCluster][iGrid];
+			V							+= e * e;
+		}
+
+		Variances[iCluster]	-= nMembers [iCluster] * V;
+		SP					+= Variances[iCluster];
+	}
+
+	if( Parameters("UPDATEVIEW")->asBool() )
+	{
+		DataObject_Update(pCluster, 0, nCluster, true);
+	}
+
+
+	//-----------------------------------------------------
+	// Hauptschleife der Iteration
+
+	noShift		= 0;
+
+	for(nPasses=1, bContinue=true; bContinue && Process_Get_Okay(false); nPasses++)
+	{
+		//-------------------------------------------------
+		for(iElement=0; iElement<nElements && bContinue; iElement++)
+		{
+			if( !(iElement % (nElements / 100)) && !Set_Progress(iElement, nElements) )
+			{
+				bContinue	= false;
+			}
+
+			if( pCluster->asInt(iElement) >= 0 )
+			{
+				if( noShift++ >= nElements )
+				{
+					bContinue	= false;
+				}
+				else
+				{
+
+					//---------------------------------------------
+					iCluster	= pCluster->asInt(iElement);
+
+					if( nMembers[iCluster] > 1 )
+					{
+						V	= 0.0;
+
+						for(iGrid=0; iGrid<nGrids; iGrid++)
+						{
+							d	= Centroids[iCluster][iGrid] - Grids[iGrid]->asDouble(iElement);
+							V	+= d * d;
+						}
+
+						n_iK	= nMembers[iCluster];
+						V1		= V * n_iK / (n_iK - 1.0);
+						VMin	= -1.0;
+
+						//-----------------------------------------
+						// Bestimme Gruppe iCluster mit evtl. groesster Verbesserung...
+
+						for(jCluster=0; jCluster<nCluster; jCluster++)
+						{
+							if( jCluster != iCluster )
+							{
+								V	= 0.0;
+
+								for(iGrid=0; iGrid<nGrids; iGrid++)
+								{
+									d	= Centroids[jCluster][iGrid] - Grids[iGrid]->asDouble(iElement);
+									V	+= d * d;
+								}
+
+								n_jK	= nMembers[jCluster];
+								V2		= V * n_jK / (n_jK + 1.0);
+
+								if( VMin < 0 || V2 < VMin )
+								{
+									VMin		= V2;
+									kCluster	= jCluster;
+								}
+							}
+						}
+
+
+						//-----------------------------------------
+						// Gruppenwechsel und Neuberechnung der Gruppencentroide...
+
+						if( VMin >= 0 && VMin < V1 )
+						{
+							noShift				= 0;
+							Variances[iCluster]	-= V1;
+							Variances[kCluster]	+= VMin;
+							SP					= SP - V1 + VMin;
+							V1					= 1.0 / (n_iK - 1.0);
+							n_jK				= nMembers[kCluster];
+							V2					= 1.0 / (n_jK + 1.0);
+
+							for(iGrid=0; iGrid<nGrids; iGrid++)
+							{
+								d							= Grids[iGrid]->asDouble(iElement);
+								Centroids[iCluster][iGrid]	= (n_iK * Centroids[iCluster][iGrid] - d) * V1;
+								Centroids[kCluster][iGrid]	= (n_jK * Centroids[kCluster][iGrid] + d) * V2;
+							}
+
+							pCluster->Set_Value(iElement, kCluster);
+
+							nMembers[iCluster]--;
+							nMembers[kCluster]++;
+						}
+					}
+				}
+			}
+		}
+
+		Process_Set_Text(CSG_String::Format(SG_T("%s: %d >> %s %f"),
+			_TL("pass")		, nPasses,
+			_TL("change")	, SP_Last < 0.0 ? SP : SP_Last - SP
+		));
+
+		SP_Last		= SP;
+
+		if( Parameters("UPDATEVIEW")->asBool() )
+		{
+			DataObject_Update(pCluster, 0, nCluster);	// Update_Output();
+		}
+	}
+
+	nElements	= nClusterElements;
+
+	return( SP );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Cluster_Analysis.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,105 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Cluster_Analysis.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Cluster_Analysis_H
+#define HEADER_INCLUDED__Grid_Cluster_Analysis_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Cluster_Analysis : public CSG_Module_Grid
+{
+public:
+	CGrid_Cluster_Analysis(void);
+	virtual ~CGrid_Cluster_Analysis(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Classification") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						nGrids, *nMembers;
+
+	double					**Centroids, *Variances;
+
+	CSG_Grid					**Grids, *pCluster;
+
+
+	void					Write_Result	(CSG_Table *pTable, long nElements, int nCluster, double SP);
+
+	double					MinimumDistance	(long &nElements, int nCluster);
+	double					HillClimbing	(long &nElements, int nCluster);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Cluster_Analysis_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,269 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_FastSegments.cpp                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_FastSegments.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_FastSegments::CGrid_FastSegments(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Grid Segmentation (b)"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Segmentation with the local minimum/maximum method."
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SEGMENTS"	, _TL("Segments"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "OBJECTS"		, _TL("Features"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// 3. General Parameters...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL("Choose if you want to segmentate either on minima or on maxima."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Minima"),
+			_TL("Maxima")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "VALUES"		, _TL("Output"),
+		_TL("The values of the resultant grid can be either the seed value (e.g. the local maximum) or the enumerated segment id."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Segment ID"),
+			_TL("Seed Value")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CGrid_FastSegments::~CGrid_FastSegments(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_FastSegments::On_Execute(void)
+{
+	int		n, x, y;
+
+	//-----------------------------------------------------
+	m_pGrid		= Parameters("INPUT")		->asGrid();
+	m_pSegments	= Parameters("SEGMENTS")	->asGrid();
+	m_pObjects	= Parameters("OBJECTS")		->asGrid();
+
+	m_bDown		= Parameters("METHOD")		->asInt() == 1;
+
+	//-----------------------------------------------------
+	m_nSegments	= 0;
+	m_pSegments	->Assign(0.0);
+	m_Values	= NULL;
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( m_pGrid->Get_Sorted(n, x, y, m_bDown) )
+		{
+			Set_Cell(x, y);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_nSegments > 0 )
+	{
+		if( Parameters("VALUES")->asInt() == 1 )
+		{
+			for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+			{
+				if( (x = m_pSegments->asInt(n) - 1) >= 0 && x < m_nSegments )
+				{
+					m_pSegments->Set_Value(n, m_Values[x]);
+				}
+				else
+				{
+					m_pSegments->Set_NoData(n);
+					m_pObjects ->Set_NoData(n);
+				}
+			}
+		}
+
+		SG_Free(m_Values);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_FastSegments::Set_Cell(int x, int y)
+{
+	int		i, ix, iy, n, s, id;
+	double	zMin;
+
+	//-----------------------------------------------------
+	if( !m_pGrid->is_InGrid(x, y) )
+	{
+		m_pSegments	->Set_NoData(x, y);
+		m_pObjects	->Set_NoData(x, y);
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		for(i=0, n=0, id=-1; i<8; i++)
+		{
+			ix	= Get_xTo(i, x);
+			iy	= Get_yTo(i, y);
+
+			if( m_pGrid->is_InGrid(ix, iy) )
+			{
+				if( (s = m_pSegments->asInt(ix, iy)) > 0 && s != id )
+				{
+					n++;
+
+					if( n == 1 || ( m_bDown && zMin > m_pGrid->asDouble(ix, iy)) || (!m_bDown && zMin < m_pGrid->asDouble(ix, iy)) )
+				//	if( n == 1 || ( m_bDown && zMin > m_Values[id - 1]) || (!m_bDown && zMin < m_Values[id - 1]) )
+					{
+						id		= s;
+						zMin	= m_pGrid->asDouble(ix, iy);
+					}
+				}
+			}
+		}
+
+		//-----------------------------------------------------
+		switch( n )
+		{
+		case 0:
+			id					= ++m_nSegments;
+			m_Values			= (double *)SG_Realloc(m_Values, m_nSegments * sizeof(double));
+			m_Values[id - 1]	= m_pGrid->asDouble(x, y);
+
+			m_pSegments	->Set_Value	(x, y, id);
+			m_pObjects	->Set_Value	(x, y, 2);
+			break;
+
+		case 1:
+			m_pSegments	->Set_Value	(x, y, id);
+			m_pObjects	->Set_NoData(x, y);
+			break;
+
+		default:
+			m_pSegments	->Set_Value	(x, y, id);
+			m_pObjects	->Set_Value	(x, y, 1);
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_FastSegments.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,117 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_FastSegments.h                  //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_FastSegments_H
+#define HEADER_INCLUDED__Grid_FastSegments_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_FastSegments : public CSG_Module_Grid
+{
+public:
+	CGrid_FastSegments(void);
+	virtual ~CGrid_FastSegments(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	bool				m_bDown;
+
+	int					m_nSegments;
+
+	double				*m_Values;
+
+	CSG_Grid				*m_pGrid, *m_pSegments, *m_pObjects;
+
+
+	void				Set_Cell		(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_FastSegments_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,613 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Segmentation.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Segmentation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						CSegment						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSegment::CSegment(int aSegment, double aValue, int axSeed, int aySeed)
+{
+	iSegment		= aSegment;
+	Value			= aValue;
+	xSeed			= axSeed;
+	ySeed			= aySeed;
+
+	nConnects		= 0;
+	maxConnects		= 10;
+
+	Connect			= (int *)SG_Malloc(maxConnects * sizeof(int));
+	Segment			= (int *)SG_Malloc(maxConnects * sizeof(int));
+}
+
+//---------------------------------------------------------
+CSegment::~CSegment(void)
+{
+	SG_Free(Connect);
+	SG_Free(Segment);
+}
+
+//---------------------------------------------------------
+inline int CSegment::Get_Segment(int jSegment)
+{
+	int		i;
+
+	for(i=0; i<nConnects; i++)
+		if( Segment[i] == jSegment )
+			return( Connect[i] );
+
+	return(0);
+}
+
+//---------------------------------------------------------
+inline void CSegment::Set_Segment(int jSegment, int jConnect)
+{
+	if( nConnects >= maxConnects )
+	{
+		maxConnects		+= 10;
+		Connect			= (int *)SG_Realloc(Connect,maxConnects * sizeof(int));
+		Segment			= (int *)SG_Realloc(Segment,maxConnects * sizeof(int));
+	}
+
+	Connect[nConnects]	= jConnect;
+	Segment[nConnects]	= jSegment;
+
+	nConnects++;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Segmentation::CGrid_Segmentation(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Grid Segmentation"));
+
+	Set_Author		(SG_T("(c) 2002 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Segmentation with the local maximum method.\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Segments"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// 3. General Parameters...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL("Choose if you want to segmentate either on minima or on maxima."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Minima"),
+			_TL("Maxima")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BORDERS"		, _TL("Borders"),
+		_TL("Keep the borders between segments as special values."),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	Parameters.Add_Choice(
+		Parameters("RESULT"), "OUTPUT_TYPE", _TL("Output"),
+		_TL("The values of the resultant grid can be either the seed value (e.g. the local maximum) or the enumerated segment id."),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Seed Value"),
+			_TL("Segment ID")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THRESHOLD"	, _TL("Threshold"),
+		_TL("Specify a threshold value as minimum difference between neighboured segments."),
+		PARAMETER_TYPE_Double
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Segmentation::~CGrid_Segmentation(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Segmentation::On_Execute(void)
+{
+	bool	bDown, bBorder, bWriteID;
+
+	int		x, y;
+
+	double	Threshold;
+
+	//-----------------------------------------------------
+	pGrid		= Parameters("INPUT")->asGrid();
+	pSegments	= Parameters("RESULT")->asGrid();
+
+	bDown		= Parameters("METHOD")->asInt() == 1;
+	bBorder		= Parameters("BORDERS")->asBool();
+	bWriteID	= Parameters("OUTPUT_TYPE")->asInt() == 1;
+	Threshold	= Parameters("THRESHOLD")->asDouble();
+
+	//-----------------------------------------------------
+	if( !bDown )
+	{
+		pGrid->Invert();
+	}
+
+	//-----------------------------------------------------
+	pSegments->Assign();
+
+	//-----------------------------------------------------
+	Do_Grid_Segmentation( Threshold );
+
+	//-----------------------------------------------------
+	if( bBorder )
+		UnPrepareBorders();
+	else
+		UnPrepareNoBorders();
+
+	//-----------------------------------------------------
+	if( Segments )
+	{
+		if( !bWriteID )
+		{
+			for(y=0; y<Get_NY(); y++)
+				for(x=0; x<Get_NX(); x++)
+					if( pSegments->asInt(x,y) > 0 )
+						pSegments->Set_Value(x,y, Segments[pSegments->asInt(x,y)-1]->Get_Value() );
+		}
+
+		for(y=0; y<nSegments; y++)
+			delete(Segments[y]);
+
+		SG_Free(Segments);
+	}
+
+	//-----------------------------------------------------
+	if( !bDown )
+	{
+		pGrid->Invert();
+		pGrid->Set_Index(false);
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Segmentation::Do_Grid_Segmentation(double Threshold)
+{
+	int		x, y, i,
+			iConnect, nConnects,
+			SegmentA, SegmentB;
+
+	long	n;
+
+	double	aVal, bVal;
+
+	//-----------------------------------------------------
+	if( Get_Initials() )
+	{
+		nConnects	= -2;
+
+		for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+		{
+			pGrid->Get_Sorted(n,x,y);
+
+			if( !Get_System()->is_InGrid(x, y, 1) )
+			{
+				pSegments->Set_Value(x,y,-1);
+			}
+			else if(pSegments->asInt(x,y) <= 0)
+			{
+				iConnect	= 0;
+				SegmentB	= 0;
+
+				for(i=0; i<8; i++)
+				{
+					SegmentA	= pSegments->asInt(Get_System()->Get_xTo(i,x),Get_System()->Get_yTo(i,y));
+
+					if( SegmentA >0 )	// <0=Border, 0=noch undefined, >0=iSegment
+					{
+						if( SegmentB == 0 )
+						{
+							SegmentB	= SegmentA;
+						}
+						else if( SegmentB != SegmentA )
+						{
+							iConnect	= Segments[SegmentA-1]->Get_Segment(SegmentB);
+
+							if( iConnect==0 )
+							{
+								aVal	= Segments[SegmentA-1]->Get_Value();
+								bVal	= Segments[SegmentB-1]->Get_Value();
+
+								if( fabs(aVal - bVal) < Threshold)
+								{
+									if( aVal < bVal )
+									{
+										Segment_Change(SegmentA,SegmentB);
+									}
+									else
+									{
+										Segment_Change(SegmentB,SegmentA);
+										SegmentB	= SegmentA;
+									}
+								}
+								else
+								{
+									iConnect	= nConnects--;
+									Segments[SegmentA-1]->Set_Segment(SegmentA,iConnect);
+									Segments[SegmentB-1]->Set_Segment(SegmentB,iConnect);
+								}
+							}
+
+							break;
+						}
+					}
+				}
+
+				pSegments->Set_Value(x,y, iConnect ? iConnect : SegmentB);
+			}
+		}
+
+		Get_Junctions();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Segmentation::Get_Initials(void)
+{
+	bool	bSegment;
+	int		x, y, ix, iy, i;
+	long	n;
+	double	d;
+
+	nSegments	= 0;
+	Segments	= NULL;
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		pGrid->Get_Sorted(n,x,y);
+
+		if( Get_System()->is_InGrid(x,y,1) )
+		{
+			d			= pGrid->asDouble(x,y);
+			bSegment	= true;
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_System()->Get_xTo(i,x);
+				iy	= Get_System()->Get_yTo(i,y);
+
+				if( Get_System()->is_InGrid(ix,iy,1) )
+				{
+					if( d < pGrid->asDouble(ix,iy) )
+						bSegment	= false;
+				}
+			}
+
+			//---------------------------------------------
+			if( bSegment )
+			{
+				nSegments++;
+				pSegments->Set_Value(x,y, nSegments);
+				Segments				= (CSegment **)SG_Realloc(Segments,nSegments * sizeof(CSegment *));
+				Segments[nSegments-1]	= (CSegment  *)new CSegment(nSegments,d,x,y);
+			}
+		}
+	}
+
+	return( nSegments > 1 );
+}
+
+//---------------------------------------------------------
+void CGrid_Segmentation::Get_Junctions(void)
+{
+	int		x, y, ix, iy, i,
+			p, p1, p2;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pSegments->asInt(x,y) < 0 )
+			{
+				p1	= p2	= 0;
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_System()->Get_xTo(i,x);
+					iy	= Get_System()->Get_yTo(i,y);
+
+					p	= !Get_System()->is_InGrid(ix,iy) ? 1 : pSegments->asInt(ix,iy);
+
+					if( p > 0 )
+					{
+						if(!p1)
+						{
+							p1	= p;
+						}
+						else if(p1!=p)
+						{
+							if(!p2)
+							{
+								p2	= p;
+							}
+							else if(p2!=p)
+							{
+								pSegments->Set_Value(x,y,-1);
+								break;
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Segmentation::Segment_Change(int iFrom, int iTo)
+{
+	bool	bContinue;
+	int		ax, ay, bx, by, x, y;
+
+	//-----------------------------------------------------
+	ax	= bx	= Segments[iFrom-1]->Get_xSeed();
+	ay	= by	= Segments[iFrom-1]->Get_ySeed();
+
+	do
+	{
+		bContinue	= false;
+
+		for(x=ax; x<=bx; x++)
+		{
+			if(Segment_Change(x,ay,iFrom,iTo))
+				bContinue		= true;
+
+			if(Segment_Change(x,by,iFrom,iTo))
+				bContinue		= true;
+		}
+
+		for(y=ay; y<=by; y++)
+		{
+			if(Segment_Change(ax,y,iFrom,iTo))
+				bContinue		= true;
+
+			if(Segment_Change(bx,y,iFrom,iTo))
+				bContinue		= true;
+		}
+
+		if(ax>0)
+			ax--;
+		if(ay>0)
+			ay--;
+		if(bx<Get_NX()-1)
+			bx++;
+		if(by<Get_NY()-1)
+			by++;
+	}
+	while( bContinue );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_Segmentation::Segment_Change(int x, int y, int iFrom, int iTo)
+{
+	if( pSegments->asInt(x,y) == iFrom )
+	{
+		pSegments->Set_Value(x,y,iTo);
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Segmentation::UnPrepareNoBorders(void)
+{
+	bool	bRepeat, bRoger;
+	int		x, y, i, ix, iy, nRepeats;
+
+	nRepeats	= 0;
+
+	do
+	{
+		bRepeat	= false;
+
+		for(y=0; y<Get_NY(); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( pSegments->asInt(x,y) < 0 )
+				{
+					bRoger	= false;
+
+					for(i=0; i<8; i++)
+					{
+						ix	= Get_System()->Get_xTo(i,x);
+						iy	= Get_System()->Get_yTo(i,y);
+
+						if(Get_System()->is_InGrid(ix,iy))
+						{
+							if( pSegments->asInt(ix,iy) > 0 )
+							{
+								pSegments->Set_Value(x,y,pSegments->asInt(ix,iy));
+								bRoger	= true;
+								break;
+							}
+						}
+					}
+
+					if(!bRoger)
+						bRepeat	= true;
+				}
+			}
+		}
+	}
+	while( bRepeat && nRepeats++ < 10 );
+}
+
+//---------------------------------------------------------
+void CGrid_Segmentation::UnPrepareBorders(void)
+{
+	bool	bKill;
+	int		x, y, i, ix, iy, z;
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pSegments->asInt(x,y) < 0 )
+			{
+				z		= -1;
+				bKill	= true;
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_System()->Get_xTo(i,x);
+					iy	= Get_System()->Get_yTo(i,y);
+
+					if( Get_System()->is_InGrid(ix,iy) )
+					{
+						if( pSegments->asInt(ix,iy) > 0 )
+						{
+							if( z < 0 )
+							{
+								z	= pSegments->asInt(ix,iy);
+							}
+							else if( z != pSegments->asInt(ix,iy) )
+							{
+								bKill	= false;
+								break;
+							}
+						}
+					}
+				}
+
+				pSegments->Set_Value(x,y, z > 0 && bKill ? z : -1);
+			}
+		}
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Segmentation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Segmentation.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Segmentation_H
+#define HEADER_INCLUDED__Grid_Segmentation_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSegment
+{
+public:
+	CSegment(int Segment, double Value, int xSeed, int ySeed);
+	~CSegment(void);
+
+	int					Get_Segment(int jSegment);
+	void				Set_Segment(int jSegment, int jConnect);
+
+	double				Get_Value(void)	{	return( Value );	}
+	int					Get_xSeed(void)	{	return( xSeed );	}
+	int					Get_ySeed(void)	{	return( ySeed );	}
+
+
+private:
+
+	int					iSegment, xSeed, ySeed,
+						nConnects, maxConnects,
+						*Connect, *Segment;
+
+	double				Value;
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Segmentation : public CSG_Module_Grid
+{
+public:
+	CGrid_Segmentation(void);
+	virtual ~CGrid_Segmentation(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	int					nSegments;
+
+	CSG_Grid				*pGrid, *pSegments;
+
+	CSegment			**Segments;
+
+
+	void				Do_Grid_Segmentation(double Threshold);
+
+	bool				Get_Initials(void);
+	void				Get_Junctions(void);
+
+	void				Segment_Change(int iFrom, int iTo);
+	bool				Segment_Change(int iFrom, int iTo, int x, int y);
+
+	void				UnPrepareNoBorders(void);
+	void				UnPrepareBorders(void);
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Segmentation_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,950 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Skeletonize.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Skeletonize.h"
+
+//---------------------------------------------------------
+#define	skNE			1
+#define skJA			2
+
+#define SEGMENT_END		1
+#define SEGMENT_NODE	2
+#define SEGMENT_LOCKED	3
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Skeletonize::CGrid_Skeletonize(void)
+{
+	Set_Name		(_TL("Grid Skeletonization"));
+
+	Set_Author		(SG_T("(c) 2002 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Simple skeletonisation methods for grids.\n"
+	));
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"			, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"			, _TL("Skeleton"),
+		_TL(""),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Char
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "VECTOR"			, _TL("Skeleton"),
+		_TL(""), PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"			, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Standard"),
+			_TL("Hilditch's Algorithm"),
+			_TL("Channel Skeleton")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL, "INIT_METHOD"		, _TL("Initialisation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Less than"),
+			_TL("Greater than") 
+		),1
+	);
+
+	Parameters.Add_Value(
+		NULL, "INIT_THRESHOLD"	, _TL("Threshold (Init.)"),
+		_TL(""),
+		PARAMETER_TYPE_Double
+	);
+
+	Parameters.Add_Value(
+		NULL, "CONVERGENCE"		, _TL("Convergence"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 3
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Skeletonize::~CGrid_Skeletonize(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Skeletonize::On_Execute(void)
+{
+	int			n, Initiation;
+	double		Threshold;
+	CSG_Grid	*pInput;
+
+	//-----------------------------------------------------
+	pInput		= Parameters("INPUT")			->asGrid();
+	pResult		= Parameters("RESULT")			->asGrid();
+
+	Initiation	= Parameters("INIT_METHOD")		->asInt();
+	Threshold	= Parameters("INIT_THRESHOLD")	->asDouble();
+
+	DataObject_Set_Colors(pResult, 3, SG_COLORS_BLACK_WHITE, true);
+	pResult->Assign(0.0);
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells(); n++)
+	{
+		switch( Initiation )
+		{
+		case 0: default:
+			if( pInput->asDouble(n) < Threshold )
+			{
+				pResult->Set_Value(n, 1);
+			}
+			break;
+
+		case 1:
+			if( pInput->asDouble(n) > Threshold )
+			{
+				pResult->Set_Value(n, 1);
+			}
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:	default:
+		Standard_Execute();
+		break;
+
+	case 1:
+		Hilditch_Execute();
+		break;
+
+	case 2:
+		SK_Execute();
+		break;
+	}
+
+	//-------------------------------------------------
+	if( Parameters("VECTOR")->asShapes() )
+	{
+		Vectorize(Parameters("VECTOR")->asShapes());
+	}
+
+	if( 1 )
+	{
+		for(n=0; n<Get_NCells(); n++)
+		{
+			switch( Initiation )
+			{
+			case 0: default:
+				if( pInput->asDouble(n) < Threshold )
+				{
+					pResult->Add_Value(n, 1);
+				}
+				break;
+
+			case 1:
+				if( pInput->asDouble(n) > Threshold )
+				{
+					pResult->Add_Value(n, 1);
+				}
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Helpers							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CGrid_Skeletonize::Get_Neighbours(int x, int y, CSG_Grid *pGrid, bool Neighbours[8])
+{
+	int		i, ix, iy, nNeighbours;
+
+	nNeighbours	= 0;
+
+	for(i=0; i<8; i++)
+	{
+		ix	= Get_System()->Get_xTo(i, x);
+		iy	= Get_System()->Get_yTo(i, y);
+
+		if( pGrid->is_InGrid(ix, iy) && pGrid->asByte(ix, iy) )
+		{
+			Neighbours[i]	= true;
+
+			nNeighbours++;
+		}
+		else
+		{
+			Neighbours[i]	= false;
+		}
+	}
+
+	return( nNeighbours );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Vectorization						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CGrid_Skeletonize::Vectorize(CSG_Shapes *pShapes)
+{
+	bool	z[8], bPrev;
+
+	int		x, y, i, ix, iy, n, nSegments;
+
+	double	xMin, yMin, dx, dy;
+
+	CSG_Shape	*pShape;
+
+	//-----------------------------------------------------
+	pShapes->Create(SHAPE_TYPE_Line, _TL("Skeleton"));
+	pShapes->Add_Field("ID", SG_DATATYPE_Int);
+
+	Lock_Create();
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pResult->asByte(x, y) )
+			{
+				n	= Get_Neighbours(x, y, pResult, z);
+				
+				if( n == 1 )
+				{
+					Lock_Set(x, y, SEGMENT_END);
+				}
+				else if( n > 1 )
+				{
+					n	= 0;
+
+					for(i=0, bPrev=z[7]; i<8; i++)
+					{
+						if( bPrev == false && z[i] == true )
+						{
+							n++;
+						}
+
+						bPrev	= z[i];
+					}
+
+					if( n > 2 )
+					{
+						Lock_Set(x, y, SEGMENT_NODE);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	nSegments	= 0;
+
+	for(y=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		dx			= pResult->Get_Cellsize();
+		xMin		= pResult->Get_XMin();// + 0.5 * dx;
+		dy			= pResult->Get_Cellsize();
+		yMin		= pResult->Get_YMin();// + 0.5 * dy;
+
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( Lock_Get(x, y) == SEGMENT_NODE || Lock_Get(x, y) == SEGMENT_END )
+			{
+				Lock_Set(x, y, SEGMENT_LOCKED);
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_System()->Get_xTo(i, x);
+					iy	= Get_System()->Get_yTo(i, y);
+
+					if( pResult->is_InGrid(ix, iy) && pResult->asByte(ix, iy) && !Lock_Get(ix, iy) )
+					{
+						pShape	= pShapes->Add_Shape();
+						pShape->Set_Value(0, ++nSegments);
+						pShape->Add_Point(xMin + dx * (double)x, yMin + dy * (double)y);
+
+						Vectorize_Trace(ix, iy, pShape);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	Lock_Destroy();
+
+	Message_Dlg(CSG_String::Format(SG_T("%d %s\n"), nSegments, _TL("segments identified")), Get_Name());
+
+	return( nSegments );
+}
+
+//---------------------------------------------------------
+bool CGrid_Skeletonize::Vectorize_Trace(int x, int y, CSG_Shape *pShape)
+{
+	bool	bContinue;
+
+	int		i, ix, iy, iNext;
+
+	double	xMin, yMin, dx, dy;
+
+	//-----------------------------------------------------
+	dx			= pResult->Get_Cellsize();
+	xMin		= pResult->Get_XMin();// + 0.5 * dx;
+	dy			= pResult->Get_Cellsize();
+	yMin		= pResult->Get_YMin();// + 0.5 * dy;
+
+	bContinue	= true;
+
+	do
+	{
+		pShape->Add_Point(xMin + dx * (double)x, yMin + dy * (double)y);
+
+		if( Lock_Get(x, y) == SEGMENT_NODE || Lock_Get(x, y) == SEGMENT_END )
+		{
+			bContinue	= false;
+		}
+		else
+		{
+			Lock_Set(x, y, SEGMENT_LOCKED);
+
+			iNext	= -1;
+
+			for(i=0; i<8; i+=2)
+			{
+				ix	= Get_System()->Get_xTo(i, x);
+				iy	= Get_System()->Get_yTo(i, y);
+
+				if( pResult->is_InGrid(ix, iy) && pResult->asByte(ix, iy) && Lock_Get(ix, iy) != SEGMENT_LOCKED )
+				{
+					iNext	= i;
+
+					if( Lock_Get(ix, iy) == SEGMENT_NODE )
+					{
+						break;
+					}
+				}
+			}
+
+			if( iNext < 0 )
+			{
+				for(i=1; i<8; i+=2)
+				{
+					ix	= Get_System()->Get_xTo(i, x);
+					iy	= Get_System()->Get_yTo(i, y);
+
+					if( pResult->is_InGrid(ix, iy) && pResult->asByte(ix, iy) && Lock_Get(ix, iy) != SEGMENT_LOCKED )
+					{
+						iNext	= i;
+
+						if( Lock_Get(ix, iy) == SEGMENT_NODE )
+						{
+							break;
+						}
+					}
+				}
+			}
+
+			if( iNext < 0 )
+			{
+				bContinue	= false;
+			}
+			else
+			{
+				x	+= Get_System()->Get_xTo(iNext);
+				y	+= Get_System()->Get_yTo(iNext);
+			}
+		}
+	}
+	while( bContinue );
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Standard						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Skeletonize::Standard_Execute(void)
+{
+	int		i, nChanges;
+
+	CSG_Grid	*pPrev, *pNext, *pTemp;
+
+	//-----------------------------------------------------
+	pPrev		= pResult;
+	pNext		= SG_Create_Grid(pPrev);
+
+	//-----------------------------------------------------
+	do
+	{
+		DataObject_Update(pResult, 0, 1, true);
+
+		nChanges	= 0;
+
+		for(i=0; i<8; i++)
+		{
+			nChanges	+= Standard_Step(i, pPrev, pNext);
+
+			pTemp		= pPrev;
+			pPrev		= pNext;
+			pNext		= pTemp;
+		}
+	}
+	while( nChanges > 0 && Process_Get_Okay(true) );
+
+	//-----------------------------------------------------
+	if( pNext == pResult )
+	{
+		delete(pPrev);
+	}
+	else
+	{
+		pResult->Assign(pNext);
+
+		delete(pNext);
+	}
+}
+
+//---------------------------------------------------------
+int CGrid_Skeletonize::Standard_Step(int iDir, CSG_Grid *pPrev, CSG_Grid *pNext)
+{
+	bool	z[8], bRemove;
+
+	int		x, y, nNeighbours, nChanges;
+
+	pNext->Assign();
+
+	nChanges	= 0;
+
+	for(y=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pPrev->asByte(x, y) )
+			{
+				bRemove		= false;
+				nNeighbours	= Get_Neighbours(x, y, pPrev, z);
+
+				if( nNeighbours > 1 && nNeighbours < 6 )
+				{
+					bRemove	= Standard_Check(iDir, z);
+				}
+
+				if( bRemove )
+				{
+					nChanges++;
+				}
+				else
+				{
+					pNext->Set_Value(x, y, 1);
+				}
+			}
+		}
+	}
+
+	return( nChanges );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_Skeletonize::Standard_Check(int iDir, bool z[8])
+{
+	bool	bRemove;
+
+	switch( iDir )
+	{
+	default:
+		bRemove	= false;
+		break;
+
+	case 0:
+		bRemove	=	!z[7] && !z[0] && !z[1]
+				&&	 z[3] &&  z[4] &&  z[5];
+		break;
+
+	case 1:
+		bRemove	=	!z[0] && !z[1] && !z[2]
+				&&	 z[4]      &&      z[6];
+		break;
+
+	case 2:
+		bRemove	=	!z[1] && !z[2] && !z[3]
+				&&	 z[5] &&  z[6] &&  z[7];
+		break;
+
+	case 3:
+		bRemove	=	!z[2] && !z[3] && !z[4]
+				&&	 z[6]      &&      z[0];
+		break;
+
+	case 4:
+		bRemove	=	!z[3] && !z[4] && !z[5]
+				&&	 z[7] &&  z[0] &&  z[1];
+		break;
+
+	case 5:
+		bRemove	=	!z[4] && !z[5] && !z[6]
+				&&	 z[0]      &&      z[2];
+		break;
+
+	case 6:
+		bRemove	=	!z[5] && !z[6] && !z[7]
+				&&	 z[1] &&  z[2] &&  z[3];
+		break;
+
+	case 7:
+		bRemove	=	!z[6] && !z[7] && !z[0]
+				&&	 z[2]      &&      z[4];
+		break;
+	}
+
+	return( bRemove );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Hilditch						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Skeletonize::Hilditch_Execute(void)
+{
+	int		nChanges;
+
+	CSG_Grid	*pPrev, *pNext, *pTemp, *pNC_Gaps;
+
+	//-----------------------------------------------------
+	pPrev		= pResult;
+	pNext		= SG_Create_Grid(pPrev);
+	pNC_Gaps	= SG_Create_Grid(pPrev, SG_DATATYPE_Char);
+
+	//-----------------------------------------------------
+	do
+	{
+		DataObject_Update(pResult, 0, 1, true);
+
+		nChanges	= Hilditch_Step(pPrev, pNext, pNC_Gaps);
+
+		pTemp		= pPrev;
+		pPrev		= pNext;
+		pNext		= pTemp;
+	}
+	while( nChanges > 0 && Process_Get_Okay(true) );
+
+	//-----------------------------------------------------
+	delete(pNC_Gaps);
+
+	if( pNext == pResult )
+	{
+		delete(pPrev);
+	}
+	else
+	{
+		pResult->Assign(pNext);
+
+		delete(pNext);
+	}
+}
+
+//---------------------------------------------------------
+int CGrid_Skeletonize::Hilditch_Step(CSG_Grid *pPrev, CSG_Grid *pNext, CSG_Grid *pNC_Gaps)
+{
+	bool	z[8], bPrev, bRemove;
+
+	int		x, y, i, nChanges, nNeighbours;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			nChanges	= 0;
+
+			if( pPrev->asByte(x, y) && Get_Neighbours(x, y, pPrev, z) > 0 )
+			{
+				for(i=0, bPrev=z[7]; i<8; i++)
+				{
+					if( bPrev == false && z[i] == true )
+					{
+						nChanges++;
+					}
+
+					bPrev	= z[i];
+				}
+			}
+
+			pNC_Gaps->Set_Value(x, y, nChanges);
+		}
+	}
+
+	//-----------------------------------------------------
+	pNext->Assign();
+
+	nChanges	= 0;
+
+	for(y=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pPrev->asByte(x, y) )
+			{
+				bRemove		= false;
+				nNeighbours	= Get_Neighbours(x, y, pPrev, z);
+
+				//-----------------------------------------
+				if( 2 <= nNeighbours && nNeighbours <= 6 && pNC_Gaps->asByte(x, y) == 1 )
+				{
+					bRemove	=	Hilditch_Check(pNC_Gaps, x, y, 0, z)
+							||	Hilditch_Check(pNC_Gaps, x, y, 2, z)
+							||	Hilditch_Check(pNC_Gaps, x, y, 4, z)
+							||	Hilditch_Check(pNC_Gaps, x, y, 6, z)
+							;
+				}
+
+				//-----------------------------------------
+				if( bRemove )
+				{
+					nChanges++;
+				}
+				else
+				{
+					pNext->Set_Value(x, y, true);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( nChanges );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_Skeletonize::Hilditch_Check(CSG_Grid *pNC_Gaps, int x, int y, int i0, bool z[8])
+{
+	int		ix, iy, i2, i4, i6;
+
+	i2		= (i0 + 2) % 8;
+	i4		= (i0 + 4) % 8;
+	i6		= (i0 + 6) % 8;
+
+	if( z[i0] || z[i2] || z[i6] )
+	{
+		ix		= Get_System()->Get_xTo(i0, x);
+		iy		= Get_System()->Get_yTo(i0, y);
+
+		if( pNC_Gaps->is_InGrid(ix, iy) && pNC_Gaps->asByte(ix, iy) == 1 )
+		{
+			return( false );
+		}
+	}
+
+	if( z[i0] || z[i2] || z[i4] )
+	{
+		ix		= Get_System()->Get_xTo(i2, x);
+		iy		= Get_System()->Get_yTo(i2, y);
+
+		if( pNC_Gaps->is_InGrid(ix, iy) && pNC_Gaps->asByte(ix, iy) == 1 )
+		{
+			return( false );
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Channel Detection					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Skeletonize::SK_Execute(void)
+{
+	int		x, y, i, ix, iy, n,
+			Convergence, NB[8];
+
+	double	z, iz;
+
+	CSG_Grid	*pInput;
+
+	//-----------------------------------------------------
+	Convergence	= Parameters("CONVERGENCE")->asInt();
+	pInput		= Parameters("INPUT")->asGrid();
+
+	pResult->Assign();
+
+
+	//-----------------------------------------------------
+	// 1.) Find definitive channel points...
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			z	= pInput->asDouble(x, y);
+			n	= 0;
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_System()->Get_xTo(i, x);
+				iy	= Get_System()->Get_yTo(i, y);
+
+				if( pInput->is_InGrid(ix, iy) && z < pInput->asDouble(ix, iy) )
+				{
+					n++;
+				}
+			}
+
+			if( Convergence > n )
+			{
+				pResult->Set_Value(x, y, 2);
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// 2.) Find channels...
+
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{	
+		if( pInput->Get_Sorted(n, x, y) )	// Von oben nach unten...
+		{
+			z	= pInput->asDouble(x, y);
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_System()->Get_xTo(i,x);
+				iy	= Get_System()->Get_yTo(i,y);
+
+				if( !pInput->is_InGrid(ix, iy) )
+				{
+					NB[i]	= skNE;
+				}
+				else
+				{
+					iz	= pInput->asDouble(ix, iy);
+
+					if( iz < z )
+					{
+						NB[i]	= skNE;
+					}
+					else if( iz > z && pResult->asByte(ix, iy) )
+					{
+						NB[i]	= skJA;
+					}
+					else
+					{
+						NB[i]	= 0;
+					}
+				}
+			}
+
+			if( SK_Connectivity(NB) )
+			{
+				pResult->Set_Value(x, y, 1);
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	/*/ 3.) Filter...
+
+	Lock_Create();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			SK_Filter(x, y);
+		}
+	}
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( Lock_Get(x, y) )
+			{
+				pResult->Set_Value(x, y, 0);
+			}
+		}
+	}
+
+	Lock_Destroy();/**/
+}
+
+//---------------------------------------------------------
+int CGrid_Skeletonize::SK_Connectivity(int NB[8])
+{
+	int		i;
+
+	for(i=0; i<8; i+=2)
+	{
+		if( !NB[i] )
+		{
+			if( !NB[(i+2)%8] )	// Diagonal Connection
+			{
+			/*
+				if( ( NB[(i+1)%8]	)
+				&&	( NB[(i+3)%8] || NB[(i+4)%8] || NB[(i+5)%8] || NB[(i+6)%8] || NB[(i+7)%8] ) )
+					return(1);
+				*/
+
+				///*
+				if( ( NB[(i+1)%8]==skNE	)
+				&&	( NB[(i+3)%8]==skJA || NB[(i+4)%8]==skJA || NB[(i+5)%8]==skJA || NB[(i+6)%8]==skJA || NB[(i+7)%8]==skJA ) )
+					return(1);
+
+				if( ( NB[(i+1)%8]==skJA	)
+				&&	( NB[(i+3)%8]==skNE || NB[(i+4)%8]==skNE || NB[(i+5)%8]==skNE || NB[(i+6)%8]==skNE || NB[(i+7)%8]==skNE ) )
+					return(1);
+				//*/
+			}
+
+			//---Orthogonal-Connection---------------------------------
+			if(!NB[(i+4)%8])
+			{	/*
+				if(	( NB[(i+1)%8] || NB[(i+2)%8] || NB[(i+3)%8] )
+				&&	( NB[(i+5)%8] || NB[(i+6)%8] || NB[(i+7)%8] ) )
+					return(1);
+				*/
+
+				///*
+				if(	( NB[(i+1)%8]==skJA || NB[(i+2)%8]==skJA || NB[(i+3)%8]==skJA )
+				&&	( NB[(i+5)%8]==skNE || NB[(i+6)%8]==skNE || NB[(i+7)%8]==skNE ) )
+					return(1);
+
+				if(	( NB[(i+1)%8]==skNE || NB[(i+2)%8]==skNE || NB[(i+3)%8]==skNE )
+				&&	( NB[(i+5)%8]==skJA || NB[(i+6)%8]==skJA || NB[(i+7)%8]==skJA ) )
+					return(1);
+				//*/
+			}
+		}
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+bool CGrid_Skeletonize::SK_Filter(int x, int y)
+{
+	bool	z[8];
+
+	if( !pResult->asByte(x, y) && Get_Neighbours(x, y, pResult, z) == 4 )
+	{
+		if( z[0] && z[2] && z[4] && z[6] )
+		{
+			Lock_Set(Get_System()->Get_xTo(0, x), Get_System()->Get_yTo(0, y));
+			Lock_Set(Get_System()->Get_xTo(2, x), Get_System()->Get_yTo(2, y));
+			Lock_Set(Get_System()->Get_xTo(4, x), Get_System()->Get_yTo(4, y));
+			Lock_Set(Get_System()->Get_xTo(6, x), Get_System()->Get_yTo(6, y));
+
+			return( true );
+		}
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/Grid_Skeletonize.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Skeletonize.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Skeletonize_H
+#define HEADER_INCLUDED__Grid_Skeletonize_H
+
+//---------------------------------------------------------
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Skeletonize : public CSG_Module_Grid
+{
+public:
+	CGrid_Skeletonize(void);
+	virtual ~CGrid_Skeletonize(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	CSG_Grid				*pResult;
+
+
+	int					Get_Neighbours(int x, int y, CSG_Grid *pGrid, bool Neighbours[8]);
+
+	int					Vectorize(CSG_Shapes *pShapes);
+	bool				Vectorize_Trace(int x, int y, CSG_Shape *pShape);
+
+	void				Standard_Execute(void);
+	int					Standard_Step(int iDir, CSG_Grid *pPrev, CSG_Grid *pNext);
+	bool				Standard_Check(int iDir, bool z[8]);
+
+	void				Hilditch_Execute(void);
+	int					Hilditch_Step(CSG_Grid *pPrev, CSG_Grid *pNext, CSG_Grid *pNC_Gaps);
+	bool				Hilditch_Check(CSG_Grid *pNC_Gaps, int x, int y, int i0, bool z[8]);
+
+	void				SK_Execute(void);
+	int					SK_Connectivity(int NB[8]);
+	bool				SK_Filter(int x, int y);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Skeletonize_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,132 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Discretisation") );
+
+	case MLB_INFO_Author:
+		return( _TL("O. Conrad (c) 2002-9") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the discretisation/classification of metric gridded data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Discretisation") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Grid_Classify_Supervised.h"
+#include "Grid_Cluster_Analysis.h"
+#include "Grid_Segmentation.h"
+#include "Grid_FastSegments.h"
+#include "Grid_Skeletonize.h"
+#include "rga_basic.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CGrid_Classify_Supervised );
+	case 1:		return( new CGrid_Cluster_Analysis );
+	case 2:		return( new CGrid_Segmentation );
+	case 3:		return( new CGrid_FastSegments );
+	case 4:		return( new CGrid_Skeletonize );
+	case 5:		return( new CRGA_Basic );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_discretisation_H
+#define HEADER_INCLUDED__grid_discretisation_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_discretisation_EXPORTS
+	#define	grid_discretisation_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_discretisation_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_discretisation_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,541 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  grid_discretisation                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    rga_basic.cpp                      //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                     Benni Bechtel                     //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "rga_basic.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define	SEEDFIELD_X		2
+#define	SEEDFIELD_Y		(SEEDFIELD_X + 1)
+#define	SEEDFIELD_Z		(SEEDFIELD_X + 2)
+
+#define NO_SEGMENT		-1
+#define NO_SIMILARITY	-1.0
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CCandidates::CCandidates(void)
+{
+	m_Candidates	= NULL;
+
+	Create();
+}
+
+//---------------------------------------------------------
+CCandidates::~CCandidates(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+void CCandidates::Create(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+void CCandidates::Destroy(void)
+{
+	if( m_Candidates )
+	{
+		SG_Free(m_Candidates);
+	}
+
+	m_nBuffer		= 0;
+	m_nCandidates	= 0;
+	m_Candidates	= NULL;
+}
+
+#include <string.h>
+//---------------------------------------------------------
+void CCandidates::Add(int x, int y, int Segment, double Similarity)
+{
+	int		iInsert	= _Find(Similarity);
+
+	if( m_nCandidates >= m_nBuffer )
+	{
+		m_nBuffer		+= 32;
+		m_Candidates	= (TCandidate *)SG_Realloc(m_Candidates, m_nBuffer * sizeof(TCandidate));
+	}
+
+	memmove(m_Candidates + iInsert + 1, m_Candidates + iInsert, sizeof(TCandidate) * (m_nCandidates - iInsert));
+//	for(int i=m_nCandidates; i>iInsert; i--)
+//	{
+//		m_Candidates[i]	= m_Candidates[i - 1];
+//	}
+
+	m_nCandidates++;
+
+	m_Candidates[iInsert].x				= x;
+	m_Candidates[iInsert].y				= y;
+	m_Candidates[iInsert].Segment		= Segment;
+	m_Candidates[iInsert].Similarity	= Similarity;
+}
+
+//---------------------------------------------------------
+int CCandidates::_Find(double Similarity)
+{
+	if( m_nCandidates == 0 )
+	{
+		return( 0 );
+	}
+
+	int		a, b;
+
+	a	= 0;
+	b	= m_nCandidates - 1;
+
+	if( Similarity < m_Candidates[a].Similarity )
+	{
+		return( a );
+	}
+
+	if( Similarity > m_Candidates[b].Similarity )
+	{
+		return( b + 1 );
+	}
+
+	for(int d=(b-a)/2 ; d>0; d/=2)
+	{
+		int		i	= a + d;
+
+		if( Similarity > m_Candidates[i].Similarity )
+		{
+			a	= a < i ? i : a + 1;
+		}
+		else
+		{
+			b	= b > i ? i : b - 1;
+		}
+	}
+
+	for(int i=a; i<=b; i++)
+	{
+		if( Similarity < m_Candidates[i].Similarity )
+		{
+			return( i );
+		}
+	}
+
+	return( b );
+}
+
+/*int CCandidates::_Find(double Similarity)
+{
+	for(int i=0; i<m_nCandidates; i++)
+	{
+		if( Similarity < m_Candidates[i].Similarity )
+		{
+			return( i );
+		}
+	}
+
+	return( m_nCandidates );
+}/**/
+
+//---------------------------------------------------------
+bool CCandidates::Get(int &x, int &y, int &Segment)
+{
+	if( m_nCandidates > 0 )
+	{
+		m_nCandidates--;
+
+		x		= m_Candidates[m_nCandidates].x;
+		y		= m_Candidates[m_nCandidates].y;
+		Segment	= m_Candidates[m_nCandidates].Segment;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CRGA_Basic::CRGA_Basic(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Simple Region Growing"));
+
+	Set_Author		(SG_T("B. Bechtel, O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		"!!!UNDER DEVELOPMENT!!!\n"
+		"\n"
+		"References\n"
+		"Bechtel, B., Ringeler, A., Boehner, J. (2008): "
+		"Segmentation for Object Extraction of Trees using MATLAB and SAGA. "
+		"In: Boehner, J., Blaschke, T., Montanarella, L. [Eds.]: SAGA - Seconds Out. "
+		"Hamburger Beitraege zur Physischen Geographie und Landschaftsoekologie, 19:59-70. "
+		"<a href=\"http://downloads.sourceforge.net/saga-gis/hbpl19_01.pdf\">download</a>\n"
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "SEEDS"		, _TL("Seeds"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "FEATURES"	, _TL("Features"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SEGMENTS"	, _TL("Segments"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SIMILARITY"	, _TL("Similarity"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Seeds"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("colour and position"),
+			_TL("colour")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "NEIGHBOUR"	, _TL("Neighbourhood"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("4 (von Neumann)"),
+			_TL("8 (Moore)")
+		), 0
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_COLSPACE"	, _TL("Colour and Space Options"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "SIG_1"			, _TL("Variance in colour space"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0, 0.0, true	// 0.36
+	);
+
+	Parameters.Add_Value(
+		pNode	, "SIG_2"			, _TL("Variance in position space"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0, 0.0, true	// 8.2141
+	);
+
+	Parameters.Add_Value(
+		pNode	, "THRESHOLD"		, _TL("Threshold - similarity"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0, 0.0, true	// 0.15
+	);
+
+	Parameters.Add_Value(
+		pNode	, "REFRESH"			, _TL("Refresh"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRGA_Basic::On_Execute(void)
+{
+	bool		bRefresh;
+	int			x, y, i, n, Segment;
+	CSG_Grid	*pSeeds;
+
+	//-----------------------------------------------------
+	m_pSegments		= Parameters("SEGMENTS")	->asGrid();
+	m_pFeatures		= Parameters("FEATURES")	->asGridList();
+	m_nFeatures		= m_pFeatures->Get_Count();
+
+	pSeeds			= Parameters("SEEDS")		->asGrid();
+	m_pSeeds		= Parameters("TABLE")		->asTable();
+
+	m_pSimilarity	= Parameters("SIMILARITY")	->asGrid();
+
+	m_dNeighbour	= Parameters("NEIGHBOUR")->asInt() == 0 ? 2 : 1;
+
+	m_Var_1			= SG_Get_Square(Parameters("SIG_1")->asDouble());
+	m_Var_2			= SG_Get_Square(Parameters("SIG_2")->asDouble());
+	m_Threshold		= Parameters("THRESHOLD")	->asDouble();
+
+	m_Method		= Parameters("METHOD")		->asInt();
+	bRefresh		= Parameters("REFRESH")		->asBool();
+
+	//-----------------------------------------------------
+	m_pSegments		->Assign(-1);
+	m_pSegments		->Set_NoData_Value(-1);
+
+	m_pSimilarity	->Assign(-1);
+	m_pSimilarity	->Set_NoData_Value(-1);
+
+	//-----------------------------------------------------
+	m_pSeeds->Destroy();
+
+	m_pSeeds->Add_Field(_TL("ID")	, SG_DATATYPE_Int);
+	m_pSeeds->Add_Field(_TL("AREA")	, SG_DATATYPE_Double);
+	m_pSeeds->Add_Field(_TL("X")	, SG_DATATYPE_Double);
+	m_pSeeds->Add_Field(_TL("Y")	, SG_DATATYPE_Double);
+
+	for(i=0; i<m_pFeatures->Get_Count(); i++)
+	{
+		m_pSeeds->Add_Field(m_pFeatures->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	for(y=0, n=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pSeeds->asInt(x, y) != 0 )
+			{
+				CSG_Table_Record	*pRec	= m_pSeeds->Add_Record();
+
+				pRec->Set_Value(0, n);
+				pRec->Set_Value(SEEDFIELD_X, x);
+				pRec->Set_Value(SEEDFIELD_Y, y);
+
+				for(i=0; i<m_pFeatures->Get_Count(); i++)
+				{
+					pRec->Set_Value(SEEDFIELD_Z + i, m_pFeatures->asGrid(i)->asDouble(x, y));
+				}
+
+				m_pSimilarity->Set_Value(x, y, 1.0);
+
+				Add_To_Segment(x, y, n++);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( n > 0 )
+	{
+		n	= 0;
+
+		while( n++ < Get_NCells() && Set_Progress_NCells(n) && Get_Next_Candidate(x, y, Segment) )
+		{
+			Add_To_Segment(x, y, Segment);
+
+			if( bRefresh && (n % Get_NX()) == 0 )
+			{
+				DataObject_Update(m_pSegments, 0, m_pSeeds->Get_Record_Count());
+
+				Process_Set_Text(CSG_String::Format(SG_T("%.2f"), 100.0 * m_Candidates.Get_Count() / Get_NCells()));
+			}
+		}
+
+		m_Candidates.Destroy();
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	m_Candidates.Destroy();
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRGA_Basic::Get_Next_Candidate(int &x, int &y, int &Segment)
+{
+	while( m_Candidates.Get(x, y, Segment) )
+	{
+		if( m_pSegments->is_NoData(x, y) )
+		{
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CRGA_Basic::Add_To_Segment(int x, int y, int Segment)
+{
+	if( is_InGrid(x, y) && m_pSegments->is_NoData(x, y) )			// if the pixel is not element of any segment...
+	{
+		int		i, ix, iy;
+
+		m_pSegments->Set_Value(x, y, Segment);						// the candidate is added to the correspondig region
+	
+		for(i=0; i<8; i+=m_dNeighbour)								// update of candidate-grid - all 8-Neigbours of the added pixel are checked
+		{
+			if( Get_System()->Get_Neighbor_Pos(i, x, y, ix, iy) && m_pSegments->is_NoData(ix, iy) )
+			{
+				double	Similarity	= Get_Similarity(ix, iy, Segment);
+
+				if(	Similarity >= m_Threshold						// a neigbour-pixel is only added as candidate if its similarity is higher than the preset threshold
+				&&	Similarity > m_pSimilarity->asDouble(ix, iy) )	// and it is not candidate for another region with a higher similarity-value yet
+				{
+					m_Candidates.Add(ix, iy, Segment, Similarity);
+
+					m_pSimilarity->Set_Value(ix, iy, Similarity);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CRGA_Basic::Get_Similarity(int x, int y, int Segment)
+{
+	CSG_Table_Record	*pSeed;
+
+	if( is_InGrid(x, y) && (pSeed = m_pSeeds->Get_Record(Segment)) != NULL )
+	{
+		int		i;
+		double	a, b, Result;
+
+		switch( m_Method )
+		{
+		//-------------------------------------------------
+		case 0:	// Colour and position
+			for(i=0, a=0.0; i<m_nFeatures; i++)
+			{
+				a	+= SG_Get_Square(m_pFeatures->asGrid(i)->asDouble(x, y) - pSeed->asDouble(SEEDFIELD_Z + i));
+			}
+
+			b	= SG_Get_Square(x - pSeed->asDouble(SEEDFIELD_X))
+				+ SG_Get_Square(y - pSeed->asDouble(SEEDFIELD_Y));
+
+			Result	= a / m_Var_1 + b / m_Var_2;
+
+			break;
+
+		//-------------------------------------------------
+		case 1:	// Colour
+			for(i=0, a=0.0; i<m_nFeatures; i++)
+			{
+				a	+= SG_Get_Square(m_pFeatures->asGrid(i)->asDouble(x, y) - pSeed->asDouble(SEEDFIELD_Z + i));
+			}
+
+			Result	= a / m_Var_1;
+
+			break;
+		}
+
+		return( 1.0 / (1.0 + Result) );	// from 'distance' to 'similarity' !!!
+	//	return( exp(-0.5 * Result) );
+	}
+
+	return( -1.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_discretisation/rga_basic.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,160 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Grid                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     rga_basic.h                       //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__rga_basic_H
+#define HEADER_INCLUDED__rga_basic_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef struct SCandidate
+{
+	int						x, y, Segment;
+
+	double					Similarity;
+}
+TCandidate;
+
+//---------------------------------------------------------
+class CCandidates
+{
+public:
+	CCandidates(void);
+	~CCandidates(void);
+
+	void					Create			(void);
+	void					Destroy			(void);
+
+	void					Add				(int x, int y, int Segment, double Similarity);
+	bool					Get				(int &x, int &y, int &Segment);
+
+	int						Get_Count		(void)	{	return( m_nCandidates );	}
+
+
+private:
+
+	int						m_nCandidates, m_nBuffer;
+
+	TCandidate				*m_Candidates;
+
+
+	int						_Find			(double Similarity);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CRGA_Basic : public CSG_Module_Grid
+{
+public:
+	CRGA_Basic(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						m_Method, m_nFeatures, m_dNeighbour;
+
+	double					m_Var_1, m_Var_2, m_Threshold;
+
+	CSG_Table				*m_pSeeds;
+
+	CSG_Grid				*m_pSegments, *m_pSimilarity;
+
+	CSG_Parameter_Grid_List	*m_pFeatures;
+
+	CCandidates				m_Candidates;
+
+
+	bool					Get_Next_Candidate	(int &x, int &y, int &Segment);
+
+	bool					Add_To_Segment		(int  x, int  y, int  Segment);
+
+	double					Get_Similarity		(int  x, int  y, int  Segment);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__rga_basic_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,265 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Filter.cpp                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Filter.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFilter::CFilter(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Simple Filter"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Filter for Grids"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"		, _TL("Filtered Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Square"),
+			_TL("Circle")
+		), 1
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"		, _TL("Filter"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Smooth"),
+			_TL("Sharpen"),
+			_TL("Edge")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL, "RADIUS"		, _TL("Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CFilter::~CFilter(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter::On_Execute(void)
+{
+	int			x, y, Mode, Radius, Method;
+	double		Mean;
+	CSG_Grid	*pResult;
+
+	//-----------------------------------------------------
+	m_pInput	= Parameters("INPUT")	->asGrid();
+	pResult		= Parameters("RESULT")	->asGrid();
+	Radius		= Parameters("RADIUS")	->asInt();
+	Mode		= Parameters("MODE")	->asInt();
+	Method		= Parameters("METHOD")	->asInt();
+
+	if( !pResult || pResult == m_pInput )
+	{
+		pResult	= SG_Create_Grid(m_pInput);
+
+		Parameters("RESULT")->Set_Value(m_pInput);
+	}
+
+	pResult->Set_NoData_Value(m_pInput->Get_NoData_Value());
+
+	switch( Mode )
+	{
+	case 0:								break;
+	case 1:	m_Radius.Create(Radius);	break;
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pInput->is_InGrid(x, y) )
+			{
+				switch( Mode )
+				{
+				case 0:		Mean	= Get_Mean_Square(x, y, Radius);	break;
+				case 1:		Mean	= Get_Mean_Circle(x, y);			break;
+				}
+
+				switch( Method )
+				{
+				case 0:	default:	// Smooth...
+					pResult->Set_Value(x, y, Mean);
+					break;
+
+				case 1:				// Sharpen...
+					pResult->Set_Value(x, y, m_pInput->asDouble(x, y) + (m_pInput->asDouble(x, y) - Mean));
+					break;
+
+				case 2:				// Edge...
+					pResult->Set_Value(x, y, m_pInput->asDouble(x, y) - Mean);
+					break;
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_pInput == Parameters("RESULT")->asGrid() )
+	{
+		m_pInput->Assign(pResult);
+
+		delete(pResult);
+	}
+
+	m_Radius.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CFilter::Get_Mean_Square(int x, int y, int Radius)
+{
+	int		ix, iy, n;
+	double	s;
+
+	for(n=0, s=0.0, iy=y-Radius; iy<=y+Radius; iy++)
+	{
+		for(ix=x-Radius; ix<=x+Radius; ix++)
+		{
+			if( m_pInput->is_InGrid(ix, iy) )
+			{
+				s	+= m_pInput->asDouble(ix, iy);
+				n	++;
+			}
+		}
+	}
+
+	return( n > 0 ? s / n : m_pInput->Get_NoData_Value() );
+}
+
+//---------------------------------------------------------
+double CFilter::Get_Mean_Circle(int x, int y)
+{
+	int		i, ix, iy, n;
+	double	s;
+
+	for(n=0, s=0.0, i=0; i<m_Radius.Get_nPoints(); i++)
+	{
+		m_Radius.Get_Point(i, x, y, ix, iy);
+
+		if( m_pInput->is_InGrid(ix, iy) )
+		{
+			s	+= m_pInput->asDouble(ix, iy);
+			n	++;
+		}
+	}
+
+	return( n > 0 ? s / n : m_pInput->Get_NoData_Value() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Filter.h                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Filter_H
+#define HEADER_INCLUDED__Filter_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CFilter : public CSG_Module_Grid
+{
+public:
+	CFilter(void);
+	virtual ~CFilter(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid_Radius			m_Radius;
+
+	CSG_Grid				*m_pInput;
+
+
+	double					Get_Mean_Square	(int x, int y, int Radius);
+	double					Get_Mean_Circle	(int x, int y);
+
+};
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Filter_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,215 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Filter_3x3.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Filter_3x3.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFilter_3x3::CFilter_3x3(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("User Defined Filter (3x3)"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"User defined 3x3 sub-window filter. The filter is entered as a table with 3 rows and 3 columns."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"	, _TL("Filtered Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	//-----------------------------------------------------
+	CSG_Table	Filter;
+
+	Filter.Add_Field("1", SG_DATATYPE_Double);
+	Filter.Add_Field("2", SG_DATATYPE_Double);
+	Filter.Add_Field("3", SG_DATATYPE_Double);
+
+	Filter.Add_Record();
+	Filter[0][0]	= 0.25;
+	Filter[0][1]	= 0.5;
+	Filter[0][2]	= 0.25;
+
+	Filter.Add_Record();
+	Filter[1][0]	= 0.5;
+	Filter[1][1]	=-1.0;
+	Filter[1][2]	= 0.5;
+
+	Filter.Add_Record();
+	Filter[2][0]	= 0.25;
+	Filter[2][1]	= 0.5;
+	Filter[2][2]	= 0.25;
+
+	Parameters.Add_FixedTable(
+		NULL, "FILTER"	, _TL("Filter Matrix"),
+		_TL(""),
+		&Filter
+	);
+}
+
+//---------------------------------------------------------
+CFilter_3x3::~CFilter_3x3(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter_3x3::On_Execute(void)
+{
+	int				x, y, ix, iy, dx, dy, fx, fy, fdx, fdy;
+	double			Sum, nSum, **f;
+	CSG_Grid			*pInput, *pResult;
+	CSG_Table			*pFilter;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	pInput	= Parameters("INPUT")->asGrid();
+	pResult	= Parameters("RESULT")->asGrid();
+
+	//-----------------------------------------------------
+	pFilter	= Parameters("FILTER")->asTable();
+
+	fdx		= pFilter->Get_Field_Count();
+	fdy		= pFilter->Get_Record_Count();
+	dx		= (fdx - 1) / 2;
+	dy		= (fdy - 1) / 2;
+
+	f		= (double **)SG_Malloc(fdy * sizeof(double *));
+	f[0]	= (double  *)SG_Malloc(fdy * fdx * sizeof(double));
+
+	for(fy=0; fy<fdy; fy++)
+	{
+		f[fy]	= f[0] + fy * fdx;
+
+		pRecord	= pFilter->Get_Record(fy);
+
+		for(fx=0; fx<fdx; fx++)
+		{
+			f[fy][fx]	= pRecord->asDouble(fx);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Sum		= nSum	= 0.0;
+
+			for(fy=0, iy=y-dy; fy<fdy; fy++, iy++)
+			{
+				for(fx=0, ix=x-dx; fx<fdx; fx++, ix++)
+				{
+					if( pInput->is_InGrid(ix, iy) )
+					{
+						Sum		+= f[fy][fx] * pInput->asDouble(ix, iy);
+						nSum	+= fabs(f[fy][fx]);
+					}
+				}
+			}
+
+			if( nSum > 0.0 )
+			{
+				pResult->Set_Value(x, y, Sum / nSum);
+			}
+			else
+			{
+				pResult->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(f[0]);
+	SG_Free(f);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_3x3.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,96 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Filter_3x3.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Filter_3x3_H
+#define HEADER_INCLUDED__Filter_3x3_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFilter_3x3 : public CSG_Module_Grid  
+{
+public:
+	CFilter_3x3(void);
+	virtual ~CFilter_3x3(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Filter_3x3_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,280 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Filter_Gauss.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Filter_Gauss.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFilter_Gauss::CFilter_Gauss(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Gaussian Filter"));
+
+	Set_Author(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+
+	Set_Description	(_TW(
+		"The Gauss Filter is a smoothing operator that is used to `blur' or 'soften' Grid Data\n"
+		"and remove detail and noise.\n"
+		"The degree of smoothing is determined by the standard deviation.\n"
+		"For higher standard deviations you need a greater Radius\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"		, _TL("Filtered Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL, "SIGMA"		, _TL("Standard Deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1, 0.0001, true
+	);
+
+	Parameters.Add_Choice(
+		NULL, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Square"),
+			_TL("Circle")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL, "RADIUS"		, _TL("Search Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 2, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CFilter_Gauss::~CFilter_Gauss(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter_Gauss::On_Execute(void)
+{
+	int			x, y, Mode, Radius;
+	double		Sigma;
+	CSG_Grid	*pResult;
+
+	//-----------------------------------------------------
+	m_pInput	= Parameters("INPUT")	->asGrid();
+	pResult		= Parameters("RESULT")	->asGrid();
+	Radius		= Parameters("RADIUS")	->asInt();
+	Mode		= Parameters("MODE")	->asInt();
+	Sigma		= Parameters("SIGMA")	->asDouble();
+
+	if( !pResult || pResult == m_pInput )
+	{
+		pResult	= SG_Create_Grid(m_pInput);
+
+		Parameters("RESULT")->Set_Value(m_pInput);
+	}
+
+	pResult->Set_NoData_Value(m_pInput->Get_NoData_Value());
+
+	//-----------------------------------------------------
+	if( Initialise(Radius, Sigma, Mode) )
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( m_pInput->is_InGrid(x, y) )
+				{
+					pResult->Set_Value(x, y, Get_Mean(x, y));
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_pInput == Parameters("RESULT")->asGrid() )
+		{
+			m_pInput->Assign(pResult);
+
+			delete(pResult);
+		}
+
+		m_Weights.Destroy();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CFilter_Gauss::Initialise(int Radius, double Sigma, int Mode)
+{
+	int		x, y;
+	double	dx, dy, val, min, max;
+
+	//-----------------------------------------------------
+	m_Weights.Create(SG_DATATYPE_Double, 1 + 2 * Radius, 1 + 2 * Radius);
+
+	//-----------------------------------------------------
+	for(y=0, dy=-Radius, min=1.0, max=0.0; y<m_Weights.Get_NY(); y++, dy++)
+	{
+		for(x=0, dx=-Radius; x<m_Weights.Get_NX(); x++, dx++)
+		{
+			switch( Mode )
+			{
+			case 1:
+				val	= sqrt(dx*dx + dy*dy) > Radius
+					? 0.0
+					: exp(-(dx*dx + dy*dy) / (2.0 * Sigma*Sigma)) / (M_PI * 2.0 * Sigma*Sigma);
+				break;
+
+			case 0:
+				val	= exp(-(dx*dx + dy*dy) / (2.0 * Sigma*Sigma)) / (M_PI * 2.0 * Sigma*Sigma);
+				break;
+			}
+
+			m_Weights.Set_Value(x, y, val);
+
+			if( min > max )
+			{
+				min	= max	= val;
+			}
+			else if( val < min )
+			{
+				min	= val;
+			}
+			else if( val > max )
+			{
+				max	= val;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( max == 0.0 )
+	{
+		Message_Dlg(_TL("Radius is too small"));
+	}
+	else if( min / max > 0.367 / 2.0 )
+	{
+		Message_Dlg(_TL("Radius is too small for your Standard Deviation"), Get_Name());
+	}
+	else
+	{
+		return( true );
+	}
+
+	m_Weights.Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CFilter_Gauss::Get_Mean(int x, int y)
+{
+	int		ix, iy, jx, jy;
+	double	s, n, w;
+
+	for(n=0.0, s=0.0, jy=0, iy=y-(m_Weights.Get_NY()-1)/2; jy<m_Weights.Get_NY(); jy++, iy++)
+	{
+		for(jx=0, ix=x-(m_Weights.Get_NX()-1)/2; jx<m_Weights.Get_NX(); jx++, ix++)
+		{
+			if( (w = m_Weights.asDouble(jx, jy)) > 0.0 && m_pInput->is_InGrid(ix, iy) )
+			{
+				s	+= w * m_pInput->asDouble(ix, iy);
+				n	+= w;
+			}
+		}
+	}
+
+	return( n > 0.0 ? s / n : m_pInput->Get_NoData_Value() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Gauss.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Filter_Gauss.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at saga-gis.org                   //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Filter_Gauss_H
+#define HEADER_INCLUDED__Filter_Gauss_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CFilter_Gauss : public CSG_Module_Grid
+{
+public:
+	CFilter_Gauss(void);
+	virtual ~CFilter_Gauss(void);
+	
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+	CSG_Grid			*m_pInput, m_Weights;
+
+
+	bool				Initialise			(int Radius, double Sigma, int Mode);
+
+	double				Get_Mean			(int x, int y);
+
+};
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Filter_Gauss_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,327 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Filter_LoG.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Filter_LoG.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFilter_LoG::CFilter_LoG(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Laplacian Filter"));
+
+	Set_Author		(SG_T("(c) 2003 by A. Ringeler, (c) 2008 by O. Conrad"));
+
+	Set_Description	(_TW(
+		 "Other Common Names: Laplacian, Laplacian of Gaussian, LoG, Marr Filter\n"
+		 "\n"
+		 "Standard kernel 1 (3x3):\n"
+		 " 0 | -1 |  0\n"
+		 "-1 |  4 | -1\n"
+		 " 0 | -1 |  0\n"
+		 "\n"
+		 "Standard kernel 2 (3x3):\n"
+		 "-1 | -1 | -1\n"
+		 "-1 |  8 | -1\n"
+		 " 0 | -1 |  0\n"
+		 "\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Filtered Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Standard Kernel 1"),
+			_TL("Standard Kernel 2"),
+			_TL("User defined")
+		), 2
+	);
+
+	CSG_Parameter	*pNode	= Parameters.Add_Node(NULL, "NODE_USER", _TL("User defined"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "SIGMA"		, _TL("Standard Deviation (Percent of Radius)"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 50.0, 0.00001, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "RADIUS"		, _TL("Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 3, 1, true
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Square"),
+			_TL("Circle")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CFilter_LoG::~CFilter_LoG(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter_LoG::On_Execute(void)
+{
+	int			Radius;
+	CSG_Grid	*pResult;
+
+	//-----------------------------------------------------
+	m_pInput	= Parameters("INPUT")	->asGrid();
+	pResult		= Parameters("RESULT")	->asGrid();
+	Radius		= Parameters("RADIUS")	->asInt();
+
+	//-----------------------------------------------------
+	if( Initialise(Parameters("METHOD")->asInt(), Radius, Parameters("SIGMA")->asDouble(), Parameters("MODE")->asInt() == 1) )
+	{
+		if( !pResult || pResult == m_pInput )
+		{
+			pResult	= SG_Create_Grid(m_pInput);
+		}
+
+		DataObject_Set_Colors(pResult, 100, SG_COLORS_BLACK_WHITE);
+
+		//-------------------------------------------------
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( m_pInput->is_InGrid(x, y) )
+				{
+					pResult->Set_Value(x, y, Get_Mean(x, y, Radius));
+				}
+				else
+				{
+					pResult->Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( !Parameters("RESULT")->asGrid() || Parameters("RESULT")->asGrid() == m_pInput )
+		{
+			m_pInput->Assign(pResult);
+
+			delete(pResult);
+		}
+
+		m_Kernel.Destroy();
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter_LoG::Initialise(int Method, int &Radius, double Sigma, bool bCircle)
+{
+	switch( Method )
+	{
+	case 0:
+		m_Kernel.Create(SG_DATATYPE_Double, 3, 3);
+		m_Kernel.Set_Value(0, 0,  0);	m_Kernel.Set_Value(0, 1, -1);	m_Kernel.Set_Value(0, 2,  0);
+		m_Kernel.Set_Value(1, 0, -1);	m_Kernel.Set_Value(1, 1,  4);	m_Kernel.Set_Value(1, 2, -1);
+		m_Kernel.Set_Value(2, 0,  0);	m_Kernel.Set_Value(2, 1, -1);	m_Kernel.Set_Value(2, 2,  0);
+		Radius	= 1;
+		return( true );
+
+	case 1:
+		m_Kernel.Create(SG_DATATYPE_Double, 3, 3);
+		m_Kernel.Set_Value(0, 0, -1);	m_Kernel.Set_Value(0, 1, -1);	m_Kernel.Set_Value(0, 2, -1);
+		m_Kernel.Set_Value(1, 0, -1);	m_Kernel.Set_Value(1, 1,  8);	m_Kernel.Set_Value(1, 2, -1);
+		m_Kernel.Set_Value(2, 0, -1);	m_Kernel.Set_Value(2, 1, -1);	m_Kernel.Set_Value(2, 2, -1);
+		Radius	= 1;
+		return( true );
+
+	case 2:	default:
+		if( Sigma > 0.0 )
+		{
+			m_Kernel.Create(SG_DATATYPE_Double, 1 + 2 * Radius, 1 + 2 * Radius);
+
+			Sigma	= SG_Get_Square(Radius * Sigma * 0.01);
+
+		//	double	min		= 999999;
+		//	double	max		= 0;
+
+			for(int y=-Radius, iy=0; y<=Radius; y++, iy++)
+			{
+				for(int x=-Radius, ix=0; x<=Radius; x++, ix++)
+				{
+					double	d	= x * x + y * y;
+
+					if( bCircle && d > Radius*Radius )
+					{
+						d	= 0.0;
+					}
+					else
+					{
+						d	= 1.0 / (M_PI * Sigma*Sigma) * (1.0 - d / (2.0 * Sigma)) * exp(-d / (2.0 * Sigma));
+					}
+
+					m_Kernel.Set_Value(ix, iy, d);
+
+		//			if( min > k )	min	= k;
+		//			if( max < k )	max	= k;
+				}
+			}
+
+		//	this->DataObject_Add(SG_Create_Grid(m_Kernel));
+
+			m_Kernel	+= -m_Kernel.Get_ArithMean();
+
+		//	if( min / max > 0.367 / 2.0 )
+		//	{
+		//		Message_Add("Warning: Radius is to small for your Standard Deviation");
+		//		return( false );
+		//	}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CFilter_LoG::Get_Mean(int x, int y, int Radius)
+{
+	double	s, n, k;
+
+	//-----------------------------------------------------
+	s	= 0.0;
+	n	= 0.0;
+
+	//-----------------------------------------------------
+	for(int ky=0, iy=y-Radius; ky<m_Kernel.Get_NY(); ky++, iy++)
+	{
+		for(int kx=0, ix=x-Radius; kx<m_Kernel.Get_NX(); kx++, ix++)
+		{
+			if( m_pInput->is_InGrid(ix, iy) && (k = m_Kernel.asDouble(kx, ky)) != 0.0 )
+			{
+				s	+= k * m_pInput->asDouble(ix, iy);
+				n	+= fabs(k);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( n > 0.0 ? s / n : 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_LoG.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Filter_LoG.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at saga-gis.org                   //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Filter_LoG_H
+#define HEADER_INCLUDED__Filter_LoG_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFilter_LoG : public CSG_Module_Grid
+{
+public:
+	CFilter_LoG(void);
+	virtual ~CFilter_LoG(void);
+	
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	CSG_Grid			*m_pInput, m_Kernel;
+
+
+	bool				Initialise		(int Method, int &Radius, double Sigma, bool bCircle);
+	
+	double				Get_Mean		(int x, int y, int Radius);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Filter_LoG_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,553 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Filter_Multi_Dir_Lee.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+#include "Filter_Multi_Dir_Lee.h"
+
+
+double Filter_Directions[16][9][9]	=
+{
+	{
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5},
+		{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
+		{0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
+	},
+		
+	{
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{1.0, 1.0, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0, 0.0},
+		{0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.5},
+		{0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 1.0, 1.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
+	},
+		
+	{
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{1.0, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.5, 0.5, 1.0, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.5, 0.5, 1.0, 0.5, 0.5, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 0.5, 0.5},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
+	},
+		
+	{
+		{0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.5, 1.0, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.5, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.5, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 0.5},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5}
+	},
+		
+	{
+		{1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0}
+	},
+		
+	{
+		{0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5}
+	},
+		
+	{
+		{0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0}
+	},
+		
+	{
+		{0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0}
+	},
+		
+	{
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0},
+		{0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0}
+	}
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFilter_Multi_Dir_Lee::CFilter_Multi_Dir_Lee(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Multi Direction Lee Filter"));
+
+	Set_Author(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+
+	Set_Description	(_TW(
+		"This Multi Direction Lee Filter is a enhanced Lee Filter\n"
+		"It looks into 16 directions for the direction with the minium variance\n"
+		"and applied a Lee Filter on this direction.\n\n"
+		"Uses this filter for remove speckle noise in SAR images or DTMs.\n"
+		"On DTMs this filter will preserves the slope and  narrow valleys. \n\n"
+		"For details on the Lee Filter, see the article by Jong-Sen Lee:\n"
+		"\"Digital Image Enhancement and Noise Filtering by Use of Local Statistics\",\n"
+		"IEEE Transactions on Pattern Analysis and Machine Intelligence,\n"
+		"Volume PAMI-2, Number 2, pages 165-168, March 1980.\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"		, _TL("Filtered Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "STDDEV"		, _TL("Minimum Standard Deviation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "DIR"			, _TL("Direction of Minimum Standard Deviation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL, "NOISE_ABS"	, _TL("Estimated Noise (absolute)"),
+		_TL("Estimated noise in units of input data"),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL, "NOISE_REL"	, _TL("Estimated Noise (relative)"),
+		_TL("Estimated noise relative to mean standard deviation"),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL, "WEIGHTED"	, _TL("Weighted"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("noise variance given as absolute value"),
+			_TL("noise variance given relative to mean standard deviation"),
+			_TL("original calculation (Ringeler)")
+		), 1
+	);
+
+	//-----------------------------------------------------
+	for(int i=1; i<8; i++)	// Mirror the last 8  filter directions
+	{
+		for(int y=0; y<9; y++)
+		{
+			for(int x=0; x<9; x++)
+			{
+				Filter_Directions[i + 8][y][x] = Filter_Directions[i][y][8 - x];
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter_Multi_Dir_Lee::On_Execute(void)
+{
+	bool	bResult	= false, bWeighted;
+
+	m_pInput		= Parameters("INPUT")		->asGrid();
+	m_pFiltered		= Parameters("RESULT")		->asGrid();
+	m_pStdDev		= Parameters("STDDEV")		->asGrid();
+	m_pDirection	= Parameters("DIR")			->asGrid();
+	bWeighted		= Parameters("WEIGHTED")	->asBool();
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:	bResult	= Get_Filter(bWeighted, true);	break;
+	case 1:	bResult	= Get_Filter(bWeighted, false);	break;
+	case 2:	bResult	= Get_Filter_Ringeler();		break;
+	}
+
+	m_pFiltered->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pInput->Get_Name(), _TL("Lee Filter")));
+
+	if( m_pStdDev )
+	{
+		m_pStdDev		->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pInput->Get_Name(), _TL("Lee Filter - Standard Deviation")));
+	}
+
+	if( m_pDirection )
+	{
+		m_pDirection	->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pInput->Get_Name(), _TL("Lee Filter - Direction")));
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFilter_Multi_Dir_Lee::Get_Filter(bool bWeighted, bool bAbsolute)
+{
+	int		x, y, ix, iy, k, kx, ky, Best_Direction;
+	double	Count, Mean, StdDev, Variance, Best_Mean, Best_StdDev, Noise, Noise2;
+
+	if( bAbsolute )
+	{
+		Noise	= Parameters("NOISE_ABS")->asDouble();
+		Noise2	= Noise*Noise;
+	}
+	else if( m_pStdDev == NULL )
+	{
+		Parameters("STDDEV")->Set_Value(m_pStdDev = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float));
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pInput->is_NoData(x, y) )
+			{
+				m_pFiltered	->Set_NoData(x, y);
+				m_pStdDev	->Set_NoData(x, y);
+
+				if( m_pDirection )	m_pDirection	->Set_NoData(x, y);
+			}
+			else
+			{
+				//-----------------------------------------
+				for(k=0; k<16; k++)
+				{
+					Variance	= Mean	= Count	= 0;
+
+					for(ky=0, iy=y-4; ky<9; iy++, ky++)
+					{
+						for(kx=0, ix=x-4; kx<9; ix++, kx++)
+						{
+							if( m_pInput->is_InGrid(ix, iy) && Filter_Directions[k][ky][kx] > 0.0 )
+							{
+								double	w	 = bWeighted ? Filter_Directions[k][ky][kx] : 1.0;
+								double	z	 = m_pInput->asDouble(ix, iy);
+								Mean		+= w * z;
+								Variance	+= w * z*z;
+								Count		+= w;
+							}
+						}
+					}
+
+					Mean		= Mean     / Count;
+					Variance	= Variance / Count - Mean*Mean;
+					StdDev		= sqrt(Variance);
+
+					if( k == 0 || StdDev < Best_StdDev )
+					{
+						Best_StdDev		= StdDev;
+						Best_Mean		= Mean;
+						Best_Direction	= k;
+					}
+				}
+
+				//-----------------------------------------
+				if( bAbsolute && Best_StdDev > Noise )
+				{
+					double	b	= Best_StdDev*Best_StdDev;
+
+					b	= (b - Noise2) / b;
+
+					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y) * b + (1.0 - b) * Best_Mean); 
+				}
+				else if( Best_StdDev > 0.0 )
+				{
+					m_pFiltered->Set_Value(x, y, Best_Mean);
+				}
+				else
+				{
+					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y));
+				}
+
+				if( m_pStdDev )		m_pStdDev		->Set_Value(x, y, Best_StdDev);
+				if( m_pDirection )	m_pDirection	->Set_Value(x, y, Best_Direction);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( !bAbsolute )
+	{
+		Noise	= Parameters("NOISE_REL")->asDouble() * m_pStdDev->Get_ArithMean();
+		Noise2	= Noise*Noise;
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !m_pInput->is_NoData(x, y) && (Best_StdDev = m_pStdDev->asDouble(x, y)) > Noise )
+				{
+					double	b	= Best_StdDev*Best_StdDev;
+
+					b	= (b - Noise2) / b;
+
+					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y) * b + (1.0 - b) * m_pFiltered->asDouble(x, y));
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const double corr_norm	= 109699939.0;
+
+const double corr[16]	=
+{
+	 97694238.970824,
+	103389994.176977,
+	109699939.129502,
+	103392028.763373,
+	103392435.589500,
+	103392028.763371,
+	109699939.129499,
+	103389994.176979,
+	 97694238.970826,
+	103389994.200091,
+	109699939.176253,
+	103392028.826671,
+	103392435.659830,
+	103392028.826669,
+	109699939.176251,
+	103389994.200092
+};
+
+//---------------------------------------------------------
+bool CFilter_Multi_Dir_Lee::Get_Filter_Ringeler(void)
+{
+	int			x, y, ix, iy, k, kx, ky, Count, Best_Direction;
+	double		Mean, StdDev, Variance, Best_Mean, Best_StdDev, Noise, Noise2;
+
+	Noise	= Parameters("NOISE_ABS")->asDouble();
+	Noise2	= Noise*Noise;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pInput->is_NoData(x, y) )
+			{
+				m_pFiltered->Set_NoData(x, y);
+
+				if( m_pDirection )	m_pDirection	->Set_NoData(x, y);
+				if( m_pStdDev )		m_pStdDev		->Set_NoData(x, y);
+			}
+			else
+			{
+				//-----------------------------------------
+				for(k=0; k<16; k++)
+				{
+					Variance	= Mean	= Count	= 0;
+
+					for(ky=0, iy=y-4; ky<9; iy++, ky++)
+					{
+						for(kx=0, ix=x-4; kx<9; ix++, kx++)
+						{
+							if( m_pInput->is_InGrid(ix, iy) && Filter_Directions[k][ky][kx] > 0.0 )
+							{
+								Mean		+= m_pInput->asDouble(ix, iy);
+								Count		++;
+							}
+						}
+					}
+
+					Mean		= Mean     / Count;
+
+					for(ky=0, iy=y-4; ky<9; iy++, ky++)
+					{
+						for(kx=0, ix=x-4; kx<9; ix++, kx++)
+						{
+							if( m_pInput->is_InGrid(ix, iy) && Filter_Directions[k][ky][kx] > 0.0 )
+							{
+								Variance	+= M_SQR(Mean - m_pInput->asDouble(ix, iy));
+							}
+						}
+					}
+
+					StdDev		= corr_norm * sqrt(Variance) / (corr[k] * Count);
+
+					if( k == 0 || StdDev < Best_StdDev )
+					{
+						Best_StdDev		= StdDev;
+						Best_Mean		= Mean;
+						Best_Direction	= k;
+					}
+				}
+
+				//-----------------------------------------
+				if( Best_StdDev > Noise )
+				{
+					double	b	= Best_StdDev*Best_StdDev;
+
+					b	= (b - Noise2) / b;
+
+					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y) * b + (1.0 - b) * Best_Mean); 
+				}
+				else if( Best_StdDev > 0.0 )
+				{
+					m_pFiltered->Set_Value(x, y, Best_Mean);
+				}
+				else
+				{
+					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y));
+				}
+
+				if( m_pDirection )	m_pDirection	->Set_Value(x, y, Best_Direction);
+				if( m_pStdDev )		m_pStdDev		->Set_Value(x, y, Best_StdDev);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/Filter_Multi_Dir_Lee.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,105 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Filter_Multi_Dir_Lee.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at saga-gis.org                   //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Filter_Multi_Dir_Lee_H
+#define HEADER_INCLUDED__Filter_Multi_Dir_Lee_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFilter_Multi_Dir_Lee : public CSG_Module_Grid
+{
+public:
+	CFilter_Multi_Dir_Lee(void);
+
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+	CSG_Grid			*m_pInput, *m_pFiltered, *m_pStdDev, *m_pDirection;
+
+
+	bool				Get_Filter			(bool bWeighted, bool bAbsolute);
+
+	bool				Get_Filter_Ringeler	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Filter_Multi_Dir_Lee_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,159 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//               SAGA User Group Associaton              //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Filter") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the manipulation of gridded data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Filter") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Filter.h"
+#include "Filter_Gauss.h"
+#include "Filter_LoG.h"
+#include "Filter_Multi_Dir_Lee.h"
+#include "Filter_3x3.h"
+#include "FilterClumps.h"
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CFilter;
+		break;
+
+	case 1:
+		pModule	= new CFilter_Gauss;
+		break;
+
+	case 2:
+		pModule	= new CFilter_LoG;
+		break;
+
+	case 3:
+		pModule	= new CFilter_Multi_Dir_Lee;
+		break;
+
+	case 4:
+		pModule	= new CFilter_3x3;
+		break;
+
+	case 5:
+		pModule	= new CFilterClumps;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_filter/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Filter                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_filter_H
+#define HEADER_INCLUDED__grid_filter_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_filter_EXPORTS
+	#define	grid_filter_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_filter_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_filter_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,333 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Interpolation.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CInterpolation::CInterpolation(void)
+{
+	CSG_Parameter	*pNode;
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"		, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TARGET"		, _TL("Target Grid"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("user defined"),
+			_TL("grid system"),
+			_TL("grid")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("USER", _TL("User defined grid")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL	, "CELL_SIZE"	, _TL("Grid Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	pNode	= pParameters->Add_Value(
+		NULL	, "FIT_EXTENT"	, _TL("Fit Extent"),
+		_TL("Automatically fits the grid to the shapes layers extent."),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	pParameters->Add_Range(
+		pNode	, "X_EXTENT"	, _TL("X-Extent"),
+		_TL("")
+	);
+
+	pParameters->Add_Range(
+		pNode	, "Y_EXTENT"	, _TL("Y-Extent"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("SYSTEM"	, _TL("Choose Grid System")	, _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GRID"	, _TL("Choose Grid")		, _TL(""));
+
+	pParameters->Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT	, false
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	//-----------------------------------------------------
+	m_pShapes	= Parameters("SHAPES")	->asShapes();
+	m_zField	= Parameters("FIELD")	->asInt();
+
+	//-----------------------------------------------------
+	if( _Get_Grid() )
+	{
+		bResult	= Interpolate();
+	}
+
+	//-----------------------------------------------------
+	m_Search.Destroy();
+
+	if( m_pShapes != Parameters("SHAPES")->asShapes() )
+	{
+		delete(m_pShapes);
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CInterpolation::Interpolate(void)
+{
+	if( On_Initialize() )
+	{
+		int		ix, iy;
+		double	 x,  y, z;
+
+		for(iy=0, y=m_pGrid->Get_YMin(); iy<m_pGrid->Get_NY() && Set_Progress(iy, m_pGrid->Get_NY()); iy++, y+=m_pGrid->Get_Cellsize())
+		{
+			for(ix=0, x=m_pGrid->Get_XMin(); ix<m_pGrid->Get_NX(); ix++, x+=m_pGrid->Get_Cellsize())
+			{
+				if( Get_Value(x, y, z) )
+				{
+					m_pGrid->Set_Value(ix, iy, z);
+				}
+				else
+				{
+					m_pGrid->Set_NoData(ix, iy);
+				}
+			}
+		}
+
+		On_Finalize();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes * CInterpolation::Get_Points(void)
+{
+	m_pShapes	= Parameters("SHAPES")	->asShapes();
+
+	if( m_pShapes->Get_Type() != SHAPE_TYPE_Point )
+	{
+		CSG_Shapes	*pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, _TL(""), m_pShapes);
+
+		for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape	= m_pShapes->Get_Shape(iShape);
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					CSG_Shape	*pPoint	= pPoints->Add_Shape(pShape, SHAPE_COPY_ATTR);
+
+					pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));
+				}
+			}
+		}
+
+		m_pShapes	= pPoints;
+	}
+
+	return( m_pShapes );
+}
+
+//---------------------------------------------------------
+bool CInterpolation::Set_Search_Engine(void)
+{
+	return( m_Search.Create(m_pShapes, m_zField) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation::_Get_Grid(void)
+{
+	CSG_Shapes	*pShapes;
+	
+	pShapes	= Parameters("SHAPES")->asShapes();
+	m_pGrid	= NULL;
+
+	//-------------------------------------------------
+	switch( Parameters("TARGET")->asInt() )
+	{
+	case 0:	// user defined...
+		if( Dlg_Parameters("USER") )
+		{
+			m_pGrid	= _Get_Grid(pShapes->Get_Extent());
+		}
+		break;
+
+	case 1:	// grid system...
+		if( Dlg_Parameters("SYSTEM") )
+		{
+			m_pGrid	= SG_Create_Grid(*Get_Parameters("SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(), SG_DATATYPE_Float);
+		}
+		break;
+
+	case 2:	// grid...
+		if( Dlg_Parameters("GRID") )
+		{
+			m_pGrid	= Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid();
+		}
+		break;
+	}
+
+	//-------------------------------------------------
+	if( m_pGrid )
+	{
+		m_pGrid->Set_Name(CSG_String::Format(SG_T("%s (%s)"), pShapes->Get_Name(), Get_Name()));
+		Parameters("GRID")->Set_Value(m_pGrid);
+	}
+
+	//-----------------------------------------------------
+	return( m_pGrid != NULL );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CInterpolation::_Get_Grid(TSG_Rect Extent)
+{
+	CSG_Parameters	*P	= Get_Parameters("USER");
+
+	if( !P->Get_Parameter("FIT_EXTENT")->asBool() )
+	{
+		Extent.xMin	= P->Get_Parameter("X_EXTENT")->asRange()->Get_LoVal();
+		Extent.yMin	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_LoVal();
+		Extent.xMax	= P->Get_Parameter("X_EXTENT")->asRange()->Get_HiVal();
+		Extent.yMax	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_HiVal();
+	}
+
+	double	d	= P->Get_Parameter("CELL_SIZE")->asDouble();
+
+	int		nx	= 1 + (int)((Extent.xMax - Extent.xMin) / d);
+	int		ny	= 1 + (int)((Extent.yMax - Extent.yMin) / d);
+
+	return( nx > 1 && ny > 1 ? SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.xMin, Extent.yMin) : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,130 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Interpolation.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Interpolation_H
+#define HEADER_INCLUDED__Interpolation_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CInterpolation : public CSG_Module
+{
+public:
+	CInterpolation(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Interpolation from Points") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+	int						m_zField;
+
+	CSG_PRQuadTree			m_Search;
+
+	CSG_Grid				*m_pGrid;
+
+	CSG_Shapes				*m_pShapes;
+
+
+	virtual bool			Interpolate			(void);
+
+	virtual bool			On_Initialize		(void)							{	return( true );	}
+	virtual bool			On_Finalize			(void)							{	return( true );	}
+
+	virtual bool			Get_Value			(double x, double y, double &z)	{	return( true );	}
+
+	CSG_Shapes *			Get_Points			(void);
+	bool					Set_Search_Engine	(void);
+
+
+private:
+
+	bool					_Get_Grid			(void);
+	CSG_Grid *				_Get_Grid			(TSG_Rect Extent);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Interpolation_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,176 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//           Interpolation_InverseDistance.cpp           //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation_InverseDistance.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CInterpolation_InverseDistance::CInterpolation_InverseDistance(void)
+{
+	Set_Name		(_TL("Inverse Distance"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2003"));
+
+	Set_Description	(_TW(
+		"Inverse distance to a power method for grid interpolation from irregular distributed points."
+	));
+
+	Parameters.Add_Value(
+		NULL	, "POWER"		, _TL("Inverse Distance: Power"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "RADIUS"		, _TL("Search Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NPOINTS"		, _TL("Maximum Points"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 10.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("all directions"),
+			_TL("quadrants")
+		)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation_InverseDistance::On_Initialize(void)
+{
+	m_Power			= Parameters("POWER")	->asDouble();
+	m_Radius		= Parameters("RADIUS")	->asDouble();
+	m_nPoints_Max	= Parameters("NPOINTS")	->asInt();
+	m_Mode			= Parameters("MODE")	->asInt();
+
+	return( Set_Search_Engine() );
+}
+
+//---------------------------------------------------------
+bool CInterpolation_InverseDistance::Get_Value(double x, double y, double &z)
+{
+	int			i, n;
+	double		ix, iy, iz, d, w;
+
+	switch( m_Mode )
+	{
+	case 0:	n	= m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius);	break;
+	case 1:	n	= m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius, 4);	break;
+	}
+
+	for(i=0, z=0.0, w=0.0; i<n; i++)
+	{
+		if( m_Search.Get_Selected_Point(i, ix, iy, iz) )
+		{
+			d	= SG_Get_Distance(x, y, ix, iy);
+
+			if( d <= 0.0 )
+			{
+				z	= iz;
+
+				return( true );
+			}
+
+			d	= pow(d, -m_Power);
+
+			z	+= d * iz;
+			w	+= d;
+		}
+	}
+
+	if( w > 0.0 )
+	{
+		z	/= w;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_InverseDistance.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//            Interpolation_InverseDistance.h            //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			Interpolation_InverseDistance.h				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Interpolation_InverseDistance_H
+#define HEADER_INCLUDED__Interpolation_InverseDistance_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CInterpolation_InverseDistance : public CInterpolation  
+{
+public:
+	CInterpolation_InverseDistance(void);
+
+
+protected:
+
+	virtual bool			On_Initialize		(void);
+
+	virtual bool			Get_Value			(double x, double y, double &z);
+
+
+private:
+
+	int						m_nPoints_Max, m_Mode;
+
+	double					m_Power, m_Radius;
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Interpolation_InverseDistance_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,191 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//          Interpolation_NaturalNeighbour.cpp           //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation_NaturalNeighbour.h"
+
+#include "nn/nn.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CInterpolation_NaturalNeighbour::CInterpolation_NaturalNeighbour(void)
+{
+	Set_Name		(_TL("Natural Neighbour"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		"Natural Neighbour method for grid interpolation from irregular distributed points.")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "SIBSON"	, _TL("Sibson"),
+		_TL(""),
+		PARAMETER_TYPE_Bool	, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation_NaturalNeighbour::Interpolate(void)
+{
+	int			i, x, y;
+	double		zMin, zMax;
+	TSG_Point	p;
+
+	nn_rule		= Parameters("SIBSON")->asBool() ? SIBSON : NON_SIBSONIAN;
+
+	//-----------------------------------------------------
+	point	*pSrc	= (point  *)SG_Malloc(m_pShapes->Get_Count() * sizeof(point));
+	double	*zSrc	= (double *)SG_Malloc(m_pShapes->Get_Count() * sizeof(double));
+
+	for(i=0; i<m_pShapes->Get_Count() && Set_Progress(i, m_pShapes->Get_Count()); i++)
+	{
+		CSG_Shape	*pShape	= m_pShapes->Get_Shape(i);
+
+		pSrc[i].x	= pShape->Get_Point(0).x;
+		pSrc[i].y	= pShape->Get_Point(0).y;
+		pSrc[i].z	= zSrc[i]	= pShape->asDouble(m_zField);
+
+		if( i == 0 )
+			zMin	= zMax	= pSrc[i].z;
+		else if( zMin > pSrc[i].z )
+			zMin	= pSrc[i].z;
+		else if( zMax < pSrc[i].z )
+			zMax	= pSrc[i].z;
+	}
+
+	Process_Set_Text(_TL("triangulating"));
+	delaunay	*pTIN	= delaunay_build(m_pShapes->Get_Count(), pSrc, 0, NULL, 0, NULL);
+
+	//-----------------------------------------------------
+	double	*xDst	= (double *)SG_Malloc(m_pGrid->Get_NCells() * sizeof(double));
+	double	*yDst	= (double *)SG_Malloc(m_pGrid->Get_NCells() * sizeof(double));
+	double	*zDst	= (double *)SG_Malloc(m_pGrid->Get_NCells() * sizeof(double));
+
+	for(y=0, i=0, p.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, p.y+=m_pGrid->Get_Cellsize())
+	{
+		for(x=0, p.x=m_pGrid->Get_XMin(); x<m_pGrid->Get_NX(); x++, p.x+=m_pGrid->Get_Cellsize(), i++)
+		{
+			xDst[i]	= p.x;
+			yDst[i]	= p.y;
+			zDst[i]	= NaN;
+		}
+	}
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("creating interpolator"));
+	nnai	*pNN	= nnai_build(pTIN, m_pGrid->Get_NCells(), xDst, yDst);
+
+    Process_Set_Text(_TL("interpolating"));
+    nnai_interpolate(pNN, zSrc, zDst);
+
+	//-----------------------------------------------------
+	for(y=0, i=0; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++)
+	{
+		for(x=0; x<m_pGrid->Get_NX(); x++, i++)
+		{
+			double	z	= zDst[i];
+
+			if( zMin <= z && z <= zMax )
+			{
+				m_pGrid->Set_Value(x, y, z);
+			}
+			else
+			{
+				m_pGrid->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	nnai_destroy(pNN);
+
+	delaunay_destroy(pTIN);
+
+	SG_Free(xDst);
+	SG_Free(yDst);
+	SG_Free(zDst);
+	SG_Free(zSrc);
+	SG_Free(pSrc);
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NaturalNeighbour.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//           Interpolation_NaturalNeighbour.h            //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			Interpolation_NaturalNeighbour.h			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Interpolation_NaturalNeighbour_H
+#define HEADER_INCLUDED__Interpolation_NaturalNeighbour_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CInterpolation_NaturalNeighbour : public CInterpolation  
+{
+public:
+	CInterpolation_NaturalNeighbour(void);
+
+
+protected:
+
+	virtual bool				Interpolate					(void);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Interpolation_NaturalNeighbour_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,111 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//          Interpolation_NearestNeighbour.cpp           //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation_NearestNeighbour.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CInterpolation_NearestNeighbour::CInterpolation_NearestNeighbour(void)
+{
+	Set_Name		(_TL("Nearest Neighbour"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Nearest Neighbour method for grid interpolation from irregular distributed points.")
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation_NearestNeighbour::On_Initialize(void)
+{
+	return( Set_Search_Engine() );
+}
+
+//---------------------------------------------------------
+bool CInterpolation_NearestNeighbour::Get_Value(double x, double y, double &z)
+{
+	double		Distance;
+	TSG_Point	Point;
+
+	return( m_Search.Get_Nearest_Point(x, y, Point, z, Distance) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_NearestNeighbour.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,104 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//           Interpolation_NearestNeighbour.h            //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			Interpolation_NearestNeighbour.h			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Interpolation_NearestNeighbour_H
+#define HEADER_INCLUDED__Interpolation_NearestNeighbour_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CInterpolation_NearestNeighbour : public CInterpolation  
+{
+public:
+	CInterpolation_NearestNeighbour(void);
+
+
+protected:
+
+	virtual bool			On_Initialize		(void);
+
+	virtual bool			Get_Value			(double x, double y, double &z);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Interpolation_NearestNeighbour_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,263 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Interpolation_Shepard.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Andre Ringeler                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation_Shepard.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CInterpolation_Shepard::CInterpolation_Shepard(void)
+{
+	Set_Name		(_TL("Modifed Quadratic Shepard"));
+
+	Set_Author		(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+
+	Set_Description	(_TW(
+		"Modified  Quadratic Shepard method for grid interpolation "
+		"from irregular distributed points. This module is based on "
+		"Module 660 in TOMS.\n"
+
+		"QSHEP2D: Fortran routines implementing the Quadratic Shepard "
+		"method for bivariate interpolation of scattered data "
+		"(see R. J. Renka, ACM TOMS 14 (1988) pp.149-150).\n"
+
+		"Classes: E2b. Interpolation of scattered, non-gridded multivariate data."
+	));
+
+	Parameters.Add_Value(
+		NULL	, "QUADRATIC_NEIGHBORS"	, _TL("Quadratic Neighbors"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 13, 5, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "WEIGHTING_NEIGHBORS"	, _TL("Weighting Neighbors"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 19, 3, true
+	);
+
+
+}
+
+//---------------------------------------------------------
+CInterpolation_Shepard::~CInterpolation_Shepard(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation_Shepard::On_Initialize(void)
+{
+	Quadratic_Neighbors	= Parameters("QUADRATIC_NEIGHBORS")	->asInt();
+	Weighting_Neighbors	= Parameters("WEIGHTING_NEIGHBORS")	->asInt();
+
+	m_pShapes			= Get_Points();
+	MaxPoints			= m_pShapes->Get_Count();
+
+	if( MaxPoints > 1 )
+	{
+		x_vals		= (double *)malloc(MaxPoints*sizeof(double));
+		y_vals		= (double *)malloc(MaxPoints*sizeof(double));
+		f_vals		= (double *)malloc(MaxPoints*sizeof(double));
+
+		for(int iPoint=0; iPoint<MaxPoints; iPoint++)
+		{
+			x_vals[iPoint]	= m_pShapes->Get_Shape(iPoint)->Get_Point(0).x;
+			y_vals[iPoint]	= m_pShapes->Get_Shape(iPoint)->Get_Point(0).y;
+			f_vals[iPoint]	= m_pShapes->Get_Shape(iPoint)->asDouble(m_zField);
+		}
+
+		Remove_Duplicate();
+
+		Interpolator.Interpolate(x_vals, y_vals, f_vals, MaxPoints - 1, Quadratic_Neighbors, Weighting_Neighbors);
+	}
+
+	return( MaxPoints > 1 );
+}
+
+//---------------------------------------------------------
+bool CInterpolation_Shepard::On_Finalize(void)
+{
+	free(x_vals);
+	free(y_vals);
+	free(f_vals);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation_Shepard::Get_Value(double x, double y, double &z)
+{
+	Interpolator.GetValue(x, y, z);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+static int Comp_Func(const void * vData1, const void * vData2)
+{
+	Data_Point * val_1	=	(Data_Point *)vData1;
+    Data_Point * val_2	=	(Data_Point *)vData2;
+	
+    if (val_1->y < val_2->y)
+	{
+        return (-1);
+	}
+    if (val_1->y > val_2->y)
+	{
+        return (1);
+	}
+    if (val_1->x < val_2->x)
+	{
+        return (-1);
+	}
+    if (val_1->x > val_2->x)
+	{
+        return (1);
+	}
+    return (0);
+}
+
+//---------------------------------------------------------
+#define eps 1e-7
+
+//---------------------------------------------------------
+void CInterpolation_Shepard::Remove_Duplicate()
+{
+	Data_Point * Data;
+	int i,j;
+
+	Data = (Data_Point * ) malloc (MaxPoints * sizeof(Data_Point) );
+
+	for (i = 0; i < MaxPoints; i++)
+	{
+		Data[i].x	=	x_vals[i];
+		Data[i].y	=	y_vals[i];
+		Data[i].val	=	f_vals[i];
+	}
+
+	qsort((void *)Data, MaxPoints, sizeof(Data_Point), Comp_Func);
+
+	bool durty = true;
+	
+	while (durty)
+	{
+		durty = false;
+		for (i = 0; i < MaxPoints -1; ++i)
+		{
+			if (fabs(Data[i].y - Data[i + 1].y) < eps)
+				if (fabs(Data[i].x - Data[i + 1].x) < eps)
+				{
+					for (j = i; j < MaxPoints -1; j++)
+					{
+						Data[j].x	=	Data[j + 1].x;
+						Data[j].y	=	Data[j + 1].y;
+						Data[j].val	=	Data[j + 1].val;
+					}
+					
+					MaxPoints--;
+					durty	=	true;
+				}
+		}			
+		qsort((void *)Data, MaxPoints, sizeof(Data_Point), Comp_Func);
+	}
+
+	for (i = 0; i < MaxPoints; i++)
+	{
+		x_vals[i]	=	Data[i].x;
+		y_vals[i]	=	Data[i].y;
+		f_vals[i]	=	Data[i].val;
+	}
+
+	free( Data );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Shepard.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,135 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Interpolation_Shepard.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			Interpolation_Shepard.h     				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Interpolation_Shepard_H
+#define HEADER_INCLUDED__Interpolation_Shepard_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation.h"
+#include "Shepard.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef struct 
+{
+    double x ;
+    double y ;
+	double val;
+}
+Data_Point;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CInterpolation_Shepard : public CInterpolation  
+{
+public:
+	CInterpolation_Shepard(void);
+	virtual ~CInterpolation_Shepard(void);
+
+
+protected:
+
+	virtual bool			On_Initialize		(void);
+	virtual bool			On_Finalize			(void);
+
+	virtual bool			Get_Value			(double x, double y, double &z);
+
+
+private:
+
+	int						MaxPoints, Quadratic_Neighbors, Weighting_Neighbors;
+
+	double					*x_vals, *y_vals, *f_vals;
+
+	CShepard2d				Interpolator;
+
+
+	void					Remove_Duplicate	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Interpolation_Shepard_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,267 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Triangulation.cpp                   //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Interpolation_Triangulation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CInterpolation_Triangulation::CInterpolation_Triangulation(void)
+{
+	Set_Name		(_TL("Triangulation"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Gridding of a shapes layer using Delaunay Triangulation."
+	));
+}
+
+//---------------------------------------------------------
+CInterpolation_Triangulation::~CInterpolation_Triangulation(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CInterpolation_Triangulation::Interpolate(void)
+{
+	int				iTriangle, iPoint;
+	TPoint			p[3];
+	CSG_TIN_Triangle	*pTriangle;
+	CSG_TIN			TIN;
+
+	if( TIN.Create(m_pShapes) )
+	{
+		m_pGrid->Assign_NoData();
+
+		for(iTriangle=0; iTriangle<TIN.Get_Triangle_Count() && Set_Progress(iTriangle, TIN.Get_Triangle_Count()); iTriangle++)
+		{
+			pTriangle	= TIN.Get_Triangle(iTriangle);
+
+			if( m_pGrid->Get_Extent().Intersects(pTriangle->Get_Extent()) != INTERSECTION_None )
+			{
+				for(iPoint=0; iPoint<3; iPoint++)
+				{
+					p[iPoint].x	= m_pGrid->Get_System().Get_xWorld_to_Grid(pTriangle->Get_Node(iPoint)->Get_X());
+					p[iPoint].y	= m_pGrid->Get_System().Get_yWorld_to_Grid(pTriangle->Get_Node(iPoint)->Get_Y());
+					p[iPoint].z	= pTriangle->Get_Node(iPoint)->asDouble(m_zField);
+				}
+
+				Set_Triangle(p);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SORT_POINTS_Y(a, b)	if( p[a].y < p[b].y ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+#define SORT_POINTS_X(a, b)	if( p[a].x < p[b].x ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+
+//---------------------------------------------------------
+void CInterpolation_Triangulation::Set_Triangle(TPoint p[3])
+{
+	int		i, j, y, y_j;
+	double	x, x_a, dx, dx_a, dy, z, z_a, dz, dz_a;
+	TPoint	pp;
+
+	//-----------------------------------------------------
+	SORT_POINTS_Y(1, 0);
+	SORT_POINTS_Y(2, 0);
+	SORT_POINTS_Y(2, 1);
+
+	//-----------------------------------------------------
+	if( p[2].y == p[0].y )
+	{
+		if( p[0].y >= 0 && p[0].y < m_pGrid->Get_NY() )
+		{
+			SORT_POINTS_X(1, 0);
+			SORT_POINTS_X(2, 0);
+			SORT_POINTS_X(2, 1);
+
+			//---------------------------------------------
+			if( p[2].x == p[0].x )
+			{
+				if(	p[0].x >= 0 && p[0].x < m_pGrid->Get_NX() )
+				{
+					m_pGrid->Set_Value(p[0].x, p[0].y, p[0].z > p[1].z
+						? (p[0].z > p[2].z ? p[0].z : p[2].z)
+						: (p[1].z > p[2].z ? p[1].z : p[2].z)
+					);
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				Set_Triangle_Line(p[0].x, p[1].x, p[0].y, p[0].z, p[1].z);
+				Set_Triangle_Line(p[1].x, p[2].x, p[0].y, p[1].z, p[2].z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= m_pGrid->Get_NY() && p[2].y >= m_pGrid->Get_NY())) )
+	{
+		dy		=  p[2].y - p[0].y;
+		dx_a	= (p[2].x - p[0].x) / dy;
+		dz_a	= (p[2].z - p[0].z) / dy;
+		x_a		=  p[0].x;
+		z_a		=  p[0].z;
+
+		for(i=0, j=1; i<2; i++, j++)
+		{
+			if( (dy	=  p[j].y - p[i].y) > 0.0 )
+			{
+				dx		= (p[j].x - p[i].x) / dy;
+				dz		= (p[j].z - p[i].z) / dy;
+				x		=  p[i].x;
+				z		=  p[i].z;
+
+				if( (y = p[i].y) < 0 )
+				{
+					x		-= y * dx;
+					z		-= y * dz;
+					y		 = 0;
+					x_a		 = p[0].x - p[0].y * dx_a;
+					z_a		 = p[0].z - p[0].y * dz_a;
+				}
+
+				if( (y_j = p[j].y) > m_pGrid->Get_NY() )
+				{
+					y_j		= m_pGrid->Get_NY();
+				}
+
+				for( ; y<y_j; y++, x+=dx, z+=dz, x_a+=dx_a, z_a+=dz_a)
+				{
+					if( x < x_a )
+					{
+						Set_Triangle_Line((int)x, (int)x_a, y, z, z_a);
+					}
+					else
+					{
+						Set_Triangle_Line((int)x_a, (int)x, y, z_a, z);
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CInterpolation_Triangulation::Set_Triangle_Line(int xa, int xb, int y, double za, double zb)
+{
+	double	dz;
+
+	if( (dz = xb - xa) > 0.0 )
+	{
+		dz	= (zb - za) / dz;
+
+		if( xa < 0 )
+		{
+			za	-= dz * xa;
+			xa	 = 0;
+		}
+
+		if( xb >= m_pGrid->Get_NX() )
+		{
+			xb	= m_pGrid->Get_NX() - 1;
+		}
+
+		for(int x=xa; x<=xb; x++, za+=dz)
+		{
+			m_pGrid->Set_Value(x, y, za);
+		}
+	}
+	else if( xa >= 0 && xa < m_pGrid->Get_NX() )
+	{
+		m_pGrid->Set_Value(xa, y, za);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Interpolation_Triangulation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,111 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             Interpolation_Triangulation.h             //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Interpolation_Triangulation_H
+#define HEADER_INCLUDED__Interpolation_Triangulation_H
+
+//---------------------------------------------------------
+#include "Interpolation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CInterpolation_Triangulation : public CInterpolation  
+{
+public:
+	CInterpolation_Triangulation(void);
+	virtual ~CInterpolation_Triangulation(void);
+
+
+protected:
+
+	virtual bool				Interpolate					(void);
+
+
+private:
+
+	typedef struct
+	{
+		int						x, y;
+
+		double					z;
+	}
+	TPoint;
+
+
+	void						Set_Triangle				(TPoint p[3]);
+	void						Set_Triangle_Line			(int xa, int xb, int y, double za, double zb);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Interpolation_Triangulation_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,132 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Gridding") );
+
+	case MLB_INFO_Author:
+		return( _TL("O. Conrad (c) 2002-8") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the gridding of points and other vector data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Gridding") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Interpolation_InverseDistance.h"
+#include "Interpolation_NearestNeighbour.h"
+#include "Interpolation_NaturalNeighbour.h"
+#include "Interpolation_Shepard.h"
+#include "Interpolation_Triangulation.h"
+#include "Shapes2Grid.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:	return( new CShapes2Grid );
+	case 1:	return( new CInterpolation_InverseDistance );
+	case 2:	return( new CInterpolation_NearestNeighbour );
+	case 3:	return( new CInterpolation_NaturalNeighbour );
+	case 4:	return( new CInterpolation_Shepard );
+	case 5:	return( new CInterpolation_Triangulation );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_gridding_H
+#define HEADER_INCLUDED__grid_gridding_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_gridding_EXPORTS
+	#define	grid_gridding_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_gridding_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_gridding_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,764 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Shapes2Grid.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+#include "Shapes2Grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define X_WORLD_TO_GRID(X)	(((X) - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize())
+#define Y_WORLD_TO_GRID(Y)	(((Y) - m_pGrid->Get_YMin()) / m_pGrid->Get_Cellsize())
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes2Grid::CShapes2Grid(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1;
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Shapes to Grid"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Gridding of a shapes layer. If some shapes are selected, only these will be gridded."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	pNode_0	= Parameters.Add_Shapes(
+		NULL	, "INPUT"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode_1	= Parameters.Add_Table_Field(
+		pNode_0	, "FIELD"		, _TL("Attribute"),
+		_TL("")
+	);
+
+	pNode_0	= Parameters.Add_Choice(
+		NULL	, "TARGET_TYPE"	, _TL("Target Dimensions"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("User defined"),
+			_TL("Grid Project"),
+			_TL("Grid")
+		), 0
+	);
+
+	pNode_0	= Parameters.Add_Choice(
+		NULL	, "LINE_TYPE"	, _TL("Method for Lines"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("thin"),
+			_TL("thick")
+		), 1
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("USER", _TL("User defined grid"), _TL(""));
+
+	pNode_0	= pParameters->Add_Value(
+		NULL	, "CELL_SIZE"	, _TL("Grid Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	pNode_0	= pParameters->Add_Value(
+		NULL	, "FIT_EXTENT"	, _TL("Fit Extent"),
+		_TL("Automatically fits the grid to the shapes layers extent."),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	pNode_1	= pParameters->Add_Range(
+		pNode_0	, "X_EXTENT"	, _TL("X-Extent"),
+		_TL("")
+	);
+
+	pNode_1	= pParameters->Add_Range(
+		pNode_0	, "Y_EXTENT"	, _TL("Y-Extent"),
+		_TL("")
+	);
+
+	pNode_0	= pParameters->Add_Choice(
+		NULL	, "GRID_TYPE"	, _TL("Target Grid Type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Integer (1 byte)"),
+			_TL("Integer (2 byte)"),
+			_TL("Integer (4 byte)"),
+			_TL("Floating Point (4 byte)"),
+			_TL("Floating Point (8 byte)")
+		), 3
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_SYSTEM"	, _TL("Choose Grid Project"), _TL(""));
+
+	pNode_0	= pParameters->Add_Grid_System(
+		NULL, "SYSTEM"		, _TL("System")		, _TL("")
+	);
+
+	pNode_0	= pParameters->Add_Choice(
+		NULL	, "GRID_TYPE"	, _TL("Target Grid Type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Integer (1 byte)"),
+			_TL("Integer (2 byte)"),
+			_TL("Integer (4 byte)"),
+			_TL("Floating Point (4 byte)"),
+			_TL("Floating Point (8 byte)")
+		), 3
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GRID"			, _TL("Choose Grid")		, _TL(""));
+
+	pNode_0	= pParameters->Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT	, false
+	);
+}
+
+//---------------------------------------------------------
+CShapes2Grid::~CShapes2Grid(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_Data_Type CShapes2Grid::Get_Grid_Type(int iType)
+{
+	switch( iType )
+	{
+	case 0:		return( SG_DATATYPE_Byte );
+	case 1:		return( SG_DATATYPE_Short );
+	case 2:		return( SG_DATATYPE_Int );
+	default:
+	case 3:		return( SG_DATATYPE_Float );
+	case 4:		return( SG_DATATYPE_Double );
+	}
+}
+
+//---------------------------------------------------------
+CSG_Grid * CShapes2Grid::Get_Target_Grid(CSG_Parameters *pParameters, CSG_Shapes *m_pShapes)
+{
+	int			nx, ny;
+	double		Cell_Size, xMin, yMin, xMax, yMax;
+
+	if( pParameters->Get_Parameter("FIT_EXTENT")->asBool() )
+	{
+		xMin	= m_pShapes->Get_Extent().m_rect.xMin;
+		yMin	= m_pShapes->Get_Extent().m_rect.yMin;
+		xMax	= m_pShapes->Get_Extent().m_rect.xMax;
+		yMax	= m_pShapes->Get_Extent().m_rect.yMax;
+	}
+	else
+	{
+		xMin	= pParameters->Get_Parameter("X_EXTENT")->asRange()->Get_LoVal();
+		yMin	= pParameters->Get_Parameter("Y_EXTENT")->asRange()->Get_LoVal();
+		xMax	= pParameters->Get_Parameter("X_EXTENT")->asRange()->Get_HiVal();
+		yMax	= pParameters->Get_Parameter("Y_EXTENT")->asRange()->Get_HiVal();
+	}
+
+	Cell_Size	= pParameters->Get_Parameter("CELL_SIZE")->asDouble();
+
+	nx			= 1 + (int)((xMax - xMin) / Cell_Size);
+	ny			= 1 + (int)((yMax - yMin) / Cell_Size);
+
+	return( SG_Create_Grid(Get_Grid_Type(pParameters->Get_Parameter("GRID_TYPE")->asInt()), nx, ny, Cell_Size, xMin, yMin) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes2Grid::On_Execute(void)
+{
+	m_pGrid		= NULL;
+	m_pShapes	= Parameters("INPUT")->asShapes();
+
+	//-----------------------------------------------------
+	if( m_pShapes->Get_Field_Count() > 0 )
+	{
+		switch( Parameters("TARGET_TYPE")->asInt() )
+		{
+		case 0:	// User defined...
+			if( Dlg_Parameters("USER") )
+			{
+				m_pGrid	= Get_Target_Grid(Get_Parameters("USER"), m_pShapes);
+			}
+			break;
+
+		case 1:	// Grid Project...
+			if( Dlg_Parameters("GET_SYSTEM") )
+			{
+				m_pGrid	= SG_Create_Grid(
+							*Get_Parameters("GET_SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(),
+							Get_Grid_Type(Get_Parameters("GET_SYSTEM")->Get_Parameter("GRID_TYPE")->asInt())
+						);
+			}
+			break;
+
+		case 2:	// Grid...
+			if( Dlg_Parameters("GRID") )
+			{
+				m_pGrid	= Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid();
+			}
+			break;
+		}
+
+		//-------------------------------------------------
+		if( m_pGrid )
+		{
+			int			i, iField;
+			CSG_Shape	*pShape;
+
+			//---------------------------------------------
+			m_Method_Lines	= Parameters("LINE_TYPE")	->asInt();
+			iField			= Parameters("FIELD")		->asInt();
+
+			if( iField >= 0 && iField < m_pShapes->Get_Field_Count()
+			&&	m_pShapes->Get_Field_Type(iField) != SG_DATATYPE_String )
+			{
+				m_pGrid->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pShapes->Get_Name(), m_pShapes->Get_Field_Name(iField)));
+			}
+			else
+			{
+				m_pGrid->Set_Name(m_pShapes->Get_Name());
+				iField	= -1;
+				Message_Add( _TL("WARNING: The selected attribute is of field type string, generating unique identifiers instead.\n"));
+			}
+
+			//---------------------------------------------
+			m_pGrid->Assign_NoData();
+			Parameters("GRID")->Set_Value(m_pGrid);
+
+			m_pLock	= m_pShapes->Get_Type() == SHAPE_TYPE_Point ? NULL
+					: SG_Create_Grid(m_pGrid, SG_DATATYPE_Byte);
+
+			//---------------------------------------------
+			for(i=0, m_Lock_ID=1; i<m_pShapes->Get_Count() && Set_Progress(i, m_pShapes->Get_Count()); i++, m_Lock_ID++)
+			{
+				pShape	= m_pShapes->Get_Shape(i);
+				if (m_pShapes->Get_Selection_Count() > 0)
+				{
+					if (!pShape->is_Selected())
+						continue;
+				}
+				m_Value	= iField < 0 ? i + 1 : pShape->asDouble(iField);
+
+				if( pShape->Intersects(m_pGrid->Get_Extent().m_rect) )
+				{
+					switch( m_pShapes->Get_Type() )
+					{
+					case SHAPE_TYPE_Point:
+					case SHAPE_TYPE_Points:		Set_Points	(pShape);	break;
+					case SHAPE_TYPE_Line:		Set_Line	(pShape);	break;
+					case SHAPE_TYPE_Polygon:	Set_Polygon	(pShape);	break;
+					}
+				}
+			}
+
+			//---------------------------------------------
+			if( m_pLock )
+			{
+				delete(m_pLock);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CShapes2Grid::Set_Value(int x, int y)
+{
+	if( m_pGrid->is_InGrid(x, y, false) )
+	{
+		if( m_pLock )
+		{
+			if( m_Lock_ID >= 255 )
+			{
+				m_Lock_ID	= 1;
+
+				m_pLock->Assign(0.0);
+			}
+
+			if( m_pLock->asInt(x, y) != m_Lock_ID )
+			{
+				m_pLock	->Set_Value(x, y, m_Lock_ID);
+
+				m_pGrid	->Set_Value(x, y, m_pGrid->is_NoData(x, y) ? m_Value : (m_Value + m_pGrid->asDouble(x, y)) / 2.0);
+			}
+		}
+		else
+		{
+			m_pGrid	->Set_Value(x, y, m_pGrid->is_NoData(x, y) ? m_Value : (m_Value + m_pGrid->asDouble(x, y)) / 2.0);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes2Grid::Set_Points(CSG_Shape *pShape)
+{
+	for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			TSG_Point	p	= pShape->Get_Point(iPoint, iPart);
+
+			Set_Value(
+				(int)(0.5 + X_WORLD_TO_GRID(p.x)),
+				(int)(0.5 + Y_WORLD_TO_GRID(p.y))
+			);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes2Grid::Set_Line(CSG_Shape *pShape)
+{
+	TSG_Point	a, b;
+
+	for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		b	= pShape->Get_Point(0, iPart);
+		b.x	= X_WORLD_TO_GRID(b.x);
+		b.y	= Y_WORLD_TO_GRID(b.y);
+
+		for(int iPoint=1; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			a	= b;
+			b	= pShape->Get_Point(iPoint, iPart);
+			b.x	= X_WORLD_TO_GRID(b.x);
+			b.y	= Y_WORLD_TO_GRID(b.y);
+
+			switch( m_Method_Lines )
+			{
+			case 0:	Set_Line_A(a, b);	break;
+			case 1:	Set_Line_B(a, b);	break;
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CShapes2Grid::Set_Line_A(TSG_Point a, TSG_Point b)
+{
+	double			ix, iy, sig;
+	double			dx, dy;
+	TSG_Point_Int	A, B;
+
+	A.x	= (int)(a.x	+= 0.5);
+	A.y	= (int)(a.y	+= 0.5);
+	B.x	= (int)(b.x	+= 0.5);
+	B.y	= (int)(b.y	+= 0.5);
+
+	//-----------------------------------------------------
+	if( A.x != B.x || A.y != B.y )
+	{
+		dx	= b.x - a.x;
+		dy	= b.y - a.y;
+
+		if( fabs(dx) > fabs(dy) )
+		{
+			sig	= dx < 0 ? -1 : 1;
+			dx	= fabs(dx);
+			dy	/= dx;
+
+			for(ix=0; ix<=dx; ix++, a.x+=sig, a.y+=dy)
+			{
+				Set_Value((int)a.x, (int)a.y);
+			}
+		}
+		else if( fabs(dy) >= fabs(dx) && dy != 0 )
+		{
+			sig	= dy < 0 ? -1 : 1;
+			dy	= fabs(dy);
+			dx	/= dy;
+
+			for(iy=0; iy<=dy; iy++, a.x+=dx, a.y+=sig)
+			{
+				Set_Value((int)a.x, (int)a.y);
+			}
+		}
+	}
+	else
+	{
+		Set_Value(A.x, A.y);
+	}
+}
+
+/*/---------------------------------------------------------
+void CShapes2Grid::Set_Line_A(TSG_Point a, TSG_Point b)
+{
+	TSG_Point_Int	A, B;
+
+	A.x	= (int)(a.x	+ 0.5);
+	A.y	= (int)(a.y	+ 0.5);
+	B.x	= (int)(b.x	+ 0.5);
+	B.y	= (int)(b.y	+ 0.5);
+
+	//-----------------------------------------------------
+	if( A.x != B.x || A.y != B.y )
+	{
+		int		d, dx, dy;
+		double	m, t;
+
+		dx	= B.x - A.x;
+		dy	= B.y - A.y;
+
+		if( fabs(dx) > fabs(dy) )
+		{
+			d	= dx < 0 ? -1 : 1;
+			m	= d * (double)dy / (double)dx;
+
+			for(t=A.y; A.x!=B.x; A.x+=d, t+=m)
+			{
+				Set_Value(A.x, (int)t);
+			}
+		}
+		else // if( fabs(dy) >= fabs(dx) )
+		{
+			d	= dy < 0 ? -1 : 1;
+			m	= d * (double)dx / (double)dy;
+
+			for(t=A.x; A.y!=B.y; A.y+=d, t+=m)
+			{
+				Set_Value((int)t, A.y);
+			}
+		}
+	}
+	else
+	{
+		Set_Value(A.x, A.y);
+	}
+}/**/
+
+//---------------------------------------------------------
+void CShapes2Grid::Set_Line_B(TSG_Point a, TSG_Point b)
+{
+	int				ix, iy;
+	double			e, d, dx, dy;
+	TSG_Point_Int	A, B;
+
+	A.x	= (int)(a.x	+= 0.5);
+	A.y	= (int)(a.y	+= 0.5);
+	B.x	= (int)(b.x	+= 0.5);
+	B.y	= (int)(b.y	+= 0.5);
+
+	Set_Value(A.x, A.y);
+
+	//-----------------------------------------------------
+	if( A.x != B.x || A.y != B.y )
+	{
+		dx	= b.x - a.x;
+		dy	= b.y - a.y;
+
+		a.x	= a.x > 0.0 ? a.x - (int)a.x : 1.0 + (a.x - (int)a.x);
+		a.y	= a.y > 0.0 ? a.y - (int)a.y : 1.0 + (a.y - (int)a.y);
+
+		//-------------------------------------------------
+		if( fabs(dx) > fabs(dy) )
+		{
+			ix	= dx > 0.0 ? 1 : -1;
+			iy	= dy > 0.0 ? 1 : -1;
+			d	= fabs(dy / dx);
+			dx	= ix < 0 ? a.x : 1.0 - a.x;
+			e	= iy > 0 ? a.y : 1.0 - a.y;
+			e	+= d * dx;
+
+			while( e > 1.0 )
+			{
+				e	-= 1.0;
+				A.y	+= iy;
+				Set_Value(A.x, A.y);
+			}
+
+			while( A.x != B.x )
+			{
+				A.x	+= ix;
+				e	+= d;
+				Set_Value(A.x, A.y);
+
+				if( A.x != B.x )
+				{
+					while( e > 1.0 )
+					{
+						e	-= 1.0;
+						A.y	+= iy;
+						Set_Value(A.x, A.y);
+					}
+				}
+			}
+
+			if( A.y != B.y )
+			{
+				iy	= A.y < B.y ? 1 : -1;
+
+				while( A.y != B.y )
+				{
+					A.y	+= iy;
+					Set_Value(A.x, A.y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		else // if( fabs(dy) > fabs(dx) )
+		{
+			ix	= dx > 0.0 ? 1 : -1;
+			iy	= dy > 0.0 ? 1 : -1;
+			d	= fabs(dx / dy);
+			dy	= iy < 0 ? a.y : 1.0 - a.y;
+			e	= ix > 0 ? a.x : 1.0 - a.x;
+			e	+= d * dy;
+
+			while( e > 1.0 )
+			{
+				e	-= 1.0;
+				A.x	+= ix;
+				Set_Value(A.x, A.y);
+			}
+
+			while( A.y != B.y )
+			{
+				A.y	+= iy;
+				e	+= d;
+				Set_Value(A.x, A.y);
+
+				if( A.y != B.y )
+				{
+					while( e > 1.0 )
+					{
+						e	-= 1.0;
+						A.x	+= ix;
+						Set_Value(A.x, A.y);
+					}
+				}
+			}
+
+			if( A.x != B.x )
+			{
+				ix	= A.x < B.x ? 1 : -1;
+
+				while( A.x != B.x )
+				{
+					A.x	+= ix;
+					Set_Value(A.x, A.y);
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes2Grid::Set_Polygon(CSG_Shape *pShape)
+{
+	bool		bFill, *bCrossing;
+	int			x, y, xStart, xStop;
+	TSG_Point	A, B, a, b, c;
+	CSG_Rect	Extent;
+
+	//-----------------------------------------------------
+	bCrossing	= (bool *)SG_Malloc(m_pGrid->Get_NX() * sizeof(bool));
+
+	Extent		= pShape->Get_Extent();
+
+	xStart		= (int)((Extent.m_rect.xMin - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize()) - 1;
+	if( xStart < 0 )
+		xStart	= 0;
+
+	xStop		= (int)((Extent.m_rect.xMax - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize()) + 1;
+	if( xStop >= m_pGrid->Get_NX() )
+		xStop	= m_pGrid->Get_NX() - 1;
+
+	A.x			= m_pGrid->Get_XMin() - 1.0;
+	B.x			= m_pGrid->Get_XMax() + 1.0;
+
+	//-----------------------------------------------------
+	for(y=0, A.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY(); y++, A.y+=m_pGrid->Get_Cellsize())
+	{
+		if( A.y >= Extent.m_rect.yMin && A.y <= Extent.m_rect.yMax )
+		{
+			B.y	= A.y;
+
+			memset(bCrossing, 0, m_pGrid->Get_NX() * sizeof(bool));
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				b	= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					a	= b;
+					b	= pShape->Get_Point(iPoint, iPart);
+
+					if(	((a.y <= A.y && A.y  < b.y)
+					||	 (a.y  > A.y && A.y >= b.y)) )
+					{
+						SG_Get_Crossing(c, a, b, A, B, false);
+
+						x	= (int)(1.0 + X_WORLD_TO_GRID(c.x));
+
+						if( x < 0 )
+						{
+							x	= 0;
+						}
+						else if( x >= m_pGrid->Get_NX() )
+						{
+							x	= m_pGrid->Get_NX() - 1;
+						}
+
+						bCrossing[x]	= !bCrossing[x];
+					}
+				}
+			}
+
+			//---------------------------------------------
+			for(x=xStart, bFill=false; x<=xStop; x++)
+			{
+				if( bCrossing[x] )
+				{
+					bFill	= !bFill;
+				}
+
+				if( bFill )
+				{
+					Set_Value(x, y);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(bCrossing);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shapes2Grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Shapes2Grid.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes2Grid_H
+#define HEADER_INCLUDED__Shapes2Grid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes2Grid : public CSG_Module  
+{
+public:
+	CShapes2Grid(void);
+	virtual ~CShapes2Grid(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	int						m_Lock_ID, m_Method_Lines;
+
+	double					m_Value;
+
+	CSG_Grid				*m_pGrid, *m_pLock;
+
+	CSG_Shapes				*m_pShapes;
+
+
+	TSG_Data_Type			Get_Grid_Type		(int iType);
+	CSG_Grid *				Get_Target_Grid		(CSG_Parameters *pParameters, CSG_Shapes *pShapes);
+
+	void					Set_Value			(int x, int y);
+
+	void					Set_Points			(CSG_Shape *pShape);
+
+	void					Set_Line			(CSG_Shape *pShape);
+	void					Set_Line_A			(TSG_Point a, TSG_Point b);
+	void					Set_Line_B			(TSG_Point a, TSG_Point b);
+
+	void					Set_Polygon			(CSG_Shape *pShape);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes2Grid_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shepard.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shepard.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_gridding/Shepard.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,2022 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_Gridding                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Shepard.cpp                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Andre Ringeler                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+#include <math.h>
+#include <stdlib.h>
+#include "Shepard.h"
+
+double _missing_;
+
+CShepard2d::CShepard2d (void)
+{
+    m_cells = NULL;
+    m_next = NULL;
+    m_rsq = NULL;
+    m_a = NULL;
+	_missing_ = -9999.99;
+}
+
+CShepard2d::~CShepard2d (void)
+{
+    if (m_cells)
+    {
+        free (m_cells);
+        m_cells = NULL;
+    }
+    if (m_next)
+    {
+        free (m_next);
+        m_next = NULL;
+    }
+    if (m_rsq)
+    {
+        free (m_rsq);
+        m_rsq = NULL;
+    }
+    if (m_a)
+    {
+        free (m_a);
+        m_a = NULL;
+    }
+}
+
+void CShepard2d::Set_Missing(double missing)
+{
+	_missing_ = missing;
+}
+
+int CShepard2d::Interpolate (double *X, double * Y, double * F, int N_Points, int Quadratic_Neighbors, int Weighting_Neighbors )
+{
+
+    int nr, lmax;
+	int status;
+
+    if (N_Points < 6)
+        return -1;
+
+    lmax = min(40, N_Points - 1);
+    if (Quadratic_Neighbors < 5 || Quadratic_Neighbors > lmax)
+        return -1;
+    if (Weighting_Neighbors < 1 || Weighting_Neighbors > lmax)
+        return -1;
+
+    nr = (int)(sqrt(N_Points / 3.0));
+    if (nr < 1)
+        nr = 1;
+
+    this->CShepard2d::~CShepard2d();
+
+    m_cells = (int *) malloc(nr * nr * sizeof(int));
+    m_next = (int *) malloc(N_Points * sizeof(int));
+
+    m_rsq = (double *) malloc(N_Points * sizeof(double));
+
+    m_a = (double *) malloc(N_Points * 5 * sizeof(double));
+
+    m_x = X;
+    m_y = Y;
+    m_f = F;
+
+    m_nPoints = N_Points;
+    m_nr = nr;
+
+     qshep2_(&N_Points, X, Y, F, &Quadratic_Neighbors, &Weighting_Neighbors, &nr, m_cells, m_next, &xmin, &ymin, &dx, &dy, &rmax, m_rsq, m_a, &status);
+
+	return status;
+}
+
+void CShepard2d::GetValue(double px, double py, double &q)
+{
+    if ( ! m_a )
+		q = _missing_;
+	else
+        q = qs2val_(&px, &py, &m_nPoints , m_x, m_y, m_f, &m_nr, m_cells, m_next, &xmin, &ymin, &dx, &dy, &rmax, m_rsq, m_a);
+}
+
+/*/////////////////////////////////////////////////////////////////////////////////////
+The folowing source ist an automatic translation 
+with f2c of Module 660 in TOMS
+ 
+QSHEP2D: Fortran routines implementing the quadratic Shepard method for
+bivariate interpolation of scattered data. (See R. J. Renka, ACM TOMS 14 (1988)
+pp. 149-150.).
+ 
+Classes  :  E2b . Interpolation of scattered, non-gridded multivariate data
+ 
+Type     : Fortran software in TOMS collection.
+Access   : Some uses prohibited. Portable.
+Precision: Single.
+ 
+Details  : Fullsource
+Sites    : (1) NETLIB
+//////////////////////////////////////////////////////////////////////////////////////*/ 
+
+
+
+struct
+{
+    double y;
+}
+stcom_;
+
+#define stcom_1 stcom_
+
+/* Table of constant values */
+
+static int c__1 = 1;
+
+
+
+int qshep2_(int *n,   double *x,   double *y,   double *f,   int *
+                             nq, int *nw, int *nr, int *lcell, int *lnext, double *
+                             xmin, double *ymin, double *dx, double *dy, double *rmax, double *rsq, double *a,
+                             int *ier)
+{
+  
+    static double rtol = 1e-5f;
+    static double dtol = .01f;
+    static double sf = 1.f;
+
+    int lcell_dim1, lcell_offset, i__1, i__2, i__3;
+    double r__1, r__2;
+
+//    double sqrt(double);
+
+    static double b[36]	/* was[6][6] */, c__;
+    static int i__, j, k;
+    static double s, t;
+    static int ib;
+    static double fk, av;
+    static int nn, np;
+    static double rq, xk, rs, yk;
+    static int ip1, jp1;
+    static double ddx, ddy;
+    static int neq, lnp, nnq, nnr, nnw;
+    static double xmn, sum, ymn, rws;
+    static int irm1;
+    static double dmin__;
+    static int ierr, lmax;
+    static double avsq;
+    static int irow, npts[40];
+    static double rsmx, rsold;
+    extern int getnp2_(double *, double *, double *, double *,
+                                            int *, int *, int *, double *, double *, double *, double *,
+                                            int *, double *), store2_(int *, double *, double *, int *,
+                                                                        int *, int *, double *, double *, double *, double *, int *),
+        setup2_(double *, double *, double *, double *, double *, double *, double *,
+                double *, double *, double *), givens_(double *, double *, double *, double *),
+        rotate_(int *, double *, double *, double *, double *);
+    static int nqwmax;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+    /* 						    01/08/90							*/
+	/*																*/
+    /*   THIS SUBROUTINE COMPUTES A SET OF PARAMETERS A AND RSQ		*/
+    /* DEFINING A SMOOTH(ONCE CONTINUOUSLY DIFFERENTIABLE) BI-		*/
+    /* VARIATE FUNCTION Q(X, Y) WHICH INTERPOLATES DATA VALUES F	*/
+    /* AT SCATTERED NODES(X, Y).  THE INTERPOLANT Q MAY BE EVAL-	*/
+    /* UATED AT AN ARBITRARY POINT BY FUNCTION QS2VAL, AND ITS		*/
+    /* FIRST DERIVATIVES ARE COMPUTED BY SUBROUTINE QS2GRD.			*/
+    /*   THE INTERPOLATION SCHEME IS A MODIFIED QUADRATIC SHEPARD	*/
+    /* METHOD --													*/
+	/*																*/
+    /* Q =(W(1)*Q(1) + W(2)*Q(2)+..+W(N)*Q(N))/(W(1) + W(2)+..+W(N))*/
+	/*																*/
+    /* FOR BIVARIATE FUNCTIONS W(K) AND Q(K).  THE NODAL FUNC-		*/
+    /* TIONS ARE GIVEN BY											*/
+	/*																*/
+    /* Q(K)(X, Y) = A(1, K)*(X - X(K))**2							*/
+	/*		+ A(2, K)*(X - X(K))*(Y - Y(K))							*/
+    /* 	    + A(3, K)*(Y - Y(K))**2 + A(4, K)*(X - X(K))			*/
+    /* 	    + A(5, K)*(Y - Y(K))	 + F(K) .						*/
+	/*																*/
+    /* THUS, Q(K) IS A QUADRATIC FUNCTION WHICH INTERPOLATES THE	*/
+    /* DATA VALUE AT NODE K.  ITS COEFFICIENTS A(, K) ARE OBTAINED	*/
+    /* BY A WEIGHTED LEAST SQUARES FIT TO THE CLOSEST NQ DATA		*/
+    /* POINTS WITH WEIGHTS SIMILAR TO W(K).	NOTE THAT THE RADIUS	*/
+    /* OF INFLUENCE FOR THE LEAST SQUARES FIT IS FIXED FOR EACH		*/
+    /* K, BUT VARIES WITH K.										*/
+    /*   THE WEIGHTS ARE TAKEN TO BE								*/
+	/*																*/
+    /* W(K)(X, Y) =((R(K) - D(K))+ / R(K)*D(K))**2					*/
+	/*																*/
+    /* WHERE(R(K) - D(K))+ = 0 IF R(K) .LE. D(K) AND D(K)(X, Y) IS	*/
+    /* THE EUCLIDEAN DISTANCE BETWEEN(X, Y) AND(X(K), Y(K)).  THE	*/
+    /* RADIUS OF INFLUENCE R(K) VARIES WITH K AND IS CHOSEN SO		*/
+    /* THAT NW NODES ARE WITHIN THE RADIUS.	NOTE THAT W(K) IS		*/
+    /* NOT DEFINED AT NODE(X(K), Y(K)), BUT Q(X, Y) HAS LIMIT F(K)	*/
+    /* AS(X, Y) APPROACHES(X(K), Y(K)).								*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	N = NUMBER OF NODES AND ASSOCIATED DATA VALUES.				*/
+    /* 	    N .GE. 6.												*/
+	/*																*/
+    /* 	X, Y = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN			*/
+    /* 	      COORDINATES OF THE NODES.								*/
+	/*																*/
+    /* 	F = ARRAY OF LENGTH N CONTAINING THE DATA VALUES			*/
+    /* 	    IN ONE - TO - ONE CORRESPONDENCE WITH THE NODES.		*/
+	/*																*/
+    /* 	NQ = NUMBER OF DATA POINTS TO BE USED IN THE LEAST			*/
+    /* 	     SQUARES FIT FOR COEFFICIENTS DEFINING THE NODAL		*/
+    /* 	     FUNCTIONS Q(K).  A HIGHLY RECOMMENDED VALUE IS			*/
+    /* 	     NQ = 13.  5 .LE. NQ .LE. MIN(40, N - 1).				*/
+	/*																*/
+    /* 	NW = NUMBER OF NODES WITHIN(AND DEFINING) THE RADII			*/
+    /* 	     OF INFLUENCE R(K) WHICH ENTER INTO THE WEIGHTS			*/
+    /* 	     W(K).  FOR N SUFFICIENTLY LARGE, A RECOMMENDED			*/
+    /* 	     VALUE IS NW = 19.	1 .LE. NW .LE. MIN(40, N - 1).		*/
+	/*																*/
+    /* 	NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID DE-		*/
+    /* 	     FINED IN SUBROUTINE STORE2.  A RECTANGLE CON-			*/
+    /* 	     TAINING THE NODES IS PARTITIONED INTO CELLS IN			*/
+    /* 	     ORDER TO INCREASE SEARCH EFFICIENCY.  NR =				*/
+    /* 	     SQRT(N/3) IS RECOMMENDED.	NR .GE. 1.					*/
+	/*																*/
+    /* THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.		*/
+	/*																*/
+    /* 	LCELL = ARRAY OF LENGTH .GE. NR**2.							*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF LENGTH .GE. N.								*/
+	/*																*/
+    /* 	RSQ = ARRAY OF LENGTH .GE. N.								*/
+	/*																*/
+    /* 	A = ARRAY OF LENGTH .GE. 5N.								*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED			*/
+    /* 		WITH CELLS.  REFER TO STORE2.							*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF LENGTH N CONTAINING NEXT - NODE INDI-		*/
+    /* 		CES.  REFER TO STORE2.									*/
+	/*																*/
+    /* 	XMIN, YMIN, DX, DY = MINIMUM NODAL COORDINATES AND CELL		*/
+    /* 			  DIMENSIONS.  REFER TO STORE2.						*/
+	/*																*/
+    /* 	RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --			*/
+    /* 	       MAXIMUM RADIUS R(K).									*/
+	/*																*/
+    /* 	RSQ = ARRAY CONTAINING THE SQUARES OF THE RADII R(K)		*/
+    /* 	      WHICH ENTER INTO THE WEIGHTS W(K).					*/
+	/*																*/
+    /* 	A = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR			*/
+    /* 	    QUADRATIC NODAL FUNCTION Q(K) IN COLUMN K.				*/
+	/*																*/
+    /*   NOTE THAT THE ABOVE OUTPUT PARAMETERS ARE NOT DEFINED		*/
+    /* UNLESS IER = 0.												*/
+	/*																*/
+    /* 	IER = ERROR INDICATOR --									*/
+    /* 	      IER = 0 IF NO ERRORS WERE ENCOUNTERED.				*/
+    /* 	      IER = 1 IF N, NQ, NW, OR NR IS OUT OF RANGE.			*/
+    /* 	      IER = 2 IF DUPLICATE NODES WERE ENCOUNTERED.			*/
+    /* 	      IER = 3 IF ALL NODES ARE COLLINEAR.					*/
+	/*																*/
+    /* MODULES REQUIRED BY QSHEP2 -- GETNP2, GIVENS, ROTATE,		*/
+    /* 				  SETUP2, STORE2								*/
+	/*																*/
+    /* INTRINSIC FUNCTIONS CALLED BY QSHEP2 -- ABS, AMIN1, FLOAT,	*/
+    /* 					    MAX0, MIN0, SQRT						*/
+	/*																*/
+    /****************************************************************/
+
+    a -= 6;
+    --rsq;
+    --lnext;
+    --f;
+    --y;
+    --x;
+    lcell_dim1 = *nr;
+    lcell_offset = 1 + lcell_dim1;
+    lcell -= lcell_offset;
+
+    /* LOCAL PARAMETERS --											*/
+	/*																*/
+    /* AV =	       ROOT - MEAN - SQUARE DISTANCE BETWEEN K AND THE	*/
+    /* 		 NODES IN THE LEAST SQUARES SYSTEM(UNLESS				*/
+    /* 		 ADDITIONAL NODES ARE INTRODUCED FOR STABIL-			*/
+    /* 		 ITY).	THE FIRST 3 COLUMNS OF THE MATRIX				*/
+    /* 		 ARE SCALED BY 1/AVSQ, THE LAST 2 BY 1/AV				*/
+    /* AVSQ =       AV*AV											*/
+    /* B =	       TRANSPOSE OF THE AUGMENTED REGRESSION MATRIX		*/
+    /* C =	       FIRST COMPONENT OF THE PLANE ROTATION USED TO	*/
+    /* 		 ZERO THE LOWER TRIANGLE OF B**T -- COMPUTED			*/
+    /* 		 BY SUBROUTINE GIVENS									*/
+    /* DDX, DDY =    LOCAL VARIABLES FOR DX AND DY					*/
+    /* DMIN =       MINIMUM OF THE MAGNITUDES OF THE DIAGONAL		*/
+    /* 		 ELEMENTS OF THE REGRESSION MATRIX AFTER				*/
+    /* 		 ZEROS ARE INTRODUCED BELOW THE DIAGONAL				*/
+    /* DTOL =       TOLERANCE FOR DETECTING AN ILL - CONDITIONED	*/
+    /* 		 SYSTEM.  THE SYSTEM IS ACCEPTED WHEN DMIN				*/
+    /* 		 .GE. DTOL												*/
+    /* FK =	       DATA VALUE AT NODE K -- F(K)						*/
+    /* I =	       INDEX FOR A, B, AND NPTS							*/
+    /* IB =	       DO - LOOP INDEX FOR BACK SOLVE					*/
+    /* IERR =       ERROR FLAG FOR THE CALL TO STORE2				*/
+    /* IP1 =        I + 1											*/
+    /* IRM1 =       IROW - 1										*/
+    /* IROW =       ROW INDEX FOR B									*/
+    /* J =	       INDEX FOR A AND B								*/
+    /* JP1 =        J + 1											*/
+    /* K =	       NODAL FUNCTION INDEX AND COLUMN INDEX FOR A		*/
+    /* LMAX =       MAXIMUM NUMBER OF NPTS ELEMENTS(MUST BE CON-	*/
+    /* 		 SISTENT WITH THE DIMENSION STATEMENT ABOVE)			*/
+    /* LNP =        CURRENT LENGTH OF NPTS							*/
+    /* NEQ =        NUMBER OF EQUATIONS IN THE LEAST SQUARES FIT	*/
+    /* NN, NNQ, NNR = LOCAL COPIES OF N, NQ, AND NR					*/
+    /* NNW =        LOCAL COPY OF NW								*/
+    /* NP =	       NPTS ELEMENT										*/
+    /* NPTS =       ARRAY CONTAINING THE INDICES OF A SEQUENCE OF	*/
+    /* 		 NODES TO BE USED IN THE LEAST SQUARES FIT				*/
+    /* 		 OR TO COMPUTE RSQ.  THE NODES ARE ORDERED				*/
+    /* 		 BY DISTANCE FROM K AND THE LAST ELEMENT				*/
+    /*(USUALLY INDEXED BY LNP) IS USED ONLY TO						*/
+    /* 		 DETERMINE RQ, OR RSQ(K) IF NW .GT. NQ					*/
+    /* NQWMAX =     MAX(NQ, NW)										*/
+    /* RQ =	       RADIUS OF INFLUENCE WHICH ENTERS INTO THE		*/
+    /* 		 WEIGHTS FOR Q(K)(SEE SUBROUTINE SETUP2)				*/
+    /* RS =	       SQUARED DISTANCE BETWEEN K AND NPTS(LNP) --		*/
+    /* 		 USED TO COMPUTE RQ AND RSQ(K)							*/
+    /* RSMX =       MAXIMUM RSQ ELEMENT ENCOUNTERED					*/
+    /* RSOLD =      SQUARED DISTANCE BETWEEN K AND NPTS(LNP - 1) -- */
+    /* 		 USED TO COMPUTE A RELATIVE CHANGE IN RS				*/
+    /* 		 BETWEEN SUCCEEDING NPTS ELEMENTS						*/
+    /* RTOL =       TOLERANCE FOR DETECTING A SUFFICIENTLY LARGE	*/
+    /* 		 RELATIVE CHANGE IN RS.  IF THE CHANGE IS				*/
+    /* 		 NOT GREATER THAN RTOL, THE NODES ARE					*/
+    /* 		 TREATED AS BEING THE SAME DISTANCE FROM K				*/
+    /* RWS =        CURRENT VALUE OF RSQ(K)							*/
+    /* S =	       SECOND COMPONENT OF THE PLANE GIVENS ROTATION	*/
+    /* SF =	       MARQUARDT STABILIZATION FACTOR USED TO DAMP		*/
+    /* 		 OUT THE FIRST 3 SOLUTION COMPONENTS(SECOND				*/
+    /* 		 PARTIALS OF THE QUADRATIC) WHEN THE SYSTEM				*/
+    /* 		 IS ILL - CONDITIONED.  AS SF INCREASES, THE			*/
+    /* 		 FITTING FUNCTION APPROACHES A LINEAR					*/
+    /* SUM =        SUM OF SQUARED EUCLIDEAN DISTANCES BETWEEN		*/
+    /* 		 NODE K AND THE NODES USED IN THE LEAST					*/
+    /* 		 SQUARES FIT(UNLESS ADDITIONAL NODES ARE				*/
+    /* 		 ADDED FOR STABILITY)									*/
+    /* T =	       TEMPORARY VARIABLE FOR ACCUMULATING A SCALAR		*/
+    /* 		 PRODUCT IN THE BACK SOLVE								*/
+    /* XK, YK =      COORDINATES OF NODE K -- X(K), Y(K)			*/
+    /* XMN, YMN =    LOCAL VARIABLES FOR XMIN AND YMIN				*/
+
+    nn = *n;
+    nnq = *nq;
+    nnw = *nw;
+    nnr = *nr;
+    nqwmax = max(nnq, nnw);
+    /* Computing MIN */
+    i__1 = 40, i__2 = nn - 1;
+    lmax = min(i__1, i__2);
+    if (5 > nnq || 1 > nnw || nqwmax > lmax || nnr < 1)
+    {
+        goto L20;
+    }
+
+    /* CREATE THE CELL DATA STRUCTURE, AND INITIALIZE RSMX. */
+
+    store2_(&nn, &x[1], &y[1], &nnr, &lcell[lcell_offset], &lnext[1], &xmn, &
+            ymn, &ddx, &ddy, &ierr);
+    if (ierr != 0)
+    {
+        goto L22;
+    }
+    rsmx = 0.f;
+
+    /* OUTER LOOP ON NODE K */
+
+    i__1 = nn;
+    for (k = 1; k <= i__1; ++k)
+    {
+        xk = x[k];
+        yk = y[k];
+        fk = f[k];
+
+        /* MARK NODE K TO EXCLUDE IT FROM THE SEARCH FOR NEAREST */
+        /*   NEIGHBORS. */
+
+        lnext[k] = -lnext[k];
+
+        /* INITIALIZE FOR LOOP ON NPTS. */
+
+        rs = 0.f;
+        sum = 0.f;
+        rws = 0.f;
+        rq = 0.f;
+        lnp = 0;
+
+        /* COMPUTE NPTS, LNP, RWS, NEQ, RQ, AND AVSQ. */
+
+    L1:
+        sum += rs;
+        if (lnp == lmax)
+        {
+            goto L3;
+        }
+        ++lnp;
+        rsold = rs;
+        getnp2_(&xk, &yk, &x[1], &y[1], &nnr, &lcell[lcell_offset], &lnext[1],
+                &xmn, &ymn, &ddx, &ddy, &np, &rs);
+        if (rs == 0.f)
+        {
+            goto L21;
+        }
+        npts[lnp - 1] = np;
+        if ((rs - rsold) / rs < rtol)
+        {
+            goto L1;
+        }
+        if (rws == 0.f && lnp > nnw)
+        {
+            rws = rs;
+        }
+        if (rq != 0.f || lnp <= nnq)
+        {
+            goto L2;
+        }
+
+        /*   RQ = 0(NOT YET COMPUTED) AND LNP .GT. NQ.	RQ = */
+        /*     SQRT(RS) IS SUFFICIENTLY LARGE TO(STRICTLY) INCLUDE */
+        /*     NQ NODES.  THE LEAST SQUARES FIT WILL INCLUDE NEQ = */
+        /*     LNP - 1 EQUATIONS FOR 5 .LE. NQ .LE. NEQ .LT. LMAX */
+        /*     .LE. N - 1. */
+
+        neq = lnp - 1;
+        rq = sqrt(rs);
+        avsq = sum / (double) neq;
+
+        /*   BOTTOM OF LOOP -- TEST FOR TERMINATION. */
+
+    L2:
+        if (lnp > nqwmax)
+        {
+            goto L4;
+        }
+        goto L1;
+
+        /* ALL LMAX NODES ARE INCLUDED IN NPTS.	RWS AND/OR RQ**2 IS */
+        /*(ARBITRARILY) TAKEN TO BE 10 PERCENT LARGER THAN THE */
+        /*   DISTANCE RS TO THE LAST NODE INCLUDED. */
+
+    L3:
+        if (rws == 0.f)
+        {
+            rws = rs * 1.1f;
+        }
+        if (rq != 0.f)
+        {
+            goto L4;
+        }
+        neq = lmax;
+        rq = sqrt(rs * 1.1f);
+        avsq = sum / (double) neq;
+
+        /* STORE RSQ(K), UPDATE RSMX IF NECESSARY, AND COMPUTE AV. */
+
+    L4:
+        rsq[k] = rws;
+        if (rws > rsmx)
+        {
+            rsmx = rws;
+        }
+        av = sqrt(avsq);
+
+        /* SET UP THE AUGMENTED REGRESSION MATRIX(TRANSPOSED) AS THE */
+        /*   COLUMNS OF B, AND ZERO OUT THE LOWER TRIANGLE(UPPER */
+        /*   TRIANGLE OF B) WITH GIVENS ROTATIONS -- QR DECOMPOSITION */
+        /*   WITH ORTHOGONAL MATRIX Q NOT STORED. */
+
+        i__ = 0;
+    L5:
+        ++i__;
+        np = npts[i__ - 1];
+        irow = min(i__, 6);
+        setup2_(&xk, &yk, &fk, &x[np], &y[np], &f[np], &av, &avsq, &rq, &b[
+                    irow * 6 - 6]);
+        if (i__ == 1)
+        {
+            goto L5;
+        }
+        irm1 = irow - 1;
+        i__2 = irm1;
+        for (j = 1; j <= i__2; ++j)
+        {
+            jp1 = j + 1;
+            givens_(&b[j + j * 6 - 7], &b[j + irow * 6 - 7], &c__, &s);
+            /* L6: */
+            i__3 = 6 - j;
+            rotate_(&i__3, &c__, &s, &b[jp1 + j * 6 - 7], &b[jp1 + irow * 6 -
+                    7]);
+        }
+        if (i__ < neq)
+        {
+            goto L5;
+        }
+
+        /* TEST THE SYSTEM FOR ILL - CONDITIONING. */
+
+        /* Computing MIN */
+        r__1 = dabs(b[0]), r__2 = dabs(b[7]), r__1 = min(r__1, r__2), r__2 =
+                                      dabs(b[14]), r__1 = min(r__1, r__2), r__2 = dabs(b[21]), r__1 =
+                                                              min(r__1, r__2), r__2 = dabs(b[28]);
+        dmin__ = dmin(r__1, r__2);
+        if (dmin__ * rq >= dtol)
+        {
+            goto L13;
+        }
+        if (neq == lmax)
+        {
+            goto L10;
+        }
+
+        /* INCREASE RQ AND ADD ANOTHER EQUATION TO THE SYSTEM TO */
+        /*   IMPROVE THE CONDITIONING.  THE NUMBER OF NPTS ELEMENTS */
+        /*   IS ALSO INCREASED IF NECESSARY. */
+
+    L7:
+        rsold = rs;
+        ++neq;
+        if (neq == lmax)
+        {
+            goto L9;
+        }
+        if (neq == lnp)
+        {
+            goto L8;
+        }
+
+        /*   NEQ .LT. LNP */
+
+        np = npts[neq];
+        /* Computing 2nd power */
+        r__1 = x[np] - xk;
+        /* Computing 2nd power */
+        r__2 = y[np] - yk;
+        rs = r__1 * r__1 + r__2 * r__2;
+        if ((rs - rsold) / rs < rtol)
+        {
+            goto L7;
+        }
+        rq = sqrt(rs);
+        goto L5;
+
+        /*   ADD AN ELEMENT TO NPTS. */
+
+    L8:
+        ++lnp;
+        getnp2_(&xk, &yk, &x[1], &y[1], &nnr, &lcell[lcell_offset], &lnext[1],
+                &xmn, &ymn, &ddx, &ddy, &np, &rs);
+        if (np == 0)
+        {
+            goto L21;
+        }
+        npts[lnp - 1] = np;
+        if ((rs - rsold) / rs < rtol)
+        {
+            goto L7;
+        }
+        rq = sqrt(rs);
+        goto L5;
+
+    L9:
+        rq = sqrt(rs * 1.1f);
+        goto L5;
+
+        /* STABILIZE THE SYSTEM BY DAMPING SECOND PARTIALS -- ADD */
+        /*   MULTIPLES OF THE FIRST THREE UNIT VECTORS TO THE FIRST */
+        /*   THREE EQUATIONS. */
+
+    L10:
+        for (i__ = 1; i__ <= 3; ++i__)
+        {
+            b[i__ + 29] = sf;
+            ip1 = i__ + 1;
+            for (j = ip1; j <= 6; ++j)
+            {
+                /* L11: */
+                b[j + 29] = 0.f;
+            }
+            for (j = i__; j <= 5; ++j)
+            {
+                jp1 = j + 1;
+                givens_(&b[j + j * 6 - 7], &b[j + 29], &c__, &s);
+                /* L12: */
+                i__3 = 6 - j;
+                rotate_(&i__3, &c__, &s, &b[jp1 + j * 6 - 7], &b[jp1 + 29]);
+            }
+        }
+
+        /* TEST THE STABILIZED SYSTEM FOR ILL - CONDITIONING. */
+
+        /* Computing MIN */
+        r__1 = dabs(b[0]), r__2 = dabs(b[7]), r__1 = min(r__1, r__2), r__2 =
+                                      dabs(b[14]), r__1 = min(r__1, r__2), r__2 = dabs(b[21]), r__1 =
+                                                              min(r__1, r__2), r__2 = dabs(b[28]);
+        dmin__ = dmin(r__1, r__2);
+        if (dmin__ * rq < dtol)
+        {
+            goto L22;
+        }
+
+        /* SOLVE THE 5 BY 5 TRIANGULAR SYSTEM FOR THE COEFFICIENTS */
+
+    L13:
+        for (ib = 1; ib <= 5; ++ib)
+        {
+            i__ = 6 - ib;
+            t = 0.f;
+            if (i__ == 5)
+            {
+                goto L15;
+            }
+            ip1 = i__ + 1;
+            for (j = ip1; j <= 5; ++j)
+            {
+                /* L14: */
+                t += b[j + i__ * 6 - 7] * a[j + k * 5];
+            }
+        L15:
+            a[i__ + k * 5] = (b[i__ * 6 - 1] - t) / b[i__ + i__ * 6 - 7];
+        }
+
+        /* SCALE THE COEFFICIENTS TO ADJUST FOR THE COLUMN SCALING. */
+
+        for (i__ = 1; i__ <= 3; ++i__)
+        {
+            /* L16: */
+            a[i__ + k * 5] /= avsq;
+        }
+        a[k * 5 + 4] /= av;
+        a[k * 5 + 5] /= av;
+
+        /* UNMARK K AND THE ELEMENTS OF NPTS. */
+
+        lnext[k] = -lnext[k];
+        i__3 = lnp;
+        for (i__ = 1; i__ <= i__3; ++i__)
+        {
+            np = npts[i__ - 1];
+            /* L17: */
+            lnext[np] = -lnext[np];
+        }
+        /* L18: */
+    }
+
+    /* NO ERRORS ENCOUNTERED. */
+
+    *xmin = xmn;
+    *ymin = ymn;
+    *dx = ddx;
+    *dy = ddy;
+    *rmax = sqrt(rsmx);
+    *ier = 0;
+    return 0;
+
+    /* N, NQ, NW, OR NR IS OUT OF RANGE. */
+
+L20:
+    *ier = 1;
+    return 0;
+
+    /* DUPLICATE NODES WERE ENCOUNTERED BY GETNP2. */
+
+L21:
+    *ier = 2;
+    return 0;
+
+    /* NO UNIQUE SOLUTION DUE TO COLLINEAR NODES. */
+
+L22:
+    *xmin = xmn;
+    *ymin = ymn;
+    *dx = ddx;
+    *dy = ddy;
+    *ier = 3;
+    return 0;
+} /* qshep2_ */
+
+double qs2val_(double *px, double *py, int *n, double *x, double *y, double *f,
+                   int *nr, int *lcell, int *lnext, double *xmin, double *ymin,
+                   double *dx, double *dy, double *rmax, double *rsq, double *a)
+{
+    int lcell_dim1, lcell_offset, i__1, i__2;
+    double ret_val;
+
+//    double sqrt(double);
+
+    static int i__, j, k;
+    static double w, rd, ds;
+    static int kp;
+    static double rs, xp, yp, sw, rds, swq;
+    static int imin, jmin, imax, jmax;
+    static double delx, dely, dxsq, dysq;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+    /* 						    10/28/87							*/
+	/*																*/
+    /*   THIS FUNCTION RETURNS THE VALUE Q(PX, PY) WHERE Q IS THE	*/
+    /* WEIGHTED SUM OF QUADRATIC NODAL FUNCTIONS DEFINED IN SUB-	*/
+    /* ROUTINE QSHEP2.  QS2GRD MAY BE CALLED TO COMPUTE A GRADI-	*/
+    /* ENT OF Q ALONG WITH THE VALUE, AND/OR TO TEST FOR ERRORS.	*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	PX, PY = CARTESIAN COORDINATES OF THE POINT P AT			*/
+    /* 		WHICH Q IS TO BE EVALUATED.								*/
+	/*																*/
+    /* 	N = NUMBER OF NODES AND DATA VALUES DEFINING Q.				*/
+    /* 	    N .GE. 6.												*/
+	/*																*/
+    /* 	X, Y, F = ARRAYS OF LENGTH N CONTAINING THE NODES AND		*/
+    /* 		DATA VALUES INTERPOLATED BY Q.							*/
+	/*																*/
+    /* 	NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.			*/
+    /* 	     REFER TO STORE2.  NR .GE. 1.							*/
+	/*																*/
+    /* 	LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED			*/
+    /* 		WITH CELLS.  REFER TO STORE2.							*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF LENGTH N CONTAINING NEXT - NODE INDI-		*/
+    /* 		CES.  REFER TO STORE2.									*/
+	/*																*/
+    /* 	XMIN, YMIN, DX, DY = MINIMUM NODAL COORDINATES AND CELL		*/
+    /* 			  DIMENSIONS.  DX AND DY MUST BE					*/
+    /* 			  POSITIVE.  REFER TO STORE2.						*/
+	/*																*/
+    /* 	RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --			*/
+    /* 	       MAXIMUM RADIUS.										*/
+	/*																*/
+    /* 	RSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII		*/
+    /* 	      WHICH ENTER INTO THE WEIGHTS DEFINING Q.				*/
+	/*																*/
+    /* 	A = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE		*/
+    /* 	    NODAL FUNCTIONS DEFINING Q.								*/
+	/*																*/
+    /*   INPUT PARAMETERS ARE NOT ALTERED BY THIS FUNCTION.	THE		*/
+    /* PARAMETERS OTHER THAN PX AND PY SHOULD BE INPUT UNALTERED	*/
+    /* FROM THEIR VALUES ON OUTPUT FROM QSHEP2.  THIS FUNCTION		*/
+    /* SHOULD NOT BE CALLED IF A NONZERO ERROR FLAG WAS RETURNED	*/
+    /* BY QSHEP2.													*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	QS2VAL = FUNCTION VALUE Q(PX, PY) UNLESS N, NR, DX,			*/
+    /* 		 DY, OR RMAX IS INVALID, IN WHICH CASE NO				*/
+    /* 		 VALUE IS RETURNED.										*/
+	/*																*/
+    /* MODULES REQUIRED BY QS2VAL -- NONE							*/
+	/*																*/
+    /* INTRINSIC FUNCTIONS CALLED BY QS2VAL -- IFIX, SQRT			*/
+	/*																*/
+    /****************************************************************/
+
+    /* Parameter adjustments										*/
+    a -= 6;
+    --rsq;
+    --lnext;
+    --f;
+    --y;
+    --x;
+    lcell_dim1 = *nr;
+    lcell_offset = 1 + lcell_dim1;
+    lcell -= lcell_offset;
+
+    /* Function Body */
+    xp = *px;
+    yp = *py;
+    if (*n < 6 || *nr < 1 || *dx <= 0.f || *dy <= 0.f || *rmax < 0.f)
+    {
+        return _missing_;
+    }
+
+    /* SET IMIN, IMAX, JMIN, AND JMAX TO CELL INDICES DEFINING */
+    /*   THE RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE */
+    /*   P.	THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTER- */
+    /*   SECTED BY(OR CONTAINED IN) A CIRCLE OF RADIUS RMAX */
+    /*   CENTERED AT P. */
+
+    imin = (int)((xp - *xmin - *rmax) / *dx) + 1;
+    imax = (int)((xp - *xmin + *rmax) / *dx) + 1;
+    if (imin < 1)
+    {
+        imin = 1;
+    }
+    if (imax > *nr)
+    {
+        imax = *nr;
+    }
+    jmin = (int)((yp - *ymin - *rmax) / *dy) + 1;
+    jmax = (int)((yp - *ymin + *rmax) / *dy) + 1;
+    if (jmin < 1)
+    {
+        jmin = 1;
+    }
+    if (jmax > *nr)
+    {
+        jmax = *nr;
+    }
+
+    /* THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE CIRCLE */
+    /*   OF RADIUS RMAX. */
+
+    if (imin > imax || jmin > jmax)
+    {
+        goto L5;
+    }
+
+    /* ACCUMULATE WEIGHT VALUES IN SW AND WEIGHTED NODAL FUNCTION */
+    /*   VALUES IN SWQ.  THE WEIGHTS ARE W(K) =((R - D)+/(R*D))**2 */
+    /*   FOR R**2 = RSQ(K) AND D = DISTANCE BETWEEN P AND NODE K. */
+
+    sw = 0.f;
+    swq = 0.f;
+
+    /* OUTER LOOP ON CELLS(I, J). */
+
+    i__1 = jmax;
+    for (j = jmin; j <= i__1; ++j)
+    {
+        i__2 = imax;
+        for (i__ = imin; i__ <= i__2; ++i__)
+        {
+            k = lcell[i__ + j * lcell_dim1];
+            if (k == 0)
+            {
+                goto L3;
+            }
+
+            /* INNER LOOP ON NODES K. */
+
+        L1:
+            delx = xp - x[k];
+            dely = yp - y[k];
+            dxsq = delx * delx;
+            dysq = dely * dely;
+            ds = dxsq + dysq;
+            rs = rsq[k];
+            if (ds >= rs)
+            {
+                goto L2;
+            }
+            if (ds == 0.f)
+            {
+                goto L4;
+            }
+            rds = rs * ds;
+            rd = sqrt(rds);
+            w = (rs + ds - rd - rd) / rds;
+            sw += w;
+            swq += w * (a[k * 5 + 1] * dxsq + a[k * 5 + 2] * delx * dely + a[
+                            k * 5 + 3] * dysq + a[k * 5 + 4] * delx + a[k * 5 + 5] *
+                        dely + f[k]);
+
+            /* BOTTOM OF LOOP ON NODES IN CELL(I, J). */
+
+        L2:
+            kp = k;
+            k = lnext[kp];
+            if (k != kp)
+            {
+                goto L1;
+            }
+        L3:
+            ;
+        }
+    }
+
+    /* SW = 0 IFF P IS NOT WITHIN THE RADIUS R(K) FOR ANY NODE K. */
+
+    if (sw == 0.f)
+    {
+        goto L5;
+    }
+    ret_val = swq / sw;
+    return ret_val;
+
+    /*(PX, PY) =(X(K), Y(K)) */
+
+L4:
+    ret_val = f[k];
+    return ret_val;
+
+    /* ALL WEIGHTS ARE 0 AT P. */
+
+L5:
+    ret_val = _missing_;
+    return ret_val;
+} 
+
+int qs2grd_(double *px,   double *py,   int *n,   double *x,   double *y,
+                             double *f, int *nr, int *lcell, int *lnext, double *xmin,
+                             double *ymin, double *dx, double *dy, double *rmax, double *rsq, double *a, double *
+                             q, double *qx, double *qy, int *ier)
+{
+    int lcell_dim1, lcell_offset, i__1, i__2;
+
+//    double sqrt(double);
+
+    static int i__, j, k;
+    static double t, w, rd, ds;
+    static int kp;
+    static double qk, rs, xp, yp, sw, wx, wy, rds, qkx, qky, swq, sws, swx, swy;
+    static int imin, jmin, imax, jmax;
+    static double delx, dely, dxsq, dysq, swqx, swqy;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+    /* 						    10/28/87							*/
+	/*																*/
+    /*   THIS SUBROUTINE COMPUTES THE VALUE AND GRADIENT AT			*/
+    /*(PX, PY) OF THE INTERPOLATORY FUNCTION Q DEFINED IN SUB-		*/
+    /* ROUTINE QSHEP2.  Q(X, Y) IS A WEIGHTED SUM OF QUADRATIC		*/
+    /* NODAL FUNCTIONS.												*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	PX, PY = CARTESIAN COORDINATES OF THE POINT AT WHICH		*/
+    /* 		Q AND ITS PARTIALS ARE TO BE EVALUATED.					*/
+	/*																*/
+    /* 	N = NUMBER OF NODES AND DATA VALUES DEFINING Q.				*/
+    /* 	    N .GE. 6.												*/
+	/*																*/
+    /* 	X, Y, F = ARRAYS OF LENGTH N CONTAINING THE NODES AND		*/
+    /* 		DATA VALUES INTERPOLATED BY Q.							*/
+	/*																*/
+    /* 	NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.			*/
+    /* 	     REFER TO STORE2.  NR .GE. 1.							*/
+	/*																*/
+    /* 	LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED			*/
+    /* 		WITH CELLS.  REFER TO STORE2.							*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF LENGTH N CONTAINING NEXT - NODE INDI-		*/
+    /* 		CES.  REFER TO STORE2.									*/
+	/*																*/
+    /* 	XMIN, YMIN, DX, DY = MINIMUM NODAL COORDINATES AND CELL		*/
+    /* 			  DIMENSIONS.  DX AND DY MUST BE					*/
+    /* 			  POSITIVE.  REFER TO STORE2.						*/
+	/*																*/
+    /* 	RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --			*/
+    /* 	       MAXIMUM RADIUS.										*/
+	/*																*/
+    /* 	RSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII		*/
+    /* 	      WHICH ENTER INTO THE WEIGHTS DEFINING Q.				*/
+	/*																*/
+    /* 	A = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE		*/
+    /* 	    NODAL FUNCTIONS DEFINING Q.								*/
+	/*																*/
+    /*   INPUT PARAMETERS ARE NOT ALTERED BY THIS SUBROUTINE.		*/
+    /* THE PARAMETERS OTHER THAN PX AND PY SHOULD BE INPUT UNAL-	*/
+    /* TERED FROM THEIR VALUES ON OUTPUT FROM QSHEP2.  THIS SUB-	*/
+    /* ROUTINE SHOULD NOT BE CALLED IF A NONZERO ERROR FLAG WAS		*/
+    /* RETURNED BY QSHEP2.											*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	Q = VALUE OF Q AT(PX, PY) UNLESS IER .EQ. 1, IN				*/
+    /* 	    WHICH CASE NO VALUES ARE RETURNED.						*/
+	/*																*/
+    /* 	QX, QY = FIRST PARTIAL DERIVATIVES OF Q AT(PX, PY)			*/
+    /* 		UNLESS IER .EQ. 1.										*/
+	/*																*/
+    /* 	IER = ERROR INDICATOR										*/
+    /* 	      IER = 0 IF NO ERRORS WERE ENCOUNTERED.				*/
+    /* 	      IER = 1 IF N, NR, DX, DY OR RMAX IS INVALID.			*/
+    /* 	      IER = 2 IF NO ERRORS WERE ENCOUNTERED BUT				*/
+    /*(PX, PY) IS NOT WITHIN THE RADIUS R(K)						*/
+    /* 		      FOR ANY NODE K(AND THUS Q = QX = QY = 0).			*/
+	/*																*/
+    /* MODULES REQUIRED BY QS2GRD -- NONE							*/
+	/*																*/
+    /* INTRINSIC FUNCTIONS CALLED BY QS2GRD -- IFIX, SQRT			*/
+	/*																*/
+    /* **************************************************************/
+
+    a -= 6;
+    --rsq;
+    --lnext;
+    --f;
+    --y;
+    --x;
+    lcell_dim1 = *nr;
+    lcell_offset = 1 + lcell_dim1;
+    lcell -= lcell_offset;
+
+    xp = *px;
+    yp = *py;
+    if (*n < 6 || *nr < 1 || *dx <= 0.f || *dy <= 0.f || *rmax < 0.f)
+    {
+        goto L5;
+    }
+
+    /* SET IMIN, IMAX, JMIN, AND JMAX TO CELL INDICES DEFINING */
+    /*   THE RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE */
+    /*   P.	THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTER- */
+    /*   SECTED BY(OR CONTAINED IN) A CIRCLE OF RADIUS RMAX */
+    /*   CENTERED AT P. */
+
+    imin = (int)((xp - *xmin - *rmax) / *dx) + 1;
+    imax = (int)((xp - *xmin + *rmax) / *dx) + 1;
+    if (imin < 1)
+    {
+        imin = 1;
+    }
+    if (imax > *nr)
+    {
+        imax = *nr;
+    }
+    jmin = (int)((yp - *ymin - *rmax) / *dy) + 1;
+    jmax = (int)((yp - *ymin + *rmax) / *dy) + 1;
+    if (jmin < 1)
+    {
+        jmin = 1;
+    }
+    if (jmax > *nr)
+    {
+        jmax = *nr;
+    }
+
+    /* THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE CIRCLE */
+    /*   OF RADIUS RMAX. */
+
+    if (imin > imax || jmin > jmax)
+    {
+        goto L6;
+    }
+
+    /* Q = SWQ/SW = SUM(W(K)*Q(K))/SUM(W(K)) WHERE THE SUM IS */
+    /*   FROM K = 1 TO N, Q(K) IS THE QUADRATIC NODAL FUNCTION, */
+    /*   AND W(K) =((R - D)+/(R*D))**2 FOR RADIUS R(K) AND DIST- */
+    /*   ANCE D(K).	THUS */
+
+    /* 	 QX =(SWQX*SW - SWQ*SWX)/SW**2  AND */
+    /* 	 QY =(SWQY*SW - SWQ*SWY)/SW**2 */
+
+    /*   WHERE SWQX AND SWX ARE PARTIAL DERIVATIVES WITH RESPECT */
+    /*   TO X OF SWQ AND SW, RESPECTIVELY.  SWQY AND SWY ARE DE- */
+    /*   FINED SIMILARLY. */
+
+    sw = 0.f;
+    swx = 0.f;
+    swy = 0.f;
+    swq = 0.f;
+    swqx = 0.f;
+    swqy = 0.f;
+
+    /* OUTER LOOP ON CELLS(I, J). */
+
+    i__1 = jmax;
+    for (j = jmin; j <= i__1; ++j)
+    {
+        i__2 = imax;
+        for (i__ = imin; i__ <= i__2; ++i__)
+        {
+            k = lcell[i__ + j * lcell_dim1];
+            if (k == 0)
+            {
+                goto L3;
+            }
+
+            /* INNER LOOP ON NODES K. */
+
+        L1:
+            delx = xp - x[k];
+            dely = yp - y[k];
+            dxsq = delx * delx;
+            dysq = dely * dely;
+            ds = dxsq + dysq;
+            rs = rsq[k];
+            if (ds >= rs)
+            {
+                goto L2;
+            }
+            if (ds == 0.f)
+            {
+                goto L4;
+            }
+            rds = rs * ds;
+            rd = sqrt(rds);
+            w = (rs + ds - rd - rd) / rds;
+            t = (rd - rs) * 2.f / (ds * rds);
+            wx = delx * t;
+            wy = dely * t;
+            qkx = a[k * 5 + 1] * 2.f * delx + a[k * 5 + 2] * dely;
+            qky = a[k * 5 + 2] * delx + a[k * 5 + 3] * 2.f * dely;
+            qk = (qkx * delx + qky * dely) / 2.f;
+            qkx += a[k * 5 + 4];
+            qky += a[k * 5 + 5];
+            qk = qk + a[k * 5 + 4] * delx + a[k * 5 + 5] * dely + f[k];
+            sw += w;
+            swx += wx;
+            swy += wy;
+            swq += w * qk;
+            swqx = swqx + wx * qk + w * qkx;
+            swqy = swqy + wy * qk + w * qky;
+
+            /* BOTTOM OF LOOP ON NODES IN CELL(I, J). */
+
+        L2:
+            kp = k;
+            k = lnext[kp];
+            if (k != kp)
+            {
+                goto L1;
+            }
+        L3:
+            ;
+        }
+    }
+
+    /* SW = 0 IFF P IS NOT WITHIN THE RADIUS R(K) FOR ANY NODE K. */
+
+    if (sw == 0.f)
+    {
+        goto L6;
+    }
+    *q = swq / sw;
+    sws = sw * sw;
+    *qx = (swqx * sw - swq * swx) / sws;
+    *qy = (swqy * sw - swq * swy) / sws;
+    *ier = 0;
+    return 0;
+
+    /*(PX, PY) =(X(K), Y(K)) */
+
+L4:
+    *q = f[k];
+    *qx = a[k * 5 + 4];
+    *qy = a[k * 5 + 5];
+    *ier = 0;
+    return 0;
+
+    /* INVALID INPUT PARAMETER. */
+
+L5:
+    *ier = 1;
+    return 0;
+
+    /* NO CELLS CONTAIN A POINT WITHIN RMAX OF P, OR */
+    /*   SW = 0 AND THUS DS .GE. RSQ(K) FOR ALL K. */
+
+L6:
+    *q = 0.f;
+    *qx = 0.f;
+    *qy = 0.f;
+    *ier = 2;
+    return 0;
+} /* qs2grd_ */
+
+/* Subroutine */ int getnp2_(double *px,   double *py,   double *x,   double *y,   int *
+                             nr, int *lcell, int *lnext, double *xmin, double *ymin, double *dx,
+                             double *dy, int *np, double *dsq)
+{
+    int lcell_dim1, lcell_offset, i__1, i__2;
+    double r__1, r__2;
+
+//    double sqrt(double);
+
+    static int i__, j, l;
+    static double r__;
+    static int i0, j0, i1, i2, j1, j2, ln;
+    static double xp, yp, rsq;
+    static int imin, jmin, imax, jmax;
+    static double delx, dely;
+    static int lmin;
+    static bool first;
+    static double rsmin;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+	/*																*/
+    /*   GIVEN A SET OF N NODES AND THE DATA STRUCTURE DEFINED IN	*/
+    /* SUBROUTINE STORE2, THIS SUBROUTINE USES THE CELL METHOD TO	*/
+    /* FIND THE CLOSEST UNMARKED NODE NP TO A SPECIFIED POINT P.	*/
+    /* NP IS THEN MARKED BY SETTING LNEXT(NP) TO -LNEXT(NP).(A		*/
+    /* NODE IS MARKED IF AND ONLY IF THE CORRESPONDING LNEXT ELE-	*/
+    /* MENT IS NEGATIVE.  THE ABSOLUTE VALUES OF LNEXT ELEMENTS,	*/
+    /* HOWEVER, MUST BE PRESERVED.)	THUS, THE CLOSEST M NODES TO	*/
+    /* P MAY BE DETERMINED BY A SEQUENCE OF M CALLS TO THIS ROU-	*/
+    /* TINE.  NOTE THAT IF THE NEAREST NEIGHBOR TO NODE K IS TO		*/
+    /* BE DETERMINED(PX = X(K) AND PY = Y(K)), THEN K SHOULD BE		*/
+    /* MARKED BEFORE THE CALL TO THIS ROUTINE.						*/
+    /*   THE SEARCH IS BEGUN IN THE CELL CONTAINING(OR CLOSEST		*/
+    /* TO) P AND PROCEEDS OUTWARD IN RECTANGULAR LAYERS UNTIL ALL	*/
+    /* CELLS WHICH CONTAIN POINTS WITHIN DISTANCE R OF P HAVE		*/
+    /* BEEN SEARCHED, WHERE R IS THE DISTANCE FROM P TO THE FIRST	*/
+    /* UNMARKED NODE ENCOUNTERED(INFINITE IF NO UNMARKED NODES		*/
+    /* ARE PRESENT).												*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	PX, PY = CARTESIAN COORDINATES OF THE POINT P WHOSE			*/
+    /* 		NEAREST UNMARKED NEIGHBOR IS TO BE FOUND.				*/
+	/*																*/
+    /* 	X, Y = ARRAYS OF LENGTH N, FOR N .GE. 2, CONTAINING			*/
+    /* 	      THE CARTESIAN COORDINATES OF THE NODES.				*/
+	/*																*/
+    /* 	NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.			*/
+    /* 	     NR .GE. 1.												*/
+	/*																*/
+    /* 	LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED			*/
+    /* 		WITH CELLS.												*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF LENGTH N CONTAINING NEXT - NODE INDI-		*/
+    /* 		CES(OR THEIR NEGATIVES).								*/
+	/*																*/
+    /* 	XMIN, YMIN, DX, DY = MINIMUM NODAL COORDINATES AND CELL		*/
+    /* 			  DIMENSIONS.  DX AND DY MUST BE					*/
+    /* 			  POSITIVE.											*/
+	/*																*/
+    /*   INPUT PARAMETERS OTHER THAN LNEXT ARE NOT ALTERED BY		*/
+    /* THIS ROUTINE.  WITH THE EXCEPTION OF(PX, PY) AND THE SIGNS	*/
+    /* OF LNEXT ELEMENTS, THESE PARAMETERS SHOULD BE UNALTERED		*/
+    /* FROM THEIR VALUES ON OUTPUT FROM SUBROUTINE STORE2.			*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	NP = INDEX(FOR X AND Y) OF THE NEAREST UNMARKED				*/
+    /* 	     NODE TO P, OR 0 IF ALL NODES ARE MARKED OR NR			*/
+    /* 	     .LT. 1 OR DX .LE. 0 OR DY .LE. 0.	LNEXT(NP)			*/
+    /* 	     .LT. 0 IF NP .NE. 0.									*/
+	/*																*/
+    /* 	DSQ = SQUARED EUCLIDEAN DISTANCE BETWEEN P AND NODE			*/
+    /* 	      NP, OR 0 IF NP = 0.									*/
+	/*																*/
+    /* MODULES REQUIRED BY GETNP2 -- NONE							*/
+	/*																*/
+    /* INTRINSIC FUNCTIONS CALLED BY GETNP2 -- IABS, IFIX, SQRT		*/
+	/*																*/
+    /****************************************************************/
+
+    --x;
+    --y;
+    lcell_dim1 = *nr;
+    lcell_offset = 1 + lcell_dim1;
+    lcell -= lcell_offset;
+    --lnext;
+
+    xp = *px;
+    yp = *py;
+
+    /* TEST FOR INVALID INPUT PARAMETERS. */
+
+    if (*nr < 1 || *dx <= 0.f || *dy <= 0.f)
+    {
+        goto L9;
+    }
+
+    /* INITIALIZE PARAMETERS -- */
+
+    /*   FIRST = TRUE IFF THE FIRST UNMARKED NODE HAS YET TO BE */
+    /* 	    ENCOUNTERED, */
+    /*   IMIN, IMAX, JMIN, JMAX = CELL INDICES DEFINING THE RANGE OF */
+    /* 			  THE SEARCH, */
+    /*   DELX, DELY = PX - XMIN AND PY - YMIN, */
+    /*   I0, J0 = CELL CONTAINING OR CLOSEST TO P, */
+    /*   I1, I2, J1, J2 = CELL INDICES OF THE LAYER WHOSE INTERSEC- */
+    /* 		  TION WITH THE RANGE DEFINED BY IMIN,..., */
+    /* 		  JMAX IS CURRENTLY BEING SEARCHED. */
+
+    first = true;
+    imin = 1;
+    imax = *nr;
+    jmin = 1;
+    jmax = *nr;
+    delx = xp - *xmin;
+    dely = yp - *ymin;
+    i0 = (int)(delx / *dx) + 1;
+    if (i0 < 1)
+    {
+        i0 = 1;
+    }
+    if (i0 > *nr)
+    {
+        i0 = *nr;
+    }
+    j0 = (int)(dely / *dy) + 1;
+    if (j0 < 1)
+    {
+        j0 = 1;
+    }
+    if (j0 > *nr)
+    {
+        j0 = *nr;
+    }
+    i1 = i0;
+    i2 = i0;
+    j1 = j0;
+    j2 = j0;
+
+    /* OUTER LOOP ON LAYERS, INNER LOOP ON LAYER CELLS, EXCLUDING */
+    /*   THOSE OUTSIDE THE RANGE(IMIN, IMAX) X(JMIN, JMAX). */
+
+L1:
+    i__1 = j2;
+    for (j = j1; j <= i__1; ++j)
+    {
+        if (j > jmax)
+        {
+            goto L7;
+        }
+        if (j < jmin)
+        {
+            goto L6;
+        }
+        i__2 = i2;
+        for (i__ = i1; i__ <= i__2; ++i__)
+        {
+            if (i__ > imax)
+            {
+                goto L6;
+            }
+            if (i__ < imin)
+            {
+                goto L5;
+            }
+            if (j != j1 && j != j2 && i__ != i1 && i__ != i2)
+            {
+                goto L5;
+            }
+
+            /* SEARCH CELL(I, J) FOR UNMARKED NODES L. */
+
+            l = lcell[i__ + j * lcell_dim1];
+            if (l == 0)
+            {
+                goto L5;
+            }
+
+            /*   LOOP ON NODES IN CELL(I, J). */
+
+        L2:
+            ln = lnext[l];
+            if (ln < 0)
+            {
+                goto L4;
+            }
+
+            /*   NODE L IS NOT MARKED. */
+
+            /* Computing 2nd power */
+            r__1 = x[l] - xp;
+            /* Computing 2nd power */
+            r__2 = y[l] - yp;
+            rsq = r__1 * r__1 + r__2 * r__2;
+            if (! first)
+            {
+                goto L3;
+            }
+
+            /*   NODE L IS THE FIRST UNMARKED NEIGHBOR OF P ENCOUNTERED. */
+            /*     INITIALIZE LMIN TO THE CURRENT CANDIDATE FOR NP, AND */
+            /*     RSMIN TO THE SQUARED DISTANCE FROM P TO LMIN.  IMIN, */
+            /*     IMAX, JMIN, AND JMAX ARE UPDATED TO DEFINE THE SMAL- */
+            /*     LEST RECTANGLE CONTAINING A CIRCLE OF RADIUS R = */
+            /*     SQRT(RSMIN) CENTERED AT P, AND CONTAINED IN(1, NR) X */
+            /*(1, NR)(EXCEPT THAT, IF P IS OUTSIDE THE RECTANGLE */
+            /*     DEFINED BY THE NODES, IT IS POSSIBLE THAT IMIN .GT. */
+            /*     NR, IMAX .LT. 1, JMIN .GT. NR, OR JMAX .LT. 1).  FIRST */
+            /*     IS RESET TO FALSE. */
+
+            lmin = l;
+            rsmin = rsq;
+            r__ = sqrt(rsmin);
+            imin = (int)((delx - r__) / *dx) + 1;
+            if (imin < 1)
+            {
+                imin = 1;
+            }
+            imax = (int)((delx + r__) / *dx) + 1;
+            if (imax > *nr)
+            {
+                imax = *nr;
+            }
+            jmin = (int)((dely - r__) / *dy) + 1;
+            if (jmin < 1)
+            {
+                jmin = 1;
+            }
+            jmax = (int)((dely + r__) / *dy) + 1;
+            if (jmax > *nr)
+            {
+                jmax = *nr;
+            }
+            first = false;
+            goto L4;
+
+            /*   TEST FOR NODE L CLOSER THAN LMIN TO P. */
+
+        L3:
+            if (rsq >= rsmin)
+            {
+                goto L4;
+            }
+
+            /*   UPDATE LMIN AND RSMIN. */
+
+            lmin = l;
+            rsmin = rsq;
+
+            /*   TEST FOR TERMINATION OF LOOP ON NODES IN CELL(I, J). */
+
+        L4:
+            if (abs(ln) == l)
+            {
+                goto L5;
+            }
+            l = abs(ln);
+            goto L2;
+        L5:
+            ;
+        }
+    L6:
+        ;
+    }
+
+    /* TEST FOR TERMINATION OF LOOP ON CELL LAYERS. */
+
+L7:
+    if (i1 <= imin && i2 >= imax && j1 <= jmin && j2 >= jmax)
+    {
+        goto L8;
+    }
+    --i1;
+    ++i2;
+    --j1;
+    ++j2;
+    goto L1;
+
+    /* UNLESS NO UNMARKED NODES WERE ENCOUNTERED, LMIN IS THE */
+    /*   CLOSEST UNMARKED NODE TO P. */
+
+L8:
+    if (first)
+    {
+        goto L9;
+    }
+    *np = lmin;
+    *dsq = rsmin;
+    lnext[lmin] = -lnext[lmin];
+    return 0;
+
+    /* ERROR -- NR, DX, OR DY IS INVALID OR ALL NODES ARE MARKED. */
+
+L9:
+    *np = 0;
+    *dsq = 0.f;
+    return 0;
+} /* getnp2_ */
+
+/* Subroutine */ int givens_(double *a,   double *b,   double *c__,   double *s)
+{
+    /* Builtin functions */
+//    double sqrt(double);
+
+    /* Local variables */
+    static double r__, u, v, aa, bb;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+	/*																*/
+    /*   THIS ROUTINE CONSTRUCTS THE GIVENS PLANE ROTATION --		*/
+    /*(C  S)														*/
+    /* G =() WHERE C*C + S*S = 1 -- WHICH ZEROS THE SECOND			*/
+    /*(-S  C)														*/
+    /* ENTRY OF THE 2 - VECTOR(A B) - TRANSPOSE.  A CALL TO GIVENS	*/
+    /* IS NORMALLY FOLLOWED BY A CALL TO ROTATE WHICH APPLIES		*/
+    /* THE TRANSFORMATION TO A 2 BY N MATRIX.  THIS ROUTINE WAS		*/
+    /* TAKEN FROM LINPACK.											*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	A, B = COMPONENTS OF THE 2 - VECTOR TO BE ROTATED.			*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	A = VALUE OVERWRITTEN BY R = +/-SQRT(A*A + B*B)				*/
+	/*																*/
+    /* 	B = VALUE OVERWRITTEN BY A VALUE Z WHICH ALLOWS C			*/
+    /* 	    AND S TO BE RECOVERED AS FOLLOWS --						*/
+    /* 	      C = SQRT(1 - Z*Z), S = Z     IF ABS(Z) .LE. 1.		*/
+    /* 	      C = 1/Z, S = SQRT(1 - C*C) IF ABS(Z) .GT. 1.			*/
+	/*																*/
+    /* 	C = +/-(A/R)												*/
+	/*																*/
+    /* 	S = +/-(B/R)												*/
+	/*																*/
+    /* MODULES REQUIRED BY GIVENS -- NONE							*/
+	/*																*/
+    /* INTRINSIC FUNCTIONS CALLED BY GIVENS - ABS, SQRT				*/
+	/*																*/
+    /****************************************************************/
+
+
+    /* LOCAL PARAMETERS -- */
+
+    /* AA, BB = LOCAL COPIES OF A AND B */
+    /* R =	  C*A + S*B = +/-SQRT(A*A + B*B) */
+    /* U, V =   VARIABLES USED TO SCALE A AND B FOR COMPUTING R */
+
+    aa = *a;
+    bb = *b;
+    if (dabs(aa) <= dabs(bb))
+    {
+        goto L1;
+    }
+
+    /* ABS(A) .GT. ABS(B) */
+
+    u = aa + aa;
+    v = bb / u;
+    r__ = sqrt(v * v + .25f) * u;
+    *c__ = aa / r__;
+    *s = v * (*c__ + *c__);
+
+    /* NOTE THAT R HAS THE SIGN OF A, C .GT. 0, AND S HAS */
+    /*   SIGN(A)*SIGN(B). */
+
+    *b = *s;
+    *a = r__;
+    return 0;
+
+    /* ABS(A) .LE. ABS(B) */
+
+L1:
+    if (bb == 0.f)
+    {
+        goto L2;
+    }
+    u = bb + bb;
+    v = aa / u;
+
+    /* STORE R IN A. */
+
+    *a = sqrt(v * v + .25f) * u;
+    *s = bb / *a;
+    *c__ = v * (*s + *s);
+
+    /* NOTE THAT R HAS THE SIGN OF B, S .GT. 0, AND C HAS */
+    /*   SIGN(A)*SIGN(B). */
+
+    *b = 1.f;
+    if (*c__ != 0.f)
+    {
+        *b = 1.f / *c__;
+    }
+    return 0;
+
+    /* A = B = 0. */
+
+L2:
+    *c__ = 1.f;
+    *s = 0.f;
+    return 0;
+} /* givens_ */
+
+int rotate_(int *n,   double *c__,   double *s,   double *x,   double *y)
+{
+    int i__1;
+
+    static int i__;
+    static double xi, yi;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+	/*																*/
+    /*(C  S)														*/
+    /*   THIS ROUTINE APPLIES THE GIVENS ROTATION() TO THE			*/
+    /*(-S  C)														*/
+    /*(X(1) ... X(N))												*/
+    /* 2 BY N MATRIX().												*/
+    /*(Y(1) ... Y(N))												*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	N = NUMBER OF COLUMNS TO BE ROTATED.						*/
+	/*																*/
+    /* 	C, S = ELEMENTS OF THE GIVENS ROTATION.	THESE MAY BE		*/
+    /* 	      DETERMINED BY SUBROUTINE GIVENS.						*/
+	/*																*/
+    /* 	X, Y = ARRAYS OF LENGTH .GE. N CONTAINING THE VECTORS		*/
+    /* 	      TO BE ROTATED.										*/
+	/*																*/
+    /* PARAMETERS N, C, AND S ARE NOT ALTERED BY THIS ROUTINE.		*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	X, Y = ROTATED VECTORS.										*/
+	/*																*/
+    /* MODULES REQUIRED BY ROTATE -- NONE							*/
+	/*																*/
+    /****************************************************************/
+
+
+    /* LOCAL PARAMETERS -- */
+
+    /* I =	  DO - LOOP INDEX */
+    /* XI, YI = X(I), Y(I) */
+
+    /* Parameter adjustments */
+    --y;
+    --x;
+
+    /* Function Body */
+    if (*n <= 0 || *c__ == 1.f && *s == 0.f)
+    {
+        return 0;
+    }
+    i__1 = *n;
+    for (i__ = 1; i__ <= i__1; ++i__)
+    {
+        xi = x[i__];
+        yi = y[i__];
+        x[i__] = *c__ * xi + *s * yi;
+        y[i__] = -(*s) * xi + *c__ * yi;
+        /* L1: */
+    }
+    return 0;
+} /* rotate_ */
+
+/* Subroutine */ int setup2_(double *xk,   double *yk,   double *fk,   double *xi,   double *yi,
+                             double *fi, double *s1, double *s2, double *r__, double *row)
+{
+//    double sqrt(double);
+
+    static double d__;
+    static int i__;
+    static double w, w1, w2, dx, dy, dxsq, dysq;
+
+
+    /****************************************************************/
+	/*																*/
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+	/*																*/
+    /*   THIS ROUTINE SETS UP THE I - TH ROW OF AN AUGMENTED RE-	*/
+    /* GRESSION MATRIX FOR A WEIGHTED LEAST - SQUARES FIT OF A		*/
+    /* QUADRATIC FUNCTION Q(X, Y) TO A SET OF DATA VALUES F, WHERE	*/
+    /* Q(XK, YK) = FK.  THE FIRST 3 COLUMNS(QUADRATIC TERMS) ARE	*/
+    /* SCALED BY 1/S2 AND THE FOURTH AND FIFTH COLUMNS(LINEAR		*/
+    /* TERMS) ARE SCALED BY 1/S1.  THE WEIGHT IS(R - D)/(R*D) IF	*/
+    /* R .GT. D AND 0 IF R .LE. D, WHERE D IS THE DISTANCE			*/
+    /* BETWEEN NODES I AND K.										*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	XK, YK, FK = COORDINATES AND DATA VALUE AT NODE K --		*/
+    /* 		   INTERPOLATED BY Q.									*/
+	/*																*/
+    /* 	XI, YI, FI = COORDINATES AND DATA VALUE AT NODE I.			*/
+	/*																*/
+    /* 	S1, S2 = RECIPROCALS OF THE SCALE FACTORS.					*/
+	/*																*/
+    /* 	R = RADIUS OF INFLUENCE ABOUT NODE K DEFINING THE			*/
+    /* 	    WEIGHT.													*/
+	/*																*/
+    /* 	ROW = ARRAY OF LENGTH 6.									*/
+	/*																*/
+    /* INPUT PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.			*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	ROW = VECTOR CONTAINING A ROW OF THE AUGMENTED				*/
+    /* 	      REGRESSION MATRIX.									*/
+	/*																*/
+    /* MODULES REQUIRED BY SETUP2 -- NONE							*/
+	/*																*/
+    /* INTRINSIC FUNCTION CALLED BY SETUP2 -- SQRT					*/
+	/*																*/
+    /****************************************************************/
+
+
+    /* LOCAL PARAMETERS - */
+
+    /* I =	 DO - LOOP INDEX */
+    /* DX =	 XI - XK */
+    /* DY =	 YI - YK */
+    /* DXSQ = DX*DX */
+    /* DYSQ = DY*DY */
+    /* D =	 DISTANCE BETWEEN NODES K AND I */
+    /* W =	 WEIGHT ASSOCIATED WITH THE ROW */
+    /* W1 =	 W/S1 */
+    /* W2 =	 W/S2 */
+
+    --row;
+
+    dx = *xi - *xk;
+    dy = *yi - *yk;
+    dxsq = dx * dx;
+    dysq = dy * dy;
+    d__ = sqrt(dxsq + dysq);
+    if (d__ <= 0.f || d__ >= *r__)
+    {
+        goto L1;
+    }
+    w = (*r__ - d__) / *r__ / d__;
+    w1 = w / *s1;
+    w2 = w / *s2;
+    row[1] = dxsq * w2;
+    row[2] = dx * dy * w2;
+    row[3] = dysq * w2;
+    row[4] = dx * w1;
+    row[5] = dy * w1;
+    row[6] = (*fi - *fk) * w;
+    return 0;
+
+    /* NODES K AND I COINCIDE OR NODE I IS OUTSIDE OF THE RADIUS */
+    /*   OF INFLUENCE.  SET ROW TO THE ZERO VECTOR. */
+
+L1:
+    for (i__ = 1; i__ <= 6; ++i__)
+    {
+        /* L2: */
+        row[i__] = 0.f;
+    }
+    return 0;
+} /* setup2_ */
+
+/* Subroutine */ int store2_(int *n,   double *x,   double *y,   int *nr,
+                             int *lcell, int *lnext, double *xmin, double *ymin, double *dx,
+                             double *dy, int *ier)
+{
+    int lcell_dim1, lcell_offset, i__1, i__2;
+
+    static int i__, j, k, l, kb, nn, np1, nnr;
+    static double xmn, ymn, xmx, ymx, delx, dely;
+
+
+    /****************************************************************/
+	/*																*/	
+    /* 						ROBERT RENKA							*/
+    /* 					UNIV. OF NORTH TEXAS						*/
+    /*(817) 565 - 2767												*/
+	/*																*/
+    /*   GIVEN A SET OF N ARBITRARILY DISTRIBUTED NODES IN THE		*/
+    /* PLANE, THIS SUBROUTINE CREATES A DATA STRUCTURE FOR A		*/
+    /* CELL - BASED METHOD OF SOLVING CLOSEST - POINT PROBLEMS.	THE */
+    /* SMALLEST RECTANGLE CONTAINING THE NODES IS PARTITIONED		*/
+    /* INTO AN NR BY NR UNIFORM GRID OF CELLS, AND NODES ARE AS-	*/
+    /* SOCIATED WITH CELLS.	IN PARTICULAR, THE DATA STRUCTURE		*/
+    /* STORES THE INDICES OF THE NODES CONTAINED IN EACH CELL.		*/
+    /* FOR A UNIFORM RANDOM DISTRIBUTION OF NODES, THE NEAREST		*/
+    /* NODE TO AN ARBITRARY POINT CAN BE DETERMINED IN CONSTANT		*/
+    /* EXPECTED TIME.												*/
+	/*																*/
+    /* ON INPUT --													*/
+	/*																*/
+    /* 	N = NUMBER OF NODES.  N .GE. 2.								*/
+	/*																*/
+    /* 	X, Y = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN			*/
+    /* 	      COORDINATES OF THE NODES.								*/
+	/*																*/
+    /* 	NR = NUMBER OF ROWS AND COLUMNS IN THE GRID.  THE			*/
+    /* 	     CELL DENSITY(AVERAGE NUMBER OF NODES PER CELL)			*/
+    /* 	     IS D = N/(NR**2).	A RECOMMENDED VALUE, BASED			*/
+    /* 	     ON EMPIRICAL EVIDENCE, IS D = 3 -- NR =				*/
+    /* 	     SQRT(N/3).  NR .GE. 1.									*/
+	/*																*/
+    /* THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.		*/
+	/*																*/
+    /* 	LCELL = ARRAY OF LENGTH .GE. NR**2.							*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF LENGTH .GE. N.								*/
+	/*																*/
+    /* ON OUTPUT --													*/
+	/*																*/
+    /* 	LCELL = NR BY NR CELL ARRAY SUCH THAT LCELL(I, J)			*/
+    /* 		CONTAINS THE INDEX(FOR X AND Y) OF THE					*/
+    /* 		FIRST NODE(NODE WITH SMALLEST INDEX) IN					*/
+    /* 		CELL(I, J), OR LCELL(I, J) = 0 IF NO NODES				*/
+    /* 		ARE CONTAINED IN THE CELL.  THE UPPER RIGHT				*/
+    /* 		CORNER OF CELL(I, J) HAS COORDINATES(XMIN+				*/
+    /* 		I*DX, YMIN + J*DY).  LCELL IS NOT DEFINED IF			*/
+    /* 		IER .NE. 0.												*/
+	/*																*/
+    /* 	LNEXT = ARRAY OF NEXT - NODE INDICES SUCH THAT				*/
+    /* 		LNEXT(K) CONTAINS THE INDEX OF THE NEXT NODE			*/
+    /* 		IN THE CELL WHICH CONTAINS NODE K, OR					*/
+    /* 		LNEXT(K) = K IF K IS THE LAST NODE IN THE				*/
+    /* 		CELL FOR K = 1,..., N.(THE NODES CONTAINED				*/
+    /* 		IN A CELL ARE ORDERED BY THEIR INDICES.)				*/
+    /* 		IF, FOR EXAMPLE, CELL(I, J) CONTAINS NODES				*/
+    /* 		2, 3, AND 5(AND NO OTHERS), THEN LCELL(I, J)			*/
+    /* 		= 2, LNEXT(2) = 3, LNEXT(3) = 5, AND					*/
+    /* 		LNEXT(5) = 5.  LNEXT IS NOT DEFINED IF					*/
+    /* 		IER .NE. 0.												*/
+	/*																*/
+    /* 	XMIN, YMIN = CARTESIAN COORDINATES OF THE LOWER LEFT		*/
+    /* 		    CORNER OF THE RECTANGLE DEFINED BY THE				*/
+    /* 		    NODES(SMALLEST NODAL COORDINATES) UN-				*/
+    /* 		    LESS IER = 1.  THE UPPER RIGHT CORNER IS			*/
+    /*(XMAX, YMAX) FOR XMAX = XMIN + NR*DX AND						*/
+    /* 		    YMAX = YMIN + NR*DY.								*/
+	/*																*/
+    /* 	DX, DY = DIMENSIONS OF THE CELLS UNLESS IER = 1.  DX		*/
+    /* 		=(XMAX - XMIN)/NR AND DY =(YMAX - YMIN)/NR				*/
+    /* 		WHERE XMIN, XMAX, YMIN, AND YMAX ARE THE				*/
+    /* 		EXTREMA OF X AND Y.										*/
+	/*																*/
+    /* 	IER = ERROR INDICATOR --									*/
+    /* 	      IER = 0 IF NO ERRORS WERE ENCOUNTERED.				*/
+    /* 	      IER = 1 IF N .LT. 2 OR NR .LT. 1.						*/
+    /* 	      IER = 2 IF DX = 0 OR DY = 0.							*/
+	/*																*/
+    /* MODULES REQUIRED BY STORE2 -- NONE							*/
+	/*																*/
+    /* INTRINSIC FUNCTIONS CALLED BY STORE2 -- FLOAT, IFIX			*/
+	/*																*/
+    /****************************************************************/
+
+    /* Parameter adjustments */
+    --lnext;
+    --y;
+    --x;
+    lcell_dim1 = *nr;
+    lcell_offset = 1 + lcell_dim1;
+    lcell -= lcell_offset;
+
+    /* Function Body */
+    nn = *n;
+    nnr = *nr;
+    if (nn < 2 || nnr < 1)
+    {
+        goto L4;
+    }
+
+    /* COMPUTE THE DIMENSIONS OF THE RECTANGLE CONTAINING THE */
+    /*   NODES. */
+
+    xmn = x[1];
+    xmx = xmn;
+    ymn = y[1];
+    ymx = ymn;
+    i__1 = nn;
+    for (k = 2; k <= i__1; ++k)
+    {
+        if (x[k] < xmn)
+        {
+            xmn = x[k];
+        }
+        if (x[k] > xmx)
+        {
+            xmx = x[k];
+        }
+        if (y[k] < ymn)
+        {
+            ymn = y[k];
+        }
+        /* L1: */
+        if (y[k] > ymx)
+        {
+            ymx = y[k];
+        }
+    }
+    *xmin = xmn;
+    *ymin = ymn;
+
+    /* COMPUTE CELL DIMENSIONS AND TEST FOR ZERO AREA. */
+
+    delx = (xmx - xmn) / (double) nnr;
+    dely = (ymx - ymn) / (double) nnr;
+    *dx = delx;
+    *dy = dely;
+    if (delx == 0.f || dely == 0.f)
+    {
+        goto L5;
+    }
+
+    /* INITIALIZE LCELL. */
+
+    i__1 = nnr;
+    for (j = 1; j <= i__1; ++j)
+    {
+        i__2 = nnr;
+        for (i__ = 1; i__ <= i__2; ++i__)
+        {
+            /* L2: */
+            lcell[i__ + j * lcell_dim1] = 0;
+        }
+    }
+
+    /* LOOP ON NODES, STORING INDICES IN LCELL AND LNEXT. */
+
+    np1 = nn + 1;
+    i__2 = nn;
+    for (k = 1; k <= i__2; ++k)
+    {
+        kb = np1 - k;
+        i__ = (int)((x[kb] - xmn) / delx) + 1;
+        if (i__ > nnr)
+        {
+            i__ = nnr;
+        }
+        j = (int)((y[kb] - ymn) / dely) + 1;
+        if (j > nnr)
+        {
+            j = nnr;
+        }
+        l = lcell[i__ + j * lcell_dim1];
+        lnext[kb] = l;
+        if (l == 0)
+        {
+            lnext[kb] = kb;
+        }
+        /* L3: */
+        lcell[i__ + j * lcell_dim1] = kb;
+    }
+
+    /* NO ERRORS ENCOUNTERED */
+
+    *ier = 0;
+    return 0;
+
+    /* INVALID INPUT PARAMETER */
+
+L4:
+    *ier = 1;
+    return 0;
+
+    /* DX = 0 OR DY = 0 */
+
+L5:
+    *ier = 2;
+    return 0;
+} 

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,290 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Gridding_Spline_BA.cpp                //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_BA.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_BA::CGridding_Spline_BA(void)
+	: CGridding_Spline_Base()
+{
+	Set_Name		(_TL("B-Spline Approximation"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates B-spline functions for choosen level of detail. "
+		"This module serves as basis for the 'Multilevel B-Spline Interpolation' "
+		"and is not suited as it is for spatial data interpolation from "
+		"scattered data. "
+
+		"\n\n"
+		"Reference:\n"
+		" - Lee, S., Wolberg, G., Shin, S.Y. (1997):"
+		" 'Scattered Data Interpolation with Multilevel B-Splines',"
+		" IEEE Transactions On Visualisation And Computer Graphics, Vol.3, No.3\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "LEVEL"		, _TL("Resolution"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1, 0.001, true
+	);
+}
+
+//---------------------------------------------------------
+CGridding_Spline_BA::~CGridding_Spline_BA(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_BA::On_Execute(void)
+{
+	bool	bResult	= false;
+	int		nx, ny;
+	double	d;
+	CSG_Grid	Phi;
+
+	if( Initialise(m_Points, true) )
+	{
+		d		= m_pGrid->Get_Cellsize() * Parameters("LEVEL")->asDouble();
+		nx		= (int)((m_pGrid->Get_XRange()) / d);
+		ny		= (int)((m_pGrid->Get_YRange()) / d);
+		Phi.Create(SG_DATATYPE_Float, nx + 4, ny + 4, d, m_pGrid->Get_XMin(), m_pGrid->Get_YMin());
+
+		BA_Get_Phi	(Phi);
+		BA_Set_Grid	(Phi);
+
+		bResult	= true;
+	}
+
+	m_Points.Clear();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGridding_Spline_BA::BA_Set_Grid(CSG_Grid &Phi, bool bAdd)
+{
+	int		ix, iy;
+	double	x, y, d	= m_pGrid->Get_Cellsize() / Phi.Get_Cellsize();
+
+	for(iy=0, y=0.0; iy<m_pGrid->Get_NY() && Set_Progress(iy, m_pGrid->Get_NY()); iy++, y+=d)
+	{
+		for(ix=0, x=0.0; ix<m_pGrid->Get_NX(); ix++, x+=d)
+		{
+			if( bAdd )
+			{
+				m_pGrid->Add_Value(ix, iy, BA_Get_Value(x, y, Phi));
+			}
+			else
+			{
+				m_pGrid->Set_Value(ix, iy, BA_Get_Value(x, y, Phi));
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline double CGridding_Spline_BA::BA_Get_Value(double x, double y, CSG_Grid &Phi)
+{
+	int		_x, _y, ix, iy;
+	double	z	= 0.0, bx[4], by;
+
+	if(	(_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3
+	&&	(_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 )
+	{
+		x	-= _x;
+		y	-= _y;
+
+		for(ix=0; ix<4; ix++)
+		{
+			bx[ix]	= BA_Get_B(ix, x);
+		}
+
+		for(iy=0; iy<4; iy++)
+		{
+			by	= BA_Get_B(iy, y);
+
+			for(ix=0; ix<4; ix++)
+			{
+				z	+= by * bx[ix] * Phi.asDouble(_x + ix, _y + iy);
+			}
+		}
+	}
+
+	return( z );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_BA::BA_Get_Phi(CSG_Grid &Phi)
+{
+	int		iPoint, _x, _y, ix, iy;
+	double	x, y, z, dx, dy, wxy, wy, SW2, W[4][4];
+	CSG_Grid	Delta;
+
+	//-----------------------------------------------------
+	Phi		.Assign(0.0);
+	Delta	.Create(Phi.Get_System());
+
+	//-----------------------------------------------------
+	for(iPoint=0; iPoint<m_Points.Get_Count() && Set_Progress(iPoint, m_Points.Get_Count()); iPoint++)
+	{
+		x	= (m_Points[iPoint].x - Phi.Get_XMin()) / Phi.Get_Cellsize();
+		y	= (m_Points[iPoint].y - Phi.Get_YMin()) / Phi.Get_Cellsize();
+		z	=  m_Points[iPoint].z;
+
+		if(	(_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3
+		&&	(_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 )
+		{
+			dx	= x - _x;
+			dy	= y - _y;
+
+			for(iy=0, SW2=0.0; iy<4; iy++)	// compute W[k,l] and Sum[a=0-3, b=0-3](W²[a,b])
+			{
+				wy	= BA_Get_B(iy, dy);
+
+				for(ix=0; ix<4; ix++)
+				{
+					wxy	= W[iy][ix]	= wy * BA_Get_B(ix, dx);
+
+					SW2	+= wxy*wxy;
+				}
+			}
+
+			for(iy=0; iy<4; iy++)
+			{
+				for(ix=0; ix<4; ix++)
+				{
+					wxy	= W[iy][ix];
+
+					Delta.Add_Value(_x + ix, _y + iy, wxy*wxy * ((wxy * z) / SW2));	// Numerator
+					Phi  .Add_Value(_x + ix, _y + iy, wxy*wxy);						// Denominator
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iy=0; iy<Phi.Get_NY(); iy++)
+	{
+		for(ix=0; ix<Phi.Get_NX(); ix++)
+		{
+			if( (z = Phi.asDouble(ix, iy)) != 0.0 )
+			{
+				Phi.Set_Value(ix, iy, Delta.asDouble(ix, iy) / z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+inline double CGridding_Spline_BA::BA_Get_B(int i, double d)
+{
+	switch( i )
+	{
+	case 0:
+		d	= 1.0 - d;
+		return( d*d*d / 6.0 );
+
+	case 1:	
+		return( ( 3.0 * d*d*d - 6.0 * d*d + 4.0) / 6.0 );
+
+	case 2:
+		return( (-3.0 * d*d*d + 3.0 * d*d + 3.0 * d + 1.0) / 6.0 );
+
+	case 3:
+		return( d*d*d / 6.0 );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_BA.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,114 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Gridding_Spline_BA.h                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_BA_H
+#define HEADER_INCLUDED__Gridding_Spline_BA_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_BA : public CGridding_Spline_Base
+{
+public:
+	CGridding_Spline_BA(void);
+	virtual ~CGridding_Spline_BA(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Points_3D			m_Points;
+
+
+	void					BA_Set_Grid		(CSG_Grid &Phi, bool bAdd = false);
+	double					BA_Get_Value	(double x, double y, CSG_Grid &Phi);
+	bool					BA_Get_Phi		(CSG_Grid &Phi);
+	double					BA_Get_B		(int i, double d);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_BA_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,329 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Gridding_Spline_Base.cpp               //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_Base::CGridding_Spline_Base(bool bGridPoints)
+{
+	CSG_Parameter	*pNode;
+	CSG_Parameters	*pParameters;
+
+	m_bGridPoints	= bGridPoints;
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	if( m_bGridPoints )
+	{
+		Parameters.Add_Grid(
+			NULL	, "GRIDPOINTS"	, _TL("Grid"),
+			_TL(""),
+			PARAMETER_INPUT
+		);
+	}
+	else
+	{
+		pNode	= Parameters.Add_Shapes(
+			NULL	, "SHAPES"		, _TL("Points"),
+			_TL(""),
+			PARAMETER_INPUT
+		);
+
+		Parameters.Add_Table_Field(
+			pNode	, "FIELD"		, _TL("Attribute"),
+			_TL("")
+		);
+	}
+
+	Parameters.Add_Choice(
+		NULL	, "TARGET"		, _TL("Target Grid"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("user defined"),
+			_TL("grid system"),
+			_TL("grid")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("USER", _TL("User defined grid")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL	, "CELL_SIZE"	, _TL("Grid Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	pNode	= pParameters->Add_Value(
+		NULL	, "FIT_EXTENT"	, _TL("Fit Extent"),
+		_TL("Automatically fits the grid to the shapes layers extent."),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	pParameters->Add_Range(
+		pNode	, "X_EXTENT"	, _TL("X-Extent"),
+		_TL("")
+	);
+
+	pParameters->Add_Range(
+		pNode	, "Y_EXTENT"	, _TL("Y-Extent"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("SYSTEM"	, _TL("Choose Grid System")	, _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GRID"	, _TL("Choose Grid")		, _TL(""));
+
+	pParameters->Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT	, false
+	);
+}
+
+//---------------------------------------------------------
+CGridding_Spline_Base::~CGridding_Spline_Base(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_Base::_Get_Points(CSG_Points_3D &Points, bool bInGridOnly)
+{
+	Points.Clear();
+
+	if( m_bGridPoints )
+	{
+		int			x, y;
+		TSG_Point	p;
+		CSG_Grid	*pGrid	= Parameters("GRIDPOINTS")	->asGrid();
+
+		for(y=0, p.y=pGrid->Get_YMin(); y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, p.y+=pGrid->Get_Cellsize())
+		{
+			for(x=0, p.x=pGrid->Get_XMin(); x<pGrid->Get_NX(); x++, p.x+=pGrid->Get_Cellsize())
+			{
+				if( !pGrid->is_NoData(x, y) && (!bInGridOnly || m_pGrid->is_InGrid_byPos(p)) )
+				{
+					Points.Add(p.x, p.y, pGrid->asDouble(x, y));
+				}
+			}
+		}
+	}
+	else
+	{
+		CSG_Shapes	*pShapes	= Parameters("SHAPES")	->asShapes();
+		int			zField		= Parameters("FIELD")	->asInt();
+
+		for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+			double		zValue	= pShape->asDouble(zField);
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					TSG_Point	p	= pShape->Get_Point(iPoint, iPart);
+
+					if( !bInGridOnly || m_pGrid->is_InGrid_byPos(p) )
+					{
+						Points.Add(p.x, p.y, zValue);
+					}
+				}
+			}
+		}
+	}
+
+	return( Points.Get_Count() >= 3 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_Base::_Get_Grid(void)
+{
+	CSG_Grid	*pGrid;
+	CSG_Shapes	*pShapes;
+
+	if( m_bGridPoints )
+	{
+		pGrid	= Parameters("GRIDPOINTS")	->asGrid();
+	}
+	else
+	{
+		pShapes	= Parameters("SHAPES")		->asShapes();
+	}
+
+	m_pGrid	= NULL;
+
+	//-------------------------------------------------
+	switch( Parameters("TARGET")->asInt() )
+	{
+	case 0:	// user defined...
+		if( Dlg_Parameters("USER") )
+		{
+			m_pGrid	= _Get_Grid(m_bGridPoints ? pGrid->Get_Extent() : pShapes->Get_Extent());
+		}
+		break;
+
+	case 1:	// grid system...
+		if( Dlg_Parameters("SYSTEM") )
+		{
+			m_pGrid	= SG_Create_Grid(*Get_Parameters("SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(), SG_DATATYPE_Float);
+		}
+		break;
+
+	case 2:	// grid...
+		if( Dlg_Parameters("GRID") )
+		{
+			m_pGrid	= Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid();
+		}
+		break;
+	}
+
+	//-------------------------------------------------
+	if( m_pGrid )
+	{
+		m_pGrid->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_bGridPoints ? pGrid->Get_Name() : pShapes->Get_Name(), Get_Name()));
+		m_pGrid->Assign_NoData();
+		Parameters("GRID")->Set_Value(m_pGrid);
+	}
+
+	//-----------------------------------------------------
+	return( m_pGrid != NULL );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CGridding_Spline_Base::_Get_Grid(TSG_Rect Extent)
+{
+	CSG_Parameters	*P	= Get_Parameters("USER");
+
+	if( !P->Get_Parameter("FIT_EXTENT")->asBool() )
+	{
+		Extent.xMin	= P->Get_Parameter("X_EXTENT")->asRange()->Get_LoVal();
+		Extent.yMin	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_LoVal();
+		Extent.xMax	= P->Get_Parameter("X_EXTENT")->asRange()->Get_HiVal();
+		Extent.yMax	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_HiVal();
+	}
+
+	double	d	= P->Get_Parameter("CELL_SIZE")->asDouble();
+
+	int		nx	= 1 + (int)((Extent.xMax - Extent.xMin) / d);
+	int		ny	= 1 + (int)((Extent.yMax - Extent.yMin) / d);
+
+	return( nx > 1 && ny > 1 ? SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.xMin, Extent.yMin) : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_Base::Initialise(void)
+{
+	return( On_Initialise() && _Get_Grid() );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_Base::Initialise(CSG_Points_3D &Points, bool bInGridOnly)
+{
+	return( Initialise() && _Get_Points(Points, bInGridOnly) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_Base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Gridding_Spline_Base.h                //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_Base_H
+#define HEADER_INCLUDED__Gridding_Spline_Base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_Base : public CSG_Module
+{
+public:
+	CGridding_Spline_Base(bool bGridPoints = false);
+	virtual ~CGridding_Spline_Base(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Spline Interpolation") );	}
+
+
+protected:
+
+	CSG_Grid				*m_pGrid;
+
+
+	bool					Initialise		(void);
+	bool					Initialise		(CSG_Points_3D &Points, bool bInGridOnly = false);
+
+	virtual bool			On_Initialise	(void)	{	return( true );	}
+
+
+private:
+
+	bool					m_bGridPoints;
+
+
+	bool					_Get_Points		(CSG_Points_3D &Points, bool bInGridOnly);
+	bool					_Get_Grid		(void);
+	CSG_Grid *				_Get_Grid		(TSG_Rect Extent);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_Base_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,268 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Gridding_Spline_CSA.cpp                //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_CSA.h"
+
+#include "csa.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _SAGA_MSW
+   #define isnan    _isnan
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_CSA::CGridding_Spline_CSA(void)
+	: CGridding_Spline_Base()
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Cubic Spline Approximation"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		"This module approximates irregular scalar 2D data in specified points using "
+		"C1-continuous bivariate cubic spline."
+		"\n"
+		"Minimal Number of Points:"
+		"                minimal number of points locally involved"
+		"                in spline calculation (normally = 3)\n"
+		"\n"
+		"Maximal Number of Points:"
+		"npmax:          maximal number of points locally involved"
+		"                in spline calculation (required > 10,"
+		"                recommended 20 < npmax < 60)"
+		"\n"
+		"Tolerance:"
+		"                relative tolerance multiple in fitting"
+		"                spline coefficients: the higher this"
+		"                value, the higher degree of the locally"
+		"                fitted spline (recommended 80 < k < 200)\n"
+		"\n"
+		"Points per square:"
+		"                average number of points per square"
+		"                (increase if the point distribution is strongly non-uniform"
+		"                to get larger cells)\n"
+		"\n"
+ 		"Author:         Pavel Sakov,"
+ 		"                CSIRO Marine Research\n"
+		"\n"
+ 		"Purpose:        2D data approximation with bivariate C1 cubic spline."
+ 		"                A set of library functions + standalone utility.\n"
+ 		"\n"
+ 		"Description:    See J. Haber, F. Zeilfelder, O.Davydov and H.-P. Seidel,"
+ 		"                Smooth approximation and rendering of large scattered data"
+ 		"                sets, in 'Proceedings of IEEE Visualization 2001'"
+ 		"                (Th.Ertl, K.Joy and A.Varshney, Eds.), pp.341-347, 571,"
+ 		"                IEEE Computer Society, 2001.\n"
+ 		"<a target=\"_blank\" href=\"http://www.uni-giessen.de/www-Numerische-Mathematik/davydov/VIS2001.ps.gz\">"
+		"www.uni-giessen.de/www-Numerische-Mathematik/davydov/VIS2001.ps.gz</a>\n"
+
+ 		"<a target=\"_blank\" href=\"http://www.math.uni-mannheim.de/~lsmath4/paper/VIS2001.pdf.gz\">"
+		"www.math.uni-mannheim.de/~lsmath4/paper/VIS2001.pdf.gz</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "NPMIN"		, _TL("Minimal Number of Points"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 3, 0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NPMAX"		, _TL("Maximal Number of Points"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 20, 11, true, 59, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NPPC"		, _TL("Points per Square"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 5, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "K"			, _TL("Tolerance"),
+		_TL("Spline sensitivity, reduce to get smoother results, recommended: 80 < Tolerance < 200"),
+		PARAMETER_TYPE_Int		, 140, 0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_CSA::On_Initialise(void)
+{
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_CSA::On_Execute(void)
+{
+	//-----------------------------------------------------
+	if( Initialise(m_Points, true) == false )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int			i, x, y;
+	TSG_Point	p;
+
+	csa			*pCSA	= csa_create();
+
+	csa_setnpmin(pCSA, Parameters("NPMIN")	->asInt());
+	csa_setnpmax(pCSA, Parameters("NPMAX")	->asInt());
+	csa_setk	(pCSA, Parameters("K")		->asInt());
+	csa_setnppc	(pCSA, Parameters("NPPC")	->asDouble());
+
+	//-----------------------------------------------------
+	point	*pSrc	= (point *)SG_Malloc(m_Points.Get_Count() * sizeof(point));
+
+	for(i=0; i<m_Points.Get_Count() && Set_Progress(i, m_Points.Get_Count()); i++)
+	{
+		pSrc[i].x	= m_Points[i].x;
+		pSrc[i].y	= m_Points[i].y;
+		pSrc[i].z	= m_Points[i].z;
+	}
+
+	csa_addpoints(pCSA, m_Points.Get_Count(), pSrc);
+
+	m_Points.Clear();
+
+	//-----------------------------------------------------
+	point	*pDst	= (point *)SG_Malloc(m_pGrid->Get_NCells() * sizeof(point));
+
+	for(y=0, i=0, p.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, p.y+=m_pGrid->Get_Cellsize())
+	{
+		for(x=0, p.x=m_pGrid->Get_XMin(); x<m_pGrid->Get_NX(); x++, p.x+=m_pGrid->Get_Cellsize(), i++)
+		{
+			pDst[i].x	= p.x;
+			pDst[i].y	= p.y;
+		}
+	}
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("calculating splines..."));
+	csa_calculatespline		(pCSA);
+
+	Process_Set_Text(_TL("approximating points..."));
+	csa_approximate_points	(pCSA, m_pGrid->Get_NCells(), pDst);
+
+	//-----------------------------------------------------
+	for(y=0, i=0; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++)
+	{
+		for(x=0; x<m_pGrid->Get_NX(); x++, i++)
+		{
+			if( isnan(pDst[i].z) )
+			{
+				m_pGrid->Set_NoData(x, y);
+			}
+			else
+			{
+				m_pGrid->Set_Value(x, y, pDst[i].z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	csa_destroy(pCSA);
+
+	SG_Free(pSrc);
+	SG_Free(pDst);
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_CSA.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Gridding_Spline_CSA.h                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_CSA_H
+#define HEADER_INCLUDED__Gridding_Spline_CSA_H
+
+//---------------------------------------------------------
+#include "Gridding_Spline_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGridding_Spline_CSA : public CGridding_Spline_Base
+{
+public:
+	CGridding_Spline_CSA(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+	virtual bool			On_Initialise	(void);
+
+
+private:
+
+	CSG_Points_3D			m_Points;
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_CSA_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,511 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Gridding_Spline_MBA.cpp                //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_MBA.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_MBA::CGridding_Spline_MBA(void)
+	: CGridding_Spline_Base()
+{
+	Set_Name		(_TL("Multilevel B-Spline Interpolation"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Multilevel B-spline algorithm for spatial interpolation of scattered data "
+		"as proposed by Lee, Wolberg and Shin (1997). "
+		"The algorithm makes use of a coarse-to-fine hierarchy of control lattices to "
+		"generate a sequence of bicubic B-spline functions, whose sum approaches the "
+		"desired interpolation function. Large performance gains are realized by using "
+		"B-spline refinement to reduce the sum of these functions into one equivalent "
+		"B-spline function. "
+		"\n\n"
+		"The 'Maximum Level' determines the maximum size of the final B-spline matrix "
+		"and increases exponential with each level. Where level=10 requires about 1mb "
+		"level=12 needs about 16mb and level=14 about 256mb(!) of additional memory. "
+		"\n\n"
+		"Reference:\n"
+		" - Lee, S., Wolberg, G., Shin, S.Y. (1997):"
+		" 'Scattered Data Interpolation with Multilevel B-Splines',"
+		" IEEE Transactions On Visualisation And Computer Graphics, Vol.3, No.3\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("without B-spline refinement"),
+			_TL("with B-spline refinement")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "EPSILON"		, _TL("Threshold Error"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0001, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LEVEL_MAX"	, _TL("Maximum Level"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 11, 1, true, 14, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "UPDATE"		, _TL("Update View"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+}
+
+//---------------------------------------------------------
+CGridding_Spline_MBA::~CGridding_Spline_MBA(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	if( Initialise(m_Points, true) )
+	{
+		m_Epsilon	= Parameters("EPSILON")		->asDouble();
+		m_Level_Max	= Parameters("LEVEL_MAX")	->asInt();
+		m_bUpdate	= Parameters("UPDATE")		->asBool();
+
+		double	dCell	= m_pGrid->Get_XRange() > m_pGrid->Get_YRange() ? m_pGrid->Get_XRange() : m_pGrid->Get_YRange();
+
+		switch( Parameters("METHOD") ? Parameters("METHOD")->asInt() : 0 )
+		{
+		case 0:	// without B-spline refinement
+			bResult	= _Set_MBA				(dCell);
+			break;
+
+		case 1:	// with B-spline refinement
+			bResult	= _Set_MBA_Refinement	(dCell);
+			break;
+		}
+	}
+
+	m_Points.Clear();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::_Set_MBA(double dCell)
+{
+	bool	bContinue;
+	int		nCells;
+	CSG_Grid	Phi;
+
+	for(bContinue=true, nCells=1; bContinue; nCells*=2, dCell/=2.0)
+	{
+		bContinue	= _Get_Phi(Phi, dCell, nCells);
+
+		BA_Set_Grid	(Phi, nCells > 1);
+
+		if( m_bUpdate )
+		{
+			DataObject_Update(m_pGrid, true);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::_Set_MBA_Refinement(double dCell)
+{
+	bool	bContinue;
+	int		nCells;
+	CSG_Grid	A, B, *Phi, *Psi, *pTmp;
+
+	for(bContinue=true, Psi=&A, Phi=&B, nCells=1; bContinue; nCells*=2, dCell/=2.0)
+	{
+		bContinue	= _Get_Phi(*Phi, dCell, nCells);
+
+		if( nCells > 1 )
+		{
+			_Set_MBA_Refinement(Psi, Phi);
+		}
+
+		pTmp	= Phi;	Phi	= Psi;	Psi	= pTmp;
+
+		if( m_bUpdate )
+		{
+			BA_Set_Grid(*Psi);	DataObject_Update(m_pGrid, true);
+		}
+	}
+
+	BA_Set_Grid(*Psi);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+#define SET_PSI(x, y, z)	if( (x) >= 0 && (x) < Psi_B->Get_NX() && (y) >= 0 && (y) < Psi_B->Get_NY() )	Psi_B->Add_Value(x, y, z);
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::_Set_MBA_Refinement(CSG_Grid *Psi_A, CSG_Grid *Psi_B)
+{
+	if(	Psi_A && Psi_B
+	&&	2 * (Psi_A->Get_NX() - 4) == (Psi_B->Get_NX() - 4)
+	&&	2 * (Psi_A->Get_NY() - 4) == (Psi_B->Get_NY() - 4) )
+	{
+		int		ax, ay, bx, by;
+		double	a[3][3];
+
+		for(ay=0, by=-1; ay<Psi_A->Get_NY() && Set_Progress(ay, Psi_A->Get_NY()); ay++, by+=2)
+		{
+			for(ax=0, bx=-1; ax<Psi_A->Get_NX(); ax++, bx+=2)
+			{
+				for(int iy=0, jy=ay-1; iy<3; iy++, jy++)
+				{
+					for(int ix=0, jx=ax-1; ix<3; ix++, jx++)
+					{
+						a[ix][iy]	= jx < 0 || jx >= Psi_A->Get_NX() || jy < 0 || jy >= Psi_A->Get_NY() ? 0.0 : Psi_A->asDouble(jx, jy);
+					}
+				}
+
+				SET_PSI(bx + 0, by + 0,
+					(  a[0][0] + a[0][2] + a[2][0] + a[2][2]
+					+ (a[0][1] + a[1][0] + a[1][2] + a[2][1]) * 6.0
+					+  a[1][1] * 36.0
+					) / 64.0
+				);
+
+				SET_PSI(bx + 0, by + 1,
+					(  a[0][1] + a[0][2] + a[2][1] + a[2][2]
+					+ (a[1][1] + a[1][2]) * 6.0
+					) / 16.0
+				);
+
+				SET_PSI(bx + 1, by + 0,
+					(  a[1][0] + a[1][2] + a[2][0] + a[2][2]
+					+ (a[1][1] + a[2][1]) * 6.0
+					) / 16.0
+				);
+
+				SET_PSI(bx + 1, by + 1,
+					(  a[1][1] + a[1][2] + a[2][1] + a[2][2]
+					) /  4.0
+				);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::_Get_Phi(CSG_Grid &Phi, double dCell, int nCells)
+{
+	Phi.Create	(SG_DATATYPE_Float, nCells + 4, nCells + 4, dCell, m_pGrid->Get_XMin(), m_pGrid->Get_YMin());
+	BA_Get_Phi	(Phi);
+
+	return( _Get_Difference(Phi) );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::_Get_Difference(CSG_Grid &Phi)
+{
+	int			i, nErrors;
+	double		x, y, z, zMax, zMean;
+	CSG_String	s;
+
+	//-----------------------------------------------------
+	for(i=0, zMax=0.0, nErrors=0, zMean=0.0; i<m_Points.Get_Count(); i++)
+	{
+		x	= (m_Points[i].x - Phi.Get_XMin()) / Phi.Get_Cellsize();
+		y	= (m_Points[i].y - Phi.Get_YMin()) / Phi.Get_Cellsize();
+		z	= (m_Points[i].z	= m_Points[i].z - BA_Get_Value(x, y, Phi));
+
+		if( (z = fabs(z)) > m_Epsilon )
+		{
+			nErrors	++;
+			zMean	+= fabs(z);
+
+			if( fabs(z) > zMax )
+			{
+				zMax	= fabs(z);
+			}
+		}
+		else
+		{
+			m_Points[i].z	 = 0.0;
+		}
+	}
+
+	if( nErrors > 0 )
+	{
+		zMean	/= nErrors;
+	}
+
+	//-----------------------------------------------------
+	i	= 1 + (int)(0.5 + log(Phi.Get_NX() - 4.0) / log(2.0));
+
+	s.Printf(SG_T("%s:%d, %s:%d, %s:%f, %s:%f"),
+		_TL("level"), i,
+		_TL("error"), nErrors,
+		_TL("max")	, zMax,
+		_TL("mean")	, zMean
+	);
+
+	Process_Set_Text(s);
+	Message_Add     (s);
+
+	return( zMax >= m_Epsilon && i < m_Level_Max && Process_Get_Okay(false) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGridding_Spline_MBA::BA_Set_Grid(CSG_Grid &Phi, bool bAdd)
+{
+	int		ix, iy;
+	double	x, y, d	= m_pGrid->Get_Cellsize() / Phi.Get_Cellsize();
+
+	for(iy=0, y=0.0; iy<m_pGrid->Get_NY() && Set_Progress(iy, m_pGrid->Get_NY()); iy++, y+=d)
+	{
+		for(ix=0, x=0.0; ix<m_pGrid->Get_NX(); ix++, x+=d)
+		{
+			if( bAdd )
+			{
+				m_pGrid->Add_Value(ix, iy, BA_Get_Value(x, y, Phi));
+			}
+			else
+			{
+				m_pGrid->Set_Value(ix, iy, BA_Get_Value(x, y, Phi));
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+double CGridding_Spline_MBA::BA_Get_Value(double x, double y, CSG_Grid &Phi)
+{
+	int		_x, _y, ix, iy;
+	double	z	= 0.0, bx[4], by;
+
+	if(	(_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3
+	&&	(_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 )
+	{
+		x	-= _x;
+		y	-= _y;
+
+		for(ix=0; ix<4; ix++)
+		{
+			bx[ix]	= BA_Get_B(ix, x);
+		}
+
+		for(iy=0; iy<4; iy++)
+		{
+			by	= BA_Get_B(iy, y);
+
+			for(ix=0; ix<4; ix++)
+			{
+				z	+= by * bx[ix] * Phi.asDouble(_x + ix, _y + iy);
+			}
+		}
+	}
+
+	return( z );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA::BA_Get_Phi(CSG_Grid &Phi)
+{
+	int		iPoint, _x, _y, ix, iy;
+	double	x, y, z, dx, dy, wxy, wy, SW2, W[4][4];
+	CSG_Grid	Delta;
+
+	//-----------------------------------------------------
+	Phi		.Assign(0.0);
+	Delta	.Create(Phi.Get_System());
+
+	//-----------------------------------------------------
+	for(iPoint=0; iPoint<m_Points.Get_Count() && Set_Progress(iPoint, m_Points.Get_Count()); iPoint++)
+	{
+		x	= (m_Points[iPoint].x - Phi.Get_XMin()) / Phi.Get_Cellsize();
+		y	= (m_Points[iPoint].y - Phi.Get_YMin()) / Phi.Get_Cellsize();
+		z	=  m_Points[iPoint].z;
+
+		if(	(_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3
+		&&	(_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 )
+		{
+			dx	= x - _x;
+			dy	= y - _y;
+
+			for(iy=0, SW2=0.0; iy<4; iy++)	// compute W[k,l] and Sum[a=0-3, b=0-3](W²[a,b])
+			{
+				wy	= BA_Get_B(iy, dy);
+
+				for(ix=0; ix<4; ix++)
+				{
+					wxy	= W[iy][ix]	= wy * BA_Get_B(ix, dx);
+
+					SW2	+= wxy*wxy;
+				}
+			}
+
+			for(iy=0; iy<4; iy++)
+			{
+				for(ix=0; ix<4; ix++)
+				{
+					wxy	= W[iy][ix];
+
+					Delta.Add_Value(_x + ix, _y + iy, wxy*wxy * ((wxy * z) / SW2));	// Numerator
+					Phi  .Add_Value(_x + ix, _y + iy, wxy*wxy);						// Denominator
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iy=0; iy<Phi.Get_NY(); iy++)
+	{
+		for(ix=0; ix<Phi.Get_NX(); ix++)
+		{
+			if( (z = Phi.asDouble(ix, iy)) != 0.0 )
+			{
+				Phi.Set_Value(ix, iy, Delta.asDouble(ix, iy) / z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+inline double CGridding_Spline_MBA::BA_Get_B(int i, double d)
+{
+	switch( i )
+	{
+	case 0:
+		d	= 1.0 - d;
+		return( d*d*d / 6.0 );
+
+	case 1:	
+		return( ( 3.0 * d*d*d - 6.0 * d*d + 4.0) / 6.0 );
+
+	case 2:
+		return( (-3.0 * d*d*d + 3.0 * d*d + 3.0 * d + 1.0) / 6.0 );
+
+	case 3:
+		return( d*d*d / 6.0 );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,127 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Gridding_Spline_MBA.h                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_MBA_H
+#define HEADER_INCLUDED__Gridding_Spline_MBA_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_MBA : public CGridding_Spline_Base
+{
+public:
+	CGridding_Spline_MBA(void);
+	virtual ~CGridding_Spline_MBA(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	bool					m_bUpdate;
+
+	int						m_Level_Max;
+
+	double					m_Epsilon, m_Resolution;
+
+	CSG_Points_3D			m_Points;
+
+
+	bool					_Set_MBA			(double dCell);
+	bool					_Set_MBA_Refinement	(double dCell);
+	bool					_Set_MBA_Refinement	(CSG_Grid *Psi, CSG_Grid *Phi);
+
+	bool					_Get_Phi			(CSG_Grid &Phi, double dCell, int nCells);
+	bool					_Get_Difference		(CSG_Grid &Phi);
+
+	void					BA_Set_Grid			(CSG_Grid &Phi, bool bAdd = false);
+	double					BA_Get_Value		(double x, double y, CSG_Grid &Phi);
+	bool					BA_Get_Phi			(CSG_Grid &Phi);
+	double					BA_Get_B			(int i, double d);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_MBA_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,530 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Gridding_Spline_MBA_Grid.cpp             //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_MBA_Grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_MBA_Grid::CGridding_Spline_MBA_Grid(void)
+	: CGridding_Spline_Base(true)
+{
+	Set_Name		(_TL("Multilevel B-Spline Interpolation (from Grid)"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Multilevel B-spline algorithm for spatial interpolation of scattered data "
+		"as proposed by Lee, Wolberg and Shin (1997). "
+		"The algorithm makes use of a coarse-to-fine hierarchy of control lattices to "
+		"generate a sequence of bicubic B-spline functions, whose sum approaches the "
+		"desired interpolation function. Large performance gains are realized by using "
+		"B-spline refinement to reduce the sum of these functions into one equivalent "
+		"B-spline function. "
+		"\n\n"
+		"The 'Maximum Level' determines the maximum size of the final B-spline matrix "
+		"and increases exponential with each level. Where level=10 requires about 1mb "
+		"level=12 needs about 16mb and level=14 about 256mb(!) of additional memory. "
+		"\n\n"
+		"Reference:\n"
+		" - Lee, S., Wolberg, G., Shin, S.Y. (1997):"
+		" 'Scattered Data Interpolation with Multilevel B-Splines',"
+		" IEEE Transactions On Visualisation And Computer Graphics, Vol.3, No.3\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("without B-spline refinement"),
+			_TL("with B-spline refinement")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "EPSILON"		, _TL("Threshold Error"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0001, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LEVEL_MAX"	, _TL("Maximum Level"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 11, 1, true, 14, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "UPDATE"		, _TL("Update View"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+}
+
+//---------------------------------------------------------
+CGridding_Spline_MBA_Grid::~CGridding_Spline_MBA_Grid(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	if( Initialise() )
+	{
+		m_Points.Create(*Parameters("GRIDPOINTS")->asGrid());
+
+		m_Epsilon	= Parameters("EPSILON")		->asDouble();
+		m_Level_Max	= Parameters("LEVEL_MAX")	->asInt();
+		m_bUpdate	= Parameters("UPDATE")		->asBool();
+
+		double	dCell	= m_pGrid->Get_XRange() > m_pGrid->Get_YRange() ? m_pGrid->Get_XRange() : m_pGrid->Get_YRange();
+
+		switch( Parameters("METHOD") ? Parameters("METHOD")->asInt() : 0 )
+		{
+		case 0:	// without B-spline refinement
+			bResult	= _Set_MBA				(dCell);
+			break;
+
+		case 1:	// with B-spline refinement
+			bResult	= _Set_MBA_Refinement	(dCell);
+			break;
+		}
+
+		m_Points.Destroy();
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::_Set_MBA(double dCell)
+{
+	bool	bContinue;
+	int		nCells;
+	CSG_Grid	Phi;
+
+	for(bContinue=true, nCells=1; bContinue; nCells*=2, dCell/=2.0)
+	{
+		bContinue	= _Get_Phi(Phi, dCell, nCells);
+
+		BA_Set_Grid	(Phi, nCells > 1);
+
+		if( m_bUpdate )
+		{
+			DataObject_Update(m_pGrid, true);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::_Set_MBA_Refinement(double dCell)
+{
+	bool	bContinue;
+	int		nCells;
+	CSG_Grid	A, B, *Phi, *Psi, *pTmp;
+
+	for(bContinue=true, Psi=&A, Phi=&B, nCells=1; bContinue; nCells*=2, dCell/=2.0)
+	{
+		bContinue	= _Get_Phi(*Phi, dCell, nCells);
+
+		if( nCells > 1 )
+		{
+			_Set_MBA_Refinement(Psi, Phi);
+		}
+
+		pTmp	= Phi;	Phi	= Psi;	Psi	= pTmp;
+
+		if( m_bUpdate )
+		{
+			BA_Set_Grid(*Psi);	DataObject_Update(m_pGrid, true);
+		}
+	}
+
+	BA_Set_Grid(*Psi);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+#define SET_PSI(x, y, z)	if( (x) >= 0 && (x) < Psi_B->Get_NX() && (y) >= 0 && (y) < Psi_B->Get_NY() )	Psi_B->Add_Value(x, y, z);
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::_Set_MBA_Refinement(CSG_Grid *Psi_A, CSG_Grid *Psi_B)
+{
+	if(	Psi_A && Psi_B
+	&&	2 * (Psi_A->Get_NX() - 4) == (Psi_B->Get_NX() - 4)
+	&&	2 * (Psi_A->Get_NY() - 4) == (Psi_B->Get_NY() - 4) )
+	{
+		int		ax, ay, bx, by;
+		double	a[3][3];
+
+		for(ay=0, by=-1; ay<Psi_A->Get_NY() && Set_Progress(ay, Psi_A->Get_NY()); ay++, by+=2)
+		{
+			for(ax=0, bx=-1; ax<Psi_A->Get_NX(); ax++, bx+=2)
+			{
+				for(int iy=0, jy=ay-1; iy<3; iy++, jy++)
+				{
+					for(int ix=0, jx=ax-1; ix<3; ix++, jx++)
+					{
+						a[ix][iy]	= jx < 0 || jx >= Psi_A->Get_NX() || jy < 0 || jy >= Psi_A->Get_NY() ? 0.0 : Psi_A->asDouble(jx, jy);
+					}
+				}
+
+				SET_PSI(bx + 0, by + 0,
+					(  a[0][0] + a[0][2] + a[2][0] + a[2][2]
+					+ (a[0][1] + a[1][0] + a[1][2] + a[2][1]) * 6.0
+					+  a[1][1] * 36.0
+					) / 64.0
+				);
+
+				SET_PSI(bx + 0, by + 1,
+					(  a[0][1] + a[0][2] + a[2][1] + a[2][2]
+					+ (a[1][1] + a[1][2]) * 6.0
+					) / 16.0
+				);
+
+				SET_PSI(bx + 1, by + 0,
+					(  a[1][0] + a[1][2] + a[2][0] + a[2][2]
+					+ (a[1][1] + a[2][1]) * 6.0
+					) / 16.0
+				);
+
+				SET_PSI(bx + 1, by + 1,
+					(  a[1][1] + a[1][2] + a[2][1] + a[2][2]
+					) /  4.0
+				);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::_Get_Phi(CSG_Grid &Phi, double dCell, int nCells)
+{
+	Phi.Create	(SG_DATATYPE_Float, nCells + 4, nCells + 4, dCell, m_pGrid->Get_XMin(), m_pGrid->Get_YMin());
+	BA_Get_Phi	(Phi);
+
+	return( _Get_Difference(Phi) );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::_Get_Difference(CSG_Grid &Phi)
+{
+	int				xPoint, yPoint, nErrors;
+	double			x, y, z, zMax, zMean;
+	TSG_Point_3D	p;
+	CSG_String		s;
+
+	//-----------------------------------------------------
+	for(yPoint=0, p.y=m_Points.Get_YMin(), zMax=0.0, nErrors=0, zMean=0.0; yPoint<m_Points.Get_NY() && Set_Progress(yPoint, m_Points.Get_NY()); yPoint++, p.y+=m_Points.Get_Cellsize())
+	{
+		for(xPoint=0, p.x=m_Points.Get_XMin(); xPoint<m_Points.Get_NX(); xPoint++, p.x+=m_Points.Get_Cellsize())
+		{
+			if( !m_Points.is_NoData(xPoint, yPoint) )
+			{
+				x	= (p.x - Phi.Get_XMin()) / Phi.Get_Cellsize();
+				y	= (p.y - Phi.Get_YMin()) / Phi.Get_Cellsize();
+				z	= m_Points.asDouble(xPoint, yPoint) - BA_Get_Value(x, y, Phi);
+
+				m_Points.Set_Value(xPoint, yPoint, z);
+
+				if( (z = fabs(z)) > m_Epsilon )
+				{
+					nErrors	++;
+					zMean	+= fabs(z);
+
+					if( fabs(z) > zMax )
+					{
+						zMax	= fabs(z);
+					}
+				}
+				else
+				{
+				//	m_Points.Set_Value(xPoint, yPoint, 0.0);
+					m_Points.Set_NoData(xPoint, yPoint);
+				}
+			}
+		}
+	}
+
+	if( nErrors > 0 )
+	{
+		zMean	/= nErrors;
+	}
+
+	//-----------------------------------------------------
+	int	i	= 1 + (int)(0.5 + log(Phi.Get_NX() - 4.0) / log(2.0));
+
+	s.Printf(SG_T("%s:%d, %s:%d, %s:%f, %s:%f"),
+		_TL("level"), i,
+		_TL("error"), nErrors,
+		_TL("max")	, zMax,
+		_TL("mean")	, zMean
+	);
+
+	Process_Set_Text(s);
+	Message_Add     (s);
+
+	return( zMax >= m_Epsilon && i < m_Level_Max && Process_Get_Okay(false) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGridding_Spline_MBA_Grid::BA_Set_Grid(CSG_Grid &Phi, bool bAdd)
+{
+	int		ix, iy;
+	double	x, y, d	= m_pGrid->Get_Cellsize() / Phi.Get_Cellsize();
+
+	for(iy=0, y=0.0; iy<m_pGrid->Get_NY() && Set_Progress(iy, m_pGrid->Get_NY()); iy++, y+=d)
+	{
+		for(ix=0, x=0.0; ix<m_pGrid->Get_NX(); ix++, x+=d)
+		{
+			if( bAdd )
+			{
+				m_pGrid->Add_Value(ix, iy, BA_Get_Value(x, y, Phi));
+			}
+			else
+			{
+				m_pGrid->Set_Value(ix, iy, BA_Get_Value(x, y, Phi));
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+double CGridding_Spline_MBA_Grid::BA_Get_Value(double x, double y, CSG_Grid &Phi)
+{
+	int		_x, _y, ix, iy;
+	double	z	= 0.0, bx[4], by;
+
+	if(	(_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3
+	&&	(_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 )
+	{
+		x	-= _x;
+		y	-= _y;
+
+		for(ix=0; ix<4; ix++)
+		{
+			bx[ix]	= BA_Get_B(ix, x);
+		}
+
+		for(iy=0; iy<4; iy++)
+		{
+			by	= BA_Get_B(iy, y);
+
+			for(ix=0; ix<4; ix++)
+			{
+				z	+= by * bx[ix] * Phi.asDouble(_x + ix, _y + iy);
+			}
+		}
+	}
+
+	return( z );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_MBA_Grid::BA_Get_Phi(CSG_Grid &Phi)
+{
+	int			xPoint, yPoint, _x, _y, ix, iy;
+	double		x, y, z, dx, dy, wxy, wy, SW2, W[4][4];
+	TSG_Point	p;
+	CSG_Grid	Delta;
+
+	//-----------------------------------------------------
+	Phi		.Assign(0.0);
+	Delta	.Create(Phi.Get_System());
+
+	//-----------------------------------------------------
+	for(yPoint=0, p.y=m_Points.Get_YMin(); yPoint<m_Points.Get_NY() && Set_Progress(yPoint, m_Points.Get_NY()); yPoint++, p.y+=m_Points.Get_Cellsize())
+	{
+		for(xPoint=0, p.x=m_Points.Get_XMin(); xPoint<m_Points.Get_NX(); xPoint++, p.x+=m_Points.Get_Cellsize())
+		{
+			if( !m_Points.is_NoData(xPoint, yPoint) )
+			{
+				x	= (p.x - Phi.Get_XMin()) / Phi.Get_Cellsize();
+				y	= (p.y - Phi.Get_YMin()) / Phi.Get_Cellsize();
+				z	= m_Points.asDouble(xPoint, yPoint);
+
+				if(	(_x = (int)x) >= 0 && _x < Phi.Get_NX() - 3
+				&&	(_y = (int)y) >= 0 && _y < Phi.Get_NY() - 3 )
+				{
+					dx	= x - _x;
+					dy	= y - _y;
+
+					for(iy=0, SW2=0.0; iy<4; iy++)	// compute W[k,l] and Sum[a=0-3, b=0-3](W²[a,b])
+					{
+						wy	= BA_Get_B(iy, dy);
+
+						for(ix=0; ix<4; ix++)
+						{
+							wxy	= W[iy][ix]	= wy * BA_Get_B(ix, dx);
+
+							SW2	+= wxy*wxy;
+						}
+					}
+
+					for(iy=0; iy<4; iy++)
+					{
+						for(ix=0; ix<4; ix++)
+						{
+							wxy	= W[iy][ix];
+
+							Delta.Add_Value(_x + ix, _y + iy, wxy*wxy * ((wxy * z) / SW2));	// Numerator
+							Phi  .Add_Value(_x + ix, _y + iy, wxy*wxy);						// Denominator
+						}
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iy=0; iy<Phi.Get_NY(); iy++)
+	{
+		for(ix=0; ix<Phi.Get_NX(); ix++)
+		{
+			if( (z = Phi.asDouble(ix, iy)) != 0.0 )
+			{
+				Phi.Set_Value(ix, iy, Delta.asDouble(ix, iy) / z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+inline double CGridding_Spline_MBA_Grid::BA_Get_B(int i, double d)
+{
+	switch( i )
+	{
+	case 0:
+		d	= 1.0 - d;
+		return( d*d*d / 6.0 );
+
+	case 1:	
+		return( ( 3.0 * d*d*d - 6.0 * d*d + 4.0) / 6.0 );
+
+	case 2:
+		return( (-3.0 * d*d*d + 3.0 * d*d + 3.0 * d + 1.0) / 6.0 );
+
+	case 3:
+		return( d*d*d / 6.0 );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_MBA_Grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,127 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Gridding_Spline_MBA_Grid.h              //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_MBA_Grid_H
+#define HEADER_INCLUDED__Gridding_Spline_MBA_Grid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_MBA_Grid : public CGridding_Spline_Base
+{
+public:
+	CGridding_Spline_MBA_Grid(void);
+	virtual ~CGridding_Spline_MBA_Grid(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	bool					m_bUpdate;
+
+	int						m_Level_Max;
+
+	double					m_Epsilon, m_Resolution;
+
+	CSG_Grid				m_Points;
+
+
+	bool					_Set_MBA			(double dCell);
+	bool					_Set_MBA_Refinement	(double dCell);
+	bool					_Set_MBA_Refinement	(CSG_Grid *Psi, CSG_Grid *Phi);
+
+	bool					_Get_Phi			(CSG_Grid &Phi, double dCell, int nCells);
+	bool					_Get_Difference		(CSG_Grid &Phi);
+
+	void					BA_Set_Grid			(CSG_Grid &Phi, bool bAdd = false);
+	double					BA_Get_Value		(double x, double y, CSG_Grid &Phi);
+	bool					BA_Get_Phi			(CSG_Grid &Phi);
+	double					BA_Get_B			(int i, double d);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_MBA_Grid_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,166 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             Gridding_Spline_TPS_Global.cpp            //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_TPS_Global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_TPS_Global::CGridding_Spline_TPS_Global(void)
+	: CGridding_Spline_Base()
+{
+	Set_Name		(_TL("Thin Plate Spline (Global)"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Creates a 'Thin Plate Spline' function using all points of selected input. "
+		"Suitable for the gridding of a small number of points. "
+		"\n\n"
+		"References:\n"
+		"- Donato G., Belongie S. (2002):"
+		" 'Approximation Methods for Thin Plate Spline Mappings and Principal Warps',"
+		" In Heyden, A., Sparr, G., Nielsen, M., Johansen, P. (Eds.):"
+		" 'Computer Vision – ECCV 2002: 7th European Conference on Computer Vision, Copenhagen, Denmark, May 28–31, 2002',"
+		" Proceedings, Part III, Lecture Notes in Computer Science."
+		" Springer-Verlag Heidelberg; pp.21-31."
+		"\n"
+		"\n"
+		"- Elonen, J. (2005):"
+		" 'Thin Plate Spline editor - an example program in C++',"
+		" <a target=\"_blank\" href=\"http://elonen.iki.fi/code/tpsdemo/index.html\">http://elonen.iki.fi/code/tpsdemo/index.html</a>."
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "REGUL"		, _TL("Regularisation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+}
+
+//---------------------------------------------------------
+CGridding_Spline_TPS_Global::~CGridding_Spline_TPS_Global(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_Global::On_Initialise(void)
+{
+	m_pShapes			= Parameters("SHAPES")	->asShapes();
+	m_zField			= Parameters("FIELD")	->asInt();
+	m_Regularisation	= Parameters("REGUL")	->asDouble();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_Global::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	if( Initialise(m_Spline.Get_Points()) && m_Spline.Create(m_Regularisation, false) )
+	{
+		int			x, y;
+		TSG_Point	p;
+
+		for(y=0, p.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, p.y+=m_pGrid->Get_Cellsize())
+		{
+			for(x=0, p.x=m_pGrid->Get_XMin(); x<m_pGrid->Get_NX(); x++, p.x+=m_pGrid->Get_Cellsize())
+			{
+				m_pGrid->Set_Value(x, y, m_Spline.Get_Value(p.x, p.y));
+			}
+		}
+
+		bResult	= true;
+	}
+
+	m_Spline.Destroy();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Global.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Gridding_Spline_TPS_Global.h             //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_TPS_Global_H
+#define HEADER_INCLUDED__Gridding_Spline_TPS_Global_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_Base.h"
+#include "Thin_Plate_Spline.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_TPS_Global : public CGridding_Spline_Base
+{
+public:
+	CGridding_Spline_TPS_Global(void);
+	virtual ~CGridding_Spline_TPS_Global(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+	virtual bool			On_Initialise	(void);
+
+
+	int						m_zField;
+
+	double					m_Regularisation;
+
+	CSG_Shapes				*m_pShapes;
+
+	CThin_Plate_Spline		m_Spline;
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_TPS_Global_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,240 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Gridding_Spline_TPS_Local.cpp            //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_TPS_Local.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_TPS_Local::CGridding_Spline_TPS_Local(void)
+	: CGridding_Spline_TPS_Global()
+{
+	Set_Name		(_TL("Thin Plate Spline (Local)"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Creates a 'Thin Plate Spline' function for each grid point "
+		"based on all of the scattered data points that are within a "
+		"given distance. The number of points can be limited to a "
+		"maximum number of closest points. "
+		"\n\n"
+		"References:\n"
+		"- Donato G., Belongie S. (2002):"
+		" 'Approximation Methods for Thin Plate Spline Mappings and Principal Warps',"
+		" In Heyden, A., Sparr, G., Nielsen, M., Johansen, P. (Eds.):"
+		" 'Computer Vision – ECCV 2002: 7th European Conference on Computer Vision, Copenhagen, Denmark, May 28–31, 2002',"
+		" Proceedings, Part III, Lecture Notes in Computer Science."
+		" Springer-Verlag Heidelberg; pp.21-31."
+		"\n"
+		"\n"
+		"- Elonen, J. (2005):"
+		" 'Thin Plate Spline editor - an example program in C++',"
+		" <a target=\"_blank\" href=\"http://elonen.iki.fi/code/tpsdemo/index.html\">http://elonen.iki.fi/code/tpsdemo/index.html</a>."
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "RADIUS"		, _TL("Search Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("all directions"),
+			_TL("quadrants")
+		)
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SELECT"		, _TL("Points Selection"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("all points in search radius"),
+			_TL("maximum number of points")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MAXPOINTS"	, _TL("Maximum Number of Points"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 10.0, 1, true
+	);
+
+	//-----------------------------------------------------
+	Parameters("REGUL")->Set_Value(0.0001);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_Local::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	if( Initialise() && m_Search.Create(m_pShapes, m_zField) )
+	{
+		m_Radius		= Parameters("RADIUS")		->asDouble();
+		m_nPoints_Max	= Parameters("SELECT")		->asInt() == 1
+						? Parameters("MAXPOINTS")	->asInt()  : -1;
+		m_Mode			= Parameters("MODE")		->asInt();
+
+		int			x, y;
+		TSG_Point	p;
+
+		for(y=0, p.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, p.y+=m_pGrid->Get_Cellsize())
+		{
+			for(x=0, p.x=m_pGrid->Get_XMin(); x<m_pGrid->Get_NX(); x++, p.x+=m_pGrid->Get_Cellsize())
+			{
+				Set_Value(x, y, p);
+			}
+		}
+
+		m_Search.Destroy();
+		m_Spline.Destroy();
+
+		bResult	= true;
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CGridding_Spline_TPS_Local::Get_Points(const TSG_Point &p, int iQuadrant)
+{
+	double	x, y, z;
+
+	if( m_Search.Select_Nearest_Points(p.x, p.y, m_nPoints_Max, m_Radius, iQuadrant) > 0 )
+	{
+		for(int i=0; i<m_Search.Get_Selected_Count(); i++)
+		{
+			if( m_Search.Get_Selected_Point(i, x, y, z) )
+			{
+				m_Spline.Add_Point(x, y, z);
+			}
+		}
+	}
+
+	return( m_Search.Get_Selected_Count() );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_Local::Set_Value(int x, int y, const TSG_Point &p)
+{
+	int		nPoints	= 0;
+
+	m_Spline.Destroy();
+
+	switch( m_Mode )
+	{
+	default:
+		nPoints	+= Get_Points(p);
+		break;
+
+	case 1:
+		nPoints	+= Get_Points(p, 0);
+		nPoints	+= Get_Points(p, 1);
+		nPoints	+= Get_Points(p, 2);
+		nPoints	+= Get_Points(p, 3);
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( nPoints >= 3 && m_Spline.Create(m_Regularisation, true) )
+	{
+		m_pGrid->Set_Value(x, y, m_Spline.Get_Value(p.x, p.y));
+
+		return( true );
+	}
+
+	m_pGrid->Set_NoData(x, y);
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_Local.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Gridding_Spline_TPS_Local.h             //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_TPS_Local_H
+#define HEADER_INCLUDED__Gridding_Spline_TPS_Local_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_TPS_Global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_TPS_Local : public CGridding_Spline_TPS_Global
+{
+public:
+	CGridding_Spline_TPS_Local(void);
+
+
+protected:
+
+	virtual bool			On_Execute				(void);
+
+
+private:
+
+	int						m_nPoints_Max, m_Mode;
+
+	double					m_Radius;
+
+	CSG_PRQuadTree			m_Search;
+
+
+	int						Get_Points				(const TSG_Point &p, int iQuadrant = -1);
+
+	bool					Set_Value				(int x, int y, const TSG_Point &p);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_TPS_Local_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,385 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Gridding_Spline_TPS_TIN.cpp             //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_TPS_TIN.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGridding_Spline_TPS_TIN::CGridding_Spline_TPS_TIN(void)
+	: CGridding_Spline_TPS_Global()
+{
+	Set_Name		(_TL("Thin Plate Spline (TIN)"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Creates a 'Thin Plate Spline' function for each triangle of a TIN "
+		"and uses it for subsequent gridding. The TIN is internally created "
+		"from the scattered data points input. The 'Neighbourhood' option "
+		"determines the number of points used for the spline generation. "
+		"'Immediate neighbourhood' includes the points of the triangle as well as the "
+		"immediate neighbour points. 'Level 1' adds the neighbours of the "
+		"immediate neighbourhood and 'level 2' adds the neighbours of 'level 1' "
+		"neighbours too. A higher neighbourhood degree reduces sharp breaks "
+		"but also increases the computation time. "
+		"\n\n"
+		"References:\n"
+		"- Donato G., Belongie S. (2002):"
+		" 'Approximation Methods for Thin Plate Spline Mappings and Principal Warps',"
+		" In Heyden, A., Sparr, G., Nielsen, M., Johansen, P. (Eds.):"
+		" 'Computer Vision – ECCV 2002: 7th European Conference on Computer Vision, Copenhagen, Denmark, May 28–31, 2002',"
+		" Proceedings, Part III, Lecture Notes in Computer Science."
+		" Springer-Verlag Heidelberg; pp.21-31."
+		"\n"
+		"\n"
+		"- Elonen, J. (2005):"
+		" 'Thin Plate Spline editor - an example program in C++',"
+		" <a target=\"_blank\" href=\"http://elonen.iki.fi/code/tpsdemo/index.html\">http://elonen.iki.fi/code/tpsdemo/index.html</a>."
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "LEVEL"		, _TL("Neighbourhood"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("immediate"),
+			_TL("level 1"),
+			_TL("level 2")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "FRAME"		, _TL("Add Frame"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+}
+
+//---------------------------------------------------------
+CGridding_Spline_TPS_TIN::~CGridding_Spline_TPS_TIN(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_TIN::_Initialise(void)
+{
+	m_Level			= Parameters("LEVEL")	->asInt();
+
+	m_Points		= NULL;
+	m_nPoints_Buf	= 0;
+
+	return( CGridding_Spline_TPS_Global::On_Initialise() );
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_TIN::_Finalise(void)
+{
+	if( m_Points )
+	{
+		SG_Free(m_Points);
+	}
+
+	m_Points		= NULL;
+	m_nPoints_Buf	= 0;
+
+	m_Spline.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_TIN::On_Execute(void)
+{
+	bool	bResult	= false;
+	CSG_TIN	TIN;
+
+	if( Initialise() && _Initialise() && _Get_TIN(TIN) )
+	{
+		for(int i=0; i<TIN.Get_Triangle_Count() && Set_Progress(i, TIN.Get_Triangle_Count()); i++)
+		{
+			_Set_Triangle(TIN.Get_Triangle(i));
+		}
+
+		_Finalise();
+
+		bResult	= true;
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGridding_Spline_TPS_TIN::_Set_Triangle(CSG_TIN_Triangle *pTriangle)
+{
+	int			i, j;
+	CSG_TIN_Node	*pPoint;
+
+	if( m_pGrid->Get_Extent().Intersects(pTriangle->Get_Extent()) != INTERSECTION_None )
+	{
+		for(j=0, m_nPoints=0; j<3; j++)
+		{
+			for(i=0, pPoint=pTriangle->Get_Node(j); i<pPoint->Get_Neighbor_Count(); i++)
+			{
+				_Add_Points(pPoint->Get_Neighbor(i), 0);
+			}
+		}
+
+		m_Spline.Destroy();
+
+		for(i=0; i<m_nPoints; i++)
+		{
+			pPoint	= m_Points[i];
+
+			m_Spline.Add_Point(pPoint->Get_Point().x, pPoint->Get_Point().y, pPoint->asDouble(m_zField));
+		}
+
+		if( m_Spline.Create(m_Regularisation, true) )
+		{
+			_Set_Grid(pTriangle);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CGridding_Spline_TPS_TIN::_Set_Grid(CSG_TIN_Triangle *pTriangle)
+{
+	int		ix, iy, ax, ay, bx, by;
+	double	x, y, xMin, yMin;
+
+	ax		= m_pGrid->Get_System().Get_xWorld_to_Grid(pTriangle->Get_Extent().Get_XMin());	if( ax < 0 )	ax	= 0;
+	ay		= m_pGrid->Get_System().Get_yWorld_to_Grid(pTriangle->Get_Extent().Get_YMin());	if( ay < 0 )	ay	= 0;
+	bx		= m_pGrid->Get_System().Get_xWorld_to_Grid(pTriangle->Get_Extent().Get_XMax());	if( bx >= m_pGrid->Get_NX() - 1 )	bx	= m_pGrid->Get_NX() - 2;
+	by		= m_pGrid->Get_System().Get_yWorld_to_Grid(pTriangle->Get_Extent().Get_YMax());	if( by >= m_pGrid->Get_NY() - 1 )	by	= m_pGrid->Get_NY() - 2;
+	xMin	= m_pGrid->Get_System().Get_xGrid_to_World(ax);
+	yMin	= m_pGrid->Get_System().Get_yGrid_to_World(ay);
+
+	for(iy=ay, y=yMin; iy<=by; iy++, y+=m_pGrid->Get_Cellsize())
+	{
+		for(ix=ax, x=xMin; ix<=bx; ix++, x+=m_pGrid->Get_Cellsize())
+		{
+			if( pTriangle->is_Containing(x, y) )
+			{
+				m_pGrid->Set_Value(ix, iy, m_Spline.Get_Value(x, y));
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGridding_Spline_TPS_TIN::_Add_Points(CSG_TIN_Node *pPoint, int Level)
+{
+	int			i, j;
+	CSG_TIN_Node	*p;
+
+	_Add_Point(pPoint);
+
+	if( Level < m_Level )
+	{
+		for(j=0; j<pPoint->Get_Neighbor_Count(); j++)
+		{
+			for(i=0, p=pPoint->Get_Neighbor(j); i<p->Get_Neighbor_Count(); i++)
+			{
+				_Add_Points(p->Get_Neighbor(i), Level + 1);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_TIN::_Add_Point(CSG_TIN_Node *pPoint)
+{
+	for(int i=0; i<m_nPoints; i++)
+	{
+		if( m_Points[i] == pPoint )
+		{
+			return( false );
+		}
+	}
+
+	if( m_nPoints_Buf <= m_nPoints )
+	{
+		m_nPoints_Buf	+= 16;
+		m_Points		= (CSG_TIN_Node **)SG_Realloc(m_Points, m_nPoints_Buf * sizeof(CSG_TIN_Node *));
+	}
+
+	m_Points[m_nPoints++]	= pPoint;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGridding_Spline_TPS_TIN::_Get_TIN(CSG_TIN &TIN)
+{
+	TIN.Destroy();
+
+	if( Parameters("FRAME")->asBool() )
+	{
+		int			iShape, iPart, iPoint, iCorner, iField, z[4];
+		double		x[4], y[4], dMin[4], d;
+		TSG_Point	p;
+		CSG_Shape		*pShape;
+
+		for(iField=0; iField<m_pShapes->Get_Field_Count(); iField++)
+		{
+			TIN.Add_Field(m_pShapes->Get_Field_Name(iField), m_pShapes->Get_Field_Type(iField));
+		}
+
+		x[0]	= m_pGrid->Get_Extent().Get_XMin();	y[0]	= m_pGrid->Get_Extent().Get_YMin();	dMin[0]	= -1.0;
+		x[1]	= m_pGrid->Get_Extent().Get_XMin();	y[1]	= m_pGrid->Get_Extent().Get_YMax();	dMin[1]	= -1.0;
+		x[2]	= m_pGrid->Get_Extent().Get_XMax();	y[2]	= m_pGrid->Get_Extent().Get_YMax();	dMin[2]	= -1.0;
+		x[3]	= m_pGrid->Get_Extent().Get_XMax();	y[3]	= m_pGrid->Get_Extent().Get_YMin();	dMin[3]	= -1.0;
+
+		for(iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
+		{
+			pShape	= m_pShapes->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					p	= pShape->Get_Point(iPoint, iPart);
+
+					TIN.Add_Node(p, pShape, false);
+
+					for(iCorner=0; iCorner<4; iCorner++)
+					{
+						d	= SG_Get_Distance(p.x, p.y, x[iCorner], y[iCorner]);
+
+						if( dMin[iCorner] < 0.0 || d < dMin[iCorner] )
+						{
+							dMin[iCorner]	= d;
+							z   [iCorner]	= iShape;
+						}
+					}
+				}
+			}
+		}
+
+		for(iCorner=0; iCorner<4; iCorner++)
+		{
+			if( dMin[iCorner] >= 0.0 )
+			{
+				p.x	= x[iCorner];
+				p.y	= y[iCorner];
+
+				TIN.Add_Node(p, m_pShapes->Get_Shape(z[iCorner]), false);
+			}
+		}
+
+		TIN.Update();
+	}
+	else
+	{
+		TIN.Create(m_pShapes);
+	}
+
+	return( TIN.Get_Triangle_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Gridding_Spline_TPS_TIN.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Gridding_Spline_TPS_TIN.h              //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gridding_Spline_TPS_TIN_H
+#define HEADER_INCLUDED__Gridding_Spline_TPS_TIN_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gridding_Spline_TPS_Global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CGridding_Spline_TPS_TIN : public CGridding_Spline_TPS_Global
+{
+public:
+	CGridding_Spline_TPS_TIN(void);
+	virtual ~CGridding_Spline_TPS_TIN(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						m_nPoints, m_nPoints_Buf, m_Level;
+
+	CSG_TIN_Node			**m_Points;
+
+
+	bool					_Initialise		(void);
+	bool					_Finalise		(void);
+
+	void					_Set_Triangle	(CSG_TIN_Triangle *pTriangle);
+	void					_Set_Grid		(CSG_TIN_Triangle *pTriangle);
+
+	void					_Add_Points		(CSG_TIN_Node *Point, int Level);
+	bool					_Add_Point		(CSG_TIN_Node *Point);
+
+	bool					_Get_TIN		(CSG_TIN &TIN);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gridding_Spline_TPS_TIN_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,137 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLP_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char *	Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Spline Interpolation") );
+
+	case MLB_INFO_Author:
+		return( _TL("O. Conrad (c) 2006-8") );
+
+	case MLB_INFO_Description:
+		return( _TW(
+			"Several spline interpolation/approximation methods for the gridding of scattered data. "
+			"In most cases the 'Multilevel B-spline Interpolation' might be the optimal choice. "
+		));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Gridding") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Gridding_Spline_TPS_Global.h"
+#include "Gridding_Spline_TPS_Local.h"
+#include "Gridding_Spline_TPS_TIN.h"
+#include "Gridding_Spline_BA.h"
+#include "Gridding_Spline_MBA.h"
+#include "Gridding_Spline_MBA_Grid.h"
+#include "Gridding_Spline_CSA.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CGridding_Spline_TPS_Global );
+	case 1:		return( new CGridding_Spline_TPS_Local );
+	case 2:		return( new CGridding_Spline_TPS_TIN );
+	case 3:		return( new CGridding_Spline_BA );
+	case 4:		return( new CGridding_Spline_MBA );
+	case 5:		return( new CGridding_Spline_MBA_Grid );
+	case 6:		return( new CGridding_Spline_CSA );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,80 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_spline_H
+#define HEADER_INCLUDED__grid_spline_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_spline_EXPORTS
+	#define	grid_spline_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_spline_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_spline_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,296 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Thin_Plate_Spline.cpp                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//
+// Based on:
+//
+// Thin Plate Spline demo/example in C++
+// Copyright (C) 2003, 2005 by Jarno Elonen
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without fee,
+// provided that the above copyright notice appear in all copies and
+// that both that copyright notice and this permission notice appear
+// in supporting documentation. The authors make no representations
+// about the suitability of this software for any purpose.
+// It is provided "as is" without express or implied warranty.
+//
+// Reference:
+// - Donato, G., Belongie, S. (2002):
+//   'Approximation Methods for Thin Plate Spline Mappings and Principal Warps'
+//
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Thin_Plate_Spline.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CThin_Plate_Spline::CThin_Plate_Spline(void)
+{
+}
+
+//---------------------------------------------------------
+CThin_Plate_Spline::~CThin_Plate_Spline(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CThin_Plate_Spline::Destroy(void)
+{
+	m_Points.Clear();
+	m_V.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CThin_Plate_Spline::Add_Point(double x, double y, double z)
+{
+	m_Points.Add(x, y, z);
+}
+
+//---------------------------------------------------------
+void CThin_Plate_Spline::Add_Point(const TSG_Point &p, double z)
+{
+	m_Points.Add(p.x, p.y, z);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CThin_Plate_Spline::_Get_hDistance(TSG_Point_3D A, TSG_Point_3D B)
+{
+	A.x	-= B.x;
+	A.y	-= B.y;
+
+	return( sqrt(A.x*A.x + A.y*A.y) );
+}
+
+//---------------------------------------------------------
+double CThin_Plate_Spline::_Get_Base_Funtion(double x)
+{
+	return( x > 0.0 ? x*x * log(x) : 0.0 );
+}
+
+//---------------------------------------------------------
+double CThin_Plate_Spline::_Get_Base_Funtion(TSG_Point_3D A, double x, double y)
+{
+	x	-= A.x;
+	y	-= A.y;
+	x	= sqrt(x*x + y*y);
+
+	return( x > 0.0 ? x*x * log(x) : 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//	Calculate Thin Plate Spline (TPS) weights from control points.
+//
+bool CThin_Plate_Spline::Create(double Regularization, bool bSilent)
+{
+	bool		bResult	= false;
+	int			n;
+
+	//-----------------------------------------------------
+	// You We need at least 3 points to define a plane
+	if( (n = m_Points.Get_Count()) >= 3 )
+	{
+		int				i, j;
+		double			a, b;
+		TSG_Point_3D	Point;
+		CSG_Matrix		M;
+
+		//-------------------------------------------------
+		// Allocate the matrix and vector
+		M	.Create(n + 3, n + 3);
+		m_V	.Create(n + 3);
+
+		//-------------------------------------------------
+		// Fill K (n x n, upper left of L) and calculate
+		// mean edge length from control points
+		//
+		// K is symmetrical so we really have to
+		// calculate only about half of the coefficients.
+		for(i=0, a=0.0; i<n && (bSilent || SG_UI_Process_Set_Progress(i, n)); ++i )
+		{
+			Point	= m_Points[i];
+
+			for(j=i+1; j<n; ++j)
+			{
+				b		 = _Get_hDistance(Point, m_Points[j]);
+				a		+= b * 2.0;	// same for upper & lower tri
+				M[i][j]	 = (M[j][i]	= _Get_Base_Funtion(b));
+			}
+		}
+
+		a	/= (double)(n*n);
+
+		//-------------------------------------------------
+		// Fill the rest of L
+		for(i=0; i<n; ++i)
+		{
+			// diagonal: reqularization parameters (lambda * a^2)
+			M[i][i]		= Regularization * (a*a);
+
+			// P (n x 3, upper right)
+			M[i][n + 0]	= 1.0;
+			M[i][n + 1]	= m_Points[i].x;
+			M[i][n + 2]	= m_Points[i].y;
+
+			// P transposed (3 x n, bottom left)
+			M[n + 0][i]	= 1.0;
+			M[n + 1][i]	= m_Points[i].x;
+			M[n + 2][i]	= m_Points[i].y;
+		}
+
+		//-------------------------------------------------
+		// O (3 x 3, lower right)
+		for(i=n; i<n+3; ++i)
+		{
+			for(j=n; j<n+3; ++j)
+			{
+				M[i][j]	= 0.0;
+			}
+		}
+
+		//-------------------------------------------------
+		// Fill the right hand vector m_V
+		for(i=0; i<n; ++i)
+		{
+			m_V[i]	= m_Points[i].z;
+		}
+
+		m_V[n + 0]	= m_V[n + 1]	= m_V[n + 2]	= 0.0;
+
+		//-------------------------------------------------
+		// Solve the linear system "inplace"
+		if( !bSilent )
+			SG_UI_Process_Set_Text(_TL("Solving Matrix"));
+
+		bResult		= SG_Matrix_Solve(M, m_V, bSilent);
+	}
+
+	//-----------------------------------------------------
+	if( !bResult )
+	{
+		Destroy();
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+double CThin_Plate_Spline::Get_Value(double x, double y)
+{
+	if( m_V.Get_N() > 0 )
+	{
+		int		n	= m_Points.Get_Count();
+		double	z	= m_V[n + 0] + m_V[n + 1] * x + m_V[n + 2] * y;
+
+		for(int i=0; i<n; i++)
+		{
+			z	+= m_V[i] * _Get_Base_Funtion(m_Points[i], x, y);
+		}
+
+		return( z );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_spline/Thin_Plate_Spline.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     grid_spline                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Thin_Plate_Spline.h                  //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Thin_Plate_Spline_H
+#define HEADER_INCLUDED__Thin_Plate_Spline_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_spline_EXPORT CThin_Plate_Spline
+{
+public:
+	CThin_Plate_Spline(void);
+	virtual ~CThin_Plate_Spline(void);
+
+	bool					Destroy				(void);
+
+	void					Add_Point			(double x, double y, double z);
+	void					Add_Point			(const TSG_Point &p, double z);
+	CSG_Points_3D &			Get_Points			(void)	{	return( m_Points );		}
+
+	bool					Create				(double Regularization = 0.0, bool bSilent = true);
+
+	bool					is_Okay				(void)	{	return( m_V.Get_N() > 0 );	}
+
+	double					Get_Value			(double x, double y);
+
+
+private:
+
+	CSG_Points_3D			m_Points;
+
+	CSG_Vector				m_V;
+
+
+	double					_Get_hDistance		(TSG_Point_3D A, TSG_Point_3D B);
+	double					_Get_Base_Funtion	(double x);
+	double					_Get_Base_Funtion	(TSG_Point_3D A, double x, double y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif	// #ifndef HEADER_INCLUDED__Thin_Plate_Spline_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,493 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   CreateGridSystem                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  CreateGridSystem.cpp                 //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de                         //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "CreateGridSystem.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+CCreateGridSystem::CCreateGridSystem(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1;
+
+	Parameters.Set_Name(_TL("Create Grid System"));
+
+	Set_Author(_TL("Copyrights (c) 2007 by Volker Wichmann"));
+	
+	Parameters.Set_Description(_TW(
+		"This module creates a new user specified Grid System for use with other modules.\n\n"
+		"First of all, please consider the following issues before using the module:\n"
+		"(a) all calculations of the module refer to the lower left corner of the grid system, i.e. "
+		"the xMin and yMin values. This coordinate is fixed unless you specify an offset.\n"
+		"(b) the module follows the philosophy of SAGA in that the values describing the extent refer to the "
+		"cell centers. If you like to match the extent with the border of a grid, use an offset.\n\n"
+		"The module provides four possibilities to set/determine the extent of the grid system:\n"
+		"(1) by specifying the coordinate of the lower left cell (xMin, yMin) and the number of cells in W-E (NX) and S-N (NY) direction\n"
+		"(2) by specifying the coordinates the of lower left (xMin, yMin) and the upper right (xMax, yMax) cell\n"
+		"(3) by the extent of the shape(s) provided in the Data Objects section\n"
+		"(4) by the extent of the grid(s) provided in the Data Objects section\n\n"
+		"After selecting the appropriate method to determine the extent, the next step is to specify the "
+		"cellsize of the new grid system.\n"
+		"For all methods supplied to determine the extent but number (1), three possibilities are provided to "
+		"adjust cellsize and grid system extent (please remember, the lower left corner is fixed!):\n"
+		"(I) adjust the extent to match the cellsize\n"
+		"(II) adjust the cellsize to match the extent in E-W direction\n"
+		"(III) adjust the cellsize to match the extent in S-N direction\n\n"
+		"Finally it is possible to apply an offset to the lower left corner of the grid system. "
+		"In this case check the Use Offset option and specify the offset in W-E and S-N direction. Positive values "
+		"result in a shift in E/N, negative in W/S direction.\n"
+		"In order to create the grid system the module needs to create a dummy grid.")
+	);
+
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Dummy Grid"),
+		_TL("")
+	);
+
+	pNode_0 = Parameters.Add_Choice(
+		NULL, "M_EXTENT", _TL("Set extent by"),
+		_TL("Please choose a method of module operation."),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("xMin, yMin, NX, NY"),
+			_TL("xMin, yMin, xMax, yMax"),
+			_TL("Shape(s)"),
+			_TL("Grid(s)")
+		), 0
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "XMIN", _TL("xMin"),
+		_TL("minimum x value"),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "YMIN", _TL("yMin"),
+		_TL("minimum y value"),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "XMAX", _TL("xMax"),
+		_TL("maximum x value"),
+		PARAMETER_TYPE_Double, 100.0
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "YMAX", _TL("yMax"),
+		_TL("maximum y value"),
+		PARAMETER_TYPE_Double, 100.0
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "NX", _TL("NX"),
+		_TL("number of cells in W-E direction"),
+		PARAMETER_TYPE_Int, 10, 1, true
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "NY", _TL("NY"),
+		_TL("number of cells in S-N direction"),
+		PARAMETER_TYPE_Int, 10, 1, true
+	);
+
+	pNode_0 = Parameters.Add_Value(
+		NULL, "CELLSIZE", _TL("Cellsize"),
+		_TL("Cellsize"),
+		PARAMETER_TYPE_Double, 10.0, 0.0, true
+	);
+
+	pNode_0 = Parameters.Add_Choice(
+		NULL, "ADJUST", _TL("Adjust"),
+		_TL("Choose method how to adjust input values."),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Extent to CellSize"),
+			_TL("CellSize to W-E Extent"),
+			_TL("CellSize to S-N Extent")
+		), 0
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL, "USEOFF", _TL("Use Offset"),
+		_TL("Apply offset?"),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "XOFFSET", _TL("X offset"),
+		_TL("Positive values result in a shift in E direction."),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	pNode_1 = Parameters.Add_Value(
+		pNode_0, "YOFFSET", _TL("Y offset"),
+		_TL("Positive values result in a shift in N direction."),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+    pNode_0 = Parameters.Add_Value(
+		NULL, "INIT", _TL("Initialization Value"),
+		_TL("Value which is assigned to the dummy grid."),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL, "SHAPESLIST", _TL("Shape(s)"),
+		_TL("Shape(s) to fit extent to"),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "GRIDLIST", _TL("Grid(s)"),
+		_TL("Grid(s) to fit extent to"),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+}
+
+//---------------------------------------------------------
+CCreateGridSystem::~CCreateGridSystem(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+bool CCreateGridSystem::On_Execute(void)		
+{
+	CSG_Grid					*pDummy;
+	CSG_Shapes					*pShapes;
+	CSG_Rect					extent;
+	CSG_Parameter_Shapes_List	*pShapesList;
+	CSG_Parameter_Grid_List		*pGridList;
+	CSG_Grid_System				System;
+
+	double		xMin, xMax, yMin, yMax, cellsize, offset_x, offset_y, xRange, yRange, n, initVal;
+	int			NX, NY, m_extent, m_adjust, i;
+	bool		useoff;
+
+
+	xMin		= Parameters("XMIN")->asDouble();
+	yMin		= Parameters("YMIN")->asDouble();
+	xMax		= Parameters("XMAX")->asDouble();
+	yMax		= Parameters("YMAX")->asDouble();
+	NX			= Parameters("NX")->asInt();
+	NY			= Parameters("NY")->asInt();
+	cellsize	= Parameters("CELLSIZE")->asDouble();
+	offset_x	= Parameters("XOFFSET")->asDouble();
+	offset_y	= Parameters("YOFFSET")->asDouble();
+	useoff		= Parameters("USEOFF")->asBool();
+	m_extent	= Parameters("M_EXTENT")->asInt();
+	m_adjust	= Parameters("ADJUST")->asInt();
+    initVal     = Parameters("INIT")->asDouble();
+	pShapesList	= Parameters("SHAPESLIST")->asShapesList();
+	pGridList	= Parameters("GRIDLIST")->asGridList();
+
+
+	if( useoff )
+	{
+		xMin += offset_x;
+		yMin += offset_y;
+		xMax += offset_x;
+		yMax += offset_y;
+	}
+
+	switch( m_extent )
+	{
+	case 0:					// xMin, yMin, NX, NY
+
+		System.Assign(cellsize, xMin, yMin, NX, NY);
+		break;
+
+	case 1:					// xMin, yMin, xMax, yMax
+
+		if( xMin > xMax || yMin > yMax )
+		{
+			Message_Add(CSG_String::Format(_TL("\nError: Please verify your xMin, yMin, xMax, yMax settings!\n")));
+			return false;
+		}
+
+		xRange = xMax - xMin;
+		yRange = yMax - yMin;
+
+		if( m_adjust == 0 )			// extent to cellsize
+		{
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) floor(xRange / cellsize + 0.5);
+				xMax = xMin + NX * cellsize;
+			}
+			
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) floor(yRange / cellsize + 0.5);
+				yMax = yMin + NY * cellsize;
+			}
+		}
+		else if( m_adjust == 1)		// cellsize to W-E extent
+		{
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) (xRange/cellsize);
+				cellsize = xRange/NX;
+			}			
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) floor(yRange / cellsize + 0.5);
+				yMax = yMin + NY * cellsize;
+			}
+		}
+		else						// cellsize to S-N extent
+		{
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) (yRange/cellsize);
+				cellsize = yRange/NY;
+			}	
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) floor(xRange / cellsize + 0.5);
+				xMax = xMin + NX * cellsize;
+			}
+		}
+
+		System.Assign(cellsize, xMin, yMin, xMax, yMax);
+		break;
+
+	case 2:			// Shape(s)
+
+		if( pShapesList == NULL || pShapesList->Get_Count() == 0)
+		{
+			Message_Add(CSG_String::Format(_TL("\nError: the method Extent by Shape(s) requires shape(s) as input!\n")));
+			return false;
+		}
+
+		for (i=0; i<pShapesList->Get_Count(); i++)
+		{
+			pShapes = pShapesList->asShapes(i);
+			extent = pShapes->Get_Extent();
+
+			if (i==0)
+			{
+				xMin = extent.Get_XMin();
+				yMin = extent.Get_YMin();
+				xMax = extent.Get_XMax();
+				yMax = extent.Get_YMax();
+			}
+			else
+			{
+				xMin = (extent.Get_XMin() < xMin) ? extent.Get_XMin() : xMin;
+				yMin = (extent.Get_YMin() < yMin) ? extent.Get_YMin() : yMin;
+				xMax = (extent.Get_XMax() > xMax) ? extent.Get_XMax() : xMax;
+				yMax = (extent.Get_YMax() > yMax) ? extent.Get_YMax() : yMax;
+			}		
+		}
+
+		if( useoff )
+		{
+			xMin += offset_x;
+			xMax += offset_x;
+			yMin += offset_y;
+			yMax += offset_y;
+		}
+
+		xRange = xMax - xMin;
+		yRange = yMax - yMin;
+
+		if( m_adjust == 0 )			// extent to cellsize
+		{
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) floor(xRange / cellsize + 0.5);
+				xMax = xMin + NX * cellsize;
+			}
+			
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) floor(yRange / cellsize + 0.5);
+				yMax = yMin + NY * cellsize;
+			}
+		}
+		else if( m_adjust == 1)		// cellsize to W-E extent
+		{
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) (xRange/cellsize);
+				cellsize = xRange/NX;
+			}	
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) floor(yRange / cellsize + 0.5);
+				yMax = yMin + NY * cellsize;
+			}
+		}
+		else						// cellsize to S-N extent
+		{
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) (yRange/cellsize);
+				cellsize = yRange/NY;
+			}
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) floor(xRange / cellsize + 0.5);
+				xMax = xMin + NX * cellsize;
+			}
+		}
+
+		System.Assign(cellsize, xMin, yMin, xMax, yMax);
+		break;	
+
+	case 3:				// Grid(s)
+
+		if( pGridList == NULL || pGridList->Get_Count() == 0)
+		{
+			Message_Add(CSG_String::Format(_TL("\nError: the method Extent by Grid(s) requires grid(s) as input!\n")));
+			return false;
+		}
+				
+		for (i=0; i<pGridList->Get_Count(); i++)
+		{
+			pDummy = pGridList->asGrid(i);
+			extent = pDummy->Get_Extent();
+
+			if (i==0)
+			{
+				xMin = extent.Get_XMin();
+				yMin = extent.Get_YMin();
+				xMax = extent.Get_XMax();
+				yMax = extent.Get_YMax();
+			}
+			else
+			{
+				xMin = (extent.Get_XMin() < xMin) ? extent.Get_XMin() : xMin;
+				yMin = (extent.Get_YMin() < yMin) ? extent.Get_YMin() : yMin;
+				xMax = (extent.Get_XMax() > xMax) ? extent.Get_XMax() : xMax;
+				yMax = (extent.Get_YMax() > yMax) ? extent.Get_YMax() : yMax;
+			}		
+		}
+
+		if( useoff )
+		{
+			xMin += offset_x;
+			xMax += offset_x;
+			yMin += offset_y;
+			yMax += offset_y;
+		}
+
+		xRange = xMax - xMin;
+		yRange = yMax - yMin;
+
+		if( m_adjust == 0 )			// extent to cellsize
+		{
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) floor(xRange / cellsize + 0.5);
+				xMax = xMin + NX * cellsize;
+			}
+			
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) floor(yRange / cellsize + 0.5);
+				yMax = yMin + NY * cellsize;
+			}
+		}
+		else if( m_adjust == 1)		// cellsize to W-E extent
+		{
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) (xRange/cellsize);
+				cellsize = xRange/NX;
+			}			
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) floor(yRange / cellsize + 0.5);
+				yMax = yMin + NY * cellsize;
+			}
+		}
+		else						// cellsize to S-N extent
+		{
+			if( modf((yRange/cellsize), &n) != 0.0 )
+			{
+				NY = (int) (yRange/cellsize);
+				cellsize = yRange/NY;
+			}			
+			if( modf((xRange/cellsize), &n) != 0.0 )
+			{
+				NX = (int) floor(xRange / cellsize + 0.5);
+				xMax = xMin + NX * cellsize;
+			}
+		}
+
+		System.Assign(cellsize, xMin, yMin, xMax, yMax);
+		break;
+	}
+		
+	pDummy = SG_Create_Grid(System, SG_DATATYPE_Double);
+	pDummy->Assign(initVal);
+	pDummy->Set_Name(_TL("Dummy Grid"));
+	Parameters("GRID")->Set_Value(pDummy);
+
+	return (true);
+
+}
+

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/CreateGridSystem.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,104 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   CreateGridSystem                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  CreateGridSystem.h                   //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     wichmann at laserdata.at                  //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__CreateGridSystem_H
+#define HEADER_INCLUDED__CreateGridSystem_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+//---------------------------------------------------------
+class grid_tools_EXPORT CCreateGridSystem : public CSG_Module
+{
+public:
+	CCreateGridSystem(void);
+	virtual ~CCreateGridSystem(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+};
+
+
+
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__CreateGridSystem_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,173 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Aggregate.cpp                  //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Victor Olaya                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+#include "Grid_Aggregate.h"
+
+#define SUM 0
+#define MIN 1
+#define MAX 2
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Aggregate::CGrid_Aggregate(void)
+{
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Aggregate"));
+
+	Set_Author(_TL("Copyrights (c) 2005 by Victor Olaya"));
+
+	Set_Description	(_TW("Aggregate")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "SIZE"	, _TL("Aggregation Size"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 2, 2, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),	_TL("Sum|Min|Max|"), 0
+	);
+
+}
+
+//---------------------------------------------------------
+CGrid_Aggregate::~CGrid_Aggregate(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+bool CGrid_Aggregate::On_Execute(void)
+{
+	int x,y;
+	int x2,y2;
+	int i,j;
+	int iNX, iNY;
+	int iSize = Parameters("SIZE")->asInt();
+	int iMethod = Parameters("METHOD")->asInt();
+	double dMin,dMax;
+	double dSum;
+	double dValue;
+
+	iNX = (int) (Get_NX() / iSize);
+	iNY = (int) (Get_NY() / iSize);
+
+	CSG_Grid *pGrid = Parameters("INPUT")->asGrid();
+
+	CSG_Grid *pOutput = SG_Create_Grid(pGrid->Get_Type(), iNX, iNY, pGrid->Get_Cellsize() * iSize, 
+					pGrid->Get_XMin(), pGrid->Get_YMin());
+
+	pOutput->Set_Name(pGrid->Get_Name());
+
+	for (y = 0, y2 = 0; y2 < iNY; y+=iSize, y2++){
+		for (x = 0, x2 = 0; x2 < iNX; x+=iSize, x2++){
+			dMax = dMin = pGrid->asDouble(x,y);
+			dSum = 0;
+			for (i = 0; i < iSize; i++){
+				for (j = 0; j < iSize; j++){
+					dValue = pGrid->asDouble(x+i,y+j);
+					if (dValue > dMax){
+						dMax = dValue;
+					}//if
+					if (dValue < dMin){
+						dMin = dValue;
+					}//if
+					dSum += dValue;
+				}//for
+			}//for
+			switch (iMethod){
+			case SUM:
+				pOutput->Set_Value(x2,y2,dSum);
+				break;
+			case MIN:
+				pOutput->Set_Value(x2,y2,dMin);
+				break;
+			case MAX:
+				pOutput->Set_Value(x2,y2,dMax);
+				break;
+			default:
+				break;
+			}
+		}//for
+	}//for
+
+	DataObject_Add(pOutput);
+
+	return true;
+
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Aggregate.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,85 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Aggregate.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Victor Olaya                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Aggregate_H
+#define HEADER_INCLUDED__Grid_Aggregate_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Aggregate : public CSG_Module_Grid  
+{
+public:
+	CGrid_Aggregate(void);
+	virtual ~CGrid_Aggregate(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Aggregate_H
\ No newline at end of file

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,225 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Buffer_Proximity.cpp              //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volker.wichmann at ku-eichstaett.de       //
+//                                                       //
+//    contact:    Volker Wichmann                        //
+//                Research Associate                     //
+//                Chair of Physical Geography		     //
+//				  KU Eichstätt-Ingolstadt				 //
+//                Ostenstr. 18                           //
+//                85072 Eichstätt                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+#include "Grid_Buffer_Proximity.h"
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+CGrid_Proximity_Buffer::CGrid_Proximity_Buffer(void){
+
+	Set_Name(_TL("Grid Proximity Buffer"));
+	Set_Author(_TL("Copyrights (c) 2006 by Volker Wichmann"));
+	Set_Description(_TW(
+		"This module calculates the euclidian distance within a buffer distance from all NoData cells to the nearest "
+		"valid neighbour in a source grid. Additionally, the source cells define the zones that will be used in the "
+		"euclidean allocation calculations. Cell values in the source grid are treated as IDs (integer) and "
+		"used in the allocation grid to identify the grid value of the closest source cell. If a cell is at an equal "
+		"distance to two or more sources, the cell is assigned to the source that is first encountered in the modules scanning "
+		"process. The buffer grid is a "
+		"reclassification of the distance grid using a user specified equidistance to create a set of discrete distance "
+		"buffers from source features. The buffer zones are coded with the maximum distance value of the corresponding buffer interval. " 
+		"The output value type for the distance grid is floating-point. The output values for the allocation and buffer "
+		"grid are of type integer. The duration of module execution is dependent on the number of source cells and the buffer distance."));
+
+	Parameters.Add_Grid(NULL, 
+						"SOURCE",
+						_TL("Source Grid"), 						
+						_TL("Grid with features to be buffered [Category/NoData]"), 
+						PARAMETER_INPUT);
+
+	Parameters.Add_Grid(NULL, 
+						"DISTANCE", 
+						_TL("Distance Grid"), 
+						_TL("Grid with euclidian distance to nearest source cell [grid units]"), 
+						PARAMETER_OUTPUT, 
+						true, 
+						SG_DATATYPE_Double);
+
+	Parameters.Add_Grid(NULL, 
+						"ALLOC", 
+						_TL("Allocation Grid"), 
+						_TL("Grid with category of nearest source cell [Category]"), 
+						PARAMETER_OUTPUT, 
+						true, 
+						SG_DATATYPE_Int);
+
+	Parameters.Add_Grid(NULL, 
+						"BUFFER", 
+						_TL("Buffer Grid"), 
+						_TL("Reclassification of distance grid to buffer zones with a width equal to the equidistance value."), 
+						PARAMETER_OUTPUT, 
+						true, 
+						SG_DATATYPE_Int);
+
+	Parameters.Add_Value(NULL, 
+						"DIST", 
+						_TL("Buffer distance"), 
+						_TL("Buffer distance (grid units)."), 
+						PARAMETER_TYPE_Double, 
+						500.0);
+
+	Parameters.Add_Value(NULL, 
+						"IVAL", 
+						_TL("Equidistance"), 
+						_TL("Reclassify buffer distance to intervals of euqidistance ..."), 
+						PARAMETER_TYPE_Int, 
+						100);
+						
+
+}
+
+
+CGrid_Proximity_Buffer::~CGrid_Proximity_Buffer(void)
+{}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+bool CGrid_Proximity_Buffer::On_Execute(void){
+	
+	CSG_Grid	*pSource, *pDistance, *pAlloc, *pBuffer;
+	double 		dBufDist, dDist, cellSize;
+	int 		x, y, i, j, imin, imax, jmin, jmax, iBufDist, alloc, ival;
+
+	pSource 	= Parameters("SOURCE")->asGrid();
+	pDistance 	= Parameters("DISTANCE")->asGrid();
+	pAlloc 		= Parameters("ALLOC")->asGrid();
+	pBuffer 	= Parameters("BUFFER")->asGrid();
+	ival		= Parameters("IVAL")->asInt();
+
+	cellSize = pSource->Get_Cellsize();
+	dBufDist = Parameters("DIST")->asDouble() / cellSize;
+	iBufDist = (int) (dBufDist + 2.0);
+	dBufDist = pow(dBufDist, 2);
+
+	pDistance->Assign_NoData();
+	pAlloc->Assign_NoData();
+	pBuffer->Assign_NoData();
+
+    for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{		
+		for(x=0; x<Get_NX(); x++)
+		{			
+ 			if( !pSource->is_NoData(x, y) )
+			{
+				alloc = pSource->asInt(x, y);
+
+				pAlloc->Set_Value(x, y, alloc);
+				pDistance->Set_Value(x, y, 0.0);
+
+				imin = M_GET_MAX(0, x-iBufDist);
+				imax = M_GET_MIN(x+iBufDist, Get_NX());
+				jmin = M_GET_MAX(0, y-iBufDist);
+				jmax = M_GET_MIN(y+iBufDist, Get_NY());
+
+				for(i=imin; i<imax; i++)
+				{
+					for(j=jmin; j<jmax; j++)
+					{
+						if( pSource->is_NoData(i, j) )
+						{
+							dDist= (x-i)*(x-i)+(y-j)*(y-j);		
+						
+							if( dDist <= dBufDist && (pDistance->is_NoData(i, j) || pDistance->asDouble(i, j) > dDist) )
+							{
+								pDistance->Set_Value(i, j, dDist);
+								pAlloc->Set_Value(i, j, alloc);
+							}
+						}
+					}//for
+				}//for
+			}//if
+		}//for
+	}//for						
+
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{		
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pDistance->is_NoData(x, y) )
+			{
+				dDist = sqrt(pDistance->asDouble(x, y)) * cellSize;
+				pDistance->Set_Value(x, y, dDist);
+
+				i = 0;
+				while( i< dDist )
+					i += ival;
+				pBuffer->Set_Value(x, y, i);
+			}
+		}
+	}
+
+	return( true );
+
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Buffer_Proximity.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Buffer_Proximity.h                //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volker.wichmann at ku-eichstaett.de       //
+//                                                       //
+//    contact:    Volker Wichmann                        //
+//                Research Associate                     //
+//                Chair of Physical Geography		     //
+//				  KU Eichstätt-Ingolstadt				 //
+//                Ostenstr. 18                           //
+//                85072 Eichstätt                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Buffer_Proximity_H
+#define HEADER_INCLUDED__Grid_Buffer_Proximity_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class grid_tools_EXPORT CGrid_Proximity_Buffer : public CSG_Module_Grid {
+
+public:
+	CGrid_Proximity_Buffer(void);
+	virtual ~CGrid_Proximity_Buffer(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Buffers") );	}
+
+
+protected:
+	virtual bool			On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Buffer_Proximity_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,177 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Tutorial                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Completion.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Completion.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Completion::CGrid_Completion(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Patching"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Fill gaps of a grid with data from another grid. "
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Standard in- and output...
+
+	Parameters.Add_Grid(
+		NULL	, "ORIGINAL"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ADDITIONAL"		, _TL("Patch Grid"),
+		_TL(""),
+		PARAMETER_INPUT, false
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "COMPLETED"		, _TL("Completed Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "INTERPOLATION"	, _TL("Interpolation Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Completion::~CGrid_Completion(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//	Run													 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Completion::On_Execute(void)
+{
+	int					x, y;
+	double				xPos, yPos, Value;
+	TSG_Grid_Interpolation	Interpolation;
+	CSG_Grid				*pGrid, *pAdditional;
+
+	pAdditional		= Parameters("ADDITIONAL")	->asGrid();
+	pGrid			= Parameters("COMPLETED")	->asGrid();
+
+	if( pGrid->is_Intersecting(pAdditional->Get_Extent()) )
+	{
+		if( pGrid != Parameters("ORIGINAL")->asGrid() )
+		{
+			Process_Set_Text(_TL("Copying original data..."));
+
+			pGrid->Assign(Parameters("ORIGINAL")->asGrid());
+		}
+
+		Interpolation	= (TSG_Grid_Interpolation)Parameters("INTERPOLATION")->asInt();
+
+		Process_Set_Text(_TL("Data completion..."));
+
+		for(y=0, yPos=Get_YMin(); y<Get_NY() && Set_Progress(y, Get_NY()); y++, yPos+=Get_Cellsize())
+		{
+			if( yPos >= pAdditional->Get_YMin() )
+			{
+				for(x=0, xPos=Get_XMin(); x<Get_NX() && xPos<=pAdditional->Get_XMax(); x++, xPos+=Get_Cellsize())
+				{
+					if( pGrid->is_NoData(x, y) && xPos >= pAdditional->Get_XMin() )
+					{
+						if( !pAdditional->is_NoData_Value(Value = pAdditional->Get_Value(xPos, yPos, Interpolation)) )
+						{
+							pGrid->Set_Value(x, y, Value);
+						}
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	Error_Set(_TL("Nothing to do: there is no intersection with additonal grid."));
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Completion.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Tutorial                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Completion.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Completion_H
+#define HEADER_INCLUDED__Grid_Completion_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Completion : public CSG_Module_Grid
+{
+public:
+	CGrid_Completion(void);
+	virtual ~CGrid_Completion(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Completion_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,335 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Cut.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "Grid_Cut.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Cut::CGrid_Cut(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Cutting"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create a new grid from interactively selected cut of an input grid.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "CUT"		, _TL("Cut"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"	, _TL("Additional Grids"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL, false
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "CUTS"	, _TL("Additional Cuts"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, false
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters	= Add_Parameters("CUT", _TL("Cut"), _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "XMIN"		, _TL("Left")		, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "XMAX"		, _TL("Right")		, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "YMIN"		, _TL("Bottom")		, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "YMAX"		, _TL("Top")		, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "NX"			, _TL("Columns")	, _TL(""), PARAMETER_TYPE_Int, 1, 1, true
+	);
+
+	pParameters->Add_Value(
+		NULL, "NY"			, _TL("Rows")		, _TL(""), PARAMETER_TYPE_Int, 1, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Cut::~CGrid_Cut(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CGrid_Cut::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	int		nx, ny;
+	double	xMin, xMax, yMin, yMax, d;
+
+	if( m_pGrid && !SG_STR_CMP(pParameters->Get_Identifier(), SG_T("CUT")) )
+	{
+		xMin	= pParameters->Get_Parameter("XMIN")->asDouble();
+		xMax	= pParameters->Get_Parameter("XMAX")->asDouble();
+		yMin	= pParameters->Get_Parameter("YMIN")->asDouble();
+		yMax	= pParameters->Get_Parameter("YMAX")->asDouble();
+		nx		= pParameters->Get_Parameter("NX")	->asInt();
+		ny		= pParameters->Get_Parameter("NY")	->asInt();
+
+		if( xMin > xMax )	{	d	= xMin;	xMin	= xMax;	xMax	= d;	}
+		if( yMin > yMax )	{	d	= yMin;	yMin	= yMax;	yMax	= d;	}
+
+		d		= m_pGrid->Get_Cellsize();
+
+		if     ( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("NX")) )
+		{
+			xMax	= xMin + nx * d;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMIN")) )
+		{
+			nx		= 1    + (int)((xMax - xMin) / d);
+			xMin	= xMax - nx * d;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMAX")) )
+		{
+			nx		= 1    + (int)((xMax - xMin) / d);
+			xMax	= xMin + nx * d;
+		}
+
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("NY")) )
+		{
+			yMax	= yMin + ny * d;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMIN")) )
+		{
+			ny		= 1    + (int)((yMax - yMin) / d);
+			yMin	= yMax - ny * d;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMAX")) )
+		{
+			ny		= 1    + (int)((yMax - yMin) / d);
+			yMax	= yMin + ny * d;
+		}
+
+		pParameters->Get_Parameter("XMIN")	->Set_Value(xMin);
+		pParameters->Get_Parameter("XMAX")	->Set_Value(xMax);
+		pParameters->Get_Parameter("YMIN")	->Set_Value(yMin);
+		pParameters->Get_Parameter("YMAX")	->Set_Value(yMax);
+		pParameters->Get_Parameter("NX")	->Set_Value(nx);
+		pParameters->Get_Parameter("NY")	->Set_Value(ny);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Cut::On_Execute(void)
+{
+	m_bDown		= false;
+
+	m_pGrid		= Parameters("GRID")	->asGrid();
+	m_pGrids	= Parameters("GRIDS")	->asGridList();
+
+	Parameters("CUTS")->asGridList()->Del_Items();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Cut::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	CSG_Rect		r;
+	CSG_Grid_System	System;
+	CSG_Grid		*pCut;
+	CSG_Parameters	*pParameters;
+
+	switch( Mode )
+	{
+	//-----------------------------------------------------
+	case MODULE_INTERACTIVE_LDOWN:
+		if( m_bDown == false )
+		{
+			m_bDown		= true;
+			m_ptDown	= Fit_to_Grid(ptWorld);
+		}
+
+		return( true );
+
+	//-----------------------------------------------------
+	case MODULE_INTERACTIVE_LUP:
+		if( m_bDown == true )
+		{
+			m_bDown		= false;
+			ptWorld		= Fit_to_Grid(ptWorld);
+
+			r.Assign(m_ptDown.Get_X(), m_ptDown.Get_Y(), ptWorld.Get_X(), ptWorld.Get_Y());
+
+			pParameters	= Get_Parameters("CUT");
+
+			pParameters->Get_Parameter("XMIN")	->Set_Value(r.Get_XMin());
+			pParameters->Get_Parameter("XMAX")	->Set_Value(r.Get_XMax());
+			pParameters->Get_Parameter("YMIN")	->Set_Value(r.Get_YMin());
+			pParameters->Get_Parameter("YMAX")	->Set_Value(r.Get_YMax());
+			pParameters->Get_Parameter("NX")	->Set_Value(1 + (int)(r.Get_XRange() / m_pGrid->Get_Cellsize()));
+			pParameters->Get_Parameter("NY")	->Set_Value(1 + (int)(r.Get_YRange() / m_pGrid->Get_Cellsize()));
+
+			if( Dlg_Parameters("CUT") )
+			{
+				r.Assign(
+					pParameters->Get_Parameter("XMIN")->asDouble(),
+					pParameters->Get_Parameter("YMIN")->asDouble(),
+					pParameters->Get_Parameter("XMAX")->asDouble(),
+					pParameters->Get_Parameter("YMAX")->asDouble()
+				);
+
+				if( r.Intersect(m_pGrid->Get_Extent()) && System.Assign(m_pGrid->Get_Cellsize(), r) )
+				{
+					pCut	= SG_Create_Grid(System, m_pGrid->Get_Type());
+					pCut->Assign(m_pGrid, GRID_INTERPOLATION_NearestNeighbour);
+					pCut->Set_Name(m_pGrid->Get_Name());
+					Parameters("CUT")->Set_Value(pCut);
+
+					for(int i=0; i<m_pGrids->Get_Count(); i++)
+					{
+						if( r.Intersect(m_pGrids->asGrid(i)->Get_Extent()) )
+						{
+							pCut	= SG_Create_Grid(System, m_pGrids->asGrid(i)->Get_Type());
+							pCut->Assign(m_pGrids->asGrid(i), GRID_INTERPOLATION_NearestNeighbour);
+							pCut->Set_Name(m_pGrids->asGrid(i)->Get_Name());
+							Parameters("CUTS")->asGridList()->Add_Item(pCut);
+							DataObject_Add(pCut);
+						}
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_Point CGrid_Cut::Fit_to_Grid(TSG_Point pt)
+{
+	pt.x	= m_pGrid->Get_XMin() + m_pGrid->Get_Cellsize() * (int)(0.5 + (pt.x - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize());
+	pt.y	= m_pGrid->Get_YMin() + m_pGrid->Get_Cellsize() * (int)(0.5 + (pt.y - m_pGrid->Get_YMin()) / m_pGrid->Get_Cellsize());
+
+	return( pt );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Cut.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Grid_Cut.h                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Cut_H
+#define HEADER_INCLUDED__Grid_Cut_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Cut : public CSG_Module_Interactive
+{
+public:
+	CGrid_Cut(void);
+	virtual ~CGrid_Cut(void);
+
+	virtual const SG_Char *	Get_MenuPath			(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual int				On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool			On_Execute				(void);
+	virtual bool			On_Execute_Position		(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	bool					m_bDown;
+
+	CSG_Point				m_ptDown;
+
+	CSG_Grid				*m_pGrid;
+
+	CSG_Parameter_Grid_List	*m_pGrids;
+
+
+	TSG_Point				Fit_to_Grid				(TSG_Point pt);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Cut_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,314 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Fill.cpp                      //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Fill.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Fill::CGrid_Fill(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Change Grid Values - Flood Fill"));
+
+	Set_Author		(SG_T("(c) 2005 by A.Ringeler, (c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Interactively use the flood fill method to replace a grid's cell values. "
+		"If the target is not set, the changes will be stored to the original grid. ")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL	, "GRID_IN"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID_OUT"	, _TL("Changed Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL	, "FILL"		, _TL("Fill Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1
+	); 
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Value to be replaced"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("value at mouse position"),
+			_TL("fixed value"),
+			_TL("tolerance as absolute values")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ZFIXED"		, _TL("Fixed value to be replaced"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	); 
+
+	Parameters.Add_Value(
+		NULL	, "DZMAX"		, _TL("Upper Tolerance"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0
+	); 
+
+	Parameters.Add_Value(
+		NULL	, "DZMIN"		, _TL("Lower Tolerance"),
+		_TL(""),
+		PARAMETER_TYPE_Double, -1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NODATA"		, _TL("Fill NoData"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	); 
+}
+
+//---------------------------------------------------------
+CGrid_Fill::~CGrid_Fill(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Fill::On_Execute(void)
+{
+	if( Parameters("GRID_OUT")->asGrid() == NULL || Parameters("GRID_IN")->asGrid() == Parameters("GRID_OUT")->asGrid() )
+	{
+		m_pGrid	= Parameters("GRID_IN")	->asGrid();
+	}
+	else
+	{
+		m_pGrid	= Parameters("GRID_OUT")->asGrid();
+		m_pGrid->Assign(Parameters("GRID_IN")->asGrid());
+	}
+
+	m_Method			= Parameters("METHOD")	->asInt();
+	m_zFill				= Parameters("FILL")	->asDouble();
+	m_zFixed			= Parameters("ZFIXED")	->asDouble();
+	m_zTolerance_Min	= Parameters("DZMIN")	->asDouble();
+	m_zTolerance_Max	= Parameters("DZMAX")	->asDouble();
+	m_bNoData			= Parameters("NODATA")	->asBool();
+
+	if( m_zTolerance_Min > m_zTolerance_Max )
+	{
+		double	z			= m_zTolerance_Min;
+		m_zTolerance_Min	= m_zTolerance_Min;
+		m_zTolerance_Max	= z;
+	}
+
+	if (m_bNoData == true)
+		m_bNoData = false;
+	else
+		m_bNoData = true;
+
+	return( true );	
+}
+
+//---------------------------------------------------------
+bool CGrid_Fill::On_Execute_Finish(void)
+{
+	m_Stack.Clear();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CGrid_Fill::Push(int x, int y)
+{
+	if( m_iStack >= m_Stack.Get_Count() )
+	{
+		m_Stack.Set_Count(m_Stack.Get_Count() + 1000);
+	}
+
+	m_Stack[m_iStack].x	= x;
+	m_Stack[m_iStack].y	= y;
+
+	m_iStack++;
+}
+
+//---------------------------------------------------------
+inline void CGrid_Fill::Pop(int &x, int &y)
+{
+	m_iStack--;
+
+	x	= m_Stack[m_iStack].x;
+	y	= m_Stack[m_iStack].y;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Fill::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	//-----------------------------------------------------
+	if(  Mode == MODULE_INTERACTIVE_LDOWN )
+	{
+		int		x, y, i, ix, iy, nReplaced;
+		double	z, zMin, zMax;
+
+		x	= Get_System()->Get_xWorld_to_Grid(ptWorld.Get_X());
+		y	= Get_System()->Get_yWorld_to_Grid(ptWorld.Get_Y());
+
+		if( m_pGrid && m_pGrid->is_InGrid(x, y, m_bNoData) )
+		{
+			Message_Add(_TL("Starting flood fill..."));
+
+			switch( m_Method )
+			{
+			case 0:	z	= m_pGrid->asDouble(x, y);	break;	// value at mouse position
+			case 1:	z	= m_zFixed;					break;	// fixed value
+			case 2:	z	= 0.0;						break;	// tolerance as absolute values
+			}
+
+			zMin		= z + m_zTolerance_Min;
+			zMax		= z + m_zTolerance_Max;
+
+			m_iStack	= 0;
+			nReplaced	= 1;
+
+			Push(x, y);
+
+			//---------------------------------------------
+			while( m_iStack > 0 && Set_Progress(nReplaced, m_pGrid->Get_NCells()) )
+			{
+				Pop(x, y);
+
+				for(i=0; i<8; i+=2)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if(	m_pGrid->is_InGrid(ix, iy, m_bNoData) )
+					{
+						z	= m_pGrid->asDouble(ix, iy);
+
+						if( z != m_zFill && z >= zMin && z <= zMax )
+						{
+							Push(ix, iy);
+
+							m_pGrid->Set_Value(ix, iy, m_zFill);
+
+							nReplaced++;
+						}
+					}
+				}
+			}
+
+			//---------------------------------------------
+			Message_Add(_TL("ready"), false);
+			Message_Add(CSG_String::Format(SG_T("%d %s"), nReplaced, _TL("replacements")));
+
+			DataObject_Update(m_pGrid, m_pGrid->Get_ZMin(), m_pGrid->Get_ZMax());
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Fill.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Fill.h                       //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Fill_H
+#define HEADER_INCLUDED__Grid_Fill_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Fill : public CSG_Module_Grid_Interactive  
+{
+public:
+	CGrid_Fill(void);
+	virtual ~CGrid_Fill(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Values") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Finish	(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	int						m_iStack, m_Method;
+
+	double					m_zFill, m_zFixed, m_zTolerance_Min, m_zTolerance_Max;
+
+	bool					m_bNoData;
+
+	CSG_Grid					*m_pGrid;
+
+	CSG_Points_Int			m_Stack;
+
+
+	void					Push				(int  x, int  y);
+	void					Pop					(int &x, int &y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Fill_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,396 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Gaps.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Gaps.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define IS_MASKED(x, y)	(pMask ? pMask->is_NoData(x, y) : false)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Gaps::CGrid_Gaps(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Close Gaps"));
+
+	Set_Author		(SG_T("(c) 2002 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Close gaps of a grid data set (i.e. eliminate no data values). "
+		"If the target is not set, the changes will be stored to the original grid. ")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "MASK"		, _TL("Mask"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"		, _TL("Changed Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL, "THRESHOLD"	, _TL("Tension Threshold"),
+		_TL(""), PARAMETER_TYPE_Double, 0.1
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Gaps::~CGrid_Gaps(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Gaps::On_Execute(void)
+{
+	bool	bKillInput;
+
+	//-----------------------------------------------------
+	pInput		= Parameters("INPUT")	->asGrid();
+	pMask		= Parameters("MASK")	->asGrid();
+
+	if( Parameters("RESULT")->asGrid() == NULL || Parameters("RESULT")->asGrid() == pInput )
+	{
+		pResult		= pInput;
+		Parameters("RESULT")->Set_Value(pResult);
+
+		pInput		= SG_Create_Grid(pInput);
+		pInput->Assign(pResult);
+
+		bKillInput	= true;
+	}
+	else
+	{
+		pResult		= Parameters("RESULT")->asGrid();
+		pResult->Get_History().Assign(pInput->Get_History());
+
+		bKillInput	= false;
+	}
+
+	//-----------------------------------------------------
+	Tension_Main();
+
+	//-----------------------------------------------------
+	if( bKillInput )
+	{
+		delete(pInput);
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Gaps::Tension_Main(void)
+{
+	int		iStep, iStart, n;
+
+	double	max, Threshold;
+
+	Threshold	= Parameters("THRESHOLD")->asDouble();
+
+	n			= Get_NX() > Get_NY() ? Get_NX() : Get_NY();
+	iStep		= 0;
+	do	{	iStep++;	}	while( pow(2.0, iStep + 1) < n );
+	iStart		= (int)pow(2.0, iStep);
+
+	pTension_Keep		= new CSG_Grid(pResult, SG_DATATYPE_Byte);
+	pTension_Temp		= new CSG_Grid(pResult);
+
+	pResult->Assign_NoData();
+
+	for(iStep=iStart; iStep>=1; iStep/=2)
+	{
+		Tension_Init(iStep);
+
+		do
+		{
+			max		= Tension_Step(iStep);
+
+			Process_Set_Text(CSG_String::Format(SG_T("[%d] %s: %f"), iStep, _TL("max. change"), max));
+		}
+		while( max > Threshold && Process_Get_Okay(true) );
+
+		DataObject_Update(pResult, pInput->Get_ZMin(), pInput->Get_ZMax(), true);
+	}
+
+	delete(pTension_Keep);
+	delete(pTension_Temp);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Gaps::Tension_Init(int iStep)
+{
+	int		x, y, i, ix, iy, nx, ny, nz;
+
+	double	z;
+
+	//-----------------------------------------------------
+	// 1. Channels...
+
+	pTension_Temp->Assign_NoData();
+	pTension_Keep->Assign();
+
+	for(y=0; y<Get_NY(); y+=iStep)
+	{
+		ny	= y + iStep < Get_NY() ? y + iStep : Get_NY();
+
+		for(x=0; x<Get_NX(); x+=iStep)
+		{
+			if( !pInput->is_NoData(x, y) || IS_MASKED(x, y) )
+			{
+				pTension_Temp->Set_Value(x, y, pInput->asDouble(x, y) );
+				pTension_Keep->Set_Value(x, y, 1.0);
+			}
+			else
+			{
+				nx	= x + iStep < Get_NX() ? x + iStep : Get_NX();
+				nz	= 0;
+				z	= 0.0;
+
+				for(iy=y; iy<ny; iy++)
+				{
+					for(ix=x; ix<nx; ix++)
+					{
+						if( pInput->is_InGrid(ix, iy) )
+						{
+							z	+= pInput->asDouble(ix, iy);
+							nz++;
+						}
+					}
+				}
+
+				if( nz > 0 )
+				{
+					pTension_Temp->Set_Value(x, y, z / (double)nz );
+					pTension_Keep->Set_Value(x, y, 1.0);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	// 2. Previous Iteration...
+
+	for(y=0; y<Get_NY(); y+=iStep)
+	{
+		for(x=0; x<Get_NX(); x+=iStep)
+		{
+			if( pTension_Keep->asByte(x, y) == false )
+			{
+				if( !pResult->is_NoData(x, y) )
+				{
+					pTension_Temp->Set_Value(x, y, pResult->asDouble(x, y));
+				}
+				else
+				{
+					nz	= 0;
+					z	= 0.0;
+
+					for(i=0; i<8; i++)
+					{
+						ix	= x + iStep * Get_System()->Get_xTo(i);
+						iy	= y + iStep * Get_System()->Get_yTo(i);
+
+						if( pResult->is_InGrid(ix, iy) )
+						{
+							z	+= pResult->asDouble(ix, iy);
+							nz++;
+						}
+					}
+
+					if( nz > 0.0 )
+					{
+						pTension_Temp->Set_Value(x, y, z / (double)nz);
+					}
+					else
+					{
+						pTension_Temp->Set_Value(x, y, pInput->asDouble(x, y));
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	// 3. ...
+
+	pResult->Assign(pTension_Temp);
+}
+
+//---------------------------------------------------------
+double CGrid_Gaps::Tension_Step(int iStep)
+{
+	int		x, y;
+
+	double	d, dMax;
+
+	dMax	= 0.0;
+
+	for(y=0; y<Get_NY(); y+=iStep)
+	{
+		for(x=0; x<Get_NX(); x+=iStep)
+		{
+			if( pTension_Keep->asByte(x, y) == false )
+			{
+				d	= Tension_Change(x, y, iStep);
+
+				pTension_Temp->Set_Value(x, y, d);
+
+				d	= fabs(d - pResult->asDouble(x, y));
+
+				if( d > dMax )
+				{
+					dMax	= d;
+				}
+			}
+		}
+	}
+
+	for(y=0; y<Get_NY(); y+=iStep)
+	{
+		for(x=0; x<Get_NX(); x+=iStep)
+		{
+			if( pTension_Keep->asByte(x, y) == false )
+			{
+				pResult->Set_Value(x, y, pTension_Temp->asDouble(x, y));
+			}
+		}
+	}
+
+	return( dMax );
+}
+
+
+//---------------------------------------------------------
+double CGrid_Gaps::Tension_Change(int x, int y, int iStep)
+{
+	int		i, ix, iy;
+
+	double	n, d, dz;
+
+	for(i=0, d=0.0, n=0.0; i<8; i++)
+	{
+		ix	= x + iStep * Get_System()->Get_xTo(i);
+		iy	= y + iStep * Get_System()->Get_yTo(i);
+
+		if( pResult->is_InGrid(ix, iy) )
+		{
+			dz	= 1.0 / Get_System()->Get_UnitLength(i);
+			d	+= dz * pResult->asDouble(ix, iy);
+			n	+= dz;
+		}
+	}
+
+	if( n > 0.0 )
+	{
+		d	/= n;
+
+		return( d );
+	}
+
+	return( pResult->asDouble(x, y) );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Grid_Gaps.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Gaps_H
+#define HEADER_INCLUDED__Grid_Gaps_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class grid_tools_EXPORT CGrid_Gaps : public CSG_Module_Grid
+{
+public:
+	CGrid_Gaps(void);
+	virtual ~CGrid_Gaps(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid				*pInput, *pMask, *pResult, *pTension_Keep, *pTension_Temp;
+
+
+	void					Tension_Main	(void);
+	double					Tension_Step	(int iStep);
+	double					Tension_Change	(int x, int y, int iStep);
+	void					Tension_Init	(int iStep);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Gaps_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,154 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Gaps_OneCell.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Gaps_OneCell.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Gaps_OneCell::CGrid_Gaps_OneCell(void)
+{
+	Set_Name(_TL("Close One Cell Gaps"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Closes one cell gaps using the mean value of the surrounding cell values. "
+		"If the target is not set, the changes will be stored to the original grid. ")
+	);
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"	, _TL("Changed Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Gaps_OneCell::~CGrid_Gaps_OneCell(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Gaps_OneCell::On_Execute(void)
+{
+	bool	bCloseGap;
+	int		x, y, i, ix, iy;
+	double	Sum;
+	CSG_Grid	*pInput, *pResult;
+
+	pInput	= Parameters("INPUT")->asGrid();
+	pResult	= Parameters("RESULT")->asGrid();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pInput->is_NoData(x, y) )
+			{
+				for(i=0, bCloseGap=true, Sum=0.0; i<8 && bCloseGap; i++)
+				{
+					Get_System()->Get_Neighbor_Pos(i, x, y, ix, iy);
+
+					if( !pInput->is_InGrid(ix, iy) )
+					{
+						bCloseGap	= false;
+					}
+					else
+					{
+						Sum			+= pInput->asDouble(ix, iy);
+					}
+				}
+
+				if( bCloseGap )
+				{
+					pResult->Set_Value(x, y, Sum / 8.0);
+				}
+				else
+				{
+					pResult->Set_NoData(x, y);
+				}
+			}
+			else
+			{
+				pResult->Set_Value(x, y, pInput->asDouble(x, y));
+			}
+		}
+	}
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Gaps_OneCell.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,86 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Gaps_OneCell.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Gaps_OneCell_H
+#define HEADER_INCLUDED__Grid_Gaps_OneCell_H
+
+//---------------------------------------------------------
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Gaps_OneCell : public CSG_Module_Grid  
+{
+public:
+	CGrid_Gaps_OneCell(void);
+	virtual ~CGrid_Gaps_OneCell(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Gaps_OneCell_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,403 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Tutorial                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Merge.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Merge.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Merge::CGrid_Merge(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Merging"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Merge Grids."
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Standard in- and output...
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids to Merge"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID_TARGET"	, _TL("Target Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "MERGED"		, _TL("Merged Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TYPE"		, _TL("Preferred data storage type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("1 bit"),
+			_TL("1 byte unsigned integer"),
+			_TL("1 byte signed integer"),
+			_TL("2 byte unsigned integer"),
+			_TL("2 byte signed integer"),
+			_TL("4 byte unsigned integer"),
+			_TL("4 byte signed integer"),
+			_TL("4 byte floating point"),
+			_TL("8 byte floating point")
+		), 7
+	);
+
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters;
+
+	pParameters	= Add_Parameters(
+		"MERGE_INFO"	, _TL("Cell Size Specification"),
+		_TW(	"Your grid selection contains grids with different cell sizes. "
+				"Please specify the cell size that you desire for the merged "
+				"grid. All grids with other cell sizes will then be resampled "
+				"according to your specification.")
+	);
+
+	pParameters->Add_Value(
+		NULL	, "MESH_SIZE"	, _TL("Cell Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "INTERPOL"	, _TL("Interpolation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "OVERLAP"		, _TL("Overlapping Cells"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("mean value"),
+			_TL("first value in order of grid list")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Merge::~CGrid_Merge(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Merge::On_Execute(void)
+{
+	bool					bMean;
+	int						x, y, i, ix, iy, ax, ay, Interpolation;
+	double					z, Cellsize;
+	TSG_Point				p;
+    CSG_Rect		        Extent;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_Grid				*pMerged, *pGrid;
+    CSG_Grid                *pCount = NULL;
+
+	//-----------------------------------------------------
+	pGrids			= Parameters("GRIDS")		->asGridList();
+	pMerged			= Parameters("GRID_TARGET")	->asGrid();
+	Interpolation	= Parameters("INTERPOL")	->asInt();
+	bMean			= Parameters("OVERLAP")		->asInt() == 0;
+
+	//-----------------------------------------------------
+	if( pGrids->Get_Count() < 2 )
+	{
+		Message_Dlg(_TL("There is nothing to merge, because less than 2 grids have been selected."), Get_Name());
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		if( pMerged == NULL )
+		{
+			bool			bResampling;
+			TSG_Data_Type	Type;
+
+			//---------------------------------------------
+			// Type...
+
+			switch( Parameters("TYPE")->asInt() )
+			{
+			case 0:				Type	= SG_DATATYPE_Bit;		break;
+			case 1:				Type	= SG_DATATYPE_Byte;		break;
+			case 2:				Type	= SG_DATATYPE_Char;		break;
+			case 3:				Type	= SG_DATATYPE_Word;		break;
+			case 4:				Type	= SG_DATATYPE_Short;	break;
+			case 5:				Type	= SG_DATATYPE_DWord;	break;
+			case 6:				Type	= SG_DATATYPE_Int;		break;
+			case 7: default:	Type	= SG_DATATYPE_Float;	break;
+			case 8:				Type	= SG_DATATYPE_Double;	break;
+			}
+
+			//---------------------------------------------
+			// Cell Size...
+
+			for(i=1, Cellsize=pGrids->asGrid(0)->Get_Cellsize(), bResampling=false; i<pGrids->Get_Count(); i++)
+			{
+				if( Cellsize != pGrids->asGrid(i)->Get_Cellsize() )
+				{
+					bResampling	= true;
+
+					if( Cellsize > pGrids->asGrid(i)->Get_Cellsize() )
+					{
+						Cellsize	= pGrids->asGrid(i)->Get_Cellsize();
+					}
+				}
+			}
+
+			if( bResampling )
+			{
+				Get_Parameters("MERGE_INFO")->Get_Parameter("MESH_SIZE")->Set_Value(Cellsize);
+
+				if( !Dlg_Parameters("MERGE_INFO") )
+				{
+					return( false );
+				}
+
+				Cellsize	= Get_Parameters("MERGE_INFO")->Get_Parameter("MESH_SIZE")->asDouble();
+			}
+
+			//---------------------------------------------
+			// Extent...
+
+			Extent.Assign(pGrids->asGrid(0)->Get_Extent());
+
+			for(i=1; i<pGrids->Get_Count(); i++)
+			{
+				Extent.Union(pGrids->asGrid(i)->Get_Extent());
+			}
+
+			//---------------------------------------------
+			// Create Grid...
+
+			Parameters("MERGED")->Set_Value(pMerged	= SG_Create_Grid(
+				Type,
+				1 + (int)(0.5 + Extent.Get_XRange() / Cellsize),
+				1 + (int)(0.5 + Extent.Get_YRange() / Cellsize),
+				Cellsize,
+				Extent.Get_XMin(),
+				Extent.Get_YMin()
+			));
+		}
+
+
+		//-------------------------------------------------
+		// Merge grids...
+
+		pMerged->Set_Name(_TL("Merged Grid"));
+
+		pMerged->Assign_NoData();
+
+		//-------------------------------------------------
+		for(i=0; i<pGrids->Get_Count(); i++)
+		{
+			Process_Set_Text(CSG_String::Format(SG_T("%s: %d (%d)"), _TL("merging grid"), i + 1, pGrids->Get_Count()));
+
+			pGrid	= pGrids->asGrid(i);
+
+			ax		= (int)((pGrid->Get_XMin() - pMerged->Get_XMin()) / pMerged->Get_Cellsize());
+			ay		= (int)((pGrid->Get_YMin() - pMerged->Get_YMin()) / pMerged->Get_Cellsize());
+
+			//---------------------------------------------
+			if(	pGrid->Get_Cellsize() == pMerged->Get_Cellsize()
+			&&	fabs(fmod(pGrid->Get_XMin() - pMerged->Get_XMin(), pMerged->Get_Cellsize())) <= 0.001 * pMerged->Get_Cellsize()
+			&&	fabs(fmod(pGrid->Get_YMin() - pMerged->Get_YMin(), pMerged->Get_Cellsize())) <= 0.001 * pMerged->Get_Cellsize() )
+			{
+				for(y=ay, iy=0; iy<pGrid->Get_NY() && Set_Progress(iy, pGrid->Get_NY()); y++, iy++)
+				{
+					if( y >= 0 && y < pMerged->Get_NY() )
+					{
+						for(x=ax, ix=0; ix<pGrid->Get_NX(); x++, ix++)
+						{
+							if( x >= 0 && x < pMerged->Get_NX() && !pGrid->is_NoData(ix, iy) )
+							{
+								if( pMerged->is_NoData(x, y) )
+								{
+									pMerged->Set_Value(x, y, pGrid->asDouble(ix, iy));
+								}
+								else if( bMean )
+								{
+                                    if (pCount == NULL)
+                                    {
+                                        pCount	= SG_Create_Grid(
+				                            SG_DATATYPE_Int,
+				                            1 + (int)(0.5 + Extent.Get_XRange() / Cellsize),
+				                            1 + (int)(0.5 + Extent.Get_YRange() / Cellsize),
+				                            Cellsize,
+				                            Extent.Get_XMin(),
+				                            Extent.Get_YMin()
+			                            );
+                                        pCount->Assign(1.0);
+                                    }
+                                    pMerged->Set_Value(x, y, pMerged->asDouble(x, y) + pGrid->asDouble(ix, iy));
+                                    pCount->Set_Value(x, y, pCount->asInt(x, y) + 1);
+								}
+							}
+						}
+					}
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				Message_Add(_TL("interpolating grid: "));	Message_Add(pGrid->Get_Name(), false);
+
+				p.y	= pMerged->Get_YMin() + ay * pMerged->Get_Cellsize();
+
+				for(y=ay; p.y<=pGrid->Get_YMax() && Set_Progress(p.y-pGrid->Get_YMin(), pGrid->Get_System().Get_YRange()); y++, p.y+=pMerged->Get_Cellsize())
+				{
+					if( y >= 0 && y < pMerged->Get_NY() )
+					{
+						p.x	= pMerged->Get_XMin() + ax * pMerged->Get_Cellsize();
+
+						for(x=ax; p.x<pGrid->Get_XMax(); x++, p.x+=pMerged->Get_Cellsize())
+						{
+							if( x >= 0 && x < pMerged->Get_NX() && pGrid->Get_Value(p, z, Interpolation) )
+							{
+								if( pMerged->is_NoData(x, y) )
+								{
+									pMerged->Set_Value(x, y, z);
+								}
+								else if( bMean )
+								{
+                                    if (pCount == NULL)
+                                    {
+                                        pCount	= SG_Create_Grid(
+				                            SG_DATATYPE_Int,
+				                            1 + (int)(0.5 + Extent.Get_XRange() / Cellsize),
+				                            1 + (int)(0.5 + Extent.Get_YRange() / Cellsize),
+				                            Cellsize,
+				                            Extent.Get_XMin(),
+				                            Extent.Get_YMin()
+			                            );
+                                        pCount->Assign(1.0);
+                                    }
+                                    pMerged->Set_Value(x, y, pMerged->asDouble(x, y) + z);
+                                    pCount->Set_Value(x, y, pCount->asInt(x, y) + 1);
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+
+
+		//-------------------------------------------------
+		DataObject_Update(pMerged);
+
+        if (bMean && pCount != NULL)
+        {
+            for (y=0; y<pMerged->Get_NY() && Set_Progress(y, pMerged->Get_NY()); y++)
+            {
+                for (x=0; x<pMerged->Get_NX(); x++)
+                {
+                    if (!pMerged->is_NoData(x, y))
+                        pMerged->Set_Value(x, y, pMerged->asDouble(x, y) / pCount->asInt(x, y));
+                }
+            }
+        }
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Merge.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Tutorial                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Merge.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Merge_H
+#define HEADER_INCLUDED__Grid_Merge_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Merge : public CSG_Module
+{
+public:
+	CGrid_Merge(void);
+	virtual ~CGrid_Merge(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Merge_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,161 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Orientation.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Orientation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Orientation::CGrid_Orientation(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Grid Orientation"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Copy, mirror (horizontally or vertically) and invert grid values. "
+		"If the target is not set, the changes will be stored to the original grid. ")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"	, _TL("Changed Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"	, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Copy"),
+			_TL("Flip"),
+			_TL("Mirror"),
+			_TL("Invert")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Orientation::~CGrid_Orientation(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Orientation::On_Execute(void)
+{
+	CSG_Grid		*pInput, *pResult;
+
+	pInput		= Parameters("INPUT")->asGrid();
+	pResult		= Parameters("RESULT")->asGrid();
+
+	if( !pResult )
+	{
+		pResult		= pInput;
+		Parameters("RESULT")->Set_Value(pInput);
+	}
+	else if( pResult != pInput )
+	{
+		pResult->Assign(pInput);
+	}
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:	default:	// Copy...
+		break;
+
+	case 1:				// Flip...
+		pResult->Flip();
+		break;
+
+	case 2:				// Mirror...
+		pResult->Mirror();
+		break;
+
+	case 3:				// Invert...
+		pResult->Invert();
+		break;
+	}
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Orientation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,87 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Orientation.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Orientation_H
+#define HEADER_INCLUDED__Grid_Orientation_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Orientation : public CSG_Module_Grid  
+{
+public:
+	CGrid_Orientation(void);
+	virtual ~CGrid_Orientation(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+
+};
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Orientation_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,373 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Resample.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "Grid_Resample.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Resample::CGrid_Resample(void)
+{
+	CSG_Parameter	*pNode;
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Resampling"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Resampling of grids.")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Resampled Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Target Grid"),
+		_TL(""),
+
+		_TL("Specify dimensions|Create new grid in existing project|Overwrite existing grid|")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "KEEP_TYPE"	, _TL("Preserve Data Type"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("DIMENSIONS"	, _TL("Target Grid Dimensions")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL	, "CELLSIZE"	, _TL("Cell Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0, 0.0, true
+	);
+
+	pParameters->Add_Value(
+		NULL	, "CELLS_NX"	, _TL("Cell Count: Columns"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 2, 2, true
+	);
+
+	pParameters->Add_Value(
+		NULL	, "CELLS_NY"	, _TL("Cell Count: Rows"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 2, 2, true
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("SYSTEM"	, _TL("Choose Grid System")	, _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GRID"		, _TL("Target Grid")				, _TL(""));
+
+	pNode	= pParameters->Add_Grid(
+		NULL	, "GRID"		, _TL("Target Grid"),
+		_TL(""),
+		PARAMETER_INPUT			, false
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("SCALE_UP"	, _TL("Up-Scaling")				, _TL(""));
+
+	pNode	= pParameters->Add_Choice(
+		NULL	, "METHOD"		, _TL("Interpolation Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation"),
+			_TL("Mean Value"),
+			_TL("Mean Value (cell area weighted)"),
+			_TL("Minimum Value"),
+			_TL("Maximum Value")
+		), 6
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("SCALE_DOWN"	, _TL("Down-Scaling")			, _TL(""));
+
+	pNode	= pParameters->Add_Choice(
+		NULL	, "METHOD"		, _TL("Interpolation Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Resample::~CGrid_Resample(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CGrid_Resample::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	int		nx, ny;
+	double	cellsize;
+	CSG_Grid	*pGrid;
+
+	if( !SG_STR_CMP(pParameters->Get_Identifier(), SG_T("DIMENSIONS")) )
+	{
+		pGrid		=  Parameters               ("INPUT")   ->asGrid();
+		cellsize	= pParameters->Get_Parameter("CELLSIZE")->asDouble();
+		nx			= pParameters->Get_Parameter("CELLS_NX")->asInt();
+		ny			= pParameters->Get_Parameter("CELLS_NY")->asInt();
+
+		if( pGrid && cellsize > 0.0 )
+		{
+			if(      !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("CELLSIZE")) )
+			{
+				nx			= 1 + (int)(pGrid->Get_XRange() / cellsize);
+				ny			= 1 + (int)(pGrid->Get_YRange() / cellsize);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("CELLS_NX")) )
+			{
+				cellsize	= pGrid->Get_XRange() / (nx - 1);
+				ny			= 1 + (int)(pGrid->Get_YRange() / cellsize);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("CELLS_NY")) )
+			{
+				cellsize	= pGrid->Get_YRange() / (ny - 1);
+				nx			= 1 + (int)(pGrid->Get_XRange() / cellsize);
+			}
+
+			pParameters->Get_Parameter("CELLSIZE")->Set_Value(cellsize);
+			pParameters->Get_Parameter("CELLS_NX")->Set_Value(nx);
+			pParameters->Get_Parameter("CELLS_NY")->Set_Value(ny);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Resample::On_Execute(void)
+{
+	bool					bResult;
+	double					Cellsize;
+	TSG_Grid_Interpolation	Interpolation;
+	CSG_Grid				*pInput, *pOutput;
+	CSG_Grid_System			System;
+	CSG_Parameters			*pParameters;
+
+	//-----------------------------------------------------
+	bResult	= false;
+
+	pInput	= Parameters("INPUT")->asGrid();
+	pOutput	= NULL;
+
+	//-----------------------------------------------------
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:	// Target Dimensions...
+		Get_Parameters("DIMENSIONS")->Get_Parameter("CELLSIZE")->Set_Value(pInput->Get_Cellsize());
+		Get_Parameters("DIMENSIONS")->Get_Parameter("CELLS_NX")->Set_Value(pInput->Get_NX());
+		Get_Parameters("DIMENSIONS")->Get_Parameter("CELLS_NY")->Set_Value(pInput->Get_NY());
+
+		if(	Dlg_Parameters("DIMENSIONS") && (Cellsize = Get_Parameters("DIMENSIONS")->Get_Parameter("CELLSIZE")->asDouble()) > 0.0 )
+		{
+			System.Assign(Cellsize, pInput->Get_XMin(), pInput->Get_YMin(),
+				1 + (int)(pInput->Get_XRange() / Cellsize),
+				1 + (int)(pInput->Get_YRange() / Cellsize)
+			);
+		}
+		break;
+
+	case 1:	// Target Project...
+		if( Dlg_Parameters("SYSTEM") )
+		{
+			System.Assign(*Get_Parameters("SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System());
+		}
+		break;
+
+	case 2:	// Target Grid...
+		if( Dlg_Parameters("GRID") )
+		{
+			System.Assign(Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid()->Get_System());
+
+			pOutput	= Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid();
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( System.is_Valid() && pInput->is_Intersecting(System.Get_Extent()) )
+	{
+		pParameters	= NULL;
+
+		//-------------------------------------------------
+		// Up-Scaling...
+
+		if( pInput->Get_Cellsize() < System.Get_Cellsize() )
+		{
+			if( Dlg_Parameters("SCALE_UP") )
+			{
+				switch( Get_Parameters("SCALE_UP")->Get_Parameter("METHOD")->asInt() )
+				{
+				case 0:	Interpolation	= GRID_INTERPOLATION_NearestNeighbour;	break;
+				case 1:	Interpolation	= GRID_INTERPOLATION_Bilinear;			break;
+				case 2:	Interpolation	= GRID_INTERPOLATION_InverseDistance;	break;
+				case 3:	Interpolation	= GRID_INTERPOLATION_BicubicSpline;		break;
+				case 4:	Interpolation	= GRID_INTERPOLATION_BSpline;			break;
+				case 5:	Interpolation	= GRID_INTERPOLATION_Mean_Nodes;		break;
+				case 6:	Interpolation	= GRID_INTERPOLATION_Mean_Cells;		break;
+				case 7:	Interpolation	= GRID_INTERPOLATION_Minimum;			break;
+				case 8:	Interpolation	= GRID_INTERPOLATION_Maximum;			break;
+				}
+
+				pParameters	= Get_Parameters("SCALE_UP");
+			}
+		}
+
+		//-------------------------------------------------
+		// Down-Scaling...
+
+		else
+		{
+			if( Dlg_Parameters("SCALE_DOWN") )
+			{
+				switch( Get_Parameters("SCALE_DOWN")->Get_Parameter("METHOD")->asInt() )
+				{
+				case 0:	Interpolation	= GRID_INTERPOLATION_NearestNeighbour;	break;
+				case 1:	Interpolation	= GRID_INTERPOLATION_Bilinear;			break;
+				case 2:	Interpolation	= GRID_INTERPOLATION_InverseDistance;	break;
+				case 3:	Interpolation	= GRID_INTERPOLATION_BicubicSpline;		break;
+				case 4:	Interpolation	= GRID_INTERPOLATION_BSpline;			break;
+				}
+
+				pParameters	= Get_Parameters("SCALE_DOWN");
+			}
+		}
+
+		//-------------------------------------------------
+		if( pParameters )
+		{
+			if( !pOutput )
+			{
+				pOutput	= SG_Create_Grid(System, Parameters("KEEP_TYPE")->asBool() || (Interpolation == GRID_INTERPOLATION_NearestNeighbour) ? pInput->Get_Type() : SG_DATATYPE_Undefined);
+			}
+
+			pOutput->Set_Name(pInput->Get_Name());
+
+			pOutput->Assign(pInput, Interpolation);
+
+			Parameters("GRID")->Set_Value(pOutput);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Resample.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,89 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Resample.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Resample_H
+#define HEADER_INCLUDED__Grid_Resample_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Resample : public CSG_Module_Grid  
+{
+public:
+	CGrid_Resample(void);
+	virtual ~CGrid_Resample(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("A:Grid|Construction") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+	virtual int				On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Resample_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,601 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Value_Reclassify.cpp               //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de                         //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Value_Reclassify.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Value_Reclassify::CGrid_Value_Reclassify(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Reclassify Grid Values"));
+
+	Set_Author(_TL("Copyrights (c) 2005 by Volker Wichmann"));
+
+	Set_Description	(_TW(
+		"The module can be used to reclassify the values of a grid. It provides three different options: (a) "
+		"reclassification of single values, (b) reclassification of a range of values and (c) reclassification "
+		"of value ranges specified in a lookup table. In addition to theses methods, two special cases "
+		"(No-Data values and values not included in the reclassification setup) are supported. In mode (a) "
+		"and (b) the 'No-Data option' is evaluated before the method settings, in mode (c) the option is "
+		"evaluated only if the No-Data value ins't included in the lookup table. The 'other values' option "
+		"is always evaluated after checking the method settings. ")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		,_TL("Grid"),
+		_TL("Grid to reclassify"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Reclassified Grid"),
+		_TL("Reclassifed grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL("Select the desired method: 1. a single value or a range defined by a single value is reclassified, 2. a range of values is reclassified, 3. the lookup table is used to reclassify the grid."),
+		_TL("single|range|simple table|user supplied table|"), 0
+	);
+
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "SINGLE", _TL("Method single"),
+		_TL("Parameter settings for method single.")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "OLD"			, _TL("old value"),
+		_TL("Value to reclassify."),
+		PARAMETER_TYPE_Double, 0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NEW"			, _TL("new value"),
+		_TL("New value."),
+		PARAMETER_TYPE_Double, 1
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "SOPERATOR"	, _TL("operator"),
+		_TL("Select the desired operator (<;.;=; >;.); it is possible to define a range above or below the old value."),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("="),
+			_TL("<"),
+			_TL("<="),
+			_TL(">="),
+			_TL(">")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "RANGE"		, _TL("Method range"),
+		_TL("Parameter settings for method range.")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "MIN"			, _TL("minimum value"),
+		_TL("Minimum value of the range to be reclassified."),
+		PARAMETER_TYPE_Double, 0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "MAX"			, _TL("maximum value"),
+		_TL("Maximum value of the range to be reclassified."),
+		PARAMETER_TYPE_Double, 10
+	);
+
+	Parameters.Add_Value(
+		pNode	, "RNEW"		, _TL("new value"),
+		_TL("new value"),
+		PARAMETER_TYPE_Double, 5
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "ROPERATOR"	, _TL("operator"),
+		_TL("Select operator: eg. min < value < max."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("<="),
+			_TL("<")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "TABLE"		, _TL("Method simple table"),
+		_TL("Parameter settings for method simple table.")
+	);
+
+	Parameters.Add_FixedTable(
+		pNode	, "RETAB"		, _TL("Lookup Table"),
+		_TL("Lookup table used in method \"table\"")
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "TOPERATOR"	, _TL("operator"),
+		_TL("Select the desired operator (min < value < max; min . value < max; min .value . max; min < value . max)."),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("min <= value < max"),
+			_TL("min <= value <= max"),
+			_TL("min < value <= max"),
+			_TL("min < value < max")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "TABLE_2"		, _TL("Method user supplied table"),
+		_TL("Parameter settings for method user supplied table.")
+	);
+
+	pNode	= Parameters.Add_Table(
+		pNode	, "RETAB_2"		, _TL("Lookup Table"),
+		_TL("Lookup table used in method \"user supplied table\""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "F_MIN"		, _TL("minimum value"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "F_MAX"		, _TL("maximum value"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "F_CODE"		, _TL("new value"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL, "OPTIONS"			, _TL("Special cases"),
+		_TL("Parameter settings for No-Data and all other values.")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NODATAOPT"	, _TL("no data values"),
+		_TL("Use this option to reclassify No-Data values independently of the method settings."),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NODATA"		, _TL("no data values >> value"),
+		_TL("new value"),
+		PARAMETER_TYPE_Double, 0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "OTHEROPT"	, _TL("other values"),
+		_TL("Use this option to reclassify all other values that are not specified in the options above."),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Value(
+		pNode	, "OTHERS"		, _TL("other values >> value"),
+		_TL("new value"),
+		PARAMETER_TYPE_Double, 0
+	);
+
+	//-----------------------------------------------------
+	CSG_Table			*pLookup;
+	CSG_Table_Record	*pRecord;
+
+	pLookup	= Parameters("RETAB")->asTable();
+
+	pLookup->Add_Field(_TL("minimum")	, SG_DATATYPE_Double);
+	pLookup->Add_Field(_TL("maximum")	, SG_DATATYPE_Double);
+	pLookup->Add_Field(_TL("new")		, SG_DATATYPE_Double);
+
+	pRecord	= pLookup->Add_Record();	pRecord->Set_Value(0,  0.0);	pRecord->Set_Value(1, 10.0);	pRecord->Set_Value(2, 1.0);
+	pRecord	= pLookup->Add_Record();	pRecord->Set_Value(0, 10.0);	pRecord->Set_Value(1, 20.0);	pRecord->Set_Value(2, 2.0);
+}
+
+//---------------------------------------------------------
+CGrid_Value_Reclassify::~CGrid_Value_Reclassify(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Value_Reclassify::On_Execute(void)
+{
+	int		method;
+
+	pInput		= Parameters("INPUT")->asGrid();
+	pResult		= Parameters("RESULT")->asGrid();
+	method		= Parameters("METHOD")->asInt();
+
+	//-----------------------------------------------------
+	switch( method )
+	{
+	case 0:	return( ReclassSingle() );
+	case 1:	return( ReclassRange() );
+	case 2:	return( ReclassTable(false) );
+	case 3:	return( ReclassTable(true) );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Value_Reclassify::ReclassRange(void)
+{
+	bool	otherOpt, noDataOpt, floating;
+	int		x, y, opera;
+	double	minValue, maxValue, value, others, noData, noDataValue, newValue;
+
+
+	minValue	= Parameters("MIN")->asDouble();
+	maxValue	= Parameters("MAX")->asDouble();
+	newValue	= Parameters("RNEW")->asDouble();
+	others		= Parameters("OTHERS")->asDouble();
+	noData		= Parameters("NODATA")->asDouble();
+	otherOpt	= Parameters("OTHEROPT")->asBool();
+	noDataOpt	= Parameters("NODATAOPT")->asBool();
+	opera		= Parameters("ROPERATOR")->asInt();
+
+	noDataValue = pInput->Get_NoData_Value();
+
+	if( (pInput->Get_Type() == SG_DATATYPE_Double) || (pInput->Get_Type() == SG_DATATYPE_Float) )
+		floating = true;
+	else
+		floating = false;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( floating == true )
+				value = pInput->asDouble(x, y);
+			else
+				value = pInput->asInt(x, y);
+
+			if( opera == 0 )												// operator <=
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+					pResult->Set_Value(x, y, noData);
+				else if( minValue <= value && value <= maxValue )			// reclass old range
+					pResult->Set_Value(x, y, newValue);						
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+
+			if( opera == 1 )												// operator <
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+					pResult->Set_Value(x, y, noData);
+				else if( minValue < value && value < maxValue )				// reclass old range
+					pResult->Set_Value(x, y, newValue);					
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGrid_Value_Reclassify::ReclassSingle(void)
+{
+	bool	otherOpt, noDataOpt, floating;
+	int		x, y, opera;
+	double	oldValue, newValue, value, others, noData, noDataValue;
+
+
+	oldValue	= Parameters("OLD")->asDouble();
+	newValue	= Parameters("NEW")->asDouble();
+	others		= Parameters("OTHERS")->asDouble();
+	noData		= Parameters("NODATA")->asDouble();
+	otherOpt	= Parameters("OTHEROPT")->asBool();
+	noDataOpt	= Parameters("NODATAOPT")->asBool();
+	opera		= Parameters("SOPERATOR")->asInt();
+
+	noDataValue = pInput->Get_NoData_Value();
+
+	if( (pInput->Get_Type() == SG_DATATYPE_Double) || (pInput->Get_Type() == SG_DATATYPE_Float) )
+		floating = true;
+	else
+		floating = false;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( floating == true )
+				value = pInput->asDouble(x, y);
+			else
+				value = pInput->asInt(x, y);
+
+			if( opera == 0 )												// operator =
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+					pResult->Set_Value(x, y, noData);
+				else if( value == oldValue )								// reclass old value
+					pResult->Set_Value(x, y, newValue);					
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+
+			if( opera == 1 )												// operator <
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+					pResult->Set_Value(x, y, noData);
+				else if( value < oldValue )									// reclass old value
+					pResult->Set_Value(x, y, newValue);						
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+
+			if( opera == 2 )												// operator <=
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+						pResult->Set_Value(x, y, noData);
+				else if( value <= oldValue )								// reclass old value
+					pResult->Set_Value(x, y, newValue);						
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+
+			if( opera == 3 )												// operator >=
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+						pResult->Set_Value(x, y, noData);
+				else if( value >= oldValue )								// reclass old value
+					pResult->Set_Value(x, y, newValue);		
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+
+			if( opera == 4 )												// operator >
+			{
+				if( noDataOpt == true && value == noDataValue )				// noData option
+						pResult->Set_Value(x, y, noData);
+				else if( value > oldValue )									// reclass old value
+					pResult->Set_Value(x, y, newValue);		
+				else if( otherOpt == true && value != noDataValue )			// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);						// or original value
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+#define MAX_CAT	128
+
+//---------------------------------------------------------
+bool CGrid_Value_Reclassify::ReclassTable(bool bUser)
+{
+	bool			set, otherOpt, noDataOpt;
+	int				n, x, y, opera, recCount, count[MAX_CAT], field_Min, field_Max, field_Code;
+	double			min[MAX_CAT], max[MAX_CAT], code[MAX_CAT], value, others, noData, noDataValue;
+
+	CSG_Table			*pReTab;
+	CSG_Table_Record	*pRecord = NULL;
+
+	if( bUser )
+	{
+		pReTab		= Parameters("RETAB_2")	->asTable();
+		field_Min	= Parameters("F_MIN")	->asInt();
+		field_Max	= Parameters("F_MAX")	->asInt();
+		field_Code	= Parameters("F_CODE")	->asInt();
+	}
+	else
+	{
+		pReTab		= Parameters("RETAB")	->asTable();
+		field_Min	= 0;
+		field_Max	= 1;
+		field_Code	= 2;
+	}
+
+	others		= Parameters("OTHERS")->asDouble();
+	noData		= Parameters("NODATA")->asDouble();
+	otherOpt	= Parameters("OTHEROPT")->asBool();
+	noDataOpt	= Parameters("NODATAOPT")->asBool();
+	opera		= Parameters("TOPERATOR")->asInt();
+
+	noDataValue = pInput->Get_NoData_Value();
+
+
+	if( pReTab == NULL )
+	{
+		Error_Set(_TL("You must specify a reclass table with a minimium (field 1), a maximum (field 2) and a code value (field 3)!\n"));
+		return( false );
+	}
+
+	recCount = pReTab->Get_Record_Count();
+	if( recCount > MAX_CAT )
+	{
+		Error_Set(_TL("At the moment the reclass table is limited to 128 categories!\n"));
+		return( false );
+	}
+
+	if( recCount == 0 )
+	{
+		Error_Set(_TL("You must specify a reclass table with a minimium of one record!\n"));
+		return( false );
+	}
+
+	for(n=0; n<recCount ; n++)								// initialize reclass arrays
+	{
+		pRecord		= pReTab->Get_Record(n);
+		min[n]		= pRecord->asDouble(field_Min);
+		max[n]		= pRecord->asDouble(field_Max);
+		code[n]		= pRecord->asDouble(field_Code);
+		count[n]	= 0;
+	}
+
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			value	= pInput->asDouble(x, y);
+			set		= false;
+
+			for(n=0; n< recCount; n++)									// reclass
+			{
+				if( opera == 0 )										// min <= value < max
+				{
+					if( value >= min[n] && value < max[n] )
+					{
+						pResult->Set_Value(x, y, code[n]);
+						set = true;
+						count[n] += 1;
+						break;
+					}
+				}
+				else if( opera == 1 )									// min <= value <= max
+				{
+					if( value >= min[n] && value <= max[n] )
+					{
+						pResult->Set_Value(x, y, code[n]);
+						set = true;
+						count[n] += 1;
+						break;
+					}
+				}
+				else if( opera == 2 )									// min < value <= max
+				{
+					if( value > min[n] && value <= max[n] )
+					{
+						pResult->Set_Value(x, y, code[n]);
+						set = true;
+						count[n] += 1;
+						break;
+					}
+				}
+				else if( opera == 3 )									// min < value < max
+				{
+					if( value > min[n] && value < max[n] )
+					{
+						pResult->Set_Value(x, y, code[n]);
+						set = true;
+						count[n] += 1;
+						break;
+					}
+				}
+			}
+
+			if( set == false )
+			{
+				if( noDataOpt == true && value == noDataValue )			// noData option
+					pResult->Set_Value(x, y, noData);
+				else if( otherOpt == true && value != noDataValue)		// other values option
+					pResult->Set_Value(x, y, others);
+				else
+					pResult->Set_Value(x, y, value);					// or original value
+			}
+		}
+	}
+
+	return (true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Reclassify.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Value_Reclassify.h                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volker.wichmann at ku-eichstaett.de       //
+//                                                       //
+//    contact:    Volker Wichmann                        //
+//                Research Associate                     //
+//                Chair of Physical Geography		     //
+//				  KU Eichstaett-Ingolstadt				 //
+//                Ostenstr. 18                           //
+//                85072 Eichstaett                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Value_Reclassify_H
+#define HEADER_INCLUDED__Grid_Value_Reclassify_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Value_Reclassify : public CSG_Module_Grid
+{
+public:
+	CGrid_Value_Reclassify(void);
+	virtual ~CGrid_Value_Reclassify(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Values") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						single;
+
+	CSG_Grid				*pInput, *pResult;
+
+
+	bool					ReclassSingle	(void);
+	bool					ReclassRange	(void);
+	bool					ReclassTable	(bool bUser);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Value_Reclassify_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,208 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Value_Replace.cpp                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Value_Replace.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Value_Replace::CGrid_Value_Replace(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Change Grid Values"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Changes values of a grid according to the rules of a user defined lookup table. "
+		"Values or value ranges that are not listed in the lookup table remain unchanged. "
+		"If the target is not set, the changes will be stored to the original grid. ")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL	, "GRID_IN"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID_OUT"	, _TL("Changed Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Replace Condition"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Grid value equals low value"),
+			_TL("Low value < grid value < high value"),
+			_TL("Low value <= grid value < high value")
+		)
+	);
+
+	//-----------------------------------------------------
+	CSG_Table			*pLookup;
+	CSG_Table_Record	*pRecord;
+
+	pLookup	= Parameters.Add_FixedTable(
+		NULL	, "LOOKUP"		, _TL("Lookup Table"),
+		_TL("")
+	)->asTable();
+
+	pLookup->Add_Field(_TL("Low Value")		, SG_DATATYPE_Double);
+	pLookup->Add_Field(_TL("High Value")		, SG_DATATYPE_Double);
+	pLookup->Add_Field(_TL("Replace with")	, SG_DATATYPE_Double);
+
+	pRecord	= pLookup->Add_Record();	pRecord->Set_Value(0, 0.0);	pRecord->Set_Value(1, 0.0);	pRecord->Set_Value(2, 10.0);
+	pRecord	= pLookup->Add_Record();	pRecord->Set_Value(0, 1.0);	pRecord->Set_Value(1, 4.0);	pRecord->Set_Value(2, 11.0);
+}
+
+//---------------------------------------------------------
+CGrid_Value_Replace::~CGrid_Value_Replace(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Value_Replace::On_Execute(void)
+{
+	bool			bReplace;
+	int				x, y, iRecord, Method;
+	double			Value;
+	CSG_Grid			*pGrid;
+	CSG_Table			*pLookup;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	pLookup	= Parameters("LOOKUP")->asTable();
+
+	if( pLookup->Get_Record_Count() > 0 )
+	{
+		if( Parameters("GRID_OUT")->asGrid() == NULL || Parameters("GRID_IN")->asGrid() == Parameters("GRID_OUT")->asGrid() )
+		{
+			pGrid	= Parameters("GRID_IN")	->asGrid();
+		}
+		else
+		{
+			pGrid	= Parameters("GRID_OUT")->asGrid();
+			pGrid->Assign(Parameters("GRID_IN")->asGrid());
+		}
+
+		Method	= Parameters("METHOD")->asInt();
+
+		//-------------------------------------------------
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				Value	= pGrid->asDouble(x, y);
+
+				for(iRecord=0, bReplace=false; iRecord<pLookup->Get_Record_Count() && !bReplace; iRecord++)
+				{
+					pRecord	= pLookup->Get_Record(iRecord);
+
+					switch( Method )
+					{
+					case 0:	// grid value equals low value...
+						bReplace	= Value == pRecord->asDouble(0);
+						break;
+
+					case 1:	// low value < grid value < high value...
+						bReplace	= pRecord->asDouble(0) < Value && Value < pRecord->asDouble(1);
+						break;
+
+					case 2:	// low value <= grid value <= high value...
+						bReplace	= pRecord->asDouble(0) <= Value && Value <= pRecord->asDouble(1);
+						break;
+					}
+
+					if( bReplace )
+					{
+						pGrid->Set_Value(x, y, pRecord->asDouble(2));
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		DataObject_Update(pGrid, pGrid->Get_ZMin(), pGrid->Get_ZMax());
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Replace.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Value_Replace.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Value_Replace_H
+#define HEADER_INCLUDED__Grid_Value_Replace_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Value_Replace : public CSG_Module_Grid  
+{
+public:
+	CGrid_Value_Replace(void);
+	virtual ~CGrid_Value_Replace(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Values") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Value_Replace_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,268 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Tutorial                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Value_Request.cpp                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Value_Request.h"
+
+//---------------------------------------------------------
+#define	FIELD_NAME		0
+#define	FIELD_VALUE		1
+
+#define	FIELD_X			0
+#define	FIELD_Y			1
+#define	FIELD_GRIDS		2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Value_Request::CGrid_Value_Request(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Grid Value Request"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Grid Value Request.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Standard in- and output...
+
+	m_pGrids	= Parameters.Add_Grid_List(
+		NULL	, "GRID_LIST"		, _TL("Grids to request"),
+		_TL(""),
+		PARAMETER_INPUT
+	)->asGridList();
+
+	Parameters.Add_Table(
+		NULL	, "VALUES"			, _TL("Values"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"			, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Single value"),
+			_TL("Collect values")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "INTERPOLATION"	, _TL("Interpolation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 0
+	);
+
+	Set_Drag_Mode(MODULE_INTERACTIVE_DRAG_NONE);
+}
+
+//---------------------------------------------------------
+CGrid_Value_Request::~CGrid_Value_Request(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Value_Request::On_Execute(void)
+{
+	int		iGrid;
+
+	if( m_pGrids->Get_Count() > 0 )
+	{
+		m_Method		= Parameters("METHOD")			->asInt();
+		m_Interpolation	= Parameters("INTERPOLATION")	->asInt();
+
+		m_pTable		= Parameters("VALUES")			->asTable();
+		m_pTable->Destroy();
+		m_pTable->Set_Name(_TL("Grid Values"));
+
+		switch( m_Method )
+		{
+		case 0: default:
+			m_pTable->Add_Field(_TL("NAME")		, SG_DATATYPE_String);
+			m_pTable->Add_Field(_TL("VALUE")	, SG_DATATYPE_Double);
+
+			m_pTable->Add_Record()->Set_Value(FIELD_NAME, _TL("X"));
+			m_pTable->Add_Record()->Set_Value(FIELD_NAME, _TL("Y"));
+
+			for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+			{
+				m_pTable->Add_Record()->Set_Value(FIELD_NAME, m_pGrids->asGrid(iGrid)->Get_Name());
+			}
+			break;
+
+		case 1:
+			m_pTable->Add_Field(_TL("X")		, SG_DATATYPE_Double);
+			m_pTable->Add_Field(_TL("Y")		, SG_DATATYPE_Double);
+
+			for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+			{
+				m_pTable->Add_Field(m_pGrids->asGrid(iGrid)->Get_Name(), SG_DATATYPE_Double);
+			}
+			break;
+		}
+
+		DataObject_Update(m_pTable, true);
+
+		return( true );
+	}
+
+	Message_Dlg(_TL("There is no grid to request."), Get_Name());
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Value_Request::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	int					iGrid;
+	double				Value;
+	CSG_Table_Record	*pRecord;
+
+	if( m_pGrids->Get_Count() > 0 )
+	{
+		switch( m_Method )
+		{
+		//-------------------------------------------------
+		case 0:
+			if( Mode == MODULE_INTERACTIVE_LDOWN || Mode == MODULE_INTERACTIVE_MOVE_LDOWN )
+			{
+				m_pTable->Get_Record(0)->Set_Value(FIELD_VALUE, ptWorld.Get_X());
+				m_pTable->Get_Record(1)->Set_Value(FIELD_VALUE, ptWorld.Get_Y());
+
+				for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+				{
+					if( m_pGrids->asGrid(iGrid)->Get_Value(ptWorld.m_point, Value, m_Interpolation, true) )
+					{
+						m_pTable->Get_Record(iGrid + 2)->Set_Value(FIELD_VALUE, Value);
+					}
+					else
+					{
+						m_pTable->Get_Record(iGrid + 2)->Set_Value(FIELD_VALUE, 0.0);
+					}
+				}
+
+				DataObject_Update(m_pTable);
+
+				return( true );
+			}
+			break;
+
+		//-------------------------------------------------
+		case 1:
+			if( Mode == MODULE_INTERACTIVE_LDOWN )
+			{
+				pRecord	= m_pTable->Add_Record();
+
+				pRecord->Set_Value(FIELD_X, ptWorld.Get_X());
+				pRecord->Set_Value(FIELD_Y, ptWorld.Get_Y());
+
+				for(iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++)
+				{
+					if( m_pGrids->asGrid(iGrid)->Get_Value(ptWorld.m_point, Value, m_Interpolation, true) )
+					{
+						pRecord->Set_Value(FIELD_GRIDS + iGrid, Value);
+					}
+					else
+					{
+						pRecord->Set_Value(FIELD_GRIDS + iGrid, 0.0);
+					}
+				}
+
+				DataObject_Update(m_pTable);
+
+				return( true );
+			}
+			break;
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Request.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Tutorial                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Value_Request.h                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Grid_Value_Request.h					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Value_Request_H
+#define HEADER_INCLUDED__Grid_Value_Request_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Value_Request : public CSG_Module_Interactive
+{
+public:
+	CGrid_Value_Request(void);
+	virtual ~CGrid_Value_Request(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Values") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	int						m_Method, m_Interpolation;
+
+	CSG_Table					*m_pTable;
+
+	CSG_Parameter_Grid_List	*m_pGrids;
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Value_Request_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,191 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Value_Type.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Value_Type.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Value_Type::CGrid_Value_Type(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Convert Data Storage Type"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Changes the storage data type of a grid "
+		"(e.g. from 4 byte floating point to 2 byte signed integer). "
+		"If the target is not set, the original grid's storage type will be changed. ")
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Grid(
+		NULL	, "INPUT"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode	= Parameters.Add_Grid(
+		NULL	, "OUTPUT"	, _TL("Converted Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	pNode	= Parameters.Add_Choice(
+		NULL	, "TYPE"	, _TL("Data storage type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("1 bit"),
+			_TL("1 byte unsigned"),
+			_TL("1 byte signed"),
+			_TL("2 byte unsigned"),
+			_TL("2 byte signed"),
+			_TL("4 byte unsigned"),
+			_TL("4 byte signed"),
+			_TL("4 byte floating point"),
+			_TL("8 byte floating point")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Value_Type::~CGrid_Value_Type(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Value_Type::On_Execute(void)
+{
+	bool			bCopy;
+	TSG_Data_Type	Type;
+	CSG_Grid		*pInput, *pOutput;
+
+	//-----------------------------------------------------
+	pOutput	= Parameters("OUTPUT")->asGrid();
+
+	if( pOutput == NULL || pOutput == Parameters("INPUT")->asGrid() )
+	{
+		bCopy	= true;
+
+		pInput	= new CSG_Grid(Parameters("INPUT")->asGrid());
+		pInput->Assign(Parameters("INPUT")->asGrid());
+
+		if( pOutput == NULL )
+		{
+			pOutput	= Parameters("INPUT")->asGrid();
+		}
+	}
+	else
+	{
+		bCopy	= false;
+
+		pInput	= Parameters("INPUT")->asGrid();
+	}
+
+	//-----------------------------------------------------
+	switch( Parameters("TYPE")->asInt() )
+	{
+	default:
+	case 0:	Type	= SG_DATATYPE_Bit;		break;
+	case 1:	Type	= SG_DATATYPE_Byte;		break;
+	case 2:	Type	= SG_DATATYPE_Char;		break;
+	case 3:	Type	= SG_DATATYPE_Word;		break;
+	case 4:	Type	= SG_DATATYPE_Short;	break;
+	case 5:	Type	= SG_DATATYPE_DWord;	break;
+	case 6:	Type	= SG_DATATYPE_Int;		break;
+	case 7:	Type	= SG_DATATYPE_Float;	break;
+	case 8:	Type	= SG_DATATYPE_Double;	break;
+	}
+
+	//-----------------------------------------------------
+	pOutput->Create(pInput, Type);
+	pOutput->Assign(pInput);
+
+	//-----------------------------------------------------
+	if( bCopy )
+	{
+		delete(pInput);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/Grid_Value_Type.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,88 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Value_Type.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Value_Type_H
+#define HEADER_INCLUDED__Grid_Value_Type_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Value_Type : public CSG_Module_Grid  
+{
+public:
+	CGrid_Value_Type(void);
+	virtual ~CGrid_Value_Type(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Values") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Value_Type_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,174 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Tools") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Victor Olaya, Volker Wichmann (c) 2002-5") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the manipulation of gridded data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Tools") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Grid_Orientation.h"
+
+#include "Grid_Resample.h"
+#include "Grid_Aggregate.h"
+#include "Grid_Cut.h"
+#include "Grid_Merge.h"
+#include "Grid_Completion.h"
+#include "Grid_Gaps_OneCell.h"
+#include "Grid_Gaps.h"
+#include "Grid_CombineGrids.h"
+#include "Grid_ConstantGrid.h"
+#include "Grid_CropToData.h"
+#include "Grid_InvertNoData.h"
+#include "GridsFromTableAndGrid.h"
+
+#include "Grid_Value_Type.h"
+#include "Grid_Value_Replace.h"
+#include "Grid_Value_Replace_Interactive.h"
+#include "Grid_Value_Request.h"
+#include "Grid_Value_Reclassify.h"
+
+#include "Grid_Buffer.h"
+#include "Grid_ThresholdBuffer.h"
+#include "Grid_Buffer_Proximity.h"
+
+#include "Grid_SortRaster.h"
+
+#include "Grid_Fill.h"
+
+#include "CreateGridSystem.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case  0:	return( new CGrid_Resample );
+	case  1:	return( new CGrid_Aggregate );
+	case  2:	return( new CGrid_Cut );
+	case  3:	return( new CGrid_Merge );
+	case  4: 	return( new CConstantGrid );
+	case  5:	return( new CGrid_Completion );
+	case  6:	return( new CGrid_Gaps_OneCell );
+	case  7:	return( new CGrid_Gaps );
+	case  8:	return( new CGrid_Buffer );
+	case  9: 	return( new CThresholdBuffer );
+	case 10:	return( new CGrid_Proximity_Buffer );
+	case 11:	return( new CGrid_Value_Type );
+	case 12:	return( new CGrid_Value_Replace );
+	case 13:	return( new CGrid_Value_Replace_Interactive );
+	case 14:	return( new CGrid_Value_Request );
+	case 15:	return( new CGrid_Value_Reclassify );
+	case 16:	return( new CGrid_Fill );
+	case 17: 	return( new CCropToData );
+	case 18: 	return( new CInvertNoData );
+	case 19:	return( new CGrid_Orientation );
+	case 20: 	return( new CCombineGrids );
+	case 21: 	return( new CSortRaster );
+	case 22: 	return( new CGridsFromTableAndGrid );
+	case 23: 	return( new CCreateGridSystem );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_tools/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_tools_H
+#define HEADER_INCLUDED__grid_tools_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_tools_EXPORTS
+	#define	grid_tools_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_tools_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_tools_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,735 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_3D_Image.cpp                   //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_3D_Image.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_3D_Image::CGrid_3D_Image(void)
+{
+	Set_Name(_TL("Create 3D Image"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description(
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"				, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "IMAGE"			, _TL("Overlay Image"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL	, "SHAPES"			, _TL("Shapes to project"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "ZEXAGG"			, _TL("Exaggeration"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ZEXAGG_MIN"		, _TL("Minimum Exaggeration [%]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "Z_ROTATE"		, _TL("Image Rotation [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "X_ROTATE"		, _TL("Local Rotation [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "X_ROTATE_LEVEL"	, _TL("Local Rotation Base Level"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Zero"),
+			_TL("Mean Elevation")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "PANBREAK"		, _TL("Panorama Break [%]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 70.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BKCOLOR"			, _TL("Background Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color, SG_COLOR_BLACK
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "PROJECTION"		, _TL("Projection"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Panorama"),
+			_TL("Circular")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "NX"				, _TL("3D Image Width"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NY"				, _TL("3D Image Height"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RGB"				, _TL("3D Image"),
+		_TL(""),
+//		PARAMETER_OUTPUT_OPTIONAL, false, SG_DATATYPE_Int
+		PARAMETER_OUTPUT_OPTIONAL, true, SG_DATATYPE_Int
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RGB_Z"			, _TL("Projected Height"),
+		_TL(""),
+//		PARAMETER_OUTPUT_OPTIONAL, false, SG_DATATYPE_Float
+		PARAMETER_OUTPUT_OPTIONAL, true, SG_DATATYPE_Float
+	);
+}
+
+//---------------------------------------------------------
+CGrid_3D_Image::~CGrid_3D_Image(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_3D_Image::On_Execute(void)
+{
+	//-----------------------------------------------------
+	m_pDEM			= Parameters("DEM")				->asGrid();
+	m_pImage		= Parameters("IMAGE")			->asGrid();
+
+	m_Projection	= Parameters("PROJECTION")		->asInt();
+
+	m_ZExagg		= Parameters("ZEXAGG")			->asDouble();
+	m_ZExagg_Min	= Parameters("ZEXAGG_MIN")		->asDouble() / 100.0;
+	m_ZMean			= Parameters("X_ROTATE_LEVEL")	->asInt() == 0 ? 0.0 : m_pDEM->Get_ZMin() + m_pDEM->Get_ZRange() / 2.0;
+	m_XRotate		= Parameters("X_ROTATE")		->asDouble() * M_DEG_TO_RAD;
+	m_ZRotate		= Parameters("Z_ROTATE")		->asDouble() * M_DEG_TO_RAD;
+
+	m_PanoramaBreak	= Parameters("PANBREAK")		->asDouble() / 100.0;
+
+	//-----------------------------------------------------
+	m_pRGB			= Parameters("RGB")				->asGrid();
+	m_pRGB_Z		= Parameters("RGB_Z")			->asGrid();
+
+	if( !m_pRGB )
+	{
+		int		nx, ny;
+
+		nx			= Parameters("NX")->asInt();
+		ny			= Parameters("NY")->asInt();
+
+		m_pRGB		= SG_Create_Grid(SG_DATATYPE_Int		, nx, ny, 1.0);
+	}
+
+	if( !m_pRGB_Z || !m_pRGB_Z->is_Compatible(m_pRGB->Get_System()) )
+	{
+		m_pRGB_Z	= SG_Create_Grid(m_pRGB, SG_DATATYPE_Float);
+	}
+
+	m_pRGB			->Set_Name(_TL("3D Image"));
+	m_pRGB			->Assign(Parameters("BKCOLOR")->asDouble());
+
+	m_pRGB_Z		->Set_Name(_TL("3D Image Height"));
+	m_pRGB_Z		->Set_NoData_Value_Range(-999999, -999999);
+	m_pRGB_Z		->Assign_NoData();
+
+	//-----------------------------------------------------
+	m_XScale		= (double)m_pRGB->Get_NX() / (double)Get_NX();
+	m_YScale		= (double)m_pRGB->Get_NY() / (double)Get_NY();
+
+	//-----------------------------------------------------
+	_Set_Grid();
+
+	CSG_Parameter_Shapes_List	*pShapes	= Parameters("SHAPES")->asShapesList();
+
+	for(int i=0; i<pShapes->Get_Count(); i++)
+	{
+		_Set_Shapes(pShapes->asShapes(i));
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DRAW_TRIANGLE(pa, pb, pc)	p[0] = pa; p[1] = pb; p[2] = pc; _Draw_Triangle(p);
+
+//---------------------------------------------------------
+void CGrid_3D_Image::_Set_Grid(void)
+{
+	T3DPoint	*a, *b, *c, *d, p[3];
+
+	//-----------------------------------------------------
+	a	= (T3DPoint *)SG_Malloc(sizeof(T3DPoint) *  Get_NX());
+	b	= (T3DPoint *)SG_Malloc(sizeof(T3DPoint) *  Get_NX());
+	c	= (T3DPoint *)SG_Malloc(sizeof(T3DPoint) * (Get_NX() - 1));
+
+	//-----------------------------------------------------
+	_Get_Line(0, b);
+
+	for(int y=1; y<Get_NY() && Set_Progress(y); y++)
+	{
+		d	= a;
+		a	= b;
+		b	= d;
+
+		_Get_Line(y, b);
+		_Get_Line(a, b, c);
+
+		for(int ax=0, bx=1; bx<Get_NX(); ax++, bx++)
+		{
+			DRAW_TRIANGLE(a[ax], a[bx], c[ax]);
+			DRAW_TRIANGLE(b[ax], b[bx], c[ax]);
+			DRAW_TRIANGLE(a[ax], b[ax], c[ax]);
+			DRAW_TRIANGLE(a[bx], b[bx], c[ax]);
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(a);
+	SG_Free(b);
+	SG_Free(c);
+
+	//-----------------------------------------------------
+	DataObject_Add(m_pRGB_Z);
+	DataObject_Add(m_pRGB);
+	DataObject_Set_Colors(m_pRGB, 100, SG_COLORS_BLACK_WHITE);
+}
+
+//---------------------------------------------------------
+void CGrid_3D_Image::_Set_Shapes(CSG_Shapes *pInput)
+{
+	int			iShape, iPart, iPoint;
+	double		x, y, z, dx, dy;
+	T3DPoint	p;
+	TSG_Point	Point;
+	CSG_Shape		*pShape;
+	CSG_Shapes		*pOutput;
+
+	if( pInput && pInput->is_Valid() )
+	{
+		Process_Set_Text(CSG_String::Format(_TL("Project \'%s\'"), pInput->Get_Name()));
+
+		pOutput	= SG_Create_Shapes(*pInput);
+		dx		= (double)Get_NX() / Get_System()->Get_XRange();
+		dy		= (double)Get_NY() / Get_System()->Get_YRange();
+
+		for(iShape=0; iShape<pOutput->Get_Count() && Set_Progress(iShape, pOutput->Get_Count()); iShape++)
+		{
+			pShape	= pOutput->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					Point	= pShape->Get_Point(iPoint, iPart);
+
+					x		= dx * (Point.x - Get_XMin());
+					y		= dy * (Point.y - Get_YMin());
+					z		= m_pDEM->is_InGrid((int)x, (int)y, true) ? m_pDEM->asDouble((int)x, (int)y) : 0.0;
+
+					_Get_Position(x, y, z, p);
+
+					pShape->Set_Point(p.x, p.y, iPoint, iPart);
+				}
+			}
+		}
+
+		DataObject_Add(pOutput);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_3D_Image::_Get_Line(int y, T3DPoint *p)
+{
+	for(int x=0; x<Get_NX(); x++)
+	{
+		if( m_pDEM->is_NoData(x, y) || m_pImage->is_NoData(x, y) )
+		{
+			p[x].bOk	= false;
+		}
+		else
+		{
+			p[x].r		= SG_GET_R(m_pImage->asInt(x, y));
+			p[x].g		= SG_GET_G(m_pImage->asInt(x, y));
+			p[x].b		= SG_GET_B(m_pImage->asInt(x, y));
+
+			_Get_Position(x, y, m_pDEM->asDouble(x, y), p[x]);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CGrid_3D_Image::_Get_Line(T3DPoint *a, T3DPoint *b, T3DPoint *c)
+{
+	for(int ax=0, bx=1; bx<Get_NX(); ax++, bx++)
+	{
+		if( (c[ax].bOk = a[ax].bOk && a[bx].bOk && b[ax].bOk && b[bx].bOk) == true )
+		{
+			c[ax].x	= (int)(0.5 +	(a[ax].x + a[bx].x + b[ax].x + b[bx].x) / 4.0);
+			c[ax].y	= (int)(0.5 +	(a[ax].y + a[bx].y + b[ax].y + b[bx].y) / 4.0);
+			c[ax].z	=				(a[ax].z + a[bx].z + b[ax].z + b[bx].z) / 4.0;
+
+			c[ax].r	=				(a[ax].r + a[bx].r + b[ax].r + b[bx].r) / 4;
+			c[ax].g	=				(a[ax].g + a[bx].g + b[ax].g + b[bx].g) / 4;
+			c[ax].b	=				(a[ax].b + a[bx].b + b[ax].b + b[bx].b) / 4;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CGrid_3D_Image::_Get_Position(double x, double y, double z, T3DPoint &p)
+{
+	bool	bResult;
+
+	//-----------------------------------------------------
+	if( m_ZRotate != 0.0 )
+	{
+		_Get_Rotated(0.5 * Get_NX(), x, 0.5 * Get_NY(), y, m_ZRotate);
+	}
+
+	x	= m_XScale *  x;
+	y	= m_YScale *  y;
+	z	= m_ZExagg * ((z - m_ZMean) / Get_Cellsize());
+
+	//-----------------------------------------------------
+	switch( m_Projection )
+	{
+	case 0: default:
+		bResult	= _Get_Panorama	(y, z);
+		break;
+
+	case 1:
+		bResult	= _Get_Circle	(y, z);
+		break;
+
+	case 2:
+		bResult	= _Get_Sinus	(y, z);
+		break;
+
+	case 3:
+		bResult	= _Get_Hyperbel	(y, z);
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		p.bOk	= true;
+		p.x		= (int)x;
+		p.y		= (int)y;
+		p.z		=      z;
+	}
+	else
+	{
+		p.bOk	= false;
+	}
+}
+
+//---------------------------------------------------------
+inline void CGrid_3D_Image::_Get_Rotated(double xAxis, double &x, double yAxis, double &y, double angle)
+{
+	double	dsin, dcos, dx, dy;
+
+	dsin	= sin(-angle);
+	dcos	= cos(-angle);
+
+	dx		= x - xAxis;
+	dy		= y - yAxis;
+
+	x		= xAxis + dcos * dx - dsin * dy;
+	y		= yAxis + dsin * dx + dcos * dy;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			now follow the projection specials			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CGrid_3D_Image::_Get_Panorama(double &y, double &z)
+{
+	int		yOffset, yRange;
+	double	angle;
+
+	if( y < (yOffset = (int)(m_PanoramaBreak * m_pRGB->Get_NY())) )
+	{
+		_Get_Rotated(y, y, 0.0, z, m_XRotate);
+	}
+	else
+	{
+		_Get_Rotated(y, y, 0.0, z, m_XRotate);
+
+		yRange	= m_pRGB->Get_NY() - yOffset;
+		angle	= M_PI_090 * ((y - yOffset) / (double)yRange);
+
+		z		= z * (m_ZExagg_Min + (1.0 - m_ZExagg_Min) * (angle > M_PI_090 ? 0.0 : 0.5 + 0.5 * cos(2.0 * angle)));
+
+	//	if( angle < m_XRotate )
+	//	{
+	//		_Get_Rotated(y, y, 0.0, z, m_XRotate - angle);
+	//	}
+
+		y		= yOffset;
+
+		_Get_Rotated(y, y, -(1.0 / M_PI_090) * yRange, z, angle);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_3D_Image::_Get_Circle(double &y, double &z)
+{
+	double	angle;
+
+	angle	= M_PI_090 * (y / (double)m_pRGB->Get_NY());
+
+	z		= z * (m_ZExagg_Min + (1.0 - m_ZExagg_Min) * (angle > M_PI_090 ? 0.0 : 0.5 + 0.5 * cos(2.0 * angle)));
+
+	y		= 0.0;
+
+	_Get_Rotated(y, y, -(1.0 / M_PI_090) * m_pRGB->Get_NY(), z, angle);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_3D_Image::_Get_Sinus(double &y, double &z)
+{
+	if( y >= 0 && y < m_pRGB->Get_NY() )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_3D_Image::_Get_Hyperbel(double &y, double &z)
+{
+	if( y >= 0 && y < m_pRGB->Get_NY() )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SORT_POINTS_Y(a, b)	if( p[a].y < p[b].y ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+#define SORT_POINTS_X(a, b)	if( p[a].x < p[b].x ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+
+//---------------------------------------------------------
+void CGrid_3D_Image::_Draw_Triangle(T3DPoint p[3])
+{
+	int		i, j, k, y, y_j;
+	double	x[2], dx[2], dy, z[2], dz[2], r[2], dr[2], g[2], dg[2], b[2], db[2];
+	T3DPoint	pp;
+
+	//-----------------------------------------------------
+	if( !p[0].bOk || !p[1].bOk || !p[2].bOk )
+	{
+		return;
+	}
+
+	//-----------------------------------------------------
+	SORT_POINTS_Y(1, 0);
+	SORT_POINTS_Y(2, 0);
+	SORT_POINTS_Y(2, 1);
+
+	//-----------------------------------------------------
+	if( p[2].y == p[0].y )
+	{
+		if( p[0].y >= 0 && p[0].y < m_pRGB->Get_NY() )
+		{
+			SORT_POINTS_X(1, 0);
+			SORT_POINTS_X(2, 0);
+			SORT_POINTS_X(2, 1);
+
+			//---------------------------------------------
+			if( p[2].x == p[0].x )
+			{
+				if(	p[0].x >= 0 && p[0].x < m_pRGB->Get_NX() )
+				{
+					i	= p[0].z > p[1].z ? (p[0].z > p[2].z ? 0 : 2) : (p[1].z > p[2].z ? 1 : 2);
+					_Draw_Pixel(p[0].x, p[0].y, p[i].z, p[i].r, p[i].g, p[i].b);
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				_Draw_Line(p[0].x, p[1].x, p[0].y, p[0].z, p[1].z, p[0].r, p[1].r, p[0].g, p[1].g, p[0].b, p[1].b);
+				_Draw_Line(p[1].x, p[2].x, p[0].y, p[1].z, p[2].z, p[1].r, p[2].r, p[1].g, p[2].g, p[1].b, p[2].b);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= m_pRGB->Get_NY() && p[2].y >= m_pRGB->Get_NY())) )
+	{
+		dy		=  p[2].y - p[0].y;
+		dx[0]	= (p[2].x - p[0].x) / dy;
+		dz[0]	= (p[2].z - p[0].z) / dy;
+		dr[0]	= (p[2].r - p[0].r) / dy;
+		dg[0]	= (p[2].g - p[0].g) / dy;
+		db[0]	= (p[2].b - p[0].b) / dy;
+		x [0]	=  p[0].x;
+		z [0]	=  p[0].z;
+		r [0]	=  p[0].r;
+		g [0]	=  p[0].g;
+		b [0]	=  p[0].b;
+
+		for(i=0, j=1; i<2; i++, j++)
+		{
+			if( (dy	=  p[j].y - p[i].y) > 0.0 )
+			{
+				dx[1]	= (p[j].x - p[i].x) / dy;
+				dz[1]	= (p[j].z - p[i].z) / dy;
+				dr[1]	= (p[j].r - p[i].r) / dy;
+				dg[1]	= (p[j].g - p[i].g) / dy;
+				db[1]	= (p[j].b - p[i].b) / dy;
+				x [1]	=  p[i].x;
+				z [1]	=  p[i].z;
+				r [1]	=  p[i].r;
+				g [1]	=  p[i].g;
+				b [1]	=  p[i].b;
+
+				if( (y = p[i].y) < 0 )
+				{
+					x[1]	-= y * dx[1];
+					z[1]	-= y * dz[1];
+					r[1]	-= y * dr[1];
+					g[1]	-= y * dg[1];
+					b[1]	-= y * db[1];
+					y		 = 0;
+					x[0]	 = p[0].x - p[0].y * dx[0];
+					z[0]	 = p[0].z - p[0].y * dz[0];
+					r[0]	 = p[0].r - p[0].y * dr[0];
+					g[0]	 = p[0].g - p[0].y * dg[0];
+					b[0]	 = p[0].b - p[0].y * db[0];
+				}
+
+				if( (y_j = p[j].y) > m_pRGB->Get_NY() )
+				{
+					y_j		= m_pRGB->Get_NY();
+				}
+
+				for( ; y<y_j; y++)
+				{
+					if( x[1] < x[0] )
+					{
+						_Draw_Line((int)x[1], (int)x[0], y, z[1], z[0], r[1], r[0], g[1], g[0], b[1], b[0]);
+					}
+					else
+					{
+						_Draw_Line((int)x[0], (int)x[1], y, z[0], z[1], r[0], r[1], g[0], g[1], b[0], b[1]);
+					}
+
+					for(k=0; k<=1; k++)
+					{
+						x[k]	+= dx[k];
+						z[k]	+= dz[k];
+						r[k]	+= dr[k];
+						g[k]	+= dg[k];
+						b[k]	+= db[k];
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CGrid_3D_Image::_Draw_Line(int xa, int xb, int y, double za, double zb, double ra, double rb, double ga, double gb, double ba, double bb)
+{
+	double	d, dz, dr, dg, db;
+
+	if( (d = xb - xa) > 0.0 )
+	{
+		dz	= (zb - za) / d;
+		dr	= (rb - ra) / d;
+		dg	= (gb - ga) / d;
+		db	= (bb - ba) / d;
+
+		if( xa < 0 )
+		{
+			za	-= dz * xa;
+			ra	-= dr * xa;
+			ga	-= dg * xa;
+			ba	-= db * xa;
+			xa	 = 0;
+		}
+
+		if( xb >= m_pRGB->Get_NX() )
+		{
+			xb	= m_pRGB->Get_NX() - 1;
+		}
+
+		for(int x=xa; x<=xb; x++, za+=dz, ra+=dr, ga+=dg, ba+=db)
+		{
+			_Draw_Pixel(x, y, za, (int)ra, (int)ga, (int)ba);
+		}
+	}
+	else if( xa >= 0 && xa < m_pRGB->Get_NX() )
+	{
+		_Draw_Pixel(xa, y, za, (int)ra, (int)ga, (int)ba);
+	}
+}
+
+//---------------------------------------------------------
+inline void CGrid_3D_Image::_Draw_Pixel(int x, int y, double z, BYTE r, BYTE g, BYTE b)
+{
+	if(	m_pRGB->is_InGrid(x, y, false) && (m_pRGB_Z->is_NoData(x, y) || z > m_pRGB_Z->asDouble(x, y)) )
+	{
+		m_pRGB_Z	->Set_Value(x, y, z);
+		m_pRGB		->Set_Value(x, y, SG_GET_RGB(r, g, b));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_3D_Image.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,144 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_3D_Image.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_3D_Image_H
+#define HEADER_INCLUDED__Grid_3D_Image_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_3D_Image : public CSG_Module_Grid  
+{
+public:
+	CGrid_3D_Image(void);
+	virtual ~CGrid_3D_Image(void);
+
+
+protected:
+
+	virtual bool					On_Execute			(void);
+
+
+private:
+
+	typedef struct
+	{
+		bool						bOk;
+
+		BYTE						r, g, b;
+
+		int							x, y;
+
+		double						z;
+	}
+	T3DPoint;
+
+
+	int								m_Projection;
+
+	double							m_ZMean, m_ZExagg, m_ZExagg_Min, m_ZRotate, m_XRotate, m_XScale, m_YScale, m_PanoramaBreak;
+
+	CSG_Grid							*m_pDEM, *m_pImage, *m_pRGB, *m_pRGB_Z;
+
+
+	void							_Set_Grid			(void);
+	void							_Set_Shapes			(CSG_Shapes *pInput);
+
+	void							_Get_Line			(int y, T3DPoint *p);
+	void							_Get_Line			(T3DPoint *a, T3DPoint *b, T3DPoint *c);
+
+	void							_Get_Position		(double x, double y, double z, T3DPoint &p);
+	void							_Get_Rotated		(double xAxis, double &x, double yAxis, double &y, double angle);
+
+	bool							_Get_Panorama		(double &y, double &z);
+	bool							_Get_Sinus			(double &y, double &z);
+	bool							_Get_Circle			(double &y, double &z);
+	bool							_Get_Hyperbel		(double &y, double &z);
+
+	void							_Draw_Triangle		(T3DPoint p[3]);
+	void							_Draw_Line			(int xa, int xb, int y, double za, double zb, double ra, double rb, double ga, double gb, double ba, double bb);
+	void							_Draw_Pixel			(int x, int y, double z, BYTE r, BYTE g, BYTE b);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_3D_Image_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,170 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Color_Blend.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Color_Blend.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Color_Blend::CGrid_Color_Blend(void)
+{
+	Set_Name(_TL("Color Blending"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description(
+		_TL("Creates a color animation based on the values of selected grids.\n")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NSTEPS"	, _TL("Interpolation Steps"),
+		_TL(""),
+		PARAMETER_TYPE_Int	, 0.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Color_Blend::~CGrid_Color_Blend(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Color_Blend::On_Execute(void)
+{
+	int						iGrid, x, y, iStep, nSteps;
+	double					d, dStep, Value_A, Value_B;
+	CSG_Grid					*pGrid, *pGrid_A, *pGrid_B;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	pGrid	= Parameters("GRID")	->asGrid();
+	pGrids	= Parameters("GRIDS")	->asGridList();
+
+	if( pGrids->Get_Count() > 1 )
+	{
+		nSteps	= Parameters("NSTEPS")->asInt();
+		dStep	= 1.0 / (1.0 + nSteps);
+		nSteps	= (1 + nSteps) * (pGrids->Get_Count() - 1);
+
+		pGrid_B	= pGrids->asGrid(0);
+
+		if( pGrid->Get_ZRange() > 0.0 )
+		{
+			pGrid->Assign(pGrid_B);
+			DataObject_Update(pGrid, true);
+		}
+		else
+		{
+			pGrid->Assign(pGrid_B);
+			DataObject_Update(pGrid, pGrid_B->Get_ZMin(), pGrid_B->Get_ZMax(), true);
+		}
+
+		for(iGrid=1, iStep=1; iGrid<pGrids->Get_Count() && Set_Progress(iStep, nSteps); iGrid++, iStep++)
+		{
+			pGrid_A	= pGrid_B;
+			pGrid_B	= pGrids->asGrid(iGrid);
+
+			for(d=dStep; d<1.0 && Set_Progress(iStep, nSteps); d+=dStep, iStep++)
+			{
+				for(y=0; y<Get_NY(); y++)
+				{
+					for(x=0; x<Get_NX(); x++)
+					{
+						Value_A	= pGrid_A->asDouble(x, y);
+						Value_B	= pGrid_B->asDouble(x, y);
+
+						pGrid->Set_Value(x, y, Value_A + d * (Value_B - Value_A) );
+					}
+				}
+
+				DataObject_Update(pGrid, true);
+			}
+
+			pGrid->Assign(pGrid_B);
+			DataObject_Update(pGrid, true);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Blend.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Color_Blend.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Color_Blend_H
+#define HEADER_INCLUDED__Grid_Color_Blend_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Color_Blend : public CSG_Module_Grid
+{
+public:
+	CGrid_Color_Blend(void);
+	virtual ~CGrid_Color_Blend(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Color_Blend_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,143 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Color_Rotate.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Color_Rotate.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Color_Rotate::CGrid_Color_Rotate(void)
+{
+	Set_Name		(_TL("Color Palette Rotation"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"The 'Color Palette Rotator' rotates the grids color palette. "
+	));
+
+	Parameters.Add_Grid(	NULL, "GRID"	, _TL("Grid")	, _TL(""), PARAMETER_INPUT);
+	Parameters.Add_Colors(	NULL, "COLORS"	, _TL("Colors")	, _TL(""));
+	Parameters.Add_Value(	NULL, "DIR"		, _TL("Down")	, _TL(""), PARAMETER_TYPE_Bool, true);
+
+}
+
+//---------------------------------------------------------
+CGrid_Color_Rotate::~CGrid_Color_Rotate(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Color_Rotate::On_Execute(void)
+{
+	bool	bDown;
+	int		i;
+	long	c;
+	CSG_Grid	*pGrid;
+	CSG_Colors	*pColors;
+
+	pGrid	= Parameters("GRID")->asGrid();
+	pColors	= Parameters("COLORS")->asColors();
+	bDown	= Parameters("DIR")->asBool();
+
+	if( pColors->Get_Count() > 1 )
+	{
+		do
+		{
+			if( bDown )
+			{
+				for(i=0, c=pColors->Get_Color(0); i<pColors->Get_Count() - 1; i++)
+				{
+					pColors->Set_Color(i, pColors->Get_Color(i + 1));
+				}
+
+				pColors->Set_Color(pColors->Get_Count() - 1, c);
+			}
+			else
+			{
+				for(i=pColors->Get_Count()-1, c=pColors->Get_Color(pColors->Get_Count()-1); i>0; i--)
+				{
+					pColors->Set_Color(i, pColors->Get_Color(i - 1));
+				}
+
+				pColors->Set_Color(0, c);
+			}
+
+			DataObject_Set_Colors(pGrid, *pColors);
+			DataObject_Update(pGrid, true);
+		}
+		while( Process_Get_Okay(true) );
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Rotate.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Color_Rotate.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Color_Rotate_H
+#define HEADER_INCLUDED__Grid_Color_Rotate_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Color_Rotate : public CSG_Module_Grid  
+{
+public:
+	CGrid_Color_Rotate(void);
+	virtual ~CGrid_Color_Rotate(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Color_Rotate_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,375 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Color_Triangle.cpp                //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Color_Triangle.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Color_Triangle::CGrid_Color_Triangle(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name		(_TL("Color Triangle Composite"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Similar to 'RGB Composite', but the three colors representing intensity of each data set can be chosen by user. "
+	));
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "A_GRID"		, _TL("A"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		pNode	, "A_COLOR"		, _TL("Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color	, SG_COLOR_RED
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "A_METHOD"	,	_TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 1"),
+			_TL("Rescale to 0 - 1"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "A_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 1
+	);
+
+	Parameters.Add_Range(
+		pNode	, "A_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "A_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "B_GRID"		, _TL("B"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		pNode	, "B_COLOR"		, _TL("Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color	, SG_COLOR_GREEN
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "B_METHOD"	, _TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 1"),
+			_TL("Rescale to 0 - 1"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "B_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 1
+	);
+
+	Parameters.Add_Range(
+		pNode	, "B_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "B_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "C_GRID"		, _TL("C"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		pNode	, "C_COLOR"		, _TL("Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color	, SG_COLOR_BLUE
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "C_METHOD"	, _TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 1.0"),
+			_TL("Rescale to 0 - 1.0"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "C_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 1
+	);
+
+	Parameters.Add_Range(
+		pNode	, "C_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "C_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Composite"),
+		_TL(""),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Int
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Color_Triangle::~CGrid_Color_Triangle(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define CHK_COLOR(C)	if( C > 255 )	C	= 255;	else if( C < 0 )	C	= 0;
+
+//---------------------------------------------------------
+bool CGrid_Color_Triangle::On_Execute(void)
+{
+	int			x, y, Color[3], aC[3], bC[3], cC[3];
+	double		aMin, bMin, cMin, aRange, bRange, cRange, a, b, c;
+	CSG_Grid	*pA, *pB, *pC, *pRGB;
+
+	//-----------------------------------------------------
+	pA		= _Get_Grid(Parameters("A_GRID")->asGrid(), Parameters("A_METHOD")->asInt(), Parameters("A_RANGE")->asRange(), Parameters("A_PERCTL")->asRange(), Parameters("A_PERCENT")->asDouble(), aMin, aRange);
+	pB		= _Get_Grid(Parameters("B_GRID")->asGrid(), Parameters("B_METHOD")->asInt(), Parameters("B_RANGE")->asRange(), Parameters("B_PERCTL")->asRange(), Parameters("B_PERCENT")->asDouble(), bMin, bRange);
+	pC		= _Get_Grid(Parameters("C_GRID")->asGrid(), Parameters("C_METHOD")->asInt(), Parameters("C_RANGE")->asRange(), Parameters("C_PERCTL")->asRange(), Parameters("C_PERCENT")->asDouble(), cMin, cRange);
+
+	x		= Parameters("A_COLOR")->asColor();
+	aC[0]	= SG_GET_R(x);
+	aC[1]	= SG_GET_G(x);
+	aC[2]	= SG_GET_B(x);
+
+	x		= Parameters("B_COLOR")->asColor();
+	bC[0]	= SG_GET_R(x);
+	bC[1]	= SG_GET_G(x);
+	bC[2]	= SG_GET_B(x);
+
+	x		= Parameters("C_COLOR")->asColor();
+	cC[0]	= SG_GET_R(x);
+	cC[1]	= SG_GET_G(x);
+	cC[2]	= SG_GET_B(x);
+
+	//-----------------------------------------------------
+	pRGB	= Parameters("GRID")->asGrid();
+	pRGB->Create(pRGB->Get_System(), SG_DATATYPE_Int);
+	DataObject_Set_Colors(pRGB, 100, SG_COLORS_BLACK_WHITE);
+
+	CSG_Parameters	Parms;
+
+	if( DataObject_Get_Parameters(pRGB, Parms) && Parms("COLORS_TYPE") )
+	{
+		Parms("COLORS_TYPE")->Set_Value(3);	// Color Classification Type: RGB
+
+		DataObject_Set_Parameters(pRGB, Parms);
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pA->is_NoData(x, y) || pB->is_NoData(x, y) || pC->is_NoData(x, y) )
+			{
+				pRGB->Set_NoData(x, y);
+			}
+			else
+			{
+				a	= aRange * (pA->asDouble(x, y) - aMin);	if( a > 1.0 )	a	= 1.0;	else if( a < 0.0 )	a	= 0.0;
+				b	= bRange * (pB->asDouble(x, y) - bMin);	if( b > 1.0 )	b	= 1.0;	else if( b < 0.0 )	b	= 0.0;
+				c	= cRange * (pC->asDouble(x, y) - cMin);	if( c > 1.0 )	c	= 1.0;	else if( c < 0.0 )	c	= 0.0;
+
+				Color[0]	= (int)((a * aC[0] + b * bC[0] + c * cC[0]));	CHK_COLOR(Color[0]);
+				Color[1]	= (int)((a * aC[1] + b * bC[1] + c * cC[1]));	CHK_COLOR(Color[1]);
+				Color[2]	= (int)((a * aC[2] + b * bC[2] + c * cC[2]));	CHK_COLOR(Color[2]);
+
+				pRGB->Set_Value(x, y, SG_GET_RGB(Color[0], Color[1], Color[2]));
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid * CGrid_Color_Triangle::_Get_Grid(CSG_Grid *pGrid, int Method, CSG_Parameter_Range *pRange, CSG_Parameter_Range *pPerctl, double Percent, double &Min, double &Range)
+{
+	if( pGrid )
+	{
+		int		x, y;
+		long	n;
+
+		switch( Method )
+		{
+		default:
+		case 0:	// 0 - 1
+			Min		= 0.0;
+			Range	= 1.0;
+			break;
+
+		case 1:	// Rescale to 0 - 1
+			Min		= pGrid->Get_ZMin();
+			Range	= pGrid->Get_ZRange();
+			Range	= Range > 0.0 ? 1.0 / Range : 0.0;
+			break;
+
+		case 2:	// User defined rescale
+			Min		= pRange->Get_LoVal();
+			Range	= pRange->Get_HiVal() - pRange->Get_LoVal();
+			Range	= Range > 0.0 ? 1.0 / Range : 0.0;
+			break;
+
+		case 3:	// Normalise
+			n		= (long)(pGrid->Get_NCells() * pPerctl->Get_LoVal() / 100.0);
+			pGrid->Get_Sorted(n < 0 ? 0 : (n >= pGrid->Get_NCells() ? pGrid->Get_NCells() - 1 : n), x, y, false, false);
+			Min		= pGrid->asDouble(x, y);
+			n		= (long)(pGrid->Get_NCells() * pPerctl->Get_HiVal() / 100.0);
+			pGrid->Get_Sorted(n < 0 ? 0 : (n >= pGrid->Get_NCells() ? pGrid->Get_NCells() - 1 : n), x, y, false, false);
+			Range	= pGrid->asDouble(x, y) - Min;
+			Range	= Range > 0.0 ? 1.0 / Range : 0.0;
+			break;
+
+		case 4:	// Standard deviation
+			Range	= sqrt(pGrid->Get_Variance()) * Percent / 100.0;
+			Min		= pGrid->Get_ArithMean() - Range;
+			Range	= Range * 2.0;
+			Range	= Range > 0.0 ? 1.0 / Range : 0.0;
+			break;
+		}
+	}
+
+	return( pGrid );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Color_Triangle.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,87 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Color_Triangle.h                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Color_Triangle_H
+#define HEADER_INCLUDED__Grid_Color_Triangle_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Color_Triangle : public CSG_Module_Grid  
+{
+public:
+	CGrid_Color_Triangle(void);
+	virtual ~CGrid_Color_Triangle(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	CSG_Grid *				_Get_Grid	(CSG_Grid *pGrid, int Method, CSG_Parameter_Range *pRange, CSG_Parameter_Range *pPerctl, double Percent, double &Min, double &Range);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Color_Triangle_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,205 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Colors_Fit.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Colors_Fit.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Colors_Fit::CGrid_Colors_Fit(void)
+{
+	Set_Name		(_TL("Fit Color Palette to Grid Values"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "COUNT"	, _TL("Number of Colors"),
+		_TL(""),
+		PARAMETER_TYPE_Int	, 100, 2, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SCALE"	, _TL("Scale"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Grid range"),
+			_TL("User defined range")
+		), 0
+	);
+
+	Parameters.Add_Range(
+		NULL	, "RANGE"	, _TL("User defined range"),
+		_TL(""),
+		0.0, 1.0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Colors_Fit::~CGrid_Colors_Fit(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Colors_Fit::On_Execute(void)
+{
+	int		iColor;
+	long	aC, bC;
+	double	aZ, bZ, dColor, zMin, zRange;
+	CSG_Colors	Colors_Old, Colors_New;
+	CSG_Grid	*pGrid;
+
+	pGrid	= Parameters("GRID")->asGrid();
+
+	Colors_New.Set_Count(Parameters("COUNT")->asInt());
+
+	switch( Parameters("SCALE")->asInt() )
+	{
+	case 0:	default:
+		zMin	= pGrid->Get_ZMin();
+		zRange	= pGrid->Get_ZMax() - zMin;
+		break;
+
+	case 1:
+		zMin	= Parameters("RANGE")->asRange()->Get_LoVal();
+		zRange	= Parameters("RANGE")->asRange()->Get_HiVal() - zMin;
+		break;
+	}
+
+	DataObject_Get_Colors(pGrid, Colors_Old);
+
+	if( Colors_Old.Get_Count() > 1 && pGrid->Get_ZRange() > 0.0 && zRange != 0.0 )
+	{
+		dColor	= 100.0 / Colors_Old.Get_Count();
+
+		aZ		= 0.0;
+		aC		= Colors_Old.Get_Color(0);
+
+		for(iColor=1; iColor<Colors_Old.Get_Count()-1; iColor++)
+		{
+			bZ	= aZ;
+			bC	= aC;
+			aZ	= (pGrid->Get_Percentile(100.0 - iColor * dColor, false) - zMin) / zRange;
+			aC	= Colors_Old.Get_Color(iColor);
+			_Set_Colors(Colors_New, bZ, bC, aZ, aC);
+		}
+
+		bZ	= aZ;
+		bC	= aC;
+		aZ	= 1.0;
+		aC	= Colors_Old.Get_Color(Colors_Old.Get_Count() - 1);
+		_Set_Colors(Colors_New, bZ, bC, aZ, aC);
+
+		DataObject_Set_Colors	(pGrid, Colors_New);
+		DataObject_Update		(pGrid, zMin, zMin + zRange);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Colors_Fit::_Set_Colors(CSG_Colors &Colors, double pos_a, long color_a, double pos_b, long color_b)
+{
+	int		a, b;
+
+	a	= (int)(pos_a * Colors.Get_Count());	if( a < 0 )	a	= 0;	else if( a >= Colors.Get_Count() )	a	= Colors.Get_Count() - 1;
+	b	= (int)(pos_b * Colors.Get_Count());	if( b < 0 )	b	= 0;	else if( b >= Colors.Get_Count() )	b	= Colors.Get_Count() - 1;
+
+	Colors.Set_Ramp(color_a, color_b, a, b);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_Colors_Fit.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Colors_Fit.h                   //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Colors_Fit_H
+#define HEADER_INCLUDED__Grid_Colors_Fit_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Colors_Fit : public CSG_Module_Grid  
+{
+public:
+	CGrid_Colors_Fit(void);
+	virtual ~CGrid_Colors_Fit(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	void					_Set_Colors		(CSG_Colors &Colors, double pos_a, long color_a, double pos_b, long color_b);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Colors_Fit_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,391 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_RGB_Composite.cpp                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_RGB_Composite.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_RGB_Composite::CGrid_RGB_Composite(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name		(_TL("RGB Composite"));
+
+	Set_Author		(SG_T("(c) 2002 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create red-green-blue overlays of grids. "
+	));
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "GRID_R"		, _TL("Red"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "R_METHOD"	,	_TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 255"),
+			_TL("Rescale to 0 - 255"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "R_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 255
+	);
+
+	Parameters.Add_Range(
+		pNode	, "R_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "R_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "GRID_G"		, _TL("Green"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "G_METHOD"	, _TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 255"),
+			_TL("Rescale to 0 - 255"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "G_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 255
+	);
+
+	Parameters.Add_Range(
+		pNode	, "G_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "G_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "GRID_B"		, _TL("Blue"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "B_METHOD"	, _TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 255"),
+			_TL("Rescale to 0 - 255"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "B_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 255
+	);
+
+	Parameters.Add_Range(
+		pNode	, "B_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "B_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= NULL;
+
+	pNode	= Parameters.Add_Grid(
+		pNode	, "GRID_A"		, _TL("Transparency"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "A_METHOD"	, _TL("Value Preparation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("0 - 255"),
+			_TL("Rescale to 0 - 255"),
+			_TL("User defined rescale"),
+			_TL("Percentiles"),
+			_TL("Percentage of standard deviation")
+		), 4
+	);
+
+	Parameters.Add_Range(
+		pNode	, "A_RANGE"		, _TL("Rescale Range"),
+		_TL(""),
+		0, 255
+	);
+
+	Parameters.Add_Range(
+		pNode	, "A_PERCTL"	, _TL("Percentiles"),
+		_TL(""),
+		1.0, 99.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "A_PERCENT"	, _TL("Percentage of standard deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 150.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID_RGB"	, _TL("Composite"),
+		_TL(""),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Int
+	);
+}
+
+//---------------------------------------------------------
+CGrid_RGB_Composite::~CGrid_RGB_Composite(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_RGB_Composite::On_Execute(void)
+{
+	int			x, y, r, g, b, a;
+	double		rMin, gMin, bMin, aMin, rRange, gRange, bRange, aRange;
+	CSG_Grid	*pR, *pG, *pB, *pA, *pRGB;
+
+	//-----------------------------------------------------
+	pR		= _Get_Grid(Parameters("GRID_R")->asGrid(), Parameters("R_METHOD")->asInt(), Parameters("R_RANGE")->asRange(), Parameters("R_PERCTL")->asRange(), Parameters("R_PERCENT")->asDouble(), rMin, rRange);
+	pG		= _Get_Grid(Parameters("GRID_G")->asGrid(), Parameters("G_METHOD")->asInt(), Parameters("G_RANGE")->asRange(), Parameters("G_PERCTL")->asRange(), Parameters("G_PERCENT")->asDouble(), gMin, gRange);
+	pB		= _Get_Grid(Parameters("GRID_B")->asGrid(), Parameters("B_METHOD")->asInt(), Parameters("B_RANGE")->asRange(), Parameters("B_PERCTL")->asRange(), Parameters("B_PERCENT")->asDouble(), bMin, bRange);
+	pA		= _Get_Grid(Parameters("GRID_A")->asGrid(), Parameters("A_METHOD")->asInt(), Parameters("A_RANGE")->asRange(), Parameters("A_PERCTL")->asRange(), Parameters("A_PERCENT")->asDouble(), aMin, aRange);
+
+	//-----------------------------------------------------
+	pRGB	= Parameters("GRID_RGB")->asGrid();
+	pRGB->Create(pRGB->Get_System(), SG_DATATYPE_Int);
+	DataObject_Set_Colors(pRGB, 100, SG_COLORS_BLACK_WHITE);
+
+	CSG_Parameters	Parms;
+
+	if( DataObject_Get_Parameters(pRGB, Parms) && Parms("COLORS_TYPE") )
+	{
+		Parms("COLORS_TYPE")->Set_Value(3);	// Color Classification Type: RGB
+
+		DataObject_Set_Parameters(pRGB, Parms);
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pR->is_NoData(x, y) || pG->is_NoData(x, y) || pB->is_NoData(x, y) )
+			{
+				pRGB->Set_NoData(x, y);
+			}
+			else
+			{
+				r	= (int)(rRange * (pR->asDouble(x, y) - rMin));
+				if( r > 255 )	r	= 255;	else if( r < 0 )	r	= 0;
+
+				g	= (int)(gRange * (pG->asDouble(x, y) - gMin));
+				if( g > 255 )	g	= 255;	else if( g < 0 )	g	= 0;
+
+				b	= (int)(bRange * (pB->asDouble(x, y) - bMin));
+				if( b > 255 )	b	= 255;	else if( b < 0 )	b	= 0;
+
+				if( pA )
+				{
+					a	= (int)(aRange * (pA->asDouble(x, y) - aMin));
+					if( a > 255 )	a	= 255;	else if( a < 0 )	a	= 0;
+
+					pRGB->Set_Value(x, y, SG_GET_RGBA(r, g, b, a));
+				}
+				else
+				{
+					pRGB->Set_Value(x, y, SG_GET_RGB(r, g, b));
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid * CGrid_RGB_Composite::_Get_Grid(CSG_Grid *pGrid, int Method, CSG_Parameter_Range *pRange, CSG_Parameter_Range *pPerctl, double Percent, double &Min, double &Range)
+{
+	if( pGrid )
+	{
+		int		x, y;
+		long	n;
+
+		switch( Method )
+		{
+		default:
+		case 0:	// 0 - 255
+			Min		= 0.0;
+			Range	= 1.0;
+			break;
+
+		case 1:	// Rescale to 0 - 255
+			Min		= pGrid->Get_ZMin();
+			Range	= pGrid->Get_ZRange();
+			Range	= Range > 0.0 ? 255.0 / Range : 0.0;
+			break;
+
+		case 2:	// User defined rescale
+			Min		= pRange->Get_LoVal();
+			Range	= pRange->Get_HiVal() - pRange->Get_LoVal();
+			Range	= Range > 0.0 ? 255.0 / Range : 0.0;
+			break;
+
+		case 3:	// Normalise
+			n		= (long)(pGrid->Get_NCells() * pPerctl->Get_LoVal() / 100.0);
+			pGrid->Get_Sorted(n < 0 ? 0 : (n >= pGrid->Get_NCells() ? pGrid->Get_NCells() - 1 : n), x, y, false, false);
+			Min		= pGrid->asDouble(x, y);
+			n		= (long)(pGrid->Get_NCells() * pPerctl->Get_HiVal() / 100.0);
+			pGrid->Get_Sorted(n < 0 ? 0 : (n >= pGrid->Get_NCells() ? pGrid->Get_NCells() - 1 : n), x, y, false, false);
+			Range	= pGrid->asDouble(x, y) - Min;
+			Range	= Range > 0.0 ? 255.0 / Range : 0.0;
+			break;
+
+		case 4:	// Standard deviation
+			Range	= sqrt(pGrid->Get_Variance()) * Percent / 100.0;
+			Min		= pGrid->Get_ArithMean() - Range;
+			Range	= Range * 2.0;
+			Range	= Range > 0.0 ? 255.0 / Range : 0.0;
+			break;
+		}
+	}
+
+	return( pGrid );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/Grid_RGB_Composite.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,87 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_RGB_Composite.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_RGB_Composite_H
+#define HEADER_INCLUDED__Grid_RGB_Composite_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_RGB_Composite : public CSG_Module_Grid  
+{
+public:
+	CGrid_RGB_Composite(void);
+	virtual ~CGrid_RGB_Composite(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	CSG_Grid *				_Get_Grid	(CSG_Grid *pGrid, int Method, CSG_Parameter_Range *pRange, CSG_Parameter_Range *pPerctl, double Percent, double &Min, double &Range);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_RGB_Composite_H

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,132 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Grid - Visualisation") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Special visualisation functions for grids.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Grid|Visualisation") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Grid_Color_Rotate.h"
+#include "Grid_Color_Blend.h"
+#include "Grid_Colors_Fit.h"
+#include "Grid_RGB_Composite.h"
+#include "Grid_3D_Image.h"
+#include "Grid_Color_Triangle.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CGrid_Color_Rotate );
+	case 1:		return( new CGrid_Color_Blend );
+	case 2:		return( new CGrid_Colors_Fit );
+	case 3:		return( new CGrid_RGB_Composite );
+	case 4:		return( new CGrid_3D_Image );
+	case 5:		return( new CGrid_Color_Triangle );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/grid/grid_visualisation/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Grid_Visualisation                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_visualisation_H
+#define HEADER_INCLUDED__grid_visualisation_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef grid_visualisation_EXPORTS
+	#define	grid_visualisation_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	grid_visualisation_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_visualisation_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Point Cloud - Tools") );
+
+	case MLB_INFO_Author:
+		return( _TL("O.Conrad (c) 2009") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for point clouds.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Point Cloud") );
+	}
+}
+
+
+//---------------------------------------------------------
+#include "pc_cut.h"
+#include "pc_from_grid.h"
+#include "pc_from_shapes.h"
+#include "pc_to_grid.h"
+#include "pc_to_shapes.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CPC_Cut );
+	case 1:		return( new CPC_Cut_Interactive );
+	case 2:		return( new CPC_From_Grid );
+	case 3:		return( new CPC_From_Shapes );
+	case 4:		return( new CPC_To_Grid );
+	case 5:		return( new CPC_To_Shapes );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,80 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__pointcloud_tools_H
+#define HEADER_INCLUDED__pointcloud_tools_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef pointcloud_tools_EXPORTS
+	#define	pointcloud_tools_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	pointcloud_tools_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__pointcloud_tools_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,371 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       pc_cut.cpp                      //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "pc_cut.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPC_Cut::CPC_Cut(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud Cutter"));
+
+	Set_Author		(SG_T("O.Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_PointCloud(
+		NULL	, "CUT"			, _TL("Cut"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "AREA"		, _TL("Choose Cut from ..."),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("User Defined Extent"),
+			_TL("Grid System Extent"),
+			_TL("Shapes Extent"),
+			_TL("Polygons")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters;
+
+	pParameters	= Add_Parameters	(	   "USER"		, _TL("User Defined Extent"), _TL(""));
+	pParameters->Add_Value			(NULL, "XMIN"		, _TL("Left")				, _TL(""), PARAMETER_TYPE_Double);
+	pParameters->Add_Value			(NULL, "XMAX"		, _TL("Right")				, _TL(""), PARAMETER_TYPE_Double);
+	pParameters->Add_Value			(NULL, "YMIN"		, _TL("Bottom")				, _TL(""), PARAMETER_TYPE_Double);
+	pParameters->Add_Value			(NULL, "YMAX"		, _TL("Top")				, _TL(""), PARAMETER_TYPE_Double);
+
+	pParameters	= Add_Parameters	(	   "GRID"		, _TL("Grid System Extent")	, _TL(""));
+	pParameters->Add_Grid_System	(NULL, "GRID"		, _TL("Grid System")		, _TL(""));
+
+	pParameters	= Add_Parameters	(	   "SHAPES"		, _TL("Shapes Extent")		, _TL(""));
+	pParameters->Add_Shapes			(NULL, "SHAPES"		, _TL("Left")				, _TL(""), PARAMETER_INPUT);
+
+	pParameters	= Add_Parameters	(	   "POLYGONS"	, _TL("Polygons")			, _TL(""));
+	pParameters->Add_Shapes			(NULL, "POLYGONS"	, _TL("Polygons")			, _TL(""), PARAMETER_INPUT, SHAPE_TYPE_Polygon);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPC_Cut::On_Execute(void)
+{
+	CSG_PointCloud	*pPoints	= Parameters("POINTS")	->asPointCloud();
+	CSG_PointCloud	*pCut		= Parameters("CUT")		->asPointCloud();
+
+	//-----------------------------------------------------
+	switch( Parameters("AREA")->asInt() )
+	{
+	case 0:	// User Defined Extent
+		if( Dlg_Parameters("USER") )
+		{
+			CSG_Rect	r(
+				Get_Parameters("USER")->Get_Parameter("XMIN")->asDouble(),
+				Get_Parameters("USER")->Get_Parameter("YMIN")->asDouble(),
+				Get_Parameters("USER")->Get_Parameter("XMAX")->asDouble(),
+				Get_Parameters("USER")->Get_Parameter("YMAX")->asDouble()
+			);
+
+			return( Get_Cut(pPoints, pCut, r) );
+		}
+		break;
+
+	case 1:	// Grid System Extent
+		if( Dlg_Parameters("GRID") )
+		{
+			return( Get_Cut(pPoints, pCut, Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid_System()->Get_Extent()) );
+		}
+		break;
+
+	case 2:	// Shapes Extent
+		if( Dlg_Parameters("SHAPES") )
+		{
+			return( Get_Cut(pPoints, pCut, Get_Parameters("SHAPES")->Get_Parameter("SHAPES")->asShapes()->Get_Extent()) );
+		}
+		break;
+
+	case 3:	// Polygons
+		if( Dlg_Parameters("POLYGONS") )
+		{
+			return( Get_Cut(pPoints, pCut, Get_Parameters("POLYGONS")->Get_Parameter("POLYGONS")->asShapes()) );
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPC_Cut::Get_Cut(CSG_PointCloud *pPoints, CSG_PointCloud *pCut, const CSG_Rect &Extent)
+{
+	if( pPoints && pPoints->is_Valid() && pCut )
+	{
+		pCut->Create(pPoints);
+		pCut->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), _TL("Cut")));
+
+		if( Extent.Intersects(pPoints->Get_Extent()) )
+		{
+			for(int i=0; i<pPoints->Get_Point_Count() && SG_UI_Process_Set_Progress(i, pPoints->Get_Point_Count()); i++)
+			{
+				pPoints->Set_Cursor(i);
+
+				if( Extent.Contains(pPoints->Get_X(), pPoints->Get_Y()) )
+				{
+					pCut->Add_Point(pPoints->Get_X(), pPoints->Get_Y(), pPoints->Get_Z());
+
+					for(int j=0; j<pPoints->Get_Field_Count() - 3; j++)
+					{
+						pCut->Set_Attribute(j, pPoints->Get_Attribute(j));
+					}
+				}
+			}
+		}
+
+		return( pCut->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPC_Cut::Get_Cut(CSG_PointCloud *pPoints, CSG_PointCloud *pCut, CSG_Shapes *pPolygons)
+{
+	if( pPoints && pPoints->is_Valid() && pCut )
+	{
+		pCut->Create(pPoints);
+		pCut->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), pPolygons->Get_Name()));
+
+		if( pPolygons && pPolygons->Get_Type() == SHAPE_TYPE_Polygon && pPolygons->Get_Extent().Intersects(pPoints->Get_Extent()) )
+		{
+			for(int i=0; i<pPoints->Get_Point_Count() && SG_UI_Process_Set_Progress(i, pPoints->Get_Point_Count()); i++)
+			{
+				pPoints->Set_Cursor(i);
+
+				if( Contains(pPolygons, pPoints->Get_X(), pPoints->Get_Y()) )
+				{
+					pCut->Add_Point(pPoints->Get_X(), pPoints->Get_Y(), pPoints->Get_Z());
+
+					for(int j=0; j<pPoints->Get_Field_Count() - 3; j++)
+					{
+						pCut->Set_Attribute(j, pPoints->Get_Attribute(j));
+					}
+				}
+			}
+		}
+
+		return( pCut->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPC_Cut::Contains(CSG_Shapes *pPolygons, double x, double y)
+{
+	if( pPolygons->Get_Extent().Contains(x, y) )
+	{
+		for(int iPolygon=0; iPolygon<pPolygons->Get_Count(); iPolygon++)
+		{
+			CSG_Shape_Polygon	*pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon);
+
+			if( pPolygon->is_Containing(x, y) )
+			{
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPC_Cut_Interactive::CPC_Cut_Interactive(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud Cutter"));
+
+	Set_Author		(SG_T("O.Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_PointCloud(
+		NULL	, "CUT"			, _TL("Cut"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters	= Add_Parameters("CUT", _TL("Cut"), _TL(""));
+
+	pParameters->Add_Value(NULL, "XMIN", _TL("Left")	, _TL(""), PARAMETER_TYPE_Double);
+	pParameters->Add_Value(NULL, "XMAX", _TL("Right")	, _TL(""), PARAMETER_TYPE_Double);
+	pParameters->Add_Value(NULL, "YMIN", _TL("Bottom")	, _TL(""), PARAMETER_TYPE_Double);
+	pParameters->Add_Value(NULL, "YMAX", _TL("Top")		, _TL(""), PARAMETER_TYPE_Double);
+}
+
+//---------------------------------------------------------
+bool CPC_Cut_Interactive::On_Execute(void)
+{
+	m_pPoints	= Parameters("POINTS")	->asPointCloud();
+	m_pCut		= Parameters("CUT")		->asPointCloud();
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CPC_Cut_Interactive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	switch( Mode )
+	{
+	//-----------------------------------------------------
+	case MODULE_INTERACTIVE_LDOWN:
+
+		m_ptDown	= ptWorld;
+
+		return( true );
+
+	//-----------------------------------------------------
+	case MODULE_INTERACTIVE_LUP:
+
+		CSG_Rect		r(m_ptDown.Get_X(), m_ptDown.Get_Y(), ptWorld.Get_X(), ptWorld.Get_Y());
+
+		CSG_Parameters	*pParameters	= Get_Parameters("CUT");
+
+		pParameters->Get_Parameter("XMIN")->Set_Value(r.Get_XMin());
+		pParameters->Get_Parameter("XMAX")->Set_Value(r.Get_XMax());
+		pParameters->Get_Parameter("YMIN")->Set_Value(r.Get_YMin());
+		pParameters->Get_Parameter("YMAX")->Set_Value(r.Get_YMax());
+
+		if( Dlg_Parameters("CUT") )
+		{
+			r.Assign(
+				pParameters->Get_Parameter("XMIN")->asDouble(),
+				pParameters->Get_Parameter("YMIN")->asDouble(),
+				pParameters->Get_Parameter("XMAX")->asDouble(),
+				pParameters->Get_Parameter("YMAX")->asDouble()
+			);
+
+			if( CPC_Cut::Get_Cut(m_pPoints, m_pCut, r) )
+			{
+				DataObject_Update(m_pCut);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_cut.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,133 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       pc_cut.h                        //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PC_Cut_H
+#define HEADER_INCLUDED__PC_Cut_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPC_Cut : public CSG_Module
+{
+public:
+	CPC_Cut(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("R:Tools") );	}
+
+	static bool					Get_Cut					(CSG_PointCloud *pPoints, CSG_PointCloud *pCut, const CSG_Rect &Extent);
+	static bool					Get_Cut					(CSG_PointCloud *pPoints, CSG_PointCloud *pCut, CSG_Shapes *pPolygons);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	static bool					Contains				(CSG_Shapes *pPolygons, double x, double y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPC_Cut_Interactive : public CSG_Module_Interactive
+{
+public:
+	CPC_Cut_Interactive(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("R:Tools") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+	virtual bool				On_Execute_Position		(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	CSG_Point					m_ptDown;
+
+	CSG_PointCloud				*m_pPoints, *m_pCut;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PC_Cut_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,158 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    pc_from_grid.cpp                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "pc_from_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPC_From_Grid::CPC_From_Grid(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud from Grid Points"));
+
+	Set_Author		(SG_T("O.Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Z Value"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Additional Values"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL, false
+	);
+
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPC_From_Grid::On_Execute(void)
+{
+	int						x, y, i;
+	TSG_Point				p;
+	CSG_Grid				*pGrid;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_PointCloud			*pPoints;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")	->asGrid();
+	pGrids	= Parameters("GRIDS")	->asGridList();
+	pPoints	= Parameters("POINTS")	->asPointCloud();
+
+	pPoints->Create();
+	pPoints->Set_Name(pGrid->Get_Name());
+
+	for(i=0; i<pGrids->Get_Count(); i++)
+	{
+		pPoints->Add_Field(pGrids->asGrid(i)->Get_Name(), SG_DATATYPE_Float);
+	}
+
+	//-----------------------------------------------------
+	for(y=0, p.y=Get_YMin(); y<Get_NY() && Set_Progress(y); y++, p.y+=Get_Cellsize())
+	{
+		for(x=0, p.x=Get_XMin(); x<Get_NX(); x++, p.x+=Get_Cellsize())
+		{
+			if( !pGrid->is_NoData(x, y) )
+			{
+				pPoints->Add_Point(p.x, p.y, pGrid->asDouble(x, y));
+
+				for(i=0; i<pGrids->Get_Count(); i++)
+				{
+					pPoints->Set_Value(3 + i, pGrids->asGrid(i)->Get_Value(p));
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    pc_from_grid.h                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PC_From_Grid_H
+#define HEADER_INCLUDED__PC_From_Grid
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPC_From_Grid : public CSG_Module_Grid
+{
+public:
+	CPC_From_Grid(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PC_From_Grid_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,185 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   pc_from_shapes.cpp                  //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "pc_from_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPC_From_Shapes::CPC_From_Shapes(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud from Shapes"));
+
+	Set_Author		(SG_T("O.Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZFIELD"		, _TL("Z Value"),
+		_TL("")
+	);
+
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "OUTPUT"		, _TL("Output"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("only z"),
+			_TL("all attributes")
+		), 0
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPC_From_Shapes::On_Execute(void)
+{
+	int				zField, iField, nFields, *Fields;
+	CSG_PointCloud	*pPoints;
+	CSG_Shapes		*pShapes;
+
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	pPoints	= Parameters("POINTS")	->asPointCloud();
+	zField	= Parameters("ZFIELD")	->asInt();
+
+	if( !pShapes->is_Valid() )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	pPoints->Create();
+	pPoints->Set_Name(pShapes->Get_Name());
+
+	nFields	= 0;
+	Fields	= new int[pShapes->Get_Field_Count()];
+
+	if( Parameters("OUTPUT")->asInt() == 1 )
+	{
+		for(iField=0, nFields=0; iField<pShapes->Get_Field_Count(); iField++)
+		{
+			if( iField != zField && SG_Data_Type_Get_Size(pShapes->Get_Field_Type(iField)) > 0 )
+			{
+				Fields[nFields++]	= iField;
+				pPoints->Add_Field(pShapes->Get_Field_Name(iField), pShapes->Get_Field_Type(iField));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+	{
+		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				TSG_Point	p	= pShape->Get_Point(iPoint, iPart);
+
+				pPoints->Add_Point(p.x, p.y, pShape->asDouble(zField));
+
+				for(iField=0; iField<nFields; iField++)
+				{
+					pPoints->Set_Value(3 + iField, pShape->asDouble(Fields[iField]));
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	delete(Fields);
+
+	return( pPoints->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_from_shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   pc_from_shapes.h                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PC_From_Shapes_H
+#define HEADER_INCLUDED__PC_From_Shapes_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPC_From_Shapes : public CSG_Module
+{
+public:
+	CPC_From_Shapes(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PC_From_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,285 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    pc_to_grid.cpp                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "pc_to_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPC_To_Grid::CPC_To_Grid(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud to Grid"));
+
+	Set_Author		(SG_T("O.Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Z Value"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "COUNT"		, _TL("Number of Points in Cell"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Attributes"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "OUTPUT"		, _TL("Output"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("only z"),
+			_TL("all attributes")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "AGGREGATION"	, _TL("Aggregation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("first value"),
+			_TL("last value"),
+			_TL("mean value"),
+			_TL("lowest z"),
+			_TL("highest z")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CELLSIZE"	, _TL("Cellsize"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPC_To_Grid::On_Execute(void)
+{
+	int						x, y, iField, iGrid;
+	CSG_Grid_System			System;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_PointCloud			*pPoints;
+
+	pPoints			= Parameters("POINTS")		->asPointCloud();
+	pGrids			= Parameters("GRIDS")		->asGridList();
+	m_Aggregation	= Parameters("AGGREGATION")	->asInt();
+
+	//-----------------------------------------------------
+	System.Assign(Parameters("CELLSIZE")->asDouble(), pPoints->Get_Extent());
+
+	//-----------------------------------------------------
+	pGrids->Del_Items();
+
+	if( Parameters("OUTPUT")->asInt() != 0 )
+	{
+		for(iField=3; iField<pPoints->Get_Field_Count(); iField++)
+		{
+			pGrids->Add_Item(SG_Create_Grid(System, SG_DATATYPE_Float));
+			pGrids->asGrid(iField - 3)->Set_Name(CSG_String::Format(SG_T("%s - %s"), pPoints->Get_Name(), pPoints->Get_Field_Name(iField)));
+		}
+	}
+
+	Parameters("GRID")	->Set_Value(m_pGrid  = SG_Create_Grid(System, SG_DATATYPE_Float));
+	Parameters("COUNT")	->Set_Value(m_pCount = SG_Create_Grid(System, SG_DATATYPE_Int));
+
+	m_pGrid		->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), pPoints->Get_Field_Name(2)));
+	m_pCount	->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), _TL("Points per Cell")));
+
+	m_pCount	->Set_NoData_Value(0.0);
+
+	//-----------------------------------------------------
+	for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++)
+	{
+		pPoints->Set_Cursor(iPoint);
+
+		if( System.Get_World_to_Grid(x, y, pPoints->Get_X(), pPoints->Get_Y()) )
+		{
+			int		n	= m_pCount->asInt(x, y);
+			double	z	= pPoints->Get_Z();
+
+			for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+			{
+				Set_Value(x, y, z, n, pPoints->Get_Value(iGrid + 3), pGrids->asGrid(iGrid));
+			}
+
+			Set_Value(x, y, z, n, z, m_pGrid);
+
+			m_pCount->Add_Value(x, y, 1);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y++)
+	{
+		for(x=0; x<System.Get_NX(); x++)
+		{
+			int		n	= m_pCount->asInt(x, y);
+
+			switch( n )
+			{
+			case 0:
+				m_pGrid->Set_NoData(x, y);
+
+				for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+				{
+					pGrids->asGrid(iGrid)->Set_NoData(x, y);
+				}
+				break;
+
+			case 1:
+				break;
+
+			default:
+				if( m_Aggregation == 2 )	// mean value
+				{
+					m_pGrid->Mul_Value(x, y, 1.0 / n);
+
+					for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+					{
+						pGrids->asGrid(iGrid)->Mul_Value(x, y, 1.0 / n);
+					}
+				}
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CPC_To_Grid::Set_Value(int x, int y, double z, int Count, double value, CSG_Grid *pGrid)
+{
+	switch( m_Aggregation )
+	{
+	case 0:	// first value
+		if( Count == 0 )
+		{
+			pGrid->Set_Value(x, y, value);
+		}
+		break;
+
+	case 1:	// last value
+		pGrid->Set_Value(x, y, value);
+		break;
+
+	case 2:	// mean value
+		pGrid->Add_Value(x, y, value);
+		break;
+
+	case 3:	// lowest z
+		if( Count == 0 || z < m_pGrid->asDouble(x, y) )
+		{
+			pGrid->Set_Value(x, y, value);
+		}
+		break;
+
+	case 4:	// highest z
+		if( Count == 0 || z > m_pGrid->asDouble(x, y) )
+		{
+			pGrid->Set_Value(x, y, value);
+		}
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,105 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     pc_to_grid.h                      //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PC_To_Grid_H
+#define HEADER_INCLUDED__PC_To_Grid_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPC_To_Grid : public CSG_Module
+{
+public:
+	CPC_To_Grid(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	int							m_Aggregation;
+
+	CSG_Grid					*m_pGrid, *m_pCount;
+
+
+	void						Set_Value		(int x, int y, double z, int Count, double value, CSG_Grid *pGrid);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PC_To_Grid_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,146 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    pc_to_shapes.cpp                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "pc_to_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPC_To_Shapes::CPC_To_Shapes(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud to Shapes"));
+
+	Set_Author		(SG_T("O.Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPC_To_Shapes::On_Execute(void)
+{
+	int				iField;
+	CSG_PointCloud	*pPoints;
+	CSG_Shapes		*pShapes;
+
+	pPoints	= Parameters("POINTS")	->asPointCloud();
+	pShapes	= Parameters("SHAPES")	->asShapes();
+
+	//-----------------------------------------------------
+	pShapes->Create(SHAPE_TYPE_Point, pPoints->Get_Name());
+
+	for(iField=2; iField<pPoints->Get_Field_Count(); iField++)
+	{
+		pShapes->Add_Field(pPoints->Get_Field_Name(iField), pPoints->Get_Field_Type(iField));
+	}
+
+	//-----------------------------------------------------
+	for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++)
+	{
+		pPoints->Set_Cursor(iPoint);
+
+		CSG_Shape	*pShape	= pShapes->Add_Shape();
+
+		pShape->Add_Point(pPoints->Get_X(), pPoints->Get_Y());
+
+		for(iField=2; iField<pPoints->Get_Field_Count(); iField++)
+		{
+			pShape->Set_Value(iField - 2, pPoints->Get_Value(iField));
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_tools/pc_to_shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_tools                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    pc_to_shapes.h                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PC_To_Shapes_H
+#define HEADER_INCLUDED__PC_To_Shapes_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPC_To_Shapes : public CSG_Module
+{
+public:
+	CPC_To_Shapes(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PC_To_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_viewer                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute for Geography                //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Point Cloud - Viewer") );
+
+	case MLB_INFO_Author:
+		return( SG_T("O.Conrad (c) 2009") );
+
+	case MLB_INFO_Description:
+		return( _TL("Point cloud viewer." ));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Point Cloud|Visualisation" ));
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "points_view_module.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CPoints_View_Module );
+
+	default:	return( NULL );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,80 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   pointcloud_viewer                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute for Geography                //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__pointcloud_viewer_mlb_H
+#define HEADER_INCLUDED__pointcloud_viewer_mlb_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef pointcloud_viewer_EXPORTS
+	#define	pointcloud_viewer_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	pointcloud_viewer_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__pointcloud_viewer_mlb_H

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,704 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     SAGA_GUI_API                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                points_view_control.cpp                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#include <wx/settings.h>
+#include <wx/dc.h>
+#include <wx/dcclient.h>
+
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#include "points_view_control.h"
+#include "points_view_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define m_Settings	(*m_pSettings)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CPoints_View_Control, wxPanel)
+	EVT_SIZE				(CPoints_View_Control::On_Size)
+	EVT_PAINT				(CPoints_View_Control::On_Paint)
+	EVT_LEFT_DOWN			(CPoints_View_Control::On_Mouse_LDown)
+	EVT_LEFT_UP				(CPoints_View_Control::On_Mouse_LUp)
+	EVT_RIGHT_DOWN			(CPoints_View_Control::On_Mouse_RDown)
+	EVT_RIGHT_UP			(CPoints_View_Control::On_Mouse_RUp)
+	EVT_MIDDLE_DOWN			(CPoints_View_Control::On_Mouse_MDown)
+	EVT_MIDDLE_UP			(CPoints_View_Control::On_Mouse_MUp)
+	EVT_MOTION				(CPoints_View_Control::On_Mouse_Motion)
+	EVT_MOUSEWHEEL			(CPoints_View_Control::On_Mouse_Wheel)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPoints_View_Control::CPoints_View_Control(wxWindow *pParent, CSG_PointCloud *pPoints, CSG_Parameters &Settings)
+	: wxPanel(pParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxSUNKEN_BORDER|wxNO_FULL_REPAINT_ON_RESIZE)
+{
+	m_pPoints	= pPoints;
+
+	m_pSettings	= &Settings;
+
+	m_zField	= 2;
+	m_cField	= 2;
+
+	m_xRotate	= 0.0;
+	m_yRotate	= 0.0;
+	m_zRotate	= 0.0;
+
+	m_xShift	= 0.0;
+	m_yShift	= 0.0;
+	m_zShift	= 1000.0;
+
+	m_bCentral	= true;
+	m_bStereo	= false;
+	m_bScale	= false;
+
+	m_dCentral	= 500.0;
+	m_Detail	= 1.0;
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode	= m_pSettings->Add_Node(NULL, "NODE_CONTROL", _TL("3D View"), _TL(""));
+
+	m_pSettings->Add_Colors(
+		pNode	, "COLORS"			, _TL("Colors"),
+		_TL("")
+	);
+
+	m_pSettings->Add_Value(
+		pNode	, "BGCOLOR"			, _TL("Background Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color, 0
+	);
+
+	m_pSettings->Add_Range(
+		pNode	, "C_RANGE"			, _TL("Colors Value Range"),
+		_TL("")
+	);
+
+	m_pSettings->Add_Value(
+		pNode	, "C_AS_RGB"		, _TL("Value as RGB Code"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	m_pSettings->Add_Value(
+		pNode	, "SIZE_DEF"		, _TL("Point Size: Default"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 0, 0, true
+	);
+
+	m_pSettings->Add_Value(
+		pNode	, "SIZE_SCALE"		, _TL("Point Size: Scaling"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 250.0, 1.0, true
+	);
+
+	m_pSettings->Add_Value(
+		pNode	, "EXAGGERATION"	, _TL("Exaggeration"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	m_pSettings->Add_Value(
+		pNode	, "STEREO_DIST"		, _TL("Stereo Eye Distance [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	m_pSelection	= (int *)SG_Malloc(m_pPoints->Get_Count() * sizeof(int));
+
+	Update_Extent(m_pPoints->Get_Extent());
+}
+
+//---------------------------------------------------------
+CPoints_View_Control::~CPoints_View_Control(void)
+{
+	if( m_pSelection )
+	{
+		SG_Free(m_pSelection);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Size(wxSizeEvent &event)
+{
+	_Set_Size();
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Paint(wxPaintEvent &WXUNUSED(event))
+{
+	if( m_Image.IsOk() && m_Image.GetWidth() > 0 && m_Image.GetHeight() > 0 )
+	{
+		wxPaintDC	dc(this);
+
+		dc.DrawBitmap(wxBitmap(m_Image), 0, 0, false);
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::Update_View(void)
+{
+	if( _Draw_Image() )
+	{
+		wxClientDC	dc(this);
+
+		dc.DrawBitmap(wxBitmap(m_Image), 0, 0, false);
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::Update_Extent(CSG_Rect Extent)
+{
+	m_Extent.Assign(Extent);
+
+	m_zStats.Invalidate();
+	m_cStats.Invalidate();
+
+	m_nSelection	= 0;
+
+	for(int i=0; i<m_pPoints->Get_Count(); i++)
+	{
+		m_pPoints->Set_Cursor(i);
+
+		TSG_Point_3D	p	= m_pPoints->Get_Point();
+
+		if( m_Extent.Contains(p.x, p.y) )
+		{
+			m_pSelection[m_nSelection++]	= i;
+
+			m_zStats.Add_Value(m_pPoints->Get_Value(m_zField));
+			m_cStats.Add_Value(m_pPoints->Get_Value(m_cField));
+		}
+	}
+
+	m_Settings("C_RANGE")->asRange()->Set_Range(
+		m_cStats.Get_Mean() - 1.5 * m_cStats.Get_StdDev(),
+		m_cStats.Get_Mean() + 1.5 * m_cStats.Get_StdDev()
+	);
+
+	Update_View();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_MOUSE_X_RELDIFF	((double)(m_Mouse_Down.x - event.GetX()) / (double)GetClientSize().x)
+#define GET_MOUSE_Y_RELDIFF	((double)(m_Mouse_Down.y - event.GetY()) / (double)GetClientSize().y)
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Mouse_LDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= event.GetPosition();
+	m_xDown			= m_zRotate;
+	m_yDown			= m_xRotate;
+
+	CaptureMouse();
+}
+
+void CPoints_View_Control::On_Mouse_LUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	if( m_Mouse_Down.x != event.GetX() || m_Mouse_Down.y != event.GetY() )
+	{
+		m_zRotate	= m_xDown + GET_MOUSE_X_RELDIFF * M_PI_180;
+		m_xRotate	= m_yDown + GET_MOUSE_Y_RELDIFF * M_PI_180;
+
+		Update_View();
+
+		((CPoints_View_Dialog *)GetParent())->Update_Rotation();
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Mouse_RDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= event.GetPosition();
+	m_xDown			= m_xShift;
+	m_yDown			= m_yShift;
+
+	CaptureMouse();
+}
+
+void CPoints_View_Control::On_Mouse_RUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	if( m_Mouse_Down.x != event.GetX() || m_Mouse_Down.y != event.GetY() )
+	{
+		m_xShift	= m_xDown - GET_MOUSE_X_RELDIFF * 1000.0;
+		m_yShift	= m_yDown - GET_MOUSE_Y_RELDIFF * 1000.0;
+
+		Update_View();
+
+		((CPoints_View_Dialog *)GetParent())->Update_Rotation();
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Mouse_MDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= event.GetPosition();
+	m_xDown			= m_yRotate;
+	m_yDown			= m_zShift;
+
+	CaptureMouse();
+}
+
+void CPoints_View_Control::On_Mouse_MUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	if( m_Mouse_Down.x != event.GetX() || m_Mouse_Down.y != event.GetY() )
+	{
+		m_yRotate	= m_xDown + GET_MOUSE_X_RELDIFF * M_PI_180;
+		m_zShift	= m_yDown + GET_MOUSE_Y_RELDIFF * 1000.0;
+
+		Update_View();
+
+		((CPoints_View_Dialog *)GetParent())->Update_Rotation();
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Mouse_Motion(wxMouseEvent &event)
+{
+	if( HasCapture() && event.Dragging() )
+	{
+		if( event.LeftIsDown() )
+		{
+			m_zRotate	= m_xDown + GET_MOUSE_X_RELDIFF * M_PI_180;
+			m_xRotate	= m_yDown + GET_MOUSE_Y_RELDIFF * M_PI_180;
+		}
+		else if( event.RightIsDown() )
+		{
+			m_xShift	= m_xDown - GET_MOUSE_X_RELDIFF * 1000.0;
+			m_yShift	= m_yDown - GET_MOUSE_Y_RELDIFF * 1000.0;
+		}
+		else if( event.MiddleIsDown() )
+		{
+			m_yRotate	= m_xDown + GET_MOUSE_X_RELDIFF * M_PI_180;
+			m_zShift	= m_yDown + GET_MOUSE_Y_RELDIFF * 1000.0;
+		}
+		else
+		{
+			return;
+		}
+
+		Update_View();
+
+		((CPoints_View_Dialog *)GetParent())->Update_Rotation();
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Control::On_Mouse_Wheel(wxMouseEvent &event)
+{
+	if( event.GetWheelRotation() )
+	{
+		m_zShift	+= 0.5 * event.GetWheelRotation();
+
+		Update_View();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPoints_View_Control::_Set_Size(void)
+{
+	Update_View();
+}
+
+//---------------------------------------------------------
+bool CPoints_View_Control::_Draw_Image(void)
+{
+	wxSize	dcSize	= GetClientSize();
+
+	if( m_pPoints->Get_Count() <= 0
+	||	dcSize.x <= 0 || dcSize.y <= 0
+	||	m_Extent.Get_XRange() <= 0.0 || m_Extent.Get_YRange() <= 0.0
+	||	m_zField < 0 || m_zField >= m_pPoints->Get_Field_Count()
+	||	m_cField < 0 || m_cField >= m_pPoints->Get_Field_Count()
+	||	m_zStats.Get_Range() <= 0.0 )
+	{
+		return( false );
+	}
+
+	//-------------------------------------------------
+	if( !m_Image.IsOk() || dcSize.x != m_Image.GetWidth() || dcSize.y != m_Image.GetHeight() )
+	{
+		m_Image		.Create(dcSize.x, dcSize.y);
+		m_Image_zMax.Create(dcSize.x, dcSize.y);
+	}
+
+	//-------------------------------------------------
+	if( m_Settings("C_RANGE")->asRange()->Get_LoVal() >= m_Settings("C_RANGE")->asRange()->Get_HiVal() )
+	{
+		m_Settings("C_RANGE")->asRange()->Set_Range(
+			m_cStats.Get_Mean() - 1.5 * m_pPoints->Get_StdDev(m_cField),
+			m_cStats.Get_Mean() + 1.5 * m_pPoints->Get_StdDev(m_cField)
+		);
+	}
+
+	m_pColors	= m_Settings("COLORS")->asColors();
+	m_cMin		= m_Settings("C_RANGE")->asRange()->Get_LoVal();
+	m_cScale	= m_pColors->Get_Count() / (m_Settings("C_RANGE")->asRange()->Get_HiVal() - m_cMin);
+
+	//-------------------------------------------------
+	if( (dcSize.x / (double)dcSize.y) > (m_Extent.Get_XRange() / m_Extent.Get_YRange()) )
+	{
+		r_Scale	= m_Image.GetWidth() / m_Extent.Get_XRange();
+	}
+	else
+	{
+		r_Scale	= m_Image.GetHeight() / m_Extent.Get_YRange();
+	}
+
+	r_sin_x		= sin(m_xRotate - M_PI_180);
+	r_cos_x		= cos(m_xRotate - M_PI_180);
+	r_sin_y		= sin(m_yRotate);
+	r_cos_y		= cos(m_yRotate);
+	r_sin_z		= sin(m_zRotate);
+	r_cos_z		= cos(m_zRotate);
+
+	r_xc		= m_Extent.Get_XCenter();
+	r_yc		= m_Extent.Get_YCenter();
+	r_zc		= m_zStats.Get_Minimum() + 0.5 * m_zStats.Get_Range();
+
+	r_Scale_z	= r_Scale * m_Settings("EXAGGERATION")->asDouble();
+
+	//-------------------------------------------------
+	m_Size_Def		= m_Settings("SIZE_DEF")->asInt();
+	m_Size_Scale	= 1.0 / m_Settings("SIZE_SCALE")->asDouble();
+
+	m_bColorAsRGB	= m_Settings("C_AS_RGB")->asBool();
+
+	int		iSelection;
+	int		nSkip	= 1 + (int)(0.001 * m_pPoints->Get_Count() * SG_Get_Square(1.0 - m_Detail));
+
+	_Draw_Background();
+
+	//-------------------------------------------------
+	if( m_bStereo == false )
+	{
+		m_Image_zMax.Assign(999999.0);
+
+		m_Color_Mode	= COLOR_MODE_RGB;
+
+		for(iSelection=0; iSelection<m_nSelection; iSelection+=nSkip)
+		{
+			_Draw_Point(m_pSelection[iSelection]);
+		}
+	}
+
+	//-------------------------------------------------
+	else
+	{
+		double	d	= m_Settings("STEREO_DIST")->asDouble() / 2.0;
+
+		m_Image_zMax.Assign(999999.0);
+
+		r_sin_y	= sin(m_yRotate - d * M_DEG_TO_RAD);
+		r_cos_y	= cos(m_yRotate - d * M_DEG_TO_RAD);
+
+		m_Color_Mode	= COLOR_MODE_RED;
+
+		for(iSelection=0; iSelection<m_nSelection; iSelection+=nSkip)
+		{
+			_Draw_Point(m_pSelection[iSelection]);
+		}
+
+		m_Image_zMax.Assign(999999.0);
+
+		r_sin_y	= sin(m_yRotate + d * M_DEG_TO_RAD);
+		r_cos_y	= cos(m_yRotate + d * M_DEG_TO_RAD);
+
+		m_Color_Mode	= COLOR_MODE_BLUE;
+
+		for(iSelection=0; iSelection<m_nSelection; iSelection+=nSkip)
+		{
+			_Draw_Point(m_pSelection[iSelection]);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPoints_View_Control::_Draw_Background(void)
+{
+	BYTE	r, g, b, *pRGB;
+	int		i, n, color;
+
+	color	= m_Settings("BGCOLOR")->asColor();
+
+	if( m_bStereo )
+	{
+		color	= (int)((SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3.0);
+		color	= SG_GET_RGB(color, color, color);
+	}
+
+	r	= SG_GET_R(color);
+	g	= SG_GET_G(color);
+	b	= SG_GET_B(color);
+
+	n	= m_Image.GetWidth() * m_Image.GetHeight();
+
+	for(i=0, pRGB=m_Image.GetData(); i<n; i++)
+	{
+		*pRGB	= r;	pRGB++;
+		*pRGB	= g;	pRGB++;
+		*pRGB	= b;	pRGB++;
+	}
+}
+
+//---------------------------------------------------------
+inline void CPoints_View_Control::_Draw_Point(int iPoint)
+{
+	int				ix, iy, iColor;
+	double			iz;
+	TSG_Point_3D	p;
+
+	m_pPoints->Set_Cursor(iPoint);
+
+	p		= m_pPoints->Get_Point();
+	p.z		= m_pPoints->Get_Value(m_zField);
+
+	p		= _Get_Projection(p);
+
+	ix		= (int)(p.x + 0.5 * m_Image.GetWidth());
+	iy		= (int)(p.y + 0.5 * m_Image.GetHeight());
+	iz		= p.z;
+
+	if( !m_bColorAsRGB )
+	{
+		iColor	= (int)(m_cScale * (m_pPoints->Get_Value(m_cField) - m_cMin));
+		iColor	= m_pColors->Get_Color(iColor < 0 ? 0 : (iColor >= m_pColors->Get_Count() ? m_pColors->Get_Count() - 1 : iColor));
+	}
+	else
+	{
+		iColor	= (int)m_pPoints->Get_Value(m_cField);
+	}
+
+	_Draw_Point(ix, iy, iz, iColor, m_Size_Def + (!m_bScale ? 0 : (int)(20.0 * exp(-m_Size_Scale * iz))));
+}
+
+//---------------------------------------------------------
+inline void CPoints_View_Control::_Draw_Point(int x, int y, double z, int color, int Size)
+{
+	if( z > 0.0 )
+	{
+		_Draw_Pixel(x, y, z, color);
+
+		if( Size > 0 && Size < 50 )
+		{
+			for(int iy=1; iy<=Size; iy++)
+			{
+				for(int ix=0; ix<=Size; ix++)
+				{
+					if( ix*ix + iy*iy <= Size*Size )
+					{
+						_Draw_Pixel(x + ix, y + iy, z, color);
+						_Draw_Pixel(x + iy, y - ix, z, color);
+						_Draw_Pixel(x - ix, y - iy, z, color);
+						_Draw_Pixel(x - iy, y + ix, z, color);
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CPoints_View_Control::_Draw_Pixel(int x, int y, double z, int color)
+{
+	if( x >= 0 && x < m_Image.GetWidth() && y >= 0 && y < m_Image.GetHeight() && z < m_Image_zMax[y][x] )
+	{
+		BYTE	*pRGB	= m_Image.GetData() + 3 * (y * m_Image.GetWidth() + x);
+
+		switch( m_Color_Mode )
+		{
+		case COLOR_MODE_RGB:
+			*pRGB		= SG_GET_R(color);	pRGB++;
+			*pRGB		= SG_GET_G(color);	pRGB++;
+			*pRGB		= SG_GET_B(color);
+			break;
+
+		case COLOR_MODE_RED:
+			*pRGB		= ((SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3);
+			break;
+
+		case COLOR_MODE_BLUE:
+			*(pRGB + 1)	= ((SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3);
+			*(pRGB + 2)	= ((SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3);
+			break;
+		}
+
+		m_Image_zMax[y][x]	= z;
+	}
+}
+
+//---------------------------------------------------------
+inline TSG_Point_3D CPoints_View_Control::_Get_Projection(TSG_Point_3D &p)
+{
+	TSG_Point_3D	q;
+
+	p.x	= (p.x - r_xc) * r_Scale;
+	p.y	= (p.y - r_yc) * r_Scale;
+	p.z	= (p.z - r_zc) * r_Scale_z;
+
+	double	a	= (r_cos_y * p.z + r_sin_y * (r_sin_z * p.y + r_cos_z * p.x));
+	double	b	= (r_cos_z * p.y - r_sin_z * p.x);
+
+	q.x	= r_cos_y * (r_sin_z * p.y + r_cos_z * p.x) - r_sin_y * p.z;
+	q.y	= r_sin_x * a + r_cos_x * b;
+	q.z	= r_cos_x * a - r_sin_x * b;
+
+	q.x	+= m_xShift;
+	q.y	+= m_yShift;
+	q.z	+= m_zShift;
+
+	if( m_bCentral )
+	{
+		q.x	*= m_dCentral / q.z;
+		q.y	*= m_dCentral / q.z;
+	}
+	else
+	{
+		double	z	= m_dCentral / m_zShift;
+		q.x	*= z;
+		q.y	*= z;
+	//	q.z	 = -q.z;
+	}
+
+	return( q );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,183 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     SAGA_GUI_API                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 points_view_control.h                 //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__points_view_control_H
+#define HEADER_INCLUDED__points_view_control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_gdi/saga_gdi.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	COLOR_MODE_RGB,
+	COLOR_MODE_RED,
+	COLOR_MODE_BLUE
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPoints_View_Control : public wxPanel
+{
+public:
+	CPoints_View_Control(wxWindow *pParent, CSG_PointCloud *pPoints, CSG_Parameters &Settings);
+	virtual ~CPoints_View_Control(void);
+
+	bool						m_bCentral, m_bStereo, m_bScale;
+
+	int							m_zField, m_cField;
+
+	double						m_xRotate, m_yRotate, m_zRotate, m_xShift, m_yShift, m_zShift, m_dCentral, m_Detail;
+
+	void						Update_View				(void);
+	void						Update_Extent			(CSG_Rect Extent);
+
+	void						On_Size					(wxSizeEvent  &event);
+	void						On_Paint				(wxPaintEvent &event);
+	void						On_Mouse_LDown			(wxMouseEvent &event);
+	void						On_Mouse_LUp			(wxMouseEvent &event);
+	void						On_Mouse_RDown			(wxMouseEvent &event);
+	void						On_Mouse_RUp			(wxMouseEvent &event);
+	void						On_Mouse_MDown			(wxMouseEvent &event);
+	void						On_Mouse_MUp			(wxMouseEvent &event);
+	void						On_Mouse_Motion			(wxMouseEvent &event);
+	void						On_Mouse_Wheel			(wxMouseEvent &event);
+
+
+private:
+
+	bool						m_bColorAsRGB;
+
+	int							m_nSelection, *m_pSelection, m_Color_Mode, m_Size_Def;
+
+	double						m_xDown, m_yDown, m_cMin, m_cScale, m_Size_Scale;
+
+	double						r_sin_x, r_sin_y, r_sin_z, r_cos_x, r_cos_y, r_cos_z, r_xc, r_yc, r_zc, r_Scale, r_Scale_z;
+
+	CSG_Rect					m_Extent;
+
+	CSG_Matrix					m_Image_zMax;
+
+	CSG_Simple_Statistics		m_zStats, m_cStats;
+
+	CSG_Parameters				*m_pSettings;
+
+	CSG_Colors					*m_pColors;
+
+	CSG_PointCloud				*m_pPoints;
+
+	wxPoint						m_Mouse_Down;
+
+	wxImage						m_Image;
+
+
+	void						_Set_Size				(void);
+
+	bool						_Draw_Image				(void);
+	void						_Draw_Background		(void);
+	void						_Draw_Point				(int iPoint);
+	void						_Draw_Point				(int x, int y, double z, int color, int Size);
+	void						_Draw_Pixel				(int x, int y, double z, int color);
+
+	TSG_Point_3D				_Get_Projection			(TSG_Point_3D &p);
+
+
+	DECLARE_EVENT_TABLE()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__points_view_control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,261 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 points_view_dialog.cpp                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "points_view_control.h"
+#include "points_view_extent.h"
+#include "points_view_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CPoints_View_Dialog, CSGDI_Dialog)
+	EVT_MOUSEWHEEL	(CPoints_View_Dialog::On_Mouse_Wheel)
+	EVT_KEY_DOWN	(CPoints_View_Dialog::On_Key_Down)
+	EVT_BUTTON		(wxID_ANY	, CPoints_View_Dialog::On_Button)
+	EVT_CHECKBOX	(wxID_ANY	, CPoints_View_Dialog::On_Update_Control)
+	EVT_TEXT_ENTER	(wxID_ANY	, CPoints_View_Dialog::On_Update_Control)
+	EVT_SLIDER		(wxID_ANY	, CPoints_View_Dialog::On_Update_Control)
+	EVT_CHOICE		(wxID_ANY	, CPoints_View_Dialog::On_Update_Choices)
+END_EVENT_TABLE()
+
+//---------------------------------------------------------
+CPoints_View_Dialog::CPoints_View_Dialog(CSG_PointCloud *pPoints)
+	: CSGDI_Dialog(_TL("Point Cloud Viewer"), SGDI_DLG_STYLE_START_MAXIMISED)
+{
+	SetWindowStyle(wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE);
+
+	//-----------------------------------------------------
+	m_Settings.Create(NULL, _TL("Point Cloud Viewer Settings"), _TL(""));
+
+	m_pView		= new CPoints_View_Control	(this, pPoints, m_Settings);
+	m_pExtent	= new CPoints_View_Extent	(this, pPoints, m_Settings, wxSize(200, 200));
+
+	//-----------------------------------------------------
+	wxArrayString	Attributes;
+
+	for(int i=0; i<pPoints->Get_Field_Count(); i++)
+	{
+		Attributes.Add(pPoints->Get_Field_Name(i));
+	}
+
+	//-----------------------------------------------------
+	Add_Button(_TL("Close"), wxID_OK);
+
+	m_pBtn_Prop			= Add_Button	(_TL("Advanced Settings")	, wxID_ANY);
+
+	Add_Spacer();
+	m_pField_Z			= Add_Choice	(_TL("Z Attribute")			, Attributes, m_pView->m_zField);
+	m_pField_Color		= Add_Choice	(_TL("Color Attribute")		, Attributes, m_pView->m_cField);
+
+	Add_Spacer();
+	m_pCheck_Central	= Add_CheckBox	(_TL("Central Projection")	, m_pView->m_bCentral);
+	m_pCheck_Stereo		= Add_CheckBox	(_TL("Anaglyph")			, m_pView->m_bStereo);
+	m_pCheck_Scale		= Add_CheckBox	(_TL("Scale Point Size")	, m_pView->m_bScale);
+
+	Add_Spacer();
+	m_pSlide_xRotate	= Add_Slider	(_TL("X-Rotation")			, m_pView->m_xRotate * M_RAD_TO_DEG, -180.0, 180.0);
+	m_pSlide_yRotate	= Add_Slider	(_TL("Y-Rotation")			, m_pView->m_yRotate * M_RAD_TO_DEG, -180.0, 180.0);
+	m_pSlide_zRotate	= Add_Slider	(_TL("Z-Rotation")			, m_pView->m_zRotate * M_RAD_TO_DEG, -180.0, 180.0);
+
+	m_pSlide_Central	= Add_Slider	(_TL("Eye Distance")		, m_pView->m_dCentral, 1.0, 2000.0);
+
+	m_pSlide_Detail		= Add_Slider	(_TL("Level of Detail")		, m_pView->m_Detail, 0.0, 1.0);
+
+//	Add_Spacer();
+//	m_pParameters		= Add_TextCtrl	(_TL("Function Parameters"), wxTE_MULTILINE|wxTE_READONLY);
+
+	Add_Spacer();
+	Add_CustomCtrl(_TL("Extent"), m_pExtent);
+
+	Add_Output(m_pView);
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::On_Mouse_Wheel(wxMouseEvent &event)
+{
+	m_pView->On_Mouse_Wheel(event);
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::On_Key_Down(wxKeyEvent &event)
+{
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::On_Update_Control(wxCommandEvent &event)
+{
+	if( event.GetEventObject() == m_pCheck_Central )
+	{
+		m_pView->m_bCentral		= m_pCheck_Central	->GetValue() == 1 ? 1 : 0;
+	}
+	else if( event.GetEventObject() == m_pCheck_Stereo )
+	{	
+		m_pView->m_bStereo		= m_pCheck_Stereo	->GetValue() == 1 ? 1 : 0;
+	}
+	else if( event.GetEventObject() == m_pCheck_Scale )
+	{	
+		m_pView->m_bScale		= m_pCheck_Scale	->GetValue() == 1 ? 1 : 0;
+	}
+	else if( event.GetEventObject() == m_pSlide_xRotate )
+	{	
+		m_pView->m_xRotate		= m_pSlide_xRotate	->Get_Value() * M_DEG_TO_RAD;
+	}
+	else if( event.GetEventObject() == m_pSlide_yRotate )
+	{	
+		m_pView->m_yRotate		= m_pSlide_yRotate	->Get_Value() * M_DEG_TO_RAD;
+	}
+	else if( event.GetEventObject() == m_pSlide_zRotate )
+	{	
+		m_pView->m_zRotate		= m_pSlide_zRotate	->Get_Value() * M_DEG_TO_RAD;
+	}
+	else if( event.GetEventObject() == m_pSlide_Central )
+	{	
+		m_pView->m_dCentral		= m_pSlide_Central	->Get_Value();
+	}
+	else if( event.GetEventObject() == m_pSlide_Detail )
+	{	
+		m_pView->m_Detail		= m_pSlide_Detail	->Get_Value();
+	}
+	else
+	{
+		return;
+	}
+
+	m_pView->Update_View();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::On_Update_Choices(wxCommandEvent &event)
+{
+	if( event.GetEventObject() == m_pField_Z )
+	{
+		m_pView		->m_zField	= m_pField_Z	->GetSelection();
+
+		m_pView		->Update_View();
+	}
+
+	else if( event.GetEventObject() == m_pField_Color )
+	{
+		m_Settings("C_RANGE")->asRange()->Set_Range(0.0, 0.0);
+
+		m_pExtent	->m_cField	= m_pField_Color->GetSelection();
+		m_pView		->m_cField	= m_pField_Color->GetSelection();
+
+		m_pExtent	->Update_View();
+		m_pView		->Update_Extent(m_pExtent->Get_Extent());
+	}
+	else
+	{
+		return;
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::On_Button(wxCommandEvent &event)
+{
+	if( event.GetEventObject() == m_pBtn_Prop )
+	{
+		if( SG_UI_Dlg_Parameters(&m_Settings, m_Settings.Get_Name()) )
+		{
+			m_pExtent	->Update_View();
+			m_pView		->Update_View();
+		}
+	}
+	else
+	{
+		event.Skip();
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::Update_Extent(void)
+{
+	m_pView->Update_Extent(m_pExtent->Get_Extent());
+}
+
+//---------------------------------------------------------
+void CPoints_View_Dialog::Update_Rotation(void)
+{
+	double	d;
+
+	d	= fmod(M_RAD_TO_DEG * m_pView->m_xRotate, 360.0);	if( d < -180.0 )	d	+= 360.0;	else if( d > 180.0 )	d	-= 360.0;
+	m_pSlide_xRotate->Set_Value(d);
+
+	d	= fmod(M_RAD_TO_DEG * m_pView->m_yRotate, 360.0);	if( d < -180.0 )	d	+= 360.0;	else if( d > 180.0 )	d	-= 360.0;
+	m_pSlide_yRotate->Set_Value(d);
+
+	d	= fmod(M_RAD_TO_DEG * m_pView->m_zRotate, 360.0);	if( d < -180.0 )	d	+= 360.0;	else if( d > 180.0 )	d	-= 360.0;
+	m_pSlide_zRotate->Set_Value(d);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_dialog.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 points_view_dialog.h                  //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__points_view_dialog_H
+#define HEADER_INCLUDED__points_view_dialog_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_gdi/saga_gdi.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPoints_View_Dialog : public CSGDI_Dialog
+{
+public:
+	CPoints_View_Dialog(CSG_PointCloud *pPoints);
+
+	void						Update_Rotation			(void);
+	void						Update_Extent			(void);
+
+
+private:
+
+	wxButton					*m_pBtn_Prop;
+
+	wxCheckBox					*m_pCheck_Central, *m_pCheck_Stereo, *m_pCheck_Scale;
+
+	wxChoice					*m_pField_Color, *m_pField_Z;
+
+	wxTextCtrl					*m_pFormula, *m_pParameters;
+
+	CSGDI_Slider				*m_pSlide_xRotate, *m_pSlide_yRotate, *m_pSlide_zRotate, *m_pSlide_Central, *m_pSlide_Detail;
+
+	class CPoints_View_Control	*m_pView;
+
+	class CPoints_View_Extent	*m_pExtent;
+
+	CSG_Parameters				m_Settings;
+
+
+	void						On_Update_Control		(wxCommandEvent &event);
+	void						On_Update_Choices		(wxCommandEvent &event);
+	void						On_Button				(wxCommandEvent &event);
+
+	void						On_Mouse_Wheel			(wxMouseEvent   &event);
+	void						On_Key_Down				(wxKeyEvent     &event);
+
+
+	DECLARE_EVENT_TABLE()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__points_view_dialog_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,413 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     SAGA_GUI_API                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 points_view_extent.cpp                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#include <wx/settings.h>
+#include <wx/dc.h>
+#include <wx/dcclient.h>
+
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#include "points_view_extent.h"
+#include "points_view_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define m_Settings	(*m_pSettings)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CPoints_View_Extent, wxPanel)
+	EVT_SIZE				(CPoints_View_Extent::On_Size)
+	EVT_ERASE_BACKGROUND	(CPoints_View_Extent::On_EraseBackGround)
+	EVT_PAINT				(CPoints_View_Extent::On_Paint)
+	EVT_LEFT_DOWN			(CPoints_View_Extent::On_Mouse_LDown)
+	EVT_LEFT_UP				(CPoints_View_Extent::On_Mouse_LUp)
+	EVT_RIGHT_DOWN			(CPoints_View_Extent::On_Mouse_RDown)
+	EVT_RIGHT_UP			(CPoints_View_Extent::On_Mouse_RUp)
+	EVT_MOTION				(CPoints_View_Extent::On_Mouse_Motion)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPoints_View_Extent::CPoints_View_Extent(wxWindow *pParent, CSG_PointCloud *pPoints, CSG_Parameters &Settings, wxSize Size)
+	: wxPanel(pParent, wxID_ANY, wxDefaultPosition, Size, wxTAB_TRAVERSAL|wxSUNKEN_BORDER|wxNO_FULL_REPAINT_ON_RESIZE)
+{
+	m_pPoints	= pPoints;
+
+	m_pSettings	= &Settings;
+
+	m_cField	= 2;
+
+	m_Select	= wxRect(0, 0, GetClientSize().x - 1, GetClientSize().y - 1);
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode	= m_pSettings->Add_Node(NULL, "NODE_EXTENT", _TL("Zoom View"), _TL(""));
+
+	m_pSettings->Add_Range(
+		pNode	, "EXT_C_RANGE"		, _TL("Colors Value Range"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	_Draw_Image();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Size(wxSizeEvent &event)
+{
+	_Draw_Image();
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_EraseBackGround(wxEraseEvent &event)
+{
+//	event.Skip();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Paint(wxPaintEvent &WXUNUSED(event))
+{
+	if( m_Image.IsOk() && m_Image.GetWidth() > 0 && m_Image.GetHeight() > 0 )
+	{
+		wxPaintDC	dc(this);
+
+		dc.DrawBitmap(wxBitmap(m_Image), 0, 0, false);
+
+		dc.SetPen(wxPen(*wxRED));
+
+		int		ax	= m_Select.GetX();
+		int		ay	= m_Select.GetY();
+		int		bx	= m_Select.GetX() + m_Select.GetWidth();
+		int		by	= m_Select.GetY() + m_Select.GetHeight();
+
+		dc.DrawLine(ax, ay, bx, ay);
+		dc.DrawLine(bx, ay, bx, by);
+		dc.DrawLine(bx, by, ax, by);
+		dc.DrawLine(ax, by, ax, ay);
+	}
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::Update_View(void)
+{
+	if( _Draw_Image() )
+	{
+		Refresh(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Mouse_LDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+
+	CaptureMouse();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Mouse_LUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	_Draw_Inverse(m_Mouse_Down, m_Mouse_Move);
+
+	wxPoint	p;
+
+	p.x	= event.GetX() < 0 ? 0 : event.GetX() >= GetClientSize().x ? GetClientSize().x - 1 : event.GetX();
+	p.y	= event.GetY() < 0 ? 0 : event.GetY() >= GetClientSize().y ? GetClientSize().y - 1 : event.GetY();
+
+	if( m_Mouse_Down.x != p.x || m_Mouse_Down.y != p.y )
+	{
+		m_Select	= wxRect(wxPoint(m_Mouse_Down.x, m_Mouse_Down.y), p);
+	}
+	else
+	{
+		m_Select.SetX(p.x - m_Select.GetWidth () / 2);
+		m_Select.SetY(p.y - m_Select.GetHeight() / 2);
+	}
+
+	Refresh(false);
+
+	((CPoints_View_Dialog *)GetParent())->Update_Extent();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Mouse_RDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+
+	CaptureMouse();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Mouse_RUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	m_Select	= wxRect(0, 0, GetClientSize().x - 1, GetClientSize().y - 1);
+
+	Refresh(false);
+
+	((CPoints_View_Dialog *)GetParent())->Update_Extent();
+}
+
+//---------------------------------------------------------
+void CPoints_View_Extent::On_Mouse_Motion(wxMouseEvent &event)
+{
+	if( HasCapture() && event.Dragging() )
+	{
+		if( event.LeftIsDown() )
+		{
+			_Draw_Inverse(m_Mouse_Down, m_Mouse_Move);
+			_Draw_Inverse(m_Mouse_Down, event.GetPosition());
+		}
+	}
+
+	m_Mouse_Move	= event.GetPosition();
+}
+
+//---------------------------------------------------------
+TSG_Rect CPoints_View_Extent::Get_Extent(void)
+{
+	TSG_Rect	r;
+
+	double	d	= m_Extent.Get_XRange() / m_Image.GetWidth();
+
+	r.xMin	= m_Extent.Get_XMin() + d *  m_Select.GetX();
+	r.xMax	= m_Extent.Get_XMin() + d * (m_Select.GetX() + m_Select.GetWidth());
+
+	r.yMax	= m_Extent.Get_YMax() - d *  m_Select.GetY();
+	r.yMin	= m_Extent.Get_YMax() - d * (m_Select.GetY() + m_Select.GetHeight());
+
+	return( r );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPoints_View_Extent::_Draw_Image(void)
+{
+	if( m_pPoints->Get_Count() <= 0 || m_pPoints->Get_Extent().Get_XRange() <= 0.0 || m_pPoints->Get_Extent().Get_YRange() <= 0.0
+	||	m_cField < 0 || m_cField >= m_pPoints->Get_Field_Count() )
+	{
+		return( false );
+	}
+
+	//-------------------------------------------------
+	wxSize		Size;
+	double		dx, dy;
+
+	Size		= GetClientSize();
+
+	m_Image			.Create(Size.x, Size.y);
+	m_Image_Value	.Create(Size.x, Size.y);
+	m_Image_Count	.Create(Size.x, Size.y);
+
+	//-------------------------------------------------
+	m_Extent	= m_pPoints->Get_Extent();
+
+	if( (dx = Size.y / (double)Size.x) < (m_Extent.Get_YRange() / m_Extent.Get_XRange()) )
+	{
+		dx	= 0.5 * (m_Extent.Get_XRange() - m_Extent.Get_YRange() / dx);
+		m_Extent.m_rect.xMin	+= dx;
+		m_Extent.m_rect.xMax	-= dx;
+	}
+	else
+	{
+		dy	= 0.5 * (m_Extent.Get_YRange() - m_Extent.Get_XRange() * dx);
+		m_Extent.m_rect.yMin	+= dy;
+		m_Extent.m_rect.yMax	-= dy;
+	}
+
+	dx	= Size.x / m_Extent.Get_XRange();
+	dy	= Size.y / m_Extent.Get_YRange();
+
+	//-------------------------------------------------
+	for(int i=0; i<m_pPoints->Get_Count(); i++)
+	{
+		TSG_Point_3D	p	= m_pPoints->Get_Point(i);	p.z	= m_pPoints->Get_Value(i, m_cField);
+
+		int	ix	= (p.x - m_Extent.Get_XMin()) * dx;
+		int	iy	= (p.y - m_Extent.Get_YMin()) * dy;
+
+		if( ix >= 0 && ix <= m_Image.GetWidth() && iy >= 0 && iy < m_Image.GetHeight() )
+		{
+			m_Image_Value[iy][ix]	+= p.z;
+			m_Image_Count[iy][ix]	++;
+		}
+	}
+
+	//-------------------------------------------------
+	double	zMin	= m_pPoints->Get_Mean(m_cField) - 1.5 * m_pPoints->Get_StdDev(m_cField);
+	double	zRange	= m_pPoints->Get_Mean(m_cField) + 1.5 * m_pPoints->Get_StdDev(m_cField) - zMin;
+
+	CSG_Colors	*pColors	= m_Settings("COLORS")->asColors();
+
+	for(int iy=0; iy<m_Image.GetHeight(); iy++)
+	{
+		for(int ix=0; ix<m_Image.GetWidth(); ix++)
+		{
+			if( m_Image_Count[iy][ix] > 0 )
+			{
+				int	ic	= (int)(pColors->Get_Count() * (m_Image_Value[iy][ix] / m_Image_Count[iy][ix] - zMin) / zRange);
+				int	c	= pColors->Get_Color(ic < 0 ? 0 : ic >= pColors->Get_Count() ? pColors->Get_Count() - 1 : ic);
+
+				_Draw_Pixel(ix, iy, c);
+			}
+			else
+			{
+				_Draw_Pixel(ix, iy, 0);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CPoints_View_Extent::_Draw_Pixel(int x, int y, int color)
+{
+	if( x >= 0 && x < m_Image.GetWidth() && y >= 0 && y < m_Image.GetHeight() )
+	{
+		BYTE	*pRGB	= m_Image.GetData() + 3 * ((m_Image.GetHeight() - y - 1) * m_Image.GetWidth() + x);
+		*pRGB	= SG_GET_R(color);	pRGB++;
+		*pRGB	= SG_GET_G(color);	pRGB++;
+		*pRGB	= SG_GET_B(color);
+	}
+}
+
+
+//---------------------------------------------------------
+void CPoints_View_Extent::_Draw_Inverse(wxPoint pa, wxPoint pb)
+{
+	wxClientDC	dc(this);
+
+	dc.SetLogicalFunction(wxINVERT);
+
+	dc.DrawRectangle(pa.x, pa.y, pb.x - pa.x, pb.y - pa.y);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_extent.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,146 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     SAGA_GUI_API                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  points_view_extent.h                 //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__points_view_extent_H
+#define HEADER_INCLUDED__points_view_extent_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_gdi/saga_gdi.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPoints_View_Extent : public wxPanel
+{
+public:
+	CPoints_View_Extent(wxWindow *pParent, CSG_PointCloud *pPoints, CSG_Parameters &Settings, wxSize Size);
+
+	int							m_cField;
+
+	void						Update_View				(void);
+
+	void						On_Size					(wxSizeEvent  &event);
+	void						On_EraseBackGround		(wxEraseEvent &event);
+	void						On_Paint				(wxPaintEvent &event);
+	void						On_Mouse_LDown			(wxMouseEvent &event);
+	void						On_Mouse_LUp			(wxMouseEvent &event);
+	void						On_Mouse_RDown			(wxMouseEvent &event);
+	void						On_Mouse_RUp			(wxMouseEvent &event);
+	void						On_Mouse_Motion			(wxMouseEvent &event);
+
+	TSG_Rect					Get_Extent				(void);
+
+
+private:
+
+	CSG_Rect					m_Extent;
+
+	CSG_Matrix					m_Image_Value, m_Image_Count;
+
+	CSG_PointCloud				*m_pPoints;
+
+	CSG_Parameters				*m_pSettings;
+
+	wxPoint						m_Mouse_Down, m_Mouse_Move;
+
+	wxRect						m_Select;
+
+	wxImage						m_Image;
+
+
+	bool						_Draw_Image				(void);
+	void						_Draw_Pixel				(int x, int y, int color);
+	void						_Draw_Inverse			(wxPoint pa, wxPoint pb);
+
+
+	DECLARE_EVENT_TABLE()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__points_view_extent_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  points_view_module                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 points_view_module.cpp                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute for Geography                //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "points_view_module.h"
+
+#include "points_view_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPoints_View_Module::CPoints_View_Module(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud Viewer"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"This module is a 3D viewer for SAGA Point Clouds. Amongst others, "
+		"the viewer supports attribute based coloring, a map view to control "
+		"the area-of-interest, point size scaling based on distance, level "
+		"of detail control and an anaglyph modus (to use with red/blue or "
+		"red/green glasses).\n\n"
+		"Module development was supported by "
+		"<a href=\"http://www.laserdata.at\">http://Laserdata GmbH, Austria</a>\n"
+		"and "
+		"<a href=\"http://www.alp-s.at\">http://alpS GmbH, Austria</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPoints_View_Module::On_Execute(void)
+{
+	CSG_PointCloud	*pPoints	= Parameters("POINTS")->asPointCloud();
+
+	if( SG_UI_Get_Window_Main() )
+	{
+		CPoints_View_Dialog	dlg(pPoints);
+
+	//	return( dlg.ShowModal() == wxID_OK );
+
+		dlg.ShowModal();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/pointcloud/pointcloud_viewer/points_view_module.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  points_view_module                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 points_view_module.h                  //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__points_view_module_H
+#define HEADER_INCLUDED__points_view_module_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPoints_View_Module : public CSG_Module  
+{
+public:
+	CPoints_View_Module(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__points_view_module_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,435 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Classes_To_Shapes.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Classes_To_Shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Classes_To_Shapes::CGrid_Classes_To_Shapes(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Vectorising Grid Classes"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Vectorising grid classes."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "CLASS_ALL"	, _TL("Class Selection"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("one single class specified by class identifier"),
+			_TL("all classes")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CLASS_ID"	, _TL("Class Identifier"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SPLIT"		, _TL("Vectorised class as..."),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("one single (multi-)polygon object"),
+			_TL("each island as separated polygon")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Classes_To_Shapes::~CGrid_Classes_To_Shapes(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classes_To_Shapes::On_Execute(void)
+{
+	bool			bSplit, bAll;
+	double			Class_ID, Value;
+	CSG_String		ID;
+	CSG_Parameters	gParms, sParms;
+	CSG_Shapes		*pShapes, Shapes(SHAPE_TYPE_Polygon);
+
+	//-----------------------------------------------------
+	m_pGrid		= Parameters("GRID")		->asGrid();
+	pShapes		= Parameters("SHAPES")		->asShapes();
+	bSplit		= Parameters("SPLIT")		->asInt() == 1;
+	bAll		= Parameters("CLASS_ALL")	->asInt() == 1;
+	Class_ID	= Parameters("CLASS_ID")	->asDouble();
+
+	//-----------------------------------------------------
+	pShapes->Create(SHAPE_TYPE_Polygon);
+	pShapes->Add_Field(m_pGrid->Get_Name()	, SG_DATATYPE_Double);
+	pShapes->Add_Field(_TL("ID")			, SG_DATATYPE_Int);
+	pShapes->Add_Field(_TL("Name")			, SG_DATATYPE_String);
+
+	if(	DataObject_Get_Parameters(m_pGrid, gParms) && gParms("COLORS_TYPE") && gParms("LUT")
+	&&	DataObject_Get_Parameters(pShapes, sParms) && sParms("COLORS_TYPE") && sParms("LUT") && sParms("COLORS_ATTRIB") )
+	{
+		sParms("LUT")->asTable()->Assign_Values(gParms("LUT")->asTable());	// Lookup Table
+		sParms("COLORS_TYPE")->Set_Value(gParms("COLORS_TYPE")->asInt());	// Color Classification Type: Lookup Table
+		sParms("COLORS_ATTRIB")->Set_Value(1);								// Color Attribute
+		DataObject_Set_Parameters(pShapes, sParms);
+	}
+
+	pShapes->Set_Name(m_pGrid->Get_Name());
+
+	//-----------------------------------------------------
+	m_pShape	= NULL;
+
+	Lock_Create();
+
+	m_Edge.Create(SG_DATATYPE_Char, 2 * Get_NX() + 1, 2 * Get_NY() + 1, 0.5 * Get_Cellsize(), Get_XMin() - 0.5 * Get_Cellsize(), Get_YMin() - 0.5 * Get_Cellsize());
+
+	for(int y=0, nClasses=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( !m_pGrid->is_NoData(x, y) && !Lock_Get(x, y) && (Class_ID == (Value = m_pGrid->asDouble(x, y)) || bAll) )
+			{
+				ID		= CSG_String::Format(SG_T("%d"), ++nClasses);
+
+				if( bSplit )
+				{
+					if( m_pShape == NULL )
+						m_pShape	= Shapes.Add_Shape();
+
+					m_pShape->Del_Parts();
+				}
+				else
+				{
+					m_pShape	= pShapes->Add_Shape();
+					m_pShape->Set_Value(0, Value);
+					m_pShape->Set_Value(1, pShapes->Get_Count());
+					m_pShape->Set_Value(2, ID);
+				}
+
+				//-----------------------------------------
+				Process_Set_Text(CSG_String::Format(SG_T("%s %d: %f"), _TL("vectorising class"), nClasses, Value));
+
+				Get_Class(Value);
+
+				//-----------------------------------------
+				if( bSplit )
+				{
+					Split_Polygons(pShapes, Value, ID);
+				}
+			}
+		}
+	}
+
+	Lock_Destroy();
+
+	m_Edge.Destroy();
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classes_To_Shapes::Split_Polygons(CSG_Shapes *pShapes, double Value, const CSG_String &ID)
+{
+	if( m_pShape && m_pShape->Get_Part_Count() > 0 )
+	{
+		int			iPart, iPoint, jPart, iShape;
+		CSG_Shape	*pShape;
+
+		for(iPart=0; iPart<m_pShape->Get_Part_Count() && Set_Progress(iPart, m_pShape->Get_Part_Count()); iPart++)
+		{
+			if( ((CSG_Shape_Polygon *)m_pShape)->is_Clockwise(iPart) == true )	// No Lake
+			{
+				pShape	= pShapes->Add_Shape();
+				pShape->Set_Value(0, Value);
+				pShape->Set_Value(1, pShapes->Get_Count());
+				pShape->Set_Value(2, ID);
+
+				for(iPoint=0; iPoint<m_pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					pShape->Add_Point(m_pShape->Get_Point(iPoint, iPart), 0);
+				}
+			}
+		}
+
+		for(iPart=0; iPart<m_pShape->Get_Part_Count() && Set_Progress(iPart, m_pShape->Get_Part_Count()); iPart++)
+		{
+			if( ((CSG_Shape_Polygon *)m_pShape)->is_Clockwise(iPart) == false )	// Lake
+			{
+				TSG_Point	p	= m_pShape->Get_Point(0, iPart);
+
+				for(iShape=0, jPart=0; jPart==0 && iShape<pShapes->Get_Count(); iShape++)
+				{
+					pShape	= pShapes->Get_Shape(iShape);
+
+					if( pShape->asDouble(0) == Value && ((CSG_Shape_Polygon *)pShape)->is_Containing(p, 0) )
+					{
+						jPart	= pShape->Get_Part_Count();
+
+						for(iPoint=0; iPoint<m_pShape->Get_Point_Count(iPart); iPoint++)
+						{
+							pShape->Add_Point(m_pShape->Get_Point(iPoint, iPart), jPart);
+						}
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classes_To_Shapes::Get_Class(double Value)
+{
+	int		x, y, i, ix, iy, n, nEdgeCells;
+
+	//-----------------------------------------------------
+	for(y=0, nEdgeCells=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !Lock_Get(x, y) && m_pGrid->asDouble(x, y) == Value )
+			{
+				Lock_Set(x, y);
+
+				for(i=0, n=0; i<8; i+=2)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( !m_pGrid->is_InGrid(ix, iy) || m_pGrid->asDouble(ix, iy) != Value )
+					{
+						ix	= Get_xTo(i    , 1 + 2 * x);
+						iy	= Get_yTo(i    , 1 + 2 * y);
+						m_Edge.Set_Value(ix, iy, i + 2);
+
+						ix	= Get_xTo(i - 1, 1 + 2 * x);
+						iy	= Get_yTo(i - 1, 1 + 2 * y);
+						m_Edge.Set_Value(ix, iy, m_Edge.asInt(ix, iy) ? -1 : i + 2);
+
+						n++;
+					}
+				}
+
+				//-----------------------------------------
+				if( n == 4 )
+				{
+					Get_Square(1 + 2 * x, 1 + 2 * y);
+				}
+				else
+				{
+					nEdgeCells++;
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( nEdgeCells > 0 )
+	{
+		Get_Polygons();
+	}
+
+	return( m_pShape->Get_Part_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_Classes_To_Shapes::Get_Square(int x, int y)
+{
+	int		i, ix, iy, iPart;
+
+	iPart	= m_pShape->Get_Part_Count();
+
+	for(i=0; i<8; i++)
+	{
+		ix	= Get_xTo(i, x);
+		iy	= Get_yTo(i, y);
+
+		m_Edge.Set_Value(ix, iy, m_Edge.asInt(ix, iy) > 0 ? 0 : (i > 1 ? i - 1 : i + 7));
+
+		if( i % 2 )
+		{
+			m_pShape->Add_Point(m_Edge.Get_System().Get_Grid_to_World(ix, iy), iPart);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Classes_To_Shapes::Get_Polygons(void)
+{
+	if( m_pShape )
+	{
+		for(int y=0; y<m_Edge.Get_NY() && Set_Progress(y, m_Edge.Get_NY()); y++)
+		{
+			for(int x=0; x<m_Edge.Get_NX(); x++)
+			{
+				if( m_Edge.asInt(x, y) > 0 )
+				{
+					Get_Polygon(x, y, m_pShape->Get_Part_Count());
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CGrid_Classes_To_Shapes::Get_Polygon(int x, int y, int iPart)
+{
+	int		i, iLast;
+
+	iLast	= -1;
+
+	while( (i = m_Edge.asInt(x, y)) != 0 )
+	{
+		if( i < 0 )
+		{
+			i	= iLast + 2;
+
+			m_Edge.Set_Value(x, y, (iLast == 2 ? 8 : iLast - 2));
+		}
+		else
+		{
+			m_Edge.Set_Value(x, y, 0);
+		}
+
+		if( i != iLast )
+		{
+			m_pShape->Add_Point(m_Edge.Get_System().Get_Grid_to_World(x, y), iPart);
+
+			iLast	= i;
+		}
+
+		x	= Get_xTo(i, x);
+		y	= Get_yTo(i, y);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Classes_To_Shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Classes_To_Shapes.h               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Classes_To_Shapes_H
+#define HEADER_INCLUDED__Grid_Classes_To_Shapes_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Classes_To_Shapes : public CSG_Module_Grid  
+{
+public:
+	CGrid_Classes_To_Shapes(void);
+	virtual ~CGrid_Classes_To_Shapes(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid				*m_pGrid, m_Edge;
+
+	CSG_Shape				*m_pShape;
+
+
+	bool					Split_Polygons	(CSG_Shapes *pShapes, double Value, const CSG_String &ID);
+
+	bool					Get_Class		(double Value);
+
+	void					Get_Square		(int x, int y);
+
+	bool					Get_Polygons	(void);
+	void					Get_Polygon		(int x, int y, int iPart);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Classes_To_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,344 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Polygon_Clip.cpp                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                     Stefan Liersch                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     stefan.liersch at ufz.de                  //
+//                stliersch at freenet.de                   //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Polygon_Clip.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MASK_OFF	-1
+#define MASK_ON		 1
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// constructor
+//---------------------------------------------------------
+CGrid_Polygon_Clip::CGrid_Polygon_Clip(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+	Set_Name		(_TL("Clip Grid with Polygon"));
+
+	Set_Author		(_TL("copyrights (c) 2006 Stefan Liersch"));
+
+	Set_Description	(_TW(
+		"Clips the input grid with a polygon shapefile. Select "
+        "polygons from the shapefile prior to module execution "
+        "in case you like to use only a subset from the shapefile "
+        "for clipping."
+	));
+
+	//-----------------------------------------------------
+	// Parameters list...
+
+	Parameters.Add_Grid_List(
+		NULL, "OUTPUT"		, _TL("Output"),
+		_TL(""),
+		PARAMETER_OUTPUT, false
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "INPUT"		, _TL("Input"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// This function is executed if the user is pressing the OK button
+//---------------------------------------------------------
+bool CGrid_Polygon_Clip::On_Execute(void)
+{
+	int						x, y, ix, iy, ax, ay, nx, ny;
+	CSG_Parameter_Grid_List	*pGrids_in, *pGrids_out;
+	CSG_Grid				*pGrid_in, *pGrid_out, Mask;
+	CSG_Shapes				*pShapes;
+
+	//-----------------------------------------------------
+	pGrids_in	= Parameters("INPUT")	->asGridList();
+	pGrids_out	= Parameters("OUTPUT")	->asGridList();
+	pShapes		= Parameters("POLYGONS")->asShapes();
+
+	//-----------------------------------------------------
+	if(	pShapes->Get_Type() == SHAPE_TYPE_Polygon && pShapes->Get_Count() > 0
+	&&	Get_System()->Get_Extent().Intersects(pShapes->Get_Extent()) )
+	{
+		// create temporary grid.
+		// Cells within the shapefile get the value +1
+		// Cells outside the shapefile get the value -1
+		Mask.Create(*Get_System(), SG_DATATYPE_Byte);
+
+		//-------------------------------------------------
+		// Get_Mask assignes +1 values to gridcells within the shapefile
+		// The function has been copied from Module: 'Grid_Statistics_AddTo_Polygon'
+		// Function: Get_ShapeIDs(...)
+		// and check extent of valid values in Mask to 
+		// calculate GridSystem parameters pGrid_out	
+		if( Get_Mask(pShapes, &Mask) && Get_Extent(ax, nx, ay, ny, &Mask) )
+		{
+			for(int iGrid=0; iGrid<pGrids_in->Get_Count(); iGrid++)
+			{
+				pGrid_in	= pGrids_in->asGrid(iGrid);
+				pGrid_out	= SG_Create_Grid(					// creating the output grid GridSystem
+					pGrid_in->Get_Type(), nx, ny, Get_Cellsize(),
+					Get_XMin() + ax * Get_Cellsize(),
+					Get_YMin() + ay * Get_Cellsize()
+				);
+
+				pGrid_out->Set_Name(pGrid_in->Get_Name());
+				pGrids_out->Add_Item(pGrid_out);
+
+				// Assign valid values from input grid to the cells of the
+				// output grid that are within the borders of the shapefile
+				// Assign NoData values to the cells outside the shapefile borders
+				for(y=0, iy=ay; y<ny && Set_Progress(y, ny); y++, iy++)
+				{
+					for(x=0, ix=ax; x<nx; x++, ix++)
+					{
+						if( Mask.asDouble(ix, iy) == MASK_ON )	// -1 = NoData_Value
+						{
+							pGrid_out->Set_Value(x, y, pGrid_in->asDouble(ix, iy));
+						}
+						else
+						{
+							pGrid_out->Set_NoData(x, y);
+						}
+					}
+				}
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+///////////////////////////////////////////////////////////
+//---------------------------------------------------------
+// This function modifies the incoming integer variables!!!
+//---------------------------------------------------------
+bool CGrid_Polygon_Clip::Get_Extent(int &xMin, int &xMax, int &yMin, int &yMax, CSG_Grid *pMask)
+{
+	int		x, y;
+
+	for(y=0, yMin=-1; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pMask->asInt(x, y) == MASK_ON )
+			{
+				if( yMin < 0 )
+				{
+					yMin	= yMax	= y;
+					xMin	= xMax	= x;
+				}
+				else
+				{
+					yMax	= y;
+
+					if( xMin > x )
+					{
+						xMin	= x;
+					}
+					else if( xMax < x )
+					{
+						xMax	= x;
+					}
+				}
+			}
+		}
+	}
+
+	if( yMin >= 0 )
+	{
+		xMax	-= xMin - 1;
+		yMax	-= yMin - 1;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+///////////////////////////////////////////////////////////
+//---------------------------------------------------------
+// This function has been copied from Module: 'Grid_Statistics_AddTo_Polygon'
+// Function: Get_ShapeIDs(...)
+// copyright by Olaf Conrad
+//
+// added support to clip only with selected polygons (Volker Wichmann)
+//---------------------------------------------------------
+bool CGrid_Polygon_Clip::Get_Mask(CSG_Shapes *pShapes, CSG_Grid *pMask)
+{
+	bool		bFill, *bCrossing;
+    bool        bOnlySelected = false;
+	int			x, y, ix, xStart, xStop, iShape, iPart, iPoint;
+	double		yPos;
+	TSG_Point	pLeft, pRight, pa, pb, p;
+	TSG_Rect	Extent;
+	CSG_Shape	*pShape;
+
+	//-----------------------------------------------------
+	pMask->Assign(MASK_OFF);
+
+	bCrossing	= (bool *)SG_Malloc(pMask->Get_NX() * sizeof(bool));
+
+    if (pShapes->Get_Selection_Count() > 0)
+        bOnlySelected = true;
+
+	//-----------------------------------------------------
+	for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+	{
+        if (bOnlySelected && !pShapes->Get_Shape(iShape)->is_Selected())
+            continue;
+
+		pShape		= pShapes->Get_Shape(iShape);
+		Extent		= pShape->Get_Extent().m_rect;
+
+		xStart		= Get_System()->Get_xWorld_to_Grid(Extent.xMin) - 1;	if( xStart < 0 )		xStart	= 0;
+		xStop		= Get_System()->Get_xWorld_to_Grid(Extent.xMax) + 1;	if( xStop >= Get_NX() )	xStop	= Get_NX() - 1;
+
+		pLeft.x		= pMask->Get_XMin() - 1.0;
+		pRight.x	= pMask->Get_XMax() + 1.0;
+
+
+		//-------------------------------------------------
+		for(y=0, yPos=pMask->Get_YMin(); y<pMask->Get_NY(); y++, yPos+=pMask->Get_Cellsize())
+		{
+			if( yPos >= Extent.yMin && yPos <= Extent.yMax )
+			{
+				memset(bCrossing, 0, pMask->Get_NX() * sizeof(bool));
+
+				pLeft.y	= pRight.y	= yPos;
+
+				//-----------------------------------------
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					pb		= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						pa	= pb;
+						pb	= pShape->Get_Point(iPoint, iPart);
+
+						if(	(	(pa.y <= yPos && yPos < pb.y)
+							||	(pa.y > yPos && yPos >= pb.y)	)	)
+						{
+							SG_Get_Crossing(p, pa, pb, pLeft, pRight, false);
+
+							ix	= (int)((p.x - pMask->Get_XMin()) / pMask->Get_Cellsize() + 1.0);
+
+							if( ix < 0)
+							{
+								ix	= 0;
+							}
+							else if( ix >= pMask->Get_NX() )
+							{
+								ix	= pMask->Get_NX() - 1;
+							}
+
+							bCrossing[ix]	= !bCrossing[ix];
+						}
+					}
+				}
+
+				//-----------------------------------------
+				for(x=xStart, bFill=false; x<=xStop; x++)
+				{
+					if( bCrossing[x] )
+					{
+						bFill	= !bFill;
+					}
+
+					if( bFill )
+					{
+						pMask->Set_Value(x, y, MASK_ON);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(bCrossing);
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Polygon_Clip.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Polygon_Clip.h                  //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                     Stefan Liersch                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     stefan.liersch at ufz.de                  //
+//                stliersch at freenet.de                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Polygon_Clip_H
+#define HEADER_INCLUDED__Grid_Polygon_Clip_H
+
+//---------------------------------------------------------
+
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Polygon_Clip : public CSG_Module_Grid
+{
+public:
+	// constructor
+	CGrid_Polygon_Clip(void);
+
+protected:
+	// execute module
+	virtual bool		On_Execute		(void);
+
+private:
+
+	// estimates the Extent of the new grid
+	bool				Get_Extent		(int &xMin, int &xCount,
+										 int &yMin, int &yCount, CSG_Grid *pMask);
+
+	// This function has been copied from Module: 'Grid_Statistics_AddTo_Polygon'
+	// Function: Get_ShapeIDs
+	// copyright by Olaf Conrad
+	bool				Get_Mask		(CSG_Shapes *pShapes, CSG_Grid *pMask);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Polygon_Clip_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,365 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//            Grid_Statistics_AddTo_Polygon.cpp          //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//                 quantile calculation:                 //
+//                 Copyright (C) 2007 by                 //
+//                   Johan Van de Wauw                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+#include <vector>
+#include <list>
+
+#include "Grid_Statistics_AddTo_Polygon.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Statistics_AddTo_Polygon::CGrid_Statistics_AddTo_Polygon(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Grid Statistics for Polygons"));
+
+	Set_Author		(SG_T("(c) 2003 by Olaf Conrad, Quantile Calculation (c) 2007 by Johan Van de Wauw"));
+
+	Set_Description	(_TW(
+		"For each polygon statistics of the contained grid values will be generated."
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "POLY"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "RESULT"	, _TL("Result"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Value(
+		NULL, "QUANTILES", _TL("Quantiles"), 
+		_TL("Calculate distribution Quantiles"),
+		PARAMETER_TYPE_Bool, 0.0
+	);
+
+	Parameters.Add_Choice(
+		NULL, "QUANTILE_STEP", _TL("Quantile Step"),
+		_TL("Choose which quantiles you would like to calculate"),
+		_TL("median|quartiles|deciles|5% interval|"),
+		1
+	);
+}
+//---------------------------------------------------------
+CGrid_Statistics_AddTo_Polygon::~CGrid_Statistics_AddTo_Polygon(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Statistics_AddTo_Polygon::On_Execute(void)
+{
+	bool				bQuantiles;
+	int					x, y, iShape, nShapes, *Num,
+						field_CELLS, field_MEAN, field_VARI, field_QUANTILES, quantile_step;
+	double				*Sum, *Dif, d;
+	CSG_Table_Record	*pRecord;
+	CSG_Grid			*pGrid, ShapeIDs;
+	CSG_Shapes			*pShapes;
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("POLY")		->asShapes();
+	pGrid		= Parameters("GRID")		->asGrid();
+	bQuantiles	= Parameters("QUANTILES")	->asBool();
+
+	switch(Parameters("QUANTILE_STEP")->asInt())
+	{
+	case 0:				quantile_step	= 50;	break;
+	case 1:				quantile_step	= 25;	break;
+	case 2:				quantile_step	= 10;	break;
+	case 3: default:	quantile_step	= 5;	break;
+	}
+
+	//-----------------------------------------------------
+	if(	pShapes->Get_Type() == SHAPE_TYPE_Polygon && pShapes->Get_Count() > 0
+	&&	pGrid->is_Intersecting(pShapes->Get_Extent()) )
+	{
+		ShapeIDs.Create(pGrid, SG_DATATYPE_Int);
+		ShapeIDs.Assign(-1.0);
+
+		//-------------------------------------------------
+		if( Get_ShapeIDs(pShapes, &ShapeIDs) )
+		{
+			nShapes	= pShapes->Get_Count();
+
+			Num		= (int    *)calloc(nShapes, sizeof(int   ));
+			Sum		= (double *)calloc(nShapes, sizeof(double));
+			Dif		= (double *)calloc(nShapes, sizeof(double));
+
+			std::vector<std::list<double> >ShapePixels(nShapes);
+
+			//---------------------------------------------
+			for(y=0; y<Get_NY() && Set_Progress(y); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					if( !pGrid->is_NoData(x, y) && (iShape = ShapeIDs.asInt(x, y)) >= 0 && iShape < nShapes )
+					{
+						d			= pGrid->asDouble(x, y);
+						Sum[iShape]	+= d;
+						Dif[iShape]	+= d * d;
+						Num[iShape]	++;
+
+						if( bQuantiles )
+							ShapePixels[iShape].push_back(d);
+					}
+				}
+			}
+			
+			//---------------------------------------------
+			pShapes	= Parameters("RESULT")->asShapes();
+			pShapes->Assign(Parameters("POLY")->asShapes());
+
+			field_CELLS	= pShapes->Get_Field_Count();
+			pShapes->Add_Field(_TL("CELLS")		, SG_DATATYPE_Int);
+
+			field_MEAN	= pShapes->Get_Field_Count();
+			pShapes->Add_Field(_TL("MEAN")		, SG_DATATYPE_Double);
+
+			field_VARI	= pShapes->Get_Field_Count();
+			pShapes->Add_Field(_TL("VARIANCE")	, SG_DATATYPE_Double);
+
+			if( bQuantiles )
+			{
+				field_QUANTILES = pShapes->Get_Field_Count();
+
+				for(int i=quantile_step; i<100; i+=quantile_step)
+				{
+					pShapes->Add_Field(CSG_String::Format(SG_T("Q%d"), i).c_str(), SG_DATATYPE_Double);
+				}
+			}
+
+			for(iShape=0; iShape<nShapes; iShape++)
+			{
+				pRecord	= pShapes->Get_Shape(iShape);
+
+				if( Num[iShape] > 0 )
+				{
+					d		= Sum[iShape] / (double)Num[iShape];
+
+					pRecord->Set_Value(field_CELLS	, Num[iShape]);
+					pRecord->Set_Value(field_MEAN	, d);
+					pRecord->Set_Value(field_VARI	, Dif[iShape] / (double)Num[iShape] - d * d);
+
+					if( bQuantiles )
+					{
+						Set_Progress(iShape,nShapes);
+						ShapePixels[iShape].sort();	
+
+						int		i	= 0;	// Used to iterate over the different quantiles
+						int		k	= 0;	// Used to count at which position in the list we are j: iterates over the list
+
+						for(std::list<double>::iterator j=ShapePixels[iShape].begin(); j!=ShapePixels[iShape].end(); j++)
+						{
+							k++;
+
+						// Konstantin Stricker (stricker at iawg.de) reported an error in indexing the search for quantils.
+						// Original code:
+						//	while( ((double)k / (Num[iShape])) > ((double)i * quantile_step / 100.0) )
+						// His solution:
+							while( ((double)k / (Num[iShape])) > ((double)(i + 1) * quantile_step / 100.0) )
+							{
+								pRecord->Set_Value(field_QUANTILES + i, *j);
+								i++;
+							}
+						}
+					}	
+				}
+				else
+				{
+					pRecord->Set_Value(field_CELLS	, 0.0);
+					pRecord->Set_Value(field_MEAN	, 0.0);
+					pRecord->Set_Value(field_VARI	, 0.0);
+				}
+			}
+
+			//---------------------------------------------
+			free(Num);
+			free(Sum);
+			free(Dif);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Statistics_AddTo_Polygon::Get_ShapeIDs(CSG_Shapes *pShapes, CSG_Grid *pShapeIDs)
+{
+	bool		bFill, *bCrossing;
+	int			x, y, ix, xStart, xStop, iShape, iPart, iPoint;
+	double		yPos;
+	TSG_Point	pLeft, pRight, pa, pb, p;
+	TSG_Rect	Extent;
+	CSG_Shape	*pShape;
+
+	//-----------------------------------------------------
+	bCrossing	= (bool *)SG_Malloc(pShapeIDs->Get_NX() * sizeof(bool));
+
+	//-----------------------------------------------------
+	for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+	{
+		pShape		= pShapes->Get_Shape(iShape);
+		Extent		= pShape->Get_Extent().m_rect;
+
+		xStart		= Get_System()->Get_xWorld_to_Grid(Extent.xMin) - 1;	if( xStart < 0 )		xStart	= 0;
+		xStop		= Get_System()->Get_xWorld_to_Grid(Extent.xMax) + 1;	if( xStop >= Get_NX() )	xStop	= Get_NX() - 1;
+
+		pLeft.x		= pShapeIDs->Get_XMin() - 1.0;
+		pRight.x	= pShapeIDs->Get_XMax() + 1.0;
+
+		//-------------------------------------------------
+		for(y=0, yPos=pShapeIDs->Get_YMin(); y<pShapeIDs->Get_NY(); y++, yPos+=pShapeIDs->Get_Cellsize())
+		{
+			if( yPos >= Extent.yMin && yPos <= Extent.yMax )
+			{
+				memset(bCrossing, 0, pShapeIDs->Get_NX() * sizeof(bool));
+
+				pLeft.y	= pRight.y	= yPos;
+
+				//-----------------------------------------
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					pb		= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						pa	= pb;
+						pb	= pShape->Get_Point(iPoint, iPart);
+
+						if(	(	(pa.y <= yPos && yPos < pb.y)
+							||	(pa.y > yPos && yPos >= pb.y)	)	)
+						{
+							SG_Get_Crossing(p, pa, pb, pLeft, pRight, false);
+
+							ix	= (int)((p.x - pShapeIDs->Get_XMin()) / pShapeIDs->Get_Cellsize() + 1.0);
+
+							if( ix < 0)
+							{
+								ix	= 0;
+							}
+							else if( ix >= pShapeIDs->Get_NX() )
+							{
+								ix	= pShapeIDs->Get_NX() - 1;
+							}
+
+							bCrossing[ix]	= !bCrossing[ix];
+						}
+					}
+				}
+
+				//-----------------------------------------
+				for(x=xStart, bFill=false; x<=xStop; x++)
+				{
+					if( bCrossing[x] )
+					{
+						bFill	= !bFill;
+					}
+
+					if( bFill )
+					{
+						pShapeIDs->Set_Value(x, y, iShape);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(bCrossing);
+
+	return( true );
+}
+
+

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Statistics_AddTo_Polygon.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,89 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             Grid_Statistics_AddTo_Polygon.h           //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Statistics_AddTo_Polygon_H
+#define HEADER_INCLUDED__Grid_Statistics_AddTo_Polygon_H
+
+//---------------------------------------------------------
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CGrid_Statistics_AddTo_Polygon : public CSG_Module_Grid  
+{
+public:
+	CGrid_Statistics_AddTo_Polygon(void);
+	virtual ~CGrid_Statistics_AddTo_Polygon(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	bool				Get_ShapeIDs(CSG_Shapes *pShapes, CSG_Grid *pShapeIDs);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Statistics_AddTo_Polygon_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,361 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_To_Contour.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_To_Contour.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_To_Contour::CGrid_To_Contour(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Contour Lines from Grid"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create contour lines (isolines) from grid values. "
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "CONTOUR"	, _TL("Contour Lines"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "ZMIN"	, _TL("Minimum Contour Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL, "ZMAX"	, _TL("Maximum Contour Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10000.0
+	);
+
+	Parameters.Add_Value(
+		NULL, "ZSTEP"	, _TL("Equidistance"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10.0, 0, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_To_Contour::~CGrid_To_Contour(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_To_Contour::On_Execute(void)
+{
+	double				zMin, zMax, zStep;
+
+	pGrid	= Parameters("INPUT"  )->asGrid();
+	pLayer	= Parameters("CONTOUR")->asShapes();
+
+	zMin	= Parameters("ZMIN"   )->asDouble()	/ pGrid->Get_ZFactor();
+	zMax	= Parameters("ZMAX"   )->asDouble()	/ pGrid->Get_ZFactor();
+	zStep	= Parameters("ZSTEP"  )->asDouble()	/ pGrid->Get_ZFactor();
+
+	if( zMin <= zMax && zStep > 0 )
+	{
+		if( zMin < pGrid->Get_ZMin() )
+		{
+			zMin	+= zStep * (int)((pGrid->Get_ZMin() - zMin) / zStep);
+		}
+
+		if( zMax > pGrid->Get_ZMax() )
+		{
+			zMax	= pGrid->Get_ZMax();
+		}
+
+		pLayer->Create(SHAPE_TYPE_Line, pGrid->Get_Name());
+
+		pLayer->Add_Field("ID", SG_DATATYPE_Int);
+		pLayer->Add_Field(CSG_String::Format(SG_T("%s"),pGrid->Get_Name()).BeforeFirst(SG_Char('.')), SG_DATATYPE_Double);
+
+		Contour_Create(zMin, zMax, zStep);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_To_Contour::Contour_Create(double zMin, double zMax, double zStep)
+{
+	int		x, y, i, ID;
+
+	double	zValue;
+
+	//-----------------------------------------------------
+	// Initialize...
+	col		= (char **)SG_Calloc(Get_NY(), sizeof(char *));
+	row		= (char **)SG_Calloc(Get_NY(), sizeof(char *));
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		col[y]	= (char *)SG_Calloc(Get_NX(), sizeof(char));
+		row[y]	= (char *)SG_Calloc(Get_NX(), sizeof(char));
+	}
+
+	if( zStep <= 0 )
+		zStep	= 1;
+
+	//-----------------------------------------------------
+	for(zValue=zMin, ID=0; zValue<=zMax && Set_Progress(zValue - zMin, zMax - zMin); zValue+=zStep)
+	{
+		//-------------------------------------------------
+		// Step1: Find Border Cells
+		for(y=0; y<Get_NY()-1; y++)
+			for(x=0; x<Get_NX()-1; x++)
+				if( pGrid->asDouble(x,y) >= zValue )
+				{
+					row[y][x]	= pGrid->asDouble(x+1,y  ) <  zValue ? 1 : 0;
+					col[y][x]	= pGrid->asDouble(x  ,y+1) <  zValue ? 1 : 0;
+				}
+				else
+				{
+					row[y][x]	= pGrid->asDouble(x+1,y  ) >= zValue ? 1 : 0;
+					col[y][x]	= pGrid->asDouble(x  ,y+1) >= zValue ? 1 : 0;
+				}
+
+		//-------------------------------------------------
+		// Step2: Interpolation + Delineation
+		for(y=0; y<Get_NY()-1; y++)
+			for(x=0; x<Get_NX()-1; x++)
+			{
+				if(row[y][x])
+				{
+					for(i=0; i<2; i++)
+						Contour_Find(x, y, zValue, true, ID++);
+					row[y][x]	= 0;
+				}
+
+				if(col[y][x])
+				{
+					for(i=0; i<2; i++)
+						Contour_Find(x, y, zValue, false, ID++);
+					col[y][x]	= 0;
+				}
+			}
+	}
+
+	//-----------------------------------------------------
+	// Finalize...
+	for(y=0; y<Get_NY(); y++)
+	{
+		SG_Free(col[y]);
+		SG_Free(row[y]);
+	}
+
+	SG_Free(col);
+	SG_Free(row);
+}
+
+//---------------------------------------------------------
+void CGrid_To_Contour::Contour_Find(int x, int y, double z, bool doRow, int ID)
+{
+	bool	doContinue	= true;
+
+	int		zx			= doRow ? x + 1 : x,
+			zy			= doRow ? y : y + 1,
+			Dir			= 0;
+
+	DWORD	n			= 0;
+
+	double	d, xPos, yPos,
+			xMin		= pGrid->Get_XMin(),
+			yMin		= pGrid->Get_YMin();
+
+	CSG_Shape	*pShape	= pLayer->Add_Shape();
+
+	pShape->Set_Value(0, ID);
+	pShape->Set_Value(1, z);
+
+	do
+	{
+		//-------------------------------------------------
+		// Interpolation...
+		d		= pGrid->asDouble(x,y);
+		d		= (d - z) / (d - pGrid->asDouble(zx,zy));
+
+		xPos	= xMin + Get_Cellsize() * (x + d * (zx - x));
+		yPos	= yMin + Get_Cellsize() * (y + d * (zy - y));
+		pShape->Add_Point(xPos, yPos);
+
+		//-------------------------------------------------
+		// Naechstes (x/y) (col/row) finden...
+		if( !Contour_FindNext(Dir, x ,y ,doRow) )
+			doContinue	= Contour_FindNext(Dir, x, y, doRow);
+
+		Dir		= (Dir + 5) % 8;
+
+		//-------------------------------------------------
+		// Loeschen und initialisieren...
+		if(doRow)
+		{
+			row[y][x]	= 0;
+			zx			= x + 1;
+			zy			= y;
+		}
+		else
+		{
+			col[y][x]	= 0;
+			zx			= x;
+			zy			= y + 1;
+		}
+	}
+	while(doContinue);
+}
+
+//---------------------------------------------------------
+inline bool CGrid_To_Contour::Contour_FindNext(int &Dir, int &x, int &y, bool &doRow)
+{
+	bool	doContinue;
+
+	if(doRow)
+	{
+		switch(Dir)
+		{
+		case 0:	// Norden
+			if(row[y+1][x  ])
+			{			y++;					Dir=0; doContinue=true; break; }
+		case 1:	// Nord-Ost
+			if(col[y  ][x+1])
+			{	x++;			doRow=false;	Dir=1; doContinue=true; break; }
+		case 2:	// Osten ist nicht...
+		case 3:	// Sued-Ost
+			if(y-1>=0) if(col[y-1][x+1])
+			{	x++;	y--;	doRow=false;	Dir=3; doContinue=true; break; }
+		case 4:	// Sueden
+			if(y-1>=0) if(row[y-1][x  ])
+			{			y--;					Dir=4; doContinue=true; break; }
+		case 5:	// Sued-West
+			if(y-1>=0) if(col[y-1][x  ])
+			{			y--;	doRow=false;	Dir=5; doContinue=true; break; }
+		case 6:	// Westen ist nicht...
+		case 7:	// Nord-West
+			if(col[y  ][x  ])
+			{					doRow=false;	Dir=7; doContinue=true; break; }
+		default:
+			Dir=0; doContinue=false;
+		}
+	}
+	else
+	{
+		switch(Dir)
+		{
+		case 0:	// Norden ist nicht...
+		case 1:	// Nord-Ost
+			if(row[y+1][x  ])
+			{			y++;	doRow=true;		Dir=1; doContinue=true; break; }
+		case 2:	// Osten
+			if(col[y  ][x+1])
+			{	x++;							Dir=2; doContinue=true; break; }
+		case 3:	// Sued-Ost
+			if(row[y  ][x  ])
+			{					doRow=true;		Dir=3; doContinue=true; break; }
+		case 4:	// Sueden ist nicht...
+		case 5:	// Sued-West
+			if(x-1>=0)	if(row[y  ][x-1])
+			{	x--;			doRow=true;		Dir=5; doContinue=true; break; }
+		case 6:	// Westen
+			if(x-1>=0)	if(col[y  ][x-1])
+			{	x--;							Dir=6; doContinue=true; break; }
+		case 7:	// Nord-West
+			if(x-1>=0)	if(row[y+1][x-1])
+			{	x--;	y++;	doRow=true;		Dir=7; doContinue=true; break; }
+		default:
+			Dir=0; doContinue=false;
+		}
+	}
+
+	return(doContinue);
+}

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Contour.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_To_Contour.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_To_Contour_H
+#define HEADER_INCLUDED__Grid_To_Contour_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_To_Contour : public CSG_Module_Grid  
+{
+public:
+	CGrid_To_Contour(void);
+	virtual ~CGrid_To_Contour(void);
+
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+	char				**col, **row;
+
+	CSG_Grid				*pGrid;
+
+	CSG_Shapes				*pLayer;
+
+
+	void				Contour_Create		(double zStart, double zStop, double zDist);
+	void				Contour_Find		(int x, int y, double z, bool doRow, int ID);
+	bool				Contour_FindNext	(int &Dir, int &x, int &y, bool &doRow);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_To_Contour_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,218 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_To_Gradient.cpp                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_To_Gradient.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_To_Gradient::CGrid_To_Gradient(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Gradient from Grid"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create lines indicating the gradient. "
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "SHAPES"		, _TL("Gradient"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "STEP"		, _TL("Skip"),
+		_TL(""),
+		PARAMETER_TYPE_Int	, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "SIZE_MIN"	, _TL("Minimum Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "SIZE_MAX"	, _TL("Maximum Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10.0
+	);
+
+	Parameters.Add_Choice(
+		NULL, "STYLE"		, _TL("Style"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|"),
+			_TL("Line"),
+			_TL("Arrow")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_To_Gradient::~CGrid_To_Gradient(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_To_Gradient::On_Execute(void)
+{
+	bool	bTangens	= false;
+	int		Style, Step, x, y;
+	double	sMin, sRange, Min, Max, dStep, Slope, Aspect, xPt, yPt;
+	CSG_Grid	*pGrid;
+	CSG_Shapes	*pShapes;
+	CSG_Shape	*pShape;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")		->asGrid();
+	pShapes	= Parameters("SHAPES")		->asShapes();
+	Step	= Parameters("STEP")		->asInt();
+	Style	= Parameters("STYLE")		->asInt();
+	sMin	= Parameters("SIZE_MIN")	->asDouble();
+	sRange	= Parameters("SIZE_MAX")	->asDouble() - sMin;
+	dStep	= Step * Get_Cellsize();
+
+	pShapes->Create(SHAPE_TYPE_Line, CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("Gradient")));
+	pShapes->Add_Field("X"	, SG_DATATYPE_Double);
+	pShapes->Add_Field("Y"	, SG_DATATYPE_Double);
+	pShapes->Add_Field("S"	, SG_DATATYPE_Double);
+	pShapes->Add_Field("A"	, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	for(y=0, Min=0.0, Max=-1.0; y<Get_NY() && Set_Progress(y); y+=Step)
+	{
+		for(x=0; x<Get_NX(); x+=Step)
+		{
+			if( pGrid->Get_Gradient(x, y, Slope, Aspect) )
+			{
+				if( Min > Max )
+					Min	= Max	= Slope;
+				else if( Min > Slope )
+					Min	= Slope;
+				else if( Max < Slope )
+					Max	= Slope;
+			}
+		}
+	}
+
+	if( Min < Max )
+	{
+		sRange	= sRange / (Max - Min);
+	}
+
+	//-----------------------------------------------------
+	for(y=0, yPt=Get_YMin(); y<Get_NY() && Set_Progress(y); y+=Step, yPt+=dStep)
+	{
+		for(x=0, xPt=Get_XMin(); x<Get_NX(); x+=Step, xPt+=dStep)
+		{
+			if( pGrid->Get_Gradient(x, y, Slope, Aspect) )
+			{
+				pShape	= pShapes->Add_Shape();
+				pShape->Set_Value(0, xPt);
+				pShape->Set_Value(1, yPt);
+				pShape->Set_Value(2, Slope);
+				pShape->Set_Value(3, Aspect);
+				pShape->Add_Point(xPt, yPt);
+
+		//		Slope	= sMin + sRange * (bTangens ? tan(Slope) : Slope / M_PI_090);
+				Slope	= sMin + sRange * (Slope - Min);
+
+				pShape->Add_Point(
+					xPt + sin(Aspect) * Slope,
+					yPt + cos(Aspect) * Slope
+				);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Gradient.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_To_Gradient.h                  //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_To_Gradient_H
+#define HEADER_INCLUDED__Grid_To_Gradient_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_To_Gradient : public CSG_Module_Grid  
+{
+public:
+	CGrid_To_Gradient(void);
+	virtual ~CGrid_To_Gradient(void);
+
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_To_Gradient_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,213 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_To_Points.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_To_Points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_To_Points::CGrid_To_Points(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Grid Values to Points"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This module saves grid values to a point shape. Optionally only points "
+		"can be saved, which are contained by polygons of the specified shapes layer. "
+		"In addition, it is possible to exclude all cells that are coded NoData in the "
+		"first grid of the grid list."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NODATA"		, _TL("Exclude NoData Cells"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, 0.0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_To_Points::~CGrid_To_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_To_Points::On_Execute(void)
+{
+	bool					bZFactor, bNoNoData;
+	int						x, y, iGrid, iPoint;
+	double					xPos, yPos;
+	CSG_Grid				*pGrid;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_Shape				*pPoint;
+	CSG_Shapes				*pPoints, *pPolygons;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("GRIDS")	->asGridList();
+	pPolygons	= Parameters("POLYGONS")->asShapes();
+	pPoints		= Parameters("POINTS")	->asShapes();
+	bNoNoData	= Parameters("NODATA")	->asBool();
+
+	bZFactor	= true;
+
+	//-----------------------------------------------------
+	if( pGrids->Get_Count() > 0 )
+	{
+		pPoints->Create(SHAPE_TYPE_Point, _TL("Points from Grid(s)"));
+
+		pPoints->Add_Field("ID"	, SG_DATATYPE_Int);
+		pPoints->Add_Field("X"	, SG_DATATYPE_Double);
+		pPoints->Add_Field("Y"	, SG_DATATYPE_Double);
+
+		for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+		{
+			pPoints->Add_Field(CSG_String::Format(SG_T("%s"),pGrids->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')).c_str(), SG_DATATYPE_Double);
+		}
+
+		//-------------------------------------------------
+		for(y=0, yPos=Get_YMin(), iPoint=0; y<Get_NY() && Set_Progress(y); y++, yPos+=Get_Cellsize())
+		{
+			for(x=0, xPos=Get_XMin(); x<Get_NX(); x++, xPos+=Get_Cellsize())
+			{
+				if( (!bNoNoData || (bNoNoData && !pGrids->asGrid(0)->is_NoData(x, y)))
+				&&	(!pPolygons || is_Contained(xPos, yPos, pPolygons)) )
+				{
+					pPoint	= pPoints->Add_Shape();
+					pPoint->Add_Point(xPos, yPos);
+
+					pPoint->Set_Value(0, ++iPoint);
+					pPoint->Set_Value(1, xPos);
+					pPoint->Set_Value(2, yPos);
+
+					for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+					{
+						pGrid	= pGrids->asGrid(iGrid);
+
+						pPoint->Set_Value(iGrid + 3, pGrid->is_NoData(x, y) ? -99999 : pGrid->asDouble(x, y, bZFactor));
+					}
+				}
+			}
+		}
+
+		return( pPoints->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline bool CGrid_To_Points::is_Contained(double x, double y, CSG_Shapes *pPolygons)
+{
+	if( pPolygons && pPolygons->Get_Type() == SHAPE_TYPE_Polygon )
+	{
+		for(int iPolygon=0; iPolygon<pPolygons->Get_Count(); iPolygon++)
+		{
+			CSG_Shape_Polygon *pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon);
+
+			if( pPolygon->is_Containing(x, y) )
+			{
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_To_Points.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_To_Points_H
+#define HEADER_INCLUDED__Grid_To_Points_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_To_Points : public CSG_Module_Grid
+{
+public:
+	CGrid_To_Points(void);
+	virtual ~CGrid_To_Points(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	bool				is_Contained	(double x, double y, CSG_Shapes *pPolygons);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_To_Points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_To_Points_Random.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <time.h>
+
+#include "Grid_To_Points_Random.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_To_Points_Random::CGrid_To_Points_Random()
+{
+	Set_Name		(_TL("Grid Values to Points (randomly)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Extract randomly points from gridded data."
+	));
+
+	Parameters.Add_Grid(	NULL, "GRID"	, _TL("Grid")		, _TL(""), PARAMETER_INPUT);
+	Parameters.Add_Value(	NULL, "FREQ"	, _TL("Frequency")	, _TL("One per x"), PARAMETER_TYPE_Int, 100, 1, true);
+
+	Parameters.Add_Shapes(	NULL, "POINTS"	, _TL("Points")		, _TL(""), PARAMETER_OUTPUT, SHAPE_TYPE_Point);
+}
+
+//---------------------------------------------------------
+CGrid_To_Points_Random::~CGrid_To_Points_Random()
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_To_Points_Random::On_Execute(void)
+{
+	int		x, y, n;
+	double	frequency;
+	CSG_Grid	*pGrid;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+
+	pGrid		= Parameters("GRID")->asGrid();
+	frequency	= 1.0 / Parameters("FREQ")->asDouble();
+	pShapes		= Parameters("POINTS")->asShapes();
+
+	pShapes->Create(SHAPE_TYPE_Point, pGrid->Get_Name());
+	pShapes->Add_Field("ID"		, SG_DATATYPE_Int);
+	pShapes->Add_Field("VALUE"	, SG_DATATYPE_Double);
+
+	srand((unsigned)time(NULL));
+
+	for(n=0, y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( (double)rand() / (double)RAND_MAX <= frequency )
+			{
+				pShape	= pShapes->Add_Shape();
+
+				pShape->Add_Point(
+					pGrid->Get_XMin() + x * Get_Cellsize(),
+					pGrid->Get_YMin() + y * Get_Cellsize()
+				);
+
+				pShape->Set_Value(0, ++n);
+				pShape->Set_Value(1, pGrid->asDouble(x, y));
+			}
+		}
+	}
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_To_Points_Random.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,96 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_To_Points_Random.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_To_Points_Random_H
+#define HEADER_INCLUDED__Grid_To_Points_Random_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_To_Points_Random : public CSG_Module_Grid  
+{
+public:
+	CGrid_To_Points_Random(void);
+	virtual ~CGrid_To_Points_Random(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_To_Points_Random_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,181 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Grid_Values_AddTo_Points.cpp             //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Values_AddTo_Points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Values_AddTo_Points::CGrid_Values_AddTo_Points(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Add Grid Values to Points"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Retrieves information from the selected grids at the positions of the points of "
+		"the selected points layer and adds it to the resulting layer."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT			, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT			, false
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "RESULT"		, _TL("Result"),
+		_TL(""),
+		PARAMETER_OUTPUT		, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "INTERPOL"	, _TL("Interpolation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Values_AddTo_Points::~CGrid_Values_AddTo_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Values_AddTo_Points::On_Execute(void)
+{
+	bool					bZFactor;
+	int						iShape, iGrid, iField, nFields, Interpol;
+	TSG_Point				Point;
+	CSG_Grid					*pGrid;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_Shape					*pShape;
+	CSG_Shapes					*pShapes;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("GRIDS" )	->asGridList();
+	pShapes		= Parameters("SHAPES")	->asShapes();
+
+	Interpol	= Parameters("INTERPOL")->asInt();
+	bZFactor	= true;
+
+	if( pGrids->Get_Count() > 0 && pShapes->Get_Type() == SHAPE_TYPE_Point )
+	{
+		if( pShapes != Parameters("RESULT")->asShapes() )
+		{
+			pShapes		= Parameters("RESULT")->asShapes();
+			pShapes->Assign(Parameters("SHAPES")->asShapes());
+		}
+
+		nFields		= pShapes->Get_Field_Count();
+
+		for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+		{
+			pShapes->Add_Field(pGrids->asGrid(iGrid)->Get_Name(), SG_DATATYPE_Double);
+		}
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= pShapes->Get_Shape(iShape);
+			Point	= pShape->Get_Point(0);
+
+			for(iGrid=0, iField=nFields; iGrid<pGrids->Get_Count(); iGrid++, iField++)
+			{
+				pGrid	= pGrids->asGrid(iGrid);
+
+				pShape->Set_Value(iField,
+					pGrid->is_InGrid_byPos(Point) ? pGrid->Get_Value(Point, Interpol, bZFactor) : -99999
+				);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,92 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Values_AddTo_Points.h              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Values_AddTo_Points_H
+#define HEADER_INCLUDED__Grid_Values_AddTo_Points_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Values_AddTo_Points : public CSG_Module  
+{
+public:
+	CGrid_Values_AddTo_Points(void);
+	virtual ~CGrid_Values_AddTo_Points(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Values_AddTo_Points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,246 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Grid_Values_AddTo_Shapes.cpp             //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Values_AddTo_Shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Values_AddTo_Shapes::CGrid_Values_AddTo_Shapes(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Get Grid Data for Shapes"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Retrieves information from the selected grids at the positions of the shapes of "
+		"the selected shapes layer and adds it to the resulting shapes layer."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT, false
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "RESULT"		, _TL("Shapes (Grid Information)"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "INTERPOL"	, _TL("Interpolation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Values_AddTo_Shapes::~CGrid_Values_AddTo_Shapes(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Values_AddTo_Shapes::On_Execute(void)
+{
+	int			iGrid, iShape;
+	CSG_Shapes		*pShapes;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("GRIDS")->asGridList();
+
+	if( pGrids->Get_Count() > 0 && Parameters("SHAPES")->asShapes()->Get_Type() == SHAPE_TYPE_Point )
+	{
+		pResult		= Parameters("RESULT")->asShapes();
+		Interpol	= Parameters("INTERPOL")->asInt();
+
+		if( pResult == Parameters("SHAPES")->asShapes() )
+		{
+			pShapes		= SG_Create_Shapes(*pResult);
+		}
+		else
+		{
+			pShapes		= Parameters("SHAPES")->asShapes();
+		}
+
+		pResult->Create(pShapes->Get_Type());
+
+		//-------------------------------------------------
+		for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+		{
+			pResult->Add_Field(pGrids->asGrid(iGrid)->Get_Name(), SG_DATATYPE_Double);
+		}
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			switch( pShapes->Get_Type() )
+			{
+			case SHAPE_TYPE_Point:
+				Get_Data_Point(		pShapes->Get_Shape(iShape) );
+				break;
+
+			case SHAPE_TYPE_Line:
+				Get_Data_Line(		pShapes->Get_Shape(iShape) );
+				break;
+
+			case SHAPE_TYPE_Polygon:
+				Get_Data_Polygon(	pShapes->Get_Shape(iShape) );
+				break;
+			}
+		}
+
+		//-------------------------------------------------
+		if( pResult == Parameters("SHAPES")->asShapes() )
+		{
+			delete(pShapes);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CGrid_Values_AddTo_Shapes::Get_Data_Point(CSG_Shape *pShape)
+{
+	int			iPart, iPoint, nValues, iGrid, Interpolation = 1;
+	double		Value_Sum;
+	TSG_Point	Point;
+	CSG_Grid		*pGrid;
+	CSG_Shape		*pShape_Result;
+
+	pShape_Result	= pResult->Add_Shape();
+
+	//-----------------------------------------------------
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			pShape_Result->Add_Point(pShape->Get_Point(iPoint, iPart), iPart);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+	{
+		Value_Sum	= 0.0;
+		nValues		= 0;
+		pGrid		= pGrids->asGrid(iGrid);
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				Point	= pShape->Get_Point(iPoint, iPart);
+
+				if( pGrid->is_InGrid_byPos(Point) )
+				{
+					Value_Sum	+= pGrid->Get_Value(Point, Interpol, true);
+					nValues		++;
+				}
+			}
+		}
+
+		if( nValues > 0 )
+		{
+			pShape_Result->Set_Value(iGrid, Value_Sum / (double)nValues);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CGrid_Values_AddTo_Shapes::Get_Data_Line(CSG_Shape *pShape)
+{
+}
+
+//---------------------------------------------------------
+void CGrid_Values_AddTo_Shapes::Get_Data_Polygon(CSG_Shape *pShape)
+{
+}

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/Grid_Values_AddTo_Shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Values_AddTo_Shapes.h              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Values_AddTo_Shapes_H
+#define HEADER_INCLUDED__Grid_Values_AddTo_Shapes_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Values_AddTo_Shapes : public CSG_Module  
+{
+public:
+	CGrid_Values_AddTo_Shapes(void);
+	virtual ~CGrid_Values_AddTo_Shapes(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+	int							Interpol;
+
+	CSG_Shapes						*pResult;
+
+	CSG_Parameter_Grid_List		*pGrids;
+
+
+	void						Get_Data_Point		(CSG_Shape *pShape );
+	void						Get_Data_Line		(CSG_Shape *pShape );
+	void						Get_Data_Polygon	(CSG_Shape *pShape );
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Values_AddTo_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,180 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Shapes - Grid") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools related to gridded and vector data (conversions, combinations, etc.).") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Shapes|Grid") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Grid_Values_AddTo_Points.h"
+#include "Grid_Values_AddTo_Shapes.h"
+#include "Grid_Statistics_AddTo_Polygon.h"
+#include "Grid_To_Points.h"
+#include "Grid_To_Points_Random.h"
+#include "Grid_To_Contour.h"
+#include "Grid_Classes_To_Shapes.h"
+#include "Grid_Polygon_Clip.h"
+#include "Grid_To_Gradient.h"
+#include "grid_local_extremes_to_points.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CGrid_Values_AddTo_Points;
+		break;
+
+	case 1:
+		pModule	= new CGrid_Values_AddTo_Shapes;
+		break;
+
+	case 2:
+		pModule	= new CGrid_Statistics_AddTo_Polygon;
+		break;
+
+	case 3:
+		pModule	= new CGrid_To_Points;
+		break;
+
+	case 4:
+		pModule	= new CGrid_To_Points_Random;
+		break;
+
+	case 5:
+		pModule	= new CGrid_To_Contour;
+		break;
+
+	case 6:
+		pModule	= new CGrid_Classes_To_Shapes;
+		break;
+
+	case 7:
+		pModule	= new CGrid_Polygon_Clip;
+		break;
+
+	case 8:
+		pModule	= new CGrid_To_Gradient;
+		break;
+
+	case 9:
+		pModule	= new CGrid_Local_Extremes_to_Points;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__shapes_grid_H
+#define HEADER_INCLUDED__shapes_grid_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef shapes_grid_EXPORTS
+	#define	shapes_grid_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	shapes_grid_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__shapes_grid_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,186 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//            grid_local_extremes_to_points.cpp          //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid_local_extremes_to_points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Local_Extremes_to_Points::CGrid_Local_Extremes_to_Points(void)
+{
+	Set_Name		(_TL("Local Minima and Maxima"));
+
+	Set_Author		(SG_T("(c) 2009 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Extracts local grid value minima and maxima of to vector points."
+	));
+
+	Parameters.Add_Grid(
+		NULL, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "MINIMA"	, _TL("Minima"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "MAXIMA"	, _TL("Maxima"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Local_Extremes_to_Points::On_Execute(void)
+{
+	bool		bMinimum, bMaximum;
+	int			x, y, i, ix, iy;
+	double		z, iz;
+	CSG_Grid	*pGrid;
+	TSG_Point	p;
+	CSG_Shape	*pPoint;
+	CSG_Shapes	*pMinima, *pMaxima;
+
+	pGrid		= Parameters("GRID")	->asGrid();
+	pMinima		= Parameters("MINIMA")	->asShapes();
+	pMaxima		= Parameters("MAXIMA")	->asShapes();
+
+	pMinima->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("Local Minima")));
+	pMinima->Add_Field(SG_T("GRID_X")	, SG_DATATYPE_Int);
+	pMinima->Add_Field(SG_T("GRID_Y")	, SG_DATATYPE_Int);
+	pMinima->Add_Field(SG_T("X")		, SG_DATATYPE_Double);
+	pMinima->Add_Field(SG_T("Y")		, SG_DATATYPE_Double);
+	pMinima->Add_Field(SG_T("Z")		, SG_DATATYPE_Double);
+
+	pMaxima->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("Local Maxima")));
+	pMaxima->Add_Field(SG_T("GRID_X")	, SG_DATATYPE_Int);
+	pMaxima->Add_Field(SG_T("GRID_Y")	, SG_DATATYPE_Int);
+	pMaxima->Add_Field(SG_T("X")		, SG_DATATYPE_Double);
+	pMaxima->Add_Field(SG_T("Y")		, SG_DATATYPE_Double);
+	pMaxima->Add_Field(SG_T("Z")		, SG_DATATYPE_Double);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			z	= pGrid->asDouble(x, y);
+
+			for(i=0, bMinimum=true, bMaximum=true; i<8 && (bMinimum || bMaximum); i++)
+			{
+				if( !Get_System()->Get_Neighbor_Pos(i, x, y, ix, iy) || pGrid->is_NoData(ix, iy) )
+				{
+					bMinimum	= bMaximum	= false;
+				}
+				else
+				{
+					iz	= pGrid->asDouble(ix, iy);
+
+					if( iz <= z )
+					{
+						bMinimum	= false;
+					}
+					else if( iz >= z )
+					{
+						bMaximum	= false;
+					}
+				}
+			}
+
+			pPoint	= bMinimum ? pMinima->Add_Shape() : (bMaximum ? pMaxima->Add_Shape() : NULL);
+
+			if( pPoint )
+			{
+				p		= Get_System()->Get_Grid_to_World(x, y);
+				pPoint->Set_Point(p, 0);
+				pPoint->Set_Value(0, x);
+				pPoint->Set_Value(1, y);
+				pPoint->Set_Value(2, p.x);
+				pPoint->Set_Value(3, p.y);
+				pPoint->Set_Value(4, z);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_grid/grid_local_extremes_to_points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Grid_Shapes                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//            grid_local_extremes_to_points.h            //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__grid_local_extremes_to_points_H
+#define HEADER_INCLUDED__grid_local_extremes_to_points_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Local_Extremes_to_Points : public CSG_Module_Grid  
+{
+public:
+	CGrid_Local_Extremes_to_Points(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__grid_local_extremes_to_points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Lines_From_Points.cpp                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Lines_From_Points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CLines_From_Points::CLines_From_Points(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Convert Points to Line"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Converts points to a line."
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ORDER"		, _TL("Order by..."),
+		_TL(""),
+		true
+	);
+}
+
+//---------------------------------------------------------
+CLines_From_Points::~CLines_From_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLines_From_Points::On_Execute(void)
+{
+	CSG_Shape	*pLine , *pPoint;
+	CSG_Shapes	*pLines, *pPoints;
+
+	pPoints	= Parameters("POINTS")	->asShapes();
+	pLines	= Parameters("LINES")	->asShapes();
+
+	if(	pPoints->Get_Count() > 0 )
+	{
+		pPoints->Set_Index(Parameters("ORDER")->asInt(), TABLE_INDEX_Ascending);
+
+		pLines->Create(SHAPE_TYPE_Line, pPoints->Get_Name(), pPoints);
+		pLines->Add_Field(SG_T("ID"), SG_DATATYPE_Int);
+		pLine	= pLines->Add_Shape();
+
+		//-------------------------------------------------
+		for(int iPoint=0; iPoint<pPoints->Get_Count(); iPoint++)
+		{
+			pPoint	= pPoints->Get_Shape_byIndex(iPoint);
+
+			pLine->Add_Point(pPoint->Get_Point(0));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Lines_From_Points.h                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Lines_From_Points_H
+#define HEADER_INCLUDED__Lines_From_Points_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CLines_From_Points : public CSG_Module  
+{
+public:
+	CLines_From_Points(void);
+	virtual ~CLines_From_Points(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Lines_From_Points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Lines_From_Polygons.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Lines_From_Polygons.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CLines_From_Polygons::CLines_From_Polygons(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Convert Polygons to Lines"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Converts polygon shapes to line shapes."
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+}
+
+//---------------------------------------------------------
+CLines_From_Polygons::~CLines_From_Polygons(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLines_From_Polygons::On_Execute(void)
+{
+	int				iShape, iPart, iPoint;
+	CSG_Shape			*pLine , *pPolygon;
+	CSG_Shapes			*pLines, *pPolygons;
+
+	pPolygons	= Parameters("POLYGONS")	->asShapes();
+	pLines		= Parameters("LINES")		->asShapes();
+
+	if(	pPolygons->Get_Count() > 0 )
+	{
+		pLines->Create(SHAPE_TYPE_Line, pPolygons->Get_Name(), pPolygons);
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pPolygons->Get_Count(); iShape++)
+		{
+			pPolygon	= pPolygons	->Get_Shape(iShape);
+			pLine		= pLines	->Add_Shape(pPolygon, SHAPE_COPY_ATTR);
+
+			for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++)
+				{
+					pLine->Add_Point(pPolygon->Get_Point(iPoint, iPart), iPart);
+				}
+
+				pLine->Add_Point(pPolygon->Get_Point(0, iPart), iPart);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/Lines_From_Polygons.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Lines_From_Polygons.h                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Lines_From_Polygons_H
+#define HEADER_INCLUDED__Lines_From_Polygons_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CLines_From_Polygons : public CSG_Module  
+{
+public:
+	CLines_From_Polygons(void);
+	virtual ~CLines_From_Polygons(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Lines_From_Polygons_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Shapes - Lines") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2005") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for lines.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Shapes|Lines") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Lines_From_Polygons.h"
+#include "Lines_From_Points.h"
+#include "line_properties.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CLines_From_Polygons );
+	case 1:		return( new CLines_From_Points );
+	case 2:		return( new CLine_Properties );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__shapes_lines_H
+#define HEADER_INCLUDED__shapes_lines_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef shapes_lines_EXPORTS
+	#define	shapes_lines_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	shapes_lines_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__shapes_lines_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,142 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  line_properties.cpp                  //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "line_properties.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CLine_Properties::CLine_Properties(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Line Properties"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"Line properties: length, number of vertices."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "OUTPUT"		, _TL("Lines with Property Attributes added"),
+		_TL("If not set property attributes will be added to the orignal lines layer."),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Line
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLine_Properties::On_Execute(void)
+{
+	CSG_Shapes	*pLines	= Parameters("LINES")->asShapes();
+
+	if(	pLines->is_Valid() && pLines->Get_Count() > 0 )
+	{
+		if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pLines )
+		{
+			pLines	= Parameters("OUTPUT")->asShapes();
+			pLines->Create(*Parameters("LINES")->asShapes());
+		}
+
+		//-------------------------------------------------
+		int		iOffset	= pLines->Get_Field_Count();
+
+		pLines->Add_Field(SG_T("N_VERTICES"), SG_DATATYPE_Int);
+		pLines->Add_Field(SG_T("LENGTH")	, SG_DATATYPE_Double);
+
+		//-------------------------------------------------
+		for(int iLine=0; iLine<pLines->Get_Count() && Set_Progress(iLine, pLines->Get_Count()); iLine++)
+		{
+			CSG_Shape	*pLine	= pLines->Get_Shape(iLine);
+
+			pLine->Set_Value(iOffset + 0, pLine->Get_Point_Count());
+			pLine->Set_Value(iOffset + 1, ((CSG_Shape_Line *)pLine)->Get_Length());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_lines/line_properties.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_lines                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   line_properties.h                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__line_properties_H
+#define HEADER_INCLUDED__line_properties_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CLine_Properties : public CSG_Module  
+{
+public:
+	CLine_Properties(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__line_properties_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,242 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_points                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Clip_Points.cpp                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Clip_Points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CClip_Points::CClip_Points(void)
+{
+	Set_Name		(_TL("Clip Points with Polygons"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	CSG_Parameter	*pNode	= Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"		, _TL("Add Attribute to Clipped Points"),
+		_TL(""),
+		true
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL	, "CLIPS"		, _TL("Clipped Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Clipping Options"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("one layer for all points"),
+			_TL("separate layer for each polygon")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CClip_Points::~CClip_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CClip_Points::On_Execute(void)
+{
+	int							Method, iField;
+	CSG_Shapes					*pPoints, *pPolygons, *pClip;
+	CSG_Parameter_Shapes_List	*pClips;
+
+	//-----------------------------------------------------
+	pPoints		= Parameters("POINTS")		->asShapes();
+	pPolygons	= Parameters("POLYGONS")	->asShapes();
+	pClips		= Parameters("CLIPS")		->asShapesList();
+	Method		= Parameters("METHOD")		->asInt();
+	iField		= Parameters("FIELD")		->asInt();
+
+	//-----------------------------------------------------
+	if( !pPoints->is_Valid() )
+	{
+		Message_Add(_TL("Invalid points layer."));
+
+		return( false );
+	}
+	else if( !pPolygons->is_Valid() )
+	{
+		Message_Add(_TL("Invalid polygon layer."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( iField >= pPolygons->Get_Field_Count() )
+	{
+		iField	= -1;
+	}
+
+	pClips->Del_Items();
+
+	if( Method == 0 )
+	{
+		pClip	= SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), pPolygons->Get_Name()), pPoints);
+
+		if( iField >= 0 )
+		{
+			pClip->Add_Field(pPolygons->Get_Field_Name(iField), pPolygons->Get_Field_Type(iField));
+		}
+	}
+
+	//-----------------------------------------------------
+	for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
+	{
+		CSG_Shape_Polygon	*pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon);
+
+		if( Method == 1 )
+		{
+			CSG_String	Name(pPoints->Get_Name());
+
+			Name	+= iField >= 0
+					? CSG_String::Format(SG_T(" [%s]"), pPolygon->asString(iField))
+					: CSG_String::Format(SG_T(" [%00d]"), 1 + pClips->Get_Count());
+
+			pClip	= SG_Create_Shapes(SHAPE_TYPE_Point, Name, pPoints);
+
+			if( iField >= 0 )
+			{
+				pClip->Add_Field(pPolygons->Get_Field_Name(iField), pPolygons->Get_Field_Type(iField));
+			}
+		}
+
+		for(int iPoint=0; iPoint<pPoints->Get_Count() && Process_Get_Okay(false); iPoint++)
+		{
+			CSG_Shape	*pPoint	= pPoints->Get_Shape(iPoint);
+
+			if( pPolygon->is_Containing(pPoint->Get_Point(0)) )
+			{
+				pPoint	= pClip->Add_Shape(pPoint, SHAPE_COPY);
+
+				if( iField >= 0 )
+				{
+					pPoint->Set_Value(pPoints->Get_Field_Count(), pPolygon->asString(iField));
+				}
+			}
+		}
+
+		if( Method == 1 )
+		{
+			if( pClip->Get_Count() > 0 )
+			{
+				pClips->Add_Item(pClip);
+			}
+			else
+			{
+				delete(pClip);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( Method == 0 )
+	{
+		if( pClip->Get_Count() > 0 )
+		{
+			pClips->Add_Item(pClip);
+		}
+		else
+		{
+			delete(pClip);
+		}
+	}
+
+	return( pClips->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/Clip_Points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,97 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Clip_Points.h                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Clip_Points_H
+#define HEADER_INCLUDED__Clip_Points_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CClip_Points : public CSG_Module
+{
+public:
+	CClip_Points(void);
+	virtual ~CClip_Points(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Clip_Points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,137 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_points                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volaya at ya.com                          //
+//                                                       //
+//    contact:    Victor Olaya Ferrero                   //
+//                Madrid                                 //
+//                Spain                                  //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Shapes - Points") );
+
+	case MLB_INFO_Author:
+		return( _TL("Various Authors") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the manipulation of point vector data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Shapes|Points") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Points_From_Table.h"
+#include "Points_From_Lines.h"
+#include "CountPoints.h"
+#include "CreatePointGrid.h"
+#include "DistanceMatrix.h"
+#include "FitNPointsToShape.h"
+#include "AddCoordinates.h"
+#include "remove_duplicates.h"
+#include "Clip_Points.h"
+#include "separate_by_direction.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CPoints_From_Table );
+	case 1:		return( new CCountPoints );
+	case 2:		return( new CCreatePointGrid );
+	case 3:		return( new CDistanceMatrix );
+	case 4:		return( new CFitNPointsToShape );
+	case 5:		return( new CPoints_From_Lines );
+	case 6:		return( new CAddCoordinates );
+	case 7:		return( new CRemove_Duplicates );
+	case 8:		return( new CClip_Points );
+	case 9:		return( new CSeparate_by_Direction );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,79 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_points                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                     Victor Olaya                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volaya at ya.com                          //
+//                                                       //
+//    contact:    Victor Olaya Ferrero                   //
+//                Madrid                                 //
+//                Spain                                  //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__shapes_points_H
+#define HEADER_INCLUDED__shapes_points_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef shapes_points_EXPORTS
+	#define	shapes_points_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	shapes_points_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__shapes_points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,255 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_points                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Remove_Duplicates.cpp                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "remove_duplicates.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CRemove_Duplicates::CRemove_Duplicates(void)
+{
+	Set_Name		(_TL("Remove Duplicate Points"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "RESULT"		, _TL("Result"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD_NUM"	, _TL("Numerical Values"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("first"),
+			_TL("last"),
+			_TL("mean")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD_STR"	, _TL("Text"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("first"),
+			_TL("last")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CRemove_Duplicates::~CRemove_Duplicates(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRemove_Duplicates::On_Execute(void)
+{
+	int					i, j;
+	double				Epsilon	= 0.00001;
+	CSG_Point			Point;
+	CSG_Shape			*pPoint, *pDuplicate;
+	CSG_Shapes			*pPoints, *pInput;
+	CSG_Shapes_Search	Search;
+
+	//-----------------------------------------------------
+	pInput			= Parameters("POINTS")		->asShapes();
+	pPoints			= Parameters("RESULT")		->asShapes();
+
+	m_Method_Num	= Parameters("METHOD_NUM")	->asInt();
+	m_Method_Str	= Parameters("METHOD_STR")	->asInt();
+
+	if( pPoints == NULL )
+	{
+		pPoints	= pInput;
+	}
+	else if( pPoints != pInput )
+	{
+		pPoints->Assign(pInput);
+	}
+
+	//-----------------------------------------------------
+	if( !pPoints->is_Valid() )
+	{
+		Message_Add(_TL("Invalid shapes layer."));
+
+		return( false );
+	}
+	else if( !Search.Create(pPoints) )
+	{
+		Message_Add(_TL("Failed to initialise search engine."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	pPoints->Select();
+
+	for(i=0; i<pPoints->Get_Count() && Set_Progress(i, pPoints->Get_Count()); i++)
+	{
+		pPoint	= pPoints->Get_Shape(i);
+
+		if( !pPoint->is_Selected() )
+		{
+			Point	= pPoint->Get_Point(0);
+
+			if( Search.Select_Radius(Point.Get_X(), Point.Get_Y(), Epsilon) > 1 )
+			{
+				for(j=0; j<Search.Get_Selected_Count(); j++)
+				{
+					pDuplicate	= Search.Get_Selected_Point(j);
+
+					if( pDuplicate && pDuplicate != pPoint && Point == pDuplicate->Get_Point(0) )
+					{
+						pPoints->Select(pDuplicate, true);
+
+						Set_Attributes(pPoint, pDuplicate);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pPoints->Get_Selection_Count() == 0 )
+	{
+		Message_Add(_TL("No duplicates found."));
+	}
+	else
+	{
+		Message_Add(CSG_String::Format(SG_T("%d %s"), pPoints->Get_Selection_Count(), _TL("duplicates have been identified.")));
+
+		pPoints->Del_Selection();
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CRemove_Duplicates::Set_Attributes(CSG_Table_Record *pTarget, CSG_Table_Record *pSource)
+{
+	if( m_Method_Num == 0 && m_Method_Str == 0 )
+	{
+		// nothing to do...
+	}
+	else if( m_Method_Num == 1 && m_Method_Str == 1 )
+	{
+		pTarget->Assign(pSource);
+	}
+	else
+	{
+		CSG_Table	*pTable	= pTarget->Get_Table();
+
+		for(int iField=0; iField<pTable->Get_Field_Count(); iField++)
+		{
+			switch( pTable->Get_Field_Type(iField) )
+			{
+			case SG_DATATYPE_String:
+			case SG_DATATYPE_Color:
+			case SG_DATATYPE_Date:
+				if( m_Method_Str == 1 )
+				{
+					pTarget->Set_Value(iField, pSource->asString(iField));
+				}
+				break;
+
+			default:
+				if( m_Method_Num == 1 )
+				{
+					pTarget->Set_Value(iField, pSource->asDouble(iField));
+				}
+				else if( m_Method_Num == 2 )
+				{
+					pTarget->Set_Value(iField, (pSource->asDouble(iField) + pTarget->asDouble(iField)) / 2.0);
+				}
+				break;
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/remove_duplicates.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Remove_Duplicates.h                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Remove_Duplicates_H
+#define HEADER_INCLUDED__Remove_Duplicates_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CRemove_Duplicates : public CSG_Module
+{
+public:
+	CRemove_Duplicates(void);
+	virtual ~CRemove_Duplicates(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	int							m_Method_Num, m_Method_Str;
+
+
+	void						Set_Attributes			(CSG_Table_Record *pTarget, CSG_Table_Record *pSource);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Remove_Duplicates_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,210 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Table_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                separate_by_direction.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "separate_by_direction.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSeparate_by_Direction::CSeparate_by_Direction(void)
+{
+	Set_Name		(_TL("Separate points by direction"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		"Separates points by direction. Direction is determined as average direction of three consecutive points A, B, C. "
+		"If the angle between the directions of A-B and B-C is higher than given tolerance angle the point is dropped. "
+		"This module has been designed to separate GPS tracks recorded by tractors while preparing a field. "
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes_List(
+		NULL	, "OUTPUT"		, _TL("Ouput"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DIRECTIONS"	, _TL("Number of Directions"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 4.0, 2.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TOLERANCE"	, _TL("Tolerance (Degree)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 5.0, 0.0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSeparate_by_Direction::On_Execute(void)
+{
+	int							iSector, dir_Field;
+	CSG_Shapes					*pPoints;
+	CSG_Parameter_Shapes_List	*pOutput;
+
+	//-----------------------------------------------------
+	pOutput		= Parameters("OUTPUT")		->asShapesList();
+	pPoints		= Parameters("POINTS")		->asShapes();
+	m_Tolerance	= Parameters("TOLERANCE")	->asDouble() * M_DEG_TO_RAD;
+	m_nSectors	= Parameters("DIRECTIONS")	->asInt();
+	m_dSector	= M_PI_360 / m_nSectors;
+
+	if( !pPoints || !pPoints->is_Valid() || pPoints->Get_Count() < 3 )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	pOutput->Del_Items();
+
+	dir_Field	= pPoints->Get_Field_Count();
+
+	for(iSector=0; iSector<m_nSectors; iSector++)
+	{
+		pOutput->Add_Item(SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("Direction %.2f"), iSector * m_dSector * M_RAD_TO_DEG), pPoints));
+		pOutput->asShapes(iSector)->Add_Field(_TL("Direction"), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	int			iPoint;
+	double		dir_A, dir_B, dir, dif;
+	CSG_Shape	*pt_A, *pt_B;
+
+	pt_B	= pPoints->Get_Shape(pPoints->Get_Count() - 2);
+	pt_A	= pPoints->Get_Shape(pPoints->Get_Count() - 1);
+
+	dir_A	= SG_Get_Angle_Of_Direction(pt_B->Get_Point(0), pt_A->Get_Point(0));
+
+	for(iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++)
+	{
+		pt_B	= pt_A;
+		pt_A	= pPoints->Get_Shape(iPoint);
+
+		dir_B	= dir_A;
+		dir_A	= SG_Get_Angle_Of_Direction(pt_B->Get_Point(0), pt_A->Get_Point(0));
+
+		dif		= fmod(dir_A - dir_B, M_PI_360);
+
+		if( dif > M_PI_180 )
+		{
+			dif	-= M_PI_360;
+		}
+		else if( dif < -M_PI_180 )
+		{
+			dif	+= M_PI_360;
+		}
+
+		if( fabs(dif) <= m_Tolerance )
+		{
+			dir		= dir_B + 0.5 * dif;
+
+			iSector	= (int)(fmod(M_PI_360 + 0.5 * m_dSector + dir, M_PI_360) / m_dSector);
+
+			if( iSector >= 0 && iSector < m_nSectors )
+			{
+				pOutput->asShapes(iSector)->Add_Shape(pt_B)->Set_Value(dir_Field, dir * M_RAD_TO_DEG);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iSector=pOutput->Get_Count()-1; iSector>=0; iSector--)
+	{
+		if( pOutput->asShapes(iSector)->Get_Count() == 0 )
+		{
+			delete(pOutput->asShapes(iSector));
+
+			pOutput->Del_Item(iSector);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( pOutput->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_points/separate_by_direction.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Table_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                separate_by_direction.h                //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__separate_by_direction_H
+#define HEADER_INCLUDED__separate_by_direction_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSeparate_by_Direction : public CSG_Module
+{
+public:
+	CSeparate_by_Direction(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						m_nSectors;
+
+	double					m_Tolerance, m_dSector;
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__separate_by_direction_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,136 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Shapes - Polygons") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Victor Olaya (c) 2002-5") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for polygons.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Shapes|Polygons") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Polygon_Intersection.h"
+#include "Polygon_Centroids.h"
+#include "Polygon_Geometrics.h"
+#include "Polygons_From_Lines.h"
+#include "Polygon_StatisticsFromPoints.h"
+#include "Polygon_Union.h"
+#include "polygon_to_points.h"
+#include "shape_index.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CPolygon_Intersection );
+	case 1:		return( new CPolygon_Centroids );
+	case 2:		return( new CPolygon_Geometrics );
+	case 3:		return( new CPolygons_From_Lines );
+	case 4:		return( new CPolygonStatisticsFromPoints );
+	case 5:		return( new CPolygon_Union );
+	case 6:		return( new CPolygon_To_Points );
+	case 7:		return( new CShape_Index );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__shapes_polygons_H
+#define HEADER_INCLUDED__shapes_polygons_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef shapes_polygons_EXPORTS
+	#define	shapes_polygons_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	shapes_polygons_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__shapes_polygon_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,169 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Polygon_Centroids.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Polygon_Centroids.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPolygon_Centroids::CPolygon_Centroids(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Polygon Centroids"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Creates a points layer containing the centroids of the input polygon layer."
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "CENTROIDS"	, _TL("Centroids"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Value(
+		NULL	, "METHOD"		, _TL("Centroids for each part"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	//-----------------------------------------------------
+}
+
+//---------------------------------------------------------
+CPolygon_Centroids::~CPolygon_Centroids(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPolygon_Centroids::On_Execute(void)
+{
+	bool			bPart;
+	int				iShape, iPart;
+	CSG_Shape			*pCentroid;
+	CSG_Shape_Polygon	*pPolygon;
+	CSG_Shapes			*pPolygons, *pCentroids;
+
+	pPolygons	= Parameters("POLYGONS")	->asShapes();
+	pCentroids	= Parameters("CENTROIDS")	->asShapes();
+	bPart		= Parameters("METHOD")		->asBool();
+
+	if(	pPolygons->Get_Type() == SHAPE_TYPE_Polygon && pPolygons->Get_Count() > 0 )
+	{
+		pCentroids->Create(SHAPE_TYPE_Point, pPolygons->Get_Name(), pPolygons);
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pPolygons->Get_Count(); iShape++)
+		{
+			pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iShape);
+
+			if( bPart )
+			{
+				for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+				{
+					pCentroid	= pCentroids->Add_Shape(pPolygon, SHAPE_COPY_ATTR);
+					pCentroid->Add_Point(pPolygon->Get_Centroid(iPart));
+				}
+			}
+			else
+			{
+				pCentroid	= pCentroids->Add_Shape(pPolygon, SHAPE_COPY_ATTR);
+				pCentroid->Add_Point(pPolygon->Get_Centroid());
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Centroids.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Polygon_Centroids.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_Centroids_H
+#define HEADER_INCLUDED__Polygon_Centroids_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPolygon_Centroids : public CSG_Module  
+{
+public:
+	CPolygon_Centroids(void);
+	virtual ~CPolygon_Centroids(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_Centroids_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Clipper.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Clipper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Clipper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Polygon_Clipper.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_Clipper_H
+#define HEADER_INCLUDED__Polygon_Clipper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		GPC_Intersection	(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_Difference		(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_ExclusiveOr		(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_Union			(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_Clipper_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,530 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Polygon_Intersection.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Polygon_Intersection.h"
+
+#include "Polygon_Clipper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MODE_FIRST		1
+#define MODE_SECOND		2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPolygon_Intersection::CPolygon_Intersection(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Polygon Intersection"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Intersection of polygon layers. Uses GPC - General Polygon Clipper - version 2.31 by Alan Murta."
+	));
+
+	/*/-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes_List(
+		NULL	, "SHAPES"		, _TL("Polygon Layers"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	/**/
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES_A"	, _TL("Layer A"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD_A"		, _TL("Attribute A"),
+		_TL(""),
+		true
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES_B"	, _TL("Layer B"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD_B"		, _TL("Attribute B"),
+		_TL(""),
+		true
+	);
+
+	/**/
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES_AB"	, _TL("Intersection"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Complete Intersection"),
+			_TL("Intersection"),
+			_TL("Difference (A - B)"),
+			_TL("Difference (B - A)")
+		), 0
+	);
+
+	pNode	= Parameters.Add_Value(
+		NULL	, "SPLITPARTS"	, _TL("Split Parts"),
+		_TL("Set true if you want multipart polygons to become separate polygons."),
+		PARAMETER_TYPE_Bool, true
+	);
+}
+
+//---------------------------------------------------------
+CPolygon_Intersection::~CPolygon_Intersection(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+/*/---------------------------------------------------------
+bool CPolygon_Intersection::On_Execute(void)
+{
+	CSG_Parameter_Shapes_List	*pList;
+
+	pList			= Parameters("SHAPES")		->asShapesList();
+	m_pShapes_AB	= Parameters("SHAPES_AB")	->asShapes();
+	m_bSplitParts	= Parameters("SPLITPARTS")	->asBool();
+
+	if(	pList->Get_Count() < 2 )
+	{
+		Message_Add(_TL("At least two polygons have to be given for intersection"));
+	}
+	else
+	{
+		m_pShapes_AB->Create(SHAPE_TYPE_Polygon);
+		m_pShapes_AB->Add_Field("ID"	, SG_DATATYPE_Int);
+		m_pShapes_AB->Add_Field("ID_A"	, SG_DATATYPE_Int);
+
+		Intersect(pList->asShapes(0), pList->asShapes(1));
+
+		//-------------------------------------------------
+		if( pList->Get_Count() > 2 )
+		{
+			CSG_Shapes	Tmp;
+
+			for(int i=2; i<pList->Get_Count() && Process_Get_Okay(false); i++)
+			{
+				Tmp.Create(*m_pShapes_AB);
+
+				Intersect(&Tmp, pList->asShapes(i));
+			}
+		}
+
+		//-------------------------------------------------
+		return( m_pShapes_AB->is_Valid() );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPolygon_Intersection::Intersect(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B)
+{
+	CSG_String	sName;
+
+	if(	pShapes_A->Get_Type() == SHAPE_TYPE_Polygon && pShapes_A->is_Valid()
+	&&	pShapes_B->Get_Type() == SHAPE_TYPE_Polygon && pShapes_B->is_Valid() )
+	{
+		m_pShapes_AB->Del_Shapes();
+
+		switch( Parameters("METHOD")->asInt() )
+		{
+		//-------------------------------------------------
+		case 0:	// Complete Intersection...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Intersection"), pShapes_A->Get_Name(), pShapes_B->Get_Name());
+
+			Get_Intersection(pShapes_A, pShapes_B, MODE_FIRST);
+			Get_Difference	(pShapes_A, pShapes_B, MODE_FIRST);
+			Get_Difference	(pShapes_B, pShapes_A, MODE_SECOND);
+
+			break;
+
+		//-------------------------------------------------
+		case 1:	// Intersection...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Intersection"), pShapes_A->Get_Name(), pShapes_B->Get_Name());
+
+			Get_Intersection(pShapes_A, pShapes_B, MODE_SINGLE);
+
+			break;
+
+		//-------------------------------------------------
+		case 2:						// Difference A - B...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Difference"), pShapes_A->Get_Name(), pShapes_B->Get_Name());
+
+			Get_Difference	(pShapes_A, pShapes_B, MODE_SINGLE);
+
+			break;
+
+		//-------------------------------------------------
+		case 3:						// Difference B - A...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Difference"), pShapes_B->Get_Name(), pShapes_A->Get_Name());
+
+			Get_Difference	(pShapes_B, pShapes_A, MODE_SINGLE);
+
+			break;
+		}
+
+		//-------------------------------------------------
+		m_pShapes_AB->Set_Name(sName);
+
+		return( m_pShapes_AB->Get_Count() > 0 );
+	}
+
+	return( false );
+}/**/
+
+//---------------------------------------------------------
+bool CPolygon_Intersection::On_Execute(void)
+{
+	CSG_String	sName;
+
+	m_pShapes_A		= Parameters("SHAPES_A")	->asShapes();
+	m_pShapes_B		= Parameters("SHAPES_B")	->asShapes();
+	m_pShapes_AB	= Parameters("SHAPES_AB")	->asShapes();
+	m_bSplitParts	= Parameters("SPLITPARTS")	->asBool();
+	m_iField_A		= Parameters("FIELD_A")		->asInt();	if( m_iField_A >= m_pShapes_A->Get_Field_Count() )	{	m_iField_A	= -1;	}
+	m_iField_B		= Parameters("FIELD_B")		->asInt();	if( m_iField_B >= m_pShapes_B->Get_Field_Count() )	{	m_iField_B	= -1;	}
+
+	if(	m_pShapes_A->Get_Type() == SHAPE_TYPE_Polygon && m_pShapes_A->is_Valid()
+	&&	m_pShapes_B->Get_Type() == SHAPE_TYPE_Polygon && m_pShapes_B->is_Valid() )
+	{
+		m_pShapes_AB->Create(SHAPE_TYPE_Polygon);
+		m_pShapes_AB->Add_Field("ID"	, SG_DATATYPE_Int);
+		m_pShapes_AB->Add_Field("ID_A"	, SG_DATATYPE_Int);
+		m_pShapes_AB->Add_Field("ID_B"	, SG_DATATYPE_Int);
+		m_pShapes_AB->Add_Field("ID_AB"	, SG_DATATYPE_Int);
+
+		if( m_iField_A >= 0 )
+		{
+			m_pShapes_AB->Add_Field(m_pShapes_A->Get_Field_Name(m_iField_A), m_pShapes_A->Get_Field_Type(m_iField_A));
+		}
+
+		if( m_iField_B >= 0 )
+		{
+			m_pShapes_AB->Add_Field(m_pShapes_B->Get_Field_Name(m_iField_B), m_pShapes_B->Get_Field_Type(m_iField_B));
+		}
+
+		//-------------------------------------------------
+		switch( Parameters("METHOD")->asInt() )
+		{
+		//-------------------------------------------------
+		case 0:	// Complete Intersection...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Intersection"), m_pShapes_A->Get_Name(), m_pShapes_B->Get_Name());
+
+			Get_Intersection(m_pShapes_A, m_pShapes_B, MODE_FIRST);
+			Get_Difference	(m_pShapes_A, m_pShapes_B, MODE_FIRST);
+			Get_Difference	(m_pShapes_B, m_pShapes_A, MODE_SECOND);
+
+			break;
+
+		//-------------------------------------------------
+		case 1:	// Intersection...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Intersection"), m_pShapes_A->Get_Name(), m_pShapes_B->Get_Name());
+
+			Get_Intersection(m_pShapes_A, m_pShapes_B, MODE_FIRST);
+
+			break;
+
+		//-------------------------------------------------
+		case 2:						// Difference A - B...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Difference"), m_pShapes_A->Get_Name(), m_pShapes_B->Get_Name());
+
+			Get_Difference	(m_pShapes_A, m_pShapes_B, MODE_FIRST);
+
+			break;
+
+		//-------------------------------------------------
+		case 3:						// Difference B - A...
+			sName.Printf(SG_T("%s [%s]-[%s]"), _TL("Difference"), m_pShapes_B->Get_Name(), m_pShapes_A->Get_Name());
+
+			Get_Difference	(m_pShapes_B, m_pShapes_A, MODE_SECOND);
+
+			break;
+		}
+
+		//-------------------------------------------------
+		m_pShapes_AB->Set_Name(sName);
+
+		return( m_pShapes_AB->Get_Count() > 0 );
+	}
+
+	return( false );
+}/**/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPolygon_Intersection::Get_Intersection(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B, int Mode)
+{
+	CSG_Shape	*pShape_A, *pShape_B, *pShape_AB;
+	CSG_Shapes	Tmp(SHAPE_TYPE_Polygon);
+
+	m_Mode		= Mode;
+
+	pShape_A	= Tmp.Add_Shape();
+	pShape_AB	= Tmp.Add_Shape();
+
+	for(int iShape_A=0; iShape_A<pShapes_A->Get_Count() && Set_Progress(iShape_A, pShapes_A->Get_Count()); iShape_A++)
+	{
+		if( pShapes_B->Select(pShapes_A->Get_Shape(iShape_A)->Get_Extent()) )
+		{
+			pShape_A	= pShapes_A->Get_Shape(iShape_A);
+
+			for(int iShape_B=0; iShape_B<pShapes_B->Get_Selection_Count(); iShape_B++)
+			{
+				pShape_B	= pShapes_B->Get_Selection(iShape_B);
+
+				if( GPC_Intersection(pShape_A, pShape_B, pShape_AB) )
+				{
+					Add_Polygon(pShape_AB, iShape_A, pShape_B->Get_Index());
+				}
+			}
+		}
+	}
+
+	return( m_pShapes_AB->is_Valid() );
+}
+
+//---------------------------------------------------------
+bool CPolygon_Intersection::Get_Difference(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B, int Mode)
+{
+	CSG_Shape	*pShape_A;
+	CSG_Shapes	Tmp(SHAPE_TYPE_Polygon);
+
+	m_Mode		= Mode;
+
+	pShape_A	= Tmp.Add_Shape();
+
+	for(int iShape_A=0; iShape_A<pShapes_A->Get_Count() && Set_Progress(iShape_A, pShapes_A->Get_Count()); iShape_A++)
+	{
+		if( pShapes_B->Select(pShapes_A->Get_Shape(iShape_A)->Get_Extent()) )
+		{
+			int		nIntersections	= 0;
+
+			pShape_A->Assign(pShapes_A->Get_Shape(iShape_A));
+
+			for(int iShape_B=0; iShape_B<pShapes_B->Get_Selection_Count(); iShape_B++)
+			{
+				if( GPC_Difference(pShape_A, pShapes_B->Get_Selection(iShape_B)) )
+				{
+					nIntersections++;
+				}
+			}
+
+			if( nIntersections && pShape_A->is_Valid() )
+			{
+				Add_Polygon(pShape_A, iShape_A);
+			}
+		}
+		else
+		{
+			Add_Polygon(pShapes_A->Get_Shape(iShape_A), iShape_A);
+		}
+	}
+
+	return( m_pShapes_AB->is_Valid() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape * CPolygon_Intersection::Get_Polygon(int iShape_A, int iShape_B)
+{
+	CSG_Shape	*pShape	= m_pShapes_AB->Add_Shape();
+
+	if( pShape )
+	{
+		pShape->Set_Value(0, m_pShapes_AB->Get_Count());
+
+		if( m_Mode == MODE_SECOND )
+		{
+			int		ID	= iShape_A;	iShape_A	= iShape_B;	iShape_B	= ID;
+		}
+
+		pShape->Set_Value(1, iShape_A);
+		pShape->Set_Value(2, iShape_B);
+		pShape->Set_Value(3, iShape_A >= 0 && iShape_B >= 0 ? 0 : iShape_A >= 0 ? -1 : 1);
+
+		if( m_iField_A >= 0 && iShape_A >= 0 )
+		{
+			pShape->Set_Value(4, m_pShapes_A->Get_Shape(iShape_A)->asString(m_iField_A));
+		}
+
+		if( m_iField_B >= 0 && iShape_B >= 0 )
+		{
+			pShape->Set_Value(m_iField_A >= 0 ? 5 : 4, m_pShapes_B->Get_Shape(iShape_B)->asString(m_iField_B));
+		}
+	}
+
+	return( pShape );
+}
+
+//---------------------------------------------------------
+void CPolygon_Intersection::Add_Polygon(CSG_Shape *pShape, int iShape_A, int iShape_B)
+{
+	int			iPoint, iPart, jPart, nParts;
+	CSG_Shape	*pShape_Add;
+
+	for(iPart=pShape->Get_Part_Count()-1; iPart>=0; iPart--)
+	{
+		if( ((CSG_Shape_Polygon *)pShape)->Get_Area(iPart) <= 0.0 )
+		{
+			pShape->Del_Part(iPart);
+		}
+		else if( pShape->Get_Point_Count(iPart) <= 3 )
+		{
+			CSG_Point	a(pShape->Get_Point(0, iPart)), b(pShape->Get_Point(1, iPart)), c(pShape->Get_Point(2, iPart));
+
+			if( a == b || b == c || c == a )
+			{
+				pShape->Del_Part(iPart);
+			}
+		}
+	}
+
+	if( pShape->is_Valid() )
+	{
+		if( m_bSplitParts && pShape->Get_Part_Count() > 1 )
+		{
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				if( !((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) && (pShape_Add = Get_Polygon(iShape_A, iShape_B)) != NULL )
+				{
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						pShape_Add->Add_Point(pShape->Get_Point(iPoint, iPart), 0);
+					}
+
+					for(jPart=0, nParts=0; jPart<pShape->Get_Part_Count(); jPart++)
+					{
+						if(	((CSG_Shape_Polygon *)pShape)->is_Lake(jPart)
+						&&	((CSG_Shape_Polygon *)pShape)->is_Containing(pShape->Get_Point(0, jPart), iPart) )
+						{
+							nParts++;
+
+							for(iPoint=0; iPoint<pShape->Get_Point_Count(jPart); iPoint++)
+							{
+								pShape_Add->Add_Point(pShape->Get_Point(iPoint, jPart), nParts);
+							}
+						}
+					}
+				}
+			}
+		}
+		else if( (pShape_Add = Get_Polygon(iShape_A, iShape_B)) != NULL )
+		{
+			pShape_Add->Assign(pShape, false);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Intersection.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Polygon_Intersection.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_Intersection_H
+#define HEADER_INCLUDED__Polygon_Intersection_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPolygon_Intersection : public CSG_Module  
+{
+public:
+	CPolygon_Intersection(void);
+	virtual ~CPolygon_Intersection(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	bool					m_bSplitParts;
+
+	int						m_Mode, m_iField_A, m_iField_B;
+
+	CSG_Shapes				*m_pShapes_A, *m_pShapes_B, *m_pShapes_AB;
+
+
+//	bool					Intersect			(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B);
+
+	bool					Get_Intersection	(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B, int Mode);
+	bool					Get_Difference		(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B, int Mode);
+
+	void					Add_Polygon			(CSG_Shape *pShape, int ID_A, int ID_B = -1);
+	CSG_Shape *				Get_Polygon			(int ID_A, int ID_B);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_Intersection_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,199 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Polygon_Union.cpp                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Polygon_Union.h"
+
+#include "Polygon_Clipper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPolygon_Union::CPolygon_Union(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Polygon Union"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"The union of polygons, which have the same attribute value."
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ATTRIBUTE"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "UNION"		, _TL("Union"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "ALL"			, _TL("Union of"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("polygons with same attribute value"),
+			_TL("all polygons")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CPolygon_Union::~CPolygon_Union(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPolygon_Union::On_Execute(void)
+{
+	bool		bAll;
+	int			iField, iPolygon;
+	CSG_String	Value;
+	CSG_Table	*pTable;
+	CSG_Shape	*pPolygon, *pUnion;
+	CSG_Shapes	*pPolygons, *pUnions;
+
+	//-----------------------------------------------------
+	pPolygons	= Parameters("POLYGONS")	->asShapes();
+	pUnions		= Parameters("UNION")		->asShapes();
+	iField		= Parameters("ATTRIBUTE")	->asInt();
+	bAll		= Parameters("ALL")			->asInt() == 1;
+
+	//-----------------------------------------------------
+	if(	pPolygons->is_Valid() && iField >= 0 && iField < pPolygons->Get_Field_Count() )
+	{
+		pTable	= pPolygons;
+
+		pUnions	->Create(SHAPE_TYPE_Polygon);
+		pUnions	->Add_Field(pTable->Get_Field_Name(iField), pTable->Get_Field_Type(iField));
+
+		//-------------------------------------------------
+		if( bAll )
+		{
+			pUnion	= pUnions->Add_Shape(pPolygons->Get_Shape(0), SHAPE_COPY_GEOM);
+
+			for(iPolygon=1; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
+			{
+				GPC_Union(pUnion, pPolygons->Get_Shape(iPolygon));
+			}
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			pTable	->Set_Index(iField, TABLE_INDEX_Ascending);
+
+			pUnions	->Set_Name(CSG_String::Format(SG_T("%s [%s]-[%s]"), _TL("Union"), pPolygons->Get_Name(), pTable->Get_Field_Name(iField)));
+
+			for(iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
+			{
+				pPolygon	= pPolygons->Get_Shape(pTable->Get_Record_byIndex(iPolygon)->Get_Index());
+
+				if( iPolygon == 0 || Value.Cmp(pPolygon->asString(iField)) )
+				{
+					Value	= pPolygon->asString(iField);
+					pUnion	= pUnions->Add_Shape(pPolygon, SHAPE_COPY_GEOM);
+					pUnion	->Set_Value(0, Value);
+				}
+				else
+				{
+					GPC_Union(pUnion, pPolygon);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		return( pUnions->is_Valid() );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygon_Union.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Polygon_Union.h                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_Union_H
+#define HEADER_INCLUDED__Polygon_Union_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPolygon_Union : public CSG_Module  
+{
+public:
+	CPolygon_Union(void);
+	virtual ~CPolygon_Union(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_Union_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,151 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Polygons_From_Lines.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Polygons_From_Lines.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPolygons_From_Lines::CPolygons_From_Lines(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Convert Lines to Polygons"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Converts line shapes to polygon shapes. Line arcs are closed to polygons simply by connecting the last point with the first."
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Line
+	);
+}
+
+//---------------------------------------------------------
+CPolygons_From_Lines::~CPolygons_From_Lines(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPolygons_From_Lines::On_Execute(void)
+{
+	int				iShape, iPart, iPoint;
+	CSG_Shape			*pLine , *pPolygon;
+	CSG_Shapes			*pLines, *pPolygons;
+
+	pPolygons	= Parameters("POLYGONS")	->asShapes();
+	pLines		= Parameters("LINES")		->asShapes();
+
+	if(	pLines->Get_Count() > 0 )
+	{
+		pPolygons->Create(SHAPE_TYPE_Polygon, pLines->Get_Name(), pLines);
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pLines->Get_Count(); iShape++)
+		{
+			pLine		= pLines	->Get_Shape(iShape);
+			pPolygon	= pPolygons	->Add_Shape(pLine, SHAPE_COPY_ATTR);
+
+			for(iPart=0; iPart<pLine->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pLine->Get_Point_Count(iPart); iPoint++)
+				{
+					pPolygon->Add_Point(pLine->Get_Point(iPoint, iPart), iPart);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/Polygons_From_Lines.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Polygons_From_Lines.h                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygons_From_Lines_H
+#define HEADER_INCLUDED__Polygons_From_Lines_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPolygons_From_Lines : public CSG_Module  
+{
+public:
+	CPolygons_From_Lines(void);
+	virtual ~CPolygons_From_Lines(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygons_From_Lines_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,170 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Shapes_Polygon                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Polygon_To_Points.cpp                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "polygon_to_points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPolygon_To_Points::CPolygon_To_Points(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Convert Polygon/Line Vertices to Points"));
+
+	Set_Author		(_TL("(c) 2008 by O. Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+}
+
+//---------------------------------------------------------
+CPolygon_To_Points::~CPolygon_To_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPolygon_To_Points::On_Execute(void)
+{
+	CSG_Shapes		*pShapes, *pPoints;
+
+	pShapes			= Parameters("SHAPES")	->asShapes();
+	pPoints			= Parameters("POINTS")	->asShapes();
+
+	//-----------------------------------------------------
+	if( pShapes->is_Valid() )
+	{
+		pPoints->Create(SHAPE_TYPE_Point, pShapes->Get_Name());
+		pPoints->Add_Field(SG_T("ID")		, SG_DATATYPE_String);
+		pPoints->Add_Field(SG_T("ID_SHAPE")	, SG_DATATYPE_Int);
+		pPoints->Add_Field(SG_T("ID_PART")	, SG_DATATYPE_Int);
+		pPoints->Add_Field(SG_T("ID_POINT")	, SG_DATATYPE_Int);
+
+		if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
+		{
+			pPoints->Add_Field(SG_T("CLOCKWISE"), SG_DATATYPE_String);
+			pPoints->Add_Field(SG_T("LAKE")		, SG_DATATYPE_String);
+		}
+
+		for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					CSG_Shape	*pPoint	= pPoints->Add_Shape();
+
+					pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));
+
+					pPoint->Set_Value(0, CSG_String::Format(SG_T("%d/%d/%d"), iShape, iPart, iPoint));
+					pPoint->Set_Value(1, iShape);
+					pPoint->Set_Value(2, iPart);
+					pPoint->Set_Value(3, iPoint);
+
+					if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
+					{
+						pPoint->Set_Value(4, ((CSG_Shape_Polygon *)pShape)->is_Clockwise(iPart) ? SG_T("Y") : SG_T("N"));
+						pPoint->Set_Value(5, ((CSG_Shape_Polygon *)pShape)->is_Lake     (iPart) ? SG_T("Y") : SG_T("N"));
+					}
+				}
+			}
+		}
+
+		return( pPoints->is_Valid() );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/polygon_to_points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Shapes_Polygon                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Polygon_To_Points.h                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_To_Points_H
+#define HEADER_INCLUDED__Polygon_To_Points_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPolygon_To_Points : public CSG_Module
+{
+public:
+	CPolygon_To_Points(void);
+	virtual ~CPolygon_To_Points(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_To_Points_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,224 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Shapes_Polygon                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Shape_Index.cpp                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shape_index.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShape_Index::CShape_Index(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Polygon Shape Indices"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Various indices describing the shape of polygons. "
+		"Based on area, perimeter, maximum distance between the vertices of a polygon.\n"
+		"\n"
+		" - Interior Edge Ratio (Perimeter / Area)\n"
+		" - Shape Index (Perimeter / (2 * SquareRoot(PI * Area))\n"
+		"\n"
+		"References:\n"
+		"Lang, S., Blaschke, T. (2007): Landschaftsanalyse mit GIS.\n"
+		"\n"
+		"Forman, R.T.T., Godron, M. (1986): Landscape Ecology. Cambridge.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "INDEX"		, _TL("Shape Index"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Polygon
+	);
+}
+
+//---------------------------------------------------------
+CShape_Index::~CShape_Index(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShape_Index::On_Execute(void)
+{
+	CSG_Shapes	*pShapes, *pIndex;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	pIndex	= Parameters("INDEX")	->asShapes();
+
+	//-----------------------------------------------------
+	if( pShapes->is_Valid() )
+	{
+		int		iField	= pShapes->Get_Field_Count();
+
+		if( pIndex == NULL )
+		{
+			pIndex	= pShapes;
+		}
+
+		if( pIndex != pShapes )
+		{
+			pIndex->Create(SHAPE_TYPE_Polygon, _TL("Shape Index"), pShapes);
+		}
+
+		pIndex->Add_Field(_TL("Area")			, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("Perimenter")		, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("P/A")			, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("P/sqrt(A)")		, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("Max.Distance")	, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("D/A")			, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("D/sqrt(A)")		, SG_DATATYPE_Double);
+		pIndex->Add_Field(_TL("Shape Index")	, SG_DATATYPE_Double);
+
+		for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape_Polygon	*pShape	= (CSG_Shape_Polygon *)pShapes->Get_Shape(iShape);
+
+			double	Area		= pShape->Get_Area();
+			double	Perimeter	= pShape->Get_Perimeter();
+			double	Distance	= Get_Distance(pShape);
+
+			if( Perimeter > 0.0 && Distance > 0.0 )
+			{
+				if( pIndex != pShapes )
+				{
+					pShape		= (CSG_Shape_Polygon *)pIndex->Add_Shape(pShape, SHAPE_COPY_ATTR);
+				}
+
+				pShape->Set_Value(iField + 0, Area);
+				pShape->Set_Value(iField + 1, Perimeter);
+				pShape->Set_Value(iField + 2, Perimeter / Area);
+				pShape->Set_Value(iField + 3, Perimeter / sqrt(Area));
+				pShape->Set_Value(iField + 4, Distance);
+				pShape->Set_Value(iField + 5, Distance / Area);
+				pShape->Set_Value(iField + 6, Distance / sqrt(Area));
+				pShape->Set_Value(iField + 7, Perimeter / (2.0 * sqrt(M_PI * Area)));
+			}
+		}
+
+		if( pIndex == pShapes )
+		{
+			DataObject_Update(pShapes);
+		}
+
+		return( pIndex->is_Valid() );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+//---------------------------------------------------------
+double CShape_Index::Get_Distance(CSG_Shape *pShape)
+{
+	double	d, dMax	= 0.0;
+
+	for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		if( pShape->Get_Point_Count(iPart) > 2 )
+		{
+			TSG_Point	A, B;
+
+			A	= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+
+			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				B	= A;
+				A	= pShape->Get_Point(iPoint, iPart);
+				d	= SG_Get_Distance(A, B);
+
+				if( dMax < d )
+				{
+					dMax	= d;
+				}
+			}
+		}
+	}
+
+	return( dMax );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_polygons/shape_index.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,102 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Shapes_Polygon                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Shape_Index.h                      //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shape_Index_H
+#define HEADER_INCLUDED__Shape_Index_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShape_Index : public CSG_Module
+{
+public:
+	CShape_Index(void);
+	virtual ~CShape_Index(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+
+	double					Get_Distance		(CSG_Shape *pShape);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shape_Index_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,168 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Shapes - Tools") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Victor Olaya (c) 2002-2009") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the manipulation of vector data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Shapes|Tools") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Shapes_Create_Empty.h"
+#include "Shapes_Assign_Table.h"
+#include "Shapes_Merge.h"
+#include "Shapes_Report.h"
+#include "CreateWebContent.h"
+
+#include "QueryBuilder.h"
+#include "SearchInTable.h"
+#include "SelectByTheme.h"
+#include "SeparateShapes.h"
+#include "TransformShapes.h"
+#include "CreateChartLayer.h"
+#include "NewLayerFromSelectedShapes.h"
+#include "GraticuleBuilder.h"
+
+#include "Summarize.h"
+
+#include "shapes_cut.h"
+#include "shapes_cut_interactive.h"
+#include "shapes_split.h"
+#include "shapes_split_randomly.h"
+#include "shapes_split_by_attribute.h"
+#include "shapes_buffer.h"
+#include "shapes_extents.h"
+
+#include "quadtree_structure.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case  0:	return( new CShapes_Create_Empty );
+	case  1:	return( new CShapes_Assign_Table );
+	case  2:	return( new CShapes_Merge );
+	case  3:	return( new CNewLayerFromSelectedShapes );
+	case  4:	return( new CQueryBuilder );
+	case  5:	return( new CSearchInTable );
+	case  6:	return( new CSelectByTheme );
+	case  7:	return( new CSeparateShapes );
+	case  8:	return( new CTransformShapes );
+	case  9:	return( new CCreateChartLayer );
+	case 10:	return( new CGraticuleBuilder );
+	case 11:	return( new CShapes_Report );
+	case 12:	return( new CSummarize );
+	case 13:	return( new CCreateWebContent );
+	case 14:	return( new CShapes_Cut );
+	case 15:	return( new CShapes_Cut_Interactive );
+	case 16:	return( new CShapes_Split );
+	case 17:	return( new CShapes_Split_Randomly );
+	case 18:	return( new CShapes_Split_by_Attribute );
+	case 19:	return( new CShapes_Buffer );
+	case 20:	return( new CShapes_Extents );
+	case 21:	return( new CQuadTree_Structure );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__shapes_tools_H
+#define HEADER_INCLUDED__shapes_tools_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef shapes_tools_EXPORTS
+	#define	shapes_tools_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	shapes_tools_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__shapes_tools_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Polygon_Clipper.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Polygon_Clipper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Polygon_Clipper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Polygon_Clipper.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_Clipper_H
+#define HEADER_INCLUDED__Polygon_Clipper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		GPC_Intersection	(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_Difference		(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_ExclusiveOr		(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_Union			(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_Clipper_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,251 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Shapes_Assign_Table.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//              Olaf Conrad  & Victor Olaya              //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Shapes_Assign_Table.h"
+
+//---------------------------------------------------------
+#define METHOD_ADD		0
+#define METHOD_REPLACE	1
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Assign_Table::CShapes_Assign_Table(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Join a Table"));
+
+	Set_Author		(SG_T("V. Olaya, O. Conrad (c) 2003"));
+
+	Set_Description	(_TW(
+		"Joins a table with shapes layer's attributes."
+	));
+
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "SHAPES_ID"	, _TL("Identifier"),
+		_TL("")
+	);
+
+	pNode	= Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Table"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "TABLE_ID"	, _TL("Identifier"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES_OUT"	, _TL("Resulting Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Attributes"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("append"),
+			_TL("replace")
+		)
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "ADDALL"		, _TL("Copy Rule"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("all shapes"),
+			_TL("only shapes with table entry")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Assign_Table::~CShapes_Assign_Table(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Assign_Table::On_Execute(void)
+{
+	bool				bAddAll;
+	int					iShape, iField, jField, off_Field, iRecord, Method, id_Shapes, id_Table;
+	CSG_String			sID;
+	CSG_Table			*pTable_A;
+	CSG_Table_Record	*pRecord_A;
+	CSG_Shapes			*pShapes_A, *pShapes_B;
+	CSG_Shape			*pShape_A, *pShape_B;
+
+	//-----------------------------------------------------
+	pShapes_A	= Parameters("SHAPES")		->asShapes();
+	pShapes_B	= Parameters("SHAPES_OUT")	->asShapes();
+	pTable_A	= Parameters("TABLE")		->asTable();
+
+	id_Shapes	= Parameters("SHAPES_ID")	->asInt();
+	id_Table	= Parameters("TABLE_ID")	->asInt();
+
+	Method		= Parameters("METHOD")		->asInt();
+	bAddAll		= Parameters("ADDALL")		->asInt() == 0;
+
+	//-----------------------------------------------------
+	if(	id_Shapes >= 0 && id_Shapes < pShapes_A->Get_Field_Count() && pShapes_A->Get_Count() > 0
+	&&	id_Table  >= 0 && id_Table  < pTable_A ->Get_Field_Count() && pTable_A ->Get_Count() > 0 )
+	{
+		if( pShapes_A == pShapes_B || pShapes_A->Get_Type() != pShapes_B->Get_Type() )
+		{
+			Parameters("SHAPES_OUT")->Set_Value(pShapes_B = SG_Create_Shapes());
+		}
+
+		if( Method == METHOD_ADD )
+		{
+			pShapes_B->Create(pShapes_A->Get_Type(), CSG_String::Format(SG_T("%s / %s"), pShapes_A->Get_Name(), pTable_A->Get_Name()), pShapes_A);
+			off_Field	= pShapes_A->Get_Field_Count();
+
+			for(iField=0; iField<pTable_A->Get_Field_Count(); iField++)
+			{
+				if( iField != id_Table )
+				{
+					pShapes_B->Add_Field(pTable_A->Get_Field_Name(iField), pTable_A->Get_Field_Type(iField));
+				}
+			}
+		}
+		else // if( Method == METHOD_REPLACE )
+		{
+			pShapes_B->Create(pShapes_A->Get_Type(), CSG_String::Format(SG_T("%s / %s"), pShapes_A->Get_Name(), pTable_A->Get_Name()), pTable_A);
+			off_Field	= 0;
+		}
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pShapes_A->Get_Count() && Set_Progress(iShape, pShapes_A->Get_Count()); iShape++)
+		{
+			pShape_A	= pShapes_A->Get_Shape(iShape);
+			sID			= pShape_A->asString(id_Shapes);
+
+			for(iRecord=0, pShape_B=NULL; iRecord<pTable_A->Get_Count() && pShape_B==NULL; iRecord++)
+			{
+				pRecord_A	= pTable_A->Get_Record(iRecord);
+
+				if( !sID.CmpNoCase(pRecord_A->asString(id_Table)) )
+				{
+					pShape_B	= pShapes_B->Add_Shape(Method == METHOD_ADD ? pShape_A : NULL);
+
+					for(iField=0, jField=off_Field; iField<pTable_A->Get_Field_Count(); iField++)
+					{
+						if( Method != METHOD_ADD || iField != id_Table )
+						{
+							pShape_B->Set_Value(jField++, pRecord_A->asString(iField));
+						}
+					}
+				}
+			}
+
+			if( pShape_B == NULL && bAddAll )
+			{
+				pShape_B	= pShapes_B->Add_Shape(Method == METHOD_ADD ? pShape_A : NULL);
+
+				if( Method != METHOD_ADD )
+				{
+					pShape_B->Set_Value(id_Table, sID);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		return( pShapes_B->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Assign_Table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,88 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Shapes_Assign_Table.h                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Assign_Table_H
+#define HEADER_INCLUDED__Shapes_Assign_Table_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Assign_Table : public CSG_Module  
+{
+public:
+	CShapes_Assign_Table(void);
+	virtual ~CShapes_Assign_Table(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Shapes_Assign_Table_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,293 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Shapes_Create_Empty.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "Shapes_Create_Empty.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_NODE(i)	CSG_String::Format(SG_T("NODE%03d"), i)
+#define GET_NAME(i)	CSG_String::Format(SG_T("NAME%03d"), i)
+#define GET_TYPE(i)	CSG_String::Format(SG_T("TYPE%03d"), i)
+
+//---------------------------------------------------------
+CSG_String CShapes_Create_Empty::m_Types	= SG_T("");
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Create_Empty::CShapes_Create_Empty(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Create New Shapes Layer"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		"Creates a new empty shapes layer of given type, "
+		"which might be either point, multipoint, line or polygon."
+		"Available field types for the attributes table are:\n"
+		" - string\n"
+		" - 1 byte integer\n"
+		" - 2 byte integer\n"
+		" - 4 byte integer\n"
+		" - 4 byte floating point\n"
+		" - 8 byte floating point\n"
+//		" - 32 bit true color (RGB)\n"
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes_Output(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL("")
+	);
+
+	Parameters.Add_String(
+		NULL	, "NAME"		, _TL("Name"),
+		_TL(""),
+		_TL("New Shapes Layer")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TYPE"		, _TL("Shape Type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Point"),
+			_TL("Multipoint"),
+			_TL("Lines"),
+			_TL("Polygon")
+		)
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NFIELDS"		, _TL("Number of Attributes"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 2, 1, true
+	);
+
+	Parameters.Add_Parameters(
+		NULL	, "FIELDS"		, _TL("Attributes"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	m_Types.Clear();
+	m_Types	+= "text";					m_Types	+= "|";
+	m_Types	+= "1 byte integer";		m_Types	+= "|";
+	m_Types	+= "2 byte integer";		m_Types	+= "|";
+	m_Types	+= "4 byte integer";		m_Types	+= "|";
+	m_Types	+= "4 byte floating point";	m_Types	+= "|";
+	m_Types	+= "8 byte floating point";	m_Types	+= "|";
+//	m_Types	+= "true color (RGB)";		m_Types	+= "|";
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pAttributes	= Parameters("FIELDS")->asParameters();
+
+	_Set_Field_Count(pAttributes, Parameters("NFIELDS")->asInt());
+
+	pAttributes->Get_Parameter(GET_NAME(0))->Set_Value(_TL("ID"));
+	pAttributes->Get_Parameter(GET_TYPE(0))->Set_Value(3);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes_Create_Empty::_Set_Field_Count(CSG_Parameters *pAttributes, int nAttributes)
+{
+	if( pAttributes && nAttributes > 0 )
+	{
+		int		nCurrent	= pAttributes->Get_Count() / 3;
+
+		if( nCurrent < nAttributes )
+		{
+			for(int i=nCurrent; i<nAttributes; i++)
+			{
+				CSG_Parameter	*pNode	= pAttributes->Add_Node(
+					NULL	, GET_NODE(i), CSG_String::Format(SG_T("%i. %s"), i + 1, _TL("Attribute")), _TL("")
+				);
+
+				pAttributes->Add_String(
+					pNode	, GET_NAME(i), _TL("Name"), _TL(""), _TL("Name")
+				);
+
+				pAttributes->Add_Choice(
+					pNode	, GET_TYPE(i), _TL("Type"), _TL(""), m_Types
+				);
+			}
+		}
+		else if( nCurrent > nAttributes )
+		{
+			CSG_Parameters	Tmp;
+			Tmp.Assign(pAttributes);
+			pAttributes->Destroy();
+			pAttributes->Set_Name(Tmp.Get_Name());
+
+			for(int i=0; i<nAttributes; i++)
+			{
+				CSG_Parameter	*pNode	= pAttributes->Add_Node(
+					NULL	, GET_NODE(i), CSG_String::Format(SG_T("%i. %s"), i + 1, _TL("Attribute")), _TL("")
+				);
+
+				pAttributes->Add_String(
+					pNode	, GET_NAME(i), _TL("Name"), _TL(""), Tmp(GET_NAME(i)) ? Tmp(GET_NAME(i))->asString() : _TL("Name")
+				);
+
+				pAttributes->Add_Choice(
+					pNode	, GET_TYPE(i), _TL("Type"), _TL(""), m_Types, Tmp(GET_TYPE(i)) ? Tmp(GET_TYPE(i))->asInt() : 0
+				);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+int CShapes_Create_Empty::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("NFIELDS")) )
+	{
+		_Set_Field_Count(pParameters->Get_Parameter("FIELDS")->asParameters(), pParameter->asInt());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Create_Empty::On_Execute(void)
+{
+	CSG_Shapes	*pShapes;
+
+	switch( Parameters("TYPE")->asInt() )
+	{
+	default:	pShapes	= NULL;	break;
+	case 0:		pShapes	= SG_Create_Shapes(SHAPE_TYPE_Point  , Parameters("NAME")->asString());	break;
+	case 1:		pShapes	= SG_Create_Shapes(SHAPE_TYPE_Points , Parameters("NAME")->asString());	break;
+	case 2:		pShapes	= SG_Create_Shapes(SHAPE_TYPE_Line   , Parameters("NAME")->asString());	break;
+	case 3:		pShapes	= SG_Create_Shapes(SHAPE_TYPE_Polygon, Parameters("NAME")->asString());	break;
+	}
+
+	if( pShapes )
+	{
+		int						i, n;
+		TSG_Data_Type	Type;
+		CSG_Parameters			*pAttributes;
+
+		pAttributes	= Parameters("FIELDS")->asParameters();
+		n			= pAttributes->Get_Count() / 3;
+
+		for(i=0; i<n; i++)
+		{
+			switch( pAttributes->Get_Parameter(GET_TYPE(i))->asInt() )
+			{
+			default:
+			case 0:	Type	= SG_DATATYPE_String;	break;
+			case 1:	Type	= SG_DATATYPE_Char  ;	break;
+			case 2:	Type	= SG_DATATYPE_Short ;	break;
+			case 3:	Type	= SG_DATATYPE_Int   ;	break;
+			case 4:	Type	= SG_DATATYPE_Float ;	break;
+			case 5:	Type	= SG_DATATYPE_Double;	break;
+			case 6:	Type	= SG_DATATYPE_Color ;	break;
+			}
+
+			pShapes->Add_Field(pAttributes->Get_Parameter(GET_NAME(i))->asString(), Type);
+		}
+
+		Parameters("SHAPES")->Set_Value(pShapes);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Create_Empty.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,98 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Shapes_Create_Empty.h                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Create_Empty_H
+#define HEADER_INCLUDED__Shapes_Create_Empty_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Create_Empty : public CSG_Module  
+{
+public:
+	CShapes_Create_Empty(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("A:Shapes|Construction") );	}
+
+
+protected:
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	static CSG_String			m_Types;
+
+	void						_Set_Field_Count		(CSG_Parameters *pAttributes, int nAttributes);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Shapes_Create_Empty_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,357 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Shapes_Report.cpp                   //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//               Olaf Conrad, Victor Olaya               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/doc_pdf.h>
+#include "Shapes_Report.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Report::CShapes_Report(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Create PDF Report for Shapes Layer"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad, V.Olaya"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "SUBTITLE"	, _TL("Subtitle"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("PDF File"),
+		_TL(""),
+		_TL("PDF Files (*.pdf)|*.pdf|All Files|*.*"),
+		_TL(""), true, false
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "PAPER_SIZE"	, _TL("Paper Format"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("A4 Portrait"),
+			_TL("A4 Landscape"),
+			_TL("A3 Portrait"),
+			_TL("A3 Landscape")
+		)
+	);
+
+	Parameters.Add_Value(
+		pNode	, "COLOR_LINE"	, _TL("Line Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color, SG_COLOR_BLACK
+	);
+
+	Parameters.Add_Value(
+		pNode	, "COLOR_FILL"	, _TL("Fill Color"),
+		_TL(""),
+		PARAMETER_TYPE_Color, SG_COLOR_GREEN
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "NODE_LAYOUT"	, _TL("Layout"), _TL(""));
+
+	Parameters.Add_Choice(
+		pNode	, "LAYOUT_MODE"	, _TL("Layout"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("horizontal"),
+			_TL("vertical")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		pNode	, "LAYOUT_BREAK", _TL("Map/Table Size Ratio [%]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 50.0, 0.0, true, 100.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "NODE_TABLE"	, _TL("Attribute Table"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "COLUMNS"		, _TL("Columns"),
+		_TL("Number of atttribute table columns."),
+		PARAMETER_TYPE_Int, 2, 1, true
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "CELL_MODE"	, _TL("Cell Sizes"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("fit to page"),
+			_TL("fixed cell height")
+		)
+	);
+
+	Parameters.Add_Value(
+		pNode	, "CELL_HEIGHT"	, _TL("Cell Height"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 8, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Report::~CShapes_Report(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Report::On_Execute(void)
+{
+	int				Page_Orientation;
+	TSG_PDF_Page_Size	Page_Size;
+	CSG_String		FileName(Parameters("FILENAME")	->asString());
+	CSG_Doc_PDF	PDF;
+
+	//-----------------------------------------------------
+	m_pShapes		= Parameters("SHAPES")		->asShapes();
+	m_iSubtitle		= Parameters("SUBTITLE")	->asInt();
+	m_Color_Line	= Parameters("COLOR_LINE")	->asColor();
+	m_Color_Fill	= Parameters("COLOR_FILL")	->asColor();
+	m_nColumns		= Parameters("COLUMNS")		->asInt();
+
+	switch( Parameters("CELL_MODE")->asInt() )
+	{
+	default:
+	case 0:	m_Cell_Height	= 0;										break;
+	case 1:	m_Cell_Height	= Parameters("CELL_HEIGHT")->asDouble();	break;
+	}
+
+	switch( Parameters("PAPER_SIZE")->asInt() )
+	{
+	default:
+	case 0:	Page_Size	= PDF_PAGE_SIZE_A4;	Page_Orientation	= PDF_PAGE_ORIENTATION_PORTRAIT;	break;	// A4 Portrait
+	case 1:	Page_Size	= PDF_PAGE_SIZE_A4;	Page_Orientation	= PDF_PAGE_ORIENTATION_LANDSCAPE;	break;	// A4 Landscape
+	case 2:	Page_Size	= PDF_PAGE_SIZE_A3;	Page_Orientation	= PDF_PAGE_ORIENTATION_PORTRAIT;	break;	// A3 Portrait
+	case 3:	Page_Size	= PDF_PAGE_SIZE_A3;	Page_Orientation	= PDF_PAGE_ORIENTATION_LANDSCAPE;	break;	// A3 Landscape
+	}
+
+	//-----------------------------------------------------
+	if( FileName.Length() > 0 && PDF.Open(Page_Size, Page_Orientation, CSG_String::Format(SG_T("%s: %s"), _TL("Summary"), m_pShapes->Get_Name())) )
+	{
+		double	d	= Parameters("LAYOUT_BREAK")->asDouble();
+
+		switch( Parameters("LAYOUT_MODE")->asInt() )
+		{
+		default:
+		case 0:	// horizontal
+			PDF.Layout_Add_Box(  0,   0, 100,   5, "TITLE");
+			PDF.Layout_Add_Box(  0,   5,   d, 100, "SHAPE");
+			PDF.Layout_Add_Box(  d,   5, 100, 100, "TABLE");
+			break;
+
+		case 1:	// vertical
+			PDF.Layout_Add_Box(  0,   0, 100,   5, "TITLE");
+			PDF.Layout_Add_Box(  0,   5, 100,   d, "SHAPE");
+			PDF.Layout_Add_Box(  0,   d, 100, 100, "TABLE");
+			break;
+		}
+
+		m_pPDF		= &PDF;
+
+		m_rTitle	= PDF.Layout_Get_Box("TITLE");
+		m_rShape	= PDF.Layout_Get_Box("SHAPE");
+		m_rTable	= PDF.Layout_Get_Box("TABLE");
+		
+		return( Add_Shapes() && PDF.Save(FileName) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Report::Add_Shapes(void)
+{
+	if( m_pShapes && m_pShapes->is_Valid() && m_pPDF && m_pPDF->Add_Page() )
+	{
+		bool			bAddAll;
+		CSG_Rect		r(m_rShape), rWorld(m_pShapes->Get_Extent());
+		CSG_String		Title;
+		CSG_Strings	sLeft, sRight;
+
+		//-------------------------------------------------
+		m_pPDF->Draw_Text(m_rTitle.Get_XCenter(), m_rTitle.Get_YCenter(), _TL("Overview"), (int)(0.7 * m_rTitle.Get_YRange()), PDF_STYLE_TEXT_ALIGN_H_CENTER|PDF_STYLE_TEXT_ALIGN_V_CENTER|PDF_STYLE_TEXT_UNDERLINE);
+
+		//-------------------------------------------------
+		r.Deflate(10, false);
+		rWorld.Inflate(5, true);
+
+		m_pPDF->Draw_Shapes   (r, m_pShapes, PDF_STYLE_POLYGON_FILLSTROKE, m_Color_Fill, m_Color_Line, 0, &rWorld);
+		m_pPDF->Draw_Graticule(r, rWorld, 10);
+
+		//-------------------------------------------------
+		sLeft	.Add(CSG_String::Format(SG_T("%s:")	, _TL("Name")));
+		sRight	.Add(CSG_String::Format(SG_T("%s")	, m_pShapes->Get_Name()));
+		sLeft	.Add(CSG_String::Format(SG_T("%s:")	, _TL("Count")));
+		sRight	.Add(CSG_String::Format(SG_T("%d")	, m_pShapes->Get_Count()));
+
+		m_pPDF->Draw_Text(m_rTable.Get_XMin()   , m_rTable.Get_YMax(), sLeft , 8, PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP);
+		m_pPDF->Draw_Text(m_rTable.Get_XCenter(), m_rTable.Get_YMax(), sRight, 8, PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP);
+
+		//-------------------------------------------------
+		bAddAll	= m_pShapes->Get_Selection_Count() == 0;
+
+		for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
+		{
+			if( bAddAll || m_pShapes->Get_Record(iShape)->is_Selected() )
+			{
+				Title.Printf(SG_T("%s: %s"), m_pShapes->Get_Field_Name(m_iSubtitle), m_pShapes->Get_Shape(iShape)->asString(m_iSubtitle));
+
+				Add_Shape(m_pShapes->Get_Shape(iShape), Title);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CShapes_Report::Add_Shape(CSG_Shape *pShape, const SG_Char *Title)
+{
+	if( m_pPDF && m_pPDF->Is_Ready_To_Draw() && pShape && pShape->is_Valid() && m_pPDF->Add_Page() )
+	{
+		CSG_Rect	r(m_rShape), rWorld(pShape->Get_Extent());
+
+		//-------------------------------------------------
+		m_pPDF->Add_Outline_Item(Title);
+
+		m_pPDF->Draw_Text(m_rTitle.Get_XCenter(), m_rTitle.Get_YCenter(), Title, (int)(0.7 * m_rTitle.Get_YRange()), PDF_STYLE_TEXT_ALIGN_H_CENTER|PDF_STYLE_TEXT_ALIGN_V_CENTER|PDF_STYLE_TEXT_UNDERLINE);
+
+		r.Deflate(10, false);
+		rWorld.Inflate(5, true);
+
+		m_pPDF->Draw_Shape		(r, pShape, PDF_STYLE_POLYGON_FILLSTROKE, m_Color_Fill, m_Color_Line, 0, &rWorld);
+		m_pPDF->Draw_Graticule	(r, rWorld, 10);
+
+		//-------------------------------------------------
+		if( pShape->Get_Table()->Get_Field_Count() > 0 )
+		{
+			CSG_Table_Record	*pRecord;
+			CSG_Table			Table;
+
+			Table.Set_Name(_TL("Attributes"));
+
+			Table.Add_Field(_TL("Attribute"), SG_DATATYPE_String);
+			Table.Add_Field(_TL("Value")	, SG_DATATYPE_String);
+
+			for(int iField=0; iField<pShape->Get_Table()->Get_Field_Count(); iField++)
+			{
+				pRecord	= Table.Add_Record();
+
+				pRecord->Set_Value(0, pShape->Get_Table()->Get_Field_Name(iField));
+				pRecord->Set_Value(1, pShape->asString(iField));
+			}
+
+			m_pPDF->Draw_Table(m_rTable, &Table, m_nColumns, m_Cell_Height, 0.0);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/Shapes_Report.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Shapes_Report.h                    //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//               Olaf Conrad, Victor Olaya               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Report_H
+#define HEADER_INCLUDED__Shapes_Report_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Report : public CSG_Module
+{
+public:
+	CShapes_Report(void);
+	virtual ~CShapes_Report(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("A:Shapes|Reports") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	int						m_iSubtitle, m_nColumns, m_Color_Line, m_Color_Fill;
+
+	double					m_Cell_Height;
+
+	CSG_Rect				m_rTitle, m_rShape, m_rTable;
+
+	CSG_Shapes					*m_pShapes;
+
+	class CSG_Doc_PDF		*m_pPDF;
+
+
+	bool					Add_Shapes			(void);
+	bool					Add_Shape			(CSG_Shape *pShape, const SG_Char *Title);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Report_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,213 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 quadtree_structure.cpp                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "quadtree_structure.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CQuadTree_Structure::CQuadTree_Structure(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("QuadTree Structure to Shapes"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ATTRIBUTE"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+}
+
+//---------------------------------------------------------
+bool CQuadTree_Structure::On_Execute(void)
+{
+	CSG_PRQuadTree	QT(Parameters("SHAPES")->asShapes(), Parameters("ATTRIBUTE")->asInt());
+
+	Get_Shapes(Parameters("LINES")		->asShapes(), (CSG_PRQuadTree_Item *)&QT.Get_Root(), SHAPE_TYPE_Line);
+	Get_Shapes(Parameters("POLYGONS")	->asShapes(), (CSG_PRQuadTree_Item *)&QT.Get_Root(), SHAPE_TYPE_Polygon);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CQuadTree_Structure::Get_Shapes(CSG_Shapes *pShapes, CSG_PRQuadTree_Item *pItem, TSG_Shape_Type Type)
+{
+	CSG_Shape	*pShape;
+
+	if( pItem )
+	{
+		switch( Type )
+		{
+		default:
+			return( false );
+
+		case SHAPE_TYPE_Line:
+			pShapes->Create(SHAPE_TYPE_Line, _TL("QuadTree - Lines"));
+			pShapes->Add_Field("LEVEL", SG_DATATYPE_Int);
+
+			pShape	= pShapes->Add_Shape();
+			pShape->Set_Value(0, 0.0);
+			pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMin());
+			pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMax());
+			pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yMax());
+			pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yMin());
+			pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMin());
+			break;
+
+		case SHAPE_TYPE_Polygon:
+			pShapes->Create(SHAPE_TYPE_Polygon, _TL("QuadTree - Squares"));
+			pShapes->Add_Field("LEVEL", SG_DATATYPE_Int);
+			pShapes->Add_Field("VALUE", SG_DATATYPE_Double);
+			break;
+		}
+
+		Get_Shapes(pShapes, pItem, 1);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CQuadTree_Structure::Get_Shapes(CSG_Shapes *pShapes, CSG_PRQuadTree_Item *pItem, int Level)
+{
+	if( pItem )
+	{
+		if( pShapes->Get_Type() == SHAPE_TYPE_Line )
+		{
+			if( pItem->is_Node() )
+			{
+				CSG_Shape	*pShape	= pShapes->Add_Shape();
+				pShape->Set_Value(0, Level);
+				pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yCenter(), 0);
+				pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yCenter(), 0);
+				pShape->Add_Point(pItem->Get_xCenter(), pItem->Get_yMin(), 1);
+				pShape->Add_Point(pItem->Get_xCenter(), pItem->Get_yMax(), 1);
+
+				for(int i=0; i<4; i++)
+				{
+					Get_Shapes(pShapes, pItem->asNode()->Get_Child(i), Level + 1);
+				}
+			}
+		}
+
+		if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
+		{
+			if( pItem->is_Node() )
+			{
+				for(int i=0; i<4; i++)
+				{
+					Get_Shapes(pShapes, pItem->asNode()->Get_Child(i), Level + 1);
+				}
+			}
+			else // if( pItem->is_Leaf() )
+			{
+				CSG_Shape	*pShape	= pShapes->Add_Shape();
+				pShape->Set_Value(0, Level + 1);
+				pShape->Set_Value(1, pItem->asLeaf()->Get_Z());
+				pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMin());
+				pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMax());
+				pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yMax());
+				pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yMin());
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/quadtree_structure.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    quadtree_structure.h                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__quadtree_structure_H
+#define HEADER_INCLUDED__quadtree_structure_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CQuadTree_Structure : public CSG_Module
+{
+public:
+	CQuadTree_Structure(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	bool					Get_Shapes		(CSG_Shapes *pShapes, CSG_PRQuadTree_Item *pItem, TSG_Shape_Type Type);
+	void					Get_Shapes		(CSG_Shapes *pShapes, CSG_PRQuadTree_Item *pItem, int Level);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__quadtree_structure_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,803 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Shapes_Buffer.cpp                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes_buffer.h"
+
+#include "Polygon_Clipper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Buffer::CShapes_Buffer(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Shapes Buffer"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"A vector based buffer construction partly based on the method supposed by Dong et al. 2003. "
+		"\n\n"
+		"References:\n"
+		"Dong, P, Yang, C., Rui, X., Zhang, L., Cheng, Q. (2003): "
+		"'An effective buffer generation method in GIS'. "
+		"Geoscience and Remote Sensing Symposium, 2003. "
+		"IGARSS '03. Proceedings. 2003 IEEE International, Vol.6, p.3706-3708.\n"
+		"<a href=\"http://ieeexplore.ieee.org/iel5/9010/28606/01295244.pdf\">online version</a>\n"
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "BUFFER"		, _TL("Buffer"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "BUF_TYPE"	, _TL("Buffer Distance"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("fix value"),
+			_TL("attribute field")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BUF_DIST"	, _TL("Buffer Distance (Fixed)"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "BUF_FIELD"	, _TL("Buffer Distance (Attribute)"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BUF_SCALE"	, _TL("Scaling Factor for Attribute Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BUF_ZONES"	, _TL("Number of Buffer Zones"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DCIRCLE"		, _TL("Circle Point Distance [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 5.0, 0.01, true, 45.0, true
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Buffer::~CShapes_Buffer(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Buffer::On_Execute(void)
+{
+	int			nZones;
+	CSG_Shapes	*pBuffers;
+
+	pBuffers	= Parameters("BUFFER")		->asShapes();
+	nZones		= Parameters("BUF_ZONES")	->asInt();
+
+	if( Initialise() )
+	{
+		if( nZones == 1 )
+		{
+			Get_Buffers(pBuffers, 1.0);
+		}
+
+		//-------------------------------------------------
+		else if( nZones > 1 )
+		{
+			double		dZone		= 1.0 / nZones;
+			CSG_Shape	*pBuffer;
+			CSG_Shapes	Buffers;
+
+			pBuffers->Create(SHAPE_TYPE_Polygon);
+			pBuffers->Add_Field(_TL("ID")	, SG_DATATYPE_Int);
+			pBuffers->Add_Field(_TL("ZONE")	, SG_DATATYPE_Double);
+
+			for(int iZone=0; iZone<nZones; iZone++)
+			{
+				Get_Buffers(&Buffers, (nZones - iZone) * dZone);
+
+				if( iZone > 0 )
+				{
+					GPC_Difference(pBuffer, Buffers.Get_Shape(0));
+				}
+
+				pBuffer	= pBuffers->Add_Shape(Buffers.Get_Shape(0));
+				pBuffer	->Set_Value(0, (nZones - iZone) + 1);
+				pBuffer	->Set_Value(1, (nZones - iZone) * dZone * 100.0);
+			}
+		}
+
+		Finalise();
+
+		pBuffers->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pShapes->Get_Name(), _TL("Buffer")));
+
+		return( pBuffers->is_Valid() );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Get_Buffers(CSG_Shapes *pBuffers, double dZone)
+{
+	//-----------------------------------------------------
+	if( pBuffers )
+	{
+		pBuffers	->Create(SHAPE_TYPE_Polygon);
+		pBuffers	->Add_Field(_TL("ID"), SG_DATATYPE_Int);
+		m_pBuffer	= pBuffers->Add_Shape();
+		m_pBuffer	->Set_Value(0, 1);
+
+		m_Distance	= dZone * Parameters("BUF_DIST")	->asDouble();
+		m_Scale		= dZone * Parameters("BUF_SCALE")	->asDouble();
+		m_ID		= 0;
+
+		for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape	= m_pShapes->Get_Shape(iShape);
+
+			if( m_Type == 0 || (m_Distance = m_Scale * pShape->asDouble(m_Field)) > 0.0 )
+			{
+				switch( m_pShapes->Get_Type() )
+				{
+				case SHAPE_TYPE_Point:		Get_Buffer_Point	(pShape);	break;
+				case SHAPE_TYPE_Points:		Get_Buffer_Points	(pShape);	break;
+				case SHAPE_TYPE_Line:		Get_Buffer_Line		(pShape);	break;
+				case SHAPE_TYPE_Polygon:	Get_Buffer_Polygon	(pShape);	break;
+				}
+			}
+		}
+
+		return( pBuffers->is_Valid() );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Initialise(void)
+{
+	//-----------------------------------------------------
+	m_pShapes	= Parameters("SHAPES")		->asShapes();
+	m_Type		= Parameters("BUF_TYPE")	->asInt();
+	m_Field		= Parameters("BUF_FIELD")	->asInt();
+	m_dArc		= Parameters("DCIRCLE")		->asDouble() * M_DEG_TO_RAD;
+
+	//-----------------------------------------------------
+	if( m_Type == 0 && Parameters("BUF_DIST")->asDouble() <= 0.0 )
+	{
+		Message_Add(_TL("Invalid Buffer Distance"));
+	}
+	else if( !m_pShapes->is_Valid() )
+	{
+		Message_Add(_TL("Invalid Shapes"));
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		m_Tmp.Create(SHAPE_TYPE_Polygon);
+
+		m_pSegment	= m_Tmp.Add_Shape();
+		m_pUnion	= m_Tmp.Add_Shape();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Finalise(void)
+{
+	m_Tmp.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Get_Buffer_Point(CSG_Shape *pPoint)
+{
+	m_pSegment->Del_Parts();
+
+	Add_Arc(pPoint->Get_Point(0), 0.0, M_PI_360);
+
+	Add_Buffer();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Get_Buffer_Points(CSG_Shape *pPoints)
+{
+	for(int iPart=0; iPart<pPoints->Get_Part_Count(); iPart++)
+	{
+		for(int iPoint=0; iPoint<pPoints->Get_Point_Count(iPart); iPoint++)
+		{
+			m_pSegment->Del_Parts();
+
+			Add_Arc(pPoints->Get_Point(iPoint), 0.0, M_PI_360);
+
+			Add_Buffer();
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Get_Buffer_Line(CSG_Shape *pLine)
+{
+	Del_Duplicates(pLine);
+
+	for(int iPart=0; iPart<pLine->Get_Part_Count(); iPart++)
+	{
+		m_pSegment->Del_Parts();
+
+		Add_Line((CSG_Shape_Line *)pLine, iPart);
+
+		Add_Buffer();
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CShapes_Buffer::Get_Buffer_Polygon(CSG_Shape *pPolygon)
+{
+	int		iPart;
+
+	Del_Duplicates(pPolygon);
+
+	for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+	{
+		if( ((CSG_Shape_Polygon *)pPolygon)->is_Lake(iPart) == false )
+		{
+			m_pSegment->Del_Parts();
+
+			Add_Polygon((CSG_Shape_Polygon *)pPolygon, iPart);
+
+			Add_Buffer();
+		}
+	}
+
+	for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+	{
+		if( ((CSG_Shape_Polygon *)pPolygon)->is_Lake(iPart) == true )
+		{
+			m_pSegment->Del_Parts();
+
+			Add_Polygon((CSG_Shape_Polygon *)pPolygon, iPart);
+
+			Add_Buffer(true);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CShapes_Buffer::Get_Direction(const TSG_Point &From, const TSG_Point &To)
+{
+	double	dx	= To.x - From.x;
+	double	dy	= To.y - From.y;
+
+	return(	dx != 0.0 ?	M_PI_180 + atan2(dy, dx)	: (
+			dy  > 0.0 ?	M_PI_270					: (
+			dy  < 0.0 ?	M_PI_090					:
+						0.0							) )
+	);
+}
+
+
+//---------------------------------------------------------
+inline void CShapes_Buffer::Add_Vertex(const TSG_Point &Center, double theta)
+{
+	m_pSegment->Add_Point(
+		Center.x + m_Distance * cos(theta),
+		Center.y + m_Distance * sin(theta)
+	);
+}
+
+//---------------------------------------------------------
+void CShapes_Buffer::Add_Arc(const TSG_Point &Center, double alpha, double beta)
+{
+	double	theta;
+
+	if( alpha < beta )
+	{
+		for(theta=alpha; theta<beta; theta+=m_dArc)
+		{
+			Add_Vertex(Center, theta);
+		}
+	}
+	else
+	{
+		for(theta=alpha; theta>beta; theta-=m_dArc)
+		{
+			Add_Vertex(Center, theta);
+		}
+	}
+
+	Add_Vertex(Center, beta);
+}
+
+//---------------------------------------------------------
+void CShapes_Buffer::Add_Arc(const TSG_Point &Center, const TSG_Point &A, const TSG_Point &B)
+{
+	double	alpha, beta;
+
+	alpha	= Get_Direction(A, Center);
+	beta	= Get_Direction(B, Center);
+
+	if( alpha - beta >= M_PI_180 )
+	{
+		beta	+= M_PI_360;
+	}
+
+	Add_Arc(Center, alpha, beta);
+}
+
+//---------------------------------------------------------
+inline bool CShapes_Buffer::Get_Parallel(const TSG_Point &A, const TSG_Point &B, TSG_Point AB[2])
+{
+	double		d;
+	TSG_Point	C;
+
+	if( (d = SG_Get_Distance(A, B)) > 0.0 )
+	{
+		d		= m_Distance / d;
+
+		C.x		= d * (A.y - B.y);
+		C.y		= d * (B.x - A.x);
+
+		AB[0].x	= A.x + C.x;
+		AB[0].y	= A.y + C.y;
+
+		AB[1].x	= B.x + C.x;
+		AB[1].y	= B.y + C.y;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CShapes_Buffer::Del_Duplicates(CSG_Shape *pShape)
+{
+	int			iPart, iPoint;
+	CSG_Point	A, B;
+
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		B	= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+
+		for(iPoint=pShape->Get_Point_Count(iPart)-2; iPoint>=0; iPoint--)
+		{
+			A	= pShape->Get_Point(iPoint, iPart);
+
+			if( A == B )
+			{
+				pShape->Del_Point(iPoint, iPart);
+			}
+			else
+			{
+				B	= A;
+			}
+		}
+
+		if( pShape->Get_Type() == SHAPE_TYPE_Polygon )
+		{
+			iPoint	= pShape->Get_Point_Count(iPart) - 1;
+
+			A	= pShape->Get_Point(iPoint, iPart);
+			B	= pShape->Get_Point(0     , iPart);
+
+			if( A == B )
+			{
+				pShape->Del_Point(iPoint, iPart);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes_Buffer::Add_Line(CSG_Shape_Line *pShape, int iPart)
+{
+	int			iPoint, n	= pShape->Get_Point_Count(iPart);
+	double		a;
+	TSG_Point	A, B, C, AB[2], BC[2];
+
+	//-----------------------------------------------------
+	B	= pShape->Get_Point(0, iPart);
+	A	= pShape->Get_Point(1, iPart);
+
+	Get_Parallel(A, B, AB);
+
+	for(iPoint=2; iPoint<n; iPoint++)
+	{
+		B	= A;
+		A	= pShape->Get_Point(iPoint, iPart);
+
+		BC[0]	= AB[0];
+		BC[1]	= AB[1];
+
+		Get_Parallel(A, B, AB);
+
+		if( SG_Get_Crossing(C, AB[0], AB[1], BC[0], BC[1]) )
+			m_pSegment->Add_Point(C);
+		else
+			Add_Arc(B, BC[0], AB[1]);
+	}
+
+	a	= Get_Direction(A, B);
+	Add_Arc(A, a - M_PI_090, a + M_PI_090);
+
+	//-----------------------------------------------------
+	B	= pShape->Get_Point(n - 1, iPart);
+	A	= pShape->Get_Point(n - 2, iPart);
+
+	Get_Parallel(A, B, AB);
+
+	for(iPoint=n-3; iPoint>=0; iPoint--)
+	{
+		B	= A;
+		A	= pShape->Get_Point(iPoint, iPart);
+
+		BC[0]	= AB[0];
+		BC[1]	= AB[1];
+
+		Get_Parallel(A, B, AB);
+
+		if( SG_Get_Crossing(C, AB[0], AB[1], BC[0], BC[1]) )
+			m_pSegment->Add_Point(C);
+		else
+			Add_Arc(B, BC[0], AB[1]);
+	}
+
+	a	= Get_Direction(A, B);
+	Add_Arc(A, a - M_PI_090, a + M_PI_090);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes_Buffer::Add_Polygon(CSG_Shape_Polygon *pShape, int iPart)
+{
+	int			iPoint, n	= pShape->Get_Point_Count(iPart);
+	TSG_Point	A, B, C, AB[2], BC[2];
+
+	//-----------------------------------------------------
+	bool	bClockwise	= pShape->is_Lake(iPart) ? pShape->is_Clockwise(iPart) : !pShape->is_Clockwise(iPart);
+
+	//-----------------------------------------------------
+	if( bClockwise )
+	{
+		B	= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+		A	= pShape->Get_Point(0, iPart);
+
+		Get_Parallel(A, B, AB);
+
+		for(iPoint=1; iPoint<=n; iPoint++)
+		{
+			B	= A;
+			A	= pShape->Get_Point(iPoint < n ? iPoint : 0, iPart);
+
+			BC[0]	= AB[0];
+			BC[1]	= AB[1];
+
+			Get_Parallel(A, B, AB);
+
+			if( SG_Get_Crossing(C, AB[0], AB[1], BC[0], BC[1]) )
+				m_pSegment->Add_Point(C);
+			else
+				Add_Arc(B, BC[0], AB[1]);
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		B	= pShape->Get_Point(0    , iPart);
+		A	= pShape->Get_Point(n - 1, iPart);
+
+		Get_Parallel(A, B, AB);
+
+		for(iPoint=n-2; iPoint>=-1; iPoint--)
+		{
+			B	= A;
+			A	= pShape->Get_Point(iPoint >= 0 ? iPoint : n - 1, iPart);
+
+			BC[0]	= AB[0];
+			BC[1]	= AB[1];
+
+			Get_Parallel(A, B, AB);
+
+			if( SG_Get_Crossing(C, AB[0], AB[1], BC[0], BC[1]) )
+				m_pSegment->Add_Point(C);
+			else
+				Add_Arc(B, BC[0], AB[1]);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes_Buffer::Add_Buffer(bool bLake)
+{
+	Get_SelfIntersection();
+
+	if( m_pUnion->is_Valid() )
+	{
+		if( m_pBuffer->Get_Part_Count() )
+		{
+			if( bLake )
+			{
+				for(int iPart=m_pUnion->Get_Part_Count()-1; iPart>=0; iPart--)
+				{
+					if( ((CSG_Shape_Polygon *)m_pUnion)->is_Clockwise(iPart) == false )
+					{
+						m_pUnion->Del_Part(iPart);
+					}
+				}
+
+				if( m_pUnion->Get_Part_Count() > 0 )
+				{
+					GPC_Difference(m_pBuffer, m_pUnion);
+				}
+			}
+			else
+			{
+				GPC_Union(m_pBuffer, m_pUnion);
+			}
+		}
+		else
+		{
+			m_pBuffer->Assign(m_pUnion, false);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CShapes_Buffer::Get_SelfIntersection(void)
+{
+	int		iPart, iMax;
+	double	dMax;
+
+	m_pUnion->Del_Parts();
+
+	Get_SelfIntersection((CSG_Shape_Polygon *)m_pSegment);
+
+	for(iPart=0, iMax=-1; iPart<m_pUnion->Get_Part_Count(); iPart++)
+	{
+		if( ((CSG_Shape_Polygon *)m_pUnion)->is_Clockwise(iPart) == false )
+		{
+			if( iMax < 0 || dMax < ((CSG_Shape_Polygon *)m_pUnion)->Get_Area(iPart) )
+			{
+				iMax	= iPart;
+				dMax	= ((CSG_Shape_Polygon *)m_pUnion)->Get_Area(iPart);
+			}
+		}
+	}
+
+	for(iPart=m_pUnion->Get_Part_Count()-1; iPart>=0; iPart--)
+	{
+		if(  ((CSG_Shape_Polygon *)m_pUnion)->Get_Area(iPart) == 0.0
+		||	(((CSG_Shape_Polygon *)m_pUnion)->is_Clockwise(iPart) == false && iPart != iMax) )
+		{
+			m_pUnion->Del_Part(iPart);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CShapes_Buffer::Get_SelfIntersection(CSG_Shape_Polygon *pSegment)
+{
+	if( pSegment->Get_Point_Count(0) >= 3 )
+	{
+		int			i, j, k;
+		TSG_Point	A[2], B[2], C;
+		CSG_Shape	*pPolygon;
+		CSG_Shapes	Points;
+
+		A[0]	= pSegment->Get_Point(0);
+
+		for(i=1; i<pSegment->Get_Point_Count(0)-2; i++)
+		{
+			A[1]	= A[0];
+			A[0]	= pSegment->Get_Point(i);
+
+			B[0]	= pSegment->Get_Point(i + 1);
+
+			for(j=i+2; j<pSegment->Get_Point_Count(0); j++)
+			{
+				B[1]	= B[0];
+				B[0]	= pSegment->Get_Point(j);
+
+				//-----------------------------------------
+				if( SG_Get_Crossing(C, A[0], A[1], B[0], B[1]) )
+				{
+					Points.Create(SHAPE_TYPE_Polygon);
+					pPolygon	= Points.Add_Shape();
+					pPolygon->Add_Point(C);
+
+					for(k=i; k<j; k++)
+						pPolygon->Add_Point(pSegment->Get_Point(k));
+
+					Get_SelfIntersection((CSG_Shape_Polygon *)pPolygon);
+
+					//-------------------------------------
+					Points.Create(SHAPE_TYPE_Polygon);
+					pPolygon	= Points.Add_Shape();
+					pPolygon->Add_Point(C);
+
+					for(k=j; k<pSegment->Get_Point_Count(0); k++)
+						pPolygon->Add_Point(pSegment->Get_Point(k));
+
+					for(k=0; k<i; k++)
+						pPolygon->Add_Point(pSegment->Get_Point(k));
+
+					Get_SelfIntersection((CSG_Shape_Polygon *)pPolygon);
+
+					return;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		int		iPart	= m_pUnion->Get_Part_Count();
+
+		for(i=0; i<pSegment->Get_Point_Count(0); i++)
+		{
+			m_pUnion->Add_Point(pSegment->Get_Point(i), iPart);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_buffer.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Shapes_Buffer.h                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Buffer_H
+#define HEADER_INCLUDED__Shapes_Buffer_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Buffer : public CSG_Module
+{
+public:
+	CShapes_Buffer(void);
+	virtual ~CShapes_Buffer(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+	bool						Initialise				(void);
+	bool						Finalise				(void);
+
+	bool						Get_Buffers				(CSG_Shapes *pBuffers, double dZone);
+
+
+private:
+
+	int							m_ID, m_Type, m_Field;
+
+	double						m_Distance, m_dArc, m_Scale;
+
+	CSG_Shape					*m_pSegment, *m_pUnion, *m_pBuffer;
+
+	CSG_Shapes					*m_pShapes, m_Tmp;
+
+
+	bool						Get_Buffer_Point		(CSG_Shape *pPoint);
+	bool						Get_Buffer_Points		(CSG_Shape *pPoints);
+	bool						Get_Buffer_Line			(CSG_Shape *pLine);
+	bool						Get_Buffer_Polygon		(CSG_Shape *pPolygon);
+
+	double						Get_Direction			(const TSG_Point &From, const TSG_Point &To);
+
+	void						Add_Vertex				(const TSG_Point &Center, double theta);
+	void						Add_Arc					(const TSG_Point &Center, double alpha, double beta);
+	void						Add_Arc					(const TSG_Point &Center, const TSG_Point &A, const TSG_Point &B);
+	bool						Get_Parallel			(const TSG_Point &A, const TSG_Point &B, TSG_Point AB[2]);
+	void						Del_Duplicates			(CSG_Shape *pShape);
+
+	void						Add_Line				(CSG_Shape_Line    *pShape, int iPart);
+	void						Add_Polygon				(CSG_Shape_Polygon *pShape, int iPart);
+
+	void						Add_Buffer				(bool bLake = false);
+
+	void						Get_SelfIntersection	(void);
+	void						Get_SelfIntersection	(CSG_Shape_Polygon *pSegment);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Buffer_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,561 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Shapes_Cut.cpp                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "shapes_cut.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool Cut_Shapes(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes, CSG_Shapes *pCut)
+{
+	if( pCut && pShapes && pShapes->is_Valid() && pPolygons && pPolygons->is_Valid() && pPolygons->Get_Extent().Intersects(pShapes->Get_Extent()) )
+	{
+		pCut->Create(
+			pShapes->Get_Type(),
+			CSG_String::Format(SG_T("%s [%s]"), pShapes->Get_Name(), _TL("Cut")),
+			pShapes
+		);
+
+		for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			bool		bAdd;
+			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+			if( Method == 2 )		// center
+			{
+				bAdd	= false;
+
+				TSG_Point	Center;
+
+				if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
+					Center	= ((CSG_Shape_Polygon *)pShape)->Get_Centroid();
+				else
+					Center	= pShape->Get_Extent().Get_Center();
+
+				if( pPolygons->Select(Center) )
+				{
+					bAdd	= true;
+				}
+			}
+			else if( Method == 1 )	// intersects
+			{
+				bAdd	= false;
+
+				for(int iPart=0; iPart<pShape->Get_Part_Count() && !bAdd; iPart++)
+				{
+					for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart) && !bAdd; iPoint++)
+					{
+						if( pPolygons->Select(pShape->Get_Point(iPoint, iPart)) )
+						{
+							bAdd	= true;
+						}
+					}
+				}
+			}
+			else					// completely contained
+			{
+				bAdd	= true;
+
+				for(int iPart=0; iPart<pShape->Get_Part_Count() && bAdd; iPart++)
+				{
+					for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart) && bAdd; iPoint++)
+					{
+						if( pPolygons->Select(pShape->Get_Point(iPoint, iPart)) == false )
+						{
+							bAdd	= false;
+						}
+					}
+				}
+			}
+
+			if( bAdd )
+			{
+				pCut->Add_Shape(pShape);
+			}
+		}
+
+		return( pCut->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool Cut_Shapes(CSG_Rect Extent, int Method, CSG_Shapes *pShapes, CSG_Shapes *pCut)
+{
+	if( pCut && pShapes && pShapes->is_Valid() && Extent.Intersects(pShapes->Get_Extent()) )
+	{
+		pCut->Create(
+			pShapes->Get_Type(),
+			CSG_String::Format(SG_T("%s [%s]"), pShapes->Get_Name(), _TL("Cut")),
+			pShapes
+		);
+
+		for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			bool		bAdd;
+			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+			if( Method == 2 )	// center
+			{
+				bAdd	= pShapes->Get_Type() == SHAPE_TYPE_Polygon
+						? Extent.Contains(((CSG_Shape_Polygon *)pShape)->Get_Centroid())
+						: Extent.Contains(pShape->Get_Extent().Get_Center());
+			}
+			else				// completely contained, intersects
+			{
+				switch( pShape->Intersects(Extent) )
+				{
+				case INTERSECTION_Identical:
+				case INTERSECTION_Contained:
+					bAdd	= true;
+					break;
+
+				case INTERSECTION_Overlaps:
+				case INTERSECTION_Contains:
+					bAdd	= Method == 1;
+					break;
+
+				default:
+					bAdd	= false;
+					break;
+				}
+			}
+
+			if( bAdd )
+			{
+				pCut->Add_Shape(pShape);
+			}
+		}
+
+		return( pCut->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Shapes * Cut_Shapes(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes)
+{
+	CSG_Shapes	*pCut	= SG_Create_Shapes();
+
+	if( Cut_Shapes(pPolygons, Method, pShapes, pCut) )
+	{
+		return( pCut );
+	}
+
+	delete(pCut);
+
+	return( NULL );
+}
+
+CSG_Shapes * Cut_Shapes(CSG_Rect Extent, int Method, CSG_Shapes *pShapes)
+{
+	CSG_Shapes	*pCut	= SG_Create_Shapes();
+
+	if( Cut_Shapes(Extent, Method, pShapes, pCut) )
+	{
+		return( pCut );
+	}
+
+	delete(pCut);
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_String Cut_Methods_Str(void)
+{
+	return( CSG_String::Format(SG_T("%s|%s|%s|"),
+		_TL("completely contained"),
+		_TL("intersects"),
+		_TL("center"))
+	);
+}
+
+//---------------------------------------------------------
+bool Cut_Set_Extent(CSG_Rect Extent, CSG_Shapes *pExtent, bool bClear)
+{
+	if( pExtent )
+	{
+		if( bClear )
+		{
+			pExtent->Create(SHAPE_TYPE_Polygon, _TL("Extent [Cut]"));
+			pExtent->Add_Field("ID", SG_DATATYPE_Int);
+		}
+
+		if( pExtent->Get_Type() == SHAPE_TYPE_Polygon )
+		{
+			CSG_Shape	*pShape	= pExtent->Add_Shape();
+
+			pShape->Set_Value(SG_T("ID"), pExtent->Get_Count());
+
+			pShape->Add_Point(Extent.Get_XMin(), Extent.Get_YMin());
+			pShape->Add_Point(Extent.Get_XMin(), Extent.Get_YMax());
+			pShape->Add_Point(Extent.Get_XMax(), Extent.Get_YMax());
+			pShape->Add_Point(Extent.Get_XMax(), Extent.Get_YMin());
+			pShape->Add_Point(Extent.Get_XMin(), Extent.Get_YMin());
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Cut::CShapes_Cut(void)
+{
+	Set_Name		(_TL("Cut Shapes Layer"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2006"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes_List(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL	, "CUT"			, _TL("Cut"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "EXTENT"		, _TL("Extent"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		Cut_Methods_Str(), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TARGET"		, _TL("Extent"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("user defined"),
+			_TL("grid project"),
+			_TL("shapes layer extent"),
+			_TL("polygons")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters;
+
+	pParameters	= Add_Parameters("CUT", _TL("Extent"), _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "AX"	, _TL("Left")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "BX"	, _TL("Right")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "AY"	, _TL("Bottom")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "BY"	, _TL("Top")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "DX"	, _TL("Horizontal Range")	, _TL(""), PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	pParameters->Add_Value(
+		NULL, "DY"	, _TL("Vertical Range")		, _TL(""), PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	pParameters	= Add_Parameters("GRID", _TL("Extent"), _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL, "GRID", _TL("Grid Project")		, _TL("")
+	);
+
+	pParameters	= Add_Parameters("SHAPES", _TL("Extent"), _TL(""));
+
+	pParameters->Add_Shapes(
+		NULL, "SHAPES", _TL("Shapes")			, _TL(""), PARAMETER_INPUT
+	);
+
+	pParameters	= Add_Parameters("POLYGONS", _TL("Polygons"), _TL(""));
+
+	pParameters->Add_Shapes(
+		NULL, "POLYGONS", _TL("Polygons")		, _TL(""), PARAMETER_INPUT, SHAPE_TYPE_Polygon
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Cut::On_Execute(void)
+{
+	int							Method;
+	CSG_Shapes					*pExtent, *pCut;
+	CSG_Parameter_Shapes_List	*pShapes, *pCuts;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapesList();
+	pCuts	= Parameters("CUT")		->asShapesList();
+	pExtent	= Parameters("EXTENT")	->asShapes();
+	Method	= Parameters("METHOD")	->asInt();
+
+	//-----------------------------------------------------
+	if( pShapes->Get_Count() > 0 )
+	{
+		int			iLayer;
+		CSG_Rect	r(pShapes->asShapes(0)->Get_Extent());
+
+		for(iLayer=1; iLayer<pShapes->Get_Count(); iLayer++)
+		{
+			r.Union(pShapes->asShapes(iLayer)->Get_Extent());
+		}
+
+		if( Get_Extent(r) )
+		{
+			pCuts->Del_Items();
+
+			Cut_Set_Extent(r, pExtent, true);
+
+			for(iLayer=0; iLayer<pShapes->Get_Count(); iLayer++)
+			{
+				if( m_pPolygons )
+				{
+					if( Cut_Shapes(m_pPolygons, Method, pShapes->asShapes(iLayer), pCut = SG_Create_Shapes()) )
+						pCuts->Add_Item(pCut);
+					else
+						delete(pCut);
+				}
+				else
+				{
+					if( Cut_Shapes(r, Method, pShapes->asShapes(iLayer), pCut = SG_Create_Shapes()) )
+						pCuts->Add_Item(pCut);
+					else
+						delete(pCut);
+				}
+			}
+
+			return( pCuts->Get_Count() > 0 );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Cut::Get_Extent(CSG_Rect &r)
+{
+	m_pPolygons	= NULL;
+
+	switch( Parameters("TARGET")->asInt() )
+	{
+	//-----------------------------------------------------
+	case 0:	// user defined
+		Get_Parameters("CUT")->Get_Parameter("AX")->Set_Value(r.Get_XMin());
+		Get_Parameters("CUT")->Get_Parameter("AY")->Set_Value(r.Get_YMin());
+		Get_Parameters("CUT")->Get_Parameter("BX")->Set_Value(r.Get_XMax());
+		Get_Parameters("CUT")->Get_Parameter("BY")->Set_Value(r.Get_YMax());
+		Get_Parameters("CUT")->Get_Parameter("DX")->Set_Value(r.Get_XRange());
+		Get_Parameters("CUT")->Get_Parameter("DY")->Set_Value(r.Get_YRange());
+
+		if( Dlg_Parameters("CUT") )
+		{
+			r.Assign(
+				Get_Parameters("CUT")->Get_Parameter("AX")->asDouble(),
+				Get_Parameters("CUT")->Get_Parameter("AY")->asDouble(),
+				Get_Parameters("CUT")->Get_Parameter("BX")->asDouble(),
+				Get_Parameters("CUT")->Get_Parameter("BY")->asDouble()
+			);
+
+			return( true );
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 1:	// grid project
+		if( Dlg_Parameters("GRID") )
+		{
+			r.Assign(Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid_System()->Get_Extent());
+
+			return( true );
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 2:	// shapes extent
+		if( Dlg_Parameters("SHAPES") )
+		{
+			r.Assign(Get_Parameters("SHAPES")->Get_Parameter("SHAPES")->asShapes()->Get_Extent());
+
+			return( true );
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 3:	// polygons
+		if( Dlg_Parameters("POLYGONS") )
+		{
+			r.Assign(Get_Parameters("POLYGONS")->Get_Parameter("POLYGONS")->asShapes()->Get_Extent());
+
+			m_pPolygons	= Get_Parameters("POLYGONS")->Get_Parameter("POLYGONS")->asShapes();
+
+			return( true );
+		}
+		break;
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+int CShapes_Cut::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	if( !SG_STR_CMP(pParameters->Get_Identifier(), SG_T("CUT")) )
+	{
+		double	ax, ay, bx, by, dx, dy, d;
+
+		ax	= pParameters->Get_Parameter("AX")->asDouble();
+		ay	= pParameters->Get_Parameter("AY")->asDouble();
+		bx	= pParameters->Get_Parameter("BX")->asDouble();
+		by	= pParameters->Get_Parameter("BY")->asDouble();
+		dx	= pParameters->Get_Parameter("DX")->asDouble();
+		dy	= pParameters->Get_Parameter("DY")->asDouble();
+
+		if( ax > bx )	{	d	= ax;	ax	= bx;	bx	= d;	}
+		if( ay > by )	{	d	= ay;	ay	= by;	by	= d;	}
+
+		if     ( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("DX")) )
+		{
+			bx	= ax + dx;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("AX"))
+			||	 !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("BX")) )
+		{
+			dx	= bx - ax;
+		}
+
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("DY")) )
+		{
+			by	= ay + dy;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("AY"))
+			||	 !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("BY")) )
+		{
+			dy	= by - ay;
+		}
+
+		pParameters->Get_Parameter("AX")->Set_Value(ax);
+		pParameters->Get_Parameter("AY")->Set_Value(ay);
+		pParameters->Get_Parameter("BX")->Set_Value(bx);
+		pParameters->Get_Parameter("BY")->Set_Value(by);
+		pParameters->Get_Parameter("DX")->Set_Value(dx);
+		pParameters->Get_Parameter("DY")->Set_Value(dy);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Shapes_Cut.h                      //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Cut_H
+#define HEADER_INCLUDED__Shapes_Cut_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes *	Cut_Shapes		(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes);
+CSG_Shapes *	Cut_Shapes		(CSG_Rect    Extent   , int Method, CSG_Shapes *pShapes);
+bool			Cut_Shapes		(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes, CSG_Shapes *pCut);
+bool			Cut_Shapes		(CSG_Rect    Extent   , int Method, CSG_Shapes *pShapes, CSG_Shapes *pCut);
+
+CSG_String		Cut_Methods_Str	(void);
+
+bool			Cut_Set_Extent	(CSG_Rect Extent, CSG_Shapes *pExtent, bool bClear);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Cut : public CSG_Module
+{
+public:
+	CShapes_Cut(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("A:Shapes|Construction") );	}
+
+
+protected:
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	CSG_Shapes					*m_pPolygons;
+
+
+	bool						Get_Extent				(CSG_Rect &r);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Cut_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,299 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Shapes_Cut_Interactive.cpp              //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "shapes_cut_interactive.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Cut_Interactive::CShapes_Cut_Interactive(void)
+{
+	Set_Name		(_TL("Cut Shapes Layer"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Set_Drag_Mode	(MODULE_INTERACTIVE_DRAG_BOX);
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "CUT"			, _TL("Cut"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "EXTENT"		, _TL("Extent"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		Cut_Methods_Str(), 0
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters	= Add_Parameters("CUT", _TL("Extent"), _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "AX"	, _TL("Left")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "BX"	, _TL("Right")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "AY"	, _TL("Bottom")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "BY"	, _TL("Top")				, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "DX"	, _TL("Horizontal Range")	, _TL(""), PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	pParameters->Add_Value(
+		NULL, "DY"	, _TL("Vertical Range")		, _TL(""), PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Cut_Interactive::~CShapes_Cut_Interactive(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Cut_Interactive::On_Execute(void)
+{
+	m_bDown		= false;
+
+	m_pShapes	= Parameters("SHAPES")	->asShapes();
+	m_pCut		= Parameters("CUT")		->asShapes();
+	m_pExtent	= Parameters("EXTENT")	->asShapes();
+	m_Method	= Parameters("METHOD")	->asInt();
+
+	m_pCut->Create(m_pShapes->Get_Type());
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CShapes_Cut_Interactive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	switch( Mode )
+	{
+	//-----------------------------------------------------
+	case MODULE_INTERACTIVE_LDOWN:
+		if( m_bDown == false )
+		{
+			m_bDown	= true;
+			m_pDown	= ptWorld;
+		}
+
+		return( true );
+
+	//-----------------------------------------------------
+	case MODULE_INTERACTIVE_LUP:
+		if( m_bDown == true )
+		{
+			m_bDown	= false;
+
+			CSG_Rect	r(m_pDown, ptWorld);
+
+			if( Get_Extent(r) )
+			{
+				if( Cut_Set_Extent(r, m_pExtent, true) )
+				{
+					DataObject_Update(m_pExtent);
+				}
+
+				if( Cut_Shapes(r, m_Method, m_pShapes, m_pCut) )
+				{
+					DataObject_Update(m_pCut);
+				}
+				else
+				{
+					Message_Add(_TL("No shapes in selection"));
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CShapes_Cut_Interactive::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	if( !SG_STR_CMP(pParameters->Get_Identifier(), SG_T("CUT")) )
+	{
+		double	ax, ay, bx, by, dx, dy, d;
+
+		ax	= pParameters->Get_Parameter("AX")->asDouble();
+		ay	= pParameters->Get_Parameter("AY")->asDouble();
+		bx	= pParameters->Get_Parameter("BX")->asDouble();
+		by	= pParameters->Get_Parameter("BY")->asDouble();
+		dx	= pParameters->Get_Parameter("DX")->asDouble();
+		dy	= pParameters->Get_Parameter("DY")->asDouble();
+
+		if( ax > bx )	{	d	= ax;	ax	= bx;	bx	= d;	}
+		if( ay > by )	{	d	= ay;	ay	= by;	by	= d;	}
+
+		if     ( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("DX")) )
+		{
+			bx	= ax + dx;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("AX"))
+			||	 !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("BX")) )
+		{
+			dx	= bx - ax;
+		}
+
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("DY")) )
+		{
+			by	= ay + dy;
+		}
+		else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("AY"))
+			||	 !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("BY")) )
+		{
+			dy	= by - ay;
+		}
+
+		pParameters->Get_Parameter("AX")->Set_Value(ax);
+		pParameters->Get_Parameter("AY")->Set_Value(ay);
+		pParameters->Get_Parameter("BX")->Set_Value(bx);
+		pParameters->Get_Parameter("BY")->Set_Value(by);
+		pParameters->Get_Parameter("DX")->Set_Value(dx);
+		pParameters->Get_Parameter("DY")->Set_Value(dy);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CShapes_Cut_Interactive::Get_Extent(CSG_Rect &r)
+{
+	CSG_Parameters	*pParameters	= Get_Parameters("CUT");
+
+	pParameters->Get_Parameter("AX")->Set_Value(r.Get_XMin());
+	pParameters->Get_Parameter("AY")->Set_Value(r.Get_YMin());
+	pParameters->Get_Parameter("BX")->Set_Value(r.Get_XMax());
+	pParameters->Get_Parameter("BY")->Set_Value(r.Get_YMax());
+	pParameters->Get_Parameter("DX")->Set_Value(r.Get_XRange());
+	pParameters->Get_Parameter("DY")->Set_Value(r.Get_YRange());
+
+	if( Dlg_Parameters("CUT") )
+	{
+		r.Assign(
+			pParameters->Get_Parameter("AX")->asDouble(),
+			pParameters->Get_Parameter("AY")->asDouble(),
+			pParameters->Get_Parameter("BX")->asDouble(),
+			pParameters->Get_Parameter("BY")->asDouble()
+		);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_cut_interactive.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Shapes_Cut_Interactive.h               //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Cut_Interactive_H
+#define HEADER_INCLUDED__Shapes_Cut_Interactive_H
+
+//---------------------------------------------------------
+#include "shapes_cut.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Cut_Interactive : public CSG_Module_Interactive
+{
+public:
+	CShapes_Cut_Interactive(void);
+	virtual ~CShapes_Cut_Interactive(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("A:Shapes|Construction") );	}
+
+
+protected:
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool				On_Execute				(void);
+	virtual bool				On_Execute_Position		(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	bool						m_bDown;
+
+	int							m_Method;
+
+	CSG_Point					m_pDown;
+
+	CSG_Shapes					*m_pShapes, *m_pCut, *m_pExtent;
+
+
+	bool						Get_Extent				(CSG_Rect &r);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Cut_Interactive_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,185 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Shapes_Extents.cpp                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes_extents.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Extents::CShapes_Extents(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Get Shapes Extents"));
+
+	Set_Author		(_TL("(c) 2008 by O. Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "EXTENTS"		, _TL("Extents"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Value(
+		NULL	, "PARTS"		, _TL("Parts"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Extents::~CShapes_Extents(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Extents::On_Execute(void)
+{
+	bool		bParts;
+	TSG_Rect	r;
+	CSG_Shape	*pShape , *pExtent;
+	CSG_Shapes	*pShapes, *pExtents;
+
+	pShapes		= Parameters("SHAPES")	->asShapes();
+	pExtents	= Parameters("EXTENTS")	->asShapes();
+	bParts		= Parameters("PARTS")	->asBool();
+
+	//-----------------------------------------------------
+	if( pShapes->Get_Type() == SHAPE_TYPE_Point )
+	{
+		Message_Add(_TL("no 'get extents' support for single point layers"));
+
+		return( false );
+	}
+
+	if( !pShapes->is_Valid() )
+	{
+		Message_Add(_TL("invalid input"));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	pExtents->Create(SHAPE_TYPE_Polygon, pShapes->Get_Name(), pShapes);
+
+	for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+	{
+		pShape	= pShapes ->Get_Shape(iShape);
+
+		if( bParts )
+		{
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				r		= pShape->Get_Extent(iPart);
+
+				pExtent	= pExtents->Add_Shape(pShape, SHAPE_COPY_ATTR);
+
+				pExtent->Add_Point(r.xMin, r.yMin);
+				pExtent->Add_Point(r.xMin, r.yMax);
+				pExtent->Add_Point(r.xMax, r.yMax);
+				pExtent->Add_Point(r.xMax, r.yMin);
+			}
+		}
+		else
+		{
+			r		= pShape->Get_Extent();
+
+			pExtent	= pExtents->Add_Shape(pShape, SHAPE_COPY_ATTR);
+
+			pExtent->Add_Point(r.xMin, r.yMin);
+			pExtent->Add_Point(r.xMin, r.yMax);
+			pExtent->Add_Point(r.xMax, r.yMax);
+			pExtent->Add_Point(r.xMax, r.yMin);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( pExtents->is_Valid() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_extents.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Shapes_Extents.h                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Extents_H
+#define HEADER_INCLUDED__Shapes_Extents_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Extents : public CSG_Module
+{
+public:
+	CShapes_Extents(void);
+	virtual ~CShapes_Extents(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Extents_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,187 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Shapes_Split.cpp                    //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes_split.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Split::CShapes_Split(void)
+{
+	Set_Name		(_TL("Split Shapes Layer"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL	, "CUTS"		, _TL("Tiles"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "EXTENT"		, _TL("Extent"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NX"			, _TL("Number of horizontal tiles"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 2, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NY"			, _TL("Number of vertical tiles"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 2, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		Cut_Methods_Str(), 0
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Split::~CShapes_Split(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Split::On_Execute(void)
+{
+	int			x, y, nx, ny, Method;
+	CSG_Shapes	*pShapes, *pCut, *pExtent;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	pExtent	= Parameters("EXTENT")	->asShapes();
+	nx		= Parameters("NX")		->asInt();
+	ny		= Parameters("NY")		->asInt();
+	Method	= Parameters("METHOD")	->asInt();
+
+	Parameters("CUTS")->asShapesList()->Del_Items();
+
+	//-----------------------------------------------------
+	if( pShapes->is_Valid() )
+	{
+		double		dx, dy;
+		TSG_Rect	r;
+
+		dx	= pShapes->Get_Extent().Get_XRange() / nx;
+		dy	= pShapes->Get_Extent().Get_YRange() / ny;
+
+		for(y=0; y<ny && Process_Get_Okay(false); y++)
+		{
+			r.yMin	= pShapes->Get_Extent().Get_YMin() + y * dy;
+			r.yMax	= r.yMin + dy;
+
+			for(x=0; x<nx && Process_Get_Okay(false); x++)
+			{
+				r.xMin	= pShapes->Get_Extent().Get_XMin() + x * dx;
+				r.xMax	= r.xMin + dx;
+
+				Cut_Set_Extent(r, pExtent, y == 0 && x == 0);
+
+				Process_Set_Text(CSG_String::Format(SG_T("%d/%d"), y * nx + (x + 1), nx * ny));
+
+				if( (pCut = Cut_Shapes(r, Method, pShapes)) != NULL )
+				{
+					pCut->Set_Name(CSG_String::Format(SG_T("%s [%d][%d]"), pShapes->Get_Name(), 1 + x, 1 + y));
+
+					Parameters("CUTS")->asShapesList()->Add_Item(pCut);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Shapes_Split.h                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Split_H
+#define HEADER_INCLUDED__Shapes_Split_H
+
+//---------------------------------------------------------
+#include "shapes_cut.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Split : public CSG_Module
+{
+public:
+	CShapes_Split(void);
+	virtual ~CShapes_Split(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("A:Shapes|Construction") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Split_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,163 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              shapes_split_by_attribute.cpp            //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes_split_by_attribute.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Split_by_Attribute::CShapes_Split_by_Attribute(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Split Table/Shapes by Attribute"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Table / Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"		, _TL("Attribute"),
+		_TL(""),
+		false
+	);
+
+	Parameters.Add_Table_List(
+		NULL	, "CUTS"		, _TL("Cuts"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Split_by_Attribute::On_Execute(void)
+{
+	int			iField;
+	CSG_Table	*pTable;
+
+	//-----------------------------------------------------
+	pTable	= Parameters("TABLE")	->asTable();
+	iField	= Parameters("FIELD")	->asInt();
+
+	Parameters("CUTS")->asTableList()->Del_Items();
+
+	//-----------------------------------------------------
+	if( pTable->is_Valid() && pTable->Set_Index(iField, TABLE_INDEX_Ascending) )
+	{
+		CSG_String	sValue;
+		CSG_Table	*pCut	= NULL;
+
+		for(int iRecord=0; iRecord<pTable->Get_Count() && Set_Progress(iRecord, pTable->Get_Count()); iRecord++)
+		{
+			CSG_Table_Record	*pRecord	= pTable->Get_Record(iRecord);
+
+			if( !pCut || sValue.Cmp(pRecord->asString(iField)) )
+			{
+				pCut	= pTable->Get_ObjectType() == DATAOBJECT_TYPE_Shapes
+						? SG_Create_Shapes(((CSG_Shapes *)pTable)->Get_Type(), SG_T(""), pTable)
+						: SG_Create_Table(pTable);
+
+				pCut->Set_Name(CSG_String::Format(SG_T("%s [%s = %s]"),
+					pTable->Get_Name(),
+					pTable->Get_Field_Name(iField),
+					pRecord->asString(iField)
+				));
+
+				Parameters("CUTS")->asTableList()->Add_Item(pCut);
+
+				sValue	= pRecord->asString(iField);
+			}
+
+			pCut->Add_Record(pRecord);
+		}
+
+		return( pCut != NULL );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_by_attribute.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,94 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              shapes_split_by_attribute.h              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__shapes_split_by_attribute_H
+#define HEADER_INCLUDED__shapes_split_by_attribute_H
+
+//---------------------------------------------------------
+#include "shapes_cut.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Split_by_Attribute : public CSG_Module
+{
+public:
+	CShapes_Split_by_Attribute(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("A:Shapes|Construction") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__shapes_split_by_attribute_H

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,166 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Shapes_Split_Randomly.cpp               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <time.h>
+
+#include "shapes_split_randomly.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CShapes_Split_Randomly::CShapes_Split_Randomly(void)
+{
+	Set_Name		(_TL("Split Shapes Layer Randomly"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Randomly splits one shapes layer into to new shapes layers. "
+		"Useful to create a control group for model testing. "
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "A"			, _TL("Group A"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "B"			, _TL("Group B"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "PERCENT"		, _TL("Relation B / A"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 25.0, 0.0, true, 100.0, true
+	);
+}
+
+//---------------------------------------------------------
+CShapes_Split_Randomly::~CShapes_Split_Randomly(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CShapes_Split_Randomly::On_Execute(void)
+{
+	double		Percent;
+	CSG_Shapes	*pShapes, *pA, *pB;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	pA		= Parameters("A")		->asShapes();
+	pB		= Parameters("B")		->asShapes();
+	Percent	= Parameters("PERCENT")	->asDouble();
+
+	//-----------------------------------------------------
+	pA->Create(pShapes->Get_Type(), CSG_String::Format(SG_T("%s [%d%%]"), pShapes->Get_Name(), (int)(100.5 - Percent)), pShapes);
+	pB->Create(pShapes->Get_Type(), CSG_String::Format(SG_T("%s [%d%%]"), pShapes->Get_Name(), (int)(  0.5 + Percent)), pShapes);
+
+	Percent	*= RAND_MAX / 100.0;
+
+	//-----------------------------------------------------
+	if( pShapes->is_Valid() )
+	{
+		srand((unsigned)time(NULL));
+
+		for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			if( Percent < rand() )
+			{
+				pA->Add_Shape(pShapes->Get_Shape(iShape));
+			}
+			else
+			{
+				pB->Add_Shape(pShapes->Get_Shape(iShape));
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/shapes/shapes_tools/shapes_split_randomly.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Shapes_Split_Randomly.h                //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Shapes_Split_Randomly_H
+#define HEADER_INCLUDED__Shapes_Split_Randomly_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CShapes_Split_Randomly : public CSG_Module
+{
+public:
+	CShapes_Split_Randomly(void);
+	virtual ~CShapes_Split_Randomly(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("A:Shapes|Construction") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Shapes_Split_Randomly_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,388 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Fit.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+#include "LMFit.h"
+#include <vector>
+#include <math.h>
+#include <string.h>
+
+#include "Fit.h"
+
+#define EPS 0.001
+
+CSG_Formula Formel;
+
+char vars[26]; 
+
+double NUG(double x)
+{
+	if (x > 0)
+		return 1.0;
+	else return 0.0;
+}
+
+double SPH(double x, double a)
+{
+	if (x < 0)
+		return 0.0;
+	
+	if (x > a)
+		return 1.0;
+	
+	double val = x/a;
+	
+	return (1.5 - 0.5*val*val)*val;
+}
+
+double EXP(double x, double a)
+{
+	if (x < 0)
+		return 0.0;
+	return 1.0 - exp(-x/a);
+}
+
+double LIN(double x, double a)
+{
+	if (a == 0.0)
+		return x;
+	
+	if (x < a)
+		return x/a;
+	return x;
+}
+
+
+CFit::CFit(void)
+{
+	Set_Name(_TL("Function Fit"));
+	
+	Set_Description(_TL("CFit\n(created by SAGA Wizard)."));
+	
+	CSG_Parameter	*pNode;
+	
+	pNode	= Parameters.Add_Table(NULL	, "SOURCE"		, _TL("Source")			, _TL(""), PARAMETER_INPUT);
+	
+	Parameters.Add_Table_Field(pNode	, "YFIELD"		, _TL("y - Values")				, _TL(""));
+	
+	Parameters.Add_Choice(pNode, "USE_X", _TL("Use x -Values"), _TL(""), _TL("No|Yes|"));
+	Parameters.Add_Table_Field(pNode	, "XFIELD"		, _TL("x - Values")				, _TL(""));
+	
+	Parameters.Add_String(NULL,	"FORMEL", _TL("Formula"), 
+		_TW(
+		"The following operators are available for the formula definition:\n"
+		"+ Addition\n"
+		"- Subtraction\n"
+		"* Multiplication\n"
+		"/ Division\n"
+		"^ power\n"
+		"sin(x)\n"
+		"cos(x)\n"
+		"tan(x)\n"
+		"asin(x)\n"
+		"acos(x)\n"
+		"atan(x)\n"
+		"abs(x)\n"
+		"sqrt(x)\n\n"
+
+		"For Variogram - Fitting you can use the folowing Variogram - Models:\n"
+		"NUG(x)\n"
+		"SPH(x,a)\n"
+		"EXP(x,a)\n"
+		"LIN(x,a)\n"
+		
+		"The Fitting variables are single characters like a,b,m .. "
+		"alphabetical order with the grid list order ('a'= first var, 'b' = second grid, ...)\n"
+		"Example: m*x+a \n"),
+				
+		SG_T("m*x+c"));
+	
+	Parameters.Add_Value(NULL, "ITER", _TL("Iterationen"), _TL(""), PARAMETER_TYPE_Int, 1000, 1, true);
+	
+	Parameters.Add_Value(NULL, "LAMDA", _TL("Max Lamda"), _TL(""), PARAMETER_TYPE_Double, 10000, 1, true);
+}
+
+int CFit::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	bool retval = false;
+	
+
+	if (!SG_STR_CMP(pParameter->Get_Identifier(), SG_T("FORMEL")) )
+	{
+		const SG_Char * formel=pParameters->Get_Parameter("FORMEL")->asString();
+		Formel.Set_Formula(formel);
+	
+		int Pos;
+		CSG_String Msg;
+		if (Formel.Get_Error(&Pos, &Msg))
+		
+		{
+			CSG_String	s;
+			
+			s.Printf(_TL("Error at character #%d of the function: \n%s\n%s\n"), Pos, formel);
+
+			Error_Set(s);			
+		
+			Message_Dlg(s,s);
+
+			return false;
+		}
+	}
+	return (retval);
+}
+
+CFit::~CFit(void)
+{}
+
+void FitFunc(double x, vector < double> ca, double &y, vector < double> &dyda, int na)
+{
+	int		i;
+
+	for(i = 0; i < na; i++)
+	{
+		Formel.Set_Variable(vars[i], ca[i]);
+	}
+	
+	y= Formel.Get_Value(x);
+	
+	for (i = 0; i < na; i++)
+	{
+		Formel.Set_Variable(vars[i], ca[i] + EPS);
+		
+		dyda[i] = Formel.Get_Value(x);
+		dyda[i] -= y;
+		dyda[i] /= EPS;
+		
+		Formel.Set_Variable(vars[i], ca[i] - EPS);
+	}
+}
+// MinGW Error !!!
+// Fit.cpp:199: error: name lookup of `i' changed for new ISO `for' scoping
+// Fit.cpp:192: error:   using obsolete binding at `i'
+
+bool CFit::On_Execute(void)
+{
+	int i, j,  NrVars;
+	vector < double> x, y, StartValue, Result;
+	CSG_String	msg;	
+	
+	CSG_Parameters StartParameters;
+
+	const SG_Char *formel	=	Parameters("FORMEL")->asString();
+
+	Formel.Add_Function(SG_T("NUG"), (TSG_PFNC_Formula_1) NUG, 1, 0);
+	Formel.Add_Function(SG_T("SPH"), (TSG_PFNC_Formula_1) SPH, 2, 0);
+	Formel.Add_Function(SG_T("EXP"), (TSG_PFNC_Formula_1) EXP, 2, 0);
+    Formel.Add_Function(SG_T("LIN"), (TSG_PFNC_Formula_1) LIN, 2, 0);
+	
+	
+	Formel.Set_Formula(formel);
+	
+	
+	int Pos;
+	CSG_String ErrorMsg;
+	if (Formel.Get_Error(&Pos, &ErrorMsg))
+	{
+		msg.Printf(_TL("Error at character #%d of the function: \n%s\n"), Pos, formel);
+		
+		Message_Add(msg);
+		
+		msg.Printf(SG_T("\n%s\n"), ErrorMsg.c_str());
+		
+		Message_Add(msg);
+		
+		return false;
+	}
+	
+	const SG_Char *uservars = NULL;
+	
+	uservars = Formel.Get_Used_Variables();
+	
+
+	NrVars	=	0;
+	for (i = 0; i < SG_STR_LEN(uservars); i++)
+	{
+		if (uservars[i] >='a' && uservars[i] <= 'z')
+		{
+			if (uservars[i] != 'x')
+				vars[NrVars++] = uservars[i];
+		}
+	}
+	
+	vars[NrVars] =(char) 0;
+	
+	StartParameters.Add_Info_String(NULL, _TL(""), _TL("Formula"), _TL("Formula"), formel);
+	
+	for (i = 0; i < strlen(vars); i++)
+	{
+		CSG_String	c(vars[i]);
+		StartParameters.Add_Value(NULL, c, c, _TL("Start Value"), PARAMETER_TYPE_Double, 1.0);
+	}
+	
+	Dlg_Parameters(&StartParameters, _TL("Start Values"));
+	
+	for (i = 0; i < strlen(vars); i++)
+	{
+		char c[3];
+		sprintf(c, "%c", vars[i]);
+		StartValue.push_back(StartParameters(c)->asDouble());
+	}
+	
+	CSG_Table	*pTable	= Parameters("SOURCE")->asTable();
+	int Record_Count = pTable->Get_Record_Count();
+	
+	int	yField		= Parameters("YFIELD")->asInt();
+	int	xField		= Parameters("XFIELD")->asInt();
+	bool Use_X		= Parameters("USE_X")->asBool();
+	
+	pTable->Add_Field(_TL("Fit")				, SG_DATATYPE_Double);	
+	
+	for (i = 0; i < Record_Count; i++)
+	{
+		CSG_Table_Record *	Record = pTable->Get_Record(i);
+		if (Use_X)
+		{
+			x.push_back(Record->asDouble(xField));
+		}
+		else
+		{
+			x.push_back(i);
+		}
+		
+		y.push_back(Record->asDouble(yField));
+	}
+	
+	TLMFit *Fit;
+	
+	Fit = new TLMFit(x, y, StartValue,  FitFunc);
+	
+	int max_iter = Parameters("ITER")->asInt();
+	double Max_lamda = Parameters("LAMDA")->asInt();
+	
+	int iter = 0; 
+	
+	try
+	{
+		Fit->Fit();
+		
+		while ((Fit->Alamda() < Max_lamda) &&(iter < max_iter) &&Process_Get_Okay(true))
+		{
+			Fit->Fit();
+			iter++;
+		}
+	}
+	catch (ESingularMatrix &E)
+	{
+		if (E.Type == 1 || E.Type == 2)
+		{
+			msg.Printf(_TL("Matrix signular\n"));
+			
+			Message_Add(msg);
+			
+			return false;
+		}
+	}
+	
+	Result    = Fit->Param();
+	
+	for (i = 0; i < NrVars; i++)
+	{
+		Formel.Set_Variable(vars[i], (double) Result[i]);
+	}
+	
+	msg.Printf(_TL("Model Parameters:"));
+	Message_Add(msg);
+	for (i = 0; i < NrVars; i++)
+	{
+		msg.Printf(SG_T("%c = %f\n"), vars[i], Result[i]);
+		Message_Add(msg);
+	}
+	
+	msg.Printf(_TL("\nRMS  of Residuals (stdfit):\t%f\n"), sqrt(Fit->Chisq()/x.size()));
+	Message_Add(msg);
+	
+	msg.Printf(_TL("Correlation Matrix of the Fit Parameters:\n"));
+	Message_Add(msg);
+	
+	vector< vector < double> > covar = Fit->Covar();
+	
+	msg.Printf(_TL(""));
+	for (j = 0; j < NrVars; j++)
+		msg.Printf(SG_T("%s\t%c"), msg.c_str(), vars[j]);
+	
+	msg.Printf(SG_T("%s\n"), msg.c_str());
+	
+	Message_Add(msg);
+	
+	for (i = 0; i < NrVars; i++)
+	{
+		msg.Printf(SG_T("%c"), vars[i]);
+		for (j = 0; j <= i; j++)
+		{	
+			msg.Printf(SG_T("%s\t%f"), msg.c_str(), covar[i][j]/covar[i][i]);
+		}
+		msg.Printf(SG_T("%s\n"), msg.c_str());
+		
+		Message_Add(msg);
+	}
+	
+	int Field_Count  = pTable->Get_Field_Count();
+	
+	for (i = 0; i < Record_Count; i++)
+	{
+		CSG_Table_Record *	Record = pTable->Get_Record(i);
+		
+		Record->Set_Value(Field_Count - 1, Formel.Get_Value(x[i]));
+	}
+
+//	API_FREE (uservars);
+	return (true);
+}

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/Fit.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                         Fit.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__CFit_H
+#define HEADER_INCLUDED__CFit_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+class CFit : public CSG_Module
+{
+public:
+	CFit(void);
+	virtual ~CFit(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+	virtual int				On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool			On_Initialize_Parameters(void)	{	return( true );	}
+	virtual void			On_Finalize_Parameters(void)	{					}
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__CFit_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,318 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       LMFit.cpp                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+#include "LMFit.h"
+
+TLMFit::TLMFit(vector<double> Xdata, vector<double> Ydata, vector<double> Param,  void(*CfuncP)(double x, vector<double> ca, double &y, vector < double> &dyda, int na))
+{
+	int		i, mfit = 0;
+	chisq = 0;
+	alamda = -1;
+	
+	ndata  = Xdata.size();
+	nparam = Param.size();
+	
+	x.resize(ndata);
+	y.resize(ndata);
+	for (i = 0; i < ndata; i++)
+	{
+		x[i]   = Xdata[i];
+		y[i]   = Ydata[i];
+	}
+	
+	a.resize(nparam);
+	ia.resize(nparam);
+	for (i = 0; i < nparam; i++)
+	{
+		a[i] = Param[i];
+		ia[i] = 1;
+		if (ia[i])
+			mfit++;
+	}
+	
+	alpha.resize(mfit);
+	covar.resize(mfit);
+	for (i = 0; i < mfit; i++)
+	{
+		covar[i].resize(mfit);
+		alpha[i].resize(mfit);
+	}
+	
+	funcP = CfuncP;
+}
+//----------------------------------------------------------------------------
+void TLMFit::Fit(void)
+{
+	mrqmin();
+}
+
+void TLMFit::gaussj(vector< vector<double> > &aa, int n, vector< vector < double> > &b, int m)
+{
+	vector < int> indxc, indxr, ipiv;
+	int i, icol, irow, j, k, l, ll;
+	double big, dum, pivinv, temp, test;
+	
+	indxc.resize(n);
+	indxr.resize(n);
+	ipiv.resize(n);
+	
+	for (j = 0; j < n; j++)
+		ipiv[j] = 0;
+	for (i = 0; i < n; i++)
+	{
+		big = 0.0;
+		for (j = 0; j < n; j++)
+			if (ipiv[j] != 1)
+				for (k = 0; k < n; k++)
+				{
+					if (ipiv[k] == 0)
+					{
+						if (fabs(aa[j][k]) >= big)
+						{
+							big = fabs(aa[j][k]);
+							irow = j;
+							icol = k;
+						}
+					}
+					else if (ipiv[k] > 1)
+					{
+						throw ESingularMatrix(1);
+					}
+				}
+				++(ipiv[icol]);
+				
+				if (irow != icol)
+				{
+					for (l = 0; l < n; l++)
+						SWAP(aa[irow][l], aa[icol][l]);
+					for (l = 0; l < m; l++)
+						SWAP(b[irow][l], b[icol][l]);
+				}
+				indxr[i] = irow;
+				indxc[i] = icol;
+				if (fabs(aa[icol][icol]) < 1E-300)
+				{
+					throw ESingularMatrix(2);
+				}
+				//         else
+				test = aa[icol][icol];
+				
+				pivinv = 1.0/test;
+				aa[icol][icol] = 1.0;
+				for (l = 0; l < n; l++)
+					aa[icol][l] *= pivinv;
+				for (l = 0; l < m; l++)
+					b[icol][l] *= pivinv;
+				
+				for (ll = 0; ll < n; ll++)
+					if (ll != icol)
+					{
+						dum = aa[ll][icol];
+						aa[ll][icol] = 0.0;
+						for (l = 0; l < n; l++)
+							aa[ll][l] -= aa[icol][l]*dum;
+						for (l = 0; l < m; l++)
+							b[ll][l] -= b[icol][l]*dum;
+					}
+	}
+	for (l =(n - 1); l > -1; l--)
+	{
+        if (indxr[l] != indxc[l])
+			for (k = 0; k < n; k++)
+				SWAP(aa[k][indxr[l]], aa[k][indxc[l]]);
+	}
+}
+//-----------------------------------------------------------------------
+void TLMFit::covsrt(int mfit)
+{
+	int i, j, k;
+	double temp;
+	
+	for (i = mfit; i < nparam; i++)
+		for (j = 0; j < i; j++)
+			covar[i][j] = 0.0;
+		k = mfit;
+		for (j = (nparam - 1); j>-1; j--)
+		{
+			if (ia[j])
+			{
+				for (i = 0; i < nparam; i++)
+					SWAP(covar[i][k], covar[i][j]);
+				for (i = 0; i < nparam; i++)
+					SWAP(covar[k][i], covar[j][i]);
+				k--;
+			}
+		}
+}
+//-----------------------------------------------------------------------
+void TLMFit::mrqcof(vector<double> &ba, vector< vector<double> > &balpha, vector < double> &bbeta)
+{
+	vector < double> dyda(nparam, 0);
+	int i, j, k, l, m, mfit = 0;
+	double ymod, wt,  dy;
+	
+	for (j = 0; j < nparam; j++)
+		if (ia[j] > 0)
+			mfit++;
+		
+		for (j = 0; j < mfit; j++)
+		{
+			for (k = 0; k <=j; k++)
+				balpha[j][k] = 0.0;
+			bbeta[j] = 0.0;
+		}
+		chisq = 0.0;
+		
+		for (i = 0; i < ndata; i++)
+		{
+			(*funcP)(x[i], ba, ymod, dyda, nparam);
+			
+			dy = y[i] - ymod;
+			for (j=-1, l = 0; l < nparam; l++)
+			{
+				if (ia[l])
+				{
+					wt = dyda[l];
+					for (j++, k=-1, m = 0; m <= l; m++)
+					{
+						if (ia[m])
+							balpha[j][++k] += wt*dyda[m];
+					}
+					bbeta[j] += dy*wt;
+				}
+			}
+			chisq += dy*dy;
+		}
+		
+		for (j = 1; j < mfit; j++)
+			for (k = 0; k < j; k++)
+				balpha[k][j] = balpha[j][k];
+}
+//-----------------------------------------------------------------------
+void TLMFit::mrqmin()
+{
+	static vector < double> atry, beta, da;
+	int j, k, l;
+	static int mfit;
+	static double ochisq;
+	static vector< vector < double> > oneda;
+	
+	if (alamda < 0.0)
+	{
+		atry.resize(nparam);
+		beta.resize(nparam);
+		da.resize(nparam);
+		
+		for (mfit = 0, j = 0; j < nparam; j++)
+			if (ia[j])
+				mfit++;
+			oneda.resize(mfit);
+			for (unsigned int i = 0; i < oneda.size(); i++)
+				oneda[i].resize(1);
+			alamda = 0.001;
+			mrqcof(a, alpha, beta);
+			ochisq = (chisq);
+			for (j = 0; j < nparam; j++)
+				atry[j] =(a[j]);
+	}
+	for (j = 0; j < mfit; j++)
+	{
+		for (k = 0; k < mfit; k++)
+			covar[j][k] = alpha[j][k];
+		covar[j][j] = alpha[j][j]*(1.0 + (alamda));
+		oneda[j][0] = beta[j];
+	}
+	try {gaussj(covar, mfit, oneda, 1);}
+	catch (ESingularMatrix &E)
+	{
+		throw;
+	}
+	for (j = 0; j < mfit; j++)
+	{
+		da[j] = oneda[j][0];
+	}
+	if (alamda == 0.0)
+	{
+		covsrt(mfit);
+		return;
+	}
+	for (j = 0, l = 0; l < nparam; l++)
+		if (ia[l])
+			atry[l] = a[l] + da[j++];
+		mrqcof(atry, covar, da);
+		if (chisq < ochisq)
+		{
+			alamda *= 0.1;
+			ochisq = (chisq);
+			for (j = 0; j < mfit; j++)
+			{
+				for (k = 0; k < mfit; k++)
+					alpha[j][k] = covar[j][k];
+				beta[j] = da[j];
+			}
+			for (j = 0; j < nparam; j++)             // Achtung!! in aelteren Versionen war hier ein Fehler
+				a[j] = atry[j];
+		} else 
+		{
+			alamda *= 10.0;
+			chisq = ochisq;
+		}
+}
+//----------------------------------------------------------------------------
+// Implementation ESinglularMatrix (error handling for singular matrix)
+//----------------------------------------------------------------------------
+ESingularMatrix::ESingularMatrix(int i)
+{
+	Type = i;
+}
+//----------------------------------------------------------------------------
+

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/LMFit.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        LMFit.h                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+#ifndef LMFitH
+#define LMFitH
+
+#include <vector>
+#include <math.h>
+#define SWAP(a,b) {temp=(a);(a)=(b);(b)=temp;}
+
+using namespace std;
+
+class TLMFit{
+public:
+
+
+   TLMFit  (vector<double> Xdata,
+            vector<double> Ydata,
+            vector<double> Param,
+                            
+   void (*CfuncP)(double x, vector<double> ca,
+                  double &y, vector<double> &dyda, int na));
+
+   ~TLMFit (){};
+
+  void Fit();
+
+  // Accessors:
+  vector< vector<double> >	Alpha() const {return alpha;};
+  vector< vector<double> > 	Covar() const {return covar;};
+  double Chisq() const {return chisq;};
+  vector<double> Param() const {return a;};
+  int Ndata() const {return ndata;};
+  int Nparam() const {return nparam;};
+  double Alamda() const {return alamda;};
+
+private:
+  void gaussj(vector< vector<double> > &a, int m, vector< vector<double> > &b, int n);
+  void covsrt(int mfit);
+  void mrqcof(vector<double> &a, vector< vector<double> > &alpha, vector<double> &beta);
+  void mrqmin(void);
+
+  double chisq, alamda;
+  vector<double> x, y, a;                 //x-, y-Values, Fit-Parameters a, Sigmas
+  vector<int> ia;                              //Use Fit-Parameter for fit (1) or not (0)
+  vector< vector<double> > covar, alpha;       //Covarianz-Matrix
+  int ndata, nparam;                           //Number of Points, Number of Parameters
+  void (*funcP)(double x, vector<double> ca, double &y, vector<double> &dyda, int na);
+};
+
+class ESingularMatrix {// Error Handling
+	public : int Type;
+        	 ESingularMatrix (int i);
+};
+#endif
+
+

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Table - Calculus") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Table|Calculus") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Fit.h"
+#include "Table_Calculator.h"
+#include "Table_CalculatorShapes.h"
+#include "Table_Trend.h"
+#include "table_running_average.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CFit );
+	case 1:		return( new CTableCalculator );
+	case 2:		return( new CTableCalculatorShapes );
+	case 3:		return( new CTable_Trend );
+	case 4:		return( new CTable_Trend_Shapes );
+	case 5:		return( new CTable_Running_Average );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__table_calculus_H
+#define HEADER_INCLUDED__table_calculus_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef table_calculus_EXPORTS
+	#define	table_calculus_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	table_calculus_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__table_calculus_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,289 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Table_Trend.cpp                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "Table_Trend.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CTable_Trend_Base::Initialise(void)
+{
+	//-----------------------------------------------------
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode	= Parameters("TABLE");
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD_X"		, _TL("X Values"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD_Y"		, _TL("Y Values"),
+		_TL("")
+	);
+
+	Parameters.Add_String(
+		NULL	, "FORMULA"		, _TL("Formula"),
+		_TL(""),
+		SG_T("m * x + b")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "FORMULAS"	, _TL("Pre-defined Formulas"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("Linear: a + b * x"),
+			_TL("Quadric: a + b * x + c * x^2"),
+			_TL("Cubic: a + b * x + c * x^2 + d * x^3"),
+			_TL("Logarithmic: a + b * ln(x)"),
+			_TL("Power: a + b * x^c"),
+			_TL("a + b / x"),
+			_TL("a + b * (1 - exp(-x / c))"),
+			_TL("a + b * (1 - exp(-(x / c)^2))")
+		), 0
+	);
+
+	Parameters.Add_Table(
+		NULL	, "TREND"		, _TL("Table (with Trend)"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+}
+
+//---------------------------------------------------------
+int CTable_Trend_Base::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("FORMULAS")) )
+	{
+		const SG_Char	*Formula;
+
+		switch( pParameter->asInt() )
+		{
+		default:	return( false );
+		case 0:	Formula	= SG_T("a + b * x");						break;
+		case 1:	Formula	= SG_T("a + b * x + c * x^2");				break;
+		case 2:	Formula	= SG_T("a + b * x + c * x^2 + d * x^3");	break;
+		case 3:	Formula	= SG_T("a + b * ln(x)");					break;
+		case 4:	Formula	= SG_T("a + b * x^c");						break;
+		case 5:	Formula	= SG_T("a + b / x");						break;
+		case 6:	Formula	= SG_T("a + b * (1 - exp(-x / c))");		break;
+		case 7:	Formula	= SG_T("a + b * (1 - exp(-(x / c)^2))");	break;
+		}
+
+		pParameters->Get_Parameter("FORMULA")->Set_Value(Formula);
+	}
+
+	if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("FORMULA")) )
+	{
+		if( !m_Trend.Set_Formula(pParameter->asString()) )
+		{
+			Message_Dlg(m_Trend.Get_Error(), _TL("Error in Formula"));
+
+			return( false );
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CTable_Trend_Base::Get_Trend(CSG_Table *pTable)
+{
+	int				i, j, xField, yField;
+	CSG_String		Name;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	if( m_Trend.Set_Formula(Parameters("FORMULA")->asString()) )
+	{
+		xField	= Parameters("FIELD_X")	->asInt();
+		yField	= Parameters("FIELD_Y")	->asInt();
+
+		m_Trend.Clr_Data();
+
+		for(i=0; i<pTable->Get_Record_Count(); i++)
+		{
+			pRecord	= pTable->Get_Record(i);
+
+			m_Trend.Add_Data(pRecord->asDouble(xField), pRecord->asDouble(yField));
+		}
+
+		//-------------------------------------------------
+		if( m_Trend.Get_Trend() )
+		{
+			Message_Add(SG_T("\n"), false);
+			Message_Add(m_Trend.Get_Formula(), false);
+			Message_Add(SG_T("\n"), false);
+			Message_Add(CSG_String::Format(SG_T("R\xc2\xb2 : %f"), 100.0 * m_Trend.Get_R2()), false);
+
+			if( Parameters("TREND")->asTable() == NULL )
+			{
+				pTable->Add_Field("TREND"	, SG_DATATYPE_Double);
+
+				for(i=0, j=pTable->Get_Field_Count()-1; i<m_Trend.Get_Data_Count(); i++)
+				{
+					pRecord	= pTable->Get_Record(i);
+					pRecord->Set_Value(j, m_Trend.Get_Value(m_Trend.Get_Data_X(i)));
+				}
+			}
+			else
+			{
+				Name.Printf(SG_T("%s [%s]"), pTable->Get_Name(), _TL("Trend"));
+				pTable	= Parameters("TREND")->asTable();
+				pTable->Destroy();
+				pTable->Set_Name(Name);
+				pTable->Add_Field("X"		, SG_DATATYPE_Double);
+				pTable->Add_Field("Y"		, SG_DATATYPE_Double);
+				pTable->Add_Field("Y_TREND"	, SG_DATATYPE_Double);
+
+				for(i=0; i<m_Trend.Get_Data_Count(); i++)
+				{
+					pRecord	= pTable->Add_Record();
+					pRecord->Set_Value(0, m_Trend.Get_Data_X(i));
+					pRecord->Set_Value(1, m_Trend.Get_Data_Y(i));
+					pRecord->Set_Value(2, m_Trend.Get_Value(m_Trend.Get_Data_X(i)));
+				}
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Trend::CTable_Trend(void)
+	: CTable_Trend_Base()
+{
+	Set_Name		(_TL("Trend for Table Data"));
+
+	Parameters.Add_Table(
+		NULL	, "TABLE"	, _TL("Table"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Initialise();
+}
+
+//---------------------------------------------------------
+bool CTable_Trend::On_Execute(void)
+{
+	return( Get_Trend(Parameters("TABLE")->asTable()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Trend_Shapes::CTable_Trend_Shapes(void)
+	: CTable_Trend_Base()
+{
+	Set_Name		(_TL("Trend for Shapes Data"));
+
+	Parameters.Add_Shapes(
+		NULL	, "TABLE"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Initialise();
+}
+
+//---------------------------------------------------------
+bool CTable_Trend_Shapes::On_Execute(void)
+{
+	return( Get_Trend(Parameters("TABLE")->asShapes()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/Table_Trend.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Table_Trend.h                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Table_Trend_H
+#define HEADER_INCLUDED__Table_Trend_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTable_Trend_Base : public CSG_Module
+{
+protected:
+
+	void						Initialise				(void);
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	bool						Get_Trend				(CSG_Table *pTable);
+
+
+private:
+
+	CSG_Trend					m_Trend;
+
+};
+
+//---------------------------------------------------------
+class CTable_Trend : public CTable_Trend_Base
+{
+public:
+	CTable_Trend(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+};
+
+//---------------------------------------------------------
+class CTable_Trend_Shapes : public CTable_Trend_Base
+{
+public:
+	CTable_Trend_Shapes(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Table_Trend_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,183 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               table_running_average.cpp               //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "table_running_average.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Running_Average::CTable_Running_Average(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Running Average"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Table(
+		NULL	, "INPUT"		, _TL("Input"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"		, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Table(
+		NULL	, "OUTPUT"		, _TL("Output"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL	, "COUNT"		, _TL("Number of Records"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 10, 2, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTable_Running_Average::On_Execute(void)
+{
+	int			iValue, nValues;
+	CSG_Table	*pTable;
+
+	//-----------------------------------------------------
+	pTable	= Parameters("INPUT")	->asTable();
+	iValue	= Parameters("FIELD")	->asInt();
+	nValues	= Parameters("COUNT")	->asInt();
+
+	if( Parameters("OUTPUT")->asTable() && Parameters("OUTPUT")->asTable() != pTable )
+	{
+		pTable	= Parameters("OUTPUT")	->asTable();
+
+		pTable->Create(*Parameters("INPUT")->asTable());
+	}
+
+	//-----------------------------------------------------
+	if( pTable->is_Valid() )
+	{
+		int		i, iLo, iHi, nRange, iAverage;
+		double	sValues;
+
+		iAverage	= pTable->Get_Field_Count();
+		pTable->Add_Field(CSG_String::Format(SG_T("%s [%s]"), pTable->Get_Field_Name(iValue), _TL("Average")), SG_DATATYPE_Double);
+
+		nRange	= nValues / 2;
+		sValues	= 0.0;
+
+		for(iLo=-nValues, i=-nRange, iHi=0; i<pTable->Get_Count() && Set_Progress(i, pTable->Get_Count() + nRange); iLo++, i++, iHi++)
+		{
+			sValues	+= pTable->Get_Record(iHi < pTable->Get_Count() ? iHi : pTable->Get_Count() - 1)->asDouble(iValue);
+
+			if( i < 0 )
+			{
+				sValues	+= pTable->Get_Record( 0 )->asDouble(iValue);
+			}
+			else
+			{
+				if( iLo < 0 )
+				{
+					sValues	-= pTable->Get_Record( 0 )->asDouble(iValue);
+				}
+				else if( iLo >= 0 )
+				{
+					sValues	-= pTable->Get_Record(iLo)->asDouble(iValue);
+				}
+
+				pTable->Get_Record(i)->Set_Value(iAverage, sValues / (double)nValues);
+			}
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_calculus/table_running_average.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,96 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Table_Calculus                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                table_running_average.h                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__table_running_average_H
+#define HEADER_INCLUDED__table_running_average_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTable_Running_Average : public CSG_Module
+{
+public:
+	CTable_Running_Average(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__table_running_average_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,145 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Table - Tools") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Table|Tools") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Table_Create_Empty.h"
+#include "Table_Rotate.h"
+#include "Table_Enumerate.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CTable_Create_Empty;
+		break;
+
+	case 1:
+		pModule	= new CTable_Rotate;
+		break;
+
+	case 2:
+		pModule	= new CTable_Enumerate;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__table_tools_H
+#define HEADER_INCLUDED__table_tools_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef table_tools_EXPORTS
+	#define	table_tools_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	table_tools_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__table_tools_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,192 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Table_Create_Empty.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Table_Create_Empty.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Create_Empty::CTable_Create_Empty(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Create Empty Table"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2005"));
+
+	Set_Description	(_TW(
+		"Creates a new empty table."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "TABLE"	, _TL("Table"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_String(
+		NULL	, "NAME"	, _TL("Name"),
+		_TL(""),
+		_TL("New table")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "FIELDS"	, _TL("Number of Fields"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CTable_Create_Empty::~CTable_Create_Empty(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTable_Create_Empty::On_Execute(void)
+{
+	int						iField, nFields, iType;
+	TSG_Data_Type	Type;
+	CSG_String				Name, Types, s;
+	CSG_Table				*pTable;
+	CSG_Parameters			P;
+	CSG_Parameter			*pNode;
+
+	//-----------------------------------------------------
+	nFields	= Parameters("FIELDS")	->asInt();
+	Name	= Parameters("NAME")	->asString();
+	pTable	= Parameters("TABLE")	->asTable();
+
+	Types.Printf(SG_T("%s|%s|%s|%s|%s|%s|%s|"),
+		_TL("character string"),
+		_TL("1 byte integer"),
+		_TL("2 byte integer"),
+		_TL("4 byte integer"),
+		_TL("4 byte floating point"),
+		_TL("8 byte floating point"),
+		_TL("color (rgb)")
+	);
+
+	P.Set_Name(_TL("Field Properties"));
+
+	for(iField=1; iField<=nFields; iField++)
+	{
+		s.Printf(SG_T("NODE_%03d") , iField);
+		pNode	= P.Add_Node(NULL, s, CSG_String::Format(SG_T("%d. %s"), iField, _TL("Field")), _TL(""));
+
+		s.Printf(SG_T("FIELD_%03d"), iField);
+		P.Add_String(pNode, s, _TL("Name"), _TL(""), s);
+
+		s.Printf(SG_T("TYPE_%03d") , iField);
+		P.Add_Choice(pNode, s, _TL("Type"), _TL(""), Types);
+	}
+
+	//-----------------------------------------------------
+	if( Dlg_Parameters(&P, _TL("Field Properties")) )
+	{
+		pTable->Destroy();
+		pTable->Set_Name(Name);
+
+		for(iField=0; iField<nFields; iField++)
+		{
+			Name	= P(CSG_String::Format(SG_T("FIELD_%03d"), iField + 1).c_str())->asString();
+			iType	= P(CSG_String::Format(SG_T("TYPE_%03d" ), iField + 1).c_str())->asInt();
+
+			switch( iType )
+			{
+			default:
+			case 0:	Type	= SG_DATATYPE_String;	break;
+			case 1:	Type	= SG_DATATYPE_Char;		break;
+			case 2:	Type	= SG_DATATYPE_Short;	break;
+			case 3:	Type	= SG_DATATYPE_Int;		break;
+			case 4:	Type	= SG_DATATYPE_Float;	break;
+			case 5:	Type	= SG_DATATYPE_Double;	break;
+			case 6:	Type	= SG_DATATYPE_Color;	break;
+			}
+
+			pTable->Add_Field(Name, Type);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Create_Empty.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Table_Create_Empty.h                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Table_Create_Empty_H
+#define HEADER_INCLUDED__Table_Create_Empty_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTable_Create_Empty : public CSG_Module
+{
+public:
+	CTable_Create_Empty(void);
+	virtual ~CTable_Create_Empty(void);
+
+
+protected:
+
+	virtual bool			On_Execute	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Table_Create_Empty_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,172 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Table_Enumerate.cpp                  //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Table_Enumerate.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Enumerate::CTable_Enumerate(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name(_TL("Enumerate a Table Attribute"));
+
+	Set_Description(
+		_TL("Enumerate attribute of a table, i.e. assign to identical values of choosen attribute field unique identifiers.\n")
+	);
+
+	pNode	= Parameters.Add_Table(
+		NULL	, "INPUT"	, _TL("Input"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Table(
+		NULL	, "OUTPUT"	, _TL("Output"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+}
+
+//---------------------------------------------------------
+CTable_Enumerate::~CTable_Enumerate(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTable_Enumerate::On_Execute(void)
+{
+	int					iField, iField_ID, iID, iRecord, old_Field;
+	TSG_Table_Index_Order	old_Order;
+	CSG_String			Value;
+	CSG_Table				*pTable, *pOutput;
+	CSG_Table_Record		*pRecord;
+
+	//-----------------------------------------------------
+	pTable	= Parameters("INPUT")	->asTable();
+	pOutput	= Parameters("OUTPUT")	->asTable();
+	iField	= Parameters("FIELD")	->asInt();
+
+	//-----------------------------------------------------
+	if( iField >= 0 && iField < pTable->Get_Field_Count() && pTable->Get_Record_Count() > 0 )
+	{
+		if( pOutput != NULL && pOutput != pTable )
+		{
+			pOutput->Create		(*pTable);
+			pOutput->Set_Name	( pTable->Get_Name());
+			pTable	= pOutput;
+		}
+
+		//-------------------------------------------------
+		pTable->Add_Field(_TL("ENUM_ID"), SG_DATATYPE_Int);
+		iField_ID	= pTable->Get_Field_Count() - 1;
+
+		old_Order	= pTable->Get_Index_Order(0);
+		old_Field	= pTable->Get_Index_Field(0);
+
+		pTable->Set_Index(iField, TABLE_INDEX_Descending);
+		Value		= pTable->Get_Record_byIndex(0)->asString(iField);
+
+		for(iRecord=0, iID=1; iRecord<pTable->Get_Record_Count(); iRecord++)
+		{
+			pRecord	= pTable->Get_Record_byIndex(iRecord);
+
+			if( Value.Cmp(pRecord->asString(iField)) )
+			{
+				Value	= pRecord->asString(iField);
+				iID++;
+			}
+
+			pRecord->Set_Value(iField_ID, iID);
+		}
+
+		pTable->Set_Index(old_Field, old_Order);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Enumerate.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Table_Enumerate.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Table_Enumerate_H
+#define HEADER_INCLUDED__Table_Enumerate_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CTable_Enumerate : public CSG_Module
+{
+public:
+	CTable_Enumerate(void);
+	virtual ~CTable_Enumerate(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Table_Enumerate_H

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,182 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Table_Rotate.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Table_Rotate.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Rotate::CTable_Rotate(void)
+{
+	Set_Name(_TL("Rotate Table"));
+
+	Set_Description(
+		_TL("Rotate a table, i.e. swap rows and columns.\n")
+	);
+
+	Parameters.Add_Table(
+		NULL	, "INPUT"	, _TL("Input"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table(
+		NULL	, "OUTPUT"	, _TL("Output"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CTable_Rotate::~CTable_Rotate(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTable_Rotate::On_Execute(void)
+{
+	bool				bCopy;
+	int					x, y;
+	TSG_Data_Type	FieldType;
+	CSG_Table				*pInput, *pOutput;
+	CSG_Table_Record		*pRec_In, *pRec_Out;
+
+	//-----------------------------------------------------
+	pInput	= Parameters("INPUT")	->asTable();
+	pOutput	= Parameters("OUTPUT")	->asTable();
+
+	//-----------------------------------------------------
+	if( pInput->Get_Field_Count() > 0 && pInput->Get_Record_Count() > 0 )
+	{
+		if( pInput != pOutput )
+		{
+			bCopy	= true;
+		}
+		else
+		{
+			bCopy	= false;
+			pOutput	= SG_Create_Table();
+		}
+
+		pOutput->Destroy();
+		pOutput->Set_Name(CSG_String::Format(_TL("%s [rotated]"), pInput->Get_Name()));
+
+		FieldType	= SG_DATATYPE_String;
+
+		//-------------------------------------------------
+		pOutput->Add_Field(pInput->Get_Field_Name(0), SG_DATATYPE_String);
+
+		for(y=0; y<pInput->Get_Record_Count(); y++)
+		{
+			pOutput->Add_Field(pInput->Get_Record(y)->asString(0), FieldType);
+		}
+
+		for(y=1; y<pInput->Get_Field_Count(); y++)
+		{
+			pRec_Out	= pOutput->Add_Record();
+			pRec_Out->Set_Value(0, pInput->Get_Field_Name(y));
+
+			for(x=0; x<pInput->Get_Record_Count(); x++)
+			{
+				pRec_In		= pInput->Get_Record(x);
+
+				if( FieldType == SG_DATATYPE_String )
+				{
+					pRec_Out->Set_Value(x + 1, pRec_In->asString(y));
+				}
+				else
+				{
+					pRec_Out->Set_Value(x + 1, pRec_In->asDouble(y));
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( !bCopy )
+		{
+			pInput->Assign(pOutput);
+			delete(pOutput);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/table/table_tools/Table_Rotate.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      Table_Tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Table_Rotate.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//              SAGA User Group Associaton               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    SAGA User Group Associaton             //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Table_Rotate_H
+#define HEADER_INCLUDED__Table_Rotate_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CTable_Rotate : public CSG_Module
+{
+public:
+	CTable_Rotate(void);
+	virtual ~CTable_Rotate(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Table_Rotate_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,152 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("TIN - Tools") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Goettingen (c) 2004") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for Triangulated Irregular Network (TIN) processing.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("TIN") );
+	}
+}
+
+
+//---------------------------------------------------------
+#include "TIN_From_Grid.h"
+#include "TIN_From_Grid_Specific_Points.h"
+#include "TIN_From_Shapes.h"
+#include "TIN_To_Shapes.h"
+#include "TIN_Gradient.h"
+#include "TIN_Flow_Trace.h"
+#include "TIN_Flow_Parallel.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CTIN_From_Grid;
+		break;
+
+	case 1:
+		pModule	= new CTIN_From_Grid_Specific_Points;
+		break;
+
+	case 2:
+		pModule	= new CTIN_From_Shapes;
+		break;
+
+	case 3:
+		pModule	= new CTIN_To_Shapes;
+		break;
+
+	case 4:
+		pModule	= new CTIN_Gradient;
+		break;
+
+	case 5:
+		pModule	= new CTIN_Flow_Trace;
+		break;
+
+	case 6:
+		pModule	= new CTIN_Flow_Parallel;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Terrain_Analysis                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__tin_tools_H
+#define HEADER_INCLUDED__tin_tools_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef tin_tools_EXPORTS
+	#define	tin_tools_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	tin_tools_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__tin_tools_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,261 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 TIN_Flow_Parallel.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_Flow_Parallel.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_Flow_Parallel::CTIN_Flow_Parallel(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Flow Accumulation (Parallel)"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates the catchment area based on the selected elevation values.\n\n"
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_TIN(
+		NULL	, "DEM"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZFIELD"		, _TL("Z Values"),
+		_TL("")
+	);
+
+	Parameters.Add_TIN(
+		NULL	, "FLOW"		, _TL("Flow Accumulation"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Single Flow Direction"),
+			_TL("Multiple Flow Direction")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CTIN_Flow_Parallel::~CTIN_Flow_Parallel(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_Flow_Parallel::On_Execute(void)
+{
+	int			iPoint;
+	CSG_TIN		*pDEM;
+
+	//-----------------------------------------------------
+	pDEM		= Parameters("DEM")		->asTIN();
+	m_iHeight	= Parameters("ZFIELD")	->asInt();
+	m_pFlow		= Parameters("FLOW")	->asTIN();
+
+	m_pFlow->Create(*pDEM);
+
+	m_iArea		= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field(_TL("AREA")		, SG_DATATYPE_Double);
+
+	m_iFlow		= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field(_TL("FLOW")		, SG_DATATYPE_Double);
+
+	m_iSpecific	= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field(_TL("SPECIFIC")	, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	m_pFlow->Set_Index(m_iHeight, TABLE_INDEX_Descending);
+
+	for(iPoint=0; iPoint<m_pFlow->Get_Node_Count() && Set_Progress(iPoint, m_pFlow->Get_Node_Count()); iPoint++)
+	{
+		switch( Parameters("METHOD")->asInt() )
+		{
+		case 0: default:
+			Let_it_flow_single		(m_pFlow->Get_Node(m_pFlow->Get_Record_byIndex(iPoint)->Get_Index()));
+			break;
+
+		case 1:
+			Let_it_flow_multiple	(m_pFlow->Get_Node(m_pFlow->Get_Record_byIndex(iPoint)->Get_Index()));
+			break;
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CTIN_Flow_Parallel::Let_it_flow_single(CSG_TIN_Node *pPoint)
+{
+	int		i, iMin;
+	double	dz, dzMin, Area;
+
+	Area	= pPoint->Get_Polygon_Area();
+
+	pPoint->Set_Value(m_iArea, Area);
+	pPoint->Add_Value(m_iFlow, Area);
+
+	for(i=0, iMin=-1, dzMin=0.0; i<pPoint->Get_Neighbor_Count(); i++)
+	{
+		if( (dz = pPoint->Get_Gradient(i, m_iHeight)) > dzMin )
+		{
+			dzMin	= dz;
+			iMin	= i;
+		}
+	}
+
+	if( iMin >= 0 )
+	{
+		pPoint->Get_Neighbor(iMin)->Add_Value(m_iFlow, pPoint->asDouble(m_iFlow));
+	}
+
+	pPoint->Set_Value(m_iSpecific, Area > 0.0 ? 1.0 / Area : -1.0);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CTIN_Flow_Parallel::Let_it_flow_multiple(CSG_TIN_Node *pPoint)
+{
+	int		i;
+	double	d, dzSum, *dz, Area;
+
+	Area	= pPoint->Get_Polygon_Area();
+
+	pPoint->Set_Value(m_iArea, Area);
+	pPoint->Add_Value(m_iFlow, Area);
+
+	if( pPoint->Get_Neighbor_Count() > 0 )
+	{
+		dz	= (double *)SG_Malloc(pPoint->Get_Neighbor_Count() * sizeof(double));
+
+		for(i=0, dzSum=0.0; i<pPoint->Get_Neighbor_Count(); i++)
+		{
+			if( (d = pPoint->Get_Gradient(i, m_iHeight)) > 0.0 )
+			{
+				dzSum	+= (dz[i]	= d);
+			}
+			else
+			{
+				dz[i]	= 0.0;
+			}
+		}
+
+		if( dzSum > 0.0 )
+		{
+			d	= pPoint->asDouble(m_iFlow);
+
+			for(i=0; i<pPoint->Get_Neighbor_Count(); i++)
+			{
+				if( dz[i] > 0.0 )
+				{
+					pPoint->Get_Neighbor(i)->Add_Value(	m_iFlow, d * dz[i] / dzSum);
+				}
+			}
+		}
+
+		SG_Free(dz);
+	}
+
+	pPoint->Set_Value(m_iSpecific, Area > 0.0 ? 1.0 / Area : -1.0);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Parallel.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  TIN_Flow_Parallel.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_Flow_Parallel_H
+#define HEADER_INCLUDED__TIN_Flow_Parallel_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_Flow_Parallel : public CSG_Module
+{
+public:
+	CTIN_Flow_Parallel(void);
+	virtual ~CTIN_Flow_Parallel(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Terrain Analysis") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	int							m_iHeight, m_iArea, m_iFlow, m_iSpecific;
+
+	CSG_TIN						*m_pFlow;
+
+
+	void						Let_it_flow_single		(CSG_TIN_Node *pPoint);
+	void						Let_it_flow_multiple	(CSG_TIN_Node *pPoint);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_Flow_Parallel_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,227 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  TIN_Flow_Trace.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_Flow_Trace.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_Flow_Trace::CTIN_Flow_Trace(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Flow Accumulation (Trace)"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates the catchment area based on the selected elevation values.\n\n"
+	));
+
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_TIN(
+		NULL	, "DEM"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZFIELD"		, _TL("Z Values"),
+		_TL("")
+	);
+
+	pNode	= Parameters.Add_TIN(
+		NULL	, "FLOW"		, _TL("Flow Accumulation"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CTIN_Flow_Trace::~CTIN_Flow_Trace(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_Flow_Trace::On_Execute(void)
+{
+	int				iPoint;
+	CSG_TIN_Node	*pPoint;
+	CSG_TIN			*pDEM;
+
+	//-----------------------------------------------------
+	pDEM		= Parameters("DEM")		->asTIN();
+	m_iHeight	= Parameters("ZFIELD")	->asInt();
+	m_pFlow		= Parameters("FLOW")	->asTIN();
+
+	m_pFlow->Create(*pDEM);
+
+	m_iDir		= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field("DIRECTION"	, SG_DATATYPE_Double);
+
+	m_iArea		= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field("AREA"		, SG_DATATYPE_Double);
+
+	m_iFlow		= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field("FLOW"		, SG_DATATYPE_Double);
+
+	m_iSpecific	= m_pFlow->Get_Field_Count();
+	m_pFlow->Add_Field("Specific"	, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	for(iPoint=0; iPoint<m_pFlow->Get_Node_Count(); iPoint++)
+	{
+		pPoint	= m_pFlow->Get_Node(iPoint);
+
+		pPoint->Set_Value(m_iDir	, Get_Lowest_Neighbor(pPoint));
+		pPoint->Set_Value(m_iArea	, pPoint->Get_Polygon_Area());
+	}
+
+	//-----------------------------------------------------
+	for(iPoint=0; iPoint<m_pFlow->Get_Node_Count() && Set_Progress(iPoint, m_pFlow->Get_Node_Count()); iPoint++)
+	{
+		pPoint	= m_pFlow->Get_Node(iPoint);
+
+		if( pPoint->asDouble(m_iArea) > 0.0 )
+		{
+			Trace(pPoint, pPoint->asDouble(m_iArea));
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iPoint=0; iPoint<m_pFlow->Get_Node_Count() && Set_Progress(iPoint, m_pFlow->Get_Node_Count()); iPoint++)
+	{
+		pPoint	= m_pFlow->Get_Node(iPoint);
+
+		pPoint->Set_Value(m_iSpecific, pPoint->asDouble(m_iArea) > 0.0
+			? 1.0 / pPoint->asDouble(m_iArea)
+			: -1.0
+		);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CTIN_Flow_Trace::Get_Lowest_Neighbor(CSG_TIN_Node *pPoint)
+{
+	int		i, iMin;
+	double	dz, dzMin;
+
+	for(i=0, iMin=-1, dzMin=0.0; i<pPoint->Get_Neighbor_Count(); i++)
+	{
+		if( (dz = pPoint->Get_Gradient(i, m_iHeight)) > dzMin )
+		{
+			dzMin	= dz;
+			iMin	= i;
+		}
+	}
+
+	return( iMin );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CTIN_Flow_Trace::Trace(CSG_TIN_Node *pPoint, double Area)
+{
+	CSG_TIN_Node	*pNeighbor;
+
+	if( (pNeighbor = pPoint->Get_Neighbor(pPoint->asInt(m_iDir))) != NULL )
+	{
+		pNeighbor->Add_Value(m_iFlow, Area);
+
+		Trace(pNeighbor, Area);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Flow_Trace.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,102 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    TIN_Flow_Trace.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_Flow_Trace_H
+#define HEADER_INCLUDED__TIN_Flow_Trace_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_Flow_Trace : public CSG_Module
+{
+public:
+	CTIN_Flow_Trace(void);
+	virtual ~CTIN_Flow_Trace(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Terrain Analysis") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	int							m_iHeight, m_iDir, m_iArea, m_iFlow, m_iSpecific;
+
+	CSG_TIN						*m_pFlow;
+
+
+	int							Get_Lowest_Neighbor(CSG_TIN_Node *pPoint);
+
+	void						Trace(CSG_TIN_Node *pPoint, double Area);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_Flow_Trace_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,180 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   TIN_From_Grid.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_From_Grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_From_Grid::CTIN_From_Grid(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Grid to TIN"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Creates a TIN from grid points. No data values will be ignored.\n\n"
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "VALUES"		, _TL("Values"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_TIN(
+		NULL	, "TIN"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CTIN_From_Grid::~CTIN_From_Grid(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid::On_Execute(void)
+{
+	int						x, y, i;
+	CSG_TIN					*pTIN;
+	CSG_Grid					*pGrid;
+	CSG_Parameter_Grid_List	*pValues;
+	CSG_Shape					*pPoint;
+	CSG_Shapes					Points;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")	->asGrid();
+	pValues	= Parameters("VALUES")	->asGridList();
+
+	Points.Create(SHAPE_TYPE_Point);
+	Points.Add_Field("VALUE", SG_DATATYPE_Double);
+
+	for(i=0; i<pValues->Get_Count(); i++)
+	{
+		Points.Add_Field(pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
+	{
+		for(x=0; x<pGrid->Get_NX(); x++)
+		{
+			if( !pGrid->is_NoData(x, y) )
+			{
+				pPoint	= Points.Add_Shape();
+
+				pPoint->Add_Point(
+					pGrid->Get_XMin() + pGrid->Get_Cellsize() * x,
+					pGrid->Get_YMin() + pGrid->Get_Cellsize() * y
+				);
+
+				pPoint->Set_Value(0, pGrid->asDouble(x, y));
+
+				for(i=0; i<pValues->Get_Count(); i++)
+				{
+					pPoint->Set_Value(1 + i, pValues->asGrid(i)->asDouble(x, y));
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( Points.Get_Count() >= 3 )
+	{
+		pTIN	= Parameters("TIN")->asTIN();
+		pTIN->Create(&Points);
+		pTIN->Set_Name(pGrid->Get_Name());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,90 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    TIN_From_Grid.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_From_Grid_H
+#define HEADER_INCLUDED__TIN_From_Grid
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_From_Grid : public CSG_Module_Grid
+{
+public:
+	CTIN_From_Grid(void);
+	virtual ~CTIN_From_Grid(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_From_Grid_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,624 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//            TIN_From_Grid_Specific_Points.cpp          //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_From_Grid_Specific_Points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_From_Grid_Specific_Points::CTIN_From_Grid_Specific_Points(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Grid to TIN (Surface Specific Points)"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Creates a TIN by identifying (surface) specific points of a grid."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL	, "VALUES"		, _TL("Values"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_TIN(
+		NULL	, "TIN"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL("The method used to identify surface specific points."),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Mark Highest Neighbour"),
+			_TL("Opposite Neighbours"),
+			_TL("Flow Direction"),
+			_TL("Flow Direction (up and down)"),
+			_TL("Peucker & Douglas")
+		), 1
+	);
+
+	pNode	= Parameters.Add_Node(NULL, "THRESHOLDS", _TL("Thresholds"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "HIGH"		, _TL("Mark Highest Neighbour"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 4, 1, true, 4, true
+	);
+
+	Parameters.Add_Range(
+		pNode	, "FLOW"		, _TL("Flow Direction"),
+		_TL(""),
+		0, 3, 0, true, 8, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "PEUCKER"		, _TL("Peucker & Douglas"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 2
+	);
+}
+
+//---------------------------------------------------------
+CTIN_From_Grid_Specific_Points::~CTIN_From_Grid_Specific_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid_Specific_Points::On_Execute(void)
+{
+	bool					bResult;
+	int						x, y, i;
+	CSG_TIN					*pTIN;
+	CSG_Grid					*pGrid, Grid;
+	CSG_Parameter_Grid_List	*pValues;
+	CSG_Shape					*pPoint;
+	CSG_Shapes					Points;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")->asGrid();
+	Grid.Create(pGrid, SG_DATATYPE_Byte);
+
+	//-----------------------------------------------------
+	switch( Parameters("METHOD")->asInt() )
+	{
+	default:
+		bResult	= false;
+		break;
+
+	case 0:
+		bResult	= Get_MarkHighestNB	(&Grid, pGrid);
+		break;
+
+	case 1:
+		bResult	= Get_OppositeNB	(&Grid, pGrid, Parameters("HIGH")->asInt());
+		break;
+
+	case 2:
+		bResult	= Get_FlowDirection	(&Grid, pGrid,
+			(int)Parameters("FLOW")->asRange()->Get_LoVal(),
+			(int)Parameters("FLOW")->asRange()->Get_HiVal()
+		);
+		break;
+
+	case 3:
+		bResult	= Get_FlowDirection2(&Grid, pGrid,
+			(int)Parameters("FLOW")->asRange()->Get_HiVal()
+		);
+		break;
+
+	case 4:
+		bResult	= Get_Peucker		(&Grid, pGrid, Parameters("PEUCKER")->asDouble());
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		pValues	= Parameters("VALUES")->asGridList();
+
+		Points.Create(SHAPE_TYPE_Point);
+		Points.Add_Field(_TL("VALUE"), SG_DATATYPE_Double);
+
+		for(i=0; i<pValues->Get_Count(); i++)
+		{
+			Points.Add_Field(pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+		}
+
+		for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( Grid.asInt(x, y) != 0 )
+				{
+					pPoint	= Points.Add_Shape();
+
+					pPoint->Add_Point(
+						Get_XMin() + Get_Cellsize() * x,
+						Get_YMin() + Get_Cellsize() * y
+					);
+
+					pPoint->Set_Value(0, pGrid->asDouble(x, y));
+
+					for(i=0; i<pValues->Get_Count(); i++)
+					{
+						pPoint->Set_Value(1 + i, pValues->asGrid(i)->asDouble(x, y));
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( Points.Get_Count() >= 3 )
+		{
+			pTIN	= Parameters("TIN")->asTIN();
+			pTIN->Create(&Points);
+			pTIN->Set_Name(pGrid->Get_Name());
+		}
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid_Specific_Points::Get_MarkHighestNB(CSG_Grid *pResult, CSG_Grid *pGrid)	// Band & Lammers...
+{
+	int		i, x, y, ix, iy, xlo, ylo, xhi, yhi;
+	double	lo, hi, z;
+	CSG_Grid	*clo, *chi;
+
+	clo		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+	chi		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+
+	// Pass 1: Auszaehlen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX()-1; x++)
+        {
+			lo	= hi	= pGrid->asDouble(x,y);
+			xhi	= xlo	= x;
+			yhi	= ylo	= y;
+
+			for(i=0; i<4; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+  
+				if( is_InGrid(ix,iy) )
+				{
+					z	= pGrid->asDouble(ix,iy);
+
+					if( z > hi )
+					{
+						hi	= z;
+						xhi	= ix;
+						yhi	= iy;
+					}
+					else if( z < lo )
+					{
+						lo	= z;
+						xlo	= ix;
+						ylo	= iy;
+					}
+				}
+			}
+
+			clo->Add_Value(xlo,ylo,1);
+			chi->Add_Value(xhi,yhi,1);
+		}
+	}
+
+	// Pass 2: Setzen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX()-1; x++)
+		{
+			if( !chi->asChar(x,y) )
+			{
+				if( !clo->asChar(x,y) )
+					pResult->Set_Value(x,y, 2);	// Sattel
+				else
+					pResult->Set_Value(x,y, 1);	// Tiefenlinie
+			}
+			else if( !clo->asChar(x,y) )
+				pResult->Set_Value(x,y, -1);	// Wasserscheide
+			else
+				pResult->Set_Value(x,y,  0);	// Nichts...
+		}
+	}
+
+	delete(clo);
+	delete(chi);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid_Specific_Points::Get_OppositeNB(CSG_Grid *pResult, CSG_Grid *pGrid, int Threshold)
+{
+	int		i, x, y, ix, iy, jx, jy;
+	double	z, iz, jz;
+	CSG_Grid	*clo, *chi;
+
+	clo		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+	chi		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+
+	// Pass 1: Auszaehlen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX()-1; x++)
+        {
+			z	= pGrid->asDouble(x,y);
+
+			for(i=0; i<4; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+
+				if( is_InGrid(ix,iy) )
+				{
+					jx	= Get_xFrom(i,x);
+					jy	= Get_yFrom(i,y);
+  
+					if( is_InGrid(jx,jy) )
+					{
+						iz	= pGrid->asDouble(ix,iy);
+						jz	= pGrid->asDouble(jx,jy);
+
+						if( iz>z && jz>z )
+							chi->Add_Value(x,y,1);
+
+						else if( iz<z && jz<z )
+							clo->Add_Value(x,y,1);
+					}
+				}
+			}
+		}
+	}
+
+	// Pass 2: Setzen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX()-1; x++)
+		{
+			if( chi->asChar(x,y) )
+			{
+				if( clo->asChar(x,y) )
+					pResult->Set_Value(x,y, 5);					// Sattel
+				else
+					pResult->Set_Value(x,y, chi->asChar(x,y) );	// Tiefenlinie
+			}
+			else if( clo->asChar(x,y) )
+				pResult->Set_Value(x,y, - clo->asChar(x,y) );	// Wasserscheide
+			else
+				pResult->Set_Value(x,y, 0);						// Nichts...
+
+			pResult->Set_Value(x, y, abs(pResult->asInt(x, y)) >= Threshold ? 1 : 0);
+		}
+	}
+
+	delete(clo);
+	delete(chi);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid_Specific_Points::Get_FlowDirection(CSG_Grid *pResult, CSG_Grid *pGrid, int Min, int Max)
+{
+	bool	bLower;
+	int		x, y, i, ix, iy, xLow, yLow;
+	double	z, iz, zLow;
+
+	pResult->Assign();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+        {
+			z		= pGrid->asDouble(x,y);
+			bLower	= false;
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+  
+				if( is_InGrid(ix,iy) )
+				{
+					iz	= pGrid->asDouble(ix,iy);
+
+					if(iz<z)
+					{
+						if(!bLower)
+						{
+							bLower	= true;
+							zLow	= iz;
+							xLow	= ix;
+							yLow	= iy;
+						}
+						else if(iz<zLow)
+						{
+							zLow	= iz;
+							xLow	= ix;
+							yLow	= iy;
+						}
+					}
+				}
+			}
+
+			if(bLower)
+			{
+				pResult->Add_Value(xLow, yLow, 1);
+			}
+		}
+	}
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+        {
+			i	= pResult->asInt(x, y);
+
+			if( i <= Min )
+			{
+				pResult->Set_Value(x, y, -1);
+			}
+			else if( i >= Max )
+			{
+				pResult->Set_Value(x, y,  1);
+			}
+			else
+			{
+				pResult->Set_Value(x, y,  0);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid_Specific_Points::Get_FlowDirection2(CSG_Grid *pResult, CSG_Grid *pGrid, int Threshold)
+{
+	CSG_Grid	Grid(*pGrid), Result(*pResult);
+
+	Get_FlowDirection(pResult, &Grid, -1, Threshold);
+	Grid.Invert();
+	Get_FlowDirection(&Result, &Grid, -1, Threshold);
+
+	for(int n=0; n<Get_NCells(); n++)
+	{
+		if( Result.asInt(n) > 0 )
+		{
+			pResult->Set_Value(n, 1);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Grid_Specific_Points::Get_Peucker(CSG_Grid *pResult, CSG_Grid *pGrid, double Threshold)
+{
+	bool	wasPlus;
+	int		x, y, i, ix, iy, nSgn;
+	double	d, dPlus, dMinus, z, alt[8];
+
+	for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
+	{
+		for(x=0; x<pGrid->Get_NX(); x++)
+		{
+			z	= pGrid->asDouble(x,y);
+
+			for(i=0; i<8; i++)
+			{
+				ix	= pGrid->Get_System().Get_xTo(i,x);
+				iy	= pGrid->Get_System().Get_yTo(i,y);
+
+				if( pGrid->is_InGrid(ix,iy) )
+					alt[i]	= pGrid->asDouble(ix,iy);
+				else
+					alt[i]	= z;
+			}
+
+			dPlus	= dMinus	= 0;
+			nSgn	= 0;
+			wasPlus	= (alt[7] - z > 0) ? true : false;
+
+			for(i=0; i<8; i++)
+			{
+				d	= alt[i] - z;
+
+				if(d>0)
+				{
+					dPlus	+= d;
+					if(!wasPlus)
+					{
+						nSgn++;
+						wasPlus	= true;
+					}
+				}
+				else if(d<0)
+				{
+					dMinus	-= d;
+					if(wasPlus)
+					{
+						nSgn++;
+						wasPlus	= false;
+					}
+				}
+			}
+
+			i	= 0;
+			if(!dPlus)									// Peak...
+				i	=  9;
+			else if(!dMinus)							// Pit
+				i	= -9;
+			else if(nSgn==4)							// Pass
+				i	= 1;
+			else if(nSgn==2)
+			{
+				i	= nSgn	= 0;
+
+				if(alt[7]>z)
+				{
+					while(alt[i++]>z);
+					do	nSgn++;	while(alt[i++]<z);
+				}
+				else
+				{
+					while(alt[i++]<z);
+					do	nSgn++;	while(alt[i++]>z);
+				}
+
+				i	= 0;
+
+				if(nSgn==4)
+				{
+					if(dMinus-dPlus > Threshold)		// convex break...
+						i	=  2;
+					else if(dPlus-dMinus > Threshold)	// concave break...
+						i	= -2;
+				}
+				else	// lines:
+				{
+					if(dMinus-dPlus>0)					// Ridge
+						i	=  7;
+					else								// Channel
+						i	= -7;
+				}
+			}
+
+			pResult->Set_Value(x, y, i == 0 ? 0 : 1);
+		}
+    }
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Grid_Specific_Points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,99 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             TIN_From_Grid_Specific_Points.h           //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_From_Grid_Specific_Points_H
+#define HEADER_INCLUDED__TIN_From_Grid_Specific_Points_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_From_Grid_Specific_Points : public CSG_Module_Grid
+{
+public:
+	CTIN_From_Grid_Specific_Points(void);
+	virtual ~CTIN_From_Grid_Specific_Points(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	bool						Get_MarkHighestNB	(CSG_Grid *pResult, CSG_Grid *pGrid);
+	bool						Get_OppositeNB		(CSG_Grid *pResult, CSG_Grid *pGrid, int Threshold);
+	bool						Get_FlowDirection	(CSG_Grid *pResult, CSG_Grid *pGrid, int Min, int Max);
+	bool						Get_FlowDirection2	(CSG_Grid *pResult, CSG_Grid *pGrid, int Threshold);
+	bool						Get_Peucker			(CSG_Grid *pResult, CSG_Grid *pGrid, double Threshold);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_From_Grid_Specific_Points_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,130 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  TIN_From_Shapes.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_From_Shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_From_Shapes::CTIN_From_Shapes(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Shapes to TIN"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description(
+		_TL("Convert a shapes layer to a TIN\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode	= Parameters.Add_TIN(
+		NULL	, "TIN"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CTIN_From_Shapes::~CTIN_From_Shapes(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_From_Shapes::On_Execute(void)
+{
+	CSG_TIN	*pTIN;
+	CSG_Shapes	*pShapes;
+
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	pTIN	= Parameters("TIN")		->asTIN();
+
+
+	return( pTIN->Create(pShapes) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_From_Shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,90 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   TIN_From_Shapes.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_From_Shapes_H
+#define HEADER_INCLUDED__TIN_From_Shapes_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_From_Shapes : public CSG_Module
+{
+public:
+	CTIN_From_Shapes(void);
+	virtual ~CTIN_From_Shapes(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_From_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,185 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    TIN_Gradient.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_Gradient.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_Gradient::CTIN_Gradient(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Gradient"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description(
+		_TL("Calculates the gradient based on the values of each triangle's points.\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_TIN(
+		NULL	, "TIN"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZFIELD"		, _TL("Z Values"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "GRADIENT"	, _TL("TIN_Gradient"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "DEGREE"		, _TL("Output Unit"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Radians"),
+			_TL("Degree")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CTIN_Gradient::~CTIN_Gradient(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_Gradient::On_Execute(void)
+{
+	bool			bDegree;
+	int				iTriangle, zField;
+	double			a, b;
+	CSG_TIN_Triangle	*pTriangle;
+	CSG_TIN			*pTIN;
+	CSG_Shape			*pShape;
+	CSG_Shapes			*pShapes;
+
+	//-----------------------------------------------------
+	pTIN		= Parameters("TIN")			->asTIN();
+	zField		= Parameters("ZFIELD")		->asInt();
+	pShapes		= Parameters("GRADIENT")	->asShapes();
+	bDegree		= Parameters("DEGREE")		->asInt() == 1;
+
+	//-----------------------------------------------------
+	pShapes->Create(SHAPE_TYPE_Polygon, CSG_String::Format(_TL("TIN_Gradient [%s], TIN [%s]"), pTIN->Get_Field_Name(zField), pTIN->Get_Name()));
+
+	pShapes->Add_Field(_TL("ID")		, SG_DATATYPE_Int);
+	pShapes->Add_Field(_TL("AREA")	, SG_DATATYPE_Double);
+	pShapes->Add_Field(_TL("DECLINE"), SG_DATATYPE_Double);
+	pShapes->Add_Field(_TL("AZIMUTH"), SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	for(iTriangle=0; iTriangle<pTIN->Get_Triangle_Count() && Set_Progress(iTriangle, pTIN->Get_Triangle_Count()); iTriangle++)
+	{
+		pTriangle	= pTIN->Get_Triangle(iTriangle);
+
+		if( pTriangle->Get_Gradient(zField, a, b) )
+		{
+			if( bDegree )
+			{
+				a	*= M_RAD_TO_DEG;
+				b	*= M_RAD_TO_DEG;
+			}
+
+			pShape		= pShapes->Add_Shape();
+			pShape->Add_Point(pTriangle->Get_Node(0)->Get_Point());
+			pShape->Add_Point(pTriangle->Get_Node(1)->Get_Point());
+			pShape->Add_Point(pTriangle->Get_Node(2)->Get_Point());
+
+			pShape->Set_Value(0, iTriangle + 1);
+			pShape->Set_Value(1, pTriangle->Get_Area());
+			pShape->Set_Value(2, a);
+			pShape->Set_Value(3, b);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_Gradient.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,90 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     TIN_Gradient.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_Gradient_H
+#define HEADER_INCLUDED__TIN_Gradient_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_Gradient : public CSG_Module
+{
+public:
+	CTIN_Gradient(void);
+	virtual ~CTIN_Gradient(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Terrain Analysis") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_Gradient_H

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,283 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   TIN_To_Shapes.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TIN_To_Shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTIN_To_Shapes::CTIN_To_Shapes(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("TIN to Shapes"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description(
+		_TL("Converts a TIN data set to shapes layers.\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_TIN(
+		NULL	, "TIN"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "CENTER"		, _TL("Center of Triangles"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "EDGES"		, _TL("Edges"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "TRIANGLES"	, _TL("Triangles"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "POLYGONS"	, _TL("Polygons"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Polygon
+	);
+}
+
+//---------------------------------------------------------
+CTIN_To_Shapes::~CTIN_To_Shapes(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTIN_To_Shapes::On_Execute(void)
+{
+	int					i, j;
+	CSG_TIN_Node		*pPoint;
+	CSG_TIN_Edge		*pEdge;
+	CSG_TIN_Triangle	*pTriangle;
+	CSG_TIN				*pTIN;
+	CSG_Shape			*pShape;
+	CSG_Shapes			*pShapes;
+
+	//-----------------------------------------------------
+	pTIN		= Parameters("TIN")			->asTIN();
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("POINTS")		->asShapes();
+	pShapes->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("%s [TIN]"), pTIN->Get_Name()));
+
+	pShapes->Add_Field("POINT_ID", SG_DATATYPE_Int);
+	for(j=0; j<pTIN->Get_Field_Count(); j++)
+	{
+		pShapes->Add_Field(pTIN->Get_Field_Name(j), pTIN->Get_Field_Type(j));
+	}
+
+	for(i=0; i<pTIN->Get_Node_Count() && Set_Progress(i, pTIN->Get_Node_Count()); i++)
+	{
+		pPoint		= pTIN->Get_Node(i);
+		pShape		= pShapes->Add_Shape();
+
+		pShape->Add_Point(pPoint->Get_Point());
+
+		pShape->Set_Value(0, 1 + i);
+		for(j=0; j<pTIN->Get_Field_Count(); j++)
+		{
+			pShape->Set_Value(j + 1, pPoint->asString(j));
+		}
+	}
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("EDGES")	->asShapes();
+	pShapes->Create(SHAPE_TYPE_Line, CSG_String::Format(_TL("%s [TIN]"), pTIN->Get_Name()));
+
+	pShapes->Add_Field("ID"			, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_A"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_B"	, SG_DATATYPE_Int);
+
+	for(i=0; i<pTIN->Get_Edge_Count() && Set_Progress(i, pTIN->Get_Edge_Count()); i++)
+	{
+		pEdge		= pTIN->Get_Edge(i);
+		pShape		= pShapes->Add_Shape();
+
+		pShape->Add_Point(pEdge->Get_Node(0)->Get_Point());
+		pShape->Add_Point(pEdge->Get_Node(1)->Get_Point());
+
+		pShape->Set_Value(0, 1 + i);
+		pShape->Set_Value(1, 1 + pEdge->Get_Node(0)->Get_ID());
+		pShape->Set_Value(2, 1 + pEdge->Get_Node(1)->Get_ID());
+	}
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("TRIANGLES")	->asShapes();
+	pShapes->Create(SHAPE_TYPE_Polygon, CSG_String::Format(_TL("%s [TIN]"), pTIN->Get_Name()));
+
+	pShapes->Add_Field("ID"			, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_A"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_B"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_C"	, SG_DATATYPE_Int);
+
+	for(i=0; i<pTIN->Get_Triangle_Count() && Set_Progress(i, pTIN->Get_Triangle_Count()); i++)
+	{
+		pTriangle	= pTIN->Get_Triangle(i);
+		pShape		= pShapes->Add_Shape();
+
+		pShape->Add_Point(pTriangle->Get_Node(0)->Get_Point());
+		pShape->Add_Point(pTriangle->Get_Node(1)->Get_Point());
+		pShape->Add_Point(pTriangle->Get_Node(2)->Get_Point());
+
+		pShape->Set_Value(0, 1 + i);
+		pShape->Set_Value(1, 1 + pTriangle->Get_Node(0)->Get_ID());
+		pShape->Set_Value(2, 1 + pTriangle->Get_Node(1)->Get_ID());
+		pShape->Set_Value(3, 1 + pTriangle->Get_Node(2)->Get_ID());
+	}
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("CENTER")		->asShapes();
+	pShapes->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("%s [TIN]"), pTIN->Get_Name()));
+
+	pShapes->Add_Field("ID"			, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_A"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_B"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("POINT_ID_C"	, SG_DATATYPE_Int);
+
+	for(i=0; i<pTIN->Get_Triangle_Count() && Set_Progress(i, pTIN->Get_Triangle_Count()); i++)
+	{
+		pTriangle	= pTIN->Get_Triangle(i);
+		pShape		= pShapes->Add_Shape();
+
+		pShape->Add_Point(pTriangle->Get_CircumCircle_Point());
+
+		pShape->Set_Value(0, 1 + i);
+		pShape->Set_Value(1, 1 + pTriangle->Get_Node(0)->Get_Index());
+		pShape->Set_Value(2, 1 + pTriangle->Get_Node(1)->Get_Index());
+		pShape->Set_Value(3, 1 + pTriangle->Get_Node(2)->Get_Index());
+	}
+
+	//-----------------------------------------------------
+	CSG_Points	Points;
+
+	pShapes		= Parameters("POLYGONS")	->asShapes();
+	pShapes->Create(SHAPE_TYPE_Polygon, CSG_String::Format(_TL("%s [TIN]"), pTIN->Get_Name()));
+
+	pShapes->Add_Field("POINT_ID", SG_DATATYPE_Int);
+	for(j=0; j<pTIN->Get_Field_Count(); j++)
+	{
+		pShapes->Add_Field(pTIN->Get_Field_Name(j), pTIN->Get_Field_Type(j));
+	}
+
+	for(i=0; i<pTIN->Get_Node_Count() && Set_Progress(i, pTIN->Get_Node_Count()); i++)
+	{
+		pPoint		= pTIN->Get_Node(i);
+
+		if( pPoint->Get_Polygon(Points) )
+		{
+			pShape		= pShapes->Add_Shape();
+
+			for(j=0; j<Points.Get_Count(); j++)
+			{
+				pShape->Add_Point(Points[j]);
+			}
+
+			pShape->Set_Value(0, 1 + i);
+			for(j=0; j<pTIN->Get_Field_Count(); j++)
+			{
+				pShape->Set_Value(j + 1, pPoint->asString(j));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules/tin/tin_tools/TIN_To_Shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,90 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       TIN_Tools                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    TIN_To_Shapes.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TIN_To_Shapes_H
+#define HEADER_INCLUDED__TIN_To_Shapes_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTIN_To_Shapes : public CSG_Module
+{
+public:
+	CTIN_To_Shapes(void);
+	virtual ~CTIN_To_Shapes(void);
+
+	virtual const SG_Char *		Get_MenuPath	(void)	{	return( _TL("R:Conversion") );	}
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__TIN_To_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,330 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 GSGrid_Regression.cpp                 //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Regression.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GRID_ZFACTOR	true
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Regression::CGSGrid_Regression(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Regression Analysis (Grid/Points)"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Regression analysis of point attributes with grid values. "
+		"The regression function is used to create a new grid with (extrapolated) values. \n"
+		"\n"
+		"Reference:\n"
+		"- Bahrenberg, G., Giese, E., Nipper, J. (1990): "
+		"'Statistische Methoden in der Geographie 1 - Univariate und bivariate Statistik', "
+		"Stuttgart, 233p.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ATTRIBUTE"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "REGRESSION"	, _TL("Regression"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "RESIDUAL"	, _TL("Residuals"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Choice(
+		NULL	,"INTERPOL"		, _TL("Grid Interpolation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Regression Function"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Y = a + b * X (linear)"),
+			_TL("Y = a + b / X"),
+			_TL("Y = a / (b - X)"),
+			_TL("Y = a * X^b (power)"),
+			_TL("Y = a e^(b * X) (exponential)"),
+			_TL("Y = a + b * ln(X) (logarithmic)")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CGSGrid_Regression::~CGSGrid_Regression(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Regression::On_Execute(void)
+{
+	int					iAttribute;
+	TSG_Regression_Type	Type;
+	CSG_Shapes			*pShapes, *pResiduals;
+	CSG_Grid			*pGrid, *pRegression;
+
+	//-----------------------------------------------------
+	pGrid			= Parameters("GRID")		->asGrid();
+	pRegression		= Parameters("REGRESSION")	->asGrid();
+	pShapes			= Parameters("SHAPES")		->asShapes();
+	pResiduals		= Parameters("RESIDUAL")	->asShapes();
+	iAttribute		= Parameters("ATTRIBUTE")	->asInt();
+	m_Interpolation	= Parameters("INTERPOL")	->asInt();
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	default:
+	case 0:	Type	= REGRESSION_Linear;	break;	// Y = a + b * X
+	case 1:	Type	= REGRESSION_Rez_X;		break;	// Y = a + b / X
+	case 2:	Type	= REGRESSION_Rez_Y;		break;	// Y = a / (b - X)
+	case 3:	Type	= REGRESSION_Pow;		break;	// Y = a * X^b
+	case 4:	Type	= REGRESSION_Exp;		break;	// Y = a e^(b * X)
+	case 5:	Type	= REGRESSION_Log;		break;	// Y = a + b * ln(X)
+	}
+
+	//-----------------------------------------------------
+	if( Get_Regression(pGrid, pShapes, pResiduals, iAttribute, Type) )
+	{
+		pRegression->Set_Name(CSG_String::Format(SG_T("%s (%s)"), pShapes->Get_Name(), Get_Name()));
+
+		Set_Regression(pGrid, pRegression);
+
+		Set_Residuals(pResiduals);
+
+		Message_Add(m_Regression.asString());
+
+		m_Regression.Destroy();
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	m_Regression.Destroy();
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Regression::Get_Regression(CSG_Grid *pGrid, CSG_Shapes *pShapes, CSG_Shapes *pResiduals, int iAttribute, TSG_Regression_Type Type)
+{
+	int			iShape, iPart, iPoint;
+	double		zShape, zGrid;
+	TSG_Point	Point;
+	CSG_Shape	*pShape, *pResidual;
+
+	//-----------------------------------------------------
+	if( pResiduals )
+	{
+		pResiduals->Create(SHAPE_TYPE_Point, _TL("Residuals"));
+		pResiduals->Add_Field("ID"			, SG_DATATYPE_Int);
+		pResiduals->Add_Field("Y"			, SG_DATATYPE_Double);
+		pResiduals->Add_Field("X"			, SG_DATATYPE_Double);
+		pResiduals->Add_Field("Y_GUESS"		, SG_DATATYPE_Double);
+		pResiduals->Add_Field("Y_RESIDUAL"	, SG_DATATYPE_Double);
+		pResiduals->Add_Field("Y_RES_VAR"	, SG_DATATYPE_Double);
+	}
+
+	m_Regression.Destroy();
+
+	//-----------------------------------------------------
+	for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+	{
+		pShape	= pShapes->Get_Shape(iShape);
+		zShape	= pShape->asDouble(iAttribute);
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				if( pGrid->Get_Value(Point = pShape->Get_Point(iPoint, iPart), zGrid, m_Interpolation, GRID_ZFACTOR) )
+				{
+					m_Regression.Add_Values(zGrid, zShape);
+
+					if( pResiduals )
+					{
+						pResidual	= pResiduals->Add_Shape();
+						pResidual->Add_Point(Point);
+						pResidual->Set_Value(0, m_Regression.Get_Count());
+						pResidual->Set_Value(1, zShape);
+						pResidual->Set_Value(2, zGrid);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( m_Regression.Calculate(Type) );
+}
+
+//---------------------------------------------------------
+bool CGSGrid_Regression::Set_Regression(CSG_Grid *pGrid, CSG_Grid *pRegression)
+{
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( pGrid->is_NoData(x, y) )
+				pRegression->Set_NoData(x, y);
+			else
+				pRegression->Set_Value (x, y, m_Regression.Get_y(pGrid->asDouble(x, y, GRID_ZFACTOR)));
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGSGrid_Regression::Set_Residuals(CSG_Shapes *pResiduals)
+{
+	int		iPoint;
+	double	m, b, v, y;
+	CSG_Shape	*pPoint;
+
+	if( pResiduals )
+	{
+		m	= m_Regression.Get_Coefficient();
+		b	= m_Regression.Get_Constant();
+		v	= 100.0 / m_Regression.Get_yVariance();
+
+		for(iPoint=0; iPoint<pResiduals->Get_Count() && Set_Progress(iPoint, pResiduals->Get_Count()); iPoint++)
+		{
+			pPoint	= pResiduals->Get_Shape(iPoint);
+
+			pPoint->Set_Value(3, y = pPoint->asDouble(2) * m + b);
+			pPoint->Set_Value(4, y = pPoint->asDouble(1) - y);
+			pPoint->Set_Value(5, y * v);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  GSGrid_Regression.h                  //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Regression_H
+#define HEADER_INCLUDED__GSGrid_Regression_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSGrid_Regression : public CSG_Module_Grid
+{
+public:
+	CGSGrid_Regression(void);
+	virtual ~CGSGrid_Regression(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Regression Analysis") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	int						m_Interpolation;
+
+	CSG_Regression			m_Regression;
+
+
+	bool					Get_Regression		(CSG_Grid *pGrid, CSG_Shapes *pShapes, CSG_Shapes *pResiduals, int iAttribute, TSG_Regression_Type Type);
+	bool					Set_Regression		(CSG_Grid *pGrid, CSG_Grid *pRegression);
+	bool					Set_Residuals		(CSG_Shapes *pResiduals);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Regression_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,388 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             GSGrid_Regression_Multiple.cpp            //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Regression_Multiple.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GRID_ZFACTOR	true
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Regression_Multiple::CGSGrid_Regression_Multiple(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Multiple Regression Analysis (Grids/Points)"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Linear regression analysis of point attributes with multiple grids. "
+		"Details of the regression/correlation analysis will be saved to a table. "
+		"The regression function is used to create a new grid with (extrapolated) values. "
+		"The multiple regression analysis uses a forward selection procedure. \n"
+		"\n"
+		"Reference:\n"
+		"- Bahrenberg, G., Giese, E., Nipper, J. (1992): "
+		"'Statistische Methoden in der Geographie 2 - Multivariate Statistik', "
+		"Stuttgart, 415p.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ATTRIBUTE"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Details"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "RESIDUAL"	, _TL("Residuals"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "REGRESSION"	, _TL("Regression"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	,"INTERPOL"		, _TL("Grid Interpolation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+CGSGrid_Regression_Multiple::~CGSGrid_Regression_Multiple(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Regression_Multiple::On_Execute(void)
+{
+	int						iAttribute;
+	CSG_Table					*pTable;
+	CSG_Shapes					*pShapes, *pResiduals;
+	CSG_Grid					*pRegression;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	//-----------------------------------------------------
+	pGrids			= Parameters("GRIDS")		->asGridList();
+	pRegression		= Parameters("REGRESSION")	->asGrid();
+	pTable			= Parameters("TABLE")		->asTable();
+	pShapes			= Parameters("SHAPES")		->asShapes();
+	pResiduals		= Parameters("RESIDUAL")	->asShapes();
+	iAttribute		= Parameters("ATTRIBUTE")	->asInt();
+	m_Interpolation	= Parameters("INTERPOL")	->asInt();
+
+	//-----------------------------------------------------
+	if( Get_Regression(pGrids, pShapes, iAttribute) )
+	{
+		pRegression->Set_Name(CSG_String::Format(SG_T("%s (%s)"), pShapes->Get_Name(), Get_Name()));
+
+		Set_Regression(pGrids, pRegression);
+
+		Set_Residuals(pShapes, iAttribute, pResiduals, pRegression);
+
+		Set_Message(pGrids);
+
+		if( pTable )
+		{
+			pTable->Assign(m_Regression.Get_Result());
+			pTable->Set_Name(_TL("Multiple Regression Analysis"));
+		}
+
+		m_Regression.Destroy();
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	m_Regression.Destroy();
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Regression_Multiple::Get_Regression(CSG_Parameter_Grid_List *pGrids, CSG_Shapes *pShapes, int iAttribute)
+{
+	int				iShape, iPart, iPoint, iGrid;
+	double			zShape, zGrid;
+	TSG_Point		Point;
+	CSG_Table			Table;
+	CSG_Table_Record	*pRecord;
+	CSG_Shape			*pShape;
+
+	//-----------------------------------------------------
+	Table.Destroy();
+	Table.Add_Field(pShapes->Get_Name(), SG_DATATYPE_Double);
+
+	for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++)
+	{
+		Table.Add_Field(pGrids->asGrid(iGrid)->Get_Name(), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+	{
+		pShape	= pShapes->Get_Shape(iShape);
+		zShape	= pShape->asDouble(iAttribute);
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				Point	= pShape->Get_Point(iPoint, iPart);
+				pRecord	= Table.Add_Record();
+				pRecord->Set_Value(0, zShape);
+
+				for(iGrid=0; iGrid<pGrids->Get_Count() && pRecord; iGrid++)
+				{
+					if( pGrids->asGrid(iGrid)->Get_Value(Point, zGrid, m_Interpolation, GRID_ZFACTOR) )
+					{
+						pRecord->Set_Value(1 + iGrid, zGrid);
+					}
+					else
+					{
+						pRecord	= NULL;
+						Table.Del_Record(Table.Get_Record_Count() - 1);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( m_Regression.Calculate(Table) );
+}
+
+//---------------------------------------------------------
+bool CGSGrid_Regression_Multiple::Set_Regression(CSG_Parameter_Grid_List *pGrids, CSG_Grid *pRegression)
+{
+	bool	bOk;
+	int		x, y, i;
+	double	z;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			z	= m_Regression.Get_RConst();
+
+			for(i=0, bOk=true; i<pGrids->Get_Count() && bOk; i++)
+			{
+				if( (bOk = !pGrids->asGrid(i)->is_NoData(x, y)) == true )
+				{
+					z	+= m_Regression.Get_RCoeff(i) * pGrids->asGrid(i)->asDouble(x, y);
+				}
+			}
+
+			if( bOk )
+			{
+				pRegression->Set_Value (x, y, z);
+			}
+			else
+			{
+				pRegression->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGSGrid_Regression_Multiple::Set_Residuals(CSG_Shapes *pShapes, int iAttribute, CSG_Shapes *pResiduals, CSG_Grid *pRegression)
+{
+	int			iPoint, iPart, iShape;
+	double		zShape, zGrid;
+	TSG_Point	Point;
+	CSG_Shape		*pShape, *pResidual;
+
+	//-----------------------------------------------------
+	if( pResiduals )
+	{
+		pResiduals->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pShapes->Get_Name(), _TL("Residuals")));
+		pResiduals->Add_Field(pShapes->Get_Field_Name(iAttribute), SG_DATATYPE_Double);
+		pResiduals->Add_Field("TREND"	, SG_DATATYPE_Double);
+		pResiduals->Add_Field("RESIDUAL", SG_DATATYPE_Double);
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= pShapes->Get_Shape(iShape);
+			zShape	= pShape->asDouble(iAttribute);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					Point	= pShape->Get_Point(iPoint, iPart);
+
+					if( pRegression->Get_Value(Point, zGrid, m_Interpolation, GRID_ZFACTOR) )
+					{
+						pResidual	= pResiduals->Add_Shape();
+						pResidual->Add_Point(Point);
+						pResidual->Set_Value(0, zShape);
+						pResidual->Set_Value(1, zGrid);
+						pResidual->Set_Value(2, zShape - zGrid);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+void CGSGrid_Regression_Multiple::Set_Message(CSG_Parameter_Grid_List *pGrids)
+{
+	int		i, j;
+
+	Message_Add(SG_T("\n"), false);
+	Message_Add(CSG_String::Format(SG_T("\n%s:"), _TL("Regression")), false);
+	Message_Add(CSG_String::Format(SG_T("\n Y = %f"), m_Regression.Get_RConst()), false);
+
+	for(i=0; i<pGrids->Get_Count(); i++)
+	{
+		if( (j = m_Regression.Get_Ordered(i)) >= 0 && j < pGrids->Get_Count() )
+		{
+			Message_Add(CSG_String::Format(SG_T(" %+f*[%s]"), m_Regression.Get_RCoeff(j), pGrids->asGrid(j)->Get_Name()), false);
+		}
+	}
+
+	Message_Add(SG_T("\n"), false);
+	Message_Add(CSG_String::Format(SG_T("\n%s:"), _TL("Correlation")), false);
+
+	for(i=0; i<pGrids->Get_Count(); i++)
+	{
+		if( (j = m_Regression.Get_Ordered(i)) >= 0 && j < pGrids->Get_Count() )
+		{
+			Message_Add(CSG_String::Format(SG_T("\n%d: R\xc2\xb2 = %f%% [%f%%] -> %s"), i + 1, 100.0 * m_Regression.Get_R2(j), 100.0 * m_Regression.Get_R2_Change(j), pGrids->asGrid(j)->Get_Name()), false);
+		}
+	}
+
+	Message_Add(SG_T("\n"), false);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Regression_Multiple.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,111 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              GSGrid_Regression_Multiple.h             //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Regression_Multiple_H
+#define HEADER_INCLUDED__GSGrid_Regression_Multiple_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSGrid_Regression_Multiple : public CSG_Module_Grid
+{
+public:
+	CGSGrid_Regression_Multiple(void);
+	virtual ~CGSGrid_Regression_Multiple(void);
+
+	virtual const SG_Char *		Get_MenuPath		(void)	{	return( _TL("R:Regression Analysis") );	}
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+	int							m_Interpolation;
+
+	CSG_Regression_Multiple		m_Regression;
+
+
+	bool						Get_Regression		(CSG_Parameter_Grid_List *pGrids, CSG_Shapes *pShapes, int iAttribute);
+	bool						Set_Regression		(CSG_Parameter_Grid_List *pGrids, CSG_Grid *pRegression);
+	bool						Set_Residuals		(CSG_Shapes *pShapes, int iAttribute, CSG_Shapes *pResiduals, CSG_Grid *pRegression);
+	void						Set_Message			(CSG_Parameter_Grid_List *pGrids);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Regression_Multiple_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,240 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  GSGrid_Residuals.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Residuals.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Residuals::CGSGrid_Residuals(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Residual Analysis (Grid)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW("Relations of each grid cell to its neighborhood. "
+		"Wilson & Gallant (2000) used this type of calculation in terrain analysis.\n"
+		"\n"
+		"Reference:\n"
+		"- Wilson, J.P., Gallant, J.C., (Eds.), 2000: "
+		"'Terrain analysis - principles and applications', "
+		"New York, John Wiley & Sons, Inc.\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(	NULL, "INPUT"		, _TL("Grid")						, _TL(""), PARAMETER_INPUT);
+
+	Parameters.Add_Grid(	NULL, "MEAN"		, _TL("Mean Value")					, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "DIFF"		, _TL("Difference from Mean Value")	, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "STDDEV"		, _TL("Standard Deviation")			, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "RANGE"		, _TL("Value Range")				, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "MIN"			, _TL("Minimum Value")				, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "MAX"			, _TL("Maximum Value")				, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "DEVMEAN"		, _TL("Deviation from Mean Value")	, _TL(""), PARAMETER_OUTPUT);
+	Parameters.Add_Grid(	NULL, "PERCENTILE"	, _TL("Percentile")					, _TL(""), PARAMETER_OUTPUT);
+
+	Parameters.Add_Value(	NULL, "RADIUS"		, _TL("Radius (Cells)")				, _TL(""), PARAMETER_TYPE_Int, 7, 1, true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Residuals::On_Execute(void)
+{
+	pInput		= Parameters("INPUT")		->asGrid();
+
+	pMean		= Parameters("MEAN")		->asGrid();
+	pDiff		= Parameters("DIFF")		->asGrid();
+	pStdDev		= Parameters("STDDEV")		->asGrid();
+	pRange		= Parameters("RANGE")		->asGrid();
+	pMin		= Parameters("MIN")			->asGrid();
+	pMax		= Parameters("MAX")			->asGrid();
+	pDevMean	= Parameters("DEVMEAN")		->asGrid();
+	pPercentile	= Parameters("PERCENTILE")	->asGrid();
+
+	DataObject_Set_Colors(pDiff			, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pStdDev		, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pRange		, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pMin			, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pMax			, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pDevMean		, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pPercentile	, 100, SG_COLORS_RED_GREY_BLUE, true);
+
+	//-----------------------------------------------------
+	m_Radius.Create(Parameters("RADIUS")->asInt() + 1);
+
+	Values		= (double *)malloc(m_Radius.Get_nPoints() * sizeof(double));
+
+	//-----------------------------------------------------
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			Get_Value(x, y);
+		}
+	}
+
+	//-----------------------------------------------------
+	m_Radius.Destroy();
+
+	free(Values);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+int CGSGrid_Residuals::Get_Value(int x, int y)
+{
+	int		iPoint, ix, iy, nPoints, nLower;
+	double	Value, zValue, zMin, zMax, Mean, StdDev;
+
+	//-----------------------------------------------------
+	nPoints	= 0;
+
+	if( pInput->is_InGrid(x, y) )
+	{
+		nLower	= 0;
+		Mean	= 0.0;
+		zValue	= pInput->asDouble(x, y);
+
+		for(iPoint=0; iPoint<m_Radius.Get_nPoints(); iPoint++)
+		{
+			m_Radius.Get_Point(iPoint, x, y, ix, iy);
+
+			if( pInput->is_InGrid(ix, iy) )
+			{
+				Mean	+= (Values[nPoints++]	= Value	= pInput->asDouble(ix, iy));
+
+				if( nPoints <= 1 )
+				{
+					zMin	= zMax	= Value;
+				}
+				else if( zMin > Value )
+				{
+					zMin	= Value;
+				}
+				else if( zMax < Value )
+				{
+					zMax	= Value;
+				}
+
+				if( Value < zValue )
+				{
+					nLower++;
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( nPoints <= 1 )
+	{
+		pMean		->Set_NoData(x, y);
+		pDiff		->Set_NoData(x, y);
+		pStdDev		->Set_NoData(x, y);
+		pRange		->Set_NoData(x, y);
+		pMin		->Set_NoData(x, y);
+		pMax		->Set_NoData(x, y);
+		pDevMean	->Set_NoData(x, y);
+		pPercentile	->Set_NoData(x, y);
+	}
+	else
+	{
+		Mean		/= (double)nPoints;
+
+		StdDev		= 0.0;
+
+		for(iPoint=0; iPoint<nPoints; iPoint++)
+		{
+			Value	= Values[iPoint] - Mean;
+
+			StdDev	+= Value * Value;
+		}
+
+		StdDev		/= (double)(nPoints - 1.0);
+
+		pMean		->Set_Value(x, y, Mean);
+		pDiff		->Set_Value(x, y, zValue - Mean);
+		pStdDev		->Set_Value(x, y, StdDev);
+		pRange		->Set_Value(x, y, zMax - zMin);
+		pMin		->Set_Value(x, y, zMin);
+		pMax		->Set_Value(x, y, zMax);
+		pDevMean	->Set_Value(x, y, (zValue - Mean) / StdDev);
+		pPercentile	->Set_Value(x, y, 100.0 * (double)nLower / (double)(nPoints - 1.0));
+	}
+
+	return( nPoints );
+}

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Residuals.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  GSGrid_Residuals.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Residuals_H
+#define HEADER_INCLUDED__GSGrid_Residuals_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSGrid_Residuals : public CSG_Module_Grid
+{
+public:
+	CGSGrid_Residuals(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Neighborhoods" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	double					*Values;
+
+	CSG_Grid_Radius			m_Radius;
+
+	CSG_Grid				*pInput, *pMean, *pDiff, *pStdDev, *pRange, *pMin, *pMax, *pDevMean, *pPercentile;
+
+
+	int						Get_Value		(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Residuals_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,236 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 GSGrid_Statistics.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Statistics.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Statistics::CGSGrid_Statistics(void)
+{
+	Set_Name		(_TL("Statistics for Grids"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW("Calculates statistical properties (arithmetic mean, minimum, maximum, "
+		"variance, standard deviation) for each cell position for the values of "
+		"the selected grids."
+	));
+
+
+	Parameters.Add_Grid_List(
+		NULL, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "MEAN"	, _TL("Arithmetic Mean"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "MIN"		, _TL("Minimum"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "MAX"		, _TL("Maximum"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "VAR"		, _TL("Variance"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "STDDEV"	, _TL("Standard Deviation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "STDDEVLO", _TL("Mean less Standard Deviation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "STDDEVHI", _TL("Mean plus Standard Deviation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+}
+
+//---------------------------------------------------------
+CGSGrid_Statistics::~CGSGrid_Statistics(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Statistics::On_Execute(void)
+{
+	int						x, y, i, n;
+	double					z, m, v, min, max;
+	CSG_Grid					*pMean, *pMin, *pMax, *pVar, *pStdDev, *pStdDevLo, *pStdDevHi;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("GRIDS")	->asGridList();
+
+	pMean		= Parameters("MEAN")	->asGrid();
+	pMin		= Parameters("MIN")		->asGrid();
+	pMax		= Parameters("MAX")		->asGrid();
+	pVar		= Parameters("VAR")		->asGrid();
+	pStdDev		= Parameters("STDDEV")	->asGrid();
+	pStdDevLo	= Parameters("STDDEVLO")->asGrid();
+	pStdDevHi	= Parameters("STDDEVHI")->asGrid();
+
+	//-----------------------------------------------------
+	if( pGrids->Get_Count() > 1 && (pMean || pMin || pMax || pVar || pStdDev || pStdDevLo || pStdDevHi) )
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				for(i=0, n=0, m=0.0, v=0.0; i<pGrids->Get_Count(); i++)
+				{
+					if( !pGrids->asGrid(i)->is_NoData(x, y) )
+					{
+						z	= pGrids->asGrid(i)->asDouble(x, y);
+
+						if( n == 0 )
+						{
+							min	= max	= z;
+						}
+						else if( min > z )
+						{
+							min	= z;
+						}
+						else if( max < z )
+						{
+							max	= z;
+						}
+
+						m	+= z;
+						v	+= z * z;
+						n++;
+					}
+				}
+
+				//-----------------------------------------
+				if( n == 0 )
+				{
+					if( pMean )		pMean		->Set_NoData(x, y);
+					if( pMin )		pMin		->Set_NoData(x, y);
+					if( pMax )		pMax		->Set_NoData(x, y);
+					if( pVar )		pVar		->Set_NoData(x, y);
+					if( pStdDev )	pStdDev		->Set_NoData(x, y);
+					if( pStdDevLo )	pStdDevLo	->Set_NoData(x, y);
+					if( pStdDevHi )	pStdDevHi	->Set_NoData(x, y);
+				}
+				else
+				{
+					m	= m / (double)n;
+					v	= v / (double)n - m * m;
+					z	= sqrt(v);
+
+					if( pMean )		pMean		->Set_Value(x, y, m);
+					if( pMin )		pMin		->Set_Value(x, y, min);
+					if( pMax )		pMax		->Set_Value(x, y, max);
+					if( pVar )		pVar		->Set_Value(x, y, v);
+					if( pStdDev )	pStdDev		->Set_Value(x, y, z);
+					if( pStdDevLo )	pStdDevLo	->Set_Value(x, y, m - z);
+					if( pStdDevHi )	pStdDevHi	->Set_Value(x, y, m + z);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Statistics.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  GSGrid_Statistics.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Statistics_H
+#define HEADER_INCLUDED__GSGrid_Statistics_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSGrid_Statistics : public CSG_Module_Grid  
+{
+public:
+	CGSGrid_Statistics(void);
+	virtual ~CGSGrid_Statistics(void);
+
+
+protected:
+
+	virtual bool			On_Execute	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Statistics_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,344 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  GSGrid_Variance.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Variance.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Variance::CGSGrid_Variance(void)
+{
+	Set_Name		(_TL("Representativeness (Grid)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Representativeness - calculation of the variance within a given search radius.\n"
+		"\n"
+		"Reference:\n"
+		"- Boehner, J., Koethe, R., Trachinow, C. (1997): "
+		"'Weiterentwicklung der automatischen Reliefanalyse auf der Basis von Digitalen Gelaendemodellen', "
+		"Goettinger Geographische Abhandlungen, Vol.100, p.3-21\n"
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "INPUT"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"	, _TL("Representativeness"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "RADIUS"	, _TL("Radius (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 10
+	);
+
+	Parameters.Add_Value(
+		NULL	, "EXPONENT", _TL("Exponent"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1
+	);
+}
+
+//---------------------------------------------------------
+CGSGrid_Variance::~CGSGrid_Variance(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Variance::On_Execute(void)
+{
+	int		x, y;
+
+	//-----------------------------------------------------
+	pInput		= Parameters("INPUT"	)->asGrid();
+	pOutput		= Parameters("RESULT"	)->asGrid();
+
+	maxRadius	= Parameters("RADIUS"	)->asInt();
+	Exponent	= Parameters("EXPONENT"	)->asDouble();
+
+	//-----------------------------------------------------
+	Initialize();
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			pOutput->Set_Value(x,y, Get_Laenge(x,y) );
+		}
+	}
+
+	//-----------------------------------------------------
+	Finalize();
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGSGrid_Variance::Initialize(void)
+{
+	pOutput->Assign_NoData();
+
+	V		= (double *)malloc((maxRadius + 2) * sizeof(double));
+	Z		= (int    *)malloc((maxRadius + 2) * sizeof(int   ));
+
+	g		= (double *)malloc((maxRadius + 2) * sizeof(double));
+	m		= (double *)malloc((maxRadius + 2) * sizeof(double));
+
+	rLength	= (int    *)malloc((maxRadius + 2) * sizeof(int   ));
+
+	Init_Radius();
+}
+
+//---------------------------------------------------------
+void CGSGrid_Variance::Init_Radius(void)
+{
+	int		k, maxZ;
+
+	long	i, j, iijj, 
+			rr, r1r1, z;
+
+	maxZ		= z	= 0;
+	rLength[0]	= 0;
+
+	x_diff		= y_diff	= NULL;
+
+	for(k=1; k<=maxRadius; k++) 
+	{
+		rr		= k*k;
+		r1r1	= (k - 1) * (k - 1);
+
+		for(i=-k; i<=k; i++)
+		{
+			for(j=-k; j<=k; j++) 
+			{
+				iijj	= i*i + j*j;
+
+				if( iijj<=rr && iijj>r1r1 ) 
+				{
+					if( maxZ<=z )
+					{
+						maxZ	+= 1000;
+						x_diff	= (int *)realloc(x_diff,maxZ*sizeof(int));
+						y_diff	= (int *)realloc(y_diff,maxZ*sizeof(int));
+					}
+
+					x_diff[z]	= j;
+					y_diff[z]	= i;
+
+					z++;
+				}
+			}
+		}
+
+		rLength[k]	= z;
+	}
+}
+
+//---------------------------------------------------------
+void CGSGrid_Variance::Finalize(void)
+{
+	free(V);
+	free(Z);
+
+	free(rLength);
+	free(g);
+	free(m);
+
+	free(x_diff);
+	free(y_diff);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CGSGrid_Variance::Get_Laenge(int x, int y)
+{
+	int		iRadius, Count;
+
+	double	d;
+
+	//-----------------------------------------------------
+	V[0]	= Get_GSGrid_Variance(x,y,1,Count);
+	Z[0]	= Count;
+
+	for(iRadius=1; iRadius<maxRadius; iRadius++)
+	{
+		V[iRadius]	= V[iRadius-1] + Get_GSGrid_Variance(x, y, iRadius + 1, Count);
+		Z[iRadius]	= Z[iRadius-1] + Count;
+	}
+
+	for(iRadius=0; iRadius<maxRadius; iRadius++)
+	{
+		V[iRadius]	/= (double)Z[iRadius];
+	}
+
+	//-----------------------------------------------------
+	d		= Get_Steigung();
+
+	if( d == 0.0 )
+		return( Get_Cellsize() * maxRadius );
+	else
+		return( V[maxRadius-1] / d / 2.0 );
+}
+ 
+//---------------------------------------------------------
+double CGSGrid_Variance::Get_GSGrid_Variance(int x, int y, int iRadius, int &Count)
+{
+	int		i, ix, iy;
+
+	double	d, z, Variance;
+
+	Variance	= 0;
+	z			= pInput->asDouble(x,y);
+
+	for(i=rLength[iRadius-1], Count=0; i<rLength[iRadius]; i++, Count++)
+	{
+		ix	= x + x_diff[i];
+		if( ix < 0 )
+			ix	= 0;
+		else if( ix >= Get_NX() )
+			ix	= Get_NX() - 1;
+
+		iy	= y + y_diff[i];
+		if( iy < 0 )
+			iy	= 0;
+		else if( iy >= Get_NY() )
+			iy	= Get_NY() - 1;
+
+		d			= z - pInput->asDouble(ix,iy);
+		Variance	+= d * d;
+	}
+
+	return( Variance );
+}
+
+//---------------------------------------------------------
+double CGSGrid_Variance::Get_Steigung(void)
+{
+	int		i;
+
+	double	summe_mg, summe_g;
+
+	//-----------------------------------------------------
+	// Steigungen berechnen...
+	m[0]		= V[0] / Get_Cellsize();
+
+	for(i=1; i<maxRadius; i++)
+		m[i]	= (V[i] - V[i-1]) / Get_Cellsize();
+
+	//-----------------------------------------------------
+	// Gewichte berechnen (inverse distance)...
+	for(i=0; i<maxRadius; i++)
+		g[i]	= pow(Get_Cellsize() * (i + 1), -Exponent);
+
+	//-----------------------------------------------------
+	// Berechne Summe der gewichteten Steigungen und Summe der Gewichte...
+	summe_mg	= 0;
+	summe_g		= 0;
+
+	for(i=0; i<maxRadius; i++)
+	{
+		summe_mg	+= m[i] * g[i];
+		summe_g		+= g[i];
+	}
+
+	return( summe_mg / summe_g );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   GSGrid_Variance.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Variance_H
+#define HEADER_INCLUDED__GSGrid_Variance_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSGrid_Variance : public CSG_Module_Grid
+{
+public:
+	CGSGrid_Variance(void);
+	virtual ~CGSGrid_Variance(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Neighborhoods") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	int						maxRadius,
+							*Z, *x_diff, *y_diff, *rLength;
+
+	double					Exponent,	// Exponent fuer "inverse distance" Gewichte (calc_Steigung).
+							*V, *m, *g;
+
+	CSG_Grid				*pInput, *pOutput, *pRadius;
+
+
+	void					Initialize			(void);
+	void					Finalize			(void);
+
+	void					Init_Radius			(void);
+
+	double					Get_Laenge			(int x, int y);
+	double					Get_GSGrid_Variance	(int x, int y, int iRadius, int &Count);
+	double					Get_Steigung		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Variance_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,340 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               GSGrid_Variance_Radius.cpp              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Variance_Radius.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Variance_Radius::CGSGrid_Variance_Radius(void)
+{
+	Set_Name		(_TL("Radius of Variance (Grid)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Find the radius within which the cell values exceed the given variance criterium. "
+		"This module is closely related to the representativeness calculation "
+		"(variance within given search radius). "
+		"For easier usage, the variance criterium is entered as standard deviation value. "
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "INPUT"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Variance Radius"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "VARIANCE"	, _TL("Standard Deviation"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "RADIUS"		, _TL("Maximum Search Radius (cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 20
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "OUTPUT"		, _TL("Type of Output"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Cells"),
+			_TL("Map Units")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pInput		= NULL;
+	pInputQ		= NULL;
+	Check		= NULL;
+	maxRadius	= 0;
+}
+
+//---------------------------------------------------------
+CGSGrid_Variance_Radius::~CGSGrid_Variance_Radius(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Variance_Radius::On_Execute(void)
+{
+	int		x, y;
+
+	//-----------------------------------------------------
+	stopVariance	= M_SQR(Parameters("VARIANCE")->asDouble());
+	maxRadius		= Parameters("RADIUS")	->asInt();
+	bWriteGridsize	= Parameters("OUTPUT")	->asInt() == 1;
+
+	pGrid			= Parameters("INPUT")	->asGrid();
+	pResult			= Parameters("RESULT")	->asGrid();
+	pResult->Set_Name(CSG_String::Format(_TL("Radius with Variance >= %f"), stopVariance));
+
+	//-----------------------------------------------------
+	Initialize();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			pResult->Set_Value(x, y, Get_Radius(x, y));
+		}
+	}
+
+	Finalize();
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGSGrid_Variance_Radius::Initialize(void)
+{
+	int		x, y;
+	double	d;
+
+	//-----------------------------------------------------
+	pInput	= SG_Create_Grid(pGrid);
+	pInputQ	= SG_Create_Grid(pGrid);
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			d	= pGrid->asDouble(x,y);
+			pInput	->Set_Value(x, y, d  );
+			pInputQ	->Set_Value(x, y, d*d);
+		}
+	}
+
+	//-----------------------------------------------------
+	// Radius Check-Matrix erstellen...
+	Check	= (int **)malloc((maxRadius + 1) * sizeof(int *));
+
+	for(y=0; y<=maxRadius; y++)
+	{
+		Check[y]	= (int *)malloc((maxRadius + 1) * sizeof(int));
+
+		for(x=0; x<=maxRadius; x++)
+		{
+		//	Check[y][x]	= (int)sqrt(x*x + y*y);
+			Check[y][x]	= (int)sqrt((x + 0.5) * (x + 0.5) + (y + 0.5) * (y + 0.5));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CGSGrid_Variance_Radius::Finalize(void)
+{
+	if( pInput )
+	{
+		delete(pInput);
+		pInput		= NULL;
+	}
+
+	if( pInputQ )
+	{
+		delete(pInputQ);
+		pInputQ		= NULL;
+	}
+
+	if( Check )
+	{
+		for(int y=0; y<=maxRadius; y++)
+		{
+			free(Check[y]);
+		}
+		free(Check);
+		Check		= NULL;
+		maxRadius	= 0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CGSGrid_Variance_Radius::Get_Radius(int xPoint, int yPoint)
+{
+	const double	sqrt2	= 1.0 / sqrt(2.0);
+
+	int		x, y, dx, dy, sRadius,
+			Radius		= 0,
+			nValues		= 0;
+
+	double	ArithMean, Variance,
+			Sum			= 0.0,
+			SumQ		= 0.0;
+
+	do
+	{
+		sRadius	= (int)(sqrt2 * (double)Radius - 4.0);
+		if( sRadius < 0 ) sRadius	= 0;
+
+		//-------------------------------------------------
+		for(dy=sRadius; dy<=Radius; dy++)
+		{
+			for(dx=sRadius; dx<=Radius; dx++)
+			{
+				if(Check[dy][dx] == Radius)
+				{
+					y	= yPoint - dy;
+
+					if(y>=0)
+					{
+						x	= xPoint - dx;
+						if(x>=0)
+						{
+							Sum			+= pInput->asDouble(x,y);
+							SumQ		+= pInputQ->asDouble(x,y);
+							nValues++;
+						}
+
+						x	= xPoint + dx;
+						if(x<Get_NX())
+						{
+							Sum			+= pInput->asDouble(x,y);
+							SumQ		+= pInputQ->asDouble(x,y);
+							nValues++;
+						}
+					}
+
+					y	= yPoint + dy;
+					if(y<Get_NY())
+					{
+						x	= xPoint - dx;
+						if(x>=0)
+						{
+							Sum			+= pInput->asDouble(x,y);
+							SumQ		+= pInputQ->asDouble(x,y);
+							nValues++;
+						}
+
+						x	= xPoint + dx;
+						if(x<Get_NX())
+						{
+							Sum			+= pInput->asDouble(x,y);
+							SumQ		+= pInputQ->asDouble(x,y);
+							nValues++;
+						}
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if(nValues)
+		{
+			ArithMean	= Sum  / nValues;
+			Variance	= SumQ / nValues - ArithMean * ArithMean;
+
+			// Andre, das ist die Formel aus deinem Buch...
+			// Variance	= (SumQ - nValues * ArithMean * ArithMean) / nValues;
+		}
+		else
+			Variance	= 0;
+
+		Radius++;
+	}
+	while(Variance < stopVariance && Radius <= maxRadius);
+
+	return( bWriteGridsize ? Radius : Radius * Get_Cellsize() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Variance_Radius.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                GSGrid_Variance_Radius.h               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Variance_Radius_H
+#define HEADER_INCLUDED__GSGrid_Variance_Radius_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSGrid_Variance_Radius : public CSG_Module_Grid
+{
+public:
+	CGSGrid_Variance_Radius(void);
+	virtual ~CGSGrid_Variance_Radius(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Neighborhoods") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	bool					bWriteGridsize;
+
+	int						**Check, maxRadius;
+
+	double					stopVariance;
+
+	CSG_Grid				*pGrid, *pResult, *pInput, *pInputQ;
+
+
+	void					Initialize		(void);
+	void					Finalize		(void);
+
+	double					Get_Radius		(int xPoint, int yPoint);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Variance_Radius_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,427 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              GSGrid_Zonal_Statistics.cpp              //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de                         //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSGrid_Zonal_Statistics.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSGrid_Zonal_Statistics::CGSGrid_Zonal_Statistics(void)
+{
+	//-----------------------------------------------------
+	// Place information about your module here...
+
+	Set_Name		(_TL("{STATZONAL_NAME} Zonal Grid Statistics"));
+
+	Set_Author		(_TL("Copyrights (c) 2005 by Volker Wichmann"));
+
+	Set_Description	(_TW("{STATZONAL_DESC} "
+		"The module can be used to create a contingency table of unique condition units (UCUs). These "
+		"units are delineated from a zonal grid (e.g. sub catchments) and optional categorial grids (e.g. "
+		"landcover, soil, ...). It is possible to calculate simple statistics (min, max, mean, standard "
+		"deviation and sum) for each UCU from optional grids with continious data (e.g. slope). The number "
+		"of input grids is only limited by available memory. The module has four different modes of "
+		"application: (1) only a zonal grid is used as input. This results in a simple contingency table with "
+		"the number of grid cells in each zone. (2) a zonal grid and additional categorial grids are used as "
+		"input. This results in a contingency table with the number of cells in each UCU. (3) a zonal grid "
+		"and additional grids with continuous data are used as input. This results in a contingency table "
+		"with the number of cells in each zone and some simple statistics for each zone. The statistics are "
+		"calculated for each continuous grid. (4) a zonal grid, additional categorial grids and additional "
+		"grids with continuous data are used as input. This results in a contingency table with the number "
+		"of cells in each UCU and the corresponding statistics for each continuous grid.\n"
+		"\n"
+		"Depending on the mode of application, the output table contains information about the category "
+		"combination of each UCU, the number of cells in each UCU and the statistics for each UCU. A "
+		"typical output table may look like this:\n"
+		"<table border=\"1\">"
+		"<tr><td>ID Zone</td><td>ID 1stCat</td><td>ID 2ndCat</td><td>Count UCU</td><td>MIN 1stCont</td><td>MAX 1stCont</td><td>MEAN 1stCont</td><td>STDDEV 1stCont</td><td>SUM 1stCont</td></tr>"
+		"<tr><td>0      </td><td>2        </td><td>6        </td><td>6        </td><td>708.5      </td><td>862.0      </td><td>734.5       </td><td>62.5          </td><td>4406.8     </td></tr>"
+		"<tr><td>0      </td><td>3        </td><td>4        </td><td>106      </td><td>829.1      </td><td>910.1      </td><td>848.8       </td><td>28.5          </td><td>89969.0    </td></tr>"
+		"</table>"
+	));
+
+
+	Parameters.Add_Grid(
+		NULL, "ZONES"		, _TL("Zone Grid"),
+		_TL("Grid defining the zones to analyse. This grid also acts as a mask. Coding: no-data / categorial values."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "CATLIST"		, _TL("Categorial Grids"),
+		_TL("Grids used to delineate the UCUs. Coding: no-data / categorial values."),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "STATLIST"	, _TL("Grids to analyse"),
+		_TL("Grids with continuous data, statistics are calculated for each grid. Coding: no-data / continuous values."),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Table(
+		NULL, "OUTTAB"		, _TL("Result Table"),
+		_TL("Summary table."),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CGSGrid_Zonal_Statistics::~CGSGrid_Zonal_Statistics(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSGrid_Zonal_Statistics::On_Execute(void)
+{
+	int						x, y, nCatGrids, nStatGrids, iGrid, zoneID, catID, NDcount, catLevel, NDcountStat;
+	double					statID;
+
+	CSG_Grid				*pZones, *pGrid;
+	CSG_Parameter_Grid_List	*pCatList;
+	CSG_Parameter_Grid_List	*pStatList;
+
+	CList_Conti				*newZone, *startList, *runList, *newSub, *parent, *runSub, *subList;
+	CList_Stat				*runStats;
+	CSG_Table				*pOutTab;
+	CSG_Table_Record		*pRecord;
+
+
+	pZones		= Parameters("ZONES")		->asGrid();
+	pCatList	= Parameters("CATLIST")		->asGridList();
+	pStatList	= Parameters("STATLIST")	->asGridList();
+	pOutTab		= Parameters("OUTTAB")		->asTable();
+
+	nCatGrids	= pCatList	->Get_Count();
+	nStatGrids	= pStatList	->Get_Count();
+	
+	NDcount		= 0;						// NoData Counter (ZoneGrid)
+	NDcountStat	= 0;						// NoData Counter (StatGrids)
+
+	if (pOutTab != NULL)
+		pOutTab->Destroy();
+
+	newZone		= new CList_Conti();								// create first list entry (dummy)
+	startList	= newZone;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{	
+			runList		= startList;
+			zoneID		= pZones->asInt(x, y);								// get zone ID
+
+			while( runList->next != NULL && runList->cat < zoneID )			// search for last entry in list or insert point
+			{
+				runList = runList->next;
+			}
+
+			if( runList->dummy == true )
+			{
+				runList->cat = zoneID;										// first list entry, write and
+				runList->dummy = false;										// setup
+			}
+			else if( runList->cat == zoneID )
+				runList = runList;											// zoneID found				
+			else if( runList->next == NULL && runList->cat < zoneID )		// append zoneID
+			{
+				newZone = new CList_Conti();
+				newZone->previous	= runList;
+				runList->next		= newZone;
+
+				newZone->cat	= zoneID;									// ... and write info		
+				newZone->dummy	= false;
+				runList			= newZone;
+			}
+			else															// insert new entry
+			{
+				newZone = new CList_Conti();
+
+				newZone->next = runList;
+				if( runList->previous != NULL )
+				{
+					newZone->previous = runList->previous;
+					runList->previous->next = newZone;
+				}
+				runList->previous = newZone;
+					
+				if( runList == startList )
+					startList = newZone;									// if new entry is first element, update startList pointer
+
+				newZone->cat	= zoneID;									// ... and write info
+				newZone->dummy	= false;
+				runList			= newZone;
+			}
+
+
+			for(iGrid=0; iGrid<nCatGrids; iGrid++)							// collect categories
+			{
+				parent  = runList;
+				if( runList->sub == NULL )									// no sub class found
+				{
+					newSub = new CList_Conti();
+					runList->sub = newSub;
+				}
+
+				runList = runList->sub;
+
+				pGrid	= pCatList->asGrid(iGrid);
+				if( !pGrid->is_NoData(x, y) )
+					catID	= pGrid->asInt(x, y);
+				else
+					catID	= (int)pGrid->Get_NoData_Value();
+
+
+				while( runList->next != NULL && runList->cat < catID )		// search for last entry in list or insert point
+				{
+					runList = runList->next;
+				}
+
+				if( runList->dummy == true )
+				{
+					runList->cat	= catID;								// first list entry, write and
+					runList->dummy	= false;								// setup
+					runList->parent	= parent;
+				}
+				else if( runList->cat == catID )
+					runList = runList;										// zoneID found, all infos already written
+				else if( runList->next == NULL && runList->cat < catID)		// append zoneID
+				{
+					newSub = new CList_Conti();
+					newSub->cat			= catID;							// ... and write info
+					newSub->previous	= runList;
+					newSub->parent		= parent;
+					newSub->dummy		= false;
+					runList->next		= newSub;
+					runList				= newSub;
+				}
+				else														// insert new entry
+				{
+					newSub = new CList_Conti();
+					newSub->cat		= catID;								// ... and write info
+					newSub->next	= runList;
+					newSub->parent	= parent;
+					newSub->dummy	= false;
+					if( runList->previous != NULL )
+					{
+						newSub->previous = runList->previous;
+						runList->previous->next = newSub;
+					}
+					else
+						parent->sub	 = newSub;
+							
+					runList->previous = newSub;
+					runList	= newSub;
+				}
+			}
+
+
+			for(iGrid=0; iGrid<nStatGrids; iGrid++)							// collect statistics for StatGrids
+			{
+				if( iGrid == 0 )
+				{
+					if( runList->stats == NULL )
+						runList->stats = new CList_Stat();
+						
+					runStats = runList->stats;
+				}
+				else
+				{
+					if( runStats->next == NULL )
+						runStats->next = new CList_Stat();
+
+					runStats = runStats->next;
+				}
+				if( !pStatList->asGrid(iGrid)->is_NoData(x, y) )
+				{
+					statID		= pStatList->asGrid(iGrid)->asDouble(x, y);
+						
+					if( runStats->dummy == true )
+					{
+						runStats->min = statID;
+						runStats->max = statID;
+						runStats->dummy = false;
+					}
+					if( runStats->min > statID )	
+						runStats->min = statID;
+					if( runStats->max < statID )
+						runStats->max = statID;
+
+					runStats->sum += statID;
+					runStats->dev += pow(statID, 2);
+				}
+				else
+					NDcountStat += 1;
+			}
+				
+
+			runList->count += 1;											// sum up unique condition area
+		}
+	}
+
+
+	// Create fields in output table (1st = Zone, 2nd = Catgrid1, 3rd = Catgrid 2, ...)
+	pOutTab->Add_Field(CSG_String::Format(SG_T("%s"),pZones->Get_Name()).BeforeFirst(SG_Char('.')), SG_DATATYPE_Int);
+	for(iGrid=0; iGrid<nCatGrids; iGrid++)
+	{
+		pOutTab->Add_Field(CSG_String::Format(SG_T("%s"),pCatList->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')), SG_DATATYPE_Int);
+	}
+	pOutTab->Add_Field("Count", SG_DATATYPE_Int);
+	for(iGrid=0; iGrid<nStatGrids; iGrid++)
+	{
+		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_MIN")   , CSG_String::Format(SG_T("%s"),pStatList->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')).c_str()), SG_DATATYPE_Double);
+		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_MAX")   , CSG_String::Format(SG_T("%s"),pStatList->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')).c_str()), SG_DATATYPE_Double);
+		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_MEAN")  , CSG_String::Format(SG_T("%s"),pStatList->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')).c_str()), SG_DATATYPE_Double);
+		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_STDDEV"), CSG_String::Format(SG_T("%s"),pStatList->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')).c_str()), SG_DATATYPE_Double);
+		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_SUM")   , CSG_String::Format(SG_T("%s"),pStatList->asGrid(iGrid)->Get_Name()).BeforeFirst(SG_Char('.')).c_str()), SG_DATATYPE_Double);
+	}
+
+	while( startList != NULL )												// scan zone layer list and write cat values in table
+	{
+		runList = startList;
+		while( runList->sub != NULL )										// fall down to lowest layer
+			runList = runList->sub;
+		
+		subList = runList;													// use pointer to scan horizontal
+
+		while( subList != NULL )											// move forward and read all categories of this layer (including the parent layers)
+		{
+			runSub = subList;
+			catLevel = nCatGrids;
+			pRecord	= pOutTab->Add_Record();								// create new record in table
+			pRecord->Set_Value((catLevel+1), runSub->count);				// read/write field count			
+
+			for(iGrid=0; iGrid<nStatGrids; iGrid++)							// read/write statistics
+			{
+				if( iGrid == 0 )
+					runStats = runSub->stats;
+				else
+					runStats = runStats->next;
+
+				pRecord->Set_Value(catLevel+2+iGrid*5, runStats->min);
+				pRecord->Set_Value(catLevel+3+iGrid*5, runStats->max);
+				pRecord->Set_Value(catLevel+4+iGrid*5, runStats->sum/runSub->count);
+				pRecord->Set_Value(catLevel+5+iGrid*5, sqrt((runStats->dev - runSub->count*pow(runStats->sum/runSub->count, 2)) / (runSub->count - 1))); // sample
+				//pRecord->Set_Value(catLevel+5+iGrid*5, sqrt((runStats->dev - pow(runStats->sum/runSub->count, 2)) / runSub->count)); // population
+				pRecord->Set_Value(catLevel+6+iGrid*5, runStats->sum);
+			}			
+			
+			while( runSub != NULL )											// read/write categories
+			{
+				pRecord->Set_Value(catLevel, runSub->cat);
+				runSub = runSub->parent;
+				catLevel -= 1;
+			}
+			subList = subList->next;
+		}
+
+		while( runList->parent != NULL && runList->parent->next == NULL )	// move up to next 'Caterory with -> next'
+			runList = runList->parent;
+
+		if( runList->parent != NULL )										// if not upper layer (zones)
+		{	
+			runList = runList->parent;										// move to parent of next 'Caterory with -> next'
+			if( runList->next != NULL && runList->parent != NULL )
+				runList->parent->sub = runList->next;						// redirect pointer to category which is next 'Categora with -> next' next
+			else if (runList->parent == NULL && runList->next != NULL )				
+				startList = runList->next;									// when upper layer (zones) is reached, move to next zone
+			else
+				startList = NULL;											// reading finished
+			
+			if( runList->parent == NULL )
+				startList = runList->next;									// ?? when upper layer is reached, move to next zone
+			else
+				runList->sub = runList->sub->next;							// on sub layers redirect pointer to ->next
+		}
+		else
+		{
+			if( nCatGrids == 0 )
+				startList = NULL;
+			else
+				startList = runList->next;									// ?? upper layer is reached, move to next zone
+		}
+
+
+		runList->next = NULL;					
+		delete (runList);													// delete disconneted part of the list
+
+	}
+
+
+	if( NDcountStat > 0 )
+	{
+		Message_Add(CSG_String::Format(SG_T("\n\n\n%s: %d %s\n\n\n"), _TL("WARNING"), NDcountStat, _TL("no-data value(s) in statistic grid(s)!")));
+	}
+
+	return (true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/GSGrid_Zonal_Statistics.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,174 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              GSGrid_Zonal_Statistics.h                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volkerwichmann at web.de                  //
+//                                                       //
+//    contact:    Volker Wichmann                        //
+//                Research Associate                     //
+//                Chair of Physical Geography		     //
+//				  KU Eichstaett-Ingolstadt				 //
+//                Ostenstr. 18                           //
+//                85072 Eichstaett                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSGrid_Zonal_Statistics_H
+#define HEADER_INCLUDED__GSGrid_Zonal_Statistics_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CList_Stat
+{
+public:
+	CList_Stat(void)
+	{
+		min		= max	= 0.0;
+		sum		= dev	= 0.0;
+		next	= NULL;
+		dummy	= true;
+	};
+
+	~CList_Stat(void)
+	{
+		if( next != NULL )
+			delete(next);
+		next	= NULL;
+	};
+
+
+	double				min, max, sum, dev;
+	bool				dummy;
+
+	CList_Stat			*next;
+
+};
+
+//---------------------------------------------------------
+class CList_Conti
+{
+public:
+	CList_Conti(void)
+	{
+		cat			= NULL;
+		count		= 0;
+		next		= NULL;
+		previous	= NULL;
+		parent		= NULL;
+		sub			= NULL;
+		stats		= NULL;
+		dummy		= true;
+	};
+
+	~CList_Conti(void)
+	{
+		if( stats != NULL )
+			delete(stats);
+
+		if( sub != NULL )
+			delete(sub);
+		sub		= NULL;
+
+		if( next != NULL )
+			delete(next);
+		next	 = NULL;					
+	};
+
+
+	int					cat, count;
+	bool				dummy;
+
+	CList_Conti			*next, *previous, *parent, *sub;
+
+	CList_Stat			*stats;
+
+};
+
+//---------------------------------------------------------
+class CGSGrid_Zonal_Statistics : public CSG_Module_Grid
+{
+public:
+	CGSGrid_Zonal_Statistics(void);
+	virtual ~CGSGrid_Zonal_Statistics(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GSGrid_Zonal_Statistics_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,165 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Geostatistics - Grids") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Volker Wichmann (c) 2002-5" ));
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for (geo)statistical analyses of grids.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Geostatistics|Grid") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "GSGrid_Residuals.h"
+#include "GSGrid_Variance.h"
+#include "GSGrid_Variance_Radius.h"
+#include "GSGrid_Regression.h"
+#include "GSGrid_Regression_Multiple.h"
+#include "GSGrid_Statistics.h"
+#include "GSGrid_Zonal_Statistics.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CGSGrid_Residuals;
+		break;
+
+	case 1:
+		pModule	= new CGSGrid_Variance;
+		break;
+
+	case 2:
+		pModule	= new CGSGrid_Variance_Radius;
+		break;
+
+	case 3:
+		pModule	= new CGSGrid_Regression;
+		break;
+
+	case 4:
+		pModule	= new CGSGrid_Regression_Multiple;
+		break;
+
+	case 5:
+		pModule	= new CGSGrid_Statistics;
+		break;
+
+	case 6:
+		pModule	= new CGSGrid_Zonal_Statistics;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_grid/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                  Geostatistics_Grid                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__geostatistics_grid_H
+#define HEADER_INCLUDED__geostatistics_grid_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef geostatistics_grid_EXPORTS
+	#define	geostatistics_grid_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	geostatistics_grid_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__geostatistics_grid_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,142 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Geostatistics - Kriging") );
+
+	case MLB_INFO_Author:
+		return( SG_T("(c) 2003-08 by O.Conrad") );
+
+	case MLB_INFO_Description:
+		return( _TL("Kriging - geostatistical procedures for the gridding of irregular distributed point data." ));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Geostatistics" ));
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "kriging_ordinary.h"
+#include "kriging_ordinary_global.h"
+#include "kriging_universal.h"
+#include "kriging_universal_global.h"
+
+#include "semivariogram.h"
+
+#include "_kriging_ordinary.h"
+#include "_kriging_ordinary_global.h"
+#include "_kriging_universal.h"
+#include "_kriging_universal_global.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CKriging_Ordinary );
+	case 1:		return( new CKriging_Ordinary_Global );
+	case 2:		return( new CKriging_Universal );
+	case 3:		return( new CKriging_Universal_Global );
+
+	case 4:		return( new CSemiVariogram );
+
+	case 5:		return( new C_Kriging_Ordinary );
+	case 6:		return( new C_Kriging_Ordinary_Global );
+	case 7:		return( new C_Kriging_Universal );
+	case 8:		return( new C_Kriging_Universal_Global );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__geostatistics_kriging_H
+#define HEADER_INCLUDED__geostatistics_kriging_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef geostatistics_kriging_EXPORTS
+	#define	geostatistics_kriging_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	geostatistics_kriging_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__geostatistics_kriging_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,516 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    _Kriging_Base.cpp                  //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+C_Kriging_Base::C_Kriging_Base(void)
+{
+	CSG_Parameter	*pNode;
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "VARIANCE"	, _TL("Variance"),
+		_TL("")
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"		, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BVARIANCE"	, _TL("Create Variance Grid"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TARGET"		, _TL("Target Grid"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("user defined"),
+			_TL("grid system"),
+			_TL("grid")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "MODEL"		, _TL("Variogram Model"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Spherical Model"),
+			_TL("Exponential Model"),
+			_TL("Gaussian Model"),
+			_TL("Linear Regression"),
+			_TL("Exponential Regression"),
+			_TL("Power Function Regression")
+		), 3
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BLOCK"		, _TL("Block Kriging"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DBLOCK"		, _TL("Block Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BLOG"		, _TL("Logarithmic Transformation"),
+		_TL(""),
+		PARAMETER_TYPE_Bool
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NUGGET"		, _TL("Nugget"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "SILL"		, _TL("Sill"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "RANGE"		, _TL("Range"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "PARMS"		, _TL("Additional Parameters"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "LIN_B"		, _TL("Linear Regression"),
+		_TL("Parameter B for Linear Regression:\n   y = Nugget + B * x"),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "EXP_B"		, _TL("Exponential Regression"),
+		_TL("Parameter B for Exponential Regression:\n   y = Nugget * e ^ (B * x)"),
+		PARAMETER_TYPE_Double, 0.1
+	);
+
+	Parameters.Add_Value(
+		pNode	, "POW_A"		, _TL("Power Function - A"),
+		_TL("Parameter A for Power Function Regression:\n   y = A * x ^ B"),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "POW_B"		, _TL("Power Function - B"),
+		_TL("Parameter B for Power Function Regression:\n   y = A * x ^ B"),
+		PARAMETER_TYPE_Double, 0.5
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("USER")	, _TL("User defined grid")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL	, "CELL_SIZE"	, _TL("Grid Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	pNode	= pParameters->Add_Value(
+		NULL	, "FIT_EXTENT"	, _TL("Fit Extent"),
+		_TL("Automatically fits the grid to the shapes layers extent."),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	pParameters->Add_Range(
+		pNode	, "X_EXTENT"	, _TL("X-Extent"),
+		_TL("")
+	);
+
+	pParameters->Add_Range(
+		pNode	, "Y_EXTENT"	, _TL("Y-Extent"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("SYSTEM")	, _TL("Choose Grid System")	, _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("GRID")	, _TL("Choose Grid")		, _TL(""));
+
+	pNode	= pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	pParameters->Add_Grid(
+		pNode	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT	, false
+	);
+
+	pParameters->Add_Grid(
+		pNode	, "VARIANCE"	, _TL("Variance"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL, false
+	);
+}
+
+//---------------------------------------------------------
+C_Kriging_Base::~C_Kriging_Base(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Base::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	m_pShapes	= NULL;
+
+	m_bLog		= Parameters("BLOG")	->asBool();
+
+	m_Model		= Parameters("MODEL")	->asInt();
+
+	m_Nugget	= Parameters("NUGGET")	->asDouble();
+	m_Sill		= Parameters("SILL")	->asDouble() - m_Nugget;	
+	m_Range		= Parameters("RANGE")	->asDouble();
+
+	m_Block		= Parameters("DBLOCK")	->asDouble() / 2.0;
+	m_bBlock	= Parameters("BLOCK")	->asBool() && m_Block > 0.0;
+
+	m_BLIN		= Parameters("LIN_B")	->asDouble();
+	m_BEXP		= Parameters("EXP_B")	->asDouble();
+	m_APOW		= Parameters("POW_A")	->asDouble();
+	m_BPOW		= Parameters("POW_B")	->asDouble();
+
+	//-----------------------------------------------------
+	if( _Get_Grid() && _Get_Points() && On_Initialise() )
+	{
+		int		ix, iy;
+		double	x, y, z, v;
+
+		for(iy=0, y=m_pGrid->Get_YMin(); iy<m_pGrid->Get_NY() && Set_Progress(iy, m_pGrid->Get_NY()); iy++, y+=m_pGrid->Get_Cellsize())
+		{
+			for(ix=0, x=m_pGrid->Get_XMin(); ix<m_pGrid->Get_NX(); ix++, x+=m_pGrid->Get_Cellsize())
+			{
+				if( Get_Value(x, y, z, v) )
+				{
+					m_pGrid->Set_Value(ix, iy, m_bLog ? exp(z) : z);
+
+					if( m_pVariance )
+					{
+						m_pVariance->Set_Value(ix, iy, v);
+					}
+				}
+				else
+				{
+					m_pGrid->Set_NoData(ix, iy);
+
+					if( m_pVariance )
+					{
+						m_pVariance->Set_NoData(ix, iy);
+					}
+				}
+			}
+		}
+
+		bResult	= true;
+	}
+
+	//-----------------------------------------------------
+	m_Points.Clear();
+	m_Search.Destroy();
+	m_G		.Destroy();
+	m_W		.Destroy();
+
+	if( m_pShapes && m_pShapes != Parameters("SHAPES")->asShapes() )
+	{
+		delete(m_pShapes);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double C_Kriging_Base::Get_Weight(double d)
+{
+	if( d > 0.0 )
+	{
+		switch( m_Model )
+		{
+		case 0:
+			return(	// Spherical Model
+				d >= m_Range
+			?	m_Nugget + m_Sill
+			:	m_Nugget + m_Sill * (3.0 * d / (2.0 * m_Range) - d*d*d / (2.0 * m_Range*m_Range*m_Range))
+			);
+
+		case 1:
+			return(	// Exponential Model
+				m_Nugget + m_Sill * (1.0 - exp(-3.0 * d / m_Range))
+			);
+
+		case 2:
+			return(	// Gaussian Model
+				m_Nugget + m_Sill * SG_Get_Square(1.0 - exp(-3.0 * d / (m_Range*m_Range)))
+			);
+
+		case 3: default:
+			return(	// Linear Regression
+				m_Nugget + d * m_BLIN
+			);
+
+		case 4:
+			return(	// Exponential Regression
+				m_Nugget * exp(d * m_BEXP)
+			);
+
+		case 5:
+			return(	// Power Function Regression
+				m_Nugget + m_APOW * pow(d, m_BPOW)
+			);
+		}
+	}
+
+	return( m_Nugget > 0.0 ? m_Nugget : 0.00001 );
+}
+
+//---------------------------------------------------------
+double C_Kriging_Base::Get_Weight(double dx, double dy)
+{
+	return( Get_Weight(sqrt(dx*dx + dy*dy)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Base::_Get_Points(void)
+{
+	int		iShape, iPart, iPoint;
+	CSG_Shape	*pShape , *pPoint;
+	CSG_Shapes	*pPoints;
+
+	m_pShapes	= Parameters("SHAPES")	->asShapes();
+	m_zField	= Parameters("FIELD")	->asInt();
+
+	if( m_pShapes->Get_Type() != SHAPE_TYPE_Point )
+	{
+		pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, SG_T(""), m_pShapes);
+
+		for(iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
+		{
+			pShape	= m_pShapes->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					pPoint	= pPoints->Add_Shape(pShape, SHAPE_COPY_ATTR);
+					pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));
+				}
+			}
+		}
+
+		m_pShapes	= pPoints;
+	}
+
+	return( m_pShapes->Get_Count() > 1 );
+}
+
+//---------------------------------------------------------
+bool C_Kriging_Base::_Get_Grid(void)
+{
+	CSG_Shapes	*pShapes	= Parameters("SHAPES")->asShapes();
+
+	m_pGrid		= NULL;
+	m_pVariance	= NULL;
+
+	//-------------------------------------------------
+	switch( Parameters("TARGET")->asInt() )
+	{
+	case 0:	// user defined...
+		if( Dlg_Parameters("USER") )
+		{
+			m_pGrid		= _Get_Grid(pShapes->Get_Extent());
+		}
+		break;
+
+	case 1:	// grid system...
+		if( Dlg_Parameters("SYSTEM") )
+		{
+			m_pGrid		= SG_Create_Grid(*Get_Parameters("SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(), SG_DATATYPE_Float);
+		}
+		break;
+
+	case 2:	// grid...
+		if( Dlg_Parameters("GRID") )
+		{
+			m_pGrid		= Get_Parameters("GRID")->Get_Parameter("GRID")		->asGrid();
+			m_pVariance	= Get_Parameters("GRID")->Get_Parameter("VARIANCE")	->asGrid();
+		}
+		break;
+	}
+
+	//-------------------------------------------------
+	if( m_pGrid )
+	{
+		if( !m_pVariance && Parameters("BVARIANCE")->asBool() )
+		{
+			m_pVariance	= SG_Create_Grid(m_pGrid, SG_DATATYPE_Float);
+		}
+
+		m_pGrid->Set_Name(CSG_String::Format(SG_T("%s (%s)"), pShapes->Get_Name(), Get_Name()));
+		Parameters("GRID")->Set_Value(m_pGrid);
+
+		if( m_pVariance )
+		{
+			m_pVariance->Set_Name(CSG_String::Format(SG_T("%s (%s - %s)"), pShapes->Get_Name(), Get_Name(), _TL("Variance")));
+			Parameters("VARIANCE")->Set_Value(m_pVariance);
+		}
+
+		if( Parameters("TARGET")->asInt() == 2 )
+		{
+			Get_Parameters("GRID")->Get_Parameter("VARIANCE")->Set_Value(m_pVariance);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( m_pGrid != NULL );
+}
+
+//---------------------------------------------------------
+CSG_Grid * C_Kriging_Base::_Get_Grid(TSG_Rect Extent)
+{
+	CSG_Parameters	*P	= Get_Parameters("USER");
+
+	if( !P->Get_Parameter("FIT_EXTENT")->asBool() )
+	{
+		Extent.xMin	= P->Get_Parameter("X_EXTENT")->asRange()->Get_LoVal();
+		Extent.yMin	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_LoVal();
+		Extent.xMax	= P->Get_Parameter("X_EXTENT")->asRange()->Get_HiVal();
+		Extent.yMax	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_HiVal();
+	}
+
+	double	d	= P->Get_Parameter("CELL_SIZE")->asDouble();
+
+	int		nx	= 1 + (int)((Extent.xMax - Extent.xMin) / d);
+	int		ny	= 1 + (int)((Extent.yMax - Extent.yMin) / d);
+
+	return( nx > 1 && ny > 1 ? SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.xMin, Extent.yMin) : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    _Kriging_Base.h                    //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED___Kriging_Base_H
+#define HEADER_INCLUDED___Kriging_Base_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT C_Kriging_Base : public CSG_Module
+{
+public:
+	C_Kriging_Base(void);
+	virtual ~C_Kriging_Base(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Kriging") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+	bool					m_bBlock;
+
+	int						m_zField;
+
+	double					m_Block;
+
+	CSG_Points_3D			m_Points;
+
+	CSG_Vector				m_G;
+
+	CSG_Matrix				m_W;
+
+	CSG_PRQuadTree			m_Search;
+
+	CSG_Grid				*m_pGrid, *m_pVariance;
+
+	CSG_Shapes				*m_pShapes;
+
+
+	virtual bool			On_Initialise	(void)	{	return( true );	}
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance)	= 0;
+
+	double					Get_Weight		(double Distance);
+	double					Get_Weight		(double dx, double dy);
+
+
+private:
+
+	bool					m_bLog;
+
+	int						m_Model;
+
+	double					m_Nugget, m_Sill, m_Range, m_BLIN, m_BEXP, m_APOW, m_BPOW;
+
+
+	bool					_Get_Points		(void);
+	bool					_Get_Grid		(void);
+	CSG_Grid *				_Get_Grid		(TSG_Rect Extent);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED___Kriging_Base_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,233 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 _Kriging_Ordinary.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_ordinary.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+C_Kriging_Ordinary::C_Kriging_Ordinary(void)
+	: C_Kriging_Ordinary_Global()
+{
+	Set_Name		(_TL("Ordinary Kriging"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Ordinary Kriging for grid interpolation from irregular sample points."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "MAXRADIUS"	, _TL("Maximum Search Radius (map units)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1000.0, 0, true
+	);
+
+	Parameters.Add_Range(
+		NULL	, "NPOINTS"		, _TL("Min./Max. Number of m_Points"),
+		_TL(""), 4, 20, 1, true
+	);
+}
+
+//---------------------------------------------------------
+C_Kriging_Ordinary::~C_Kriging_Ordinary(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Ordinary::On_Initialise(void)
+{
+	m_Radius		= Parameters("MAXRADIUS")->asDouble();
+
+	m_nPoints_Min	= (int)Parameters("NPOINTS")->asRange()->Get_LoVal();
+	m_nPoints_Max	= (int)Parameters("NPOINTS")->asRange()->Get_HiVal();
+
+	//-----------------------------------------------------
+	if( m_Search.Create(m_pShapes, m_zField) )
+	{
+		m_Points.Set_Count	(m_nPoints_Max);
+		m_G		.Create		(m_nPoints_Max + 1);
+		m_W		.Create		(m_nPoints_Max + 1, m_nPoints_Max + 1);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Ordinary::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = Get_Weights(x, y)) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int C_Kriging_Ordinary::Get_Weights(double x, double y)
+{
+	int		i, j, n;
+
+	//-----------------------------------------------------
+	if( (n = m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius)) >= m_nPoints_Min )
+	{
+		for(i=0; i<n; i++)
+		{
+			m_Search.Get_Selected_Point(i, m_Points[i].x, m_Points[i].y, m_Points[i].z);
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<n; i++)
+		{
+			m_W[i][i]	= 0.0;				// diagonale...
+			m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+			for(j=i+1; j<n; j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= Get_Weight(
+					m_Points[i].x - m_Points[j].x,
+					m_Points[i].y - m_Points[j].y
+				);
+			}
+		}
+
+		m_W[n][n]	= 0.0;
+
+		if( m_W.Set_Inverse(true, 1 + n) )
+		{
+			return( n );
+		}
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  _Kriging_Ordinary.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _INTERPOLATION__Kriging_ORDINARY_H
+#define _INTERPOLATION__Kriging_ORDINARY_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_ordinary_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT C_Kriging_Ordinary : public C_Kriging_Ordinary_Global
+{
+public:
+	C_Kriging_Ordinary(void);
+	virtual ~C_Kriging_Ordinary(void);
+
+
+protected:
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	int						m_nPoints_Min, m_nPoints_Max;
+
+	double					m_Radius;
+
+
+	int						Get_Weights		(double x, double y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _INTERPOLATION__Kriging_ORDINARY_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,220 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              _Kriging_Ordinary_Global.cpp             //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_ordinary_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+C_Kriging_Ordinary_Global::C_Kriging_Ordinary_Global(void)
+	: C_Kriging_Base()
+{
+	Set_Name		(_TL("Ordinary Kriging (Global)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Ordinary Kriging for grid interpolation from irregular sample points. "
+		"This implementation does not use a maximum search radius. The weighting "
+		"matrix is generated once globally for all points."
+	));
+}
+
+//---------------------------------------------------------
+C_Kriging_Ordinary_Global::~C_Kriging_Ordinary_Global(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Ordinary_Global::On_Initialise(void)
+{
+	return( Get_Weights() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Ordinary_Global::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = m_Points.Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Ordinary_Global::Get_Weights(void)
+{
+	int		i, j, n;
+
+	//-----------------------------------------------------
+	for(int iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+	{
+		CSG_Shape	*pShape	= m_pShapes->Get_Shape(iShape);
+
+		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				m_Points.Add(
+					pShape->Get_Point(iPoint, iPart).x,
+					pShape->Get_Point(iPoint, iPart).y,
+					pShape->asDouble(m_zField)
+				);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( (n = m_Points.Get_Count()) > 4 )
+	{
+		m_G	.Create(n + 1);
+		m_W	.Create(n + 1, n + 1);
+
+		for(i=0; i<n; i++)
+		{
+			m_W[i][i]	= 0.0;				// diagonal...
+			m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+			for(j=i+1; j<n; j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= Get_Weight(
+					m_Points[i].x - m_Points[j].x,
+					m_Points[i].y - m_Points[j].y
+				);
+			}
+		}
+
+		m_W[n][n]	= 0.0;
+
+		return( m_W.Set_Inverse(false) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_ordinary_global.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               _Kriging_Ordinary_Global.h              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED___Kriging_Ordinary_Global_H
+#define HEADER_INCLUDED___Kriging_Ordinary_Global_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT C_Kriging_Ordinary_Global : public C_Kriging_Base
+{
+public:
+	C_Kriging_Ordinary_Global(void);
+	virtual ~C_Kriging_Ordinary_Global(void);
+
+
+protected:
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	bool					Get_Weights		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED___Kriging_Ordinary_Global_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,257 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 _Kriging_Universal.cpp                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_universal.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+C_Kriging_Universal::C_Kriging_Universal(void)
+	: C_Kriging_Universal_Global()
+{
+	Set_Name		(_TL("Universal Kriging"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Universal Kriging for grid interpolation from irregular sample points."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "MAXRADIUS"	, _TL("Maximum Search Radius (map units)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1000.0, 0, true
+	);
+
+	Parameters.Add_Range(
+		NULL	, "NPOINTS"		, _TL("Min./Max. Number of m_Points"),
+		_TL(""), 4, 20, 1, true
+	);
+}
+
+//---------------------------------------------------------
+C_Kriging_Universal::~C_Kriging_Universal(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Universal::On_Initialise(void)
+{
+	m_pGrids		= Parameters("GRIDS")		->asGridList();
+	m_Interpolation	= Parameters("INTERPOL")	->asInt();
+
+	m_Radius		= Parameters("MAXRADIUS")	->asDouble();
+
+	m_nPoints_Min	= (int)Parameters("NPOINTS")->asRange()->Get_LoVal();
+	m_nPoints_Max	= (int)Parameters("NPOINTS")->asRange()->Get_HiVal();
+
+	//-----------------------------------------------------
+	if( m_Search.Create(m_pShapes, m_zField) )
+	{
+		m_Points.Set_Count	(m_nPoints_Max);
+		m_G		.Create		(m_nPoints_Max + 1 + m_pGrids->Get_Count());
+		m_W		.Create		(m_nPoints_Max + 1 + m_pGrids->Get_Count(), m_nPoints_Max + 1 + m_pGrids->Get_Count());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Universal::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n, nGrids;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = Get_Weights(x, y)) > 0 && (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		for(i=0, j=n+1; i<nGrids; i++, j++)
+		{
+			if( !m_pGrids->asGrid(i)->Get_Value(x, y, m_G[j], m_Interpolation) )
+			{
+				return( false );
+			}
+		}
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n+nGrids; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int C_Kriging_Universal::Get_Weights(double x, double y)
+{
+	int		i, j, n, iGrid, nGrids;
+
+	//-----------------------------------------------------
+	if( (n = m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius)) >= m_nPoints_Min  && (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			m_Search.Get_Selected_Point(i, m_Points[i].x, m_Points[i].y, m_Points[i].z);
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<n; i++)
+		{
+			m_W[i][i]	= 0.0;				// diagonal...
+			m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+			for(j=i+1; j<n; j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= Get_Weight(
+					m_Points[i].x - m_Points[j].x,
+					m_Points[i].y - m_Points[j].y
+				);
+			}
+
+			for(iGrid=0, j=n+1; iGrid<nGrids; iGrid++, j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= m_pGrids->asGrid(iGrid)->Get_Value(
+					m_Points[i].x, m_Points[i].y, m_Interpolation
+				);
+			}
+		}
+
+		for(i=n; i<=n+nGrids; i++)
+		{
+			for(j=n; j<=n+nGrids; j++)
+			{
+				m_W[i][j]	= 0.0;
+			}
+		}
+
+		if( m_W.Set_Inverse(true, n + 1 + nGrids) )
+		{
+			return( n );
+		}
+	}	
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  _Kriging_Universal.h                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED___Kriging_UNIVERSAL_H
+#define HEADER_INCLUDED___Kriging_UNIVERSAL_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_universal_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT C_Kriging_Universal : public C_Kriging_Universal_Global
+{
+public:
+	C_Kriging_Universal(void);
+	virtual ~C_Kriging_Universal(void);
+
+
+protected:
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	int						m_nPoints_Min, m_nPoints_Max;
+
+	double					m_Radius;
+
+
+	int						Get_Weights		(double x, double y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED___Kriging_UNIVERSAL_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,266 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             _Kriging_Universal_Global.cpp             //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_universal_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+C_Kriging_Universal_Global::C_Kriging_Universal_Global(void)
+	: C_Kriging_Base()
+{
+	Set_Name		(_TL("Universal Kriging (Global)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Universal Kriging for grid interpolation from irregular sample points.\n"
+		"This implementation does not use a maximum search radius. The weighting "
+		"matrix is generated globally for all points."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	,"INTERPOL"		, _TL("Grid Interpolation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+C_Kriging_Universal_Global::~C_Kriging_Universal_Global(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Universal_Global::On_Initialise(void)
+{
+	m_pGrids		= Parameters("GRIDS")		->asGridList();
+	m_Interpolation	= Parameters("INTERPOL")	->asInt();
+
+	return( Get_Weights() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Universal_Global::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n, nGrids;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = m_Points.Get_Count()) > 1 && (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		for(i=0, j=n+1; i<nGrids; i++, j++)
+		{
+			if( !m_pGrids->asGrid(i)->Get_Value(x, y, m_G[j], m_Interpolation, true) )
+			{
+				return( false );
+			}
+		}
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n+nGrids; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool C_Kriging_Universal_Global::Get_Weights(void)
+{
+	int		i, j, n, iGrid, nGrids;
+
+	//-----------------------------------------------------
+	if( (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(int iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+		{
+			CSG_Shape	*pShape	= m_pShapes->Get_Shape(iShape);
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					m_Points.Add(
+						pShape->Get_Point(iPoint, iPart).x,
+						pShape->Get_Point(iPoint, iPart).y,
+						pShape->asDouble(m_zField)
+					);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( (n = m_Points.Get_Count()) > 1 )
+		{
+			m_G.Create(n + 1 + nGrids);
+			m_W.Create(n + 1 + nGrids, n + 1 + nGrids);
+
+			for(i=0; i<n; i++)
+			{
+				m_W[i][i]	= 0.0;				// diagonal...
+				m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+				for(j=i+1; j<n; j++)
+				{
+					m_W[i][j]	= m_W[j][i]	= Get_Weight(
+						m_Points[i].x - m_Points[j].x,
+						m_Points[i].y - m_Points[j].y
+					);
+				}
+
+				for(iGrid=0, j=n+1; iGrid<nGrids; iGrid++, j++)
+				{
+					m_W[i][j]	= m_W[j][i]	= m_pGrids->asGrid(iGrid)->Get_Value(
+						m_Points[i].x, m_Points[i].y, m_Interpolation
+					);
+				}
+			}
+
+			for(i=n; i<=n+nGrids; i++)
+			{
+				for(j=n; j<=n+nGrids; j++)
+				{
+					m_W[i][j]	= 0.0;
+				}
+			}
+
+			return( m_W.Set_Inverse() );
+		}
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/_kriging_universal_global.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              _Kriging_Universal_Global.h              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED___Kriging_Universal_Global_H
+#define HEADER_INCLUDED___Kriging_Universal_Global_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "_kriging_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT C_Kriging_Universal_Global : public C_Kriging_Base
+{
+public:
+	C_Kriging_Universal_Global(void);
+	virtual ~C_Kriging_Universal_Global(void);
+
+
+protected:
+
+	int						m_Interpolation;
+
+	CSG_Parameter_Grid_List	*m_pGrids;
+
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	bool					Get_Weights		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED___Kriging_Universal_Global_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,536 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   kriging_base.cpp                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "variogram_dialog.h"
+
+#include "kriging_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CKriging_Base::CKriging_Base(void)
+{
+	CSG_Parameter	*pNode;
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZFIELD"		, _TL("Attribute"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "VARIANCE"	, _TL("Variance"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BVARIANCE"	, _TL("Create Variance Grid"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TARGET"		, _TL("Target Grid"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("user defined"),
+			_TL("grid system"),
+			_TL("grid")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "VARIOGRAM"	, _TL("Semi-Variogram"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DISTMAX"		, _TL("Maximum Distance"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, -1.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DISTCOUNT"	, _TL("Initial Number of Distance Classes"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NSKIP"		, _TL("Skip Number"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "BLOCK"		, _TL("Block Kriging"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DBLOCK"		, _TL("Block Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("USER")	, _TL("User defined grid")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL	, "CELL_SIZE"	, _TL("Grid Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	pParameters->Add_Range(
+		pNode	, "X_EXTENT"	, _TL("X-Extent"),
+		_TL("")
+	);
+
+	pParameters->Add_Range(
+		pNode	, "Y_EXTENT"	, _TL("Y-Extent"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("SYSTEM")	, _TL("Choose Grid System")	, _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("GRID")	, _TL("Choose Grid")		, _TL(""));
+
+	pNode	= pParameters->Add_Grid_System(
+		NULL	, "SYSTEM"		, _TL("Grid System"),
+		_TL("")
+	);
+
+	pParameters->Add_Grid(
+		pNode	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_OUTPUT, false
+	);
+
+	pParameters->Add_Grid(
+		pNode	, "VARIANCE"	, _TL("Variance"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, false
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters(SG_T("FORMULA"), _TL("Formula"), _TL(""));
+
+	pParameters->Add_String(
+		NULL	, "STRING"		, _TL("Formula String"),
+		_TL(""),
+		SG_T("a + b * x")
+	);
+
+	//-----------------------------------------------------
+	m_Variances.Add_Field(SG_T("DISTANCE")	, SG_DATATYPE_Double);
+	m_Variances.Add_Field(SG_T("VAR_CUM")	, SG_DATATYPE_Double);
+	m_Variances.Add_Field(SG_T("VAR_CLS")	, SG_DATATYPE_Double);
+}
+
+//---------------------------------------------------------
+CKriging_Base::~CKriging_Base(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Base::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	if( _Initialise() && _Get_Variances() )
+	{
+		m_Variogram.Set_Formula	(Get_Parameters("FORMULA")->Get_Parameter("STRING")->asString());
+
+		if( SG_UI_Get_Window_Main() )
+		{
+			CVariogram_Dialog	dlg(&m_Variogram, &m_Variances);
+
+			bResult	= dlg.ShowModal() == wxID_OK;
+		}
+		else
+		{
+			m_Variogram.Clr_Data();
+
+			for(int i=0; i<m_Variances.Get_Count(); i++)
+			{
+				m_Variogram.Add_Data(m_Variances[i][0], m_Variances[i][1]);
+			}
+
+			bResult	= m_Variogram.Get_Trend();
+		}
+
+		if( bResult && m_Variogram.is_Okay() && On_Initialise() )
+		{
+			bResult	= _Interpolate();
+
+			Get_Parameters("FORMULA")->Get_Parameter("STRING")->Set_Value(m_Variogram.Get_Formula(SG_TREND_STRING_Formula));
+		}
+	}
+
+	_Finalise();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Base::_Initialise(void)
+{
+	//-----------------------------------------------------
+	m_Block		= Parameters("DBLOCK")	->asDouble() / 2.0;
+	m_bBlock	= Parameters("BLOCK")	->asBool() && m_Block > 0.0;
+
+	//-----------------------------------------------------
+	m_pPoints	= Parameters("POINTS")	->asShapes();
+	m_zField	= Parameters("ZFIELD")	->asInt();
+
+	if( m_pPoints->Get_Count() <= 1 )
+	{
+		SG_UI_Msg_Add(_TL("not enough points for interpolation"), true);
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CKriging_Base::_Initialise_Grids(void)
+{
+	TSG_Rect		r;
+	CSG_Parameters	*P;
+
+	//-----------------------------------------------------
+	m_pGrid		= NULL;
+	m_pVariance	= NULL;
+
+	//-----------------------------------------------------
+	switch( Parameters("TARGET")->asInt() )
+	{
+	case 0:	// user defined...
+		r	= m_pPoints->Get_Extent();
+		P	= Get_Parameters("USER");
+
+		P->Get_Parameter("X_EXTENT")->asRange()->Set_LoVal(r.xMin);
+		P->Get_Parameter("Y_EXTENT")->asRange()->Set_LoVal(r.yMin);
+		P->Get_Parameter("X_EXTENT")->asRange()->Set_HiVal(r.xMax);
+		P->Get_Parameter("Y_EXTENT")->asRange()->Set_HiVal(r.yMax);
+
+		if( Dlg_Parameters("USER") )
+		{
+			r.xMin	= P->Get_Parameter("X_EXTENT")->asRange()->Get_LoVal();
+			r.yMin	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_LoVal();
+			r.xMax	= P->Get_Parameter("X_EXTENT")->asRange()->Get_HiVal();
+			r.yMax	= P->Get_Parameter("Y_EXTENT")->asRange()->Get_HiVal();
+
+			double	d	= P->Get_Parameter("CELL_SIZE")->asDouble();
+			int		nx	= 1 + (int)((r.xMax - r.xMin) / d);
+			int		ny	= 1 + (int)((r.yMax - r.yMin) / d);
+
+			if( nx > 1 && ny > 1 )
+			{
+				m_pGrid	= SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, r.xMin, r.yMin);
+			}
+		}
+		break;
+
+	case 1:	// grid system...
+		if( Dlg_Parameters("SYSTEM") )
+		{
+			m_pGrid		= SG_Create_Grid(*Get_Parameters("SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(), SG_DATATYPE_Float);
+		}
+		break;
+
+	case 2:	// grid...
+		if( Dlg_Parameters("GRID") )
+		{
+			m_pGrid		= Get_Parameters("GRID")->Get_Parameter("GRID")		->asGrid();
+			m_pVariance	= Get_Parameters("GRID")->Get_Parameter("VARIANCE")	->asGrid();
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( m_pGrid )
+	{
+		if( !m_pVariance && Parameters("BVARIANCE")->asBool() )
+		{
+			m_pVariance	= SG_Create_Grid(m_pGrid, SG_DATATYPE_Float);
+		}
+
+		m_pGrid->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), Get_Name()));
+		Parameters("GRID")->Set_Value(m_pGrid);
+
+		if( m_pVariance )
+		{
+			m_pVariance->Set_Name(CSG_String::Format(SG_T("%s (%s - %s)"), m_pPoints->Get_Name(), Get_Name(), _TL("Variance")));
+			Parameters("VARIANCE")->Set_Value(m_pVariance);
+		}
+
+		if( Parameters("TARGET")->asInt() == 2 )
+		{
+			Get_Parameters("GRID")->Get_Parameter("VARIANCE")->Set_Value(m_pVariance);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CKriging_Base::_Finalise(void)
+{
+	m_Points	.Clear();
+	m_Search	.Destroy();
+	m_G			.Destroy();
+	m_W			.Destroy();
+	m_Variogram	.Clr_Data();
+	m_Variances	.Del_Records();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Base::_Interpolate(void)
+{
+	if( _Initialise_Grids() )
+	{
+		int		ix, iy;
+		double	x, y, z, v;
+
+		for(iy=0, y=m_pGrid->Get_YMin(); iy<m_pGrid->Get_NY() && Set_Progress(iy, m_pGrid->Get_NY()); iy++, y+=m_pGrid->Get_Cellsize())
+		{
+			for(ix=0, x=m_pGrid->Get_XMin(); ix<m_pGrid->Get_NX(); ix++, x+=m_pGrid->Get_Cellsize())
+			{
+				if( Get_Value(x, y, z, v) )
+				{
+					m_pGrid->Set_Value(ix, iy, z);
+
+					if( m_pVariance )
+					{
+						m_pVariance->Set_Value(ix, iy, v);
+					}
+				}
+				else
+				{
+					m_pGrid->Set_NoData(ix, iy);
+
+					if( m_pVariance )
+					{
+						m_pVariance->Set_NoData(ix, iy);
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	DIF_FIELD_DISTANCE		= 0,
+	DIF_FIELD_DIFFERENCE
+};
+
+//---------------------------------------------------------
+enum
+{
+	VAR_FIELD_DISTANCE		= 0,
+	VAR_FIELD_VARIANCE
+};
+
+//---------------------------------------------------------
+bool CKriging_Base::_Get_Variances(void)
+{
+	int			i, j, k, n, nDistances, nSkip;
+	double		z, d, dx, dy, maxDistance, lagDistance;
+	TSG_Point	Pt_i, Pt_j;
+	CSG_Vector	Count, Variance;
+	CSG_Shape	*pPoint;
+
+	//-----------------------------------------------------
+	nSkip		= Parameters("NSKIP")		->asInt();
+	maxDistance	= Parameters("DISTMAX")		->asDouble();
+	nDistances	= Parameters("DISTCOUNT")	->asInt();
+
+	if( maxDistance <= 0.0 )
+	{
+		maxDistance	= SG_Get_Length(m_pPoints->Get_Extent().Get_XRange(), m_pPoints->Get_Extent().Get_XRange());
+	}
+
+	lagDistance	= maxDistance / nDistances;
+
+	Count		.Create(nDistances);
+	Variance	.Create(nDistances);
+
+	//-----------------------------------------------------
+	for(i=0, n=0; i<m_pPoints->Get_Count()-nSkip && Set_Progress(n, SG_Get_Square(m_pPoints->Get_Count()/nSkip)/2); i+=nSkip)
+	{
+		pPoint	= m_pPoints->Get_Shape(i);
+		Pt_i	= pPoint->Get_Point(0);
+		z		= pPoint->asDouble(m_zField);
+
+		for(j=i+nSkip; j<m_pPoints->Get_Count(); j+=nSkip, n++)
+		{
+			pPoint	= m_pPoints->Get_Shape(j);
+			Pt_j	= pPoint->Get_Point(0);
+			dx		= Pt_j.x - Pt_i.x;
+			dy		= Pt_j.y - Pt_i.y;
+			d		= sqrt(dx*dx + dy*dy);
+			k		= (int)(d / lagDistance);
+
+			if( k < nDistances )
+			{
+				d	= pPoint->asDouble(m_zField) - z;
+
+				Count	[k]	++;
+				Variance[k]	+= d * d;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(i=0, z=0.0, n=0; i<nDistances && Process_Get_Okay(); i++)
+	{
+		if( Count[i] > 0 )
+		{
+			n	+= Count	[i];
+			z	+= Variance	[i];
+
+			CSG_Table_Record	*pRecord	= m_Variances.Add_Record();
+			pRecord->Set_Value(0, (i + 1) * lagDistance);
+			pRecord->Set_Value(1, 0.5 * Variance[i] / Count[i]);
+			pRecord->Set_Value(2, 0.5 * z / n);
+		}
+	}
+
+	return( Process_Get_Okay() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,148 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    kriging_base.h                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__kriging_base_H
+#define HEADER_INCLUDED__kriging_base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT CKriging_Base : public CSG_Module
+{
+public:
+	CKriging_Base(void);
+	virtual ~CKriging_Base(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Kriging with Variogram Fit") );	}
+
+
+protected:
+
+	bool					m_bBlock;
+
+	int						m_zField;
+
+	double					m_Block;
+
+	CSG_Points_3D			m_Points;
+
+	CSG_Vector				m_G;
+
+	CSG_Matrix				m_W;
+
+	CSG_PRQuadTree			m_Search;
+
+	CSG_Shapes				*m_pPoints;
+
+
+	virtual bool			On_Execute				(void);
+
+	virtual bool			On_Initialise			(void)					{	return( true );	}
+
+	virtual bool			Get_Value				(double x, double y, double &z, double &Variance)	= 0;
+
+	double					Get_Weight				(double d)				{	return( m_Variogram.Get_Value(d) );	}
+	double					Get_Weight				(double dx, double dy)	{	return( m_Variogram.Get_Value(sqrt(dx*dx + dy*dy)) );	}
+
+
+private:
+
+	CSG_Table				m_Variances;
+
+	CSG_Trend				m_Variogram;
+
+	CSG_Grid				*m_pGrid, *m_pVariance;
+
+
+	bool					_Initialise				(void);
+	bool					_Initialise_Grids		(void);
+	bool					_Finalise				(void);
+
+	bool					_Interpolate			(void);
+
+	bool					_Get_Variances			(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__kriging_base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,262 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Kriging_Ordinary.cpp                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_ordinary.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CKriging_Ordinary::CKriging_Ordinary(void)
+	: CKriging_Ordinary_Global()
+{
+	Set_Name		(_TL("Ordinary Kriging (VF)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Ordinary Kriging for grid interpolation from irregular sample points."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "MAXRADIUS"	, _TL("Maximum Search Radius (map units)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1000.0, 0, true
+	);
+
+	Parameters.Add_Range(
+		NULL	, "NPOINTS"		, _TL("Min./Max. Number of m_Points"),
+		_TL(""), 4, 20, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("all directions"),
+			_TL("quadrants")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CKriging_Ordinary::~CKriging_Ordinary(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Ordinary::On_Initialise(void)
+{
+	m_Radius		= Parameters("MAXRADIUS")	->asDouble();
+
+	m_nPoints_Min	= (int)Parameters("NPOINTS")->asRange()->Get_LoVal();
+	m_nPoints_Max	= (int)Parameters("NPOINTS")->asRange()->Get_HiVal();
+
+	m_Mode			= Parameters("MODE")		->asInt();
+
+	//-----------------------------------------------------
+	if( !m_Search.Create(m_pPoints, m_zField) )
+	{
+		SG_UI_Msg_Add(_TL("could not initialize point search engine"), true);
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int		nPoints_Max;
+
+	switch( m_Mode )
+	{
+	default:	nPoints_Max	= m_nPoints_Max;		break;
+	case 1:		nPoints_Max	= m_nPoints_Max * 4;	break;
+	}
+
+	m_Points.Set_Count	(nPoints_Max);
+	m_G		.Create		(nPoints_Max + 1);
+	m_W		.Create		(nPoints_Max + 1, nPoints_Max + 1);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Ordinary::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = Get_Weights(x, y)) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CKriging_Ordinary::Get_Weights(double x, double y)
+{
+	int		i, j, n;
+
+	//-----------------------------------------------------
+	switch( m_Mode )
+	{
+	default:	n	= m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius);	break;
+	case 1:		n	= m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius, 4);	break;
+	}
+
+	//-----------------------------------------------------
+	if( n >= m_nPoints_Min )
+	{
+		for(i=0; i<n; i++)
+		{
+			m_Search.Get_Selected_Point(i, m_Points[i].x, m_Points[i].y, m_Points[i].z);
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<n; i++)
+		{
+			m_W[i][i]	= 0.0;				// diagonale...
+			m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+			for(j=i+1; j<n; j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= Get_Weight(
+					m_Points[i].x - m_Points[j].x,
+					m_Points[i].y - m_Points[j].y
+				);
+			}
+		}
+
+		m_W[n][n]	= 0.0;
+
+		if( m_W.Set_Inverse(true, 1 + n) )
+		{
+			return( n );
+		}
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Kriging_Ordinary.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Kriging_Ordinary_H
+#define HEADER_INCLUDED__Kriging_Ordinary_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_ordinary_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT CKriging_Ordinary : public CKriging_Ordinary_Global
+{
+public:
+	CKriging_Ordinary(void);
+	virtual ~CKriging_Ordinary(void);
+
+
+protected:
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	int						m_nPoints_Min, m_nPoints_Max, m_Mode;
+
+	double					m_Radius;
+
+
+	int						Get_Weights		(double x, double y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Kriging_Ordinary_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,214 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Kriging_Ordinary_Global.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_ordinary_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CKriging_Ordinary_Global::CKriging_Ordinary_Global(void)
+	: CKriging_Base()
+{
+	Set_Name		(_TL("Ordinary Kriging (VF, Global)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Ordinary Kriging for grid interpolation from irregular sample points. "
+		"This implementation does not use a maximum search radius. The weighting "
+		"matrix is generated once globally for all points."
+	));
+}
+
+//---------------------------------------------------------
+CKriging_Ordinary_Global::~CKriging_Ordinary_Global(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Ordinary_Global::On_Initialise(void)
+{
+	return( Get_Weights() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Ordinary_Global::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = m_Points.Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Ordinary_Global::Get_Weights(void)
+{
+	int		i, j, n;
+
+	//-----------------------------------------------------
+	for(i=0; i<m_pPoints->Get_Count(); i++)
+	{
+		CSG_Shape	*pPoint	= m_pPoints->Get_Shape(i);
+
+		m_Points.Add(
+			pPoint->Get_Point(0).x,
+			pPoint->Get_Point(0).y,
+			pPoint->asDouble(m_zField)
+		);
+	}
+
+	//-----------------------------------------------------
+	if( (n = m_Points.Get_Count()) > 4 )
+	{
+		m_G	.Create(n + 1);
+		m_W	.Create(n + 1, n + 1);
+
+		for(i=0; i<n; i++)
+		{
+			m_W[i][i]	= 0.0;				// diagonal...
+			m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+			for(j=i+1; j<n; j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= Get_Weight(
+					m_Points[i].x - m_Points[j].x,
+					m_Points[i].y - m_Points[j].y
+				);
+			}
+		}
+
+		m_W[n][n]	= 0.0;
+
+		return( m_W.Set_Inverse(false) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_ordinary_global.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Kriging_Ordinary_Global.h               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Kriging_Ordinary_Global_H
+#define HEADER_INCLUDED__Kriging_Ordinary_Global_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT CKriging_Ordinary_Global : public CKriging_Base
+{
+public:
+	CKriging_Ordinary_Global(void);
+	virtual ~CKriging_Ordinary_Global(void);
+
+
+protected:
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	bool					Get_Weights		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Kriging_Ordinary_Global_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,286 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Kriging_Universal.cpp                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_universal.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CKriging_Universal::CKriging_Universal(void)
+	: CKriging_Universal_Global()
+{
+	Set_Name		(_TL("Universal Kriging (VF)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Universal Kriging for grid interpolation from irregular sample points."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "MAXRADIUS"	, _TL("Maximum Search Radius (map units)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1000.0, 0, true
+	);
+
+	Parameters.Add_Range(
+		NULL	, "NPOINTS"		, _TL("Min./Max. Number of m_Points"),
+		_TL(""), 4, 20, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "MODE"		, _TL("Search Mode"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("all directions"),
+			_TL("quadrants")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CKriging_Universal::~CKriging_Universal(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Universal::On_Initialise(void)
+{
+	m_pGrids		= Parameters("GRIDS")		->asGridList();
+	m_Interpolation	= Parameters("INTERPOL")	->asInt();
+
+	m_Radius		= Parameters("MAXRADIUS")	->asDouble();
+
+	m_nPoints_Min	= (int)Parameters("NPOINTS")->asRange()->Get_LoVal();
+	m_nPoints_Max	= (int)Parameters("NPOINTS")->asRange()->Get_HiVal();
+
+	m_Mode			= Parameters("MODE")		->asInt();
+
+	//-----------------------------------------------------
+	if( !m_Search.Create(m_pPoints, m_zField) )
+	{
+		SG_UI_Msg_Add(_TL("could not initialize point search engine"), true);
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int		nPoints_Max;
+
+	switch( m_Mode )
+	{
+	default:	nPoints_Max	= m_nPoints_Max;		break;
+	case 1:		nPoints_Max	= m_nPoints_Max * 4;	break;
+	}
+
+	m_Points.Set_Count	(nPoints_Max);
+	m_G		.Create		(nPoints_Max + 1 + m_pGrids->Get_Count());
+	m_W		.Create		(nPoints_Max + 1 + m_pGrids->Get_Count(), nPoints_Max + 1 + m_pGrids->Get_Count());
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Universal::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n, nGrids;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = Get_Weights(x, y)) > 0 && (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		for(i=0, j=n+1; i<nGrids; i++, j++)
+		{
+			if( !m_pGrids->asGrid(i)->Get_Value(x, y, m_G[j], m_Interpolation) )
+			{
+				return( false );
+			}
+		}
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n+nGrids; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CKriging_Universal::Get_Weights(double x, double y)
+{
+	int		i, j, n, iGrid, nGrids	= m_pGrids->Get_Count();
+
+	//-----------------------------------------------------
+	switch( m_Mode )
+	{
+	default:	n	= m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius);	break;
+	case 1:		n	= m_Search.Select_Nearest_Points(x, y, m_nPoints_Max, m_Radius, 4);	break;
+	}
+
+	//-----------------------------------------------------
+	if( n >= m_nPoints_Min )
+	{
+		for(i=0; i<n; i++)
+		{
+			m_Search.Get_Selected_Point(i, m_Points[i].x, m_Points[i].y, m_Points[i].z);
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<n; i++)
+		{
+			m_W[i][i]	= 0.0;				// diagonal...
+			m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+			for(j=i+1; j<n; j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= Get_Weight(
+					m_Points[i].x - m_Points[j].x,
+					m_Points[i].y - m_Points[j].y
+				);
+			}
+
+			for(iGrid=0, j=n+1; iGrid<nGrids; iGrid++, j++)
+			{
+				m_W[i][j]	= m_W[j][i]	= m_pGrids->asGrid(iGrid)->Get_Value(
+					m_Points[i].x, m_Points[i].y, m_Interpolation
+				);
+			}
+		}
+
+		for(i=n; i<=n+nGrids; i++)
+		{
+			for(j=n; j<=n+nGrids; j++)
+			{
+				m_W[i][j]	= 0.0;
+			}
+		}
+
+		if( m_W.Set_Inverse(true, n + 1 + nGrids) )
+		{
+			return( n );
+		}
+	}	
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Kriging_Universal.h                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Kriging_Universal_H
+#define HEADER_INCLUDED__Kriging_Universal_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_universal_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT CKriging_Universal : public CKriging_Universal_Global
+{
+public:
+	CKriging_Universal(void);
+	virtual ~CKriging_Universal(void);
+
+
+protected:
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	int						m_nPoints_Min, m_nPoints_Max, m_Mode;
+
+	double					m_Radius;
+
+
+	int						Get_Weights		(double x, double y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Kriging_Universal_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,260 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Kriging                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             Kriging_Universal_Global.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_universal_global.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CKriging_Universal_Global::CKriging_Universal_Global(void)
+	: CKriging_Base()
+{
+	Set_Name		(_TL("Universal Kriging (VF, Global)"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Universal Kriging for grid interpolation from irregular sample points.\n"
+		"This implementation does not use a maximum search radius. The weighting "
+		"matrix is generated globally for all points."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	,"INTERPOL"		, _TL("Grid Interpolation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neighbor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+}
+
+//---------------------------------------------------------
+CKriging_Universal_Global::~CKriging_Universal_Global(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Universal_Global::On_Initialise(void)
+{
+	m_pGrids		= Parameters("GRIDS")		->asGridList();
+	m_Interpolation	= Parameters("INTERPOL")	->asInt();
+
+	return( Get_Weights() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Universal_Global::Get_Value(double x, double y, double &z, double &v)
+{
+	int		i, j, n, nGrids;
+	double	Lambda;
+
+	//-----------------------------------------------------
+	if(	(n = m_Points.Get_Count()) > 1 && (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( !m_bBlock )
+			{
+				m_G[i]	=	Get_Weight(x - m_Points[i].x, y - m_Points[i].y);
+			}
+			else
+			{
+				m_G[i]	= (	Get_Weight((x          ) - m_Points[i].x, (y          ) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x + m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y + m_Block) - m_Points[i].y)
+						+	Get_Weight((x - m_Block) - m_Points[i].x, (y - m_Block) - m_Points[i].y) ) / 5.0;
+			}
+		}
+
+		m_G[n]	= 1.0;
+
+		for(i=0, j=n+1; i<nGrids; i++, j++)
+		{
+			if( !m_pGrids->asGrid(i)->Get_Value(x, y, m_G[j], m_Interpolation, true) )
+			{
+				return( false );
+			}
+		}
+
+		//-------------------------------------------------
+		for(i=0, z=0.0, v=0.0; i<n; i++)
+		{
+			for(j=0, Lambda=0.0; j<=n+nGrids; j++)
+			{
+				Lambda	+= m_W[i][j] * m_G[j];
+			}
+
+			z	+= Lambda * m_Points[i].z;
+			v	+= Lambda * m_G[i];
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKriging_Universal_Global::Get_Weights(void)
+{
+	int		i, j, n, iGrid, nGrids;
+
+	//-----------------------------------------------------
+	if( (nGrids = m_pGrids->Get_Count()) > 0 )
+	{
+		for(i=0; i<m_pPoints->Get_Count(); i++)
+		{
+			CSG_Shape	*pPoint	= m_pPoints->Get_Shape(i);
+
+			m_Points.Add(
+				pPoint->Get_Point(0).x,
+				pPoint->Get_Point(0).y,
+				pPoint->asDouble(m_zField)
+			);
+		}
+
+		//-------------------------------------------------
+		if( (n = m_Points.Get_Count()) > 1 )
+		{
+			m_G.Create(n + 1 + nGrids);
+			m_W.Create(n + 1 + nGrids, n + 1 + nGrids);
+
+			for(i=0; i<n; i++)
+			{
+				m_W[i][i]	= 0.0;				// diagonal...
+				m_W[i][n]	= m_W[n][i]	= 1.0;	// edge...
+
+				for(j=i+1; j<n; j++)
+				{
+					m_W[i][j]	= m_W[j][i]	= Get_Weight(
+						m_Points[i].x - m_Points[j].x,
+						m_Points[i].y - m_Points[j].y
+					);
+				}
+
+				for(iGrid=0, j=n+1; iGrid<nGrids; iGrid++, j++)
+				{
+					m_W[i][j]	= m_W[j][i]	= m_pGrids->asGrid(iGrid)->Get_Value(
+						m_Points[i].x, m_Points[i].y, m_Interpolation
+					);
+				}
+			}
+
+			for(i=n; i<=n+nGrids; i++)
+			{
+				for(j=n; j<=n+nGrids; j++)
+				{
+					m_W[i][j]	= 0.0;
+				}
+			}
+
+			return( m_W.Set_Inverse() );
+		}
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/kriging_universal_global.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Kriging_Universal_Global.h               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Kriging_Universal_Global_H
+#define HEADER_INCLUDED__Kriging_Universal_Global_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "kriging_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class geostatistics_kriging_EXPORT CKriging_Universal_Global : public CKriging_Base
+{
+public:
+	CKriging_Universal_Global(void);
+	virtual ~CKriging_Universal_Global(void);
+
+
+protected:
+
+	int						m_Interpolation;
+
+	CSG_Parameter_Grid_List	*m_pGrids;
+
+
+	virtual bool			On_Initialise	(void);
+
+	virtual bool			Get_Value		(double x, double y, double &z, double &Variance);
+
+
+private:
+
+	bool					Get_Weights		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Kriging_Universal_Global_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,326 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Points                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  semivariogram.cpp                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "semivariogram.h"
+
+#include "variogram_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	FIELD_CLASSNR	= 0,
+	FIELD_DISTANCE,
+	FIELD_COUNT,
+	FIELD_VARIANCE,
+	FIELD_VARCUMUL,
+	FIELD_MODEL
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSemiVariogram::CSemiVariogram(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Semivariogram (Dialog))"));
+
+	Set_Author		(SG_T("(c) 2009 by O.Conrad"));
+
+	Set_Description(
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ATTRIBUTE"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "RESULT"		, _TL("Semi-Variances"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DISTMAX"		, _TL("Maximum Distance"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, -1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DISTCOUNT"	, _TL("Initial Number of Distance Classes"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NSKIP"		, _TL("Skip Number"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters;
+
+	pParameters	= Add_Parameters(SG_T("FORMULA"), _TL("Formula"), _TL(""));
+
+	pParameters->Add_String(
+		NULL	, "STRING"		, _TL("Formula String"),
+		_TL(""),
+		SG_T("a + b * x")
+	);
+
+	//-----------------------------------------------------
+	m_Variances.Add_Field(SG_T("DISTANCE")	, SG_DATATYPE_Double);
+	m_Variances.Add_Field(SG_T("VAR_CUM")	, SG_DATATYPE_Double);
+	m_Variances.Add_Field(SG_T("VAR_CLS")	, SG_DATATYPE_Double);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSemiVariogram::On_Execute(void)
+{
+	bool		bResult	= false;
+	int			Attribute;
+	CSG_Shapes	*pPoints;
+	CSG_Table	*pTable;
+
+	//-----------------------------------------------------
+	pPoints		= Parameters("POINTS")		->asShapes();
+	pTable		= Parameters("RESULT")		->asTable();
+	Attribute	= Parameters("ATTRIBUTE")	->asInt();
+
+	//-----------------------------------------------------
+	if( Get_Variances(pTable, pPoints, Attribute) )
+	{
+		m_Variogram.Set_Formula	(Get_Parameters("FORMULA")->Get_Parameter("STRING")->asString());
+
+		if( SG_UI_Get_Window_Main() )
+		{
+			CVariogram_Dialog	dlg(&m_Variogram, &m_Variances);
+
+			bResult	= dlg.ShowModal() == wxID_OK;
+		}
+		else
+		{
+			m_Variogram.Clr_Data();
+
+			for(int i=0; i<m_Variances.Get_Count(); i++)
+			{
+				m_Variogram.Add_Data(m_Variances[i][0], m_Variances[i][1]);
+			}
+
+			bResult	= m_Variogram.Get_Trend();
+		}
+
+		if( bResult && m_Variogram.is_Okay() )
+		{
+			Get_Parameters("FORMULA")->Get_Parameter("STRING")->Set_Value(m_Variogram.Get_Formula(SG_TREND_STRING_Formula));
+
+			Message_Add(m_Variogram.Get_Formula(), false);
+
+			for(int i=0; i<pTable->Get_Count(); i++)
+			{
+				CSG_Table_Record	*pRecord	= pTable->Get_Record(i);
+
+				pRecord->Set_Value(FIELD_MODEL, m_Variogram.Get_Value(pRecord->asDouble(FIELD_DISTANCE)));
+			}
+		}
+	}
+
+	m_Variogram	.Clr_Data();
+	m_Variances	.Del_Records();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSemiVariogram::Get_Variances(CSG_Table *pTable, CSG_Shapes *pPoints, int Attribute)
+{
+	int					i, j, k, n, nDistances, nSkip;
+	double				z, d, dx, dy, maxDistance, lagDistance;
+	TSG_Point			Pt_i, Pt_j;
+	CSG_Vector			Count, Variance;
+	CSG_Table_Record	*pRecord;
+	CSG_Shape			*pPoint;
+
+	//-----------------------------------------------------
+	nSkip		= Parameters("NSKIP")		->asInt();
+	maxDistance	= Parameters("DISTMAX")		->asDouble();
+	nDistances	= Parameters("DISTCOUNT")	->asInt();
+
+	if( maxDistance <= 0.0 )
+	{
+		maxDistance	= SG_Get_Length(pPoints->Get_Extent().Get_XRange(), pPoints->Get_Extent().Get_XRange());
+	}
+
+	lagDistance	= maxDistance / nDistances;
+
+	Count		.Create(nDistances);
+	Variance	.Create(nDistances);
+
+	//-----------------------------------------------------
+	for(i=0, n=0; i<pPoints->Get_Count()-nSkip && Set_Progress(n, SG_Get_Square(pPoints->Get_Count()/nSkip)/2); i+=nSkip)
+	{
+		pPoint	= pPoints->Get_Shape(i);
+		Pt_i	= pPoint->Get_Point(0);
+		z		= pPoint->asDouble(Attribute);
+
+		for(j=i+nSkip; j<pPoints->Get_Count(); j+=nSkip, n++)
+		{
+			pPoint	= pPoints->Get_Shape(j);
+			Pt_j	= pPoint->Get_Point(0);
+			dx		= Pt_j.x - Pt_i.x;
+			dy		= Pt_j.y - Pt_i.y;
+			d		= sqrt(dx*dx + dy*dy);
+			k		= (int)(d / lagDistance);
+
+			if( k < nDistances )
+			{
+				d	= pPoint->asDouble(Attribute) - z;
+
+				Count	[k]	++;
+				Variance[k]	+= d * d;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	pTable->Destroy();
+	pTable->Set_Name(CSG_String::Format(SG_T("%s [%s]"), _TL("Semivariogram"), pPoints->Get_Name()));
+	pTable->Add_Field(_TL("Class")		, SG_DATATYPE_Int);		// FIELD_CLASSNR
+	pTable->Add_Field(_TL("Distance")	, SG_DATATYPE_Double);	// FIELD_DISTANCE
+	pTable->Add_Field(_TL("Count")		, SG_DATATYPE_Int);		// FIELD_COUNT
+	pTable->Add_Field(_TL("Variance")	, SG_DATATYPE_Double);	// FIELD_VARIANCE
+	pTable->Add_Field(_TL("Cum.Var.")	, SG_DATATYPE_Double);	// FIELD_VARCUMUL
+	pTable->Add_Field(_TL("Model")		, SG_DATATYPE_Double);	// FIELD_MODEL
+
+	pRecord	= pTable->Add_Record();
+	pRecord->Set_Value(FIELD_CLASSNR	, 0.0);
+	pRecord->Set_Value(FIELD_DISTANCE	, 0.0);
+	pRecord->Set_Value(FIELD_COUNT		, 0.0);
+	pRecord->Set_Value(FIELD_VARIANCE	, 0.0);
+	pRecord->Set_Value(FIELD_VARCUMUL	, 0.0);
+
+	for(i=0, z=0.0, n=0; i<nDistances; i++)
+	{
+		if( Count[i] > 0 )
+		{
+			n	+= Count[i];
+			z	+= Variance[i];
+
+			pRecord	= pTable->Add_Record();
+			pRecord->Set_Value(FIELD_CLASSNR	, (i + 1));
+			pRecord->Set_Value(FIELD_DISTANCE	, (i + 1) * lagDistance);
+			pRecord->Set_Value(FIELD_COUNT		, Count[i]);
+			pRecord->Set_Value(FIELD_VARIANCE	, 0.5 * Variance[i] / Count[i]);
+			pRecord->Set_Value(FIELD_VARCUMUL	, 0.5 * z / n);
+
+			pRecord	= m_Variances.Add_Record();
+			pRecord->Set_Value(0				, (i + 1) * lagDistance);
+			pRecord->Set_Value(1				, 0.5 * Variance[i] / Count[i]);
+			pRecord->Set_Value(2				, 0.5 * z / n);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/semivariogram.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Points                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   semivariogram.h                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__semivariogram_H
+#define HEADER_INCLUDED__semivariogram_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSemiVariogram : public CSG_Module  
+{
+public:
+	CSemiVariogram(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Points") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	CSG_Table				m_Variances;
+
+	CSG_Trend				m_Variogram;
+
+
+	bool					Get_Variances		(CSG_Table *pTable, CSG_Shapes *pPoints, int Attribute);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__semivariogram_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,306 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//            geostatistics_kriging_variogram            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Variogram_Dialog.cpp                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "variogram_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVariogram_Diagram : public CSGDI_Diagram
+{
+public:
+	CVariogram_Diagram(wxWindow *pParent, CSG_Trend *pVariogram, CSG_Table *pVariances);
+
+	CSG_Trend					*m_pVariogram;
+
+
+	void						Set_Trend				(double Distance, bool bCumulative);
+
+
+private:
+
+	bool						m_bCumulative;
+
+	double						m_Distance;
+
+	CSG_Table					*m_pVariances;
+
+
+	virtual void				On_Draw					(wxDC &dc, wxRect rDraw);
+
+};
+
+//---------------------------------------------------------
+CVariogram_Diagram::CVariogram_Diagram(wxWindow *pParent, CSG_Trend *pVariogram, CSG_Table *pVariances)
+	: CSGDI_Diagram(pParent)
+{
+	m_xName			= _TL("Distance");
+	m_yName			= _TL("Semivariance");
+
+	m_pVariogram	= pVariogram;
+	m_pVariances	= pVariances;
+
+	m_bCumulative	= false;
+	m_Distance		= -1.0;
+
+	//-----------------------------------------------------
+	m_xMin	= m_yMin	= 0.0;
+	m_xMax	= m_pVariances->Get_Maximum(0);
+	m_yMax	= (1.0 + 0.02) * m_pVariances->Get_Maximum(m_pVariances->Get_Maximum(1) > m_pVariances->Get_Maximum(2) ? 1 : 2);
+}
+
+//---------------------------------------------------------
+void CVariogram_Diagram::Set_Trend(double Distance, bool bCumulative)
+{
+	if( bCumulative != m_bCumulative || Distance < 0 || Distance != m_Distance )
+	{
+		m_bCumulative	= bCumulative;
+		m_Distance		= Distance;
+
+		m_pVariogram->Clr_Data();
+
+		for(int i=0; i<m_pVariances->Get_Count(); i++)
+		{
+			if( (*m_pVariances)[i][0] <= Distance )
+			{
+				m_pVariogram->Add_Data((*m_pVariances)[i][0], (*m_pVariances)[i][m_bCumulative ? 2 : 1]);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CVariogram_Diagram::On_Draw(wxDC &dc, wxRect rDraw)
+{
+	if( m_pVariances->Get_Count() > 0 )
+	{
+		int		i, ix, iy, jx, jy, k;
+		double	x, dx;
+
+		//-------------------------------------------------
+		if( m_pVariogram->Get_Data_Count() > 0 )
+		{
+			ix	= Get_xToScreen(m_pVariogram->Get_Data_XMax());
+			dc.SetPen  (wxPen(wxColour(  0, 127,   0), 2));
+			dc.DrawLine(ix, Get_yToScreen(m_yMin), ix, Get_yToScreen(m_yMax));
+		}
+
+		//-------------------------------------------------
+		dc.SetPen  (wxColour(191, 191, 191));
+		dc.SetBrush(wxColour(191, 191, 191));
+
+		for(i=0, k=m_bCumulative ? 1 : 2; i<m_pVariances->Get_Count(); i++)
+		{
+			ix	= Get_xToScreen((*m_pVariances)[i][0]);
+			iy	= Get_yToScreen((*m_pVariances)[i][k]);
+
+			dc.DrawCircle(ix, iy, 1);
+		}
+
+		//-------------------------------------------------
+		dc.SetPen  (wxColour(127, 127, 127));
+		dc.SetBrush(wxColour(  0,   0,   0));
+
+		for(i=0, k=m_bCumulative ? 2 : 1; i<m_pVariances->Get_Count(); i++)
+		{
+			ix	= Get_xToScreen((*m_pVariances)[i][0]);
+			iy	= Get_yToScreen((*m_pVariances)[i][k]);
+
+			dc.DrawCircle(ix, iy, 3);
+		}
+
+		//-------------------------------------------------
+		if( m_pVariogram->is_Okay() )
+		{
+			dc.SetPen(wxPen(*wxRED, 2));
+
+			dx	= (m_xMax - m_xMin) / (double)rDraw.GetWidth();
+
+			ix	= Get_xToScreen(m_xMin);
+			iy	= Get_yToScreen(m_pVariogram->Get_Value(m_xMin));
+
+			for(x=m_xMin+dx; x<=m_xMax; x+=dx)
+			{
+				jx	= ix;
+				jy	= iy;
+				ix	= Get_xToScreen(x);
+				iy	= Get_yToScreen(m_pVariogram->Get_Value(x));
+
+				dc.DrawLine(jx, jy, ix, iy);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVariogram_Dialog, CSGDI_Dialog)
+	EVT_CHECKBOX	(wxID_ANY	, CVariogram_Dialog::On_Update_Control)
+	EVT_TEXT_ENTER	(wxID_ANY	, CVariogram_Dialog::On_Update_Control)
+	EVT_SLIDER		(wxID_ANY	, CVariogram_Dialog::On_Update_Control)
+	EVT_CHOICE		(wxID_ANY	, CVariogram_Dialog::On_Update_Choices)
+END_EVENT_TABLE()
+
+//---------------------------------------------------------
+CVariogram_Dialog::CVariogram_Dialog(CSG_Trend *pVariogram, CSG_Table *pVariances)
+	: CSGDI_Dialog(_TL("Semi-Variogram"))
+{
+	//-----------------------------------------------------
+	wxArrayString	Formulas;
+
+	Formulas.Empty();
+	Formulas.Add(SG_T("a + b * x"));
+	Formulas.Add(SG_T("a + b * x + c * x^2"));
+	Formulas.Add(SG_T("a + b * x + c * x^2 + d * x^3"));
+	Formulas.Add(SG_T("a + b * x + c * x^2 + d * x^3 + e * x^4"));
+	Formulas.Add(SG_T("a + b * ln(x)"));
+	Formulas.Add(SG_T("a + b * x^c"));
+	Formulas.Add(SG_T("a + b / x"));
+	Formulas.Add(SG_T("a + b * sqrt(c + x)"));
+	Formulas.Add(SG_T("a * (1 - exp(-(abs(x) / b)^2))"));
+	Formulas.Add(SG_T("n + (s - n) * (1 - exp(-(x / r)^2))"));
+	Formulas.Add(SG_T("n+(s-n)*ifelse(x>r,1,3*x/(2*r)-x^3/(2*r^3))"));
+
+	//-----------------------------------------------------
+	Add_Button(_TL("Ok")		, wxID_OK);
+	Add_Button(_TL("Cancel")	, wxID_CANCEL);
+
+	Add_Spacer();
+	m_pCumulative	= Add_CheckBox	(_TL("Cumulative Variance"), false);
+
+	Add_Spacer();
+	m_pFormulas		= Add_Choice	(_TL("Predefined Functions"), Formulas, 0);
+
+	Add_Spacer();
+	m_pDistance		= Add_Slider	(_TL("Function Fitting Range"), pVariances->Get_Maximum(0), 0.0, pVariances->Get_Maximum(0));
+
+	Add_Spacer();
+	m_pParameters	= Add_TextCtrl	(_TL("Function Parameters"), wxTE_MULTILINE|wxTE_READONLY);
+
+	//-----------------------------------------------------
+	Add_Output(
+		m_pDiagram = new CVariogram_Diagram(this, pVariogram, pVariances),
+		m_pFormula = new wxTextCtrl(this, wxID_ANY, pVariogram->Get_Formula(SG_TREND_STRING_Formula).c_str(), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER),
+		1, 0
+	);
+
+	Fit_Function();
+}
+
+//---------------------------------------------------------
+void CVariogram_Dialog::On_Update_Control(wxCommandEvent &WXUNUSED(event))
+{
+	Fit_Function();
+}
+
+void CVariogram_Dialog::On_Update_Choices(wxCommandEvent &WXUNUSED(event))
+{
+	m_pFormula->SetValue(m_pFormulas->GetStringSelection().c_str());
+
+	Fit_Function();
+}
+
+//---------------------------------------------------------
+void CVariogram_Dialog::Fit_Function(void)
+{
+	wxString	s;
+
+	m_pDiagram->Set_Trend(m_pDistance->Get_Value(), m_pCumulative->GetValue());
+
+	if(	!m_pDiagram->m_pVariogram->Set_Formula(m_pFormula->GetValue().c_str()) )
+	{
+		s	+= _TL("invalid formula !");
+	}
+	else if( !m_pDiagram->m_pVariogram->Get_Trend() )
+	{
+		s	+= _TL("function fitting failed !");
+	}
+	else
+	{
+		s	+= m_pDiagram->m_pVariogram->Get_Formula(SG_TREND_STRING_Function).c_str();
+		s	+= wxString::Format(wxT("\n%s: %.*f")	, _TL("Fitting range")		, SG_Get_Significant_Decimals(m_pDistance->Get_Value()), m_pDistance->Get_Value());
+		s	+= wxString::Format(wxT("\n%s: %d")		, _TL("Samples in range")	, m_pDiagram->m_pVariogram->Get_Data_Count());
+		s	+= wxString::Format(wxT("\n%s: %.2f%")	, _TL("R2")					, m_pDiagram->m_pVariogram->Get_R2() * 100.0);
+	}
+
+	m_pParameters->SetValue(s);
+
+	m_pDiagram->Refresh(true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_kriging/variogram_dialog.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,130 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Variogram_Dialog.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Variogram_Dialog_H
+#define HEADER_INCLUDED__Variogram_Dialog_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include <saga_gdi/saga_gdi.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVariogram_Dialog : public CSGDI_Dialog
+{
+public:
+	CVariogram_Dialog(CSG_Trend *pVariogram, CSG_Table *pVariances);
+
+
+private:
+
+	wxCheckBox					*m_pCumulative;
+
+	wxChoice					*m_pFormulas;
+
+	wxTextCtrl					*m_pFormula, *m_pParameters;
+
+	CSGDI_Slider				*m_pDistance;
+
+	class CVariogram_Diagram	*m_pDiagram;
+
+
+	void						On_Update_Control		(wxCommandEvent &event);
+	void						On_Update_Choices		(wxCommandEvent &event);
+
+	void						Fit_Function			(void);
+
+
+	DECLARE_EVENT_TABLE()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Variogram_Dialog_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,314 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Points                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              GSPoints_Semi_Variances.cpp              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "GSPoints_Semi_Variances.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	DIF_FIELD_DISTANCE		= 0,
+	DIF_FIELD_DIFFERENCE
+};
+
+//---------------------------------------------------------
+enum
+{
+	VAR_FIELD_DISTANCE		= 0,
+	VAR_FIELD_VARIANCE,
+	VAR_FIELD_STDDEV,
+	VAR_FIELD_CLASSVAR,
+	VAR_FIELD_COUNT
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGSPoints_Semi_Variances::CGSPoints_Semi_Variances(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name	(_TL("Semivariogram"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "POINTS"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"		, _TL("Attribute"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "RESULT"		, _TL("Semi-Variances"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DISTLAG"		, _TL("Distance Increment"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 10.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DISTMAX"		, _TL("Maximum Distance"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, -1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NSKIP"		, _TL("Skip Number"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CGSPoints_Semi_Variances::~CGSPoints_Semi_Variances(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGSPoints_Semi_Variances::On_Execute(void)
+{
+	CSG_Shapes		*pShapes;
+	CSG_Table		*pTable, Table_Differences;
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("POINTS")->asShapes();
+
+	Get_Differences(
+		pShapes,
+		&Table_Differences,
+		Parameters("FIELD")		->asInt(),
+		Parameters("NSKIP")		->asInt(),
+		Parameters("DISTMAX")	->asDouble()
+	);
+
+	//-----------------------------------------------------
+	pTable		= Parameters("RESULT")->asTable();
+
+	Get_Variances(
+		pTable,
+		&Table_Differences,
+		Parameters("DISTLAG")	->asDouble()
+	);
+
+	//-----------------------------------------------------
+	pTable->Set_Name(CSG_String::Format(SG_T("%s [%s]: %s"),
+		pShapes->Get_Name(),
+		pShapes->Get_Field_Name(Parameters("FIELD")->asInt()),
+		_TL("Semi-Variances")
+	));
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGSPoints_Semi_Variances::Get_Differences(CSG_Shapes *pShapes, CSG_Table *pTable, int zField, int nSkip, double maxDist)
+{
+	int					iPoint, jPoint;
+	double				d, dx, dy, z;
+	CSG_Shape			*pPoint;
+	CSG_Table_Record	*pRecord;
+	TSG_Point			Pt_i, Pt_j;
+
+	//-----------------------------------------------------
+	pTable->Destroy();
+	pTable->Add_Field(_TL("Distance")	, SG_DATATYPE_Double);	// DIF_FIELD_DISTANCE
+	pTable->Add_Field(_TL("Difference")	, SG_DATATYPE_Double);	// DIF_FIELD_DIFFERENCE
+
+	//-----------------------------------------------------
+	for(iPoint=0; iPoint<pShapes->Get_Count()-nSkip && Set_Progress(iPoint, pShapes->Get_Count()-nSkip); iPoint+=nSkip)
+	{
+		pPoint	= pShapes->Get_Shape(iPoint);
+		Pt_i	= pPoint->Get_Point(0);
+		z		= pPoint->asDouble(zField);
+
+		for(jPoint=iPoint+nSkip; jPoint<pShapes->Get_Count(); jPoint+=nSkip)
+		{
+			pPoint	= pShapes->Get_Shape(jPoint);
+			Pt_j	= pPoint->Get_Point(0);
+			dx		= Pt_j.x - Pt_i.x;
+			dy		= Pt_j.y - Pt_i.y;
+
+			if( (d = sqrt(dx*dx + dy*dy)) < maxDist || maxDist < 0.0 )
+			{
+				pRecord	= pTable->Add_Record();
+				pRecord->Set_Value(DIF_FIELD_DISTANCE	, d);
+				pRecord->Set_Value(DIF_FIELD_DIFFERENCE	, pPoint->asDouble(zField) - z);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGSPoints_Semi_Variances::Get_Variances(CSG_Table *pTab_Var, CSG_Table *pTab_Dif, double Dist_Step)
+{
+	int					iDif, nVar, nVarS;
+	double				iDist, dz, zVar, zVarS, Dist;
+	CSG_Table_Record	*pRec_Dif, *pRec_Var;
+
+	//-----------------------------------------------------
+	if( Process_Get_Okay(false) )
+	{
+		pTab_Var->Destroy();
+		pTab_Var->Add_Field(_TL("Distance")			, SG_DATATYPE_Double);	// VAR_FIELD_DISTANCE
+		pTab_Var->Add_Field(_TL("Variance")			, SG_DATATYPE_Double);	// VAR_FIELD_VARIANCE
+		pTab_Var->Add_Field(_TL("Std.Deviation")	, SG_DATATYPE_Double);	// VAR_FIELD_STDDEV
+		pTab_Var->Add_Field(_TL("Class Variance")	, SG_DATATYPE_Double);	// VAR_FIELD_CLASSVAR
+		pTab_Var->Add_Field(_TL("Class Count")		, SG_DATATYPE_Int);		// VAR_FIELD_COUNT
+
+		pTab_Dif->Set_Index(DIF_FIELD_DISTANCE, TABLE_INDEX_Ascending);
+
+		//-----------------------------------------------------
+		iDist		= 0.0;
+		zVar		= 0.0;
+		nVar		= 0;
+		zVarS		= 0.0;
+		nVarS		= 0;
+
+		//-----------------------------------------------------
+		for(iDif=0; iDif<pTab_Dif->Get_Record_Count() && Set_Progress(iDif, pTab_Dif->Get_Record_Count()); iDif++)
+		{
+			pRec_Dif	= pTab_Dif->Get_Record_byIndex(iDif);
+
+			if( (Dist = pRec_Dif->asDouble(DIF_FIELD_DISTANCE)) > iDist )
+			{
+				if( nVar > 0 )
+				{
+					zVarS	+= zVar;
+					nVarS	+= nVar;
+
+					pRec_Var	= pTab_Var->Add_Record();
+					pRec_Var->Set_Value(VAR_FIELD_DISTANCE	, iDist);
+					pRec_Var->Set_Value(VAR_FIELD_VARIANCE	, 0.5 * zVarS / (double)nVarS);
+					pRec_Var->Set_Value(VAR_FIELD_STDDEV	, sqrt(0.5 * zVarS / (double)nVarS));
+					pRec_Var->Set_Value(VAR_FIELD_CLASSVAR	, 0.5 * zVar  / (double)nVar);
+					pRec_Var->Set_Value(VAR_FIELD_COUNT		, nVar);
+				}
+
+				zVar		= 0.0;
+				nVar		= 0;
+
+				do	iDist	+= Dist_Step;	while( Dist > iDist );
+			}
+
+			dz		= pRec_Dif->asDouble(DIF_FIELD_DIFFERENCE);
+			zVar	+= dz*dz;
+			nVar++;
+		}
+
+		//-----------------------------------------------------
+		pTab_Dif->Set_Index(DIF_FIELD_DISTANCE, TABLE_INDEX_None);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/GSPoints_Semi_Variances.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Points                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               GSPoints_Semi_Variances.h               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSPoints_Semi_Variances_H
+#define HEADER_INCLUDED__GSPoints_Semi_Variances_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGSPoints_Semi_Variances : public CSG_Module  
+{
+public:
+	CGSPoints_Semi_Variances(void);
+	virtual ~CGSPoints_Semi_Variances(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	void				Get_Differences	(CSG_Shapes *pShapes, CSG_Table *pTable, int zField, int nSkip, double maxDist);
+	void				Get_Variances	(CSG_Table *pTab_Var, CSG_Table *pTab_Dif, double Dist_Step);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__GSPoints_Semi_Variances_H

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,135 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Points                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Geostatistics - Points") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Geostatistical analyses for point data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Geostatistics|Points") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "GSPoints_Semi_Variances.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CGSPoints_Semi_Variances;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_geostatistics/geostatistics/geostatistics_points/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 Geostatistics_Points                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__geostatistics_points_H
+#define HEADER_INCLUDED__geostatistics_points_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef geostatistics_points_EXPORTS
+	#define	geostatistics_points_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	geostatistics_points_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__geostatistics_points_H

Added: packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1571 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     ESRI_E00.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ESRI_E00_Import.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CESRI_E00_Import::CESRI_E00_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. info_Table...
+
+	Set_Name	(_TL("Import ESRI E00 File"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import data sets from ESRI's E00 interchange format.\n\n"
+
+		"This import filter is based on the E00 format analysis of the GRASS GIS module "
+		"\'m.in.e00\' written by Michel J. Wurtz. Go to the "
+		"<a target=\"_blank\" href=\"http://grass.itc.it/\">GRASS GIS Hompage</a> "
+		"for more information.\n"
+
+		"The <a target=\"_blank\" href=\"http://avce00.maptools.org/e00compr/index.html\">\'E00Compr\' library</a> "
+		"written by Daniel Morissette has been used for e00 file access, so that "
+		"compressed e00 files also can be read.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "ARCS"	, _TL("Arcs"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "SITES"	, _TL("Sites"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "LABELS"	, _TL("Labels"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "BND"		, _TL("Boundary"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "TIC"		, _TL("Tick Points"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Output(
+		NULL	, "TABLE"	, _TL("Table"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("ESRI E00 Files|*.e00;*.e0*|All Files|*.*")
+	);
+}
+
+//---------------------------------------------------------
+CESRI_E00_Import::~CESRI_E00_Import(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CESRI_E00_Import::On_Execute(void)
+{
+	bool	bResult;
+
+	bResult		= false;
+	hReadPtr	= NULL;
+
+	if( Open(Parameters("FILE")->asString()) )
+	{
+		bResult	= Load();
+	}
+
+	if( hReadPtr )
+	{
+		E00ReadClose(hReadPtr);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CESRI_E00_Import::E00GotoLine(int iLine)
+{
+	if( hReadPtr )
+	{
+		E00ReadRewind(hReadPtr);
+
+		while( E00ReadNextLine(hReadPtr) && hReadPtr->nInputLineNo != iLine );
+
+		return( hReadPtr->nInputLineNo == iLine );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CESRI_E00_Import::Open(const SG_Char *FileName)
+{
+	const char	*Line;
+
+	//-----------------------------------------------------
+	if( FileName == NULL || (hReadPtr = E00ReadOpen(CSG_String(FileName).b_str())) == NULL )
+	{
+		Error_Set(CSG_String::Format(_TL("%s - not found\n"), FileName));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( (Line = E00ReadNextLine(hReadPtr)) == NULL )
+	{
+		Error_Set(CSG_String::Format(_TL("\"%s\" is not an Arc-info_Table Export file !\n"), FileName));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( strncmp(Line, "EXP", 3) )
+	{
+		Error_Set(CSG_String::Format(_TL("\"%s\" is not an Arc-info_Table Export file !\n"), FileName));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	e00_Name	= FileName;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CESRI_E00_Import::Load(void)
+{
+	const char	*line;
+
+	int			prec_grd, prec_arc, prec_lab, prec_pal;
+
+	long		current_line,
+				offset_grd	= 0,
+				offset_arc	= 0,
+				offset_lab	= 0,
+				offset_pal	= 0;
+
+	double		scale		= 1.0;
+
+	TSG_Shape_Type	shape_type;
+
+	CSG_Grid		*pGrid;
+
+	CSG_Shapes		*pShapes;
+
+	//-----------------------------------------------------
+	pPAT	= NULL;
+	pAAT	= NULL;
+
+	//-----------------------------------------------------
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL && strncmp(line, "EOS", 3) )
+	{
+		current_line = hReadPtr->nInputLineNo;
+
+		// GRID SECTION
+		if( !strncmp(line, "GRD  ", 5) )
+		{
+			offset_grd	= current_line;
+			prec_grd	= line[5] - '2';
+			skip("EOG");
+			continue;
+		}
+
+		// ARC SECTION
+		if( !strncmp(line, "ARC  ", 5) )
+		{
+			offset_arc	= current_line;
+			prec_arc	= line[5] - '2';
+			skip_arc(prec_arc);
+			continue;
+		}
+
+		// POLYGON TOPOLOGY
+		if(	!strncmp(line, "PAL  ", 5)
+		||	!strncmp(line, "PFF  ", 5)	)
+		{
+			offset_pal	= current_line;
+			prec_pal	= line[5] - '2';
+			skip_pal(prec_pal);
+			continue;
+		}
+
+		// CENTROID SECTION
+		if( !strncmp(line, "CNT  ", 5) )
+		{
+			skip_dat();
+			continue;
+		}
+
+		// LABEL SECTION
+		if( !strncmp(line, "LAB  ", 5))
+		{
+			offset_lab	= current_line;
+			prec_lab	= line[5] - '2';
+			skip_lab(prec_lab);
+			continue;
+		}
+
+		// INFO SECTION
+		if( !strncmp(line, "IFO  ", 5) )
+		{
+			info_Get_Tables();
+			continue;
+		}
+
+		// PROJECTION INFOS
+		if( !strncmp(line, "PRJ  ", 5) )
+		{
+			scale		= getproj();
+			continue;
+		}
+
+		// Annotations (text). To be imported ? Does anybody have an idea ?
+		if( !strncmp(line, "TXT  ", 5) )
+		{
+			skip_txt(line[5] - '2');
+			continue;
+		}
+
+		// Mask description ? Noting to do with it
+		if( !strncmp(line, "MSK  ", 5) )
+		{
+			skip_msk();
+			continue;
+		}
+
+		// TOLERANCE SECTION. Should we really use it ?
+		if( !strncmp(line, "TOL  ", 5) )
+		{
+			skip_dat();
+			continue;
+		}
+
+		// UNKNOW KEYWORD SECTION. Don't know what to do with. Does anybody have an idea?
+		if( !strncmp(line, "LNK  ", 5) )
+		{
+			skip("END OF LINK DATA");
+			continue;
+		}
+
+		// SPATIAL INDEX SECTION. Noting to do with it
+		if( !strncmp(line, "SIN  ", 5) )
+		{
+			skip("EOX");
+			continue;
+		}
+
+		// Line pattern and palette. Shade pattern and palette end same as e00 archive !
+		if(	!strncmp(line, "CLN  ", 5)
+		||	!strncmp(line, "CSH  ", 5)	)
+		{
+			skip("EOS");
+			continue;
+		}
+
+		// Font description ? Noting to do with it
+		if( !strncmp(line, "FNT  ", 5) )
+		{
+			skip("EOF");
+			continue;
+		}
+
+		// PLOT SECTION. Why should we import it ?
+		if( !strncmp(line, "PLT  ", 5) )
+		{
+			skip("EOP");
+			continue;
+		}
+
+		// LOG SECTION. Nothing to do with it
+		if( !strncmp(line, "LOG  ", 5) )
+		{
+			skip("EOL");
+			continue;
+		}
+
+		if(	!strncmp(line, "RPL  ", 5)		// Specific to regions. Contains PAL formated data for each subclass
+		||	!strncmp(line, "RXP  ", 5)		// Specific to regions. Seems to link regions IDs to PAL polygons IDs
+		||	!strncmp(line, "TX6  ", 5)		// Other kind of annotations not same termination. Other differences ?
+		||	!strncmp(line, "TX7  ", 5)	)	// Very close from TX6. So same questions and same rules...
+		{
+			skip("JABBERWOCKY");
+			continue;
+		}
+	}
+
+	//-----------------------------------------------------
+	switch( pPAT ? (pAAT ? 3 : 2) : (pAAT ? 1 : 0) )
+	{
+	case 0: default:
+		shape_type	= offset_arc != 0 ? SHAPE_TYPE_Line : SHAPE_TYPE_Point;
+		break;
+
+	case 1:	// pAAT
+		shape_type	= SHAPE_TYPE_Line;
+		break;
+
+	case 2:	// pPAT
+		shape_type	= offset_arc != 0 ? SHAPE_TYPE_Polygon : SHAPE_TYPE_Point;
+		break;
+
+	case 3:	// pAAT && pPAT
+		shape_type	= offset_pal != 0 || offset_lab != 0 ? SHAPE_TYPE_Polygon : SHAPE_TYPE_Line;
+		break;
+	}
+
+	//-----------------------------------------------------
+	// Extracting useful information as noted before...
+
+	//-----------------------------------------------------
+	if( offset_grd > 0 )
+	{
+		E00GotoLine(offset_grd);
+
+		if( (pGrid = getraster	(prec_grd, scale)) != NULL )
+		{
+			pGrid->Set_Name(e00_Name);
+
+			Parameters("GRID")->Set_Value(pGrid);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( offset_arc != 0 )
+	{
+		E00GotoLine(offset_arc);
+
+		if( (pShapes = getarcs	(prec_arc, scale, shape_type)) != NULL )
+		{
+			pShapes->Set_Name(e00_Name);
+
+			Parameters("ARCS")->Set_Value(pShapes);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( offset_lab != 0 && shape_type == SHAPE_TYPE_Point )
+	{
+		E00GotoLine(offset_lab);
+
+		if( (pShapes = getsites	(prec_lab, scale)) != NULL )
+		{
+			pShapes->Set_Name(e00_Name);
+
+			Parameters("SITES")->Set_Value(pShapes);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( offset_lab != 0 && shape_type != SHAPE_TYPE_Point )
+	{
+		E00GotoLine(offset_lab);
+
+		if( (pShapes = getlabels(prec_lab, scale)) != NULL )
+		{
+			pShapes->Set_Name(e00_Name);
+
+			Parameters("LABELS")->Set_Value(pShapes);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Grid							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid * CESRI_E00_Import::getraster(int prec, double scale)
+{
+	const char	*line;
+
+	int		x, y, ix;
+	long	rows, cols, depth, p[5];
+	float	f[5];
+	double	xres, yres, xmin, ymin, xmax, ymax, nul_val, d[3];
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	if( (line = E00ReadNextLine(hReadPtr)) == NULL )
+		return( NULL );
+//	sscanf(line, "%ld%ld%ld", &cols, &rows, &depth, &nul_val);
+	sscanf(line, "%ld%ld%ld%lf", &cols, &rows, &depth, &nul_val);
+
+	if( (line = E00ReadNextLine(hReadPtr)) == NULL )
+		return( NULL );
+	sscanf(line, "%lf%lf", &xres, &yres);
+
+	if( (line = E00ReadNextLine(hReadPtr)) == NULL )
+		return( NULL );
+	sscanf(line, "%lf%lf", &xmin, &ymin);
+
+	if( (line = E00ReadNextLine(hReadPtr)) == NULL )
+		return( NULL );
+	sscanf(line, "%lf%lf", &xmax, &ymax);
+
+	xmax	= xmax * scale;
+	xmin	= xmin * scale;
+	ymax	= ymax * scale;
+	ymin	= ymin * scale;
+	xres	= xres * scale;
+	yres	= yres * scale;
+
+	if( depth == 2 && prec )
+	{
+		depth	= 3;
+	}
+
+	//-----------------------------------------------------
+	switch( depth )
+	{
+	default:
+		pGrid	= NULL;
+		break;
+
+	//-----------------------------------------------------
+	case 1:
+		pGrid	= SG_Create_Grid(SG_DATATYPE_Int, cols, rows, xres, xmin, ymin);
+		pGrid->Set_NoData_Value(nul_val);
+
+		for(y=0; y<rows && line && Set_Progress(y, rows); y++)
+		{
+			for(x=0; x<cols; x+= 5)
+			{
+				if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+				{
+					sscanf(line, "%ld%ld%ld%ld%ld", p, p+1, p+2, p+3, p+4);
+
+					for(ix=0; ix<5 && x+ix<cols; ix++)
+					{
+						pGrid->Set_Value(x + ix, y, p[ix]);
+					}
+				}
+			}
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 2:
+		pGrid	= SG_Create_Grid(SG_DATATYPE_Float, cols, rows, xres, xmin, ymin);
+		pGrid->Set_NoData_Value(nul_val);
+
+		for(y=0; y<rows && line && Set_Progress(y, rows); y++)
+		{
+			for(x=0; x<cols; x+= 5)
+			{
+				if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+				{
+					sscanf(line, "%f%f%f%f%f", f, f+1, f+2, f+3, f+4);
+
+					for(ix=0; ix<5 && x+ix<cols; ix++)
+					{
+						pGrid->Set_Value(x + ix, y, f[ix]);
+					}
+				}
+			}
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 3:
+		pGrid	= SG_Create_Grid(SG_DATATYPE_Double, cols, rows, xres, xmin, ymin);
+		pGrid->Set_NoData_Value(nul_val);
+
+		for(y=0; y<rows && line && Set_Progress(y, rows); y++)
+		{
+			for(x=0; x<cols; x+= 3)
+			{
+				if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+				{
+					sscanf(line, "%lf%lf%lf", d, d+1, d+2);
+
+					for(ix=0; ix<3 && x+ix<cols; ix++)
+					{
+						pGrid->Set_Value(x + ix, y, d[ix]);
+					}
+				}
+			}
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	skip("EOG");
+
+	return( pGrid );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define ARC_FNODE	2
+#define ARC_TNODE	3
+#define ARC_LPOL	4
+#define ARC_RPOL	5
+
+//---------------------------------------------------------
+CSG_Shapes * CESRI_E00_Import::getarcs(int prec, double scale, TSG_Shape_Type &shape_type)
+{
+	const char	*line;
+
+	int		covnum, cov_id, fnode, tnode, lpol, rpol, nPoints, iPoint;
+	double	x_buf[2], y_buf[2];
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+
+	//-----------------------------------------------------
+	pShapes	= SG_Create_Shapes(shape_type);
+	pShapes->Add_Field("ID"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("ID#"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("FNODE"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("TNODE"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("LPOL"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("RPOL"	, SG_DATATYPE_Int);
+
+	Set_Progress(0, 100);
+
+	//-----------------------------------------------------
+	do
+	{
+		Process_Set_Text(CSG_String::Format(SG_T("Loaded arcs: %d"), pShapes->Get_Count()));
+
+		if( (line = E00ReadNextLine(hReadPtr)) == NULL )
+		{
+			covnum	= -1;
+		}
+		else
+		{
+			sscanf(line, "%d %d %d %d %d %d %d", &covnum, &cov_id, &fnode, &tnode, &lpol, &rpol, &nPoints);
+		}
+
+		if( covnum != -1 )
+		{
+			pShape	= pShapes->Add_Shape();
+
+			pShape->Set_Value(0			, covnum);
+			pShape->Set_Value(1			, cov_id);
+			pShape->Set_Value(ARC_FNODE	, fnode);
+			pShape->Set_Value(ARC_TNODE	, tnode);
+			pShape->Set_Value(ARC_LPOL	, lpol);
+			pShape->Set_Value(ARC_RPOL	, rpol);
+
+			//---------------------------------------------
+			if( prec )	// double precision : 1 coord pair / line
+			{
+				for(iPoint=0; iPoint<nPoints && line; iPoint++)
+				{
+					if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+					{
+						sscanf(line, "%lf %lf", x_buf, y_buf);
+
+						pShape->Add_Point(x_buf[0] * scale, y_buf[0] * scale);
+					}
+				}
+			}
+
+			//---------------------------------------------
+			else		// single precision : 2 x,y pairs / line
+			{
+				for(iPoint=0; iPoint<nPoints && line; iPoint+=2)
+				{
+					if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+					{
+						sscanf(line, "%lf %lf %lf %lf", x_buf, y_buf, x_buf + 1, y_buf + 1);
+
+						pShape->Add_Point(x_buf[0] * scale, y_buf[0] * scale);
+
+						if( iPoint + 1 < nPoints )
+						{
+							pShape->Add_Point(x_buf[1] * scale, y_buf[1] * scale);
+						}
+					}
+				}
+			}
+		}
+	}
+	while( covnum != -1 && line && Process_Get_Okay(false) );
+
+	//-----------------------------------------------------
+	if( pShapes->Get_Count() == 0 )
+	{
+		delete(pShapes);
+
+		shape_type	= SHAPE_TYPE_Point;
+
+		return( NULL );
+	}
+
+	if( shape_type == SHAPE_TYPE_Polygon )
+	{
+		pShapes	= Arcs2Polygons(pShapes);
+
+		Assign_Attributes(pShapes);
+	}
+
+	return( pShapes );
+}
+
+//---------------------------------------------------------
+CSG_Shapes * CESRI_E00_Import::Arcs2Polygons(CSG_Shapes *pArcs)
+{
+	int			iArc, nArcs, id;
+	CSG_Shapes	*pPolygons;
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Arcs to polygons"));
+
+	pPolygons	= SG_Create_Shapes(SHAPE_TYPE_Polygon);
+	pPolygons->Add_Field("ID", SG_DATATYPE_Int);
+
+	nArcs		= pArcs->Get_Count();
+
+	//-----------------------------------------------------
+	while( (iArc = pArcs->Get_Count() - 1) >= 0 && Set_Progress(nArcs - iArc - 1, nArcs) )
+	{
+		id	= pArcs->Get_Shape(iArc)->asInt(ARC_LPOL);
+
+		if( id == pArcs->Get_Shape(iArc)->asInt(ARC_RPOL) )
+		{
+			pArcs->Del_Shape(iArc);
+		}
+		else if( id > 1 )
+		{
+			Arcs2Polygon(pArcs, pPolygons, id);
+		}
+
+		if( (iArc = pArcs->Get_Count() - 1) >= 0 )
+		{
+			id	= pArcs->Get_Shape(iArc)->asInt(ARC_RPOL);
+
+			if( id > 1 )
+			{
+				Arcs2Polygon(pArcs, pPolygons, id);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	delete( pArcs );
+
+	return( pPolygons );
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::Arcs2Polygon(CSG_Shapes *pArcs, CSG_Shapes *pPolygons, int id)
+{
+	int		iShape, iPart, iPoint, iNode;
+	CSG_Shape	*pArc, *pShape;
+	CSG_Shapes	Arcs;
+
+	//-----------------------------------------------------
+	Arcs.Create(SHAPE_TYPE_Line);
+	Arcs.Add_Field("FROM_NODE", SG_DATATYPE_Int);
+	Arcs.Add_Field("TO___NODE", SG_DATATYPE_Int);
+
+	//-----------------------------------------------------
+	for(iShape=pArcs->Get_Count()-1; iShape>=0; iShape--)
+	{
+		pShape	= pArcs->Get_Shape(iShape);
+
+		if( id == pShape->asInt(ARC_LPOL) )
+		{
+			pArc	= Arcs.Add_Shape();
+			pArc->Set_Value(0, pShape->asInt(ARC_FNODE));
+			pArc->Set_Value(1, pShape->asInt(ARC_TNODE));
+
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(0); iPoint++)
+			{
+				pArc->Add_Point(pShape->Get_Point(iPoint, 0), 0);
+			}
+
+			if( pShape->asInt(ARC_RPOL) <= 1 )
+			{
+				pArcs->Del_Shape(iShape);
+			}
+			else
+			{
+				pShape->Set_Value(ARC_LPOL, 1);
+			}
+		}
+		else if( id == pShape->asInt(ARC_RPOL) )
+		{
+			pArc	= Arcs.Add_Shape();
+			pArc->Set_Value(1, pShape->asInt(ARC_FNODE));
+			pArc->Set_Value(0, pShape->asInt(ARC_TNODE));
+
+			for(iPoint=pShape->Get_Point_Count(0)-1; iPoint>=0; iPoint--)
+			{
+				pArc->Add_Point(pShape->Get_Point(iPoint, 0), 0);
+			}
+
+			if( pShape->asInt(ARC_LPOL) <= 1 )
+			{
+				pArcs->Del_Shape(iShape);
+			}
+			else
+			{
+				pShape->Set_Value(ARC_RPOL, 1);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( Arcs.Get_Count() > 0 )
+	{
+		iPart	= 0;
+		pShape	= pPolygons->Add_Shape();
+		pShape->Set_Value(0, id);
+
+		do
+		{
+			pArc	= Arcs.Get_Shape(0);
+
+			while( pArc )
+			{
+				for(iPoint=0; iPoint<pArc->Get_Point_Count(0); iPoint++)
+				{
+					pShape->Add_Point(pArc->Get_Point(iPoint, 0), iPart);
+				}
+
+				iNode	= pArc->asInt(1);
+				Arcs.Del_Shape(pArc);
+
+				for(iShape=0, pArc=NULL; iShape<Arcs.Get_Count() && !pArc; iShape++)
+				{
+					if( iNode == Arcs.Get_Shape(iShape)->asInt(0) )
+					{
+						pArc	= Arcs.Get_Shape(iShape);
+					}
+				}
+			}
+
+			iPart++;
+		}
+		while( Arcs.Get_Count() > 0 );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes * CESRI_E00_Import::getlabels(int prec, double scale)	// shape_type: LINE or AREA
+{
+	const char	*line;
+
+	int		num, id;	// coverage-# and coverage-ID
+	double	x, y;
+	CSG_Shapes	*pShapes;
+	CSG_Shape	*pShape;
+
+	pShapes	= SG_Create_Shapes(SHAPE_TYPE_Point);
+
+	pShapes->Add_Field("ID#"	, SG_DATATYPE_Int);
+	pShapes->Add_Field("ID"	, SG_DATATYPE_Int);
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf(line, "%d %d %lf %lf", &id, &num, &x, &y);
+
+		if( id == -1 )
+		{
+			break;
+		}
+		else
+		{
+			pShape	= pShapes->Add_Shape();
+
+			pShape->Add_Point(x * scale, y * scale);
+
+			pShape->Set_Value(0, num);
+			pShape->Set_Value(1, id);
+
+			//---------------------------------------------
+			E00ReadNextLine(hReadPtr);		// 4 values to skip
+
+			if( prec )
+			{
+				E00ReadNextLine(hReadPtr);	// on 2nd line when double precision
+			}
+		}
+	}
+
+	if( pShapes->Get_Count() <= 0 )
+	{
+		delete( pShapes );
+		pShapes	= NULL;
+	}
+
+	return( pShapes );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes * CESRI_E00_Import::getsites(int prec, double scale)
+{
+	const char	*line;
+
+	int		id;
+	double	x, y;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+
+	pShapes	= SG_Create_Shapes(SHAPE_TYPE_Point);
+	pShapes->Add_Field("ID", SG_DATATYPE_Int);
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf(line, "%d %*d %lf %lf", &id, &x, &y);
+
+		if( id == -1 )
+		{
+			break;
+		}
+
+		pShape	= pShapes->Add_Shape();
+
+		pShape->Add_Point(x * scale, y * scale);
+		pShape->Set_Value(0, id);
+
+		//-------------------------------------------------
+		E00ReadNextLine(hReadPtr);		// 4 values to skip
+
+		if( prec )
+		{
+			E00ReadNextLine(hReadPtr);	// on 2nd line when double precision
+		}
+	}
+
+	if( pShapes->Get_Count() <= 0 )
+	{
+		delete( pShapes );
+		pShapes	= NULL;
+	}
+	else
+	{
+		Assign_Attributes(pShapes);
+	}
+
+	return( pShapes );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CESRI_E00_Import::getproj(void)
+{
+	const char	*line;
+
+	double	scale	= 1.0;
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL && strncmp(line, "EOP", 3) )
+	{
+		if( !strncmp(line, "Units", 5) )
+		{
+			sscanf(line + 6, "%lf", &scale);
+		}
+	}
+
+	scale	= 1.0 / scale;
+
+	return( scale );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						info section					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+struct info_Field
+{
+	char				Name[18];	// name of item
+
+	int					Position,	// position in data line
+						Size,		// size for reading
+						Type;		// type of data
+};
+
+//---------------------------------------------------------
+struct info_Table
+{
+	char				Name[34],
+						AI[4];		// XX if Arc/info file, spaces otherwise
+
+	int					uFields,	// number of usable items in this table
+						nFields,	// number of items in this table
+						ldr;		// length of data record
+
+	long				nRecords,	// number of data records
+						length;		// total length for one data line
+
+	struct info_Field	*Field;		// One per field...
+};
+
+//---------------------------------------------------------
+// [06.06.2006] ESRI E00 Import crash fix, James Flemer
+int CESRI_E00_Import::info_Get_Tables(void)
+{
+	const char *line;
+
+	char				tmp[12], *p;
+	int					i;
+	CSG_String			s;
+	CSG_Table				*pTable;
+	struct info_Table	info;
+
+	//-----------------------------------------------------
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL && strncmp(line, "EOI", 3) )
+	{
+		strncpy(info.Name, line, 32);
+		info.Name[32]	= 0;
+		p	= strchr(info.Name, ' ');
+		if( p != NULL )
+			*p	= 0;
+		p	= strchr(info.Name, '.');
+		if( p == 0 )
+			p	= info.Name;
+		else
+			p++;
+		s	= p;
+
+		strncpy(info.AI	, line + 32,  2);	info.AI[2]	= 0;
+		strncpy(tmp		, line + 34,  4);	tmp[ 4]		= 0;	info.uFields	= atoi(tmp);
+		strncpy(tmp		, line + 38,  4);	tmp[ 4]		= 0;	info.nFields	= atoi(tmp);
+		strncpy(tmp		, line + 42,  4);	tmp[ 4]		= 0;	info.ldr		= atoi(tmp);
+		strncpy(tmp		, line + 46, 11);	tmp[11]		= 0;	info.nRecords	= atol(tmp);
+
+		info.length	= 0;
+		info.Field	= (struct info_Field *)malloc(info.nFields * sizeof(struct info_Field));
+
+		//---------------------------------------------
+		for(i=0; i<info.nFields; i++)
+		{
+			if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+			{
+				sscanf(line, "%16s", info.Field[i].Name);
+				info.Field[i].Size	= atoi(&line[16]);
+				info.Field[i].Type	= atoi(&line[34]);
+			}
+
+			//---------------------------------------------
+			switch( info.Field[i].Type )
+			{
+			case 60:	// float / double
+				info.Field[i].Size = info.Field[i].Size == 4 ? 14 : 24;
+				break;
+
+			case 50:	// short / long
+				info.Field[i].Size = info.Field[i].Size == 2 ?  6 : 11;
+				break;
+
+			case 40:	// float
+				info.Field[i].Size = 14;
+				break;
+
+			case 10:
+				info.Field[i].Size = 8;
+				break;
+
+			default:	// string
+				break;
+			}
+
+			if( i < info.uFields )
+			{
+				info.length			+= info.Field[i].Size;
+			}
+
+			if( i == 0 )
+			{
+				info.Field[i].Position	= 0;
+			}
+			else
+			{
+				info.Field[i].Position	= info.Field[i-1].Position + info.Field[i-1].Size;
+			}
+		}
+
+		//---------------------------------------------
+		pTable	= NULL;
+
+		if     ( !s.CmpNoCase(SG_T("aat")) && pAAT == NULL )
+		{
+			pTable	= pAAT	= info_Get_Table(info);
+		}
+		else if( !s.CmpNoCase(SG_T("pat")) && pPAT == NULL )
+		{
+			pTable	= pPAT	= info_Get_Table(info);
+		}
+	//	else if( !s.CmpNoCase("vat") )		// value table (grid)
+	//	else if( !s.CmpNoCase("bnd") )		// coverage boundaries
+	//	else if( !s.CmpNoCase("tic") )		// tick marks
+	//	else if( !s.CmpNoCase("sta") )		// stats on grid
+	//	else if( !s.CmpNoCase("lut") )		// look-up table
+	//	else if( !s.CmpNoCase("acode") )	// arc attributes
+	//	else if( !s.CmpNoCase("pcode") )	// polygon attributes
+	//	else								// non graphic tables
+		else	// come on, let's get every table we can get...
+		{
+			pTable	= info_Get_Table(info);
+		}
+
+		//-------------------------------------------------
+		free(info.Field);
+
+		if( pTable )
+		{
+			CSG_Table_Record	*pRecord;
+			CSG_Shape			*pShape;
+			CSG_Shapes			*pBND, *pTIC;
+
+			if     ( !s.CmpNoCase(SG_T("bnd")) )	// coverage boundaries
+			{
+				pBND	= SG_Create_Shapes(SHAPE_TYPE_Polygon, SG_T("Boundary"));
+				pBND->Add_Field("XMIN", SG_DATATYPE_Double);
+				pBND->Add_Field("YMIN", SG_DATATYPE_Double);
+				pBND->Add_Field("XMAX", SG_DATATYPE_Double);
+				pBND->Add_Field("YMAX", SG_DATATYPE_Double);
+				pRecord	= pTable->Get_Record(0);
+				pShape	= pBND->Add_Shape();
+				pShape->Set_Value(0, pRecord->asDouble(0));
+				pShape->Set_Value(1, pRecord->asDouble(1));
+				pShape->Set_Value(2, pRecord->asDouble(2));
+				pShape->Set_Value(3, pRecord->asDouble(3));
+				pShape->Add_Point(pRecord->asDouble(0), pRecord->asDouble(1));
+				pShape->Add_Point(pRecord->asDouble(0), pRecord->asDouble(3));
+				pShape->Add_Point(pRecord->asDouble(2), pRecord->asDouble(3));
+				pShape->Add_Point(pRecord->asDouble(2), pRecord->asDouble(1));
+				Parameters("BND")->Set_Value(pBND);
+				delete(pTable);
+			}
+			else if( !s.CmpNoCase(SG_T("tic")) )	// tick marks
+			{
+				pTIC	= SG_Create_Shapes(SHAPE_TYPE_Point, SG_T("Tick Points"));
+				pTIC->Add_Field("ID", SG_DATATYPE_Int);
+				pTIC->Add_Field("X" , SG_DATATYPE_Double);
+				pTIC->Add_Field("Y" , SG_DATATYPE_Double);
+				for(i=0; i<pTable->Get_Record_Count(); i++)
+				{
+					pRecord	= pTable->Get_Record(i);
+					pShape	= pTIC->Add_Shape();
+					pShape->Set_Value(0, pRecord->asInt   (0));
+					pShape->Set_Value(1, pRecord->asDouble(1));
+					pShape->Set_Value(2, pRecord->asDouble(2));
+					pShape->Add_Point(pRecord->asDouble(1), pRecord->asDouble(2));
+				}
+				Parameters("TIC")->Set_Value(pTIC);
+				delete(pTable);
+			}
+			else
+			{
+				Parameters("TABLE")->Set_Value(pTable);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	// 0 if none, 1 if AAT, 2 if PAT, 3 if both
+	return( pPAT ? (pAAT ? 3 : 2) : (pAAT ? 1 : 0) );
+}
+
+//---------------------------------------------------------
+CSG_Table * CESRI_E00_Import::info_Get_Table(struct info_Table info)
+{
+	char			*buffer_record, *buffer_item;
+	int				iRecord, iField;
+	CSG_Table			*pTable;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	Process_Set_Text(CSG_String(info.Name));
+
+	buffer_record	= (char *)malloc(info.length + 3);
+	buffer_item		= (char *)malloc(info.length + 3);
+
+	pTable			= SG_Create_Table();
+	pTable->Set_Name(CSG_String(info.Name));
+
+	//-----------------------------------------------------
+	for(iField=0; iField<info.uFields; iField++)
+	{
+		switch( info.Field[iField].Type )
+		{
+		case 60:	// float / double
+			pTable->Add_Field(info.Field[iField].Name, SG_DATATYPE_Double);
+			break;
+
+		case 50:	// short / long
+			pTable->Add_Field(info.Field[iField].Name, SG_DATATYPE_Int);
+			break;
+
+		case 40:	// float
+			pTable->Add_Field(info.Field[iField].Name, SG_DATATYPE_Double);
+			break;
+
+		case 10:	// short
+			pTable->Add_Field(info.Field[iField].Name, SG_DATATYPE_Int);
+			break;
+
+		default:	// string
+			pTable->Add_Field(info.Field[iField].Name, SG_DATATYPE_String);
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iRecord=0; iRecord<info.nRecords && Set_Progress(iRecord, info.nRecords); iRecord++)
+	{
+		info_Get_Record(buffer_record, info.length);
+
+		pRecord	= pTable->Add_Record();
+
+		for(iField=0; iField<info.uFields; iField++)
+		{
+			strncpy(buffer_item, &buffer_record[info.Field[iField].Position], info.Field[iField].Size);
+			buffer_item[info.Field[iField].Size] = 0;
+
+			switch( pTable->Get_Field_Type(iField) )
+			{
+			default:
+				pRecord->Set_Value(iField, atof(buffer_item));
+				break;
+
+			case SG_DATATYPE_Int:
+				pRecord->Set_Value(iField, atoi(buffer_item));
+				break;
+
+			case SG_DATATYPE_String:
+				pRecord->Set_Value(iField, CSG_String(buffer_item));
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	free(buffer_record);
+	free(buffer_item);
+
+	return( pTable );
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::info_Skip_Table(struct info_Table info)
+{
+	char	*buffer_record;
+	int		iRecord;
+
+	buffer_record	= (char *)malloc(info.length + 3);
+
+	for(iRecord=0; iRecord<info.nRecords; iRecord++)
+	{
+		info_Get_Record(buffer_record, info.length);
+	}
+
+	free(buffer_record);
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::info_Get_Record(char *buffer, int buffer_length)
+{
+	const char *line;
+
+	char	*p;
+	int		l;
+
+	//-----------------------------------------------------
+	p	= buffer;
+	l	= 0;
+
+	//-----------------------------------------------------
+	if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		strncpy(buffer, line, buffer_length < 84 ? buffer_length : 84);
+
+		while( l < buffer_length )
+		{
+			if( *p =='\r' || *p == '\n' || *p == 0 )
+			{
+				while( (l % 80 || p == buffer) && l < buffer_length )
+				{
+					l++;
+					*p++	= ' ';
+				}
+
+				if( l == buffer_length )
+				{
+					break;
+				}
+				else if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+				{
+					strncpy(p, line, buffer_length - l < 84 ? buffer_length - l : 84);
+
+					if( *p =='\r' || *p == '\n' || *p == 0 )	// if empty line
+					{
+						l++;
+						*p++	= ' ';
+						*p		= 0;
+					}
+				}
+			}
+			else
+			{
+				l++;
+				p++;
+			}
+		}
+
+		*p	= 0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Skips							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CESRI_E00_Import::Assign_Attributes(CSG_Shapes *pShapes)
+{
+	int				iShape, iRecord, iField, oField, id;
+	CSG_Table_Record	*pRec;
+	CSG_Shape			*pShape;
+
+	if( pShapes && pShapes->Get_Field_Count() > 0 && pPAT && pPAT->Get_Field_Count() > 2 )
+	{
+		Process_Set_Text(_TL("Assign attributes to shapes..."));
+
+		oField	= pShapes->Get_Field_Count();
+
+		for(iField=0; iField<pPAT->Get_Field_Count(); iField++)
+		{
+			pShapes->Add_Field(pPAT->Get_Field_Name(iField), pPAT->Get_Field_Type(iField));
+		}
+
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= pShapes->Get_Shape(iShape);
+			id		= pShape->asInt(0);
+
+			for(iRecord=0; iRecord<pPAT->Get_Record_Count(); iRecord++)
+			{
+				pRec	= pPAT->Get_Record(iRecord);
+
+				if( id == pRec->asInt(2) )
+				{
+					for(iField=0; iField<pPAT->Get_Field_Count(); iField++)
+					{
+						switch( pPAT->Get_Field_Type(iField) )
+						{
+						case SG_DATATYPE_String:
+							pShape->Set_Value(oField + iField, pRec->asString(iField));
+							break;
+
+						default:
+							pShape->Set_Value(oField + iField, pRec->asDouble(iField));
+							break;
+						}
+					}
+
+					break;
+				}
+			}
+
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Skips							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip(char *end)
+{
+	const char	*line;
+
+	int		l	= strlen(end);
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL && strncmp(line, end, l) );
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip_dat(void)
+{
+	const char	*line;
+
+	int		i	= 0;
+	
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL && i != -1 )
+	{
+		sscanf(line, "%d", &i);
+	}
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip_msk(void)
+{
+	const char	*line;
+
+	double	xmin, ymin, xmax, ymax, res, sk;
+	long	xsize, ysize, nskip;
+
+	if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf(line, "%lf %lf %lf", &xmin, &ymin, &xmax);
+
+		if( (line = E00ReadNextLine(hReadPtr)) != NULL )
+		{
+			sscanf(line, "%lf %lf %ld %ld", &ymax, &res, &xsize, &ysize);
+
+			sk		= ((ymax - ymin) / res) * ((xmax - xmin) / res) / 32.0;
+			nskip	= (long)ceil(sk / 7.0);
+
+			while( nskip-- )
+			{
+				E00ReadNextLine(hReadPtr);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip_arc(int prec)
+{
+	const char	*line;
+
+	int		i, covnum, nPoints;
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf(line, "%d %*d %*d %*d %*d %*d %d", &covnum, &nPoints);
+
+		if( covnum == -1 )
+			break;
+
+		if( prec == 0 )
+			nPoints	= (nPoints + 1) / 2;	// number of coordinate lines
+
+		for(i=0; i<nPoints; i++)
+		{
+			E00ReadNextLine(hReadPtr);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip_lab(int prec)
+{
+	const char	*line;
+
+	long	covid;
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf(line, "%ld", &covid);
+
+		if( covid == -1 )
+			break;
+
+		E00ReadNextLine(hReadPtr);
+
+		if( prec )	// two lines of coordinates in double precision
+			E00ReadNextLine(hReadPtr);
+	}
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip_pal(int prec)
+{
+	const char	*line;
+
+	int		i, narcs;
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf(line, "%d", &narcs);
+
+		if( prec )	// two lines of coordinates in double precision
+			E00ReadNextLine(hReadPtr);
+
+		if( narcs == -1 )
+			break;
+
+		for(i=(narcs+1)/2; i; i--)
+			E00ReadNextLine(hReadPtr);
+	}
+}
+
+//---------------------------------------------------------
+void CESRI_E00_Import::skip_txt(int prec)
+{
+	const char	*line;
+
+	int		i, n, nskip;
+
+	nskip	= prec ? 7 : 5;
+
+	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
+	{
+		sscanf( line, "%d", &n);
+
+		if( n == -1 )
+			break;
+
+		for(i=0; i<nskip; i++)
+			E00ReadNextLine(hReadPtr);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/ESRI_E00_Import.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      ESRI_E00.h                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						ESRI_E00.h						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ESRI_E00_H
+#define HEADER_INCLUDED__ESRI_E00_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include "./e00compr/e00compr.h"
+
+//---------------------------------------------------------
+class CESRI_E00_Import : public CSG_Module
+{
+public:
+	CESRI_E00_Import(void);
+	virtual ~CESRI_E00_Import(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	E00ReadPtr				hReadPtr;
+
+	CSG_String				e00_Name;
+
+	CSG_Table				*pPAT, *pAAT;
+
+
+	bool					Open(const SG_Char *FileName);
+	bool					Load(void);
+
+	bool					E00GotoLine(int iLine);
+
+	CSG_Grid *				getraster	(int prec, double scale);
+	CSG_Shapes *			getarcs		(int prec, double scale, TSG_Shape_Type &shape_type);
+	CSG_Shapes *			getlabels	(int prec, double scale);
+	CSG_Shapes *			getsites	(int prec, double scale);
+	double					getproj		(void);
+
+	int						info_Get_Tables	(void);
+	CSG_Table *				info_Get_Table	(struct info_Table info);
+	void					info_Skip_Table	(struct info_Table info);
+	void					info_Get_Record	(char *buffer, int buffer_length);
+
+	bool					Assign_Attributes(CSG_Shapes *pShapes);
+
+	CSG_Shapes *			Arcs2Polygons(CSG_Shapes *pArcs);
+	void					Arcs2Polygon (CSG_Shapes *pArcs, CSG_Shapes *pPolygons, int id);
+
+	void					skip	(char *end);
+	void					skip_dat(void);
+	void					skip_msk(void);
+	void					skip_arc(int prec);
+	void					skip_lab(int prec);
+	void					skip_pal(int prec);
+	void					skip_txt(int prec);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__ESRI_E00_H

Added: packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/esri_e00/io_esri_e00/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      io_esri_e00                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_esri_e00_H
+#define HEADER_INCLUDED__io_esri_e00_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_esri_e00_EXPORTS
+	#define	io_esri_e00_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_esri_e00_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_esri_e00_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Grid_IO_GDAL                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                        Author                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     author at email.de                        //
+//                                                       //
+//    contact:    Author                                 //
+//                Sesame Street 7                        //
+//                12345 Metropolis                       //
+//                Nirwana                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import/Export - GDAL/OGR") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2008" ));
+
+	case MLB_INFO_Description:
+		return( _TL("SAGA interface to Frank Warmerdam's Geospatial Data Abstraction Library (GDAL).") );
+
+	case MLB_INFO_Version:
+		return( SG_T("2.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|GDAL/OGR") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "gdal_import.h"
+#include "gdal_export.h"
+#include "gdal_export_geotiff.h"
+
+#include "ogr_import.h"
+#include "ogr_export.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CGDAL_Import );
+	case 1:		return( new CGDAL_Export );
+	case 2:		return( new CGDAL_Export_GeoTIFF );
+
+	case 3:		return( new COGR_Import );
+	case 4:		return( new COGR_Export );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,78 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Library Grid_IO_GDAL                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                        Author                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     author at email.de                        //
+//                                                       //
+//    contact:    Author                                 //
+//                Sesame Street. 7                       //
+//                12345 Metropolis                       //
+//                Nirwana                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_grid_gdal_H
+#define HEADER_INCLUDED__io_grid_gdal_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_grid_gdal_EXPORTS
+	#define	io_grid_gdal_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_grid_gdal_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_grid_gdal_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,311 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   gdal_driver.cpp                     //
+//                                                       //
+//            Copyright (C) 2007 by O. Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "gdal_driver.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGDAL_Driver	g_GDAL_Driver;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGDAL_Driver::CGDAL_Driver(void)
+{
+	GDALAllRegister();
+
+	pManager	= GetGDALDriverManager();
+
+	//-----------------------------------------------------
+	for(int i=0; i<Get_Count(); i++)
+    {
+    }
+}
+
+//---------------------------------------------------------
+CGDAL_Driver::~CGDAL_Driver(void)
+{
+	GDALDestroyDriverManager();	
+}
+
+//---------------------------------------------------------
+TSG_Data_Type CGDAL_Driver::Get_Grid_Type(GDALDataType Type)
+{
+	switch( Type )
+	{
+	case GDT_Byte: 		return( SG_DATATYPE_Byte );			// Eight bit unsigned integer
+	case GDT_UInt16:	return( SG_DATATYPE_Word );			// Sixteen bit unsigned integer
+	case GDT_Int16:		return( SG_DATATYPE_Short );		// Sixteen bit signed integer
+	case GDT_UInt32:	return( SG_DATATYPE_DWord );		// Thirty two bit unsigned integer
+	case GDT_Int32: 	return( SG_DATATYPE_Int );			// Thirty two bit signed integer
+	case GDT_Float32: 	return( SG_DATATYPE_Float );		// Thirty two bit floating point
+	case GDT_Float64: 	return( SG_DATATYPE_Double );		// Sixty four bit floating point
+
+	case GDT_CInt16: 	return( SG_DATATYPE_Undefined );	// Complex Int16
+	case GDT_CInt32: 	return( SG_DATATYPE_Undefined );	// Complex Int32
+	case GDT_CFloat32: 	return( SG_DATATYPE_Undefined );	// Complex Float32
+	case GDT_CFloat64: 	return( SG_DATATYPE_Undefined );	// Complex Float64
+
+	default:			return( SG_DATATYPE_Undefined );
+	}
+}
+
+//---------------------------------------------------------
+GDALDataType CGDAL_Driver::Get_GDAL_Type(TSG_Data_Type Type)
+{
+	switch( Type )
+	{
+	case SG_DATATYPE_Bit: 		return( GDT_Byte );			// Eight bit unsigned integer
+	case SG_DATATYPE_Byte: 		return( GDT_Byte );			// Eight bit unsigned integer
+	case SG_DATATYPE_Char: 		return( GDT_Byte );			// Eight bit unsigned integer
+	case SG_DATATYPE_Word:		return( GDT_UInt16 );		// Sixteen bit unsigned integer
+	case SG_DATATYPE_Short:		return( GDT_Int16 );		// Sixteen bit signed integer
+	case SG_DATATYPE_DWord:		return( GDT_UInt32 );		// Thirty two bit unsigned integer
+	case SG_DATATYPE_Int: 		return( GDT_Int32 );		// Thirty two bit signed integer
+	case SG_DATATYPE_Float: 	return( GDT_Float32 );		// Thirty two bit floating point
+	case SG_DATATYPE_Double: 	return( GDT_Float64 );		// Sixty four bit floating point
+
+	default:					return( GDT_Float64 );
+	}
+}
+
+//---------------------------------------------------------
+GDALDataType CGDAL_Driver::Get_GDAL_Type(CSG_Parameter_Grid_List *pGrids)
+{
+	TSG_Data_Type	Type	= SG_DATATYPE_Byte;
+
+	if( pGrids )
+	{
+		for(int i=0; i<pGrids->Get_Count(); i++)
+		{
+			if( SG_Data_Type_Get_Size(Type) <= SG_Data_Type_Get_Size(pGrids->asGrid(i)->Get_Type()) )
+			{
+				Type	= pGrids->asGrid(i)->Get_Type();
+			}
+		}
+	}
+
+	return( Get_GDAL_Type(Type) );
+}
+
+//---------------------------------------------------------
+bool CGDAL_Driver::Set_Transform(GDALDataset *pDataset, CSG_Grid_System *pSystem)
+{
+	if( pDataset && pSystem )
+	{
+		double	Transform[6]	=
+		{
+			pSystem->Get_XMin() - 0.5 * pSystem->Get_Cellsize(), pSystem->Get_Cellsize(), 0.0,
+			pSystem->Get_YMax() + 0.5 * pSystem->Get_Cellsize(), 0.0, -pSystem->Get_Cellsize()
+		};
+
+		pDataset->SetGeoTransform(Transform);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGDAL_System::CGDAL_System(void)
+{
+	m_pDataSet	= NULL;
+}
+
+//---------------------------------------------------------
+CGDAL_System::CGDAL_System(const CSG_String &File_Name, int ioAccess)
+{
+	m_pDataSet	= NULL;
+
+	Create(File_Name, ioAccess);
+}
+
+//---------------------------------------------------------
+CGDAL_System::~CGDAL_System(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool CGDAL_System::Create(const CSG_String &File_Name, int ioAccess)
+{
+	Destroy();
+
+	//-----------------------------------------------------
+	if( ioAccess == IO_READ )
+	{
+		if( (m_pDataSet = (GDALDataset *)GDALOpen(SG_STR_SGTOMB(File_Name), GA_ReadOnly)) != NULL )
+		{
+			if( m_pDataSet->GetGeoTransform(m_Transform) != CE_None )
+			{
+				m_Transform[0]	=  0.0;
+				m_Transform[1]	=  1.0;
+				m_Transform[2]	=  0.0;
+				m_Transform[3]	=  0.0;
+				m_Transform[4]	=  0.0;
+				m_Transform[5]	= -1.0;
+			}
+
+			m_Access	= IO_READ;
+
+			m_NX		= m_pDataSet->GetRasterXSize();
+			m_NY		= m_pDataSet->GetRasterYSize();
+
+			m_DX		= m_Transform[1];
+			m_DY		= m_Transform[5];
+
+			to_World(0.5, m_NY - 0.5, m_xMin, m_yMin);
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( ioAccess == IO_WRITE )
+	{
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGDAL_System::Destroy(void)
+{
+	if( m_pDataSet )
+	{
+		GDALClose(m_pDataSet);
+
+		m_pDataSet	= NULL;
+	}
+
+	m_Access	= IO_CLOSED;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CGDAL_System::Read_Band(int i)
+{
+	GDALRasterBand	*pBand;
+
+	if( is_Reading() && (pBand = m_pDataSet->GetRasterBand(i + 1)) != NULL )
+	{
+		CSG_Grid	*pGrid	= SG_Create_Grid(g_GDAL_Driver.Get_Grid_Type(pBand->GetRasterDataType()),
+			Get_NX(), Get_NY(), Get_DX(), Get_xMin(), Get_yMin()
+		);
+
+		pGrid->Set_Name			(SG_STR_MBTOSG(pBand->GetMetadataItem(GDAL_DMD_LONGNAME)));
+		pGrid->Set_Description	(SG_STR_MBTOSG(pBand->GetMetadataItem(GDAL_DMD_LONGNAME)));
+		pGrid->Set_Unit			(SG_STR_MBTOSG(pBand->GetUnitType()));
+		pGrid->Set_NoData_Value	(pBand->GetNoDataValue());
+		pGrid->Set_ZFactor		(pBand->GetScale());
+
+		//-------------------------------------------------
+		double		zMin, *zLine;
+
+		zLine	= (double *)SG_Malloc(Get_NX() * sizeof(double));
+		zMin	= pBand->GetOffset();
+
+		for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+		{
+			if( pBand->RasterIO(GF_Read, 0, y, Get_NX(), 1, zLine, Get_NX(), 1, GDT_Float64, 0, 0) == CE_None )
+			{
+				for(int x=0; x<Get_NX(); x++)
+				{
+				//	double	NaN	= 0.0;	NaN	= -1.0 / NaN;	if( NaN == zLine[x] )	pGrid->Set_NoData(x, System.Get_NY() - 1 - y); else
+
+					pGrid->Set_Value (x, Get_NY() - 1 - y, zMin + zLine[x]);
+				}
+			}
+		}
+
+		SG_Free(zLine);
+
+		return( pGrid );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_driver.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,190 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    gdal_driver.h                      //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__gdal_driver_H
+#define HEADER_INCLUDED__gdal_driver_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include <gdal_priv.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGDAL_Driver
+{
+public:
+	CGDAL_Driver(void);
+	virtual ~CGDAL_Driver(void);
+
+	int						Get_Count		(void)				{	return( pManager->GetDriverCount() );	}
+	const char *			Get_Name		(int Index)			{	return( Get_Driver(Index)->GetMetadataItem(GDAL_DMD_LONGNAME) );	}
+	const char *			Get_Description	(int Index)			{	return( Get_Driver(Index)->GetDescription() );	}
+	GDALDriver *			Get_Driver		(int Index)			{	return( (GDALDriver *)GDALGetDriver(Index) );	}
+	GDALDriver *			Get_Driver		(const char *Name)	{	return( (GDALDriver *)GDALGetDriverByName(Name) );	}
+
+
+	static TSG_Data_Type	Get_Grid_Type	(GDALDataType  Type);
+	static GDALDataType		Get_GDAL_Type	(TSG_Data_Type Type);
+	static GDALDataType		Get_GDAL_Type	(CSG_Parameter_Grid_List *pGrids);
+	static bool				Set_Transform	(GDALDataset *pDataset, CSG_Grid_System *pSystem);
+
+
+private:
+
+	GDALDriverManager		*pManager;
+
+};
+
+//---------------------------------------------------------
+#define IO_CLOSED		0x00
+#define IO_READ			0x01
+#define IO_WRITE		0x02
+#define IO_READWRITE	(IO_READ|IO_WRITE)
+
+//---------------------------------------------------------
+class CGDAL_System
+{
+public:
+	CGDAL_System(void);
+	CGDAL_System(const CSG_String &File_Name, int ioAccess = IO_READ);
+	virtual ~CGDAL_System(void);
+
+	bool					Create			(const CSG_String &File_Name, int ioAccess = IO_READ);
+	bool					Destroy			(void);
+
+	bool					is_Okay			(void)	{	return( m_pDataSet != NULL );	}
+	bool					is_Reading		(void)	{	return( m_pDataSet != NULL && m_Access & IO_READ );	 }
+	bool					is_Writing		(void)	{	return( m_pDataSet != NULL && m_Access & IO_WRITE );	}
+
+	int						Get_NX			(void)	{	return( m_NX );		}
+	int						Get_NY			(void)	{	return( m_NY );		}
+	double					Get_xMin		(void)	{	return( m_xMin );	}
+	double					Get_yMin		(void)	{	return( m_yMin );	}
+	double					Get_DX			(void)	{	return( m_DX );		}
+	double					Get_DY			(void)	{	return( m_DY );		}
+	double					Get_Transform	(int i)	{	return( m_Transform[i] );	}
+
+	GDALDriver *			Get_Driver		(void)	{	return( m_pDataSet ? m_pDataSet->GetDriver     () : NULL );	}
+	const char *			Get_Projection	(void)	{	return( m_pDataSet && m_pDataSet->GetProjectionRef() ? m_pDataSet->GetProjectionRef() : NULL );	}
+
+	int						Get_Count		(void)	{	return( m_pDataSet ? m_pDataSet->GetRasterCount() : 0    );	}
+	CSG_Grid *				Read_Band		(int i);
+
+	GDALDataset *			Get_DataSet		(void)	{	return( m_pDataSet );	}
+
+
+private:
+
+	int						m_Access, m_NX, m_NY;
+
+	double					m_xMin, m_yMin, m_DX, m_DY, m_Transform[6];
+
+	GDALDataset				*m_pDataSet;
+
+
+public:
+
+	bool					to_World		(double x, double y, double &xWorld, double &yWorld)
+	{
+		if( m_pDataSet )
+		{
+			xWorld	= m_Transform[0] + x * m_Transform[1] + y * m_Transform[2];
+			yWorld	= m_Transform[3] + y * m_Transform[4] + y * m_Transform[5];
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	bool					to_Grid			(int x, int y, CSG_Grid *pGrid, int &xGrid, int &yGrid)
+	{
+		if( m_pDataSet && pGrid )
+		{
+			double	xWorld, yWorld;
+
+			to_World(x, y, xWorld, yWorld);
+
+			xGrid	= (int)(0.5 + (xWorld - pGrid->Get_XMin()) / pGrid->Get_Cellsize());
+			yGrid	= (int)(0.5 + (yWorld - pGrid->Get_YMin()) / pGrid->Get_Cellsize());
+
+			return( pGrid->is_InGrid(xGrid, yGrid, false) );
+		}
+
+		return( false );
+	}
+
+};
+
+//---------------------------------------------------------
+extern CGDAL_Driver	g_GDAL_Driver;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__gdal_driver_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,242 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   gdal_export.cpp                     //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "gdal_export.h"
+
+#include <cpl_string.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGDAL_Export::CGDAL_Export(void)
+{
+	Set_Name	(_TL("GDAL: Export Raster"));
+
+	Set_Author	(SG_T("(c) 2007 by O.Conrad"));
+
+	CSG_String	Description, Formats;
+
+	Description	= _TW(
+		"The \"GDAL Raster Export\" module exports one or more grids to various file formats using the "
+		"\"Geospatial Data Abstraction Library\" (GDAL) by Frank Warmerdam. "
+		"For more information have a look at the GDAL homepage:\n"
+		"  <a target=\"_blank\" href=\"http://www.gdal.org/\">"
+		"  http://www.gdal.org</a>\n"
+		"\n"
+		"Following raster formats are currently supported:\n"
+		"<table border=\"1\"><tr><th>ID</th><th>Name</th></tr>\n"
+	);
+
+	for(int i=0; i<g_GDAL_Driver.Get_Count(); i++)
+    {
+		if( CSLFetchBoolean(g_GDAL_Driver.Get_Driver(i)->GetMetadata(), GDAL_DCAP_CREATE, false) )
+		{
+			Description	+= CSG_String::Format(SG_T("<tr><td>%s</td><td>%s</td></tr>\n"),
+				SG_STR_MBTOSG(g_GDAL_Driver.Get_Description(i)),
+				SG_STR_MBTOSG(g_GDAL_Driver.Get_Name(i))
+			);
+
+			Formats		+= CSG_String::Format(SG_T("%s|"), SG_STR_MBTOSG(g_GDAL_Driver.Get_Name(i)));
+
+			m_DriverNames.Add(SG_STR_MBTOSG(g_GDAL_Driver.Get_Description(i)));
+		}
+    }
+
+	Description	+= SG_T("</table>");
+
+	Set_Description(Description);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL, "GRIDS"	, _TL("Grid(s)"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL, "FILE"	, _TL("File"),
+		_TL(""),
+		NULL, NULL, true
+	);
+
+	Parameters.Add_Choice(
+		NULL, "FORMAT"	, _TL("Format"),
+		_TL(""),
+		Formats
+	);
+
+	Parameters.Add_Choice(
+		NULL, "TYPE"	, _TL("Data Type"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("match input data"),
+			_TL("8 bit unsigned integer"),
+			_TL("16 bit unsigned integer"),
+			_TL("16 bit signed integer"),
+			_TL("32 bit unsigned integer"),
+			_TL("32 bit signed integer"),
+			_TL("32 bit floating point"),
+			_TL("64 bit floating point")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CGDAL_Export::~CGDAL_Export(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGDAL_Export::On_Execute(void)
+{
+	char					**pOptions	= NULL;
+	int						x, y, n;
+	double					*zLine;
+	CSG_String				File_Name;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_Grid				*pGrid;
+	GDALDataType			gdal_Type;
+	GDALDriver				*pDriver;
+	GDALDataset				*pDataset;
+	GDALRasterBand			*pBand;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("GRIDS")	->asGridList();
+	File_Name	= Parameters("FILE")	->asString();
+
+	//-----------------------------------------------------
+	switch( Parameters("TYPE")->asInt() )
+	{
+	default:
+	case 0:	gdal_Type	= g_GDAL_Driver.Get_GDAL_Type(pGrids);	break;	// match input data
+	case 1:	gdal_Type	= GDT_Byte;		break;	// Eight bit unsigned integer
+	case 2:	gdal_Type	= GDT_UInt16;	break;	// Sixteen bit unsigned integer
+	case 3:	gdal_Type	= GDT_Int16;	break;	// Sixteen bit signed integer
+	case 4:	gdal_Type	= GDT_UInt32;	break;	// Thirty two bit unsigned integer
+	case 5:	gdal_Type	= GDT_Int32;	break;	// Thirty two bit signed integer
+	case 6:	gdal_Type	= GDT_Float32;	break;	// Thirty two bit floating point
+	case 7:	gdal_Type	= GDT_Float64;	break;	// Sixty four bit floating point
+	}
+
+	//-----------------------------------------------------
+	if( (pDriver = g_GDAL_Driver.Get_Driver(SG_STR_SGTOMB(m_DriverNames[Parameters("FORMAT")->asInt()]))) == NULL )
+	{
+		Message_Add(_TL("Driver not found."));
+	}
+	else if( CSLFetchBoolean(pDriver->GetMetadata(), GDAL_DCAP_CREATE, false) == false )
+	{
+		Message_Add(_TL("Driver does not support file creation."));
+	}
+	else if( (pDataset = pDriver->Create(File_Name.b_str(), Get_NX(), Get_NY(), pGrids->Get_Count(), gdal_Type, pOptions)) == NULL )
+	{
+		Message_Add(_TL("Could not create dataset."));
+	}
+	else
+	{
+		g_GDAL_Driver.Set_Transform(pDataset, Get_System());
+
+		zLine	= (double *)SG_Malloc(Get_NX() * sizeof(double));
+
+		for(n=0; n<pGrids->Get_Count(); n++)
+		{
+			Process_Set_Text(CSG_String::Format(SG_T("%s %d"), _TL("Band"), n + 1));
+
+			pGrid	= pGrids->asGrid(n);
+			pBand	= pDataset->GetRasterBand(n + 1);
+
+			for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					zLine[x]	= pGrid->asDouble(x, Get_NY() - 1 - y);
+				}
+
+				pBand->RasterIO(GF_Write, 0, y, Get_NX(), 1, zLine, Get_NX(), 1, GDT_Float64, 0, 0);
+			}
+		}
+
+		//-------------------------------------------------
+		SG_Free(zLine);
+
+		GDALClose(pDataset);
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,97 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    gdal_export.h                      //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__gdal_export_H
+#define HEADER_INCLUDED__gdal_export_H
+
+//---------------------------------------------------------
+#include "gdal_driver.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGDAL_Export : public CSG_Module_Grid
+{
+public:
+	CGDAL_Export(void);
+	virtual ~CGDAL_Export(void);
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	CSG_Strings					m_DriverNames;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__gdal_export_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,190 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               gdal_export_geotiff.cpp                 //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "gdal_export_geotiff.h"
+
+#include <cpl_string.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGDAL_Export_GeoTIFF::CGDAL_Export_GeoTIFF(void)
+{
+	Set_Name		(_TL("GDAL: Export Raster to GeoTIFF"));
+
+	Set_Author		(SG_T("(c) 2007 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"The \"GDAL GeoTIFF Export\" module exports one or more grids to a Geocoded Tagged Image File Format using the "
+		"\"Geospatial Data Abstraction Library\" (GDAL) by Frank Warmerdam. "
+		"For more information have a look at the GDAL homepage:\n"
+		"  <a target=\"_blank\" href=\"http://www.gdal.org/\">"
+		"  http://www.gdal.org</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL, "GRIDS"	, _TL("Grid(s)"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL, "FILE"	, _TL("File"),
+		_TL(""),
+
+		CSG_String::Format(
+			SG_T("%s|*.tif;*.tiff|%s|*.*"),
+			_TL("TIFF files (*.tif)"),
+			_TL("All Files")
+		), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CGDAL_Export_GeoTIFF::~CGDAL_Export_GeoTIFF(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGDAL_Export_GeoTIFF::On_Execute(void)
+{
+	char					**pOptions	= NULL;
+	int						x, y, n;
+	double					*zLine;
+	CSG_String				File_Name;
+	CSG_Parameter_Grid_List	*pGrids;
+	CSG_Grid				*pGrid;
+	GDALDataType			gdal_Type;
+	GDALDriver				*pDriver;
+	GDALDataset				*pDataset;
+	GDALRasterBand			*pBand;
+
+	//-----------------------------------------------------
+	pGrids		= Parameters("GRIDS")	->asGridList();
+	File_Name	= Parameters("FILE")	->asString();
+
+	//-----------------------------------------------------
+	gdal_Type	= g_GDAL_Driver.Get_GDAL_Type(pGrids);
+
+	//-----------------------------------------------------
+	if( (pDriver = g_GDAL_Driver.Get_Driver("GTiff")) == NULL )
+	{
+		Message_Add(_TL("GeoTIFF driver not found."));
+	}
+	else if( CSLFetchBoolean(pDriver->GetMetadata(), GDAL_DCAP_CREATE, false) == false )
+	{
+		Message_Add(_TL("Driver does not support file creation."));
+	}
+	else if( (pDataset = pDriver->Create(File_Name.b_str(), Get_NX(), Get_NY(), pGrids->Get_Count(), gdal_Type, pOptions)) == NULL )
+	{
+		Message_Add(_TL("Could not create dataset."));
+	}
+	else
+	{
+		g_GDAL_Driver.Set_Transform(pDataset, Get_System());
+
+		zLine	= (double *)SG_Malloc(Get_NX() * sizeof(double));
+
+		for(n=0; n<pGrids->Get_Count(); n++)
+		{
+			Process_Set_Text(CSG_String::Format(SG_T("%s %d"), _TL("Band"), n + 1));
+
+			pGrid	= pGrids->asGrid(n);
+			pBand	= pDataset->GetRasterBand(n + 1);
+
+			for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					zLine[x]	= pGrid->asDouble(x, Get_NY() - 1 - y);
+				}
+
+				pBand->RasterIO(GF_Write, 0, y, Get_NX(), 1, zLine, Get_NX(), 1, GDT_Float64, 0, 0);
+			}
+		}
+
+		//-------------------------------------------------
+		SG_Free(zLine);
+
+		GDALClose(pDataset);
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_export_geotiff.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,92 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                gdal_export_geotiff.h                  //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__gdal_export_geotiff_H
+#define HEADER_INCLUDED__gdal_export_geotiff_H
+
+//---------------------------------------------------------
+#include "gdal_driver.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGDAL_Export_GeoTIFF : public CSG_Module_Grid
+{
+public:
+	CGDAL_Export_GeoTIFF(void);
+	virtual ~CGDAL_Export_GeoTIFF(void);
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__gdal_export_geotiff_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,294 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   gdal_import.cpp                     //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "gdal_import.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGDAL_Import::CGDAL_Import(void)
+{
+	Set_Name	(_TL("GDAL: Import Raster"));
+
+	Set_Author	(SG_T("(c) 2007 by O.Conrad (A.Ringeler)"));
+
+	CSG_String	Description;
+
+	Description	= _TW(
+		"The \"GDAL Raster Import\" module imports grid data from various file formats using the "
+		"\"Geospatial Data Abstraction Library\" (GDAL) by Frank Warmerdam. "
+		"For more information have a look at the GDAL homepage:\n"
+		"  <a target=\"_blank\" href=\"http://www.gdal.org/\">"
+		"  http://www.gdal.org</a>\n"
+		"\n"
+		"Following raster formats are currently supported:\n"
+		"<table border=\"1\"><tr><th>ID</th><th>Name</th></tr>\n"
+	);
+
+	for(int i=0; i<g_GDAL_Driver.Get_Count(); i++)
+    {
+		Description	+= CSG_String::Format(SG_T("<tr><td>%s</td><td>%s</td></tr>\n"),
+			SG_STR_MBTOSG(g_GDAL_Driver.Get_Description(i)),
+			SG_STR_MBTOSG(g_GDAL_Driver.Get_Name(i))
+		);
+    }
+
+	Description	+= SG_T("</table>");
+
+	Set_Description(Description);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, false
+	);
+
+	Parameters.Add_FilePath(
+		NULL, "FILE"	, _TL("File"),
+		_TL("")
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGDAL_Import::On_Execute(void)
+{
+	CSG_String		File_Name;
+	CGDAL_System	System;
+
+	//-----------------------------------------------------
+	File_Name	= Parameters("FILE")	->asString();
+
+	m_pGrids	= Parameters("GRIDS")	->asGridList();
+
+	m_pGrids	->Del_Items();
+
+	//-----------------------------------------------------
+	if( System.Create(File_Name, IO_READ) == false )
+	{
+		Message_Add(_TL("could not find suitable import driver"));
+	}
+	else if( System.Get_Count() <= 0 )
+	{
+		return( Load_Sub(System, SG_File_Get_Name(File_Name, false)) );
+	}
+	else
+    {
+		return( Load(System, SG_File_Get_Name(File_Name, false)) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGDAL_Import::Load_Sub(CGDAL_System &System, const CSG_String &Name)
+{
+	if( System.is_Reading() )
+	{
+		char	**pMetaData	= System.Get_DataSet()->GetMetadata("SUBDATASETS");
+
+		if( CSLCount(pMetaData) > 0 )
+		{
+			int				i, n;
+			CSG_String		s, sID, sName, sDesc;
+			CSG_Parameters	P;
+
+			for(i=0; pMetaData[i]!=NULL; i++)
+			{
+				Message_Add(CSG_String::Format(SG_T("  %s\n"), pMetaData[i]), false);
+
+				s		= pMetaData[i];
+
+				if( s.Contains(SG_T("SUBDATASET_")) && s.Contains(SG_T("_NAME=")) )
+				{
+					sID		= s.AfterFirst('_').BeforeFirst('_');
+					sName	= s.AfterFirst('=');
+					sDesc	= _TL("no description available");
+
+					if( pMetaData[i + 1] != NULL )
+					{
+						s		= pMetaData[i + 1];
+
+						if( s.Contains(SG_T("SUBDATASET_")) && s.Contains(SG_T("_DESC")) )
+						{
+							sDesc	= s.AfterFirst ('=');
+						}
+					}
+
+					P.Add_Value(NULL, sName, sDesc, SG_T(""), PARAMETER_TYPE_Bool, false);
+				}
+			}
+
+			if( Dlg_Parameters(&P, _TL("Select from Subdatasets...")) )
+			{
+				for(i=0, n=0; i<P.Get_Count() && Process_Get_Okay(false); i++)
+				{
+					if( P(i)->asBool() && System.Create(P(i)->Get_Identifier(), IO_READ) && Load(System, P(i)->Get_Name()) )
+					{
+						n++;
+					}
+				}
+
+				return( n > 0 );
+			}
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGDAL_Import::Load(CGDAL_System &System, const CSG_String &Name)
+{
+	//-----------------------------------------------------
+	if( System.is_Reading() )
+	{
+		Message_Add(CSG_String::Format(
+			SG_T("\n%s: %s/%s\n"),
+			_TL("Driver"),
+			System.Get_Driver()->GetDescription(), 
+			System.Get_Driver()->GetMetadataItem(GDAL_DMD_LONGNAME)
+		), false);
+
+		Message_Add(CSG_String::Format(
+			SG_T("%s: x %d, y %d\n%s: %d\n%s x: %.6f, %.6f, %.6f\n%s y: %.6f, %.6f, %.6f"),
+			_TL("Cells")			, System.Get_NX(), System.Get_NY(),
+			_TL("Bands")			, System.Get_Count(),
+			_TL("Transformation")	, System.Get_Transform(0), System.Get_Transform(1), System.Get_Transform(2),
+			_TL("Transformation")	, System.Get_Transform(3), System.Get_Transform(4), System.Get_Transform(5)
+		), false);
+
+		if( System.Get_Projection() != NULL )
+		{
+			CSG_String	s(System.Get_Projection());
+
+			s.Replace(SG_T("[")  , SG_T("\t"));
+			s.Replace(SG_T("]],"), SG_T("\n"));
+			s.Replace(SG_T("]]") , SG_T("\n"));
+			s.Replace(SG_T("],") , SG_T("\n"));
+			s.Replace(SG_T(",")  , SG_T("\t"));
+
+			Message_Add(CSG_String::Format(
+				SG_T("\n%s:\n%s"),
+				_TL("Projection"),
+				s.c_str()
+			), false);
+		}
+
+		//-------------------------------------------------
+		int			i, n;
+		CSG_Grid	*pGrid;
+
+		for(i=0, n=0; i<System.Get_Count(); i++)
+		{
+			if( (pGrid = System.Read_Band(i)) != NULL )
+			{
+				n++;
+
+				pGrid->Set_Name(System.Get_Count() > 1
+					? CSG_String::Format(SG_T("%s [%02d]"), Name.c_str(), i + 1).c_str()
+					: Name.c_str()
+				);
+
+				m_pGrids->Add_Item(pGrid);
+
+				DataObject_Add			(pGrid);
+				DataObject_Set_Colors	(pGrid, CSG_Colors(100, SG_COLORS_BLACK_WHITE, false));
+			}
+        }
+
+		//-------------------------------------------------
+		return( n > 0 );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/gdal_import.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    gdal_import.h                      //
+//                                                       //
+//            Copyright (C) 2007 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__gdal_import_H
+#define HEADER_INCLUDED__gdal_import_H
+
+//---------------------------------------------------------
+#include "gdal_driver.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGDAL_Import : public CSG_Module
+{
+public:
+	CGDAL_Import(void);
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	CSG_Parameter_Grid_List		*m_pGrids;
+
+
+	bool						Load_Sub		(CGDAL_System &System, const CSG_String &Name);
+	bool						Load			(CGDAL_System &System, const CSG_String &Name);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__gdal_import_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,687 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    ogr_driver.cpp                     //
+//                                                       //
+//            Copyright (C) 2008 by O. Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ogr_driver.h"
+
+#include <ogr_core.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+COGR_Driver		g_OGR_Driver;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+COGR_Driver::COGR_Driver(void)
+{
+	OGRRegisterAll();
+
+	m_pManager	= OGRSFDriverRegistrar::GetRegistrar();
+}
+
+//---------------------------------------------------------
+COGR_Driver::~COGR_Driver(void)
+{
+//	OGRCleanupAll();	
+}
+
+//---------------------------------------------------------
+OGRSFDriver * COGR_Driver::Get_Driver(const CSG_String &Name)
+{
+	return( m_pManager ? m_pManager->GetDriverByName(SG_STR_SGTOMB(Name)) : NULL );
+}
+
+//---------------------------------------------------------
+bool COGR_Driver::Can_Read(int iDriver)
+{
+	return( Get_Driver(iDriver) != NULL );
+}
+
+bool COGR_Driver::Can_Write(int iDriver)
+{
+	return( Get_Driver(iDriver) != NULL );//&& Get_Driver(iDriver)->TestCapability(ODrCCreateDataSource) );
+}
+
+//---------------------------------------------------------
+CSG_String COGR_Driver::Get_Description(int iDriver)
+{
+	OGRSFDriver	*pDriver	= m_pManager->GetDriver(iDriver);
+	CSG_String	s;
+
+	s	+= pDriver->TestCapability(ODrCCreateDataSource)	? SG_T("\n[x] ") : SG_T("\n[ ] ");
+	s	+= _TL("create data source");
+
+	s	+= pDriver->TestCapability(ODrCDeleteDataSource)	? SG_T("\n[x] ") : SG_T("\n[ ] ");
+	s	+= _TL("delete data source");
+
+/*	s	+= pDriver->TestCapability(ODsCCreateLayer)			? SG_T("\n[x]") : SG_T("\n[ ]");
+	s	+= _TL("create layer");
+
+	s	+= pDriver->TestCapability(ODsCDeleteLayer)			? SG_T("\n[x]") : SG_T("\n[ ]");
+	s	+= _TL("delete layer");
+
+	s	+= pDriver->TestCapability(OLCDeleteFeature)		? SG_T("\n[x]") : SG_T("\n[ ]");
+	s	+= _TL("delete feature");
+
+	s	+= pDriver->TestCapability(OLCRandomRead)			? SG_T("\n[x]") : SG_T("\n[ ]");
+	s	+= _TL("random read");
+
+	s	+= pDriver->TestCapability(OLCRandomWrite)			? SG_T("\n[x]") : SG_T("\n[ ]");
+	s	+= _TL("random write");
+
+	s	+= pDriver->TestCapability(OLCSequentialWrite)		? SG_T("\n[x]") : SG_T("\n[ ]");
+	s	+= _TL("sequential write");
+/**/
+
+	return( SG_STR_MBTOSG(s) );
+}
+
+//---------------------------------------------------------
+TSG_Shape_Type COGR_Driver::Get_Type(OGRwkbGeometryType Type)
+{
+	switch( Type )
+	{
+	case wkbPoint:					// 0-dimensional geometric object, standard WKB
+		return( SHAPE_TYPE_Point );
+
+	case wkbMultiPoint:				// GeometryCollection of Points, standard WKB
+		return( SHAPE_TYPE_Points );
+
+	case wkbLineString:				// 1-dimensional geometric object with linear interpolation between Points, standard WKB
+	case wkbMultiLineString:		// GeometryCollection of LineStrings, standard WKB
+		return( SHAPE_TYPE_Line );
+
+	case wkbPolygon:				// planar 2-dimensional geometric object defined by 1 exterior boundary and 0 or more interior boundaries, standard WKB
+	case wkbMultiPolygon:			// GeometryCollection of Polygons, standard WKB
+		return( SHAPE_TYPE_Polygon );
+
+	default:
+	case wkbUnknown:				// unknown type, non-standard
+	case wkbGeometryCollection:		// geometric object that is a collection of 1 or more geometric objects, standard WKB
+	case wkbNone:					// non-standard, for pure attribute records
+	case wkbLinearRing:				// non-standard, just for createGeometry()
+	case wkbPoint25D:				// 2.5D extension as per 99-402
+	case wkbLineString25D:			// 2.5D extension as per 99-402
+	case wkbPolygon25D:				// 2.5D extension as per 99-402
+	case wkbMultiPoint25D:			// 2.5D extension as per 99-402
+	case wkbMultiLineString25D:		// 2.5D extension as per 99-402
+	case wkbMultiPolygon25D:		// 2.5D extension as per 99-402
+	case wkbGeometryCollection25D:	// 2.5D extension as per 99-402 
+		return( SHAPE_TYPE_Undefined );
+	}
+}
+
+//---------------------------------------------------------
+OGRwkbGeometryType COGR_Driver::Get_Type(TSG_Shape_Type Type)
+{
+	switch( Type )
+	{
+	case SHAPE_TYPE_Point:	 	return( wkbPoint );				// point
+	case SHAPE_TYPE_Points: 	return( wkbMultiPoint );		// points
+	case SHAPE_TYPE_Line: 		return( wkbMultiLineString );	// line
+	case SHAPE_TYPE_Polygon:	return( wkbMultiPolygon );		// polygon
+
+	default:					return( wkbUnknown );
+	}
+}
+
+//---------------------------------------------------------
+TSG_Data_Type COGR_Driver::Get_Type(OGRFieldType Type)
+{
+	switch( Type )
+	{
+	case OFTInteger:		// Simple 32bit integer
+		return( SG_DATATYPE_Int );
+
+	case OFTReal:			// Double Precision floating point
+		return( SG_DATATYPE_Double );
+
+	case OFTString:			// String of ASCII chars
+		return( SG_DATATYPE_String );
+
+	case OFTDateTime:		// Date and Time 
+		return( SG_DATATYPE_Date );
+
+	default:
+	case OFTIntegerList:	// List of 32bit integers
+	case OFTRealList:		// List of doubles
+	case OFTStringList:		// Array of strings
+	case OFTWideString:		// deprecated
+	case OFTWideStringList:	// deprecated
+	case OFTBinary:			// Raw Binary data
+	case OFTDate:			// Date
+	case OFTTime:			// Time
+		return( SG_DATATYPE_Undefined );
+	}
+}
+
+//---------------------------------------------------------
+OGRFieldType COGR_Driver::Get_Type(TSG_Data_Type Type)
+{
+	switch( Type )
+	{
+	default:
+	case SG_DATATYPE_String:
+	case SG_DATATYPE_Date:
+		return( OFTString );
+
+	case SG_DATATYPE_Byte:
+	case SG_DATATYPE_Char:
+	case SG_DATATYPE_Word:
+	case SG_DATATYPE_Short:
+	case SG_DATATYPE_DWord:
+	case SG_DATATYPE_Int:
+	case SG_DATATYPE_ULong:
+	case SG_DATATYPE_Long:
+	case SG_DATATYPE_Color:
+		return( OFTInteger );
+
+	case SG_DATATYPE_Float:
+	case SG_DATATYPE_Double:
+		return( OFTReal );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+COGR_DataSource::COGR_DataSource(void)
+{
+	m_pDataSource	= NULL;
+}
+
+COGR_DataSource::COGR_DataSource(const CSG_String &File)
+{
+	m_pDataSource	= NULL;
+
+	Create(File);
+}
+
+//---------------------------------------------------------
+COGR_DataSource::~COGR_DataSource(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::Create(const CSG_String &File)
+{
+	Destroy();
+
+	m_pDataSource	= OGRSFDriverRegistrar::Open(SG_STR_SGTOMB(File));
+
+	return( m_pDataSource != NULL );
+}
+
+bool COGR_DataSource::Create(const CSG_String &File, const CSG_String &DriverName)
+{
+	OGRSFDriver	*pDriver;
+
+	Destroy();
+
+	if( (pDriver = g_OGR_Driver.Get_Driver(DriverName)) != NULL )
+	{
+		m_pDataSource	= pDriver->CreateDataSource(SG_STR_SGTOMB(File), NULL);
+	}
+
+	return( m_pDataSource != NULL );
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::Destroy(void)
+{
+	if( m_pDataSource )
+	{
+		OGRDataSource::DestroyDataSource(m_pDataSource);
+
+		m_pDataSource	= NULL;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int COGR_DataSource::Get_Count(void)
+{
+	if( m_pDataSource )
+	{
+		return( m_pDataSource->GetLayerCount() );
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+OGRLayer * COGR_DataSource::Get_Layer(int iLayer)
+{
+	if( m_pDataSource && iLayer >= 0 && iLayer < m_pDataSource->GetLayerCount() )
+	{
+		return( m_pDataSource->GetLayer(iLayer) );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+TSG_Shape_Type COGR_DataSource::Get_Type(int iLayer)
+{
+	if( m_pDataSource && iLayer >= 0 && iLayer < m_pDataSource->GetLayerCount() )
+	{
+		return( COGR_Driver::Get_Type(m_pDataSource->GetLayer(iLayer)->GetLayerDefn()->GetGeomType()) );
+	}
+
+	return( SHAPE_TYPE_Undefined );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer)
+{
+	OGRLayer	*pLayer	= Get_Layer(iLayer);
+
+	//-----------------------------------------------------
+	if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined )
+	{
+		int				iField;
+		OGRFeature		*pFeature;
+		OGRFeatureDefn	*pDef		= pLayer->GetLayerDefn();
+		CSG_Shapes		*pShapes	= SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName()));
+
+		for(iField=0; iField<pDef->GetFieldCount(); iField++)
+		{
+			OGRFieldDefn	*pDefField	= pDef->GetFieldDefn(iField);
+
+			pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType()));
+		}
+
+		pLayer->ResetReading();
+
+		//-------------------------------------------------
+		while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) )
+		{
+			OGRGeometry	*pGeometry	= pFeature->GetGeometryRef();
+
+			if( pGeometry != NULL )
+			{
+				CSG_Shape	*pShape	= pShapes->Add_Shape();
+
+				for(iField=0; iField<pDef->GetFieldCount(); iField++)
+				{
+					OGRFieldDefn	*pDefField	= pDef->GetFieldDefn(iField);
+
+					switch( pDefField->GetType() )
+					{
+					default:			pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField)));	break;
+					case OFTString:		pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField)));	break;
+					case OFTInteger:	pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField));	break;
+					case OFTReal:		pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField));	break;
+					}
+				}
+
+				//-----------------------------------------
+				if( _Read_Geometry(pShape, pGeometry) == false )
+				{
+					pShapes->Del_Shape(pShape);
+				}
+			}
+
+			OGRFeature::DestroyFeature(pFeature);
+		}
+
+		return( pShapes );
+	}
+
+	//-----------------------------------------------------
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::_Read_Geometry(CSG_Shape *pShape, OGRGeometry *pGeometry)
+{
+	if( pShape && pGeometry )
+	{
+		switch( pGeometry->getGeometryType() )
+		{
+		//-------------------------------------------------
+		case wkbPoint:				// 0-dimensional geometric object, standard WKB
+			pShape->Add_Point(((OGRPoint *)pGeometry)->getX(), ((OGRPoint *)pGeometry)->getY());
+			return( true );
+
+		//-------------------------------------------------
+		case wkbLineString:			// 1-dimensional geometric object with linear interpolation between Points, standard WKB
+			return( _Read_Line(pShape, (OGRLineString *)pGeometry) );
+
+		//-------------------------------------------------
+		case wkbPolygon:			// planar 2-dimensional geometric object defined by 1 exterior boundary and 0 or more interior boundaries, standard WKB
+			return( _Read_Polygon(pShape, (OGRPolygon *)pGeometry) );
+
+		//-------------------------------------------------
+		case wkbMultiPoint:			// GeometryCollection of Points, standard WKB
+		case wkbMultiLineString:	// GeometryCollection of LineStrings, standard WKB
+		case wkbMultiPolygon:		// GeometryCollection of Polygons, standard WKB
+			{
+				for(int i=0; i<((OGRGeometryCollection *)pGeometry)->getNumGeometries(); i++)
+				{
+					if( _Read_Geometry(pShape, ((OGRGeometryCollection *)pGeometry)->getGeometryRef(i)) == false )
+					{
+						return( false );
+					}
+				}
+			}
+
+			return( true );
+
+		//-------------------------------------------------
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::_Read_Line(CSG_Shape *pShape, OGRLineString *pLine)
+{
+	if( pShape && pLine && pLine->getNumPoints() > 0 )
+	{
+		int		iPart	= pShape->Get_Part_Count();
+
+		for(int iPoint=0; iPoint<pLine->getNumPoints(); iPoint++)
+		{
+			pShape->Add_Point(pLine->getX(iPoint), pLine->getY(iPoint), iPart);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::_Read_Polygon(CSG_Shape *pShape, OGRPolygon *pPolygon)
+{
+	if( pShape && pPolygon )
+	{
+		_Read_Line(pShape, pPolygon->getExteriorRing());
+
+		for(int i=0; i<pPolygon->getNumInteriorRings(); i++)
+		{
+			pPolygon->getInteriorRing(i);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool COGR_DataSource::Write_Shapes(CSG_Shapes *pShapes)
+{
+	OGRLayer	*pLayer;
+
+	//-----------------------------------------------------
+	if( m_pDataSource && pShapes && pShapes->is_Valid() && (pLayer = m_pDataSource->CreateLayer(SG_STR_SGTOMB(pShapes->Get_Name()), NULL, g_OGR_Driver.Get_Type(pShapes->Get_Type()))) != NULL )
+	{
+		bool			bResult	= true;
+		int				iField;
+
+		//-------------------------------------------------
+		for(iField=0; iField<pShapes->Get_Field_Count() && bResult; iField++)
+		{
+			OGRFieldDefn	DefField(SG_STR_SGTOMB(pShapes->Get_Field_Name(iField)), g_OGR_Driver.Get_Type(pShapes->Get_Field_Type(iField)));
+
+			//	DefField.SetWidth(32);
+
+			if( pLayer->CreateField(&DefField) != OGRERR_NONE )
+			{
+				bResult	= false;
+			}
+		}
+
+		//-------------------------------------------------
+		for(int iShape=0; iShape<pShapes->Get_Count() && bResult && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape		= pShapes->Get_Shape(iShape);
+			OGRFeature	*pFeature	= OGRFeature::CreateFeature(pLayer->GetLayerDefn());
+
+			for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
+			{
+				switch( pShapes->Get_Field_Type(iField) )
+				{
+				default:
+				case SG_DATATYPE_Char:
+				case SG_DATATYPE_String:
+				case SG_DATATYPE_Date:
+					pFeature->SetField(iField, SG_STR_SGTOMB(pShape->asString(iField)));
+					break;
+
+				case SG_DATATYPE_Short:
+				case SG_DATATYPE_Int:
+				case SG_DATATYPE_Long:
+				case SG_DATATYPE_Color:
+					pFeature->SetField(iField, pShape->asInt(iField));
+					break;
+
+				case SG_DATATYPE_Float:
+				case SG_DATATYPE_Double:
+					pFeature->SetField(iField, pShape->asDouble(iField));
+					break;
+				}
+			}
+
+			if( !_Write_Geometry(pShape, pFeature) || pLayer->CreateFeature(pFeature) != OGRERR_NONE )
+			{
+				bResult	= false;
+			}
+
+			OGRFeature::DestroyFeature(pFeature);
+		}
+
+		//-------------------------------------------------
+		return( bResult );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::_Write_Geometry(CSG_Shape *pShape, OGRFeature *pFeature)
+{
+	if( pShape && pFeature )
+	{
+		int					iPoint, iPart;
+		TSG_Point			sgPoint;
+		OGRPoint			Point;
+		OGRMultiPoint		Points;
+		OGRLineString		Line;
+		OGRMultiLineString	Lines;
+		OGRLinearRing		Ring;
+		OGRPolygon			Polygon;
+
+		switch( pShape->Get_Type() )
+		{
+		//-------------------------------------------------
+		case SHAPE_TYPE_Point:
+			sgPoint	= pShape->Get_Point(0);
+			Point.setX(sgPoint.x);
+			Point.setY(sgPoint.y);
+
+			return( pFeature->SetGeometry(&Point) == OGRERR_NONE );
+
+		//-------------------------------------------------
+		case SHAPE_TYPE_Points:
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					sgPoint	= pShape->Get_Point(iPoint, iPart);
+					Point.setX(sgPoint.x);
+					Point.setY(sgPoint.y);
+
+					Points.addGeometry(&Point);
+				}
+			}
+
+			return( pFeature->SetGeometry(&Points) == OGRERR_NONE );
+
+		//-------------------------------------------------
+		case SHAPE_TYPE_Line:
+			if( pShape->Get_Part_Count() == 1 )
+			{
+				_Write_Line(pShape, &Line, 0);
+
+				return( pFeature->SetGeometry(&Line) == OGRERR_NONE );
+			}
+			else
+			{
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					if( _Write_Line(pShape, &Line, iPart) )
+					{
+						Lines.addGeometry(&Line);
+					}
+				}
+
+				return( pFeature->SetGeometry(&Lines) == OGRERR_NONE );
+			}
+
+		//-------------------------------------------------
+		case SHAPE_TYPE_Polygon:
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				if( _Write_Line(pShape, &Ring, iPart) )
+				{
+					Polygon.addRing(&Ring);
+				}
+			}
+
+			return( pFeature->SetGeometry(&Polygon) == OGRERR_NONE );
+
+		//-------------------------------------------------
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool COGR_DataSource::_Write_Line(CSG_Shape *pShape, OGRLineString *pLine, int iPart)
+{
+	if( pLine && pShape && iPart >= 0 && iPart < pShape->Get_Part_Count() )
+	{
+		pLine->empty();
+
+		for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			TSG_Point	sgPoint	= pShape->Get_Point(iPoint, iPart);
+
+			pLine->addPoint(sgPoint.x, sgPoint.y);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_driver.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,147 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     ogr_driver.h                      //
+//                                                       //
+//            Copyright (C) 2008 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ogr_driver_H
+#define HEADER_INCLUDED__ogr_driver_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include <gdal_priv.h>
+#include <ogrsf_frmts.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class COGR_Driver
+{
+public:
+	COGR_Driver(void);
+	virtual ~COGR_Driver(void);
+
+	int							Get_Count		(void)				{	return( m_pManager->GetDriverCount() );	}
+	CSG_String					Get_Name		(int iDriver)		{	return( SG_STR_MBTOSG(m_pManager->GetDriver(iDriver)->GetName()) );	}
+	CSG_String					Get_Description	(int iDriver);
+	OGRSFDriver *				Get_Driver		(int iDriver)		{	return( m_pManager->GetDriver(iDriver) );			}
+	OGRSFDriver *				Get_Driver		(const CSG_String &Name);
+
+	bool						Can_Read		(int iDriver);
+	bool						Can_Write		(int iDriver);
+
+	static TSG_Shape_Type		Get_Type		(OGRwkbGeometryType   Type);
+	static OGRwkbGeometryType	Get_Type		(TSG_Shape_Type       Type);
+	static TSG_Data_Type	Get_Type		(OGRFieldType         Type);
+	static OGRFieldType			Get_Type		(TSG_Data_Type Type);
+
+
+private:
+
+	OGRSFDriverRegistrar		*m_pManager;
+
+};
+
+//---------------------------------------------------------
+class COGR_DataSource
+{
+public:
+	COGR_DataSource(void);
+	COGR_DataSource(const CSG_String &File);
+	COGR_DataSource(const CSG_String &File, const CSG_String &DriverName);
+	virtual ~COGR_DataSource(void);
+
+	bool						Create			(const CSG_String &File);
+	bool						Create			(const CSG_String &File, const CSG_String &DriverName);
+	bool						Destroy			(void);
+
+	int							Get_Count		(void);
+	OGRLayer *					Get_Layer		(int iLayer);
+	TSG_Shape_Type				Get_Type		(int iLayer);
+
+	CSG_Shapes *				Read_Shapes		(int iLayer);
+	bool						Write_Shapes	(CSG_Shapes *pShapes);
+
+
+private:
+
+	OGRDataSource				*m_pDataSource;
+
+
+	bool						_Read_Geometry	(CSG_Shape *pShape, OGRGeometry *pGeometry);
+	bool						_Read_Line		(CSG_Shape *pShape, OGRLineString *pLine);
+	bool						_Read_Polygon	(CSG_Shape *pShape, OGRPolygon *pPolygon);
+
+	bool						_Write_Geometry	(CSG_Shape *pShape, OGRFeature *pFeature);
+	bool						_Write_Line		(CSG_Shape *pShape, OGRLineString *pLine, int iPart);
+
+};
+
+//---------------------------------------------------------
+extern COGR_Driver	g_OGR_Driver;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ogr_driver_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,165 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    ogr_export.cpp                     //
+//                                                       //
+//            Copyright (C) 2008 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ogr_export.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+COGR_Export::COGR_Export(void)
+{
+	Set_Name		(_TL("OGR: Export Vector Data"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	CSG_String	Description, Formats;
+
+	Description	= _TW(
+		"The \"GDAL Vector Data Export\" module exports vector data to various file formats using the "
+		"\"Geospatial Data Abstraction Library\" (GDAL) by Frank Warmerdam. "
+		"For more information have a look at the GDAL homepage:\n"
+		"  <a target=\"_blank\" href=\"http://www.gdal.org/\">"
+		"  http://www.gdal.org</a>\n"
+		"\n"
+		"Following vector formats are currently supported:\n"
+		"<table border=\"1\"><tr><th>Name</th><th>Description</th></tr>\n"
+	);
+
+	for(int i=0; i<g_OGR_Driver.Get_Count(); i++)
+    {
+		if( g_OGR_Driver.Can_Write(i) )
+		{
+			Description	+= CSG_String::Format(SG_T("<tr><td>%s</td><td>%s</td></tr>\n"),
+				g_OGR_Driver.Get_Name(i).c_str(),
+				g_OGR_Driver.Get_Description(i).c_str()
+			);
+
+			Formats		+= CSG_String::Format(SG_T("%s|"), g_OGR_Driver.Get_Name(i).c_str());
+		}
+    }
+
+	Description	+= SG_T("</table>");
+
+	Set_Description(Description);
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL, "FILE"	, _TL("File"),
+		_TL(""),
+		NULL, NULL, true
+	);
+
+	Parameters.Add_Choice(
+		NULL, "FORMAT"	, _TL("Format"),
+		_TL(""),
+		Formats
+	);
+}
+
+//---------------------------------------------------------
+COGR_Export::~COGR_Export(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool COGR_Export::On_Execute(void)
+{
+	CSG_String		File_Name;
+	CSG_Shapes		*pShapes;
+	COGR_DataSource	ds;
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("SHAPES")	->asShapes();
+	File_Name	= Parameters("FILE")	->asString();
+
+	//-----------------------------------------------------
+	if( ds.Create(File_Name, Parameters("FORMAT")->asString()) == false )
+	{
+		Message_Add(_TL("Could not create data source."));
+	}
+	else if( ds.Write_Shapes(pShapes) )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_export.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,92 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     ogr_export.h                      //
+//                                                       //
+//            Copyright (C) 2008 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ogr_export_H
+#define HEADER_INCLUDED__ogr_export_H
+
+//---------------------------------------------------------
+#include "ogr_driver.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class COGR_Export : public CSG_Module
+{
+public:
+	COGR_Export(void);
+	virtual ~COGR_Export(void);
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ogr_export_H

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,169 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    ogr_import.cpp                     //
+//                                                       //
+//            Copyright (C) 2008 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ogr_import.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+COGR_Import::COGR_Import(void)
+{
+	Set_Name	(_TL("OGR: Import Vector Data"));
+
+	Set_Author	(SG_T("(c) 2008 by O.Conrad"));
+
+	CSG_String	Description;
+
+	Description	= _TW(
+		"The \"GDAL Vector Data Import\" module imports vector data from various file/database formats using the "
+		"\"Geospatial Data Abstraction Library\" (GDAL) by Frank Warmerdam. "
+		"For more information have a look at the GDAL homepage:\n"
+		"  <a target=\"_blank\" href=\"http://www.gdal.org/\">"
+		"  http://www.gdal.org</a>\n"
+		"\n"
+		"Following vector data formats are currently supported:\n"
+		"<table border=\"1\"><tr><th>Name</th><th>Description</th></tr>\n"
+	);
+
+	for(int i=0; i<g_OGR_Driver.Get_Count(); i++)
+    {
+		if( g_OGR_Driver.Can_Read(i) )
+		{
+			Description	+= CSG_String::Format(SG_T("<tr><td>%s</td><td>%s</td></tr>\n"),
+				g_OGR_Driver.Get_Name(i).c_str(),
+				g_OGR_Driver.Get_Description(i).c_str()
+			);
+		}
+    }
+
+	Description	+= SG_T("</table>");
+
+	Set_Description(Description);
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes_List(
+		NULL, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL, "FILE"	, _TL("File"),
+		_TL("")
+	);
+}
+
+//---------------------------------------------------------
+COGR_Import::~COGR_Import(void)
+{}
+
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool COGR_Import::On_Execute(void)
+{
+	COGR_DataSource	ds;
+
+	//-----------------------------------------------------
+	if( !ds.Create(Parameters("FILE")->asString()) )
+	{
+		Message_Add(_TL("could not open data source"));
+
+		return( false );
+	}
+
+	if( ds.Get_Count() <= 0 )
+	{
+		Message_Add(_TL("no layers in data source"));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	Parameters("SHAPES")->asShapesList()->Del_Items();
+
+	for(int iLayer=0; iLayer<ds.Get_Count(); iLayer++)
+	{
+		CSG_Shapes	*pShapes	= ds.Read_Shapes(iLayer);
+
+		if( pShapes )
+		{
+			Parameters("SHAPES")->asShapesList()->Add_Item(pShapes);
+		}
+	}
+
+	return( Parameters("SHAPES")->asShapesList()->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gdal/io_gdal/ogr_import.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,92 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                       io_gdal                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     ogr_import.h                      //
+//                                                       //
+//            Copyright (C) 2008 O. Conrad               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.de                    //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Bundesstr. 55                          //
+//                D-20146 Hamburg                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ogr_import_H
+#define HEADER_INCLUDED__ogr_import_H
+
+//---------------------------------------------------------
+#include "ogr_driver.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class COGR_Import : public CSG_Module
+{
+public:
+	COGR_Import(void);
+	virtual ~COGR_Import(void);
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ogr_import_H

Added: packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,137 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                      Models                           //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import GPS Data") );
+
+	case MLB_INFO_Author:
+		return( _TL("Victor Olaya (c) 2004") );
+
+	case MLB_INFO_Description:
+		return( _TL("Modules for GPS data handling.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|GPS Import") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "gpx2shp.h"
+#include "GPSBabel.h"
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CGPX2SHP;
+		break;	
+		
+	case 1:
+		pModule	= new CGPSBabel;
+		break;	
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+		
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/gps/io_gps/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Terrain_Analysis                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_gps_H
+#define HEADER_INCLUDED__io_gps_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_gps_EXPORTS
+	#define	io_gps_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_gps_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_gps_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,143 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import/Export - Grids") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the import and export of gridded data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|Grid") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "esri_arcinfo.h"
+#include "surfer.h"
+#include "raw.h"
+#include "xyz.h"
+#include "usgs_srtm.h"
+#include "mola.h"
+#include "srtm30.h"
+#include "bmp_export.h"
+#include "erdas_lan.h"
+#include "grid_table.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CESRI_ArcInfo_Export );
+	case 1:		return( new CESRI_ArcInfo_Import );
+	case 2:		return( new CSurfer_Export );
+	case 3:		return( new CSurfer_Import );
+	case 4:		return( new CRaw_Import );
+	case 5:		return( new CXYZ_Export );
+	case 6:		return( new CXYZ_Import );
+	case 7:		return( new CUSGS_SRTM_Import );
+	case 8:		return( new CMOLA_Import );
+	case 9:		return( new CSRTM30_Import );
+	case 10:	return( new CBMP_Export );
+	case 11:	return( new CErdas_LAN_Import );
+	case 12:	return( new CGrid_Table_Import );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_grid_H
+#define HEADER_INCLUDED__io_grid_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_grid_EXPORTS
+	#define	io_grid_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_grid_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_grid_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,237 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    bmp_export.cpp                     //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "bmp_export.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CBMP_Export::CBMP_Export(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Export True Color Bitmap"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Export red-green-blue coded image grids to MS-Windows true color bitmaps. "
+		"This module writes the data directly to the file and is hence particularly "
+		"suitable for very large data sets. "
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "IMAGE"	, _TL("Image Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("MS Windows Bitmap (*.bmp)|*.bmp|All Files|*.*"),
+		NULL, true, false
+	);
+}
+
+//---------------------------------------------------------
+CBMP_Export::~CBMP_Export(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define	SIZE_HEADER_FILE	14
+#define	SIZE_HEADER_BITMAP	40
+#define	SIZE_HEADER_TOTAL	(SIZE_HEADER_FILE + SIZE_HEADER_BITMAP)
+
+//---------------------------------------------------------
+bool CBMP_Export::On_Execute(void)
+{
+	//-----------------------------------------------------
+	char		*Line, *pLine;
+	int			x, y, Value, nBytes_Image, nBytes_Line;
+	FILE		*Stream;
+	CSG_Grid	*pGrid;
+	CSG_String	FileName;
+
+	//-----------------------------------------------------
+	pGrid		= Parameters("IMAGE")	->asGrid();
+	FileName	= Parameters("FILE")	->asString();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(FileName.b_str(), "wb")) != NULL )
+	{
+		nBytes_Line		= 3 * sizeof(BYTE) * Get_NX();
+
+		if( (Value = nBytes_Line % 4) != 0 )					// must be a multiple of DWORD size...
+		{
+			nBytes_Line	+= 4 - Value;
+		}
+
+		nBytes_Image	= nBytes_Line * Get_NY();
+
+		//-------------------------------------------------
+		Write_WORD	(Stream, 0x4d42);							// bfType      - 0x42 = "B", 0x4d = "M"...
+		Write_DWORD	(Stream, SIZE_HEADER_TOTAL + nBytes_Image);	// bfSize      - size of the entire file...
+		Write_WORD	(Stream, 0);								// bfReserved1
+		Write_WORD	(Stream, 0);								// bfReserved2
+		Write_DWORD	(Stream, SIZE_HEADER_TOTAL);				// bfOffBits   - offset to the array of color indices...
+
+		//-------------------------------------------------
+		Write_DWORD	(Stream, SIZE_HEADER_BITMAP);				// biSize;
+		Write_LONG	(Stream, Get_NX());							// biWidth;
+		Write_LONG	(Stream, Get_NY());							// biHeight;
+		Write_WORD	(Stream, 1);								// biPlanes;
+		Write_WORD	(Stream, 24);								// biBitCount;
+		Write_DWORD	(Stream, 0);								// biCompression;
+		Write_DWORD	(Stream, nBytes_Image);						// biSizeImage;
+		Write_LONG	(Stream, 0);								// biXPelsPerMeter;
+		Write_LONG	(Stream, 0);								// biYPelsPerMeter;
+		Write_DWORD	(Stream, 2^24);								// biClrUsed;
+		Write_DWORD	(Stream, 0);								// biClrImportant;
+
+		//-------------------------------------------------
+		Line	= (char *)SG_Calloc(nBytes_Line, sizeof(char));
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0, pLine=Line; x<Get_NX(); x++, pLine+=3)
+			{
+				Value		= pGrid->asInt(x, y);
+
+				pLine[0]	= SG_GET_B(Value);
+				pLine[1]	= SG_GET_G(Value);
+				pLine[2]	= SG_GET_R(Value);
+			}
+
+			fwrite(Line, sizeof(char), nBytes_Line, Stream);
+		}
+
+		SG_Free(Line);
+
+		//-------------------------------------------------
+		fclose(Stream);
+
+		FileName	= SG_File_Make_Path(SG_File_Get_Path(FileName), SG_File_Get_Name(FileName, false), SG_T("bpw"));
+
+		if( (Stream = fopen(FileName.b_str(), "w")) != NULL )
+		{
+			fprintf(Stream, "%f\n%f\n%f\n%f\n%f\n%f\n",
+				 pGrid->Get_Cellsize(),
+				 0.0, 0.0,
+				-pGrid->Get_Cellsize(),
+				 pGrid->Get_XMin(),
+				 pGrid->Get_YMax()
+			);
+
+			fclose(Stream);
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CBMP_Export::Write_WORD	(FILE *Stream, WORD  Value)
+{
+	fwrite(&Value, sizeof(Value), 1, Stream);
+}
+
+//---------------------------------------------------------
+void CBMP_Export::Write_DWORD	(FILE *Stream, DWORD Value)
+{
+	fwrite(&Value, sizeof(Value), 1, Stream);
+}
+
+//---------------------------------------------------------
+void CBMP_Export::Write_LONG	(FILE *Stream, long  Value)
+{
+	fwrite(&Value, sizeof(Value), 1, Stream);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/bmp_export.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      bmp_export.h                     //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__bmp_export_H
+#define HEADER_INCLUDED__bmp_export_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CBMP_Export : public CSG_Module_Grid
+{
+public:
+	CBMP_Export(void);
+	virtual ~CBMP_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	void					Write_WORD		(FILE *Stream, WORD  Value);
+	void					Write_DWORD		(FILE *Stream, DWORD Value);
+	void					Write_LONG		(FILE *Stream, long  Value);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__bmp_export_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,291 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    erdas_lan.cpp                      //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "erdas_lan.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CErdas_LAN_Import::CErdas_LAN_Import(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Import Erdas LAN/GIS"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import Erdas LAN/GIS files. \n"
+		"The format analysis is based on the GRASS module i.in.erdas. "
+		"Go to the " 
+		"<a target=\"_blank\" href=\"http://grass.itc.it/\">GRASS GIS Hompage</a> "
+		"for more information.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("Erdas LAN/GIS files (*.lan, *.gis)|*.lan;*.gis|All Files|*.*"),
+		NULL, false, false
+	);
+}
+
+//---------------------------------------------------------
+CErdas_LAN_Import::~CErdas_LAN_Import(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SWAP(v)		if( bSwap ) SG_Swap_Bytes(&v, sizeof(v));
+
+//---------------------------------------------------------
+bool CErdas_LAN_Import::On_Execute(void)
+{
+	//-----------------------------------------------------
+	bool					bResult	= false, bSwap	= false;
+	BYTE					*Line, *pLine;
+	char					head[6], empty[56];
+	short					vType, nBands, maptyp, nclass, unit;
+	int						x, y, i, nLine;
+	long					nx, ny, px, py;
+	float					area, dx, dy, xPos, yPos;
+	double					Cellsize, xMin, yMin, Value;
+	FILE					*Stream;
+	TSG_Data_Type			gType;
+	CSG_Parameter_Grid_List	*Grids;
+	CSG_String				FileName;
+
+	//-----------------------------------------------------
+	Grids		= Parameters("GRIDS")	->asGridList();
+	FileName	= Parameters("FILE")	->asString();
+
+	Grids->Del_Items();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(FileName.b_str(), "rb")) != NULL )
+	{
+		fread( head		,  6, sizeof(char)	, Stream);					// "HEAD74"
+		fread(&vType	,  1, sizeof(short)	, Stream);	SWAP(vType);	// 0 = 8 bit, 1 = 4 bit, 2 = 16 bit
+		fread(&nBands	,  1, sizeof(short)	, Stream);	SWAP(nBands);	// number of bands
+		fread( empty	,  6, sizeof(char)	, Stream);					// empty
+		fread(&nx		,  1, sizeof(long)	, Stream);	SWAP(nx);		// number of columns
+		fread(&ny		,  1, sizeof(long)	, Stream);	SWAP(ny);		// number of rows
+		fread(&px		,  1, sizeof(long)	, Stream);	SWAP(px);		// x position of top-left pixel "database location"
+		fread(&py		,  1, sizeof(long)	, Stream);	SWAP(py);		// y position of top-left pixel "database location"
+		fread( empty	, 56, sizeof(char)	, Stream);					// empty
+		fread(&maptyp	,  1, sizeof(short)	, Stream);	SWAP(maptyp);	// map projection
+		fread(&nclass	,  1, sizeof(short)	, Stream);	SWAP(nclass);	// number of classes
+		fread( empty	, 14, sizeof(char)	, Stream);					// empty
+		fread(&unit		,  1, sizeof(short)	, Stream);	SWAP(unit);		// units of area per pixel - 0 = none, 1 = acre, 2 = hectare, 3 = other
+		fread(&area		,  1, sizeof(float)	, Stream);	SWAP(area);		// area per pixel
+		fread(&xPos		,  1, sizeof(float)	, Stream);	SWAP(xPos);		// x coordinate of top-left pixel
+		fread(&yPos		,  1, sizeof(float)	, Stream);	SWAP(yPos);		// y coordinate of top-left pixel
+		fread(&dx		,  1, sizeof(float)	, Stream);	SWAP(dx);		// linear size of a pixel (feet/degrees/meters)
+		fread(&dy		,  1, sizeof(float)	, Stream);	SWAP(dy);		// linear size of a pixel (feet/degrees/meters)
+
+		//-------------------------------------------------
+		CSG_File	fWorld;
+
+		if( fWorld.Open(SG_File_Make_Path(NULL, FileName, SG_T("lnw")), SG_FILE_R, false) )
+		{
+			double		d;
+			CSG_String	sLine;
+
+			if( fWorld.Read_Line(sLine) )	{	if( sLine.asDouble(d) )	dx		= (float)d;	}
+			if( fWorld.Read_Line(sLine) )	{	}
+			if( fWorld.Read_Line(sLine) )	{	}
+			if( fWorld.Read_Line(sLine) )	{	if( sLine.asDouble(d) )	dy		= (float)d;	}
+			if( fWorld.Read_Line(sLine) )	{	if( sLine.asDouble(d) )	xPos	= (float)d;	}
+			if( fWorld.Read_Line(sLine) )	{	if( sLine.asDouble(d) )	yPos	= (float)d;	}
+		}
+
+		//-------------------------------------------------
+		if( feof(Stream) )
+		{
+			Message_Add(_TL("File error"));
+		}
+		else if( strncmp(head, "HEAD74", sizeof(head)) )
+		{
+			Message_Add(_TL("ERDAS files other than version 7.4 are not supported."));
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			bResult		= true;
+			Cellsize	= dx;
+			xMin		= xPos;
+			yMin		= yPos - ny * Cellsize;
+
+			switch( vType )
+			{
+			case 0:	default:	//  8 bit
+				gType	= SG_DATATYPE_Byte;
+				nLine	= nx;
+				break;
+
+			case 1:				//  4 bit
+				gType	= SG_DATATYPE_Byte;
+				nLine	= nx / 2 + (nx % 2 ? 1 : 0);
+				break;
+
+			case 2:				// 16 bit
+				gType	= SG_DATATYPE_Word;
+				nLine	= nx * 2;
+				break;
+			}
+
+			Line	= (BYTE *)SG_Malloc(nLine * sizeof(BYTE));
+
+			for(i=0; i<nBands; i++)
+			{
+				Grids->Add_Item(SG_Create_Grid(gType, nx, ny, Cellsize, xMin, yMin));
+				Grids->asGrid(i)->Set_Name(CSG_String::Format(SG_T("%s [%d]"), SG_File_Get_Name(FileName, false).c_str(), i + 1));
+			}
+
+			//---------------------------------------------
+			for(y=0; y<ny && Set_Progress(y, ny); y++)
+			{
+				for(i=0; i<nBands; i++)
+				{
+					fread(Line, nLine, sizeof(BYTE), Stream);
+
+					for(x=0, pLine=Line; x<nx; x++)
+					{
+						switch( vType )
+						{
+						case 0: default:
+							Value	= *pLine;
+							pLine	++;
+							break;
+
+						case 1:
+							if( x % 2 )
+							{
+								Value	= (*pLine & ~0x11) >> 4;
+								pLine	++;
+							}
+							else
+							{
+								Value	= (*pLine &  0x11);
+							}
+							break;
+
+						case 2:
+							if( bSwap )
+							{
+								SG_Swap_Bytes(pLine, 2);
+							}
+
+							Value	= *((short *)pLine);
+							pLine	+= 2;
+							break;
+						}
+
+						Grids->asGrid(i)->Set_Value(x, ny - y - 1, Value);
+					}
+				}
+			}
+
+			//---------------------------------------------
+			SG_Free(Line);
+
+			for(i=0; i<nBands; i++)
+			{
+				DataObject_Add			(Grids->asGrid(i));
+				DataObject_Set_Colors	(Grids->asGrid(i), 100, SG_COLORS_BLACK_WHITE);
+			}
+		}
+
+		//-------------------------------------------------
+		fclose(Stream);
+	}
+
+	//-----------------------------------------------------
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/erdas_lan.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      erdas_lan.h                      //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__erdas_lan_H
+#define HEADER_INCLUDED__erdas_lan_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CErdas_LAN_Import : public CSG_Module
+{
+public:
+	CErdas_LAN_Import(void);
+	virtual ~CErdas_LAN_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__erdas_lan_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,616 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   ESRI_ArcInfo.cpp                    //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "esri_arcinfo.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define HDR_NROWS			"NROWS"
+#define HDR_NCOLS			"NCOLS"
+#define HDR_X_CORNER		"XLLCORNER"
+#define HDR_Y_CORNER		"YLLCORNER"
+#define HDR_X_CENTER		"XLLCENTER"
+#define HDR_Y_CENTER		"YLLCENTER"
+#define HDR_CELLSIZE		"CELLSIZE"
+#define HDR_NODATA			"NODATA_VALUE"
+#define HDR_BYTEORDER		"BYTE_ORDER"
+#define HDR_BYTEORDER_HI	"MSB_FIRST"
+#define HDR_BYTEORDER_LO	"LSB_FIRST"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CESRI_ArcInfo_Import::CESRI_ArcInfo_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Import ESRI Arc/Info Grid"));
+
+	Set_Author		(SG_T("(c) 2007 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import grid from ESRI's Arc/Info grid format.")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+
+		CSG_String::Format(
+			SG_T("%s|*.asc;*.flt|%s|*.asc|%s|*.flt|%s|*.*"),
+			_TL("ESRI Arc/Info Grids"),
+			_TL("ESRI Arc/Info ASCII Grids (*.asc)"),
+			_TL("ESRI Arc/Info Binary Grids (*.flt)"),
+			_TL("All Files")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CESRI_ArcInfo_Import::~CESRI_ArcInfo_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CESRI_ArcInfo_Import::On_Execute(void)
+{
+	bool		bResult;
+	int			x, y, iy;
+	float		Value, *Line;
+	FILE		*Stream;
+	CSG_String	fName;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	bResult	= false;
+	pGrid	= NULL;
+
+	if( Parameters("FILE")->asString() )
+	{
+		//-------------------------------------------------
+		// Binary...
+
+		if(	SG_File_Cmp_Extension(Parameters("FILE")->asString(), SG_T("flt"))
+		||	SG_File_Cmp_Extension(Parameters("FILE")->asString(), SG_T("hdr")) )
+		{
+			fName	= SG_File_Make_Path(SG_T(""), Parameters("FILE")->asString(), SG_T("hdr"));
+
+			if( (Stream = fopen(fName.b_str(), "r")) != NULL && (pGrid = Read_Header(Stream)) != NULL )
+			{
+				fclose(Stream);
+
+				fName	= SG_File_Make_Path(SG_T(""), Parameters("FILE")->asString(), SG_T("flt"));
+
+				if( (Stream = fopen(fName.b_str(), "rb")) != NULL )
+				{
+					Line	= (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float));
+
+					for(iy=0, y=pGrid->Get_NY()-1; iy<pGrid->Get_NY() && !feof(Stream) && Set_Progress(iy, pGrid->Get_NY()); iy++, y--)
+					{
+						fread(Line, pGrid->Get_NX(), sizeof(float), Stream);
+
+						for(x=0; x<pGrid->Get_NX(); x++)
+						{
+							pGrid->Set_Value(x, y, Line[x]);
+						}
+					}
+
+					SG_Free(Line);
+
+					fclose(Stream);
+				}
+			}
+		}
+
+
+		//-------------------------------------------------
+		// ASCII...
+
+		else
+		{
+			fName	= Parameters("FILE")->asString();
+
+			if( (Stream = fopen(fName.b_str(), "r")) != NULL )
+			{
+				if( (pGrid = Read_Header(Stream)) != NULL )
+				{
+					for(iy=0, y=pGrid->Get_NY()-1; iy<pGrid->Get_NY() && !feof(Stream) && Set_Progress(iy, pGrid->Get_NY()); iy++, y--)
+					{
+						for(x=0; x<pGrid->Get_NX(); x++)
+						{
+							fscanf(Stream, "%f", &Value);
+
+							pGrid->Set_Value(x, y, Value);
+						}
+					}
+				}
+
+				fclose(Stream);
+			}
+		}
+
+		//-------------------------------------------------
+		if( pGrid )
+		{
+			pGrid->Set_Name(SG_File_Get_Name(Parameters("FILE")->asString(), false));
+
+			Parameters("GRID")->Set_Value(pGrid);
+
+			bResult	= true;
+		}
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CESRI_ArcInfo_Import::Read_Line(FILE *Stream, CSG_String &sLine)
+{
+	if( Stream && !feof(Stream) )
+	{
+		char	c;
+
+		sLine.Clear();
+
+		while( !feof(Stream) && (c = getc(Stream)) != 0x0A && c != 0x0D )
+		{
+			sLine.Append(c);
+		}
+
+		sLine.Make_Upper();
+
+		sLine.Replace(SG_T(","), SG_T("."));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CESRI_ArcInfo_Import::Read_Value(const CSG_String &sKey, CSG_String &sLine, int &Value)
+{
+	sLine.Make_Upper();
+
+	if( sLine.Contains(sKey) )
+	{
+		CSG_String	sValue(sLine.c_str() + sKey.Length());
+
+		return( sValue.asInt(Value) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CESRI_ArcInfo_Import::Read_Value(const CSG_String &sKey, CSG_String &sLine, double &Value)
+{
+	sLine.Make_Upper();
+
+	if( sLine.Contains(sKey) )
+	{
+		CSG_String	sValue(sLine.c_str() + sKey.Length());
+
+		return( sValue.asDouble(Value) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CESRI_ArcInfo_Import::Read_Header(FILE *Stream)
+{
+	bool		bCorner_X, bCorner_Y;
+	int			NX, NY;
+	double		CellSize, xMin, yMin, NoData	= -9999.0;
+	CSG_String	sLine;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	if( Stream )
+	{
+		//-------------------------------------------------
+		Read_Line(Stream, sLine);
+
+		if( !Read_Value(HDR_NCOLS   , sLine, NX) )
+			return( NULL );
+
+		//-------------------------------------------------
+		Read_Line(Stream, sLine);
+
+		if( !Read_Value(HDR_NROWS   , sLine, NY) )
+			return( NULL );
+
+		//-------------------------------------------------
+		Read_Line(Stream, sLine);
+
+		if(	     Read_Value(HDR_X_CORNER, sLine, xMin) )
+			bCorner_X	= true;
+		else if( Read_Value(HDR_X_CENTER, sLine, xMin) )
+			bCorner_X	= false;
+		else
+			return( NULL );
+
+		//-------------------------------------------------
+		Read_Line(Stream, sLine);
+
+		if(	     Read_Value(HDR_Y_CORNER, sLine, yMin) )
+			bCorner_Y	= true;
+		else if( Read_Value(HDR_Y_CENTER, sLine, yMin) )
+			bCorner_Y	= false;
+		else
+			return( NULL );
+
+		//-------------------------------------------------
+		Read_Line(Stream, sLine);
+
+		if( !Read_Value(HDR_CELLSIZE, sLine, CellSize) )
+			return( NULL );
+
+		//-------------------------------------------------
+		Read_Line(Stream, sLine);
+
+		if( !Read_Value(HDR_NODATA  , sLine, NoData) )
+		//	return( NULL );
+		{}
+
+		//-------------------------------------------------
+		if( bCorner_X )
+			xMin	+= CellSize / 2.0;
+
+		if( bCorner_Y )
+			yMin	+= CellSize / 2.0;
+
+		//-------------------------------------------------
+		if( (pGrid = SG_Create_Grid(SG_DATATYPE_Float, NX, NY, CellSize, xMin, yMin)) != NULL )
+		{
+			pGrid->Set_NoData_Value(NoData);
+
+			return( pGrid );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CESRI_ArcInfo_Export::CESRI_ArcInfo_Export(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Export ESRI Arc/Info Grid"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Export grid to ESRI's Arc/Info grid format.")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+
+		CSG_String::Format(
+			SG_T("%s|*.asc;*.flt|%s|*.asc|%s|*.flt|%s|*.*"),
+			_TL("ESRI Arc/Info Grids"),
+			_TL("ESRI Arc/Info ASCII Grids (*.asc)"),
+			_TL("ESRI Arc/Info Binary Grids (*.flt)"),
+			_TL("All Files")
+		), NULL, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "FORMAT"	, _TL("Format"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("binary"),
+			_TL("ASCII")
+		), 1
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "GEOREF"	, _TL("Geo-Reference"),
+		_TL("The grids geo-reference must be related either to the center or the corner of its lower left grid cell."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("corner"),
+			_TL("center")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "PREC"	, _TL("ASCII Precision"),
+		_TL("Number of decimals when writing floating point values in ASCII format."),
+		PARAMETER_TYPE_Int	, 4, -1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "DECSEP"	, _TL("ASCII Decimal Separator"),
+		_TL("Applies also to the binary format header file."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("point (.)"),
+			_TL("comma (,)")
+		), 0
+	);
+
+//	Parameters.Add_Choice(
+//		NULL	, "BYTEORD"	, _TL("Binary Byte Order"),
+//		_TL("Byte order when writing floating point values in binary format"),
+//
+//		CSG_String::Format(SG_T("%s|%s|"),
+//			_TL("most significant first"),
+//			_TL("least significant first")
+//		), 0
+//	);
+}
+
+//---------------------------------------------------------
+CESRI_ArcInfo_Export::~CESRI_ArcInfo_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CESRI_ArcInfo_Export::On_Execute(void)
+{
+	bool		bResult, bSwapBytes, bComma;
+	int			x, y, iy, Precision;
+	float		*Line;
+	FILE		*Stream;
+	CSG_Grid	*pGrid;
+	CSG_String	fName;
+
+	//-----------------------------------------------------
+	bResult		= false;
+
+	pGrid		= Parameters("GRID")	->asGrid();
+	Precision	= Parameters("PREC")	->asInt();
+	bComma		= Parameters("DECSEP")	->asInt() == 1;
+	bSwapBytes	= false;	//	bSwapBytes	= Parameters("BYTEORD")	->asInt() == 1;
+
+
+	//-----------------------------------------------------
+	// Binary...
+
+	if( Parameters("FORMAT")->asInt() == 0 )
+	{
+		fName	= SG_File_Make_Path(SG_T(""), Parameters("FILE")->asString(), SG_T("hdr"));
+
+		if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+		{
+			if( Write_Header(Stream, pGrid, bComma) )
+			{
+				fclose(Stream);
+
+				fName	= SG_File_Make_Path(SG_T(""), Parameters("FILE")->asString(), SG_T("flt"));
+
+				if( (Stream = fopen(fName.b_str(), "wb")) != NULL )
+				{
+					Line	= (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float));
+
+					for(iy=0, y=pGrid->Get_NY()-1; iy<pGrid->Get_NY() && Set_Progress(iy, pGrid->Get_NY()); iy++, y--)
+					{
+						for(x=0; x<pGrid->Get_NX(); x++)
+						{
+							Line[x]	= pGrid->asFloat(x, y);
+
+							if( bSwapBytes )
+							{
+								SG_Swap_Bytes(Line + x, sizeof(float));
+							}
+						}
+
+						fwrite(Line, pGrid->Get_NX(), sizeof(float), Stream);
+					}
+
+					SG_Free(Line);
+
+					fclose(Stream);
+
+					bResult	= true;
+				}
+			}
+			else
+			{
+				fclose(Stream);
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// ASCII...
+
+	else
+	{
+		fName	= Parameters("FILE")->asString();
+
+		if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+		{
+			if( Write_Header(Stream, pGrid, bComma) )
+			{
+				CSG_String	s;
+
+				for(iy=0, y=pGrid->Get_NY()-1; iy<pGrid->Get_NY() && Set_Progress(iy, pGrid->Get_NY()); iy++, y--)
+				{
+					for(x=0; x<pGrid->Get_NX(); x++)
+					{
+						if( Precision < 0 )
+						{
+							s.Printf(SG_T("%f")		, pGrid->asFloat(x, y));
+						}
+						else if( Precision == 0 )
+						{
+							s.Printf(SG_T("%d")		, (int)(0.5 + pGrid->asFloat(x, y)));
+						}
+						else
+						{
+							s.Printf(SG_T("%.*f")	, Precision, pGrid->asFloat(x, y));
+						}
+
+						if( bComma )
+							s.Replace(SG_T("."), SG_T(","));
+						else
+							s.Replace(SG_T(","), SG_T("."));
+
+						fprintf(Stream, "%s ", s.b_str());
+					}
+
+					fprintf(Stream, "\n");
+				}
+
+				bResult	= true;
+			}
+
+			fclose(Stream);
+		}
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CESRI_ArcInfo_Export::Write_Header(FILE *Stream, CSG_Grid *pGrid, bool bComma)
+{
+	if( Stream && pGrid && pGrid->is_Valid() )
+	{
+		CSG_String	s;
+
+		s	+= CSG_String::Format(SG_T("%s %d\n")		, HDR_NCOLS		, pGrid->Get_NX());
+		s	+= CSG_String::Format(SG_T("%s %d\n")		, HDR_NROWS		, pGrid->Get_NY());
+
+		if( Parameters("GEOREF")->asInt() == 0 )
+		{
+			s	+= CSG_String::Format(SG_T("%s %f\n")	, HDR_X_CORNER	, pGrid->Get_XMin() - 0.5 * pGrid->Get_Cellsize());
+			s	+= CSG_String::Format(SG_T("%s %f\n")	, HDR_Y_CORNER	, pGrid->Get_YMin() - 0.5 * pGrid->Get_Cellsize());
+		}
+		else
+		{
+			s	+= CSG_String::Format(SG_T("%s %f\n")	, HDR_X_CENTER	, pGrid->Get_XMin());
+			s	+= CSG_String::Format(SG_T("%s %f\n")	, HDR_Y_CENTER	, pGrid->Get_YMin());
+		}
+
+		s	+= CSG_String::Format(SG_T("%s %f\n")		, HDR_CELLSIZE	, (float)pGrid->Get_Cellsize());
+		s	+= CSG_String::Format(SG_T("%s %f\n")		, HDR_NODATA	, (float)pGrid->Get_NoData_Value());
+
+		if( Parameters("FORMAT")->asInt() == 0 )	// binary
+		{	if( Parameters("BYTEORD") )
+			s	+= CSG_String::Format(SG_T("%s %s\n")	, HDR_BYTEORDER	, Parameters("BYTEORD")->asInt() == 1 ? HDR_BYTEORDER_LO : HDR_BYTEORDER_HI);
+		}
+
+		if( bComma )
+			s.Replace(SG_T("."), SG_T(","));
+		else
+			s.Replace(SG_T(","), SG_T("."));
+
+		fprintf(Stream, s.b_str());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/esri_arcinfo.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    ESRI_ArcInfo.h                     //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					ESRI_ArcInfo.h						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ESRI_ArcInfo_H
+#define HEADER_INCLUDED__ESRI_ArcInfo_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CESRI_ArcInfo_Import : public CSG_Module
+{
+public:
+	CESRI_ArcInfo_Import(void);
+	virtual ~CESRI_ArcInfo_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)				{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	bool					Read_Line		(FILE *Stream, CSG_String &sLine);
+	bool					Read_Value		(const CSG_String &sKey, CSG_String &sLine, int    &Value);
+	bool					Read_Value		(const CSG_String &sKey, CSG_String &sLine, double &Value);
+	CSG_Grid *				Read_Header		(FILE *Stream);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CESRI_ArcInfo_Export : public CSG_Module_Grid
+{
+public:
+	CESRI_ArcInfo_Export(void);
+	virtual ~CESRI_ArcInfo_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)				{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	bool					Write_Header	(FILE *Stream, CSG_Grid *pGrid, bool bComma);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ESRI_ArcInfo_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,242 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Table.cpp                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid_table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Table_Import::CGrid_Table_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Import Grid from Table"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Imports grid from from table.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"			, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE_DATA"		, _TL("Table"),
+		_TL("")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "DXY"				, _TL("Cell Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "XMIN"			, _TL("Left Border (X)"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "YMIN"			, _TL("Lower Border (Y)"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0
+	);
+
+	Parameters.Add_String(
+		NULL	, "UNIT"			, _TL("Unit Name"),
+		_TL(""),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ZFACTOR"			, _TL("Z Multiplier"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NODATA"			, _TL("No Data Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, -99999.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "DATA_TYPE"		, _TL("Data Type"),
+		_TL(""), _TW(
+		"1 Byte Integer (unsigned)|"
+		"1 Byte Integer (signed)|"
+		"2 Byte Integer (unsigned)|"
+		"2 Byte Integer (signed)|"
+		"4 Byte Integer (unsigned)|"
+		"4 Byte Integer (signed)|"
+		"4 Byte Floating Point|"
+		"8 Byte Floating Point|")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TOPDOWN"			, _TL("Line Order"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Bottom to Top"),
+			_TL("Top to Bottom")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Table_Import::~CGrid_Table_Import(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Table_Import::On_Execute(void)
+{
+	bool			bDown;
+	int				x, y, nx, ny;
+	double			dxy, xmin, ymin, zFactor, zNoData;
+	TSG_Data_Type		data_type;
+	CSG_String		FileName, Unit;
+	CSG_Grid			*pGrid;
+	CSG_Table			Table;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	FileName	= Parameters("FILE_DATA")		->asString();
+	dxy			= Parameters("DXY")				->asDouble();
+	xmin		= Parameters("XMIN")			->asDouble();
+	ymin		= Parameters("YMIN")			->asDouble();
+	bDown		= Parameters("TOPDOWN")			->asInt() == 1;
+	Unit		= Parameters("UNIT")			->asString();
+	zFactor		= Parameters("ZFACTOR")			->asDouble();
+	zNoData		= Parameters("NODATA")			->asDouble();
+
+	switch( Parameters("DATA_TYPE")->asInt() )
+	{
+	default:	data_type	= SG_DATATYPE_Undefined;	break;	// not handled
+	case 0:		data_type	= SG_DATATYPE_Byte;			break;	// 1 Byte Integer (unsigned)
+	case 1:		data_type	= SG_DATATYPE_Char;			break;	// 1 Byte Integer (signed)
+	case 2:		data_type	= SG_DATATYPE_Word;			break;	// 2 Byte Integer (unsigned)
+	case 3:		data_type	= SG_DATATYPE_Short;		break;	// 2 Byte Integer (signed)
+	case 4:		data_type	= SG_DATATYPE_DWord;		break;	// 4 Byte Integer (unsigned)
+	case 5:		data_type	= SG_DATATYPE_Int;			break;	// 4 Byte Integer (signed)
+	case 6:		data_type	= SG_DATATYPE_Float;		break;	// 4 Byte Floating Point
+	case 7:		data_type	= SG_DATATYPE_Double;		break;	// 8 Byte Floating Point
+	}
+
+	//-----------------------------------------------------
+	if( Table.Create(FileName) && (nx = Table.Get_Field_Count()) > 0 && (ny = Table.Get_Record_Count()) > 0 )
+	{
+		pGrid	= SG_Create_Grid(data_type, nx, ny, dxy, xmin, ymin);
+
+		for(y=0; y<ny && Set_Progress(y, ny); y++)
+		{
+			pRecord	= Table.Get_Record(bDown ? ny - 1 - y : y);
+
+			for(x=0; x<nx; x++)
+			{
+				pGrid->Set_Value(x, y, pRecord->asDouble(x));
+			}
+		}
+
+		pGrid->Set_Unit			(Unit);
+		pGrid->Set_ZFactor		(zFactor);
+		pGrid->Set_NoData_Value	(zNoData);
+		pGrid->Set_Name			(SG_File_Get_Name(FileName, false));
+
+		Parameters("GRID")->Set_Value(pGrid);
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/grid_table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Table.h                      //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Table_H
+#define HEADER_INCLUDED__Grid_Table_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Table_Import : public CSG_Module
+{
+public:
+	CGrid_Table_Import(void);
+	virtual ~CGrid_Table_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Table_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,312 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       MOLA.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mola.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CMOLA_Import::CMOLA_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Import MOLA Grid (MEGDR)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import Mars Orbit Laser Altimeter (MOLA) grids of the Mars Global Surveyor (MGS) Mission "
+		"(Topographic maps, Mission Experiment Gridded Data Records - MEGDRs). "
+		"Find more information and obtain free data from "
+		"<a target=\"_blank\" href=\"http://pds-geosciences.wustl.edu/missions/mgs/mola.html\">"
+		"Mars Global Surveyor: MOLA (NASA)</a>\n\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("MOLA Grids (*.img)|*.img|All Files|*.*")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TYPE"	, _TL("Grid Type"),
+		_TL(""),
+		_TL("2 byte integer|4 byte floating point|"), 1
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "ORIENT"	, _TL("Orientation"),
+		_TL(""),
+		_TL("normal|down under|"), 1
+	);
+}
+
+//---------------------------------------------------------
+CMOLA_Import::~CMOLA_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CMOLA_Import::On_Execute(void)
+{
+	bool			bDown;
+	int				xa, xb, y, yy, NX, NY;
+	short			*sLine;
+	double			D, xMin, yMin;
+	CSG_File		Stream;
+	TSG_Data_Type	Type;
+	CSG_Grid		*pGrid;
+	CSG_String		fName, sName;
+
+	//-----------------------------------------------------
+	pGrid	= NULL;
+
+	switch( Parameters("TYPE")->asInt() )
+	{
+	case 0:				Type	= SG_DATATYPE_Short;	break;
+	case 1: default:	Type	= SG_DATATYPE_Float;	break;
+	}
+
+	bDown	= Parameters("ORIENT")->asInt() == 1;
+
+	//-----------------------------------------------------
+	// MEGpxxnyyyrv
+	// 012345678901
+	//  p indicates the product type (A for areoid, C for counts, R for
+	//    radius, and T for topography)
+	//  xx is the latitude of the upper left corner of the image
+	//  n indicates whether the latitude is north (N) or south (S)
+	//  yyy is the east longitude of the upper left corner of the image
+	//  r is the map resolution using the pattern
+	//    c =   4 pixel per degree
+	//    e =  16 pixel per degree
+	//    f =  32 pixel per degree
+	//    g =  64 pixel per degree
+	//    h = 128 pixel per degree
+	//    (This convention is consistent with that used for the Mars Digital
+	//    Image Model [MDIM] archives.)
+	//  v is a letter indicating the product version.
+
+	fName	= SG_File_Get_Name(Parameters("FILE")->asString(), false);
+	fName.Make_Upper();
+
+	if( fName.Length() < 12 )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	switch( fName[3] )
+	{
+	default:
+		return( false );
+
+	case 'A':
+		sName.Printf(SG_T("MOLA: Areoid v%c")		, fName[11]);
+		break;
+
+	case 'C':
+		sName.Printf(SG_T("MOLA: Counts v%c")		, fName[11]);
+		break;
+
+	case 'R':
+		sName.Printf(SG_T("MOLA: Radius v%c")		, fName[11]);
+		break;
+
+	case 'T':
+		sName.Printf(SG_T("MOLA: Topography v%c")	, fName[11]);
+		break;
+	}
+
+	//-----------------------------------------------------
+	switch( fName[10] )
+	{
+	default:
+		return( false );
+
+	case 'C':	// 1/4th degree...
+		D		= 1.0 /   4.0;
+		NX		=   4 * 360;
+		NY		=   4 * 180;
+		yMin	= - 90.0;
+		xMin	= -180.0;
+		break;
+
+	case 'D':	// 1/8th degree...
+		D		= 1.0 /   8.0;
+		NX		=   8 * 360;
+		NY		=   8 * 180;
+		yMin	= - 90.0;
+		xMin	= -180.0;
+		break;
+
+	case 'E':	// 1/16th degree...
+		D		= 1.0 /  16.0;
+		NX		=  16 * 360;
+		NY		=  16 * 180;
+		yMin	= - 90.0;
+		xMin	= -180.0;
+		break;
+
+	case 'F':	// 1/32th degree...
+		D		= 1.0 /  32.0;
+		NX		=  32 * 360;
+		NY		=  32 * 180;
+		yMin	= - 90.0;
+		xMin	= -180.0;
+		break;
+
+	case 'G':	// 1/64th degree...
+		D		= 1.0 /  64.0;
+		NX		=  64 * 180;
+		NY		=  64 *  90;
+		yMin	= (fName[6] == 'S' ? -1.0 :  1.0) * fName.Right(3).asInt();
+		yMin	= yMin - NY * D;
+		xMin	= fName.Right(6).asInt();
+		if( xMin >= 180.0 )
+		{
+			xMin	-= 360.0;
+		}
+		break;
+
+	case 'H':	// 1/128th degree...
+		D		= 1.0 / 128.0;
+		NX		= 128 *  90;
+		NY		= 128 *  44;
+		yMin	= (fName[6] == 'S' ? -1.0 :  1.0) * fName.Right(3).asInt();
+		yMin	= yMin - NY * D;
+		xMin	= fName.Right(6).asInt();
+		if( xMin >= 180.0 )
+		{
+			xMin	-= 360.0;
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( Stream.Open(Parameters("FILE")->asString(), SG_FILE_R, true) )
+	{
+		if( (pGrid = SG_Create_Grid(Type, NX, NY, D, xMin + D / 2.0, yMin + D / 2.0)) != NULL )
+		{
+			pGrid->Set_Name(sName);
+			pGrid->Set_NoData_Value(-999999);
+
+			//---------------------------------------------
+			sLine	= (short *)SG_Malloc(NX * sizeof(short));
+
+			for(y=0; y<NY && !Stream.is_EOF() && Set_Progress(y, NY); y++)
+			{
+				yy	= bDown ? NY - 1 - y : y;
+
+				Stream.Read(sLine, NX, sizeof(short));
+
+				if( fName[10] == 'G' || fName[10] == 'H' )
+				{
+					for(xa=0; xa<NX; xa++)
+					{
+						SG_Swap_Bytes(sLine + xa, sizeof(short));
+
+						pGrid->Set_Value(xa, yy, sLine[xa]);
+					}
+				}
+				else
+				{
+					for(xa=0, xb=NX/2; xb<NX; xa++, xb++)
+					{
+						SG_Swap_Bytes(sLine + xa, sizeof(short));
+						SG_Swap_Bytes(sLine + xb, sizeof(short));
+
+						pGrid->Set_Value(xa, yy, sLine[xb]);
+						pGrid->Set_Value(xb, yy, sLine[xa]);
+					}
+				}
+			}
+
+			//---------------------------------------------
+			SG_Free(sLine);
+
+			Parameters("GRID")->Set_Value(pGrid);
+		}
+	}
+
+	return( pGrid != NULL );
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/mola.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,88 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        MOLA.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//							MOLA.h						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__MOLA_Import_H
+#define HEADER_INCLUDED__MOLA_Import_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CMOLA_Import : public CSG_Module
+{
+public:
+	CMOLA_Import(void);
+	virtual ~CMOLA_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)				{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__MOLA_Import_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,363 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Raw.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "raw.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CRaw_Import::CRaw_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Import Binary Raw Data"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Imports grid from binary raw data.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"			, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE_DATA"		, _TL("Raw Data File"),
+		_TL("")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "NX"				, _TL("Cell Count (X)"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NY"				, _TL("Cell Count (Y)"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DXY"				, _TL("Cell Size"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "XMIN"			, _TL("Left Border (X)"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "YMIN"			, _TL("Lower Border (Y)"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0
+	);
+
+	Parameters.Add_String(
+		NULL	, "UNIT"			, _TL("Unit Name"),
+		_TL(""),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ZFACTOR"			, _TL("Z Multiplier"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NODATA"			, _TL("No Data Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, -99999.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DATA_OFFSET"		, _TL("Data Offset (Bytes)"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LINE_OFFSET"		, _TL("Line Offset (Bytes)"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LINE_ENDSET"		, _TL("Line Endset (Bytes)"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 0.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "DATA_TYPE"		, _TL("Data Type"),
+		_TL(""),
+		_TW(
+			"1 Byte Integer (unsigned)|"
+			"1 Byte Integer (signed)|"
+			"2 Byte Integer (unsigned)|"
+			"2 Byte Integer (signed)|"
+			"4 Byte Integer (unsigned)|"
+			"4 Byte Integer (signed)|"
+			"4 Byte Floating Point|"
+			"8 Byte Floating Point|"
+		)
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "BYTEORDER_BIG"	, _TL("Byte Order"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Little Endian (Intel)"),
+			_TL("Big Endian (Motorola)")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "TOPDOWN"			, _TL("Line Order"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Bottom to Top"),
+			_TL("Top to Bottom")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CRaw_Import::~CRaw_Import(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRaw_Import::On_Execute(void)
+{
+	bool		bDown, bBig;
+	int			nx, ny, data_head, line_head, line_tail;
+	double		dxy, xmin, ymin, zFactor, zNoData;
+	FILE		*Stream;
+	TSG_Data_Type	data_type;
+	CSG_String	FileName, Unit;
+	CSG_Grid		*pGrid;
+
+	//-----------------------------------------------------
+	pGrid		= NULL;
+
+	FileName	= Parameters("FILE_DATA")		->asString();
+	nx			= Parameters("NX")				->asInt();
+	ny			= Parameters("NY")				->asInt();
+	dxy			= Parameters("DXY")				->asDouble();
+	xmin		= Parameters("XMIN")			->asDouble();
+	ymin		= Parameters("YMIN")			->asDouble();
+	data_head	= Parameters("DATA_OFFSET")		->asInt();
+	line_head	= Parameters("LINE_OFFSET")		->asInt();
+	line_tail	= Parameters("LINE_ENDSET")		->asInt();
+	bDown		= Parameters("TOPDOWN")			->asInt() == 1;
+	bBig		= Parameters("BYTEORDER_BIG")	->asInt() == 1;
+	Unit		= Parameters("UNIT")			->asString();
+	zFactor		= Parameters("ZFACTOR")			->asDouble();
+	zNoData		= Parameters("NODATA")			->asDouble();
+
+	switch( Parameters("DATA_TYPE")->asInt() )
+	{
+	default:	data_type	= SG_DATATYPE_Undefined;	break;	// not handled
+	case 0:		data_type	= SG_DATATYPE_Byte;			break;	// 1 Byte Integer (unsigned)
+	case 1:		data_type	= SG_DATATYPE_Char;			break;	// 1 Byte Integer (signed)
+	case 2:		data_type	= SG_DATATYPE_Word;			break;	// 2 Byte Integer (unsigned)
+	case 3:		data_type	= SG_DATATYPE_Short;		break;	// 2 Byte Integer (signed)
+	case 4:		data_type	= SG_DATATYPE_DWord;		break;	// 4 Byte Integer (unsigned)
+	case 5:		data_type	= SG_DATATYPE_Int;			break;	// 4 Byte Integer (signed)
+	case 6:		data_type	= SG_DATATYPE_Float;		break;	// 4 Byte Floating Point
+	case 7:		data_type	= SG_DATATYPE_Double;		break;	// 8 Byte Floating Point
+	}
+
+	//-----------------------------------------------------
+	if( data_type != SG_DATATYPE_Undefined && (Stream = fopen(FileName.b_str(), "rb")) != NULL )
+	{
+		if( (pGrid = Load_Data(Stream, data_type, nx, ny, dxy, xmin, ymin, data_head, line_head, line_tail, bDown, bBig)) != NULL )
+		{
+			pGrid->Set_Unit			(Unit);
+			pGrid->Set_ZFactor		(zFactor);
+			pGrid->Set_NoData_Value	(zNoData);
+			pGrid->Set_Name			(SG_File_Get_Name(FileName, false));
+
+			Parameters("GRID")->Set_Value(pGrid);
+		}
+
+		fclose(Stream);
+	}
+
+	//-----------------------------------------------------
+	return( pGrid != NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid * CRaw_Import::Load_Data(FILE *Stream, TSG_Data_Type data_type, int nx, int ny, double dxy, double xmin, double ymin, int data_head, int line_head, int line_tail, bool bDown, bool bBig)
+{
+	char	*pLine, *pValue;
+	int		x, y, nBytes_Value, nBytes_Line;
+
+	CSG_Grid	*pGrid	= NULL;
+
+	//-----------------------------------------------------
+	if( Stream && data_type != SG_DATATYPE_Undefined )
+	{
+		for(x=0; x<data_head && !feof(Stream); x++)
+		{
+			fgetc(Stream);
+		}
+
+		//-------------------------------------------------
+		if( !feof(Stream) )
+		{
+			pGrid			= SG_Create_Grid(data_type, nx, ny, dxy, xmin, ymin);
+			nBytes_Value	= SG_Data_Type_Get_Size(data_type);
+			nBytes_Line		= nBytes_Value * nx;
+			pLine			= (char *)SG_Malloc(nBytes_Line);
+
+			//---------------------------------------------
+			for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++)
+			{
+				for(x=0; x<line_head; x++)
+				{
+					fgetc(Stream);
+				}
+
+				fread(pLine, nBytes_Line, sizeof(char), Stream);
+
+				for(x=0, pValue=pLine; x<pGrid->Get_NX(); x++, pValue+=nBytes_Value)
+				{
+					if( bBig )
+					{
+						SG_Swap_Bytes(pValue, nBytes_Value);
+					}
+
+					switch( data_type )
+					{
+					case SG_DATATYPE_Byte:		pGrid->Set_Value(x, y, *(unsigned char  *)pValue);	break;	// 1 Byte Integer (unsigned)
+					case SG_DATATYPE_Char:		pGrid->Set_Value(x, y, *(signed char    *)pValue);	break;	// 1 Byte Integer (signed)
+					case SG_DATATYPE_Word:		pGrid->Set_Value(x, y, *(unsigned short *)pValue);	break;	// 2 Byte Integer (unsigned)
+					case SG_DATATYPE_Short:		pGrid->Set_Value(x, y, *(signed short   *)pValue);	break;	// 2 Byte Integer (signed)
+					case SG_DATATYPE_DWord:		pGrid->Set_Value(x, y, *(unsigned int   *)pValue);	break;	// 4 Byte Integer (unsigned)
+					case SG_DATATYPE_Int:		pGrid->Set_Value(x, y, *(signed int     *)pValue);	break;	// 4 Byte Integer (signed)
+					case SG_DATATYPE_Float:		pGrid->Set_Value(x, y, *(float          *)pValue);	break;	// 4 Byte Floating Point
+					case SG_DATATYPE_Double:	pGrid->Set_Value(x, y, *(double         *)pValue);	break;	// 8 Byte Floating Point
+					}
+				}
+
+				for(x=0; x<line_tail; x++)
+				{
+					fgetc(Stream);
+				}
+			}
+
+			//---------------------------------------------
+			SG_Free(pLine);
+
+			if( bDown )
+			{
+				pGrid->Flip();
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( pGrid );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/raw.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                         Raw.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Raw_Import_H
+#define HEADER_INCLUDED__Raw_Import_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CRaw_Import : public CSG_Module
+{
+public:
+	CRaw_Import(void);
+	virtual ~CRaw_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid *					Load_Data		(FILE *Stream, TSG_Data_Type data_type, int nx, int ny, double dxy, double xmin, double ymin, int data_head, int line_head, int line_tail, bool bDown, bool bBig);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Raw_Import_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,297 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      SRTM30.cpp                       //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "srtm30.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSRTM30_Import::CSRTM30_Import(void)
+{
+	CSG_Parameter	*pNode_0;
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Import SRTM30 DEM"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Extracts elevation grids from SRTM30 data.\n\n"
+
+		"<i>\"SRTM30 is a near-global digital elevation model (DEM) comprising a "
+		"combination of data from the Shuttle Radar Topography Mission, flown "
+		"in February, 2000 and the the U.S. Geological Survey's GTOPO30 data "
+		"set. It can be considered to be either an SRTM data set enhanced with "
+		"GTOPO30, or as an upgrade to GTOPO30.\"</i> (NASA)\n\n"
+
+		"Further information about the GTOPO30 data set:\n"
+		"<a target=\"_blank\" href=\"http://edcdaac.usgs.gov/gtopo30/gtopo30.html\">"
+		"http://edcdaac.usgs.gov/gtopo30/gtopo30.html</a>\n\n"
+
+		"SRTM30 data can be downloaded from:\n"
+		"<a target=\"_blank\" href=\"ftp://e0srp01u.ecs.nasa.gov/srtm/version2/SRTM30/\">"
+		"ftp://e0srp01u.ecs.nasa.gov/srtm/version2/SRTM30/</a>\n\n"
+
+		"A directory, that contains the uncompressed SRTM30 DEM files, can be located using "
+		"the \"Path\" Parameter of this module.")
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	pNode_0	= Parameters.Add_FilePath(
+		NULL	, "PATH"		, _TL("Path"),
+		_TL(""),
+		NULL, NULL, false, true
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "XMIN"		, _TL("West []"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 60.0
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "XMAX"		, _TL("East []"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 120.0
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "YMIN"		, _TL("South []"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 20.0
+	);
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "YMAX"		, _TL("North []"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 50.0
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("TILE", _TL(""), _TL(""));
+
+	pNode_0	= pParameters->Add_Info_String(
+		NULL	, "INFO"		, _TL("File does not exist:"),
+		_TL(""),
+		_TL("")
+	);
+
+	pNode_0	= pParameters->Add_FilePath(
+		NULL	, "PATH"		, _TL("Select file"),
+		_TL(""),
+		_TL("SRTM30 DEM Tiles (*.dem)|*.dem|All Files|*.*")
+	);
+}
+
+//---------------------------------------------------------
+CSRTM30_Import::~CSRTM30_Import(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define	X_WIDTH		4800
+#define	Y_WIDTH		6000
+
+//---------------------------------------------------------
+bool CSRTM30_Import::On_Execute(void)
+{
+	char	x_sTile[9][5]	= {	"W180", "W140", "W100", "W060", "W020", "E020", "E060", "E100", "E140"	},
+			y_sTile[3][4]	= {	"S10", "N40", "N90"	};
+
+	double	dSize			= 30.0 / (60.0 * 60.0);
+
+	//-----------------------------------------------------
+	int			xTile, yTile;
+	double		xMin, xMax, yMin, yMax;
+	TSG_Rect	rOut, rTile;
+	CSG_String	sTile;
+	CSG_Grid		*pOut;
+
+	//-----------------------------------------------------
+	xMin		= Parameters("XMIN")->asInt();
+	xMax		= Parameters("XMAX")->asInt();
+	yMin		= Parameters("YMIN")->asInt();
+	yMax		= Parameters("YMAX")->asInt();
+
+	rOut.xMin	= (180 + xMin) / 40.0 * X_WIDTH;
+	rOut.xMax	= rOut.xMin + (int)((xMax - xMin) / dSize);
+	rOut.yMin	= ( 60 + yMin) / 50.0 * Y_WIDTH;
+	rOut.yMax	= rOut.yMin + (int)((yMax - yMin) / dSize);
+
+	//-----------------------------------------------------
+	pOut		= SG_Create_Grid(SG_DATATYPE_Short,
+					(int)(rOut.xMax - rOut.xMin),
+					(int)(rOut.yMax - rOut.yMin),
+					dSize,
+					xMin + 0.5 * dSize,
+					yMin + 0.5 * dSize
+				);
+
+	pOut->Set_NoData_Value(-9999);
+	pOut->Assign_NoData();
+	pOut->Set_Name(SG_T("SRTM30"));
+
+	//-----------------------------------------------------
+	for(yTile=0, rTile.yMin=0, rTile.yMax=Y_WIDTH; yTile<3; yTile++, rTile.yMin+=Y_WIDTH, rTile.yMax+=Y_WIDTH)
+	{
+		for(xTile=0, rTile.xMin=0, rTile.xMax=X_WIDTH; xTile<9; xTile++, rTile.xMin+=X_WIDTH, rTile.xMax+=X_WIDTH)
+		{
+			sTile.Printf(SG_T("Tile: %s%s"), x_sTile[xTile], y_sTile[yTile]);
+			Process_Set_Text(sTile);
+
+			sTile.Printf(SG_T("%s%s%s.dem"), Parameters("PATH")->asString(), x_sTile[xTile], y_sTile[yTile]);
+			Tile_Load(sTile, rTile, pOut, rOut);
+		}
+	}
+
+	//-----------------------------------------------------
+	Parameters("GRID")->Set_Value(pOut);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSRTM30_Import::Tile_Load(const SG_Char *sTile, TSG_Rect &rTile, CSG_Grid *pOut, TSG_Rect &rOut)
+{
+	short		Value;
+	int			x, y, xOut, yOut;
+	FILE		*Stream;
+	CSG_Rect	r(rTile);
+
+	if( r.Intersects(rOut) != INTERSECTION_None && (Stream = Tile_Open(sTile)) != NULL )
+	{
+		for(y=0, yOut=(int)(rTile.yMax-rOut.yMin); y<Y_WIDTH && yOut>=0 && Set_Progress(y, Y_WIDTH); y++, yOut--)
+		{
+			for(x=0, xOut=(int)(rTile.xMin-rOut.xMin); x<X_WIDTH; x++, xOut++)
+			{
+				fread(&Value, 1, sizeof(short), Stream);
+
+				if(	xOut >= 0 && xOut < pOut->Get_NX() && yOut >= 0 && yOut < pOut->Get_NY() )
+				{
+					SG_Swap_Bytes(&Value, sizeof(short));
+
+					pOut->Set_Value(xOut, yOut, Value);
+				}
+			}
+		}
+
+		fclose(Stream);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+FILE * CSRTM30_Import::Tile_Open(const SG_Char *sTile)
+{
+	const SG_Char	*sPath;
+	FILE			*Stream;
+	CSG_String		fName;
+	CSG_Parameters	*pParameters;
+
+	fName	= sTile;
+
+	if( (Stream = fopen(fName.b_str(), "rb")) == NULL )
+	{
+		pParameters	= Get_Parameters("TILE");
+		pParameters->Get_Parameter("INFO")->Set_Value(sTile);
+
+		if( Dlg_Parameters(pParameters, _TL("Locate STRM30 Data File")) && (sPath = pParameters->Get_Parameter("PATH")->asString()) != NULL )
+		{
+			fName	= sPath;
+			Stream	= fopen(fName.b_str(), "rb");
+		}
+	}
+
+	return( Stream );
+}

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/srtm30.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,91 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       SRTM30.h                        //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Import_SRTM30_H
+#define HEADER_INCLUDED__Import_SRTM30_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CSRTM30_Import : public CSG_Module
+{
+public:
+	CSRTM30_Import(void);
+	virtual ~CSRTM30_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)				{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	bool					Tile_Load(const SG_Char *sTile, TSG_Rect &rTile, CSG_Grid *pOut, TSG_Rect &rOut);
+	FILE *					Tile_Open(const SG_Char *sTile);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Import_SRTM30_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,455 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Surfer.cpp                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "surfer.h"
+
+//---------------------------------------------------------
+#define NODATAVALUE	1.70141e38f
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSurfer_Import::CSurfer_Import(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Import Surfer Grid"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import grid from Golden Software's Surfer grid format.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("Surfer Grid (*.grd)|*.grd|All Files|*.*")
+	);
+
+	pNode	= Parameters.Add_Choice(
+		NULL	, "NODATA"	, _TL("No Data Value"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Surfer's No Data Value"),
+			_TL("User Defined")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NODATA_VAL"	, _TL("User Defined No Data Value"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, -99999.0
+	);
+}
+
+//---------------------------------------------------------
+CSurfer_Import::~CSurfer_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CSurfer_Import::On_Execute(void)
+{
+	int			x, y, NX, NY;
+	short		sValue;
+	long		lValue;
+	float		*fLine;
+	double		*dLine, dValue, DX, DY, xMin, yMin;
+	FILE		*Stream;
+	CSG_String	fName;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	pGrid	= NULL;
+	fName	= Parameters("FILE")->asString();
+
+	//-----------------------------------------------------
+	if( fName.Length() > 0 && (Stream = fopen(fName.b_str(), "rb")) != NULL )
+	{
+		fread(&lValue, 1, sizeof(long), Stream);
+
+		//-------------------------------------------------
+		// Surfer 7: Binary...
+
+		if( !strncmp((char *)&lValue, "DSRB", 4) )
+		{
+			fread(&lValue, 1, sizeof(long)	, Stream);			// SectionSize...
+			fread(&lValue, 1, sizeof(long)	, Stream);			// Version
+			fread(&lValue, 1, sizeof(long)	, Stream);
+
+			if( lValue == 0x44495247 )							// Grid-Header...
+			{
+				fread(&lValue	, 1, sizeof(long)	, Stream);	// SectionSize...
+
+				fread(&lValue	, 1, sizeof(long)	, Stream);	// NX...
+				NY		= (int)lValue;
+				fread(&lValue	, 1, sizeof(long)	, Stream);	// NY...
+				NX		= (int)lValue;
+
+				fread(&xMin		, 1, sizeof(double)	, Stream);	// xMin...
+				fread(&yMin		, 1, sizeof(double)	, Stream);	// yMin...
+
+				fread(&DX		, 1, sizeof(double)	, Stream);	// DX...
+				fread(&DY		, 1, sizeof(double)	, Stream);	// DY...
+
+				fread(&dValue	, 1, sizeof(double)	, Stream);	// zMin...
+				fread(&dValue	, 1, sizeof(double)	, Stream);	// zMax...
+
+				fread(&dValue	, 1, sizeof(double)	, Stream);	// Rotation (unused)...
+				fread(&dValue	, 1, sizeof(double)	, Stream);	// Blank Value...
+				fread(&lValue	, 1, sizeof(long)	, Stream);	// ???...
+
+				if( lValue == 0x41544144 )						// Load Binary Double...
+				{
+					fread(&lValue, 1, sizeof(long)	, Stream);	// SectionSize...
+
+					//-------------------------------------
+					if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Double, NX, NY, DX, xMin, yMin)) != NULL )
+					{
+						dLine	= (double *)SG_Malloc(pGrid->Get_NX() * sizeof(double));
+
+						for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++)
+						{
+							fread(dLine, pGrid->Get_NX(), sizeof(double), Stream);
+
+							for(x=0; x<pGrid->Get_NX(); x++)
+							{
+								pGrid->Set_Value(x, y, dLine[x]);
+							}
+						}
+
+						SG_Free(dLine);
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		// Surfer 6: Binary...
+
+		else if( !strncmp((char *)&lValue, "DSBB", 4) )
+		{
+			fread(&sValue	, 1, sizeof(short)	, Stream);
+			NX		= sValue;
+			fread(&sValue	, 1, sizeof(short)	, Stream);
+			NY		= sValue;
+
+			fread(&xMin		, 1, sizeof(double)	, Stream);
+			fread(&dValue	, 1, sizeof(double)	, Stream);	// XMax
+			DX		= (dValue - xMin) / (NX - 1.0);
+
+			fread(&yMin		, 1, sizeof(double)	, Stream);
+			fread(&dValue	, 1, sizeof(double)	, Stream);	// YMax...
+			DY		= (dValue - yMin) / (NY - 1.0);
+
+			fread(&dValue	, 1, sizeof(double)	, Stream);	// ZMin...
+			fread(&dValue	, 1, sizeof(double)	, Stream);	// ZMax...
+
+			//---------------------------------------------
+			if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Float, NX, NY, DX, xMin, yMin)) != NULL )
+			{
+				fLine	= (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float));
+
+				for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++)
+				{
+					fread(fLine, pGrid->Get_NX(), sizeof(float), Stream);
+
+					for(x=0; x<pGrid->Get_NX(); x++)
+					{
+						pGrid->Set_Value(x, y, fLine[x]);
+					}
+				}
+
+				SG_Free(fLine);
+			}
+		}
+
+		//-------------------------------------------------
+		// Surfer 6: ASCII...
+
+		else if( !strncmp((char *)&lValue, "DSAA", 4) )
+		{
+			fscanf(Stream, "%d %d"	, &NX	, &NY);
+
+			fscanf(Stream, "%lf %lf", &xMin	, &dValue);
+			DX		= (dValue - xMin) / (NX - 1.0);
+
+			fscanf(Stream, "%lf %lf", &yMin	, &dValue);
+			DY		= (dValue - yMin) / (NY - 1.0);
+
+			fscanf(Stream, "%lf %lf", &dValue, &dValue);
+
+			//---------------------------------------------
+			if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Float, NX, NY, DX, xMin, yMin)) != NULL )
+			{
+				for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++)
+				{
+					for(x=0; x<pGrid->Get_NX(); x++)
+					{
+						fscanf(Stream, "%lf", &dValue);
+
+						pGrid->Set_Value(x, y, dValue);
+					}
+				}
+			}
+		}
+
+		fclose(Stream);
+	}
+
+	//-----------------------------------------------------
+	if( pGrid )
+	{
+		pGrid->Set_Name(Parameters("FILE")->asString());
+		pGrid->Set_NoData_Value(Parameters("NODATA")->asInt() == 0 ? NODATAVALUE : Parameters("NODATA_VAL")->asDouble());
+
+		Parameters("GRID")->Set_Value(pGrid);
+	}
+
+	return( pGrid != NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSurfer_Export::CSurfer_Export(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Export Surfer Grid"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Export grid to Golden Software's Surfer grid format.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL(
+		"Surfer Grid (*.grd)|*.grd|All Files|*.*"), NULL, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "FORMAT"	, _TL("Format"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("binary"),
+			_TL("ASCII")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NODATA"	, _TL("Use Surfer's No-Data Value"),
+		_TL(""),
+		PARAMETER_TYPE_Bool	, false
+	);
+}
+
+//---------------------------------------------------------
+CSurfer_Export::~CSurfer_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CSurfer_Export::On_Execute(void)
+{
+	const char	ID_BINARY[]	= "DSBB";
+
+	bool		bNoData;
+	short		sValue;
+	int			x, y;
+	float		*fLine;
+	double		dValue;
+	FILE		*Stream;
+	CSG_String	fName;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")	->asGrid();
+	fName	= Parameters("FILE")	->asString();
+	bNoData	= Parameters("NODATA")	->asBool();
+
+	switch( Parameters("FORMAT")->asInt() )
+	{
+	//-----------------------------------------------------
+	case 0:	// Surfer 6 - Binary...
+
+		if( (Stream = fopen(fName.b_str(), "wb")) != NULL )
+		{
+			fwrite(ID_BINARY, 4, sizeof(char  ), Stream);
+
+			sValue	= (short)pGrid->Get_NX();
+			fwrite(&sValue	, 1, sizeof(short ), Stream);
+			sValue	= (short)pGrid->Get_NY();
+			fwrite(&sValue	, 1, sizeof(short ), Stream);
+
+			dValue	= pGrid->Get_XMin();
+			fwrite(&dValue	, 1, sizeof(double), Stream);
+			dValue	= pGrid->Get_XMax();
+			fwrite(&dValue	, 1, sizeof(double), Stream);
+
+			dValue	= pGrid->Get_YMin();
+			fwrite(&dValue	, 1, sizeof(double), Stream);
+			dValue	= pGrid->Get_YMax();
+			fwrite(&dValue	, 1, sizeof(double), Stream);
+
+			dValue	= pGrid->Get_ZMin();
+			fwrite(&dValue	, 1, sizeof(double), Stream);
+			dValue	= pGrid->Get_ZMax();
+			fwrite(&dValue	, 1, sizeof(double), Stream);
+
+			//---------------------------------------------
+			fLine	= (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float));
+
+			for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
+			{
+				for(x=0; x<pGrid->Get_NX(); x++)
+				{
+					fLine[x]	= bNoData && pGrid->is_NoData(x, y) ? NODATAVALUE : pGrid->asFloat(x, y);
+				}
+
+				fwrite(fLine, pGrid->Get_NX(), sizeof(float), Stream);
+			}
+
+			SG_Free(fLine);
+
+			fclose(Stream);
+
+			return( true );
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 1:	// Surfer - ASCII...
+
+		if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+		{
+			fprintf(Stream, "DSAA\n" );
+			fprintf(Stream, "%d %d\n", pGrid->Get_NX()	, pGrid->Get_NY()	);
+			fprintf(Stream, "%f %f\n", pGrid->Get_XMin(), pGrid->Get_XMax()	);
+			fprintf(Stream, "%f %f\n", pGrid->Get_YMin(), pGrid->Get_YMax()	);
+			fprintf(Stream, "%f %f\n", pGrid->Get_ZMin(), pGrid->Get_ZMax()	);
+
+			//---------------------------------------------
+			for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
+			{
+				for(x=0; x<pGrid->Get_NX(); x++)
+				{
+					if( bNoData && pGrid->is_NoData(x, y) )
+					{
+						fprintf(Stream, "1.70141e38 ");
+					}
+					else
+					{
+						fprintf(Stream, "%f ", pGrid->asFloat(x, y));
+					}
+				}
+
+				fprintf(Stream, "\n");
+			}
+
+			fclose(Stream);
+
+			return( true );
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/surfer.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Surfer.h                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Surfer.h						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Surfer_H
+#define HEADER_INCLUDED__Surfer_H
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CSurfer_Import : public CSG_Module
+{
+public:
+	CSurfer_Import(void);
+	virtual ~CSurfer_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)				{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+//---------------------------------------------------------
+class CSurfer_Export : public CSG_Module_Grid
+{
+public:
+	CSurfer_Export(void);
+	virtual ~CSurfer_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)				{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Surfer_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,242 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     USGS_SRTM.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "usgs_srtm.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CUSGS_SRTM_Import::CUSGS_SRTM_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Import USGS SRTM Grid"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import grid from USGS SRTM (Shuttle Radar Topography Mission) data.\n"
+
+		"You find data and further information at:\n"
+		"  <a target=\"_blank\" href=\"ftp://e0srp01u.ecs.nasa.gov/srtm/\">"
+		"  ftp://e0srp01u.ecs.nasa.gov/srtm/</a>\n"
+		"  <a target=\"_blank\" href=\"http://seamless.usgs.gov/\">"
+		"  http://seamless.usgs.gov/</a>\n"
+		"  <a target=\"_blank\" href=\"http://www.jpl.nasa.gov/srtm/\">"
+		"  http://www.jpl.nasa.gov/srtm/</a>\n"
+
+		"\nFarr, T.G., M. Kobrick (2000):\n"
+		"  'Shuttle Radar Topography Mission produces a wealth of data',\n"
+		"  Amer. Geophys. Union Eos, v. 81, p. 583-585\n"
+
+		"\nRosen, P.A., S. Hensley, I.R. Joughin, F.K. Li, S.N. Madsen, E. Rodriguez, R.M. Goldstein (2000):\n"
+		"  'Synthetic aperture radar interferometry'\n"
+		"  Proc. IEEE, v. 88, p. 333-382\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"	, _TL("Grids"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, false
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("Files"),
+		_TL(""),
+		_TL("USGS SRTM Grids (*.hgt)|*.hgt|All Files|*.*"), NULL, false, false, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "RESOLUTION"	, _TL("Resolution"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("1 arc-second"),
+			_TL("3 arc-second")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CUSGS_SRTM_Import::~CUSGS_SRTM_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CUSGS_SRTM_Import::On_Execute(void)
+{
+	int						N;
+	double					D;
+	CSG_Strings				fNames;
+	CSG_Grid				*pGrid;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	pGrids	= Parameters("GRIDS")->asGridList();
+	pGrids	->Del_Items();
+
+	//-----------------------------------------------------
+	switch( Parameters("RESOLUTION")->asInt() )
+	{
+	default:
+		return( false );
+
+	case 0:	// 1 arcsec...
+		N			= 3601;
+		D			= 1.0 / 3600.0;
+		break;
+
+	case 1:	// 3 arcsec...
+		N			= 1201;
+		D			= 3.0 / 3600.0;
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( Parameters("FILE")->asFilePath()->Get_FilePaths(fNames) && fNames.Get_Count() > 0 )
+	{
+		for(int i=0; i<fNames.Get_Count(); i++)
+		{
+			if( (pGrid = Load(fNames.Get_String(i), N, D)) != NULL )
+			{
+				pGrids->Add_Item(pGrid);
+			}
+		}
+
+		return( pGrids->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CUSGS_SRTM_Import::Load(CSG_String File, int N, double D)
+{
+	int			x, y;
+	short		*sLine;
+	double		xMin, yMin;
+	FILE		*Stream;
+	CSG_String	fName;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	pGrid	= NULL;
+	fName	= SG_File_Get_Name(File, false);
+
+	if( fName.Length() >= 7 )
+	{
+		fName	.Make_Upper();
+
+		Process_Set_Text(CSG_String::Format(SG_T("%s: %s"), _TL("Importing"), fName.c_str()));
+
+		yMin	= (fName[0] == 'N' ?  1.0 : -1.0) * fName.Right(6).asInt();
+		xMin	= (fName[3] == 'W' ? -1.0 :  1.0) * fName.Right(3).asInt();
+
+		//-------------------------------------------------
+		if( (Stream = fopen(File.b_str(), "rb")) != NULL )
+		{
+			if( (pGrid = SG_Create_Grid(SG_DATATYPE_Float, N, N, D, xMin, yMin)) != NULL )
+			{
+				pGrid->Set_Name			(fName);
+				pGrid->Set_NoData_Value	(-32768);
+
+				//-----------------------------------------
+				sLine	= (short *)SG_Malloc(N * sizeof(short));
+
+				for(y=0; y<N && !feof(Stream) && Set_Progress(y, N); y++)
+				{
+					fread(sLine, N, sizeof(short), Stream);
+
+					for(x=0; x<N; x++)
+					{
+						SG_Swap_Bytes(sLine + x, sizeof(short));
+
+						pGrid->Set_Value(x, N - 1 - y, sLine[x]);
+					}
+				}
+
+				SG_Free(sLine);
+			}
+
+			fclose(Stream);
+		}
+	}
+
+	return( pGrid );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/usgs_srtm.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,90 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      USGS_SRTM.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						USGS_SRTM.h						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__USGS_SRTM_H
+#define HEADER_INCLUDED__USGS_SRTM_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CUSGS_SRTM_Import : public CSG_Module
+{
+public:
+	CUSGS_SRTM_Import(void);
+	virtual ~CUSGS_SRTM_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid *				Load			(CSG_String fName, int N, double D);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__USGS_SRTM_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,363 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        XYZ.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "xyz.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CXYZ_Export::CXYZ_Export(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Export Grid to XYZ"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2003"));
+
+	Set_Description	(_TW(
+		"Export grid to a table (text format), that contains for each grid cell "
+		"the x/y-coordinates and additionally data from selected grids.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_List(
+		NULL	, "GRIDS"		, _TL("Grids"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("File Name"),
+		_TL(""),
+		CSG_String::Format(
+			SG_T("%s|*.xyz|%s|*.txt|%s|*.*"),
+			_TL("XYZ files (*.xyz)"),
+			_TL("Text files (*.txt)"),
+			_TL("All Files")
+		), NULL, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CAPTION"		, _TL("Write Field Names"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+	);
+}
+
+//---------------------------------------------------------
+bool CXYZ_Export::On_Execute(void)
+{
+	int						x, y, i;
+	TSG_Point				p;
+	CSG_File				Stream;
+	CSG_String				FileName;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	pGrids		= Parameters("GRIDS")	->asGridList();
+	FileName	= Parameters("FILENAME")->asString();
+
+	if( pGrids->Get_Count() > 0 && Stream.Open(FileName, SG_FILE_W, false) )
+	{
+		if( Parameters("CAPTION")->asBool() )
+		{
+			Stream.Printf(SG_T("\"X\"\t\"Y\""));
+
+			for(i=0; i<pGrids->Get_Count(); i++)
+			{
+				Stream.Printf(SG_T("\t\"%s\""), pGrids->asGrid(i)->Get_Name());
+			}
+
+			Stream.Printf(SG_T("\n"));
+		}
+
+		for(y=0, p.y=Get_YMin(); y<Get_NY() && Set_Progress(y); y++, p.y+=Get_Cellsize())
+		{
+			for(x=0, p.x=Get_XMin(); x<Get_NX(); x++, p.x+=Get_Cellsize())
+			{
+				Stream.Printf(SG_T("%f\t%f"), p.x,  p.y);
+
+				for(i=0; i<pGrids->Get_Count(); i++)
+				{
+					Stream.Printf(SG_T("\t%f"), pGrids->asGrid(i)->asDouble(x, y));
+				}
+
+				Stream.Printf(SG_T("\n"));
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CXYZ_Import::CXYZ_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Import Grid from XYZ"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"Import grid from a table (text format), that contains for each grid cell "
+		"the x/y/z-coordinates and additional data from selected grids.\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "COUNT"		, _TL("Count"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("File Name"),
+		_TL(""),
+		CSG_String::Format(
+			SG_T("%s|*.xyz|%s|*.txt|%s|*.*"),
+			_TL("XYZ files (*.xyz)"),
+			_TL("Text files (*.txt)"),
+			_TL("All Files")
+		), NULL, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CAPTION"		, _TL("Has Field Names"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CELLSIZE"	, _TL("Target Cellsize"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SEPARATOR"	, _TL("Separator"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|,|;|"),
+			_TL("space"),
+			_TL("tabulator")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+bool CXYZ_Import::On_Execute(void)
+{
+	int			nx, ny, nValues, fLength;
+	double		x, y, z, xMin, yMin, xMax, yMax, Cellsize;
+	CSG_File	Stream;
+	CSG_String	FileName, sLine;
+	CSG_Grid	*pGrid, *pCount;
+
+	FileName	= Parameters("FILENAME")->asString();
+	Cellsize	= Parameters("CELLSIZE")->asDouble();
+
+	switch( Parameters("SEPARATOR")->asInt() )
+	{
+	case 0:	m_Separator	= SG_T(' ');	break;
+	case 1:	m_Separator	= SG_T('\t');	break;
+	case 2:	m_Separator	= SG_T(',');	break;
+	case 3:	m_Separator	= SG_T(';');	break;
+	}
+
+	if( Cellsize > 0.0 && Stream.Open(FileName, SG_FILE_R, false) )
+	{
+		if( Parameters("CAPTION")->asBool() )
+		{
+			Stream.Read_Line(sLine);
+		}
+
+		fLength	= Stream.Length();
+		nValues	= 0;
+
+		while( Read_Values(Stream, x, y, z) && Set_Progress(Stream.Tell(), fLength) )
+		{
+			if( nValues == 0 )
+			{
+				xMin	= xMax	= x;
+				yMin	= yMax	= y;
+			}
+			else
+			{
+				if( xMin > x )	xMin	= x;	else if( xMax < x )	xMax	= x;
+				if( yMin > y )	yMin	= y;	else if( yMax < y )	yMax	= y;
+			}
+
+			nValues++;
+		}
+
+		//-------------------------------------------------
+		if( xMin < xMax && yMin < yMax )
+		{
+			nx		= 1 + (int)((xMax - xMin) / Cellsize);
+			ny		= 1 + (int)((yMax - yMin) / Cellsize);
+
+			Parameters("GRID" )->Set_Value(pGrid  = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, Cellsize, xMin, yMin));
+			Parameters("COUNT")->Set_Value(pCount = SG_Create_Grid(SG_DATATYPE_Byte , nx, ny, Cellsize, xMin, yMin));
+
+			if( pGrid && pCount )
+			{
+				pGrid	->Set_Name(FileName = SG_File_Get_Name(FileName, false));
+				pCount	->Set_Name(CSG_String::Format(SG_T("%s [%s]"), FileName.c_str(), _TL("Count")));
+
+				Stream.Seek_Start();
+
+				if( Parameters("CAPTION")->asBool() )
+				{
+					Stream.Read_Line(sLine);
+				}
+
+				while( Read_Values(Stream, x, y, z) && Set_Progress(Stream.Tell(), fLength) )
+				{
+					if( pGrid->Get_System().Get_World_to_Grid(nx, ny, x, y) )
+					{
+						pGrid ->Add_Value(nx, ny, z);
+						pCount->Add_Value(nx, ny, 1.0);
+					}
+				}
+
+				for(ny=0; ny<pGrid->Get_NY() && Set_Progress(ny, pGrid->Get_NY()); ny++)
+				{
+					for(nx=0; nx<pGrid->Get_NX(); nx++)
+					{
+						nValues	= pCount->asInt(nx, ny);
+
+						if( nValues == 0 )
+						{
+							pGrid->Set_NoData(nx, ny);
+						}
+						else if( nValues > 1 )
+						{
+							pGrid->Mul_Value(nx, ny, 1.0 / nValues);
+						}
+					}
+				}
+
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline bool CXYZ_Import::Read_Values(CSG_File &Stream, double &x, double &y, double &z)
+{
+	CSG_String	sLine;
+
+	if( Stream.Read_Line(sLine) )
+	{
+		if( sLine.asDouble(x) )
+		{
+			sLine	= sLine.AfterFirst(m_Separator);
+
+			if( sLine.asDouble(y) )
+			{
+				sLine	= sLine.AfterFirst(m_Separator);
+
+				if( sLine.asDouble(z) )
+				{
+					return( true );
+				}
+			}
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid/xyz.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                        Grid_IO                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                         XYZ.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__XYZ_H
+#define HEADER_INCLUDED__XYZ_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CXYZ_Export : public CSG_Module_Grid
+{
+public:
+	CXYZ_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)			{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CXYZ_Import : public CSG_Module
+{
+public:
+	CXYZ_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)			{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	SG_Char					m_Separator;
+
+
+	bool					Read_Values		(CSG_File &Stream, double &x, double &y, double &z);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__XYZ_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char *	Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import/Export - Images") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2005") );
+
+	case MLB_INFO_Description:
+		return( _TL("Image Import/Export.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|Grid") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "grid_export.h"
+#include "grid_import.h"
+
+#include <wx/image.h>
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:	return( new CGrid_Export );
+	case 1:	return( new CGrid_Import );
+	}
+
+	//------------------------------------------------------
+	wxInitAllImageHandlers();
+
+//	wxImage::AddHandler(new wxBMPHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxICOHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxJPEGHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxPCXHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxPNGHandler);	// For loading (including alpha support) and saving.
+//	wxImage::AddHandler(new wxPNMHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxTIFFHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxXPMHandler);	// For loading and saving.
+//	wxImage::AddHandler(new wxGIFHandler);	// Only for loading, due to legal issues.
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_grid_image_H
+#define HEADER_INCLUDED__io_grid_image_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_grid_image_EXPORTS
+	#define	io_grid_image_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_grid_image_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_grid_image_H

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,344 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Export.cpp                    //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/filename.h>
+#include <wx/image.h>
+
+#include "grid_export.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Export::CGrid_Export(void)
+{
+	Set_Name		(_TL("Export Image (bmp, jpg, png)"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2005"));
+
+	Set_Description	(_TW(
+		"Saves a grid as image using display properties as used by the graphical user interface.\n")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SHADE"		, _TL("Shade"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("Image File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s"),
+			_TL("Windows or OS/2 Bitmap (*.bmp)")				, SG_T("*.bmp"),
+			_TL("JPEG - JFIF Compliant (*.jpg, *.jif, *.jpeg)")	, SG_T("*.jpg;*.jif;*.jpeg"),
+			_TL("Zsoft Paintbrush (*.pcx)")						, SG_T("*.pcx"),
+			_TL("Portable Network Graphics (*.png)")			, SG_T("*.png"),
+			_TL("Tagged Image File Format (*.tif, *.tiff)")		, SG_T("*.tif;*.tiff")
+		), NULL, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "FILE_KML"		, _TL("Create KML File"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	if( !SG_UI_Get_Window_Main() )
+	{
+		Parameters.Add_Value(
+			NULL	, "COL_COUNT"	, _TL("Number of Colors"),
+			_TL(""),
+			PARAMETER_TYPE_Int, 100
+		);
+
+		Parameters.Add_Choice(
+			NULL	, "COL_PALETTE"	, _TL("Color Palette"),
+			_TL(""),
+			CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+				_TL("SG_COLORS_DEFAULT"),
+				_TL("SG_COLORS_DEFAULT_BRIGHT"),
+				_TL("SG_COLORS_BLACK_WHITE"),
+				_TL("SG_COLORS_BLACK_RED"),
+				_TL("SG_COLORS_BLACK_GREEN"),
+				_TL("SG_COLORS_BLACK_BLUE"),
+				_TL("SG_COLORS_WHITE_RED"),
+				_TL("SG_COLORS_WHITE_GREEN"),
+				_TL("SG_COLORS_WHITE_BLUE"),
+				_TL("SG_COLORS_YELLOW_RED"),
+				_TL("SG_COLORS_YELLOW_GREEN"),
+				_TL("SG_COLORS_YELLOW_BLUE"),
+				_TL("SG_COLORS_RED_GREEN"),
+				_TL("SG_COLORS_RED_BLUE"),
+				_TL("SG_COLORS_GREEN_BLUE"),
+				_TL("SG_COLORS_RED_GREY_BLUE"),
+				_TL("SG_COLORS_RED_GREY_GREEN"),
+				_TL("SG_COLORS_GREEN_GREY_BLUE"),
+				_TL("SG_COLORS_RED_GREEN_BLUE"),
+				_TL("SG_COLORS_RED_BLUE_GREEN"),
+				_TL("SG_COLORS_GREEN_RED_BLUE"),
+				_TL("SG_COLORS_RAINBOW"),
+				_TL("SG_COLORS_NEON"),
+				_TL("SG_COLORS_COUNT")
+			), 0
+		);
+
+		Parameters.Add_Value(
+			NULL, "COL_REVERT"	, _TL("Revert Palette"),
+			_TL(""),
+			PARAMETER_TYPE_Bool, false
+		);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Export::On_Execute(void)
+{
+	wxInitAllImageHandlers();
+
+	int			x, y, c, r, g, b;
+	double		d;
+	CSG_Grid	*pGrid, *pShade, Grid, Shade;
+	CSG_File	Stream;
+	CSG_String	fName, fExt;
+	wxImage		img;
+
+	//-----------------------------------------------------
+	pGrid	= Parameters("GRID")	->asGrid();
+	pShade	= Parameters("SHADE")	->asGrid();
+	fName	= Parameters("FILE")	->asString();
+
+	//-----------------------------------------------------
+	if(      SG_File_Cmp_Extension(fName, SG_T("bmp")) )
+	{
+		fExt	= SG_T("bpw");
+	}
+	else if( SG_File_Cmp_Extension(fName, SG_T("jpg")) )
+	{
+		fExt	= SG_T("jgw");
+	}
+	else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) )
+	{
+		fExt	= SG_T("pxw");
+	}
+	else if( SG_File_Cmp_Extension(fName, SG_T("png")) )
+	{
+		fExt	= SG_T("pgw");
+	}
+	else if( SG_File_Cmp_Extension(fName, SG_T("tif")) )
+	{
+		fExt	= SG_T("tfw");
+	}
+	else
+	{
+		fExt	= SG_T("pgw");
+
+		fName	= SG_File_Make_Path(NULL, fName, SG_T("png"));
+	}
+
+	//-----------------------------------------------------
+	if( !pGrid || pGrid->Get_ZRange() == 0.0 )
+	{
+		return( false );
+	}
+	else if( !SG_UI_DataObject_asImage(pGrid, &Grid) )
+	{
+		int			nColors	= Parameters("COL_COUNT")->asInt();
+		CSG_Colors	Colors(nColors, Parameters("COL_PALETTE")->asInt(), Parameters("COL_REVERT")->asBool());
+
+		Grid.Create(*Get_System(), SG_DATATYPE_Int);
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( pGrid->is_NoData(x, y) )
+					Grid.Set_NoData(x, Get_NY() - 1 - y);
+				else
+					Grid.Set_Value(x, Get_NY() - 1 - y, Colors[(int)(
+						nColors * (pGrid->asDouble(x, y) - pGrid->Get_ZMin()) / pGrid->Get_ZRange()
+					)]);
+			}
+		}
+	}
+
+	if( !pShade || pShade->Get_ZRange() == 0.0 )
+	{
+		pShade	= NULL;
+	}
+	else if( !SG_UI_DataObject_asImage(pShade, &Shade) )
+	{
+		int			nColors	= 100;
+		CSG_Colors	Colors(nColors, SG_COLORS_BLACK_WHITE);
+
+		Shade.Create(*Get_System(), SG_DATATYPE_Int);
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( pShade->is_NoData(x, y) )
+					Shade.Set_NoData(x, Get_NY() - 1 - y);
+				else
+					Shade.Set_Value(x, Get_NY() - 1 - y, Colors[(int)(
+						nColors * (pShade->asDouble(x, y) - pShade->Get_ZMin()) / pShade->Get_ZRange()
+					)]);
+			}
+		}
+	}
+
+	//-------------------------------------------------
+	img.Create(Get_NX(), Get_NY());
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			c	= Grid.asInt(x, y);
+
+			r	= SG_GET_R(c);
+			g	= SG_GET_G(c);
+			b	= SG_GET_B(c);
+
+			if( pShade )
+			{
+				c	= Shade.asInt(x, y);
+
+				d	= (SG_GET_R(c) + SG_GET_G(c) + SG_GET_B(c)) / (3.0 * 255.0);
+
+				r	= (int)(d * r);
+				g	= (int)(d * g);
+				b	= (int)(d * b);
+			}
+
+			img.SetRGB(x, y, r, g, b);
+		}
+	}
+
+	//-------------------------------------------------
+	if( img.SaveFile(fName.c_str()) )
+	{
+		if( Stream.Open(SG_File_Make_Path(NULL, fName, fExt), SG_FILE_W, false) )
+		{
+			Stream.Printf(SG_T("%f\n%f\n%f\n%f\n%f\n%f\n"),
+				 pGrid->Get_Cellsize(),
+				 0.0, 0.0,
+				-pGrid->Get_Cellsize(),
+				 pGrid->Get_XMin(),
+				 pGrid->Get_YMax()
+			);
+		}
+
+		if( Parameters("FILE_KML")->asBool() && Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("kml")), SG_FILE_W, false) )
+		{
+			Stream.Printf(SG_T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
+			Stream.Printf(SG_T("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"));
+			Stream.Printf(SG_T("  <Folder>\n"));
+			Stream.Printf(SG_T("    <name>Raster exported from SAGA</name>\n"));
+			Stream.Printf(SG_T("    <description>System for Automated Geoscientific Analyses - www.saga-gis.org</description>\n"));
+			Stream.Printf(SG_T("    <GroundOverlay>\n"));
+			Stream.Printf(SG_T("      <name>%s</name>\n")				, pGrid->Get_Name());
+			Stream.Printf(SG_T("      <description>%s</description>\n")	, pGrid->Get_Description());
+			Stream.Printf(SG_T("      <Icon>\n"));
+			Stream.Printf(SG_T("        <href>%s</href>\n")				, SG_File_Get_Name(fName, true).c_str());
+			Stream.Printf(SG_T("      </Icon>\n"));
+			Stream.Printf(SG_T("      <LatLonBox>\n"));
+			Stream.Printf(SG_T("        <north>%f</north>\n")			, pGrid->Get_YMax());
+			Stream.Printf(SG_T("        <south>%f</south>\n")			, pGrid->Get_YMin());
+			Stream.Printf(SG_T("        <east>%f</east>\n")				, pGrid->Get_XMax());
+			Stream.Printf(SG_T("        <west>%f</west>\n")				, pGrid->Get_XMin());
+			Stream.Printf(SG_T("        <rotation>0.0</rotation>\n"));
+			Stream.Printf(SG_T("      </LatLonBox>\n"));
+			Stream.Printf(SG_T("    </GroundOverlay>\n"));
+			Stream.Printf(SG_T("  </Folder>\n"));
+			Stream.Printf(SG_T("</kml>\n"));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_export.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,109 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Export.h                     //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Export_H
+#define HEADER_INCLUDED__Grid_Export_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class io_grid_image_EXPORT CGrid_Export : public CSG_Module_Grid
+{
+public:
+	CGrid_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Export_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,294 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Import.cpp                    //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/filename.h>
+#include <wx/image.h>
+
+#include "grid_import.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Import::CGrid_Import(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Import Image (bmp, jpg, png, tif, gif, pnm, xpm)"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Loads an image."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "OUT_GRID"	, _TL("Image"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "OUT_RED"		, _TL("Image (Red Channel)"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "OUT_GREEN"	, _TL("Image (Green Channel)"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "OUT_BLUE"	, _TL("Image (Blue Channel)"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("Image File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s"),
+			_TL("All Recognized File Types")					, SG_T("*.bmp;*.ico;*.gif;*.jpg;*.jif;*.jpeg;*.pcx;*.png;*.pnm;*.tif;*.tiff;*.xpm"),
+			_TL("CompuServe Graphics Interchange (*.gif)")		, SG_T("*.gif"),
+			_TL("JPEG - JFIF Compliant (*.jpg, *.jif, *.jpeg)")	, SG_T("*.jpg;*.jif;*.jpeg"),
+			_TL("Portable Network Graphics (*.png)")			, SG_T("*.png"),
+			_TL("Tagged Image File Format (*.tif, *.tiff)")		, SG_T("*.tif;*.tiff"),
+			_TL("Windows or OS/2 Bitmap (*.bmp)")				, SG_T("*.bmp"),
+			_TL("Zsoft Paintbrush (*.pcx)")						, SG_T("*.pcx"),
+			_TL("All Files")									, SG_T("*.*")
+		)
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Options"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Standard"),
+			_TL("Split Channels"),
+			_TL("Enforce True Color")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Import::~CGrid_Import(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define ADD_GRID(g, s, t)	g	= SG_Create_Grid(t, img.GetWidth(), img.GetHeight(), Cellsize, xMin, yMin); g->Set_Name(s);
+
+//---------------------------------------------------------
+bool CGrid_Import::On_Execute(void)
+{
+	int					x, y, yy, Method;
+	double				d, Cellsize, xMin, yMin;
+	CSG_Colors			Colors;
+	CSG_Grid			*pR, *pG, *pB;
+	FILE				*Stream;
+	wxFileName			fName;
+	wxImage				img;
+	wxImageHistogram	hst;
+
+	//-----------------------------------------------------
+	fName	= Parameters("FILE")	->asString();
+	Method	= Parameters("METHOD")	->asInt();
+
+	if( img.LoadFile(fName.GetFullPath()) )
+	{
+		if(      !fName.GetExt().CmpNoCase(SG_T("bmp")) )
+		{
+			fName.SetExt(SG_T("bpw"));
+		}
+		else if( !fName.GetExt().CmpNoCase(SG_T("jpg")) )
+		{
+			fName.SetExt(SG_T("jgw"));
+		}
+		else if( !fName.GetExt().CmpNoCase(SG_T("png")) )
+		{
+			fName.SetExt(SG_T("pgw"));
+		}
+		else if( !fName.GetExt().CmpNoCase(SG_T("tif")) )
+		{
+			fName.SetExt(SG_T("tfw"));
+		}
+		else
+		{
+			fName.SetExt(SG_T("world"));
+		}
+
+		//-------------------------------------------------
+		if( (Stream = fopen(fName.GetFullPath().mb_str(), "r")) != NULL )
+		{
+			fscanf(Stream, "%lf %lf %lf %lf %lf %lf ", &Cellsize, &d, &d, &d, &xMin, &yMin);
+			yMin		= yMin - (img.GetHeight() - 1) * Cellsize;
+			fclose(Stream);
+		}
+		else
+		{
+			Cellsize	= 1.0;
+			xMin		= 0.0;
+			yMin		= 0.0;
+		}
+
+		//-------------------------------------------------
+		if( Method == 1 )
+		{
+			ADD_GRID(pR, CSG_String::Format(SG_T("%s [R]"), fName.GetName().c_str()), SG_DATATYPE_Byte);
+			ADD_GRID(pG, CSG_String::Format(SG_T("%s [G]"), fName.GetName().c_str()), SG_DATATYPE_Byte);
+			ADD_GRID(pB, CSG_String::Format(SG_T("%s [B]"), fName.GetName().c_str()), SG_DATATYPE_Byte);
+
+			for(y=0, yy=pR->Get_NY()-1; y<pR->Get_NY() && Set_Progress(y, pR->Get_NY()); y++, yy--)
+			{
+				for(x=0; x<pR->Get_NX(); x++)
+				{
+					pR->Set_Value(x, y, img.GetRed  (x, yy));
+					pG->Set_Value(x, y, img.GetGreen(x, yy));
+					pB->Set_Value(x, y, img.GetBlue (x, yy));
+				}
+			}
+
+			Parameters("OUT_RED")	->Set_Value(pR);
+			DataObject_Set_Colors(pR, 100, SG_COLORS_BLACK_RED);
+
+			Parameters("OUT_GREEN")	->Set_Value(pG);
+			DataObject_Set_Colors(pG, 100, SG_COLORS_BLACK_GREEN);
+
+			Parameters("OUT_BLUE")	->Set_Value(pB);
+			DataObject_Set_Colors(pB, 100, SG_COLORS_BLACK_BLUE);
+		}
+
+		//-------------------------------------------------
+		else if( Method == 0 && (yy = img.ComputeHistogram(hst)) <= 256 )
+		{
+			Colors.Set_Count(yy);
+
+			for(wxImageHistogram::iterator i=hst.begin(); i!=hst.end(); ++i)
+			{
+				Colors.Set_Color(i->second.index, SG_GET_R(i->first), SG_GET_G(i->first), SG_GET_B(i->first));
+			}
+
+			ADD_GRID(pR, CSG_String( fName.GetName() ), yy <= 2 ? SG_DATATYPE_Bit : SG_DATATYPE_Byte);
+
+			for(y=0, yy=pR->Get_NY()-1; y<pR->Get_NY() && Set_Progress(y, pR->Get_NY()); y++, yy--)
+			{
+				for(x=0; x<pR->Get_NX(); x++)
+				{
+					pR->Set_Value(x, y, hst[SG_GET_RGB(img.GetRed(x, yy), img.GetGreen(x, yy), img.GetBlue(x, yy))].index);
+				}
+			}
+
+			Parameters("OUT_GRID")	->Set_Value(pR);
+			DataObject_Set_Colors(pR, Colors);
+			DataObject_Update(pR, 0, Colors.Get_Count() - 1);
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			hst.clear();
+
+			ADD_GRID(pR, CSG_String( fName.GetName() ).c_str(), SG_DATATYPE_Int);
+
+			for(y=0, yy=pR->Get_NY()-1; y<pR->Get_NY() && Set_Progress(y, pR->Get_NY()); y++, yy--)
+			{
+				for(x=0; x<pR->Get_NX(); x++)
+				{
+					pR->Set_Value(x, y, SG_GET_RGB(img.GetRed(x, yy), img.GetGreen(x, yy), img.GetBlue(x, yy)));
+				}
+			}
+
+			Parameters("OUT_GRID")	->Set_Value(pR);
+			DataObject_Set_Colors(pR, 100, SG_COLORS_BLACK_WHITE);
+
+			CSG_Parameters	Parms;
+
+			if( DataObject_Get_Parameters(pR, Parms) && Parms("COLORS_TYPE") )
+			{
+				Parms("COLORS_TYPE")->Set_Value(3);	// Color Classification Type: RGB
+
+				DataObject_Set_Parameters(pR, Parms);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/grid/io_grid_image/grid_import.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       image_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Grid_Import.h                     //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    SAGA User Group Association            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Import_H
+#define HEADER_INCLUDED__Grid_Import_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class io_grid_image_EXPORT CGrid_Import : public CSG_Module
+{
+public:
+	CGrid_Import(void);
+	virtual ~CGrid_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Grid_Import_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,145 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import/Export - Shapes") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the import and export of vector data.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|Shapes") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "gstat.h"
+#include "xyz.h"
+#include "generate.h"
+#include "surfer_bln.h"
+#include "atlas_bna.h"
+#include "wasp_map.h"
+#include "stl.h"
+#include "gpx.h"
+#include "pointcloud_from_file.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case  0:	return( new CGStat_Export );
+	case  1:	return( new CGStat_Import );
+	case  2:	return( new CXYZ_Export );
+	case  3:	return( new CXYZ_Import );
+	case  4:	return( new CGenerate_Export );
+	case  5:	return( new CSurfer_BLN_Export );
+	case  6:	return( new CSurfer_BLN_Import );
+	case  7:	return( new CAtlas_BNA_Export );
+	case  8:	return( new CAtlas_BNA_Import );
+	case  9:	return( new CWASP_MAP_Export );
+	case 10:	return( new CWASP_MAP_Import );
+	case 11:	return( new CSTL_Import );
+	case 12:	return( new CSTL_Export );
+	case 13:	return( new CGPX_Import );
+	case 14:	return( new CGPX_Export );
+	case 15:	return( new CPointCloud_From_File );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_shapes_H
+#define HEADER_INCLUDED__io_shapes_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_shapes_EXPORTS
+	#define	io_shapes_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_shapes_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_shapes_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,383 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Atlas_BNA.cpp                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "atlas_bna.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CAtlas_BNA_Import::CAtlas_BNA_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Import Atlas Boundary File"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("Atlas Boundary Files (*.bna)|*.bna|All Files|*.*")
+	);
+}
+
+//---------------------------------------------------------
+CAtlas_BNA_Import::~CAtlas_BNA_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CAtlas_BNA_Import::On_Execute(void)
+{
+	bool		bOk;
+	int			iPoint, nPoints;
+	double		x, y;
+	FILE		*Stream;
+	CSG_String	FileName, sLine, sName1, sName2;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pPoints, *pLines, *pPolygons;
+
+	//-----------------------------------------------------
+	FileName	= Parameters("FILE")	->asString();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(FileName.b_str(), "r")) != NULL )
+	{
+		pPoints		= SG_Create_Shapes(SHAPE_TYPE_Point  , SG_File_Get_Name(FileName, false));
+		pPoints		->Add_Field("NAME1"	, SG_DATATYPE_String);
+		pPoints		->Add_Field("NAME2"	, SG_DATATYPE_String);
+
+		pLines		= SG_Create_Shapes(SHAPE_TYPE_Line   , SG_File_Get_Name(FileName, false));
+		pLines		->Add_Field("NAME1"	, SG_DATATYPE_String);
+		pLines		->Add_Field("NAME2"	, SG_DATATYPE_String);
+
+		pPolygons	= SG_Create_Shapes(SHAPE_TYPE_Polygon, SG_File_Get_Name(FileName, false));
+		pPolygons	->Add_Field("NAME1"	, SG_DATATYPE_String);
+		pPolygons	->Add_Field("NAME2"	, SG_DATATYPE_String);
+
+		//-------------------------------------------------
+		bOk		= true;
+
+		while( bOk && SG_Read_Line(Stream, sLine) && Process_Get_Okay(true) )
+		{
+			sName1	= sLine.AfterFirst('\"').BeforeFirst('\"');
+			sName2	= sLine.BeforeLast('\"').AfterLast('\"');
+			sLine	= sLine.AfterLast('\"');	if( sLine.Find(',', true) >= 0 )	sLine	= sLine.AfterLast(',');
+
+			nPoints	= sLine.asInt();
+
+			if( nPoints == 1 )
+			{
+				pShape	= pPoints	->Add_Shape();
+			}
+			else if( nPoints < 0 )
+			{
+				pShape	= pLines	->Add_Shape();
+				nPoints	= -nPoints;
+			}
+			else if( nPoints > 2 )
+			{
+				pShape	= pPolygons	->Add_Shape();
+			}
+			else
+			{
+				bOk		= false;
+			}
+
+			if( bOk )
+			{
+				pShape->Set_Value(0, sName1);
+				pShape->Set_Value(1, sName2);
+
+				for(iPoint=0; iPoint<nPoints && bOk; iPoint++)
+				{
+					if( (bOk = SG_Read_Line(Stream, sLine)) == true )
+					{
+						SG_SSCANF(sLine, SG_T("%lf %lf"), &x, &y);
+						pShape->Add_Point(x, y);
+					}
+				}
+			}
+		}
+
+		fclose(Stream);
+
+		//-------------------------------------------------
+		bOk		= false;
+
+		if( pPoints->is_Valid() && pPoints->Get_Count() > 0 )
+		{
+			bOk		= true;
+			DataObject_Add(pPoints);
+		}
+		else
+		{
+			delete(pPoints);
+		}
+
+		if( pLines->is_Valid() && pLines->Get_Count() > 0 )
+		{
+			bOk		= true;
+			DataObject_Add(pLines);
+		}
+		else
+		{
+			delete(pLines);
+		}
+
+		if( pPolygons->is_Valid() && pPolygons->Get_Count() > 0 )
+		{
+			bOk		= true;
+			DataObject_Add(pPolygons);
+		}
+		else
+		{
+			delete(pPolygons);
+		}
+
+		return( bOk );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CAtlas_BNA_Export::CAtlas_BNA_Export(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Export Atlas Boundary File"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	CSG_Parameter	*pNode;
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "PNAME"	, _TL("Primary Name"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "SNAME"	, _TL("Secondary Name"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL(
+		"Atlas Boundary Files (*.bna)|*.bna|All Files|*.*"), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CAtlas_BNA_Export::~CAtlas_BNA_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CAtlas_BNA_Export::On_Execute(void)
+{
+	int			iShape, iPart, iPoint, iName1, iName2;
+	FILE		*Stream;
+	TSG_Point	p;
+	CSG_Points	Pts;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+	CSG_String	fName;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	fName	= Parameters("FILE")	->asString();
+
+	iName1	= Parameters("PNAME")	->asInt();
+	iName2	= Parameters("SNAME")	->asInt();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+	{
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= pShapes->Get_Shape(iShape);
+
+			switch( pShapes->Get_Type() )
+			{
+			default:
+				break;
+
+			//---------------------------------------------
+			case SHAPE_TYPE_Point:
+				fprintf(Stream, "\"%s\",\"%s\",%d\n",
+					pShape->asString(iName1),
+					pShape->asString(iName2),
+					1
+				);
+
+				p	= pShape->Get_Point(0);
+				fprintf(Stream, "%f,%f\n", p.x, p.y);
+				break;
+
+			//---------------------------------------------
+			case SHAPE_TYPE_Line:
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					fprintf(Stream, "\"%s\",\"%s\",%d\n",
+						pShape->asString(iName1),
+						pShape->asString(iName2),
+						-pShape->Get_Point_Count(iPart)
+					);
+
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						p	= pShape->Get_Point(iPoint, iPart);
+						fprintf(Stream, "%f,%f\n", p.x, p.y);
+					}
+				}
+				break;
+
+			//---------------------------------------------
+			case SHAPE_TYPE_Polygon:
+				if( pShape->Get_Part_Count() > 0 && pShape->Get_Point_Count(0) > 2 )
+				{
+					Pts.Clear();
+
+					for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+					{
+						for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+						{
+							Pts.Add(pShape->Get_Point(iPoint, iPart));
+						}
+
+						if( iPart > 0 )
+						{
+							Pts.Add(pShape->Get_Point(0, 0));
+						}
+					}
+
+					if( Pts.Get_Count() > 2 )
+					{
+						fprintf(Stream, "\"%s\",\"%s\",%d\n",
+							pShape->asString(iName1),
+							pShape->asString(iName2),
+							Pts.Get_Count()
+						);
+
+						for(iPoint=0; iPoint<Pts.Get_Count(); iPoint++)
+						{
+							fprintf(Stream, "%f,%f\n", Pts[iPoint].x, Pts[iPoint].y);
+						}
+					}
+				}
+				break;
+			}
+		}
+
+		fclose(Stream);
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/atlas_bna.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Atlas_BNA.h                      //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Atlas_BNA_H
+#define HEADER_INCLUDED__Atlas_BNA_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CAtlas_BNA_Import : public CSG_Module
+{
+public:
+	CAtlas_BNA_Import(void);
+	virtual ~CAtlas_BNA_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CAtlas_BNA_Export : public CSG_Module
+{
+public:
+	CAtlas_BNA_Export(void);
+	virtual ~CAtlas_BNA_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Atlas_BNA_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,174 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Generate.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "generate.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGenerate_Export::CGenerate_Export(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name(_TL("Export Shapes to Generate"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW("Export generate shapes format."));
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME", _TL("File"),
+		_TL("")
+	);
+}
+
+//---------------------------------------------------------
+CGenerate_Export::~CGenerate_Export(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGenerate_Export::On_Execute(void)
+{
+	int			iShape, iPart, iPoint, iField;
+	FILE		*aus;
+	TSG_Point	Point;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pLayer;
+	CSG_String	fName;
+
+	fName	= Parameters("FILENAME")->asString();
+
+	if(	(pLayer = Parameters("SHAPES")->asShapes()) != NULL )
+	{
+		if( (aus = fopen(fName.b_str(), "w")) != NULL )
+		{
+			if( pLayer->Get_Field_Count() > 0 )
+			{
+				iField	= Parameters("FIELD")->asInt();
+
+				if( pLayer->Get_Field_Type(iField) == SG_DATATYPE_String )
+				{
+					iField	= -1;
+				}
+
+				fprintf(aus, "EXP %s\nARC ", pLayer->Get_Name());
+
+				for(iShape=0; iShape<pLayer->Get_Count() && Set_Progress(iShape, pLayer->Get_Count()); iShape++)
+				{
+					pShape	= pLayer->Get_Shape(iShape);
+
+					for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+					{
+						// Value...
+						if( iField < 0 )
+						{
+							fprintf(aus, "%d ", iShape + 1);
+						}
+						else
+						{
+							fprintf(aus, "%lf ", pShape->asDouble(iField));
+						}
+
+						// dummy_I dummy_I dummy_I dummy_I dummy_I...
+						fprintf(aus, "1 2 3 4 5 ");
+						// I_np...
+						fprintf(aus, "%d ", pShape->Get_Point_Count(iPart));
+
+						for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+						{
+							Point	= pShape->Get_Point(iPoint, iPart);
+
+							fprintf(aus, "%f %f ", Point.x, Point.y);
+						}
+					}
+				}
+			}
+
+			fclose(aus);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/generate.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Generate.h                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GENERATE_H
+#define HEADER_INCLUDED__GENERATE_H
+
+//---------------------------------------------------------
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGenerate_Export : public CSG_Module  
+{
+public:
+	CGenerate_Export(void);
+	virtual ~CGenerate_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__GENERATE_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,451 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        gpx.cpp                        //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "gpx.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGPX_Import::CGPX_Import(void)
+{
+	Set_Name		(_TL("Import GPX"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"Imports GPS data from GPS eXchange format GPX.\n"
+		"\n"
+		"References:\n"
+		"<a href=\"http://www.topografix.com/\">The GPS Exchange Format</a>"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes_List(
+		NULL	, "SHAPES"			, _TL("GPX Import"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"			, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s"),
+			_TL("GPS Exchange Format (*.gpx)")	, SG_T("*.gpx"),
+			_TL("All Files")					, SG_T("*.*")
+		), NULL, false
+ 	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME"			, _TL("Time Stamp without date"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+ 	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGPX_Import::On_Execute(void)
+{
+	CSG_Shapes		*pWay;
+	CSG_MetaData	GPX;
+
+	//-----------------------------------------------------
+	m_Name		= Parameters("FILE")	->asString();
+	m_pShapes	= Parameters("SHAPES")	->asShapesList();
+	m_bTime		= Parameters("TIME")	->asBool();
+
+	//-----------------------------------------------------
+	if( !GPX.Create(m_Name) || GPX.Get_Name().CmpNoCase(SG_T("gpx")) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	pWay		= SG_Create_Shapes(SHAPE_TYPE_Point, m_Name);
+
+	m_Name		= SG_File_Get_Name(m_Name, false);
+
+	m_pShapes->Del_Items();
+
+	//-----------------------------------------------------
+	for(int i=0; i<GPX.Get_Children_Count(); i++)
+	{
+		CSG_MetaData	*pChild	= GPX.Get_Child(i);
+
+		     if( pChild->Get_Name().CmpNoCase(SG_T("wpt")) == 0 )
+		{
+			Add_Point(pChild, pWay);
+		}
+		else if( pChild->Get_Name().CmpNoCase(SG_T("rte")) == 0 )
+		{
+			Add_Route(pChild);
+		}
+		else if( pChild->Get_Name().CmpNoCase(SG_T("trk")) == 0 )
+		{
+			Add_Track(pChild);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pWay->Get_Count() > 0 )
+	{
+		m_pShapes->Add_Item(pWay);
+	}
+	else
+	{
+		delete(pWay);
+	}
+
+	return( m_pShapes->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_CONTENT(node, child, default)	(node->Get_Child(SG_T(child)) ? node->Get_Child(SG_T(child))->Get_Content() : SG_T(default))
+
+//---------------------------------------------------------
+bool CGPX_Import::Add_Route(CSG_MetaData *pRoute)
+{
+	// <name>	xsd:string
+	// <cmt>	xsd:string
+	// <desc>	xsd:string
+	// <src>	xsd:string
+	// <link>	linkType
+	// <number> xsd:nonNegativeInteger
+	// <type>	xsd:string
+
+	CSG_String	Name(GET_CONTENT(pRoute, "name", "Route"));
+
+	CSG_Shapes	*pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), m_Name.c_str(), Name.c_str()));
+
+	m_pShapes->Add_Item(pPoints);
+
+	for(int i=0; i<pRoute->Get_Children_Count(); i++)
+	{
+		CSG_MetaData	*pChild	= pRoute->Get_Child(i);
+
+		if( pChild->Get_Name().CmpNoCase(SG_T("rtept")) == 0 )
+		{
+			Add_Point(pChild, pPoints);
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGPX_Import::Add_Track(CSG_MetaData *pTrack)
+{
+	// <name>	xsd:string
+	// <cmt>	xsd:string
+	// <desc>	xsd:string
+	// <src>	xsd:string
+	// <link>	linkType
+	// <number> xsd:nonNegativeInteger
+	// <type>	xsd:string
+
+	CSG_MetaData	*pSegment	= pTrack->Get_Child(SG_T("trkseg"));
+
+	if( pSegment )
+	{
+		CSG_String	Name(GET_CONTENT(pTrack, "name", "Track Segment"));
+
+		CSG_Shapes	*pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), m_Name.c_str(), Name.c_str()));
+
+		m_pShapes->Add_Item(pPoints);
+
+		for(int i=0; i<pSegment->Get_Children_Count(); i++)
+		{
+			CSG_MetaData	*pChild	= pSegment->Get_Child(i);
+
+			if( pChild->Get_Name().CmpNoCase(SG_T("trkpt")) == 0 )
+			{
+				Add_Point(pChild, pPoints);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define ADD_FIELD(key, type)	if( pNode->Get_Child(SG_T(key)) )	{	pPoints->Add_Field(SG_T(key), type);	}
+
+inline bool CGPX_Import::Add_Fields(CSG_MetaData *pNode, CSG_Shapes *pPoints)
+{
+	if( pPoints->Get_Field_Count() == 0 )
+	{
+		ADD_FIELD("ele"				, SG_DATATYPE_Double);	// <ele>			xsd:decimal				(Höhe)
+		ADD_FIELD("time"			, SG_DATATYPE_String);	// <time>			xsd:dateTime			(Datum und Zeit)
+		ADD_FIELD("magvar"			, SG_DATATYPE_Double);	// <magvar>			degreesType				(lokale magn. Missweisung)
+		ADD_FIELD("geoidheight"		, SG_DATATYPE_Double);	// <geoidheight>	xsd:decimal				(Höhe bezogen auf Geoid)
+		ADD_FIELD("name"			, SG_DATATYPE_String);	// <name>			xsd:string				(Beschreibung)
+		ADD_FIELD("cmt"				, SG_DATATYPE_String);	// <cmt>			xsd:string				(Kommentar)
+		ADD_FIELD("desc"			, SG_DATATYPE_String);	// <desc>			xsd:string				(Elementbeschreibung)
+		ADD_FIELD("src"				, SG_DATATYPE_String);	// <src>			xsd:string				(Quelle)
+		ADD_FIELD("link"			, SG_DATATYPE_String);	// <link>			linkType				(Link)
+		ADD_FIELD("sym"				, SG_DATATYPE_String);	// <sym>			xsd:string				(Darstellungssymbol)
+		ADD_FIELD("type"			, SG_DATATYPE_String);	// <type>			xsd:string				(Klassifikation)
+		ADD_FIELD("fix"				, SG_DATATYPE_Double);	// <fix>			fixType
+		ADD_FIELD("sat"				, SG_DATATYPE_Int   );	// <sat>			xsd:nonNegativeInteger	(Anzahl der empfangenen Satelliten)
+		ADD_FIELD("hdop"			, SG_DATATYPE_Double);	// <hdop>			xsd:decimal				(hDOP)
+		ADD_FIELD("vdop"			, SG_DATATYPE_Double);	// <vdop>			xsd:decimal				(vDOP)
+		ADD_FIELD("pdop"			, SG_DATATYPE_Double);	// <pdop>			xsd:decimal				(3D DOP)
+		ADD_FIELD("ageofdgpsdata"	, SG_DATATYPE_Double);	// <ageofdgpsdata>	xsd:decimal				(Letzter DGPS update)
+		ADD_FIELD("dgpsid"			, SG_DATATYPE_Int   );	// <dgpsid>			dgpsStationType			(DGPS ID)
+
+		if( m_bTime && pNode->Get_Child(SG_T("time")) )
+		{
+			pPoints->Add_Field(SG_T("dtime"), SG_DATATYPE_Double);
+		}
+		else
+		{
+			m_bTime	= false;
+		}
+	}
+
+	return( pPoints->Get_Field_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CGPX_Import::Add_Point(CSG_MetaData *pNode, CSG_Shapes *pPoints)
+{
+	const SG_Char	*cString;
+	TSG_Point		Point;
+
+	if(	(cString = pNode->Get_Property(SG_T("lon"))) != NULL && CSG_String(cString).asDouble(Point.x)
+	&&	(cString = pNode->Get_Property(SG_T("lat"))) != NULL && CSG_String(cString).asDouble(Point.y)
+	&&	Add_Fields(pNode, pPoints) )
+	{
+		CSG_Shape	*pPoint	= pPoints->Add_Shape();
+
+		pPoint->Add_Point(Point, 0);
+
+		for(int i=0; i<pNode->Get_Children_Count(); i++)
+		{
+			CSG_MetaData	*pChild	= pNode->Get_Child(i);
+
+			pPoint->Set_Value(pChild->Get_Name(), pChild->Get_Content());
+		}
+
+		if( m_bTime )
+		{
+			double		h	= CSG_String(pPoint->asString(SG_T("time"))).AfterFirst(SG_T('T')).asDouble();
+			double		m	= CSG_String(pPoint->asString(SG_T("time"))).AfterFirst(SG_T(':')).asDouble();
+			double		s	= CSG_String(pPoint->asString(SG_T("time"))).AfterLast (SG_T(':')).asDouble();
+
+			pPoint->Set_Value(SG_T("dtime"), h + m / 60.0 + s / 3600.0);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGPX_Export::CGPX_Export(void)
+{
+	Set_Name		(_TL("Export GPX"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"Exports vector data points to GPS eXchange format GPX.\n"
+		"\n"
+		"References:\n"
+		"<a href=\"http://www.topografix.com/\">The GPS Exchange Format</a>"
+	));
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"			, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"			, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s"),
+			_TL("GPS Exchange Format (*.gpx)")	, SG_T("*.gpx"),
+			_TL("All Files")					, SG_T("*.*")
+		), NULL, true
+ 	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ELE"				, _TL("Elevation"),
+		_TL(""),
+		true
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "NAME"			, _TL("Name"),
+		_TL(""),
+		true
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "CMT"				, _TL("Comment"),
+		_TL(""),
+		true
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "DESC"			, _TL("Description"),
+		_TL(""),
+		true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGPX_Export::On_Execute(void)
+{
+	int				iEle, iName, iCmt, iDesc;
+	CSG_String		File;
+	CSG_MetaData	GPX;
+	CSG_Shapes		*pShapes;
+
+	//-----------------------------------------------------
+	File		= Parameters("FILE")	->asString();
+	pShapes		= Parameters("SHAPES")	->asShapes();
+
+	iEle		= Parameters("ELE")		->asInt();	if( iEle  >= pShapes->Get_Field_Count() )	iEle	= -1;
+	iName		= Parameters("NAME")	->asInt();	if( iName >= pShapes->Get_Field_Count() )	iName	= -1;
+	iCmt		= Parameters("CMT")		->asInt();	if( iCmt  >= pShapes->Get_Field_Count() )	iCmt	= -1;
+	iDesc		= Parameters("DESC")	->asInt();	if( iDesc >= pShapes->Get_Field_Count() )	iDesc	= -1;
+
+	//-----------------------------------------------------
+	GPX.Set_Name(SG_T("gpx"));
+	GPX.Add_Property(SG_T("version")			, SG_T("1.0"));
+	GPX.Add_Property(SG_T("creator")			, SG_T("SAGA - System for Automated Geoscientific Analyses - http://www.saga-gis.org"));
+	GPX.Add_Property(SG_T("xmlns:xsi")			, SG_T("http://www.w3.org/2001/XMLSchema-instance"));
+	GPX.Add_Property(SG_T("xmlns")				, SG_T("http://www.topografix.com/GPX/1/0"));
+	GPX.Add_Property(SG_T("xsi:schemaLocation")	, SG_T("http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"));
+
+	for(int iShape=0; iShape<pShapes->Get_Count(); iShape++)
+	{
+		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				CSG_MetaData	*pPoint	= GPX.Add_Child(SG_T("wpt"));
+
+				pPoint->Add_Property(SG_T("lon"), pShape->Get_Point(iPoint, iPart).x);
+				pPoint->Add_Property(SG_T("lat"), pShape->Get_Point(iPoint, iPart).y);
+
+				if( iEle  > 0 )	pPoint->Add_Child(SG_T("ele" ), pShape->asString(iEle));
+				if( iName > 0 )	pPoint->Add_Child(SG_T("name"), pShape->asString(iName));
+				if( iCmt  > 0 )	pPoint->Add_Child(SG_T("cmt" ), pShape->asString(iCmt));
+				if( iDesc > 0 )	pPoint->Add_Child(SG_T("desc"), pShape->asString(iDesc));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( !GPX.Save(File) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gpx.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,140 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                         gpx.h                         //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GPX_H
+#define HEADER_INCLUDED__GPX_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGPX_Import : public CSG_Module
+{
+public:
+	CGPX_Import(void);
+
+	virtual const SG_Char *		Get_MenuPath		(void)	{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+	bool						m_bTime;
+
+	CSG_String					m_Name;
+
+	CSG_Parameter_Shapes_List	*m_pShapes;
+
+
+	bool						Add_Route			(CSG_MetaData *pNode);
+	bool						Add_Track			(CSG_MetaData *pNode);
+
+	bool						Add_Point			(CSG_MetaData *pNode, CSG_Shapes *pPoints);
+	bool						Add_Fields			(CSG_MetaData *pNode, CSG_Shapes *pPoints);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGPX_Export : public CSG_Module
+{
+public:
+	CGPX_Export(void);
+
+	virtual const SG_Char *		Get_MenuPath		(void)	{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__GPX_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,476 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Gstat.cpp                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "gstat.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGStat_Export::CGStat_Export(void)
+{
+	CSG_Parameter	*pNode_0;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Export GStat Shapes"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(
+		_TL("GStat shapes format export.")
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode_0	= Parameters.Add_FilePath(
+		NULL	, "FILENAME", _TL("File"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("GStat Files (*.gstat)")	, SG_T("*.gstat"),
+			_TL("Text Files (*.txt)")		, SG_T("*.txt"),
+			_TL("All Files")				, SG_T("*.*")
+		), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CGStat_Export::~CGStat_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CGStat_Export::On_Execute(void)
+{
+	int			iShape, iPart, iPoint, iField;
+	FILE		*Stream;
+	TSG_Point	Point;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+	CSG_String	fName;
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("SHAPES")		->asShapes();
+	fName		= Parameters("FILENAME")	->asString();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+	{
+		switch( pShapes->Get_Type() )
+		{
+		//-------------------------------------------------
+		case SHAPE_TYPE_Point:
+			fprintf(Stream, "%s (created by DiGeM 2.0)\n%d\nX-Coordinate\nY-Coordinate",
+				Parameters("FILENAME")->asString(),
+				pShapes->Get_Field_Count() + 2
+			);
+
+			for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
+			{
+				if( pShapes->Get_Field_Type(iField) == SG_DATATYPE_String )
+				{
+					fprintf(Stream, "\n%%%s",	pShapes->Get_Field_Name(iField) );
+				}
+				else
+				{
+					fprintf(Stream, "\n%s",	pShapes->Get_Field_Name(iField) );
+				}
+			}
+
+			for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+			{
+				pShape	= pShapes->Get_Shape(iShape);
+
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						Point	= pShape->Get_Point(iPoint, iPart);
+						fprintf(Stream, "\n%f\t%f", Point.x, Point.y);
+
+						for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
+						{
+							if( pShapes->Get_Field_Type(iField) == SG_DATATYPE_String )
+							{
+								fprintf(Stream, "\t\"%s\"",	pShape->asString(iField) );
+							}
+							else
+							{
+								fprintf(Stream, "\t%f",		pShape->asDouble(iField) );
+							}
+						}
+					}
+				}
+			}
+			break;
+
+		//-------------------------------------------------
+		case SHAPE_TYPE_Line:
+			fprintf(Stream, "EXP %s\nARC ", pShapes->Get_Name());
+
+			for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape,pShapes->Get_Count()); iShape++)
+			{
+				pShape	= pShapes->Get_Shape(iShape);
+
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					//I_ok...
+					fprintf(Stream, "%d ", iShape + 1);
+					// dummy_I dummy_I dummy_I dummy_I dummy_I...
+					fprintf(Stream, "1 2 3 4 5 ");
+					// I_np...
+					fprintf(Stream, "%d ", pShape->Get_Point_Count(iPart));
+
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						Point	= pShape->Get_Point(iPoint, iPart);
+						fprintf(Stream, "%f %f ", Point.x, Point.y);
+					}
+				}
+			}
+			break;
+
+		//-------------------------------------------------
+		case SHAPE_TYPE_Polygon:
+			fprintf(Stream, "EXP %s\nARC ", pShapes->Get_Name());
+
+			for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+			{
+				pShape	= pShapes->Get_Shape(iShape);
+
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					//I_ok...
+					fprintf(Stream, "%d ", iShape + 1);
+					// dummy_I dummy_I dummy_I dummy_I dummy_I...
+					fprintf(Stream, "1 2 3 4 5 ");
+					// I_np...
+					fprintf(Stream, "%d ", pShape->Get_Point_Count(iPart));
+
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						Point	= pShape->Get_Point(iPoint, iPart);
+						fprintf(Stream, "%f %f ", Point.x, Point.y);
+					}
+				}
+			}
+			break;
+		}
+
+		fclose(Stream);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGStat_Import::CGStat_Import(void)
+{
+	CSG_Parameter	*pNode_0;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Import GStat Shapes"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(
+		_TL("GStat shapes format import.")
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	pNode_0	= Parameters.Add_FilePath(
+		NULL	, "FILENAME", _TL("File"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("GStat Files (*.gstat)")	, SG_T("*.gstat"),
+			_TL("Text Files (*.txt)")		, SG_T("*.txt"),
+			_TL("All Files")				, SG_T("*.*")
+		), NULL, false
+	);
+}
+
+//---------------------------------------------------------
+CGStat_Import::~CGStat_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CGStat_Import::On_Execute(void)
+{
+	char		c[3];
+	int			i, nFields, fLength;
+	double		x, y, Value;
+	FILE		*Stream;
+	CSG_String	s, fName;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")		->asShapes();
+	fName	= Parameters("FILENAME")	->asString();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(fName.b_str(), "rb")) != NULL )
+	{
+		fseek(Stream, 0, SEEK_END);
+		fLength	= ftell(Stream);
+		fseek(Stream, 0, SEEK_SET);
+
+		if( fLength > 0 && SG_Read_Line(Stream, s) )
+		{
+			//---------------------------------------------
+			// Point...
+			if( s.CmpNoCase(SG_T("EXP")) )
+			{
+				pShapes->Create(SHAPE_TYPE_Point, Parameters("FILENAME")->asString());
+
+				//-----------------------------------------
+				// Load Header...
+
+				// Field Count...
+				fscanf(Stream, "%d", &nFields);
+				SG_Read_Line(Stream, s);	// zur naexten Zeile...
+
+				// Fields...
+				for(i=0; i<nFields; i++)
+				{
+					if( SG_Read_Line(Stream, s) )
+					{
+						if( !s.CmpNoCase(SG_T("[ignore]")) || s[0] == '%' )
+						{
+							pShapes->Add_Field(s, SG_DATATYPE_String);
+						}
+						else
+						{
+							pShapes->Add_Field(s, SG_DATATYPE_Double);
+						}
+					}
+				}
+
+				//-----------------------------------------
+				if( nFields < 2 )
+				{
+					Message_Dlg(_TL("Invalid File Format."), _TL("Loading GSTAT-File"));
+				}
+				else
+				{
+					while( !feof(Stream) && Set_Progress(ftell(Stream), fLength) )
+					{
+						fscanf(Stream, "%lf%lf", &x, &y); 
+
+						if( !feof(Stream) )
+						{
+							pShape	= pShapes->Add_Shape();
+							pShape->Add_Point(x, y);
+							pShape->Set_Value(0, x);
+							pShape->Set_Value(1, y);
+
+							for(i=2; i<nFields && !feof(Stream); i++)
+							{
+								if( SG_STR_CMP(pShapes->Get_Field_Name(i), SG_T("[ignore]")) )
+								{
+									Stream_Find_NextWhiteChar(Stream);
+									pShape->Set_Value(i, SG_T("NA"));
+								}
+								else if( pShapes->Get_Field_Name(i)[0] == '%' )
+								{
+									Stream_Get_StringInQuota(Stream, s);
+									pShape->Set_Value(i, s);
+								}
+								else
+								{
+									fscanf(Stream, "%lf", &Value);
+									pShape->Set_Value(i, Value);
+								}
+							}
+
+							SG_Read_Line(Stream, s);
+						}
+					}
+				}
+			}
+
+			//---------------------------------------------
+			// Line, Polygon...
+			else
+			{
+				fread(c, 3, sizeof(char), Stream);
+
+				if( !strncmp(c, "ARC", 3) )
+				{
+					pShapes->Create(SHAPE_TYPE_Line, Parameters("FILENAME")->asString());
+					pShapes->Add_Field("VALUE", SG_DATATYPE_Double);
+
+					//---------------------------------------------
+					while( !feof(Stream) && Set_Progress(ftell(Stream), fLength) )
+					{
+						fscanf(Stream, "%lf", &Value);						// i_ok...
+						fscanf(Stream, "%d%d%d%d%d", &i, &i, &i, &i, &i);	// dummy 1..5
+						fscanf(Stream, "%d", &nFields);
+
+						if( nFields > 0 )
+						{
+							pShape	= NULL;
+
+							for(i=0; i<nFields; i++)
+							{
+								fscanf(Stream, "%lf%lf", &x, &y);
+
+								if( !feof(Stream) )
+								{
+									if( !pShape )
+									{
+										pShape	= pShapes->Add_Shape();
+										pShape->Set_Value(0, Value);
+									}
+
+									pShape->Add_Point(x, y);
+								}
+								else
+								{
+									break;
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+
+		fclose(Stream);
+	}
+
+	return( pShapes->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Import - Helper						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGStat_Import::Stream_Find_NextWhiteChar(FILE *Stream)
+{
+	char	c;
+
+	if( Stream )
+	{
+		do
+		{
+			c	= fgetc(Stream);
+		}
+		while( !feof(Stream) && c > 32 );
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGStat_Import::Stream_Get_StringInQuota(FILE *Stream, CSG_String &String)
+{
+	char	c;
+
+	String.Clear();
+
+	if( Stream )
+	{
+		do
+		{
+			c	= fgetc(Stream);
+		}
+		while( !feof(Stream) && c != '\"' );
+
+		while( !feof(Stream) && (c = fgetc(Stream)) != '\"' )
+		{
+			String.Append(c);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/gstat.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Gstat.h                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__GSTAT_H
+#define HEADER_INCLUDED__GSTAT_H
+
+//---------------------------------------------------------
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGStat_Export : public CSG_Module  
+{
+public:
+	CGStat_Export(void);
+	virtual ~CGStat_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGStat_Import : public CSG_Module  
+{
+public:
+	CGStat_Import(void);
+	virtual ~CGStat_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	bool					Stream_Find_NextWhiteChar	(FILE *Stream);
+	bool					Stream_Get_StringInQuota	(FILE *Stream, CSG_String &String);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__GSTAT_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,172 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                pointcloud_from_file.cpp               //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+	#include "pointcloud_from_file.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPointCloud_From_File::CPointCloud_From_File(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Point Cloud from File"));
+
+	Set_Author		(_TL("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud_Output(
+		NULL	, "POINTS"		, _TL("Point Cloud"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s"),
+			_TL("ESRI Shapefiles")	, SG_T("*.shp"),
+			_TL("All Files")		, SG_T("*.*")
+		)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPointCloud_From_File::On_Execute(void)
+{
+	CSG_String	fName(Parameters("FILE")->asString());
+
+	if( Read_Shapefile(fName) )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPointCloud_From_File::Read_Shapefile(const CSG_String &fName)
+{
+	int			iField, iPoint;
+	CSG_Shapes	Shapes;
+
+	if( !Shapes.Create(fName) || Shapes.Get_Count() == 0 )
+	{
+		return( false );
+	}
+
+	if( Shapes.Get_Type() != SHAPE_TYPE_Point )
+	{
+		 return( false );
+	}
+
+	//-----------------------------------------------------
+	CSG_PointCloud	*pPoints	= SG_Create_PointCloud();
+	pPoints->Set_Name(SG_File_Get_Name(fName, false));
+	Parameters("POINTS")->Set_Value(pPoints);
+
+	for(iField=0; iField<Shapes.Get_Field_Count(); iField++)
+	{
+		pPoints->Add_Field(Shapes.Get_Field_Name(iField), SG_DATATYPE_Double);
+	}
+
+	for(iPoint=0; iPoint<Shapes.Get_Count(); iPoint++)
+	{
+		CSG_Shape	*pPoint	= Shapes.Get_Shape(iPoint);
+
+		pPoints->Add_Point(pPoint->Get_Point(0).x, pPoint->Get_Point(0).y, 0.0);
+
+		for(iField=0; iField<Shapes.Get_Field_Count(); iField++)
+		{
+			pPoints->Set_Value(3 + iField, pPoint->asDouble(iField));
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/pointcloud_from_file.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 pointcloud_from_file.h                //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__pointcloud_from_file_H
+#define HEADER_INCLUDED__pointcloud_from_file_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPointCloud_From_File : public CSG_Module
+{
+public:
+	CPointCloud_From_File(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	bool					Read_Shapefile		(const CSG_String &fName);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__pointcloud_from_file_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,669 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//					      stl.cpp                        //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "stl.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSTL_Import::CSTL_Import(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Import Stereo Lithography File (STL)"));
+
+	Set_Author		(_TL("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		"<a href=\"http://www.ennex.com/~fabbers/StL.asp\">The StL Format</a>"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_PointCloud_Output(
+		NULL	, "POINTS"		, _TL("Point Cloud"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"		, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s"),
+			_TL("STL Files")	, SG_T("*.stl"),
+			_TL("All Files")	, SG_T("*.*")
+		)
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Target"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("point cloud"),
+			_TL("points"),
+			_TL("raster")
+		), 2
+	);
+
+	Parameters.Add_Value(
+		NULL	, "GRID_RES"	, _TL("Raster Resolution (Pixels X)"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 2000, 10, true
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_ROTATE"	, _TL("Rotation"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "ROT_X"		, _TL("X Axis"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "ROT_Y"		, _TL("Y Axis"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "ROT_Z"		, _TL("Z Axis"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSTL_Import::On_Execute(void)
+{
+	int			Method;
+	DWORD		iFacette, nFacettes;
+	TSTL_Point	p[3];
+	CSG_String	sFile, sHeader;
+	CSG_File	Stream;
+
+	//-----------------------------------------------------
+	sFile		= Parameters("FILE")		->asString();
+	Method		= Parameters("METHOD")		->asInt();
+
+	r_sin_x	= sin(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD);
+	r_sin_y	= sin(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD);
+	r_sin_z	= sin(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD);
+	r_cos_x	= cos(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD);
+	r_cos_y	= cos(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD);
+	r_cos_z	= cos(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD);
+
+	//-----------------------------------------------------
+	if( !Stream.Open(sFile) )
+	{
+		return( false );
+	}
+
+	if( !Stream.Read(sHeader, 80) )
+	{
+		return( false );
+	}
+
+	Message_Add(sHeader);
+
+	if( !Stream.Read(&nFacettes, sizeof(nFacettes)) )
+	{
+		return( false );
+	}
+
+	Message_Add(CSG_String::Format(SG_T("%s: %d"), _TL("Number of Facettes"), nFacettes));
+
+	//-----------------------------------------------------
+	switch( Method )
+	{
+
+	//-----------------------------------------------------
+	case 0:	{
+		CSG_PointCloud	*pPoints	= SG_Create_PointCloud();
+		Parameters("POINTS")->Set_Value(pPoints);
+		pPoints->Set_Name(SG_File_Get_Name(sFile, false));
+		pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined);
+
+		for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
+		{
+			if( Read_Facette(Stream, p) )
+			{
+				pPoints->Add_Point(
+					(p[0].x + p[1].x + p[2].x) / 3.0,
+					(p[0].y + p[1].y + p[2].y) / 3.0,
+					(p[0].z + p[1].z + p[2].z) / 3.0
+				);
+			}
+		}
+
+	break;	}
+
+	//-----------------------------------------------------
+	case 1:	{
+		CSG_Shapes	*pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, SG_File_Get_Name(sFile, false));
+		pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Float);
+		Parameters("SHAPES")->Set_Value(pPoints);
+
+		for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
+		{
+			if( Read_Facette(Stream, p) )
+			{
+				CSG_Shape	*pPoint	= pPoints->Add_Shape();
+
+				pPoint->Add_Point(
+					(p[0].x + p[1].x + p[2].x) / 3.0,
+					(p[0].y + p[1].y + p[2].y) / 3.0
+				);
+
+				pPoint->Set_Value(0,
+					(p[0].z + p[1].z + p[2].z) / 3.0
+				);
+			}
+		}
+
+	break;	}
+
+	//-----------------------------------------------------
+	case 2:	{
+		float	xMin = 1, xMax = 0, yMin, yMax;
+
+		for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
+		{
+			TSTL_Point	p[3];
+
+			if( Read_Facette(Stream, p) )
+			{
+				if( iFacette == 0 )
+				{
+					xMin	= xMax	= p[0].x;
+					yMin	= yMax	= p[0].y;
+				}
+
+				for(int i=0; i<3; i++)
+				{
+					if( xMin > p[i].x )	{	xMin	= p[i].x;	}	else if( xMax < p[i].x )	{	xMax	= p[i].x;	}
+					if( yMin > p[i].y )	{	yMin	= p[i].y;	}	else if( yMax < p[i].y )	{	yMax	= p[i].y;	}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( xMin < xMax && yMin < yMax && Stream.Seek(80 + sizeof(nFacettes)) )
+		{
+			int		nx, ny;
+			double	d;
+
+			nx		= Parameters("GRID_RES")->asInt();
+			d		= (xMax - xMin) / nx;
+			ny		= 1 + (int)((yMax - yMin) / d);
+
+			m_pGrid	= SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, xMin, yMin);
+			m_pGrid->Set_Name(SG_File_Get_Name(sFile, false));
+			m_pGrid->Set_NoData_Value(-99999);
+			m_pGrid->Assign_NoData();
+
+			Parameters("GRID")->Set_Value(m_pGrid);
+
+			//---------------------------------------------
+			for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
+			{
+				if( Read_Facette(Stream, p) )
+				{
+					TGRD_Point	Point[3];
+
+					for(int i=0; i<3; i++)
+					{
+						Point[i].x	= m_pGrid->Get_System().Get_xWorld_to_Grid(p[i].x);
+						Point[i].y	= m_pGrid->Get_System().Get_yWorld_to_Grid(p[i].y);
+						Point[i].z	= p[i].z;
+					}
+
+					Set_Triangle(Point);
+				}
+			}
+		}
+
+	break;	}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CSTL_Import::Read_Facette(CSG_File &Stream, TSTL_Point p[3])
+{
+	WORD	Attribute;
+
+	if( Stream.Read(p + 0, sizeof(TSTL_Point))
+	&&	Stream.Read(p + 0, sizeof(TSTL_Point))
+	&&	Stream.Read(p + 1, sizeof(TSTL_Point))
+	&&	Stream.Read(p + 2, sizeof(TSTL_Point))
+	&&	Stream.Read(&Attribute, sizeof(Attribute)) )
+	{
+		Rotate(p[0]);
+		Rotate(p[1]);
+		Rotate(p[2]);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline void CSTL_Import::Rotate(TSTL_Point &p)
+{
+	float	d;
+
+	d	= (float)(r_cos_z * p.x - r_sin_z * p.y);
+	p.y	= (float)(r_sin_z * p.x + r_cos_z * p.y);
+	p.x	= d;
+
+	d	= (float)(r_cos_y * p.z - r_sin_y * p.x);
+	p.x	= (float)(r_sin_y * p.z + r_cos_y * p.x);
+	p.z	= d;
+
+	d	= (float)(r_cos_x * p.z - r_sin_x * p.y);
+	p.y	= (float)(r_sin_x * p.z + r_cos_x * p.y);
+	p.z	= d;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SORT_POINTS_Y(a, b)	if( p[a].y < p[b].y ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+#define SORT_POINTS_X(a, b)	if( p[a].x < p[b].x ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+
+//---------------------------------------------------------
+void CSTL_Import::Set_Triangle(TGRD_Point p[3])
+{
+	int		i, j, y, y_j;
+	double	x, x_a, dx, dx_a, dy, z, z_a, dz, dz_a;
+	TGRD_Point	pp;
+
+	//-----------------------------------------------------
+	SORT_POINTS_Y(1, 0);
+	SORT_POINTS_Y(2, 0);
+	SORT_POINTS_Y(2, 1);
+
+	//-----------------------------------------------------
+	if( p[2].y == p[0].y )
+	{
+		if( p[0].y >= 0 && p[0].y < m_pGrid->Get_NY() )
+		{
+			SORT_POINTS_X(1, 0);
+			SORT_POINTS_X(2, 0);
+			SORT_POINTS_X(2, 1);
+
+			//---------------------------------------------
+			if( p[2].x == p[0].x )
+			{
+				if(	p[0].x >= 0 && p[0].x < m_pGrid->Get_NX() )
+				{
+					Set_Triangle_Point(p[0].x, p[0].y, p[0].z > p[1].z
+						? (p[0].z > p[2].z ? p[0].z : p[2].z)
+						: (p[1].z > p[2].z ? p[1].z : p[2].z)
+					);
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				Set_Triangle_Line(p[0].x, p[1].x, p[0].y, p[0].z, p[1].z);
+				Set_Triangle_Line(p[1].x, p[2].x, p[0].y, p[1].z, p[2].z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= m_pGrid->Get_NY() && p[2].y >= m_pGrid->Get_NY())) )
+	{
+		dy		=  p[2].y - p[0].y;
+		dx_a	= (p[2].x - p[0].x) / dy;
+		dz_a	= (p[2].z - p[0].z) / dy;
+		x_a		=  p[0].x;
+		z_a		=  p[0].z;
+
+		for(i=0, j=1; i<2; i++, j++)
+		{
+			if( (dy	=  p[j].y - p[i].y) > 0.0 )
+			{
+				dx		= (p[j].x - p[i].x) / dy;
+				dz		= (p[j].z - p[i].z) / dy;
+				x		=  p[i].x;
+				z		=  p[i].z;
+
+				if( (y = p[i].y) < 0 )
+				{
+					x		-= y * dx;
+					z		-= y * dz;
+					y		 = 0;
+					x_a		 = p[0].x - p[0].y * dx_a;
+					z_a		 = p[0].z - p[0].y * dz_a;
+				}
+
+				if( (y_j = p[j].y) > m_pGrid->Get_NY() )
+				{
+					y_j		= m_pGrid->Get_NY();
+				}
+
+				for( ; y<y_j; y++, x+=dx, z+=dz, x_a+=dx_a, z_a+=dz_a)
+				{
+					if( x < x_a )
+					{
+						Set_Triangle_Line((int)x, (int)x_a, y, z, z_a);
+					}
+					else
+					{
+						Set_Triangle_Line((int)x_a, (int)x, y, z_a, z);
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CSTL_Import::Set_Triangle_Line(int xa, int xb, int y, double za, double zb)
+{
+	double	dz;
+
+	if( (dz = xb - xa) > 0.0 )
+	{
+		dz	= (zb - za) / dz;
+
+		if( xa < 0 )
+		{
+			za	-= dz * xa;
+			xa	 = 0;
+		}
+
+		if( xb >= m_pGrid->Get_NX() )
+		{
+			xb	= m_pGrid->Get_NX() - 1;
+		}
+
+		for(int x=xa; x<=xb; x++, za+=dz)
+		{
+			Set_Triangle_Point(x, y, za);
+		}
+	}
+	else if( xa >= 0 && xa < m_pGrid->Get_NX() )
+	{
+		Set_Triangle_Point(xa, y, za);
+	}
+}
+
+//---------------------------------------------------------
+inline void CSTL_Import::Set_Triangle_Point(int x, int y, double z)
+{
+	if( m_pGrid->is_NoData(x, y) || m_pGrid->asDouble(x, y) < z )
+	{
+		m_pGrid->Set_Value(x, y, z);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSTL_Export::CSTL_Export(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Export TIN to Stereo Lithography File (STL)"));
+
+	Set_Author		(_TL("Navaladi, Schoeller, Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"<a href=\"http://www.ennex.com/~fabbers/StL.asp\">The StL Format</a>"
+	));
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_TIN(
+		NULL	, "TIN"			, _TL("TIN"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZFIELD"		, _TL("Z Attribute"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s"),
+			_TL("STL Files")	, SG_T("*.stl"),
+			_TL("All Files")	, SG_T("*.*")
+		), NULL, true
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "BINARY"		, _TL("Output Type"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("ASCII"),
+			_TL("binary")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+bool CSTL_Export::On_Execute(void)
+{
+	bool		bBinary;
+	int			zField;
+	float		v[3];
+	CSG_String	File;
+	CSG_File	Stream;
+	CSG_TIN		*pTIN;
+
+	pTIN	= Parameters("TIN")		->asTIN();
+	File	= Parameters("FILE")	->asString();
+	zField	= Parameters("ZFIELD")	->asInt(); 
+	bBinary	= Parameters("BINARY")	->asInt() == 1; 
+
+	if( !Stream.Open(File, SG_FILE_W, bBinary) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( bBinary )
+	{
+		char	*sHeader	= (char *)SG_Calloc(80, sizeof(char));
+		DWORD	nFacets		= pTIN->Get_Triangle_Count();
+		WORD	nBytes		= 0;
+
+		Stream.Write(sHeader , sizeof(char), 80);
+		Stream.Write(&nFacets, sizeof(DWORD));
+
+		SG_Free(sHeader);
+
+		//-------------------------------------------------
+		for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++)
+		{
+			CSG_TIN_Triangle	*pTriangle	= pTIN->Get_Triangle(iTriangle);
+
+			Get_Normal(pTriangle, zField, v);
+
+			Stream.Write(v, sizeof(float), 3);	// facet normal
+
+			for(int iNode=0; iNode<3; iNode++)
+			{
+				CSG_TIN_Node	*pNode	= pTriangle->Get_Node(iNode);
+
+				v[0]	= (float)pNode->Get_X();
+				v[1]	= (float)pNode->Get_Y();
+				v[2]	= (float)pNode->asDouble(zField);
+
+				Stream.Write(v, sizeof(float), 3);
+			}
+
+			Stream.Write(&nBytes, sizeof(WORD));
+		}
+	}
+
+	//-----------------------------------------------------
+	else	// ASCII
+	{
+		Stream.Printf(SG_T("solid %s\n"), SG_File_Get_Name(File, false).c_str());
+
+		for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++)
+		{
+			CSG_TIN_Triangle	*pTriangle	= pTIN->Get_Triangle(iTriangle);
+
+			Get_Normal(pTriangle, zField, v);
+
+			Stream.Printf(SG_T(" facet normal %.4f %.4f %.4f\n"), v[0], v[1], v[2]);
+			Stream.Printf(SG_T("  outer loop\n"));
+
+			for(int iNode=0; iNode<3; iNode++)
+			{
+				CSG_TIN_Node	*pNode	= pTriangle->Get_Node(iNode);
+
+				v[0]	= (float)pNode->Get_X();
+				v[1]	= (float)pNode->Get_Y();
+				v[2]	= (float)pNode->asDouble(zField);
+
+				Stream.Printf(SG_T("   vertex %.4f %.4f %.4f\n"), v[0], v[1], v[2]);
+			}
+
+			Stream.Printf(SG_T("  endloop\n"));
+			Stream.Printf(SG_T(" endfacet\n"));		
+		}
+
+		Stream.Printf(SG_T("endsolid %s\n"), SG_File_Get_Name(File, false).c_str());
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CSTL_Export::Get_Normal(CSG_TIN_Triangle *pTriangle, int zField, float Normal[3])
+{
+	double			u[3], v[3];
+	CSG_TIN_Node	*pA, *pB;
+
+	pA			= pTriangle->Get_Node(0);
+
+	pB			= pTriangle->Get_Node(1);
+	u[0]		= pB->Get_X()          - pA->Get_X();
+	u[1]		= pB->Get_Y()          - pA->Get_Y();
+	u[2]		= pB->asDouble(zField) - pA->asDouble(zField);
+
+	pB			= pTriangle->Get_Node(2);
+	v[0]		= pB->Get_X()          - pA->Get_X();
+	v[1]		= pB->Get_Y()          - pA->Get_Y();
+	v[2]		= pB->asDouble(zField) - pA->asDouble(zField);
+
+	Normal[0]	= (float)(u[1] * v[2] - u[2] * v[2]);
+	Normal[1]	= (float)(u[2] * v[0] - u[0] * v[1]);
+	Normal[2]	= (float)(u[0] * v[1] - u[1] * v[0]);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/stl.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,154 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                         stl.h                         //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__stl_H
+#define HEADER_INCLUDED__stl_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSTL_Import : public CSG_Module
+{
+public:
+	CSTL_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	typedef struct
+	{
+		float				x, y, z;
+	}
+	TSTL_Point;
+
+	typedef struct
+	{
+		int					x, y;
+
+		double				z;
+	}
+	TGRD_Point;
+
+
+	double					r_sin_x, r_cos_x, r_sin_y, r_cos_y, r_sin_z, r_cos_z;
+
+	CSG_Grid				*m_pGrid;
+
+
+	bool					Read_Facette		(CSG_File &Stream, TSTL_Point p[3]);
+	void					Rotate				(TSTL_Point &p);
+
+	void					Set_Triangle		(TGRD_Point p[3]);
+	void					Set_Triangle_Line	(int xa, int xb, int y, double za, double zb);
+	void					Set_Triangle_Point	(int x, int y, double z);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSTL_Export : public CSG_Module
+{
+public:
+	CSTL_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	bool					Get_Normal			(CSG_TIN_Triangle *pTriangle, int zField, float Normal[3]);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__stl_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,427 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Surfer_BLN.cpp                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "surfer_bln.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSurfer_BLN_Import::CSurfer_BLN_Import(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Import Surfer Blanking Files"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Import polygons/polylines from Golden Software's Surfer Blanking File format.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Table(
+		NULL	, "TABLE"	, _TL("Look up table (Points)"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL("Surfer Blanking Files (*.bln)|*.bln|All Files|*.*")
+	);
+
+	pNode	= Parameters.Add_Choice(
+		NULL	, "TYPE"	, _TL("Shape Type"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("points"),
+			_TL("lines"),
+			_TL("polygons")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CSurfer_BLN_Import::~CSurfer_BLN_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CSurfer_BLN_Import::On_Execute(void)
+{
+	bool				bOk;
+	int					ID, Flag, iPoint, nPoints;
+	double				x, y;
+	FILE				*Stream;
+	TSG_Shape_Type		Type;
+	CSG_String			FileName, sLine, sName, sDesc, sTemp;
+	CSG_Table_Record	*pRecord;
+	CSG_Table			*pTable;
+	CSG_Shape			*pShape;
+	CSG_Shapes			*pShapes;
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("SHAPES")	->asShapes();
+	pTable		= Parameters("TABLE")	->asTable();
+	FileName	= Parameters("FILE")	->asString();
+
+	switch( Parameters("TYPE")->asInt() )
+	{
+	case 0:				Type	= SHAPE_TYPE_Point;		break;
+	case 1:	default:	Type	= SHAPE_TYPE_Line;		break;
+	case 2:				Type	= SHAPE_TYPE_Polygon;	break;
+	}
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(FileName.b_str(), "r")) != NULL )
+	{
+		bOk		= true;
+		ID		= 0;
+
+		if(	pShapes->Get_Type() != SHAPE_TYPE_Undefined
+		&&	pShapes->Get_Type() != Type )
+		{
+			pShapes	= SG_Create_Shapes(Type, SG_File_Get_Name(FileName, false));
+			Parameters("SHAPES")->Set_Value(pShapes);
+			DataObject_Add(pShapes);
+		}
+		else
+		{
+			pShapes->Create(Type, SG_File_Get_Name(FileName, false));
+		}
+
+		if( Type == SHAPE_TYPE_Point )
+		{
+			if( pTable == NULL )
+			{
+				pTable	= SG_Create_Table();
+				Parameters("TABLE")->Set_Value(pTable);
+			}
+			else
+			{
+				pTable->Destroy();
+			}
+
+			pTable->			 Add_Field("ID"		, SG_DATATYPE_Int);
+			pTable->			 Add_Field("FLAG"	, SG_DATATYPE_Int);
+			pTable->			 Add_Field("NAME"	, SG_DATATYPE_String);
+			pTable->			 Add_Field("DESC"	, SG_DATATYPE_String);
+
+			pShapes->Add_Field("ID"		, SG_DATATYPE_Int);
+			pShapes->Add_Field("ID_LUT"	, SG_DATATYPE_Int);
+			pShapes->Add_Field("Z"		, SG_DATATYPE_Double);
+		}
+		else
+		{
+			pShapes->Add_Field("ID"		, SG_DATATYPE_Int);
+			pShapes->Add_Field("FLAG"	, SG_DATATYPE_Int);
+			pShapes->Add_Field("NAME"	, SG_DATATYPE_String);
+			pShapes->Add_Field("DESC"	, SG_DATATYPE_String);
+		}
+
+		//-------------------------------------------------
+		while( bOk && SG_Read_Line(Stream, sLine) && sLine.BeforeFirst(',').asInt(nPoints) && nPoints > 0 && Process_Get_Okay(true) )
+		{
+			Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), ++ID, _TL("shape in process")));
+
+			sTemp	= sLine.AfterFirst (',');	sLine	= sTemp;
+			Flag	= sLine.BeforeFirst(',').asInt();
+
+			sTemp	= sLine.AfterFirst (',');	sLine	= sTemp;
+			sTemp	= sLine.BeforeFirst(',');
+			sName	= sTemp.AfterFirst('\"').BeforeLast('\"');
+
+			sTemp	= sLine.AfterFirst (',');	sLine	= sTemp;
+			sTemp	= sLine.BeforeFirst(',');
+			sDesc	= sTemp.AfterFirst('\"').BeforeLast('\"');
+
+			if( Type == SHAPE_TYPE_Point )
+			{
+				pRecord	= pTable->Add_Record();
+				pRecord->Set_Value(0, ID);
+				pRecord->Set_Value(1, Flag);
+				pRecord->Set_Value(2, sName);
+				pRecord->Set_Value(3, sDesc);
+
+				for(iPoint=0; iPoint<nPoints && bOk; iPoint++)
+				{
+					if( (bOk = SG_Read_Line(Stream, sLine)) == true )
+					{
+						pShape	= pShapes->Add_Shape();
+						pShape->Set_Value(0, iPoint + 1);
+						pShape->Set_Value(1, ID);
+						pShape->Set_Value(2, sLine.AfterLast (',').asDouble());
+
+						x	= sLine.BeforeFirst(',').asDouble();
+						y	= sLine.AfterFirst (',').asDouble();
+						pShape->Add_Point(x, y);
+					}
+				}
+			}
+			else
+			{
+				pShape	= pShapes->Add_Shape();
+				pShape->Set_Value(0, ID);
+				pShape->Set_Value(1, Flag);
+				pShape->Set_Value(2, sName);
+				pShape->Set_Value(3, sDesc);
+
+				for(iPoint=0; iPoint<nPoints && bOk; iPoint++)
+				{
+					if( (bOk = SG_Read_Line(Stream, sLine)) == true )
+					{
+						x	= sLine.BeforeFirst(',').asDouble();
+						y	= sLine.AfterFirst (',').asDouble();
+						pShape->Add_Point(x, y);
+					}
+				}
+			}
+		}
+
+		fclose(Stream);
+	}
+
+	//-----------------------------------------------------
+	if( pShapes->is_Valid() && pShapes->Get_Count() > 0 )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSurfer_BLN_Export::CSurfer_BLN_Export(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Export Surfer Blanking File"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Export shapes to Golden Software's Surfer Blanking File format.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	CSG_Parameter	*pNode;
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "NAME"	, _TL("Name"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "DESC"	, _TL("Description"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "ZVAL"	, _TL("z values"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BNAME"	, _TL("Export names"),
+		_TL(""),
+		PARAMETER_TYPE_Bool	, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BDESC"	, _TL("Export descriptions"),
+		_TL(""),
+		PARAMETER_TYPE_Bool	, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BZVAL"	, _TL("Export z values"),
+		_TL(""),
+		PARAMETER_TYPE_Bool	, false
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"	, _TL("File"),
+		_TL(""),
+		_TL(
+		"Surfer Blanking Files (*.bln)|*.bln|All Files|*.*"), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CSurfer_BLN_Export::~CSurfer_BLN_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CSurfer_BLN_Export::On_Execute(void)
+{
+	int			iShape, iPart, iPoint, iName, iDesc, iZVal, Flag;
+	double		z;
+	FILE		*Stream;
+	TSG_Point	p;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+	CSG_String	fName;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	fName	= Parameters("FILE")	->asString();
+
+	iName	= Parameters("BNAME")	->asBool() ? Parameters("NAME")->asInt() : -1;
+	iDesc	= Parameters("BDESC")	->asBool() ? Parameters("DESC")->asInt() : -1;
+	iZVal	= Parameters("BZVAL")	->asBool() ? Parameters("ZVAL")->asInt() : -1;
+
+	Flag	= 1;
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+	{
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= pShapes->Get_Shape(iShape);
+
+			if( iZVal >= 0 )
+			{
+				z		= pShape->asDouble(iZVal);
+			}
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				fprintf(Stream, "%d,%d", pShape->Get_Point_Count(iPart), Flag);
+
+				if( iName >= 0 )
+				{
+					fprintf(Stream, ",\"%s\"", pShape->asString(iName));
+				}
+
+				if( iDesc >= 0 )
+				{
+					fprintf(Stream, ",\"%s\"", pShape->asString(iDesc));
+				}
+
+				fprintf(Stream, "\n");
+
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					p	= pShape->Get_Point(iPoint, iPart);
+
+					if( iZVal >= 0 )
+					{
+						fprintf(Stream, "%f,%f,%f\n", p.x, p.y, z);
+					}
+					else
+					{
+						fprintf(Stream, "%f,%f\n"   , p.x, p.y);
+					}
+				}
+			}
+		}
+
+		fclose(Stream);
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/surfer_bln.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_shapes                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Surfer_BLN.h                      //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Surfer_BLN_H
+#define HEADER_INCLUDED__Surfer_BLN_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSurfer_BLN_Import : public CSG_Module
+{
+public:
+	CSurfer_BLN_Import(void);
+	virtual ~CSurfer_BLN_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSurfer_BLN_Export : public CSG_Module
+{
+public:
+	CSurfer_BLN_Export(void);
+	virtual ~CSurfer_BLN_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Surfer_BLN_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,395 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WASP_MAP.cpp                      //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wasp_map.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWASP_MAP_Export::CWASP_MAP_Export(void)
+{
+	Set_Name		(_TL("Export WASP terrain map file"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Reference:\n"
+		"<a href=\"http://www.risoe.dk/vea/projects/nimo/WAsPHelp/Wasp8.htm#FileFormatofMAP.htm\" target=\"_blank\">"
+		"http://www.risoe.dk/vea/projects/nimo/WAsPHelp/Wasp8.htm#FileFormatofMAP.htm</a>"
+	));
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pShapes	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Contour Lines"),
+		_TL(""),
+		PARAMETER_INPUT			, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Table_Field(
+		pShapes	, "ELEVATION"	, _TL("Map File"),
+		_TL("")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("File Name"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|*.map|%s|*.*"),
+			_TL("WASP Map Files (*.map)"),
+			_TL("All Files")
+		), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CWASP_MAP_Export::~CWASP_MAP_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CWASP_MAP_Export::On_Execute(void)
+{
+	int			zField;
+	FILE		*Stream;
+	CSG_String	fName;
+	CSG_Shape	*pLine;
+	CSG_Shapes	*pLines;
+
+	//-----------------------------------------------------
+	pLines	= Parameters("SHAPES")		->asShapes();
+	zField	= Parameters("ELEVATION")	->asInt();
+	fName	= Parameters("FILE")		->asString();
+
+	//-----------------------------------------------------
+	if( pLines && pLines->is_Valid() && (Stream = fopen(fName.b_str(), "w")) != NULL )
+	{
+		// 1)	Text string identifying the terrain map: + ...
+
+		fprintf(Stream, "+ %s\n", pLines->Get_Name());
+
+
+		// 2)	Fixed point #1 in user and metric [m] coordinates:
+		//			X1(user) Y1(user) X1(metric) Y1(metric)
+
+		fprintf(Stream, "%f %f %f %f\n", 0.0, 0.0, 0.0, 0.0);
+
+
+		// 3)	Fixed point #2 in user and metric [m] coordinates:
+		//			X2(user) Y2(user) X2(metric) Y2(metric)
+
+		fprintf(Stream, "%f %f %f %f\n", 1.0, 1.0, 1.0, 1.0);
+
+
+		// 4)	Scaling factor and offset for height scale (Z):
+		//			Zmetric = {scaling factor}(Zuser + {offset})
+
+		fprintf(Stream, "%f %f\n", 1.0, 0.0);
+
+
+		for(int iLine=0; iLine<pLines->Get_Count() && Set_Progress(iLine, pLines->Get_Count()); iLine++)
+		{
+			pLine	= pLines->Get_Shape(iLine);
+
+			for(int iPart=0; iPart<pLine->Get_Part_Count(); iPart++)
+			{
+				if( pLine->Get_Point_Count(iPart) > 1 )
+				{
+					// 5a)	Height contour: elevation (Z) and number of points (n) in line:
+					//			Z n
+
+					fprintf(Stream, "%f %d\n", pLine->asDouble(zField), pLine->Get_Point_Count(iPart));
+
+
+					// 5b)	Roughness change line:
+					//			roughness lengths to the left (z0l) and right (z0r) side of the line,
+					//			respectively, and number of points:
+					//				z0l z0r n
+
+					// 5c)	Roughness and contour line:
+					//			roughness lengths to the left and right of the line,
+					//			respectively, elevation and number of points:
+					//				z0l z0r Z n
+
+
+					// 6–)	Cartesian coordinates (X, Y) of line described in 5a, 5b or 5c:
+					//			X1 Y1 [... Xn Yn]
+					//			Xn+1 Yn+1
+					//			... where [] embrace optional numbers and n is > 0
+
+					for(int iPoint=0; iPoint<pLine->Get_Point_Count(iPart); iPoint++)
+					{
+						TSG_Point	p	= pLine->Get_Point(iPoint, iPart);
+
+						fprintf(Stream, "%f\t%f\n", p.x, p.y);
+					}
+				}
+			}
+		}
+
+		fclose(Stream);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWASP_MAP_Import::CWASP_MAP_Import(void)
+{
+	Set_Name		(_TL("Import WASP terrain map file"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Reference:\n"
+		"<a href=\"http://www.risoe.dk/vea/projects/nimo/WAsPHelp/Wasp8.htm#FileFormatofMAP.htm\" target=\"_blank\">"
+		"http://www.risoe.dk/vea/projects/nimo/WAsPHelp/Wasp8.htm#FileFormatofMAP.htm</a>"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Contour Lines"),
+		_TL(""),
+		PARAMETER_OUTPUT		, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("File Name"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|*.map|%s|*.*"),
+			_TL("WASP Map Files (*.map)"),
+			_TL("All Files")
+		), NULL, false
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Input Specification"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("elevation"),
+			_TL("roughness"),
+			_TL("elevation and roughness")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CWASP_MAP_Import::~CWASP_MAP_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CWASP_MAP_Import::On_Execute(void)
+{
+	int			n, Method, nLength;
+	double		z, dz, zMin, rLeft, rRight;
+	FILE		*Stream;
+	TSG_Point	p, pu[2], pm[2];
+	CSG_String	fName, sLine;
+	CSG_Shape	*pLine;
+	CSG_Shapes	*pLines;
+
+	//-----------------------------------------------------
+	pLines	= Parameters("SHAPES")		->asShapes();
+	fName	= Parameters("FILE")		->asString();
+	Method	= Parameters("METHOD")		->asInt();
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(fName.b_str(), "r")) != NULL )
+	{
+		fseek(Stream, 0, SEEK_END);
+		nLength	= ftell(Stream);
+		fseek(Stream, 0, SEEK_SET);
+
+		pLines->Create(SHAPE_TYPE_Line, SG_File_Get_Name(fName, false));
+
+		switch( Method )
+		{
+		case 0:	// elevation
+			pLines->Add_Field("Z"		, SG_DATATYPE_Double);
+			break;
+
+		case 1:	// roughness
+			pLines->Add_Field("RLEFT"	, SG_DATATYPE_Double);
+			pLines->Add_Field("RRIGHT"	, SG_DATATYPE_Double);
+			break;
+
+		case 2:	// elevation and roughness
+			pLines->Add_Field("Z"		, SG_DATATYPE_Double);
+			pLines->Add_Field("RLEFT"	, SG_DATATYPE_Double);
+			pLines->Add_Field("RRIGHT"	, SG_DATATYPE_Double);
+			break;
+		}
+
+
+		// 1)	Text string identifying the terrain map: + ...
+
+		SG_Read_Line(Stream, sLine);
+
+
+		// 2)	Fixed point #1 in user and metric [m] coordinates:
+		//			X1(user) Y1(user) X1(metric) Y1(metric)
+
+		fscanf(Stream, "%lf %lf %lf %lf", &pu[0].x, &pu[0].y, &pm[0].x, &pm[0].y);
+
+
+		// 3)	Fixed point #2 in user and metric [m] coordinates:
+		//			X2(user) Y2(user) X2(metric) Y2(metric)
+
+		fscanf(Stream, "%lf %lf %lf %lf", &pu[1].x, &pu[1].y, &pm[1].x, &pm[1].y);
+
+
+		// 4)	Scaling factor and offset for height scale (Z):
+		//			Zmetric = {scaling factor}(Zuser + {offset})
+
+		fscanf(Stream, "%lf %lf", &dz, &zMin);
+
+
+		while( !feof(Stream) && Set_Progress(ftell(Stream), nLength) )
+		{
+			pLine	= NULL;
+
+			switch( Method )
+			{
+			case 0:	// elevation
+				// 5a)	Height contour: elevation (Z) and number of points (n) in line:
+				//			Z n
+
+				fscanf(Stream, "%lf %d", &z, &n);
+
+				if( !feof(Stream) && n > 1 )
+				{
+					pLine	= pLines->Add_Shape();
+					pLine->Set_Value(0, zMin + dz * z);
+				}
+				break;
+
+			case 1:	// roughness
+				// 5b)	Roughness change line:
+				//			roughness lengths to the left (z0l) and right (z0r) side of the line,
+				//			respectively, and number of points:
+				//				z0l z0r n
+
+				fscanf(Stream, "%lf %lf %d", &rLeft, &rRight, &n);
+
+				if( !feof(Stream) && n > 1 )
+				{
+					pLine	= pLines->Add_Shape();
+					pLine->Set_Value(0, rLeft);
+					pLine->Set_Value(1, rRight);
+				}
+				break;
+
+			case 2:	// elevation and roughness
+				// 5c)	Roughness and contour line:
+				//			roughness lengths to the left and right of the line,
+				//			respectively, elevation and number of points:
+				//				z0l z0r Z n
+
+				fscanf(Stream, "%lf %lf %lf %d", &rLeft, &rRight, &z, &n);
+
+				if( !feof(Stream) && n > 1 )
+				{
+					pLine	= pLines->Add_Shape();
+					pLine->Set_Value(0, zMin + dz * z);
+					pLine->Set_Value(1, rLeft);
+					pLine->Set_Value(2, rRight);
+				}
+				break;
+			}
+
+
+			// 6–)	Cartesian coordinates (X, Y) of line described in 5a, 5b or 5c:
+			//			X1 Y1 [... Xn Yn]
+			//			Xn+1 Yn+1
+			//			... where [] embrace optional numbers and n is > 0
+
+			for(int i=0; i<n && !feof(Stream) && Process_Get_Okay(false); i++)
+			{
+				fscanf(Stream, "%lf %lf", &p.x, &p.y);
+
+				pLine->Add_Point(p);
+			}
+		}
+
+		fclose(Stream);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/wasp_map.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     shapes_tools                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      WASP_MAP.h                       //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__WASP_MAP_H
+#define HEADER_INCLUDED__WASP_MAP_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWASP_MAP_Export : public CSG_Module
+{
+public:
+	CWASP_MAP_Export(void);
+	virtual ~CWASP_MAP_Export(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+};
+
+//---------------------------------------------------------
+class CWASP_MAP_Import : public CSG_Module
+{
+public:
+	CWASP_MAP_Import(void);
+	virtual ~CWASP_MAP_Import(void);
+
+	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__WASP_MAP_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,363 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Xyz.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "xyz.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CXYZ_Export::CXYZ_Export(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Export Shapes to XYZ"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(
+		_TL("XYZ export filter for shapes. ")
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode_1	= Parameters.Add_Table_Field(
+		pNode_0	, "FIELD"	, _TL("Attribute"),
+		_TL("")
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "ALL"		, _TL("Save All Attributes"),
+		_TL("Ignores specified attribute ('Save Attribute') and saves all attributes."),
+		PARAMETER_TYPE_Bool	, false
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "HEADER"	, _TL("Save Table Header"),
+		_TL(""),
+		PARAMETER_TYPE_Bool	, true
+	);
+
+	pNode_0	= Parameters.Add_Choice(
+		NULL	, "SEPARATE", _TL("Separate Line/Polygon Points"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("none"),
+			_TL("*"),
+			_TL("number of points")
+		), 0
+	);
+
+	pNode_0	= Parameters.Add_FilePath(
+		NULL	, "FILENAME", _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("XYZ Files (*.xyz)")	, SG_T("*.xyz"),
+			_TL("Text Files (*.txt)")	, SG_T("*.txt"),
+			_TL("All Files")			, SG_T("*.*")
+		), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CXYZ_Export::~CXYZ_Export(void)
+{}
+
+//---------------------------------------------------------
+bool CXYZ_Export::On_Execute(void)
+{
+	bool		bAll, bHeader;
+	int			iShape, iPart, iPoint, iField, Separate;
+	FILE		*Stream;
+	TSG_Point	Point;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+	CSG_String	fName;
+
+	//-----------------------------------------------------
+	pShapes		= Parameters("SHAPES")	->asShapes();
+	fName		= Parameters("FILENAME")->asString();
+	bAll		= Parameters("ALL")		->asBool();
+	bHeader		= Parameters("HEADER")	->asBool();
+	iField		= Parameters("FIELD")	->asInt();
+	Separate	= pShapes->Get_Type() == SHAPE_TYPE_Point ? 0
+				: Parameters("SEPARATE")->asInt();
+
+	if( bAll && (iField < 0 || iField >= pShapes->Get_Field_Count()) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( (Stream = fopen(fName.b_str(), "w")) != NULL )
+	{
+		if( bHeader )
+		{
+			fprintf(Stream, "X\tY");
+
+			if( bAll )
+			{
+				for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
+				{
+					fprintf(Stream, "\t%s", pShapes->Get_Field_Name(iField));
+				}
+			}
+			else
+			{
+				fprintf(Stream, "\tZ");
+			}
+
+			fprintf(Stream, "\n");
+		}
+
+		//-------------------------------------------------
+		for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= pShapes->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				switch( Separate )
+				{
+				case 1:	// *
+					fprintf(Stream, "*\n");
+					break;
+
+				case 2:	// number of points
+					fprintf(Stream, "%d\n", pShape->Get_Point_Count(iPart));
+					break;
+				}
+
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					Point	= pShape->Get_Point(iPoint, iPart);
+					fprintf(Stream, "%f\t%f", Point.x, Point.y);
+
+					if( bAll )
+					{
+						for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
+						{
+							switch( pShapes->Get_Field_Type(iField) )
+							{
+							case SG_DATATYPE_String:
+								fprintf(Stream, "\t\"%s\""	,pShape->asString(iField));
+								break;
+
+							default:
+								fprintf(Stream, "\t%f"		,pShape->asDouble(iField));
+								break;
+							}
+						}
+					}
+					else
+					{
+						switch( pShapes->Get_Field_Type(iField) )
+						{
+						case SG_DATATYPE_String:
+							fprintf(Stream, "\t\"%s\""	,pShape->asString(iField));
+							break;
+
+						default:
+							fprintf(Stream, "\t%f"		,pShape->asDouble(iField));
+							break;
+						}
+					}
+
+					fprintf(Stream, "\n");
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		fclose(Stream);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CXYZ_Import::CXYZ_Import(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Import Shapes from XYZ"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(
+		_TL("Point shapes import from text formated XYZ-table.")
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+//	pNode_0	= Parameters.Add_Value(
+//		NULL	, "HEADLINE"	, "File contains headline",
+//		_TL(""),
+//		PARAMETER_TYPE_Bool		, true
+//	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "X_FIELD"		, _TL("X Column"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 1, 1, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "Y_FIELD"		, _TL("Y Column"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 2, 1, true
+	);
+
+	pNode_0	= Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("File"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("XYZ Files (*.xyz)")	, SG_T("*.xyz"),
+			_TL("Text Files (*.txt)")	, SG_T("*.txt"),
+			_TL("All Files")			, SG_T("*.*")
+		), NULL, false
+	);
+}
+
+//---------------------------------------------------------
+CXYZ_Import::~CXYZ_Import(void)
+{}
+
+//---------------------------------------------------------
+bool CXYZ_Import::On_Execute(void)
+{
+	int					xField, yField, iRecord;
+	CSG_Table			Table;
+	CSG_Table_Record	*pRecord;
+	CSG_Shapes			*pShapes;
+	CSG_Shape			*pShape;
+
+	//-----------------------------------------------------
+	pShapes	= Parameters("SHAPES")	->asShapes();
+	xField	= Parameters("X_FIELD")	->asInt() - 1;
+	yField	= Parameters("Y_FIELD")	->asInt() - 1;
+
+	//-----------------------------------------------------
+	if( !Table.Create(Parameters("FILENAME")->asString()) )	// Parameters("HEADLINE")->asBool()
+	{
+		Message_Add(_TL("Table could not be opened."));
+	}
+	else if( Table.Get_Record_Count() <= 0 )
+	{
+		Message_Add(_TL("Table does not contain any data."));
+	}
+	else if( xField == yField || xField < 0 || xField >= Table.Get_Field_Count() || yField < 0 || yField >= Table.Get_Field_Count() )
+	{
+		Message_Add(_TL("Invalid X/Y fields."));
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		pShapes->Create(SHAPE_TYPE_Point, Table.Get_Name(), &Table);
+
+		for(iRecord=0; iRecord<Table.Get_Record_Count(); iRecord++)
+		{
+			pRecord	= Table.Get_Record(iRecord);
+			pShape	= pShapes->Add_Shape(pRecord);
+			pShape->Add_Point(pRecord->asDouble(xField), pRecord->asDouble(yField));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes/xyz.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,109 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Shapes_IO                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                         Xyz.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__XYZ_H
+#define HEADER_INCLUDED__XYZ_H
+
+//---------------------------------------------------------
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CXYZ_Export : public CSG_Module  
+{
+public:
+	CXYZ_Export(void);
+	virtual ~CXYZ_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+//---------------------------------------------------------
+class CXYZ_Import : public CSG_Module  
+{
+public:
+	CXYZ_Import(void);
+	virtual ~CXYZ_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__XYZ_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,125 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_IO_DXF                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import/Export - DXF") );
+
+	case MLB_INFO_Author:
+		return( _TL("(c) 2007 by O. Conrad") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the import and export of DXF files.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|Shapes") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "dxf_import.h"
+//#include "dxf_export.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case  0:	return( new CDXF_Import );
+//	case  1:	return( new CDXF_Export );
+	default:	return( NULL );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     Shapes_IO_DXF                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_shapes_dxf_H
+#define HEADER_INCLUDED__io_shapes_dxf_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_shapes_dxf_EXPORTS
+	#define	io_shapes_dxf_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_shapes_dxf_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_shapes_dxf_H

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,554 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     io_shapes_dxf                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     dxf_import.cpp                    //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dxf_import.h"
+
+#include "./dxflib/dl_dxf.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define ADD_RESULT(list, result)	if( result->is_Valid() && result->Get_Count() > 0 ) Parameters(list)->asList()->Add_Item(result); else delete(result);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	TBL_LAYERS_NAME		= 0,
+	TBL_LAYERS_FLAGS
+};
+
+enum
+{
+	TBL_BLOCKS_NAME		= 0,
+	TBL_BLOCKS_FLAGS,
+	TBL_BLOCKS_X,
+	TBL_BLOCKS_Y,
+	TBL_BLOCKS_Z
+};
+
+enum
+{
+	TBL_POINTS_LAYER	= 0,
+	TBL_POINTS_Z
+};
+
+enum
+{
+	TBL_LINES_LAYER		= 0,
+	TBL_LINES_Z1,
+	TBL_LINES_Z2
+};
+
+enum
+{
+	TBL_POLYOBJ_LAYER	= 0,
+	TBL_POLYOBJ_FLAGS
+};
+
+enum
+{
+	TBL_TRIANGLE_LAYER	= 0,
+	TBL_TRIANGLE_THICK,
+	TBL_TRIANGLE_Z1,
+	TBL_TRIANGLE_Z2,
+	TBL_TRIANGLE_Z3
+};
+
+enum
+{
+	TBL_TEXT_LAYER		= 0,
+	TBL_TEXT_Z,
+	TBL_TEXT_TEXT,
+	TBL_TEXT_HEIGHT,
+	TBL_TEXT_ANGLE,
+	TBL_TEXT_APX,
+	TBL_TEXT_APY,
+	TBL_TEXT_APZ,
+	TBL_TEXT_SCALE,
+	TBL_TEXT_HJUST,
+	TBL_TEXT_VJUST,
+	TBL_TEXT_STYLE,
+	TBL_TEXT_FLAGS
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDXF_Import::CDXF_Import(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(_TL("Import DXF Files"));
+
+	Set_Author		(SG_T("(c) 2007 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This module imports DXF files using the free \"dxflib\" library. Get more information "
+		"about this library from the RibbonSoft homepage at:\n"
+		"<a href=\"http://www.ribbonsoft.com/dxflib.html\">http://www.ribbonsoft.com/dxflib.html</a>"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. Parameters...
+
+	Parameters.Add_Shapes_List(
+		NULL	, "SHAPES"		, _TL("Shapes"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL	, "TABLES"		, _TL("Tables"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILE"		, _TL("File"),
+		_TL(""),
+		_TL("DXF Files (*.dxf)|*.dxf|All Files|*.*")
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "FILTER"		, _TL("Import Filter"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("all entities"),
+			_TL("only entities with layer definition"),
+			_TL("only entities without layer definition")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DCIRCLE"		, _TL("Circle Point Distance [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 5.0, 0.01, true, 45.0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CDXF_Import::On_Execute(void)
+{
+	CSG_String	fName	= Parameters("FILE")->asString();
+
+	Parameters("TABLES")->asTableList() ->Del_Items();
+	Parameters("SHAPES")->asShapesList()->Del_Items();
+
+	m_Filter	= Parameters("FILTER")	->asInt();
+	m_dArc		= Parameters("DCIRCLE")	->asDouble() * M_DEG_TO_RAD;
+
+	//-----------------------------------------------------
+	if( SG_File_Exists(fName) )
+	{
+		m_pLayers		= SG_Create_Table();
+		m_pLayers		->Set_Name(CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Layers")));
+		m_pLayers		->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pLayers		->Add_Field("FLAGS"	, SG_DATATYPE_Int);
+
+		m_pBlocks		= SG_Create_Table();
+		m_pBlocks		->Set_Name(CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Blocks")));
+		m_pBlocks		->Add_Field("BLOCK"	, SG_DATATYPE_String);
+		m_pBlocks		->Add_Field("FLAGS"	, SG_DATATYPE_Int);
+		m_pBlocks		->Add_Field("X"		, SG_DATATYPE_Double);
+		m_pBlocks		->Add_Field("Y"		, SG_DATATYPE_Double);
+		m_pBlocks		->Add_Field("Z"		, SG_DATATYPE_Double);
+
+		m_pPoints		= SG_Create_Shapes(SHAPE_TYPE_Point		, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Points")));
+		m_pPoints		->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pPoints		->Add_Field("Z"		, SG_DATATYPE_Double);
+
+		m_pLines		= SG_Create_Shapes(SHAPE_TYPE_Line		, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Lines")));
+		m_pLines		->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pLines		->Add_Field("Z1"	, SG_DATATYPE_Double);
+		m_pLines		->Add_Field("Z2"	, SG_DATATYPE_Double);
+
+		m_pPolyLines	= SG_Create_Shapes(SHAPE_TYPE_Line		, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Polylines")));
+		m_pPolyLines	->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pPolyLines	->Add_Field("FLAGS"	, SG_DATATYPE_Int);
+
+		m_pPolygons		= SG_Create_Shapes(SHAPE_TYPE_Polygon	, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Polygons")));
+		m_pPolygons		->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pPolygons		->Add_Field("FLAGS"	, SG_DATATYPE_Int);
+
+		m_pCircles		= SG_Create_Shapes(SHAPE_TYPE_Line		, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Circles")));
+		m_pCircles		->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pCircles		->Add_Field("FLAGS"	, SG_DATATYPE_Int);
+
+		m_pTriangles	= SG_Create_Shapes(SHAPE_TYPE_Polygon	, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Triangles")));
+		m_pTriangles	->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pTriangles	->Add_Field("THICK"	, SG_DATATYPE_Int);
+		m_pTriangles	->Add_Field("Z1"	, SG_DATATYPE_Double);
+		m_pTriangles	->Add_Field("Z2"	, SG_DATATYPE_Double);
+		m_pTriangles	->Add_Field("Z3"	, SG_DATATYPE_Double);
+
+		m_pText			= SG_Create_Shapes(SHAPE_TYPE_Point		, CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Text")));
+		m_pText			->Add_Field("LAYER"	, SG_DATATYPE_String);
+		m_pText			->Add_Field("Z"		, SG_DATATYPE_Double);
+		m_pText			->Add_Field("TEXT"	, SG_DATATYPE_String);
+		m_pText			->Add_Field("HEIGHT", SG_DATATYPE_Int);
+		m_pText			->Add_Field("ANGLE"	, SG_DATATYPE_Double);
+		m_pText			->Add_Field("APX"	, SG_DATATYPE_Double);
+		m_pText			->Add_Field("APY"	, SG_DATATYPE_Double);
+		m_pText			->Add_Field("APZ"	, SG_DATATYPE_Double);
+		m_pText			->Add_Field("SCALE"	, SG_DATATYPE_Double);
+		m_pText			->Add_Field("HJUST"	, SG_DATATYPE_Int);
+		m_pText			->Add_Field("VJUST"	, SG_DATATYPE_Int);
+		m_pText			->Add_Field("STYLE"	, SG_DATATYPE_String);
+		m_pText			->Add_Field("FLAGS"	, SG_DATATYPE_Int);
+
+		//-------------------------------------------------
+		m_Offset.x		= 0.0;
+		m_Offset.y		= 0.0;
+		m_Offset.z		= 0.0;
+
+		m_pPolyLine		= NULL;
+
+		DL_Dxf	*pDXF	= new DL_Dxf();
+
+		pDXF->in(fName.b_str(), this);
+
+		delete(pDXF);
+
+		//-------------------------------------------------
+		ADD_RESULT("TABLES", m_pLayers);
+		ADD_RESULT("TABLES", m_pBlocks);
+		ADD_RESULT("SHAPES", m_pPoints);
+		ADD_RESULT("SHAPES", m_pLines);
+		ADD_RESULT("SHAPES", m_pPolyLines);
+		ADD_RESULT("SHAPES", m_pPolygons);
+		ADD_RESULT("SHAPES", m_pCircles);
+		ADD_RESULT("SHAPES", m_pTriangles);
+		ADD_RESULT("SHAPES", m_pText);
+	}
+
+	//-----------------------------------------------------
+	return( Parameters("SHAPES")->asShapesList()->Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CDXF_Import::Check_Process(void)
+{
+	static int	iProcess	= 0;
+
+	if( (iProcess++) % 100 == 0 )
+	{
+		Process_Get_Okay();
+	}
+}
+
+//---------------------------------------------------------
+inline bool CDXF_Import::Check_Layer(const CSG_String &Name)
+{
+	Check_Process();
+
+	switch( m_Filter )
+	{
+	case 1:	return( Name.Cmp(SG_T("0")) != 0 );
+	case 2:	return( Name.Cmp(SG_T("0")) == 0 );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline void CDXF_Import::Add_Arc_Point(CSG_Shape *pShape, double cx, double cy, double d, double theta)
+{
+	pShape->Add_Point(
+		cx + d * cos(theta),
+		cy + d * sin(theta)
+	);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::Add_Arc(CSG_Shape *pShape, double cx, double cy, double d, double alpha, double beta)
+{
+	double	theta;
+
+	alpha	*= M_DEG_TO_RAD;
+	beta	*= M_DEG_TO_RAD;
+
+	if( alpha > beta )
+	{
+		beta	+= M_PI_360;
+	}
+
+	for(theta=alpha; theta<beta; theta+=m_dArc)
+	{
+		Add_Arc_Point(pShape, cx, cy, d, theta);
+	}
+
+	Add_Arc_Point(pShape, cx, cy, d, beta);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDXF_Import::addLayer(const DL_LayerData &data)
+{
+	CSG_Table_Record	*pRecord	= m_pLayers->Add_Record();
+
+	pRecord->Set_Value(TBL_LAYERS_NAME	, CSG_String(data.name.c_str()));
+	pRecord->Set_Value(TBL_LAYERS_FLAGS	, data.flags);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addBlock(const DL_BlockData &data)
+{
+	CSG_Table_Record	*pRecord	= m_pBlocks->Add_Record();
+
+	pRecord->Set_Value(TBL_BLOCKS_NAME	, CSG_String(data.name.c_str()));
+	pRecord->Set_Value(TBL_BLOCKS_FLAGS	, data.flags);
+	pRecord->Set_Value(TBL_BLOCKS_X		, data.bpx);
+	pRecord->Set_Value(TBL_BLOCKS_Y		, data.bpy);
+	pRecord->Set_Value(TBL_BLOCKS_Z		, data.bpz);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::endBlock(void)
+{
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addPoint(const DL_PointData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	CSG_Shape	*pPoint	= m_pPoints->Add_Shape();
+
+	pPoint->Add_Point(m_Offset.x + data.x, m_Offset.y + data.y);
+
+	pPoint->Set_Value(TBL_POINTS_LAYER	, CSG_String(attributes.getLayer().c_str()));
+	pPoint->Set_Value(TBL_POINTS_Z		, m_Offset.z + data.z);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addLine(const DL_LineData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	CSG_Shape	*pLine	= m_pLines->Add_Shape();
+
+	pLine->Add_Point(m_Offset.x + data.x1, m_Offset.y + data.y1);
+	pLine->Add_Point(m_Offset.x + data.x2, m_Offset.y + data.y2);
+
+	pLine->Set_Value(TBL_LINES_LAYER	, CSG_String(attributes.getLayer().c_str()));
+	pLine->Set_Value(TBL_LINES_Z1		, m_Offset.z + data.z1);
+	pLine->Set_Value(TBL_LINES_Z2		, m_Offset.z + data.z2);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addPolyline(const DL_PolylineData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	switch( data.flags )
+	{
+	default:
+	case 0:	m_pPolyLine	= m_pPolyLines	->Add_Shape();	break;
+	case 1:	m_pPolyLine	= m_pPolygons	->Add_Shape();	break;
+	}
+
+	m_pPolyLine->Set_Value(TBL_POLYOBJ_LAYER, CSG_String(attributes.getLayer().c_str()));
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addVertex(const DL_VertexData &data)
+{
+	if( m_pPolyLine )
+	{
+		m_pPolyLine->Add_Point(m_Offset.x + data.x, m_Offset.y + data.y);	// data.z, data.bulge
+	}
+}
+
+//---------------------------------------------------------
+void CDXF_Import::endSequence(void)
+{
+	if( m_pPolyLine )
+	{
+		if( !m_pPolyLine->is_Valid() )
+		{
+			((CSG_Shapes *)m_pPolyLine->Get_Table())->Del_Shape(m_pPolyLine);
+		}
+
+		m_pPolyLine	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addCircle(const DL_CircleData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	CSG_Shape	*pCircle	= m_pCircles->Add_Shape();
+
+	Add_Arc(pCircle, data.cx, data.cy, data.radius, 0.0, 360.0);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addArc(const DL_ArcData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	CSG_Shape	*pArc	= m_pPolyLine ? m_pPolyLine : m_pPolyLines->Add_Shape();
+
+	Add_Arc(pArc, data.cx, data.cy, data.radius, data.angle1, data.angle2);
+
+	if( pArc != m_pPolyLine )
+	{
+		pArc->Set_Value(TBL_POLYOBJ_LAYER, CSG_String(attributes.getLayer().c_str()));
+	}
+}
+
+//---------------------------------------------------------
+void CDXF_Import::add3dFace(const DL_3dFaceData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	CSG_Shape	*pTriangle	= m_pTriangles->Add_Shape();
+
+	for(int i=0; i<3; i++)
+	{
+		pTriangle->Add_Point(m_Offset.x + data.x[i], m_Offset.y + data.y[i]);
+	}
+
+	pTriangle->Set_Value(TBL_TRIANGLE_LAYER	, CSG_String(attributes.getLayer().c_str()));
+	pTriangle->Set_Value(TBL_TRIANGLE_THICK	, data.thickness);
+	pTriangle->Set_Value(TBL_TRIANGLE_Z1	, m_Offset.z + data.z[0]);
+	pTriangle->Set_Value(TBL_TRIANGLE_Z2	, m_Offset.z + data.z[1]);
+	pTriangle->Set_Value(TBL_TRIANGLE_Z3	, m_Offset.z + data.z[2]);
+}
+
+//---------------------------------------------------------
+void CDXF_Import::addText(const DL_TextData &data)
+{
+	if( !Check_Layer(attributes.getLayer().c_str()) )
+		return;
+
+	CSG_Shape	*pText	= m_pText->Add_Shape();
+
+	pText->Add_Point(m_Offset.x + data.ipx, m_Offset.y + data.ipy);
+
+	pText->Set_Value(TBL_TEXT_LAYER	, CSG_String(attributes.getLayer().c_str()));
+	pText->Set_Value(TBL_TEXT_Z		, m_Offset.z + data.ipz);
+	pText->Set_Value(TBL_TEXT_TEXT	, CSG_String(data.text.c_str()));
+	pText->Set_Value(TBL_TEXT_HEIGHT, data.height);
+	pText->Set_Value(TBL_TEXT_ANGLE	, data.angle * M_RAD_TO_DEG);
+	pText->Set_Value(TBL_TEXT_APX	, m_Offset.z + data.apx);
+	pText->Set_Value(TBL_TEXT_APY	, m_Offset.z + data.apy);
+	pText->Set_Value(TBL_TEXT_APZ	, m_Offset.z + data.apz);
+	pText->Set_Value(TBL_TEXT_SCALE	, data.xScaleFactor);
+	pText->Set_Value(TBL_TEXT_HJUST	, data.hJustification);
+	pText->Set_Value(TBL_TEXT_VJUST	, data.vJustification);
+	pText->Set_Value(TBL_TEXT_STYLE	, CSG_String(data.style.c_str()));
+	pText->Set_Value(TBL_TEXT_SCALE	, data.textGenerationFlags);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/shapes/io_shapes_dxf/dxf_import.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,143 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     io_shapes_dxf                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     dxf_import.cpp                    //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__dxf_import_H
+#define HEADER_INCLUDED__dxf_import_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include "./dxflib/dl_creationadapter.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDXF_Import : public CSG_Module, DL_CreationAdapter
+{
+public:
+	CDXF_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						m_Filter;
+
+	double					m_dArc;
+
+	TSG_Point_3D			m_Offset;
+
+	CSG_Shape				*m_pPolyLine;
+
+	CSG_Table				*m_pLayers, *m_pBlocks;
+
+	CSG_Shapes				*m_pPoints, *m_pLines, *m_pPolyLines, *m_pPolygons, *m_pCircles, *m_pTriangles, *m_pText;
+
+
+	void					Check_Process	(void);
+	bool					Check_Layer		(const CSG_String &Name);
+
+	void					Add_Arc_Point	(CSG_Shape *pShape, double cx, double cy, double d, double theta);
+	void					Add_Arc			(CSG_Shape *pShape, double cx, double cy, double d, double alpha, double beta);
+
+	virtual void			addLayer		(const DL_LayerData    &data);
+
+	virtual void			addBlock		(const DL_BlockData    &data);
+	virtual void			endBlock		(void);
+
+	virtual void			addPoint		(const DL_PointData    &data);
+	virtual void			addLine			(const DL_LineData     &data);
+	virtual void			addPolyline		(const DL_PolylineData &data);
+	virtual void			addVertex		(const DL_VertexData   &data);
+	virtual void			endSequence		(void);
+	virtual void			addArc			(const DL_ArcData      &data);
+	virtual void			addCircle		(const DL_CircleData   &data);
+	virtual void			add3dFace		(const DL_3dFaceData   &data);
+
+	virtual void			addText			(const DL_TextData     &data);
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__dxf_import_H

Added: packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_table                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Import/Export - Tables") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton (c) 2008") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the import and export of tables.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("File|Tables") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "io_table_txt.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case  0:	return( new CTable_Text_Export );
+	case  1:	return( new CTable_Text_Import );
+	case  2:	return( new CTable_Text_Import_Numbers );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/table/io_table/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       io_table                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_table_H
+#define HEADER_INCLUDED__io_table_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef io_table_EXPORTS
+	#define	io_table_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	io_table_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_table_H

Added: packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,455 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       table_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    io_table_txt.cpp                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "io_table_txt.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Export							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Text_Export::CTable_Text_Export(void)
+{
+	Set_Name		(_TL("Export Text Table"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Table"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "HEADLINE"	, _TL("Save Headline"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "STRQUOTA"	, _TL("Strings in Quota"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SEPARATOR"	, _TL("Separator"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("tabulator"),
+			_TL(";"),
+			_TL(","),
+			_TL("other")
+		), 0
+	);
+
+	Parameters.Add_String(
+		NULL	, "SEP_OTHER"	, _TL("Separator (other)"),
+		_TL(""),
+		SG_T("*")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("Text Files (*.txt)")	, SG_T("*.txt"),
+			_TL("CSV Files (*.csv)")	, SG_T("*.csv"),
+			_TL("All Files")			, SG_T("*.*")
+		), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+bool CTable_Text_Export::On_Execute(void)
+{
+	CSG_String	StrFormat, Separator;
+	CSG_File	Stream;
+	CSG_Table	*pTable;
+
+	//-----------------------------------------------------
+	pTable		= Parameters("TABLE")		->asTable();
+	StrFormat	= Parameters("STRQUOTA")	->asBool() ? SG_T("\"%s\"") : SG_T("%s");
+
+	switch( Parameters("SEPARATOR")->asInt() )
+	{
+	case 0:		Separator	= "\t";	break;
+	case 1:		Separator	=  ";";	break;
+	case 2:		Separator	=  ",";	break;
+	default:	Separator	= Parameters("SEP_OTHER")->asString();	break;
+	}
+
+	//-----------------------------------------------------
+	if( !Stream.Open(Parameters("FILENAME")->asString(), SG_FILE_W, false) )
+	{
+		Message_Add(_TL("file could not be opened."));
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		if( Parameters("HEADLINE")->asBool() )
+		{
+			for(int iField=0; iField<pTable->Get_Field_Count(); iField++)
+			{
+				Stream.Printf(StrFormat, pTable->Get_Field_Name(iField));
+				Stream.Printf(iField < pTable->Get_Field_Count() - 1 ? Separator.c_str() : SG_T("\n"));
+			}
+		}
+
+		//-------------------------------------------------
+		for(int iRecord=0; iRecord<pTable->Get_Record_Count() && Set_Progress(iRecord, pTable->Get_Record_Count()); iRecord++)
+		{
+			CSG_Table_Record	*pRecord	= pTable->Get_Record(iRecord);
+
+			for(int iField=0; iField<pTable->Get_Field_Count(); iField++)
+			{
+				switch( pTable->Get_Field_Type(iField) )
+				{
+				default:
+				case SG_DATATYPE_Char:
+				case SG_DATATYPE_String:
+				case SG_DATATYPE_Date:
+					Stream.Printf(StrFormat		, pRecord->asString(iField));
+					break;
+
+				case SG_DATATYPE_Short:
+				case SG_DATATYPE_Int:
+				case SG_DATATYPE_Long:
+				case SG_DATATYPE_Color:
+					Stream.Printf(SG_T("%d")	, pRecord->asDouble(iField));
+
+				case SG_DATATYPE_Float:
+				case SG_DATATYPE_Double:
+					Stream.Printf(SG_T("%f")	, pRecord->asDouble(iField));
+					break;
+				}
+
+				Stream.Printf(iField < pTable->Get_Field_Count() - 1 ? Separator.c_str() : SG_T("\n"));
+			}
+		}
+
+		//-------------------------------------------------
+		Stream.Close();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Text_Import::CTable_Text_Import(void)
+{
+	Set_Name		(_TL("Import Text Table"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Points"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "HEADLINE"	, _TL("File contains headline"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SEPARATOR"	, _TL("Separator"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("tabulator"),
+			_TL(";"),
+			_TL(","),
+			_TL("space"),
+			_TL("other")
+		), 0
+	);
+
+	Parameters.Add_String(
+		NULL	, "SEP_OTHER"	, _TL("Separator (other)"),
+		_TL(""),
+		SG_T("*")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("Text Files (*.txt)")	, SG_T("*.txt"),
+			_TL("CSV Files (*.csv)")	, SG_T("*.csv"),
+			_TL("All Files")			, SG_T("*.*")
+		), NULL, false
+	);
+}
+
+//---------------------------------------------------------
+bool CTable_Text_Import::On_Execute(void)
+{
+	bool		bHeader;
+	CSG_String	Separator;
+	CSG_Table	*pTable;
+
+	//-----------------------------------------------------
+	pTable	= Parameters("TABLE")		->asTable();
+	bHeader	= Parameters("HEADLINE")	->asBool();
+
+	switch( Parameters("SEPARATOR")->asInt() )
+	{
+	case 0:		Separator	= "\t";	break;
+	case 1:		Separator	=  ";";	break;
+	case 2:		Separator	=  ",";	break;
+	case 3:		Separator	=  " ";	break;
+	default:	Separator	= Parameters("SEP_OTHER")->asString();	break;
+	}
+
+	//-----------------------------------------------------
+	if( !pTable->Create(Parameters("FILENAME")->asString(), bHeader ? TABLE_FILETYPE_Text : TABLE_FILETYPE_Text_NoHeadLine, Separator) )
+	{
+		Message_Add(_TL("table could not be opened."));
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Import							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTable_Text_Import_Numbers::CTable_Text_Import_Numbers(void)
+{
+	Set_Name		(_TL("Import Text Table with Numbers only"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Table"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "HEADLINE"	, _TL("File contains headline"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SEPARATOR"	, _TL("Separator"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("tabulator"),
+			_TL(";"),
+			_TL(","),
+			_TL("other")
+		), 0
+	);
+
+	Parameters.Add_String(
+		NULL	, "SEP_OTHER"	, _TL("Separator (other)"),
+		_TL(""),
+		SG_T("*")
+	);
+
+	Parameters.Add_FilePath(
+		NULL	, "FILENAME"	, _TL("File"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s"),
+			_TL("Text Files (*.txt)")	, SG_T("*.txt"),
+			_TL("CSV Files (*.csv)")	, SG_T("*.csv"),
+			_TL("All Files")			, SG_T("*.*")
+		), NULL, false
+	);
+}
+
+//---------------------------------------------------------
+bool CTable_Text_Import_Numbers::On_Execute(void)
+{
+	bool		bHeader;
+	double		Value;
+	CSG_String	sLine, sHead, Separator;
+	CSG_File	Stream;
+	CSG_Table	*pTable;
+
+	//-----------------------------------------------------
+	pTable	= Parameters("TABLE")		->asTable();
+	bHeader	= Parameters("HEADLINE")	->asBool();
+
+	switch( Parameters("SEPARATOR")->asInt() )
+	{
+	case 0:		Separator	= "\t";	break;
+	case 1:		Separator	=  ";";	break;
+	case 2:		Separator	=  ",";	break;
+	default:	Separator	= Parameters("SEP_OTHER")->asString();	break;
+	}
+
+	//-----------------------------------------------------
+	if( !Stream.Open(Parameters("FILENAME")->asString(), SG_FILE_R, false) )
+	{
+		Message_Add(_TL("file could not be opened"));
+	}
+
+	else if( !Stream.Read_Line(sLine) || sLine.Length() == 0 )
+	{
+		Message_Add(_TL("empty or corrupted file"));
+	}
+
+	else if( bHeader && (!Stream.Read_Line(sLine) || sLine.Length() == 0) )
+	{
+		Message_Add(_TL("empty or corrupted file"));
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		pTable->Destroy();
+		pTable->Set_Name(SG_File_Get_Name(Parameters("FILENAME")->asString(), false));
+
+		sLine.Replace(Separator, SG_T("\t"));
+		sHead	= sLine;
+
+		do
+		{
+			sHead.Trim();
+
+			if( sHead.asDouble(Value) )
+			{
+				pTable->Add_Field(CSG_String::Format(SG_T("%d"), 1 + pTable->Get_Field_Count()), SG_DATATYPE_Double);
+			}
+
+			sHead	= sHead.AfterFirst('\t');
+		}
+		while( sHead.Length() > 0 );
+
+		//-------------------------------------------------
+		if( pTable->Get_Field_Count() > 0 )
+		{
+			int		fLength	= Stream.Length();
+
+			do
+			{
+				sLine.Replace(Separator, SG_T("\t"));
+
+				CSG_Table_Record	*pRecord	= pTable->Add_Record();
+
+				for(int i=0; i<pTable->Get_Field_Count(); i++)
+				{
+					sLine.Trim();
+
+					pRecord->Set_Value(i, sLine.asDouble());
+
+					sLine	= sLine.AfterFirst('\t');
+				}
+			}
+			while( Stream.Read_Line(sLine) && sLine.Length() > 0 && Set_Progress(Stream.Tell(), fLength) );
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_io/table/io_table/io_table_txt.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       table_io                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    io_table_txt.h                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__io_table_txt_H
+#define HEADER_INCLUDED__io_table_txt_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTable_Text_Export : public CSG_Module  
+{
+public:
+	CTable_Text_Export(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Export") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+//---------------------------------------------------------
+class CTable_Text_Import : public CSG_Module  
+{
+public:
+	CTable_Text_Import(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+//---------------------------------------------------------
+class CTable_Text_Import_Numbers : public CSG_Module  
+{
+public:
+	CTable_Text_Import_Numbers(void);
+
+	virtual const SG_Char *	Get_MenuPath(void)		{	return( _TL("R:Import") );	}
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__io_table_txt_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,197 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_01.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_01.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_01::CExercise_01(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("01: My first module"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Input"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "OUTPUT"	, _TL("Output"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "FACTOR"	, _TL("Factor"),
+		_TL("Type in a value that shall be used for the chosen mathematical operation."),
+		PARAMETER_TYPE_Double,
+		1.0
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"	, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Addition|"),
+			_TL("Subtraction"),
+			_TL("Multiplication"),
+			_TL("Division")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_01::~CExercise_01(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_01::On_Execute(void)
+{
+	int		x, y, Method;
+	double	Factor, Value_Input, Value_Output;
+	CSG_Grid	*pInput, *pOutput;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	pInput		= Parameters("INPUT" )->asGrid();
+	pOutput		= Parameters("OUTPUT")->asGrid();
+	Factor		= Parameters("FACTOR")->asDouble();
+	Method		= Parameters("METHOD")->asInt();
+
+
+	//-----------------------------------------------------
+	// Check for valid parameter settings...
+
+	if( Method == 3 && Factor == 0.0 )
+	{
+		Message_Add(_TL("Division by zero is not allowed !!!"));
+		Message_Dlg(_TL("Division by zero is not allowed !!!"));
+
+		return( false );	// prevent a division by zero!!!
+	}
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Value_Input	= pInput->asDouble(x, y);
+
+			switch( Method )
+			{
+			case 0:	// Addition...
+				Value_Output	= Value_Input + Factor;
+				break;
+
+			case 1:	// Subtraction...
+				Value_Output	= Value_Input - Factor;
+				break;
+
+			case 2:	// Multiplication...
+				Value_Output	= Value_Input * Factor;
+				break;
+
+			case 3:	// Division...
+				Value_Output	= Value_Input / Factor;
+				break;
+			}
+
+			pOutput->Set_Value(x, y, Value_Output);
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_01.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,88 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_01.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_01_H
+#define HEADER_INCLUDED__Exercise_01_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_01 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_01(void);							// constructor
+	virtual ~CExercise_01(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_01_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,198 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_02.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_02.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_02::CExercise_02(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("02: Pixel by pixel operations with two grids"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Pixel by pixel operations with two grids.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT_A"	, _TL("First input grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "INPUT_B"	, _TL("Second input grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "OUTPUT"	, _TL("Output"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"	, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Addition|"),
+			_TL("Subtraction"),
+			_TL("Multiplication"),
+			_TL("Division")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_02::~CExercise_02(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_02::On_Execute(void)
+{
+	int		x, y, Method;
+	double	a, b;
+	CSG_Grid	*pInput_A, *pInput_B, *pOutput;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	pInput_A	= Parameters("INPUT_A")->asGrid();
+	pInput_B	= Parameters("INPUT_B")->asGrid();
+	pOutput		= Parameters("OUTPUT")->asGrid();
+	Method		= Parameters("METHOD")->asInt();
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pInput_A->is_NoData(x, y) || pInput_B->is_NoData(x, y) )	// don't work with 'no data'...
+			{
+				pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				a	= pInput_A->asDouble(x, y);
+				b	= pInput_B->asDouble(x, y);
+
+				switch( Method )
+				{
+				case 0:	// Addition...
+					pOutput->Set_Value(x, y, a + b);
+					break;
+
+				case 1:	// Subtraction...
+					pOutput->Set_Value(x, y, a - b);
+					break;
+
+				case 2:	// Multiplication...
+					pOutput->Set_Value(x, y, a * b);
+					break;
+
+				case 3:	// Division...
+					if( b != 0.0 )	// prevent division by zero...
+					{
+						pOutput->Set_Value(x, y, a / b);
+					}
+					else
+					{
+						pOutput->Set_NoData(x, y);
+					}
+					break;
+				}
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_02.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,88 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_02.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_02_H
+#define HEADER_INCLUDED__Exercise_02_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_02 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_02(void);							// constructor
+	virtual ~CExercise_02(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_02_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,318 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_03.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_03.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_03::CExercise_03(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("03: Direct neighbours"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Simple neighbourhood analysis for grid cells.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Input grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "OUTPUT"	, _TL("Output"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"	, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Difference to left neighbour"),
+			_TL("Difference to left neighbour (using a while loop)"),
+			_TL("Slope gradient to left neighbour [%%]"),
+			_TL("Slope gradient to left neighbour [Degree]")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_03::~CExercise_03(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_03::On_Execute(void)
+{
+	bool	bResult;
+	int		Method;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	m_pInput	= Parameters("INPUT" )->asGrid();
+	m_pOutput	= Parameters("OUTPUT")->asGrid();
+
+	Method		= Parameters("METHOD")->asInt();
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	switch( Method )
+	{
+	case 0:
+		bResult	= Method_01();
+		break;
+
+	case 1:
+		bResult	= Method_02();
+		break;
+
+	case 2:
+		bResult	= Method_03();
+		break;
+
+	case 3:
+		bResult	= Method_04();
+		break;
+
+	default:
+		bResult	= false;
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_03::Method_01(void)
+{
+	int		x, y, ix;
+	double	a, b, c;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX()-1; x++)
+		{
+			ix	= x + 1;
+
+			if( m_pInput->is_NoData(x, y) || m_pInput->is_NoData(ix, y) )	// don't work with 'no data'...
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				a	= m_pInput->asDouble( x, y);
+				b	= m_pInput->asDouble(ix, y);
+
+				c	= a - b;
+
+				m_pOutput->Set_Value(x, y, c);
+			}
+		}
+
+		m_pOutput->Set_NoData(Get_NX() - 1, y);	// what shall we do with the last cell in a row ??!!
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_03::Method_02(void)
+{
+	int		x, y, ix;
+	double	a, b, c;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		x	= 0;	// initialize x...
+		
+		while( x < Get_NX() - 1 )	// condition for x...
+		{
+			ix	= x + 1;
+
+			if( m_pInput->is_NoData(x, y) || m_pInput->is_NoData(ix, y) )	// don't work with 'no data'...
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				a	= m_pInput->asDouble( x, y);
+				b	= m_pInput->asDouble(ix, y);
+
+				c	= a - b;
+
+				m_pOutput->Set_Value(x, y, c);
+			}
+
+			x++;	// increment x...
+		}
+
+		m_pOutput->Set_NoData(Get_NX() - 1, y);	// what shall we do with the last cell in a row ??!!
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_03::Method_03(void)
+{
+	int		x, y, ix;
+	double	a, b, c;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0, ix=1; x<Get_NX()-1; x++, ix++)
+		{
+			if( m_pInput->is_NoData(x, y) || m_pInput->is_NoData(ix, y) )	// don't work with 'no data'...
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				a	= m_pInput->asDouble( x, y);
+				b	= m_pInput->asDouble(ix, y);
+
+				c	= 100.0 * (a - b) / Get_Cellsize();
+
+				m_pOutput->Set_Value(x, y, c);
+			}
+		}
+
+		m_pOutput->Set_NoData(x, y);	// what shall we do with the last cell in a row ??!!
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_03::Method_04(void)
+{
+	int		x, y, ix;
+	double	a, b, c;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0, ix=1; x<Get_NX()-1; x++, ix++)
+		{
+			if( m_pInput->is_NoData(x, y) || m_pInput->is_NoData(ix, y) )	// don't work with 'no data'...
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				a	= m_pInput->asDouble( x, y);
+				b	= m_pInput->asDouble(ix, y);
+
+				c	= atan((a - b) / Get_Cellsize()) * 180.0 / M_PI;
+
+				m_pOutput->Set_Value(x, y, c);
+			}
+		}
+
+		m_pOutput->Set_NoData(x, y);	// what shall we do with the last cell in a row ??!!
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_03.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_03.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_03_H
+#define HEADER_INCLUDED__Exercise_03_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_03 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_03(void);							// constructor
+	virtual ~CExercise_03(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pInput, *m_pOutput;
+
+
+	bool				Method_01(void);
+	bool				Method_02(void);
+	bool				Method_03(void);
+	bool				Method_04(void);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_03_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,446 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_04.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_04.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_04::CExercise_04(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("04: Direct neighbours - more..."));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Simple neighbourhood analysis for grid cells.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"	, _TL("Input grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "OUTPUT"	, _TL("Output"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"	, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Arithmetic mean (version 1)"),
+			_TL("Arithmetic mean (version 2)"),
+			_TL("Difference from all neighbour's mean"),
+			_TL("Variance (version 1)"),
+			_TL("Variance (version 2)"),
+			_TL("Standard deviation")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_04::~CExercise_04(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_04::On_Execute(void)
+{
+	bool	bResult;
+	int		Method;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	m_pInput	= Parameters("INPUT" )->asGrid();
+	m_pOutput	= Parameters("OUTPUT")->asGrid();
+
+	Method		= Parameters("METHOD")->asInt();
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	switch( Method )
+	{
+	case 0:
+		bResult	= Method_01();
+		break;
+
+	case 1:
+		bResult	= Method_02();
+		break;
+
+	case 2:
+		bResult	= Method_03();
+		break;
+
+	case 3:
+		bResult	= Method_04();
+		break;
+
+	case 4:
+		bResult	= Method_05();
+		break;
+
+	case 5:
+		bResult	= Method_06();
+		break;
+
+	default:
+		bResult	= false;
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_04::Method_01(void)
+{
+	int		x, y, ix, iy, n;
+	double	s;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			s	= 0.0;
+			n	= 0;
+
+			for(iy=y-1; iy<=y+1; iy++)
+			{
+				for(ix=x-1; ix<=x+1; ix++)
+				{
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) )
+					{
+						s	+= m_pInput->asDouble(ix, iy);
+						n++;
+					}
+				}
+			}
+
+			if( n > 0 )
+			{
+				m_pOutput->Set_Value(x, y, s / n);
+			}
+			else
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_04::Method_02(void)
+{
+	int		x, y, i, ix, iy, n;
+	double	s;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pInput->is_NoData(x, y) )
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				s	= m_pInput->asDouble(x, y);
+				n	= 1;
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) )
+					{
+						s	+= m_pInput->asDouble(ix, iy);
+						n++;
+					}
+				}
+
+				m_pOutput->Set_Value(x, y, s / n);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_04::Method_03(void)
+{
+	int		x, y, i, ix, iy, n;
+	double	s;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pInput->is_NoData(x, y) )
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+			else
+			{
+				s	= 0.0;
+				n	= 0;
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) )
+					{
+						s	+= m_pInput->asDouble(ix, iy);
+						n++;
+					}
+				}
+
+				if( n > 0 )
+				{
+					m_pOutput->Set_Value(x, y, m_pInput->asDouble(x, y) - s / n);
+				}
+				else
+				{
+					m_pOutput->Set_NoData(x, y);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_04::Method_04(void)
+{
+	int		x, y, i, ix, iy, n;
+	double	m, v, z[9], dz;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0, ix=1; x<Get_NX(); x++, ix++)
+		{
+			for(n=0, iy=y-1; iy<=y+1; iy++)
+			{
+				for(ix=x-1; ix<=x+1; ix++)
+				{
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) )
+					{
+						z[n++]	= m_pInput->asDouble(ix, iy);
+					}
+				}
+			}
+
+			if( n > 0 )
+			{
+				for(m=0.0, i=0; i<n; i++)
+				{
+					m	+= z[i];
+				}
+
+				m	/= n;
+
+				for(v=0.0, i=0; i<n; i++)
+				{
+					dz	 = m - z[i];
+					v	+= dz * dz;
+				}
+
+				v	/= n;
+
+				m_pOutput->Set_Value(x, y, v);
+			}
+			else
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_04::Method_05(void)
+{
+	int		x, y, ix, iy, n;
+	double	m, v, z;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			n	= 0;
+			m	= 0.0;
+			v	= 0.0;
+
+			for(iy=y-1; iy<=y+1; iy++)
+			{
+				for(ix=x-1; ix<=x+1; ix++)
+				{
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) )
+					{
+						n++;
+
+						z	 = m_pInput->asDouble(ix, iy);
+
+						m	+= z;
+						v	+= z * z;
+					}
+				}
+			}
+
+			if( n > 0 )
+			{
+				m	= m / n;
+				v	= v / n - m * m;
+
+				m_pOutput->Set_Value(x, y, v);
+			}
+			else
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_04::Method_06(void)
+{
+	int		n;
+	double	v;
+
+	//-----------------------------------------------------
+	if( Method_05() == false )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( m_pOutput->is_NoData(n) == false )
+		{
+			v	= m_pOutput->asDouble(n);
+
+			m_pOutput->Set_Value(n, sqrt(v));
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_04.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,97 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_04.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_04_H
+#define HEADER_INCLUDED__Exercise_04_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_04 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_04(void);							// constructor
+	virtual ~CExercise_04(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pInput, *m_pOutput;
+
+
+	bool				Method_01(void);
+	bool				Method_02(void);
+	bool				Method_03(void);
+	bool				Method_04(void);
+	bool				Method_05(void);
+	bool				Method_06(void);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_04_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,373 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_05.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_05.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_05::CExercise_05(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("05: Direct neighbours - slope and aspect"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Simple neighbourhood analysis for grid cells.\n"
+		"- Zevenbergen, L.W. / Thorne, C.R. (1987):\n"
+		"    'Quantitative analysis of land surface topography',\n"
+		"    Earth Surface Processes and Landforms, 12: 47-56.\n\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "ELEVATION"	, _TL("Input grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "SLOPE"		, _TL("Slope"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "ASPECT"		, _TL("Aspect"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"		, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Steepest gradient (first version)"),
+			_TL("Steepest gradient (second version)"),
+			_TL("Zevenbergen & Thorne")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_05::~CExercise_05(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_05::On_Execute(void)
+{
+	bool	bResult;
+	int		Method;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	m_pDTM		= Parameters("ELEVATION")->asGrid();
+
+	m_pSlope	= Parameters("SLOPE"    )->asGrid();
+	m_pAspect	= Parameters("ASPECT"   )->asGrid();
+
+	Method		= Parameters("METHOD")->asInt();
+
+
+	m_pSlope	->Set_ZFactor(180.0 / M_PI);
+	m_pSlope	->Set_Unit(SG_T("Degree"));
+
+	m_pAspect	->Set_ZFactor(180.0 / M_PI);
+	m_pAspect	->Set_Unit(SG_T("Degree"));
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	switch( Method )
+	{
+	case 0:
+		bResult	= Method_01();
+		break;
+
+	case 1:
+		bResult	= Method_02();
+		break;
+
+	default:
+		bResult	= false;
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_05::Method_01(void)
+{
+	int		x, y, i, ix, iy, iMax;
+	double	z, dz, dzMax,
+			dx[2]	= { Get_Cellsize(), sqrt(2.0) * Get_Cellsize()	};
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDTM->is_NoData(x, y) )
+			{
+				m_pSlope	->Set_NoData(x, y);
+				m_pAspect	->Set_NoData(x, y);
+			}
+			else
+			{
+				z		= m_pDTM->asDouble(x, y);
+				iMax	= -1;
+
+				for(i=0; i<8; i++)
+				{
+					ix		= Get_xTo(i, x);
+					iy		= Get_yTo(i, y);
+
+					if( is_InGrid(ix, iy) && !m_pDTM->is_NoData(ix, iy) )
+					{
+						dz	= (z - m_pDTM->asDouble(ix, iy)) / dx[i % 2];
+
+						if( dz > 0.0 && (iMax < 0 || (iMax >= 0 && dzMax < dz)) )
+						{
+							iMax	= i;
+							dzMax	= dz;
+						}
+					}
+				}
+
+				if( iMax < 0 )
+				{
+					m_pSlope	->Set_NoData(x, y);
+					m_pAspect	->Set_NoData(x, y);
+				}
+				else
+				{
+					m_pSlope	->Set_Value(x, y, atan(dzMax));
+					m_pAspect	->Set_Value(x, y, M_PI_045 * iMax);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_05::Method_02(void)
+{
+	int		x, y, i, ix, iy, iMax;
+	double	z, dz, dzMax;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDTM->is_NoData(x, y) )
+			{
+				m_pSlope	->Set_NoData(x, y);
+				m_pAspect	->Set_NoData(x, y);
+			}
+			else
+			{
+				z		= m_pDTM->asDouble(x, y);
+				iMax	= -1;
+
+				for(i=0; i<8; i++)
+				{
+					ix		= Get_xTo(i, x);
+					iy		= Get_yTo(i, y);
+
+					if( is_InGrid(ix, iy) && !m_pDTM->is_NoData(ix, iy) )
+					{
+						dz	= (z - m_pDTM->asDouble(ix, iy)) / Get_Length(i);
+
+						if( dz > 0.0 && (iMax < 0 || (iMax >= 0 && dzMax < dz)) )
+						{
+							iMax	= i;
+							dzMax	= dz;
+						}
+					}
+				}
+
+				if( iMax < 0 )
+				{
+					m_pSlope	->Set_NoData(x, y);
+					m_pAspect	->Set_NoData(x, y);
+				}
+				else
+				{
+					m_pSlope	->Set_Value(x, y, atan(dzMax));
+					m_pAspect	->Set_Value(x, y, M_PI_045 * iMax);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_05::Method_03(void)
+{
+	static int	x_To[]	= { 0, 1, 0, -1 },
+				y_To[]	= { 1, 0, -1, 0 };
+
+	int		x, y, i, ix, iy;
+	double	z, dz[4], G, H, dx2;
+
+	//-----------------------------------------------------
+	dx2		= 2.0 * Get_Cellsize();
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDTM->is_NoData(x, y) )
+			{
+				m_pSlope	->Set_NoData(x, y);
+				m_pAspect	->Set_NoData(x, y);
+			}
+
+			//---------------------------------------------
+			else
+			{
+				z		= m_pDTM->asDouble(x, y);
+
+				for(i=0; i<4; i++)
+				{
+					ix		= x + x_To[i];
+					iy		= y + y_To[i];
+
+					if( m_pDTM->is_NoData(ix, iy) )
+					{
+						dz[i]	= 0.0;
+					}
+					else
+					{
+						dz[i]	= m_pDTM->asDouble(ix, iy) - z;
+					}
+				}
+
+				//-----------------------------------------
+				G		= (dz[0] - dz[2]) / dx2;
+				H		= (dz[1] - dz[3]) / dx2;
+
+				m_pSlope		->Set_Value(x, y, atan(sqrt(G*G + H*H)));
+
+				if( G != 0.0 )
+				{
+					m_pAspect	->Set_Value(x, y, M_PI_180 + atan2(H, G));
+				}
+				else if( H > 0.0 )
+				{
+					m_pAspect	->Set_Value(x, y, M_PI_270);
+				}
+				else if( H < 0.0 )
+				{
+					m_pAspect	->Set_Value(x, y, M_PI_090);
+				}
+				else
+				{
+					m_pAspect	->Set_NoData(x, y);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_05.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,94 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_05.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_05_H
+#define HEADER_INCLUDED__Exercise_05_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_05 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_05(void);							// constructor
+	virtual ~CExercise_05(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pDTM, *m_pSlope, *m_pAspect;
+
+
+	bool				Method_01(void);
+	bool				Method_02(void);
+	bool				Method_03(void);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_05_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,323 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_06.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_06.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_06::CExercise_06(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("06: Extended neighbourhoods"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Extended neigbourhoods for grids.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "INPUT"		, _TL("Input grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "OUTPUT"		, _TL("Output grid"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "RADIUS"		, _TL("Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"		, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Quadratic"),
+			_TL("Circle"),
+			_TL("Distance Weighted (inverse distance)")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_06::~CExercise_06(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_06::On_Execute(void)
+{
+	int		Radius;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	m_pInput	= Parameters("INPUT" )->asGrid();
+	m_pOutput	= Parameters("OUTPUT")->asGrid();
+
+	Radius		= Parameters("RADIUS")->asInt();
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:
+		return( Method_01(Radius) );
+
+	case 1:
+		return( Method_02(Radius) );
+
+	case 2:
+		return( Method_03(Radius) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_06::Method_01(int Radius)
+{
+	int		x, y, ix, iy, n;
+	double	s;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			n	= 0;
+			s	= 0.0;
+
+			for(iy=y-Radius; iy<=y+Radius; iy++)
+			{
+				for(ix=x-Radius; ix<=x+Radius; ix++)
+				{
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) )
+					{
+						n++;
+						s	+= m_pInput->asDouble(ix, iy);
+					}
+				}
+			}
+
+			if( n > 0 )
+			{
+				m_pOutput->Set_Value(x, y, s / n);
+			}
+			else
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_06::Method_02(int Radius)
+{
+	int		x, y, ix, iy, xMask, yMask, nMask, n;
+	double	s, Distance;
+	CSG_Grid	gMask;
+
+	//-----------------------------------------------------
+	nMask	= 1 + 2 * Radius;
+
+	gMask.Create(SG_DATATYPE_Byte, nMask, nMask);
+
+	for(iy=-Radius, yMask=0; yMask<nMask; iy++, yMask++)
+	{
+		for(ix=-Radius, xMask=0; xMask<nMask; ix++, xMask++)
+		{
+			Distance	= sqrt((double)(ix*ix + iy*iy));
+
+			gMask.Set_Value(xMask, yMask, Distance <= Radius ? true : false);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			n	= 0;
+			s	= 0.0;
+
+			for(iy=y-Radius, yMask=0; yMask<nMask; iy++, yMask++)
+			{
+				for(ix=x-Radius, xMask=0; xMask<nMask; ix++, xMask++)
+				{
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) && gMask.asByte(xMask, yMask) )
+					{
+						n++;
+						s	+= m_pInput->asDouble(ix, iy);
+					}
+				}
+			}
+
+			if( n > 0 )
+			{
+				m_pOutput->Set_Value(x, y, s / n);
+			}
+			else
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_06::Method_03(int Radius)
+{
+	int		x, y, ix, iy, xMask, yMask, nMask;
+	double	s, n, Distance, Weight;
+	CSG_Grid	gMask;
+
+	//-----------------------------------------------------
+	nMask	= 1 + 2 * Radius;
+
+	gMask.Create(SG_DATATYPE_Double, nMask, nMask);
+
+	for(iy=-Radius, yMask=0; yMask<nMask; iy++, yMask++)
+	{
+		for(ix=-Radius, xMask=0; xMask<nMask; ix++, xMask++)
+		{
+			Distance	= sqrt((double)(ix*ix + iy*iy));
+
+			gMask.Set_Value(xMask, yMask, Distance > 0.0 && Distance <= Radius ? 1.0 / Distance : 0.0);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			n	= 0;
+			s	= 0.0;
+
+			for(iy=y-Radius, yMask=0; yMask<nMask; iy++, yMask++)
+			{
+				for(ix=x-Radius, xMask=0; xMask<nMask; ix++, xMask++)
+				{
+					if( is_InGrid(ix, iy) && !m_pInput->is_NoData(ix, iy) && (Weight = gMask.asDouble(xMask, yMask)) > 0.0 )
+					{
+						n	+= Weight;
+						s	+= Weight * m_pInput->asDouble(ix, iy);
+					}
+				}
+			}
+
+			if( n > 0 )
+			{
+				m_pOutput->Set_Value(x, y, s / n);
+			}
+			else
+			{
+				m_pOutput->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_06.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,94 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_06.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_06_H
+#define HEADER_INCLUDED__Exercise_06_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_06 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_06(void);							// constructor
+	virtual ~CExercise_06(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pInput, *m_pOutput;
+
+
+	bool				Method_01(int Radius);
+	bool				Method_02(int Radius);
+	bool				Method_03(int Radius);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_06_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,322 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_07.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_07.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_07::CExercise_07(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("07: Extended neighbourhoods - catchment areas (trace flow)"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Extended Neighbourhoods - Catchment areas.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "AREA"		, _TL("Catchment area"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "LENGTH"		, _TL("Flow Path Length"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "STEP"		, _TL("Step"),
+		_TL("Skip cells (step value)."),
+		PARAMETER_TYPE_Int	, 1, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Needs less memory, but is slow"),
+			_TL("Needs more memory, but is quicker")
+		)
+	);
+
+	pNode	= Parameters.Add_Value(
+		NULL	, "ONECELL"		, _TL("Single Cell"),
+		_TL("Set \'false\' to execute the calculation for each point in grid. Set \'true\' tu calculate the flow of one single cell."),
+		PARAMETER_TYPE_Bool	, false
+	);
+
+	Parameters.Add_Value(
+		pNode	, "XCELL"	, _TL("X Position"),
+		_TL(""),
+		PARAMETER_TYPE_Int
+	);
+
+	Parameters.Add_Value(
+		pNode	, "YCELL"	, _TL("Y Position"),
+		_TL(""),
+		PARAMETER_TYPE_Int
+	);
+}
+
+//---------------------------------------------------------
+CExercise_07::~CExercise_07(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_07::On_Execute(void)
+{
+	bool		bCell;
+	int			x, y, Step, xCell, yCell;
+	CSG_Grid	*pLength;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	m_pDTM			= Parameters("ELEVATION")->asGrid();
+	m_pArea			= Parameters("AREA"     )->asGrid();
+	pLength			= Parameters("LENGTH"   )->asGrid();
+
+	Step			= Parameters("STEP"     )->asInt();
+
+	m_Method		= Parameters("METHOD"   )->asInt();
+
+	bCell			= Parameters("ONECELL"  )->asBool();
+	xCell			= Parameters("XCELL"    )->asInt();
+	yCell			= Parameters("YCELL"    )->asInt();
+
+
+	//-----------------------------------------------------
+	// General initialisations...
+
+	m_pArea			->Assign(0.0);
+	m_pArea			->Set_Unit(SG_T("m\xc2\xb2"));
+	DataObject_Set_Colors(m_pArea, 100, SG_COLORS_WHITE_BLUE);
+
+	pLength			->Assign(0.0);
+	pLength			->Set_Unit(SG_T("m"));
+
+	m_Area_of_Cell	= Get_Cellsize() * Get_Cellsize();
+
+
+	//-----------------------------------------------------
+	// Special initialisations...
+
+	switch( m_Method )
+	{
+	case 0: default:	// Needs less memory, but is slow...
+		m_pDir	= NULL;
+		break;
+
+	case 1:				// Needs more memory, but is quicker...
+		m_pDir	= new CSG_Grid(m_pDTM, SG_DATATYPE_Char);
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y+=Step)
+		{
+			for(x=0; x<Get_NX(); x+=Step)
+			{
+				m_pDir->Set_Value(x, y, Get_FlowDirection(x, y));
+			}
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	if( bCell )
+	{
+		pLength->Set_Value(xCell, yCell, Trace_Flow(xCell, yCell));
+	}
+	else
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y+=Step)
+		{
+			for(x=0; x<Get_NX(); x+=Step)
+			{
+				pLength->Set_Value(x, y, Trace_Flow(x, y));
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Special finalisations...
+
+	if( m_pDir != NULL )
+	{
+		delete(m_pDir);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CExercise_07::Get_FlowDirection(int x, int y)
+{
+	int		i, ix, iy, iMax;
+	double	z, dz, dzMax;
+
+	iMax	= -1;
+
+	if( is_InGrid(x, y) && !m_pDTM->is_NoData(x, y) )
+	{
+		z		= m_pDTM->asDouble(x, y);
+		dzMax	= 0.0;
+
+		for(i=0; i<8; i++)
+		{
+			ix		= Get_xTo(i, x);
+			iy		= Get_yTo(i, y);
+
+			if( is_InGrid(ix, iy) && !m_pDTM->is_NoData(ix, iy) )
+			{
+				dz		= (z - m_pDTM->asDouble(ix, iy)) / Get_Length(i);
+
+				if( dz > dzMax )
+				{
+					dzMax	= dz;
+					iMax	= i;
+				}
+			}
+		}
+	}
+
+	return( iMax );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CExercise_07::Trace_Flow(int x, int y)
+{
+	int		Direction;
+	double	Length;
+
+	Length	= 0.0;
+
+	if( is_InGrid(x, y) && !m_pDTM->is_NoData(x, y) )
+	{
+		do
+		{
+			m_pArea->Add_Value(x, y, m_Area_of_Cell);
+
+			Direction	= m_pDir != NULL
+						? m_pDir->asInt(x, y)
+						: Get_FlowDirection(x, y);
+
+			if( Direction >= 0 )
+			{
+				x		= Get_xTo(Direction, x);
+				y		= Get_yTo(Direction, y);
+
+				Length	+= Get_Length(Direction);
+			}
+		}
+		while( Direction >= 0 );
+	}
+
+	return( Length );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_07.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,98 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_07.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//														 //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_07_H
+#define HEADER_INCLUDED__Exercise_07_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_07 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_07(void);							// constructor
+	virtual ~CExercise_07(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	int					m_Method;
+
+	double				m_Area_of_Cell;
+
+	CSG_Grid				*m_pDTM, *m_pArea, *m_pDir;
+
+
+	int					Get_FlowDirection(int x, int y);
+
+	double				Trace_Flow(int x, int y);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_07_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,290 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_08.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_08.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_08::CExercise_08(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("08: Extended neighbourhoods - catchment areas (parallel)"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Extended Neighbourhoods - Catchment areas.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "ELEVATION"	, _TL("Elevation grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "AREA"		, _TL("Catchment area"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"		, _TL("Method"),
+		_TL("Choose a method"),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("D8"),
+			_TL("MFD")
+		)
+	);
+}
+
+//---------------------------------------------------------
+CExercise_08::~CExercise_08(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_08::On_Execute(void)
+{
+	bool	bResult;
+	int		Method;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	m_pDTM		= Parameters("ELEVATION")->asGrid();
+
+	m_pArea		= Parameters("AREA"     )->asGrid();
+
+	Method		= Parameters("METHOD")->asInt();
+
+
+	m_pArea		->Assign(0.0);
+	m_pArea		->Set_Unit(SG_T("m\xc2\xb2"));
+	DataObject_Set_Colors(m_pArea, 100, SG_COLORS_WHITE_BLUE);
+
+
+	//-----------------------------------------------------
+	// Execute calculation...
+
+	switch( Method )
+	{
+	case 0:
+		bResult	= Method_01();
+		break;
+
+	case 1:
+		bResult	= Method_02();
+		break;
+
+	default:
+		bResult	= false;
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_08::Method_01(void)
+{
+	int		n, x, y, i, ix, iy, iMax;
+	double	z, dz, dzMax,
+			Area_of_Cell	= Get_Cellsize() * Get_Cellsize();
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		m_pDTM->Get_Sorted(n, x, y, true, false);
+
+		if( m_pDTM->is_NoData(x, y) )
+		{
+			m_pArea->Set_NoData(x, y);
+		}
+		else
+		{
+			m_pArea->Add_Value(x, y, Area_of_Cell);
+
+			z		= m_pDTM->asDouble(x, y);
+			iMax	= -1;
+
+			for(i=0; i<8; i++)
+			{
+				ix		= Get_xTo(i, x);
+				iy		= Get_yTo(i, y);
+
+				if( is_InGrid(ix, iy) && !m_pDTM->is_NoData(ix, iy) )
+				{
+					dz	= (z - m_pDTM->asDouble(ix, iy)) / Get_Length(i);
+
+					if( dz > 0.0 && (iMax < 0 || (iMax >= 0 && dzMax < dz)) )
+					{
+						iMax	= i;
+						dzMax	= dz;
+					}
+				}
+			}
+
+			if( iMax >= 0 )
+			{
+				ix		= Get_xTo(iMax, x);
+				iy		= Get_yTo(iMax, y);
+
+				m_pArea->Add_Value(ix, iy, m_pArea->asDouble(x, y));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_08::Method_02(void)
+{
+	int		n, x, y, i, ix, iy;
+	double	z, d, dz[8], dzSum,
+			Area_of_Cell	= Get_Cellsize() * Get_Cellsize(),
+			MFD_Converge	= 1.1;
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		m_pDTM->Get_Sorted(n, x, y, true, false);
+
+		if( m_pDTM->is_NoData(x, y) )
+		{
+			m_pArea->Set_NoData(x, y);
+		}
+		else
+		{
+			m_pArea->Add_Value(x, y, Area_of_Cell);
+
+			z		= m_pDTM->asDouble(x, y);
+			dzSum	= 0.0;
+
+			for(i=0; i<8; i++)
+			{
+				ix		= Get_xTo(i, x);
+				iy		= Get_yTo(i, y);
+
+				if( is_InGrid(ix, iy) && !m_pDTM->is_NoData(ix, iy) && (d = z - m_pDTM->asDouble(ix, iy)) > 0.0 )
+				{
+					dz[i]	= pow(d / Get_Length(i), MFD_Converge);
+					dzSum	+= dz[i];
+				}
+				else
+				{
+					dz[i]	= 0.0;
+				}
+			}
+
+			if( dzSum > 0.0 )
+			{
+				d		= m_pArea->asDouble(x, y) / dzSum;
+
+				for(i=0; i<8; i++)
+				{
+					if( dz[i] > 0.0 )
+					{
+						ix		= Get_xTo(i, x);
+						iy		= Get_yTo(i, y);
+
+						m_pArea->Add_Value(ix, iy, dz[i] * d);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_08.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_08.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//														 //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_08_H
+#define HEADER_INCLUDED__Exercise_08_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_08 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_08(void);							// constructor
+	virtual ~CExercise_08(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pDTM, *m_pArea;
+
+
+	bool				Method_01(void);
+	bool				Method_02(void);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_08_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,211 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_09.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_09.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_09::CExercise_09(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("09: Extended neighbourhoods - catchment areas (recursive)"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Extended Neighbourhoods - Use recursive function calls for catchment area calculations.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL, "ELEVATION"	, _TL("Elevation grid"),
+		_TL("This must be your input data of type grid."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "AREA"		, _TL("Catchment area"),
+		_TL("This will contain your output data of type grid."),
+		PARAMETER_OUTPUT
+	);
+}
+
+//---------------------------------------------------------
+CExercise_09::~CExercise_09(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_09::On_Execute(void)
+{
+	int			x, y;
+	CSG_Grid	*pDTM;
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	pDTM		= Parameters("ELEVATION")->asGrid();
+	m_pArea		= Parameters("AREA"     )->asGrid();
+
+
+	//-----------------------------------------------------
+	// Initialisations...
+
+	m_pArea		->Assign(0.0);
+	m_pArea		->Set_Unit(SG_T("m\xc2\xb2"));
+	DataObject_Set_Colors(m_pArea, 100, SG_COLORS_WHITE_BLUE);
+
+
+	//-----------------------------------------------------
+	// Save flow directions to temporary grid...
+
+	m_pDir		= new CSG_Grid(pDTM, SG_DATATYPE_Char);	// this object has to be deleted later...
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			m_pDir->Set_Value(x, y, pDTM->Get_Gradient_NeighborDir(x, y) % 8);
+		}
+	}
+
+
+	//-------------------------------------------------
+	// Execute calculation...
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Get_Area(x, y);
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Finalisations...
+
+	delete(m_pDir);
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CExercise_09::Get_Area(int x, int y)
+{
+	int		i, ix, iy;
+	double	area;
+
+	//-----------------------------------------------------
+	area	= m_pArea->asDouble(x, y);
+
+	if( area <= 0.0 )												// cell has not been processed yet...
+	{
+		m_pArea->Set_Value(x, y, 1.0);								// Very important: mark this cell as processed to prevent endless loops...
+
+		area	= Get_Cellsize() * Get_Cellsize();								// initialize the cell's area with its own cell size...
+
+		for(i=0; i<8; i++)
+		{
+			ix	= Get_xFrom(i, x);
+			iy	= Get_yFrom(i, y);
+
+			if( is_InGrid(ix, iy) && i == m_pDir->asInt(ix, iy) )	// drains ith neigbour into this cell ???...
+			{
+				area	+= Get_Area(ix, iy);						// ...then add its area (recursive call of this function!)...
+			}
+		}
+
+		m_pArea->Set_Value(x, y, area);
+	}
+
+	//-----------------------------------------------------
+	return( area );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_09.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,92 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_09.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//														 //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_09_H
+#define HEADER_INCLUDED__Exercise_09_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_09 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_09(void);							// constructor
+	virtual ~CExercise_09(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pArea, *m_pDir;
+
+
+	double				Get_Area(int x, int y);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_09_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,260 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_10.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_10.h"
+#include <time.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_10::CExercise_10(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name	(_TL("10: Dynamic Simulation - Life"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Conway's game of life. A cellular automate.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"		, _TL("Life"),
+		_TL(""),
+		PARAMETER_OUTPUT, true, SG_DATATYPE_Byte
+	);
+
+	Parameters.Add_Value(
+		NULL, "REFRESH"		, _TL("Refresh"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "COLORS"		, _TL("Fade Color Count"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 64, 3, true, 255, true
+	);
+}
+
+//---------------------------------------------------------
+CExercise_10::~CExercise_10(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//	Run													 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_10::On_Execute(void)
+{
+	bool	bAlive;
+	int		x, y, i;
+	CSG_Colors	Colors;
+
+
+	//-----------------------------------------------------
+	// General initialisations...
+
+	m_pLife		= Parameters("RESULT")->asGrid();
+
+	m_nColors	= Parameters("COLORS")->asInt();
+
+	Colors.Set_Count(m_nColors + 1);
+	Colors.Set_Ramp(SG_GET_RGB(127, 127, 127), SG_GET_RGB(0, 0, 0));
+	Colors.Set_Color(0, SG_GET_RGB(255, 255, 255));
+	DataObject_Set_Colors(m_pLife, Colors);
+
+
+	//-----------------------------------------------------
+	// Initialise life's world...
+
+	if( Parameters("REFRESH")->asBool() )
+	{
+		srand((unsigned)time(NULL));
+
+		for(y=0; y<Get_NY(); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				m_pLife->Set_Value(x, y, rand() > RAND_MAX / 2 ? 0 : 1);
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Execution...
+
+	m_pTemp		= SG_Create_Grid(m_pLife, SG_DATATYPE_Byte);
+
+	for(i=1, bAlive=true; bAlive && Process_Get_Okay(true); i++)
+	{
+		Process_Set_Text(CSG_String::Format(SG_T("%d %s"), i, _TL("Life Cycle")));
+
+		if( (bAlive = Next_Step()) == false )
+		{
+			Message_Add(CSG_String::Format(SG_T("%s %d %s\n"), _TL("Dead after"), i, _TL("Life Cycles")));
+		}
+	}
+
+	delete(m_pTemp);
+
+
+	//-----------------------------------------------------
+	// Finish...
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_10::Next_Step(void)
+{
+	bool	bAlive;
+	int		x, y, i, ix, iy, n;
+
+	bAlive	= false;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			//---------------------------------------------
+			// Count neighours...
+
+			for(i=0, n=0; i<8; i++)
+			{
+				ix	= Get_xTo(i, x);
+				if( ix < 0 )
+					ix	= Get_NX() - 1;
+				else if( ix >= Get_NX() )
+					ix	= 0;
+
+				iy	= Get_yTo(i, y);
+				if( iy < 0 )
+					iy	= Get_NY() - 1;
+				else if( iy >= Get_NY() )
+					iy	= 0;
+
+				if( m_pLife->asByte(ix, iy) == 0 )
+				{
+					n++;
+				}
+			}
+
+
+			//---------------------------------------------
+			// Dead or alive...
+
+			i	= m_pLife->asByte(x, y);
+
+			switch( n )
+			{
+			case 2:		// keep status...
+				if( i > 0 && i < m_nColors )	// color fading...
+				{
+					i++;
+				}
+				break;
+
+			case 3:		// Birth...
+				i	= 0;
+				break;
+
+			default:	// Dead...
+				if( i < m_nColors )				// color fading...
+				{
+					i++;
+				}
+			}
+
+			if( i > 1 && i < m_nColors )
+			{
+				bAlive	= true;
+			}
+
+			m_pTemp->Set_Value(x, y, i);
+		}
+	}
+
+	//-----------------------------------------------------
+	m_pLife->Assign(m_pTemp);
+
+	DataObject_Update(m_pLife, 0, m_nColors, true);
+
+	return( bAlive );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_10.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,98 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_10.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_10_H
+#define HEADER_INCLUDED__Exercise_10_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CExercise_10 : public CSG_Module_Grid
+{
+public:
+	CExercise_10(void);
+	virtual ~CExercise_10(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	int						m_nColors;
+
+	CSG_Grid					*m_pLife, *m_pTemp;
+
+
+	bool					Next_Step(void);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Exercise_10_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,328 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_11.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_11.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_11::CExercise_11(void)
+{
+	Set_Name	(_TL("11: Dynamic Simulation - Soil Nitrogen Dynamics"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Spatially Distributed Simulation of Soil Nitrogen Dynamics. "
+
+		"\nReference:"
+		"\nHugget, R.J. (1993): 'Modelling the Human Impact on Nature', Oxford University Press.\n"
+
+		"\n(c) 2003 by Olaf Conrad, Goettingen\nemail: oconrad at gwdg.de")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "NSTORE"		, _TL("Soil Nitrogen"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "TIME_SPAN"	, _TL("Time Span [a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_STEP"	, _TL("Time Interval [a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "UPDATE"		, _TL("Update View"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "NINIT"		, _TL("Initial Nitrogen Content [kg/ha]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 5000.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NRAIN"		, _TL("Nitrogen in Rainfall [kg/ha/a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 16.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CExercise_11::~CExercise_11(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_11::On_Execute(void)
+{
+	bool		bUpdate;
+	int			iStep, nSteps;
+	double		sTime, dTime, N_Init, N_Rain;
+	CSG_Grid	*pDEM;
+
+	//-----------------------------------------------------
+	sTime	= Parameters("TIME_SPAN")	->asDouble();
+	dTime	= Parameters("TIME_STEP")	->asDouble();
+	nSteps	= (int)(sTime / dTime);
+
+	bUpdate	= Parameters("UPDATE")		->asBool();
+
+	N_Init	= Parameters("NINIT")		->asDouble();
+	N_Rain	= Parameters("NRAIN")		->asDouble();
+
+	pDEM	= Parameters("DEM")			->asGrid();
+
+	m_pN	= Parameters("NSTORE")		->asGrid();
+	m_pN->Assign(N_Init);
+	DataObject_Set_Colors(m_pN, 100, SG_COLORS_YELLOW_GREEN);
+
+	Initialize(pDEM);
+
+	//-----------------------------------------------------
+	for(iStep=0; iStep<=nSteps && Set_Progress(iStep, nSteps); iStep++)
+	{
+		Process_Set_Text(CSG_String::Format(SG_T("Time [a]: %f (%f)"), dTime * iStep, sTime));
+
+		if( bUpdate )
+		{
+			DataObject_Update(m_pN, m_pN->Get_ZMin(), m_pN->Get_ZMax(), true);
+		}
+
+		Next_Step(N_Rain, dTime);
+	}
+
+	//-----------------------------------------------------
+	Finalize();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_11::Initialize(CSG_Grid *pDEM)
+{
+	int		x, y, i, ix, iy;
+	double	z, dz, dzSum;
+
+	//-----------------------------------------------------
+	m_Next	.Create(pDEM, SG_DATATYPE_Float);
+	m_dzSum	.Create(pDEM, SG_DATATYPE_Float);
+
+	for(i=0; i<8; i++)
+	{
+		m_dz[i].Create(pDEM, SG_DATATYPE_Float);
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			dzSum	= 0.0;
+
+			if( !pDEM->is_NoData(x, y) )
+			{
+				z		= pDEM->asDouble(x, y);
+
+				for(i=0; i<8; i++)
+				{
+					ix		= Get_xTo(i, x);
+					iy		= Get_yTo(i, y);
+
+					if( pDEM->is_InGrid(ix, iy) && (dz = (z - pDEM->asDouble(ix, iy)) / Get_Length(i)) > 0.0 )
+					{
+						m_dz[i].Set_Value(x, y, dz);
+
+						dzSum	+= dz;
+					}
+					else
+					{
+						m_dz[i].Set_Value(x, y, 0.0);
+					}
+				}
+
+				if( dzSum > 0.0 )
+				{
+					for(i=0; i<8; i++)
+					{
+						m_dz[i].Mul_Value(x, y, 1.0 / dzSum);
+					}
+				}
+			}
+
+			m_dzSum.Set_Value(x, y, dzSum);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CExercise_11::Finalize(void)
+{
+	int		i;
+
+	m_Next	.Destroy();
+	m_dzSum	.Destroy();
+
+	for(i=0; i<8; i++)
+	{
+		m_dz[i].Destroy();
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_11::Next_Step(double N_Rain, double dTime)
+{
+	int		x, y, i;
+	double	dz, dzSum, N, dN;
+
+	m_Next.Assign(0.0);
+
+	N_Rain	*= dTime;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Process_Get_Okay(false); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			N		= m_pN->asDouble(x, y);
+
+			if( (dzSum = m_dzSum.asDouble(x, y)) > 0.0 )
+			{
+				dN		= N * dzSum * dTime;
+
+				if( dN > N )
+				{
+					dN		= N;
+				}
+
+				for(i=0; i<8; i++)
+				{
+					if( (dz = m_dz[i].asDouble(x, y)) > 0.0 )
+					{
+						m_Next.Add_Value(Get_xTo(i, x), Get_yTo(i, y), dz * dN);
+					}
+				}
+			}
+			else
+			{
+				dN		= 0.0;
+			}
+
+			m_Next.Add_Value(x, y, N - dN + N_Rain);
+		}
+	}
+
+	if( is_Progress() )
+	{
+		m_pN->Assign(&m_Next);
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_11.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,91 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_11.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_11_H
+#define HEADER_INCLUDED__Exercise_11_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_11 : public CSG_Module_Grid
+{
+public:
+	CExercise_11(void);
+	virtual ~CExercise_11(void);
+
+
+protected:
+
+	virtual bool				On_Execute(void);
+
+
+private:
+
+	CSG_Grid						*m_pN, m_Next, m_dz[8], m_dzSum;
+
+	bool						Initialize(CSG_Grid *pDEM);
+	bool						Finalize(void);
+
+	bool						Next_Step(double N_Rain, double dTime);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Exercise_11_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,177 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Lectures_Shapes                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_12.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_12.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_12::CExercise_12(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("12: First steps with shapes"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Copy a shapes layer and move it to a new position.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Shapes(
+		NULL	, "INPUT"	, _TL("Input"),
+		_TL("This must be your input data of type shapes."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "OUTPUT"	, _TL("Output"),
+		_TL("This will contain your output data of type shapes."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DX"		, _TL("Translation: X"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		10.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DY"		, _TL("Translation: Y"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		10.0
+	);
+}
+
+//---------------------------------------------------------
+CExercise_12::~CExercise_12(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_12::On_Execute(void)
+{
+	int			iShape, iPart, iPoint;
+	double		dx, dy;
+	TSG_Point	Point;
+	CSG_Shapes	*pShapes_A, *pShapes_B;
+	CSG_Shape	*pShape_A, *pShape_B;
+
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	pShapes_A	= Parameters("INPUT")	->asShapes();
+	pShapes_B	= Parameters("OUTPUT")	->asShapes();
+
+	dx			= Parameters("DX")		->asDouble();
+	dy			= Parameters("DY")		->asDouble();
+
+	pShapes_B->Create(pShapes_A->Get_Type(), _TL("Translation"), pShapes_A);
+
+
+	//-----------------------------------------------------
+	// Copy shapes layer A to B and translate each point's position...
+
+	for(iShape=0; iShape<pShapes_A->Get_Count() && Set_Progress(iShape, pShapes_A->Get_Count()); iShape++)
+	{
+		pShape_A	= pShapes_A->Get_Shape(iShape);
+		pShape_B	= pShapes_B->Add_Shape(pShape_A, SHAPE_COPY_ATTR);
+
+		for(iPart=0; iPart<pShape_A->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<pShape_A->Get_Point_Count(iPart); iPoint++)
+			{
+				Point	= pShape_A->Get_Point(iPoint, iPart);
+
+				Point.x	+= dx;	// perform the translation before
+				Point.y	+= dy;	// you add the point to the new shape...
+
+				pShape_B->Add_Point(Point, iPart);
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_12.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,88 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Lectures_Shapes                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_12.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_12_H
+#define HEADER_INCLUDED__Exercise_12_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_12 : public CSG_Module
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_12(void);							// constructor
+	virtual ~CExercise_12(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_12_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,380 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Lectures_Shapes                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_13.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_13.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_13::CExercise_13(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("13: Reprojecting a shapes layer"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Copy a shapes layer and move it to a new position.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Shapes input and output...
+
+	Parameters.Add_Shapes(
+		NULL	, "INPUT"	, _TL("Input"),
+		_TL("This must be your input data of type shapes."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "OUTPUT"	, _TL("Output"),
+		_TL("This will contain your output data of type shapes."),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Transformation parameters...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Translation"),
+			_TL("Scaling"),
+			_TL("Shearing"),
+			_TL("Rotation"),
+			_TL("Combination A"),
+			_TL("Combination B")
+		)
+	);
+
+	//-----------------------------------------------------
+	// Transformation parameters...
+
+	pNode	= Parameters.Add_Node(NULL, "NODE_TRANS", _TL("Translation"), _TL(""));
+	Parameters.Add_Value(
+		pNode	, "TRANS_X"	, SG_T("X"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		10.0
+	);
+	Parameters.Add_Value(
+		pNode	, "TRANS_Y"	, SG_T("Y"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		10.0
+	);
+
+	pNode	= Parameters.Add_Node(NULL, "NODE_SCALE", _TL("Scale factors")	, _TL(""));
+	Parameters.Add_Value(
+		pNode	, "SCALE_X"	, SG_T("X"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		10.0
+	);
+	Parameters.Add_Value(
+		pNode	, "SCALE_Y"	, SG_T("Y"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		10.0
+	);
+
+	pNode	= Parameters.Add_Node(NULL, "NODE_SHEAR", _TL("Shear factors")	, _TL(""));
+	Parameters.Add_Value(
+		pNode	, "SHEAR_X"	, SG_T("X"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		0.5
+	);
+	Parameters.Add_Value(
+		pNode	, "SHEAR_Y"	, SG_T("Y"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		0.5
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ROTAT"	, _TL("Rotation angle [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double,
+		45.0
+	);
+}
+
+//---------------------------------------------------------
+CExercise_13::~CExercise_13(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SET_MATRIX(M, a1, a2, a3, b1, b2, b3, c1, c2, c3)	M[0][0]=a1; M[1][0]=b1; M[2][0]=c1;\
+															M[0][1]=a2; M[1][1]=b2; M[2][1]=c2;\
+															M[0][2]=a3; M[1][2]=b3; M[2][2]=c3;
+
+//---------------------------------------------------------
+bool CExercise_13::On_Execute(void)
+{
+	int			Method;
+	double		trn_x, trn_y, scl_x, scl_y, shr_x, shr_y, rot,
+				m_trn[3][3], m_scl[3][3], m_shr[3][3], m_rot[3][3], m[3][3];
+	CSG_Shapes		*pShapes_A, *pShapes_B;
+
+
+	//-----------------------------------------------------
+	// Get parameter settings...
+
+	pShapes_A	= Parameters("INPUT")	->asShapes();
+	pShapes_B	= Parameters("OUTPUT")	->asShapes();
+
+	pShapes_B->Create(pShapes_A->Get_Type(), _TL("Transformation"), pShapes_A);
+
+	Method		= Parameters("METHOD")	->asInt();
+
+	trn_x		= Parameters("TRANS_X")	->asDouble();
+	trn_y		= Parameters("TRANS_Y")	->asDouble();
+
+	scl_x		= Parameters("SCALE_X")	->asDouble();
+	scl_y		= Parameters("SCALE_Y")	->asDouble();
+
+	shr_x		= Parameters("SHEAR_X")	->asDouble();
+	shr_y		= Parameters("SHEAR_Y")	->asDouble();
+
+	rot			= Parameters("ROTAT")	->asDouble() * M_DEG_TO_RAD;
+
+
+	//-----------------------------------------------------
+	// Initialise transformation matrices...
+
+	// Translation...
+	SET_MATRIX(m_trn,
+		1.0			, 0.0		, trn_x	,
+		0.0			, 1.0		, trn_y	,
+		0.0			, 0.0		, 1.0	);
+
+	// Scaling...
+	SET_MATRIX(m_scl,
+		scl_x		, 0.0		, 0.0	,
+		0.0			, scl_y		, 0.0	,
+		0.0			, 0.0		, 1.0	);
+
+	// Shearing...
+	SET_MATRIX(m_shr,
+		1.0			, shr_x		, 0.0	,
+		shr_y		, 1.0		, 0.0	,
+		0.0			, 0.0		, 1.0	);
+
+	// Rotation...
+	SET_MATRIX(m_rot,
+		 cos(rot)	, sin(rot)	, 0.0	,
+		-sin(rot)	, cos(rot)	, 0.0	,
+		 0.0		, 0.0		, 1.0	);
+
+	// Initialise m as matrix, that does nothing...
+	SET_MATRIX(m,
+		1.0			, 0.0		, 0.0	,
+		0.0			, 1.0		, 0.0	,
+		0.0			, 0.0		, 1.0	);
+
+
+	//-----------------------------------------------------
+	// Set final transformation matrix m...
+
+	switch( Method )
+	{
+	case 0:	// Translation...
+		Multiply_Matrices(m, m_trn);
+		break;
+
+	case 1:	// Scaling...
+		Multiply_Matrices(m, m_scl);
+		break;
+
+	case 2:	// Shearing...
+		Multiply_Matrices(m, m_shr);
+		break;
+
+	case 3:	// Rotation...
+		Multiply_Matrices(m, m_rot);
+		break;
+
+	case 4:	// Combination A...
+		Multiply_Matrices(m, m_trn);
+		Multiply_Matrices(m, m_scl);
+		Multiply_Matrices(m, m_shr);
+		Multiply_Matrices(m, m_rot);
+		break;
+
+	case 5:	// Combination B...
+		Multiply_Matrices(m, m_rot);
+		Multiply_Matrices(m, m_shr);
+		Multiply_Matrices(m, m_scl);
+		Multiply_Matrices(m, m_trn);
+		break;
+	}
+
+
+	//-----------------------------------------------------
+	// Execute transformation...
+
+	Transformation(pShapes_A, pShapes_B, m);
+
+
+	//-----------------------------------------------------
+	// Return 'true' if everything went okay...
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CExercise_13::Transformation(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B, double m[3][3])
+{
+	int			iShape, iPart, iPoint;
+	double		x;
+	TSG_Point	p;
+	CSG_Shape		*pShape_A, *pShape_B;
+
+
+	//-----------------------------------------------------
+	// Copy shapes layer A to B and reproject each point's position using matrix m...
+
+	for(iShape=0; iShape<pShapes_A->Get_Count() && Set_Progress(iShape, pShapes_A->Get_Count()); iShape++)
+	{
+		pShape_A	= pShapes_A->Get_Shape(iShape);
+		pShape_B	= pShapes_B->Add_Shape(pShape_A, SHAPE_COPY_ATTR);
+
+		for(iPart=0; iPart<pShape_A->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<pShape_A->Get_Point_Count(iPart); iPoint++)
+			{
+				p	= pShape_A->Get_Point(iPoint, iPart);
+
+				x	= m[0][0] * p.x + m[0][1] * p.y + m[0][2];
+				p.y	= m[1][0] * p.x + m[1][1] * p.y + m[1][2];
+				p.x	= x;
+
+				pShape_B->Add_Point(p, iPart);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CExercise_13::Multiply_Matrices(double A[3][3], double B[3][3])
+{
+	int		x, y, k;
+	double	C[3][3];
+
+	//-----------------------------------------------------
+	for(x=0; x<3; x++)
+	{
+		for(y=0; y<3; y++)
+		{
+			C[x][y]	= 0.0;
+
+			for(k=0; k<3; k++)
+			{				
+				C[x][y]	+= A[x][k] * B[k][y];
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(x=0; x<3; x++)
+	{
+		for(y=0; y<3; y++)
+		{
+			A[x][y]	= C[x][y];
+		}
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_13.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,91 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Lectures_Shapes                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_13.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//                                                       //												
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_13_H
+#define HEADER_INCLUDED__Exercise_13_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_13 : public CSG_Module
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_13(void);							// constructor
+	virtual ~CExercise_13(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	void				Transformation(CSG_Shapes *pShapes_A, CSG_Shapes *pShapes_B, double m[3][3]);
+
+	void				Multiply_Matrices(double A[3][3], double B[3][3]);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_13_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,373 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Lectures_Shapes                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Exercise_14.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Exercise_14.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Defines							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define NOCHANNEL	0
+#define SPRING		1
+#define CHANNEL		2
+#define MOUTH		3
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CExercise_14::CExercise_14(void)
+{
+	//-----------------------------------------------------
+	// Give some information about your module...
+
+	Set_Name	(_TL("14: Vectorising channel lines"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"Vectorising channel lines.\n"
+		"(c) 2003 by Olaf Conrad, Goettingen\n"
+		"email: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Define your parameters list...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation grid"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CHANNELS"	, _TL("Channels (Raster)"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Channels (Vector)"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THRESHOLD"	, _TL("Threshold"),
+		_TL(""),
+		PARAMETER_TYPE_Int	, 4, 0, true, 8, true
+	);
+}
+
+//---------------------------------------------------------
+CExercise_14::~CExercise_14(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_14::On_Execute(void)
+{
+	int		Threshold;
+
+	//-----------------------------------------------------
+	m_pDTM		= Parameters("ELEVATION")	->asGrid();
+	m_pChnl		= Parameters("CHANNELS")	->asGrid();
+	m_pShapes	= Parameters("SHAPES")		->asShapes();
+
+	Threshold	= Parameters("THRESHOLD")	->asInt();
+
+	//-----------------------------------------------------
+	m_pDir		= NULL;
+
+	if( Initialise(Threshold) )
+	{
+		Find_Channels();
+
+		Vectorise();
+	}
+
+	//-----------------------------------------------------
+	if( m_pDir )
+	{
+		delete(m_pDir);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CExercise_14::Initialise(int Threshold)
+{
+	int		x, y, i, ix, iy, Dir;
+	double	z, dz, dzMax;
+	CSG_Colors	Colors;
+
+	//-----------------------------------------------------
+	m_pDir	= new CSG_Grid(m_pDTM, SG_DATATYPE_Char);
+
+	m_pChnl->Assign();
+
+	Colors.Set_Count(4);
+	Colors.Set_Color(0, 192, 192, 192);	// NOCHANNEL
+	Colors.Set_Color(1,   0, 255,   0);	// SPRING
+	Colors.Set_Color(2,   0,   0, 255);	// CHANNEL
+	Colors.Set_Color(3, 255,   0,   0);	// MOUTH
+	DataObject_Set_Colors(m_pChnl, Colors);
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Dir		= -1;
+
+			if( is_InGrid(x, y) && !m_pDTM->is_NoData(x, y) )
+			{
+				z		= m_pDTM->asDouble(x, y);
+				dzMax	= 0.0;
+
+				for(i=0; i<8; i++)
+				{
+					ix		= Get_xTo(i, x);
+					iy		= Get_yTo(i, y);
+
+					if( is_InGrid(ix, iy) && !m_pDTM->is_NoData(ix, iy) )
+					{
+						dz		= (z - m_pDTM->asDouble(ix, iy)) / Get_Length(i);
+
+						if( dz > dzMax )
+						{
+							dzMax	= dz;
+							Dir		= i;
+						}
+					}
+				}
+			}
+
+			//---------------------------------------------
+			m_pDir->Set_Value(x, y, Dir);
+
+			if( Dir >= 0 )
+			{
+				m_pChnl->Add_Value(Get_xTo(Dir, x), Get_yTo(Dir, y), 1);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			m_pChnl->Set_Value(x, y, m_pChnl->asInt(x, y) >= Threshold ? SPRING : NOCHANNEL);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CExercise_14::Find_Channels(void)
+{
+	int		n, x, y;
+
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( m_pDTM->Get_Sorted(n, x, y, true) && m_pChnl->asInt(x, y) == SPRING )
+		{
+			m_pChnl	->Set_Value(x, y, SPRING);
+
+			Find_Channels(x, y);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CExercise_14::Find_Channels(int x, int y)
+{
+	int		Dir, ix, iy;
+
+	if( (Dir = m_pDir->asInt(x, y)) >= 0 )
+	{
+		ix	= Get_xTo(Dir, x);
+		iy	= Get_yTo(Dir, y);
+
+		switch( m_pChnl->asInt(ix, iy) )
+		{
+		case NOCHANNEL: case SPRING:
+			m_pChnl	->Set_Value(ix, iy, CHANNEL);
+			Find_Channels(ix, iy);	// recursive function call...
+			break;
+
+		case CHANNEL:
+			m_pChnl	->Set_Value(ix, iy, MOUTH);
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CExercise_14::Vectorise(void)
+{
+	int			x, y, Segment_ID;
+	double		Length;
+	CSG_Shape	*pSegment;
+
+	m_pShapes->Create(SHAPE_TYPE_Line, _TL("Channels"));
+
+	m_pShapes->Add_Field("SEGMENT_ID"	, SG_DATATYPE_Int);
+	m_pShapes->Add_Field("LENGTH"		, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	for(y=0, Segment_ID=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			switch( m_pChnl->asInt(x, y) )
+			{
+			case SPRING: case MOUTH:
+				pSegment	= m_pShapes->Add_Shape();
+
+				Length		= Vectorise(x, y, pSegment);
+
+				if( Length > 0.0 )
+				{
+					pSegment->Set_Value(0, ++Segment_ID);
+					pSegment->Set_Value(1, Length);
+				}
+				else
+				{
+					m_pShapes->Del_Shape(pSegment);
+				}
+
+				break;
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+double CExercise_14::Vectorise(int x, int y, CSG_Shape *pSegment)
+{
+	int		Dir, ix, iy;
+	double	Length;
+
+	Length	= 0.0;
+
+	pSegment->Add_Point(Get_XMin() + x * Get_Cellsize(), Get_YMin() + y * Get_Cellsize());
+
+	if( (Dir = m_pDir->asInt(x, y)) >= 0 )
+	{
+		Length	= Get_Length(Dir);
+
+		ix		= Get_xTo(Dir, x);
+		iy		= Get_yTo(Dir, y);
+
+		switch( m_pChnl->asInt(ix, iy) )
+		{
+		case CHANNEL:
+			Length	+= Vectorise(ix, iy, pSegment);	// recursive function call...
+			break;
+
+		case MOUTH:
+			Length	+= Get_Length(Dir);
+			pSegment->Add_Point(Get_XMin() + ix * Get_Cellsize(), Get_YMin() + iy * Get_Cellsize());
+			break;
+		}
+	}
+
+	return( Length );
+}

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/Exercise_14.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Exercise_14.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //												
+//														 //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Exercise_14_H
+#define HEADER_INCLUDED__Exercise_14_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+class CExercise_14 : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CExercise_14(void);							// constructor
+	virtual ~CExercise_14(void);				// destructor
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool		On_Execute(void);		// always override this function
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pDTM, *m_pChnl, *m_pDir;
+
+	CSG_Shapes				*m_pShapes;
+
+
+	bool				Initialise(int Threshold);
+
+	void				Find_Channels(void);
+	void				Find_Channels(int x, int y);
+
+	void				Vectorise(void);
+	double				Vectorise(int x, int y, CSG_Shape *pSegment);
+
+};
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Exercise_14_H

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,200 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Lectures - Introducing Module Programming" ));
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2003" ));
+
+	case MLB_INFO_Description:
+		return( _TL("A set of basic SAGA module programming lectures." ));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Lectures|Introducing Module Programming" ));
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Exercise_01.h"
+#include "Exercise_02.h"
+#include "Exercise_03.h"
+#include "Exercise_04.h"
+#include "Exercise_05.h"
+#include "Exercise_06.h"
+#include "Exercise_07.h"
+#include "Exercise_08.h"
+#include "Exercise_09.h"
+#include "Exercise_10.h"
+#include "Exercise_11.h"
+#include "Exercise_12.h"
+#include "Exercise_13.h"
+#include "Exercise_14.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CExercise_01;
+		break;
+
+	case 1:
+		pModule	= new CExercise_02;
+		break;
+
+	case 2:
+		pModule	= new CExercise_03;
+		break;
+
+	case 3:
+		pModule	= new CExercise_04;
+		break;
+
+	case 4:
+		pModule	= new CExercise_05;
+		break;
+
+	case 5:
+		pModule	= new CExercise_06;
+		break;
+
+	case 6:
+		pModule	= new CExercise_07;
+		break;
+
+	case 7:
+		pModule	= new CExercise_08;
+		break;
+
+	case 8:
+		pModule	= new CExercise_09;
+		break;
+
+	case 9:
+		pModule	= new CExercise_10;
+		break;
+
+	case 10:
+		pModule	= new CExercise_11;
+		break;
+
+	case 11:
+		pModule	= new CExercise_12;
+		break;
+
+	case 12:
+		pModule	= new CExercise_13;
+		break;
+
+	case 13:
+		pModule	= new CExercise_14;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_lectures/lectures/lectures_introduction/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Lectures                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__lectures_H
+#define HEADER_INCLUDED__lectures_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef lectures_EXPORTS
+	#define	lectures_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	lectures_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__lectures_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,190 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                   Grid_Georeference                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Collect_Points.cpp                  //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+// Completely rearranged by O.Conrad April 2006 !!!
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Collect_Points.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CCollect_Points::CCollect_Points(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Create Reference Points"));
+
+	Set_Author		(SG_T("(c) 2004 Ringeler, (c) 2006 O.Conrad"));
+
+	Set_Description	(_TW(
+		"Digitize reference points for georeferencing grids, images and shapes. "
+		"Click with the mouse on known locations in the map window "
+		"and add the reference coordinates. "
+		"After choosing 4 or more points, stop the interactive module execution "
+		"by unchecking it in the in the modules menu."
+	));
+
+
+	Parameters.Add_Shapes(
+		NULL, "REF_SOURCE"	, _TL("Reference Points (Origin)"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "REF_TARGET"	, _TL("Reference Points (Projection)"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParameters	= Add_Parameters("REFERENCE", _TL("Point Position"), _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "X"			, _TL("x Position"),
+		_TL(""),
+		PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "Y"			, _TL("y Position"),
+		_TL(""),
+		PARAMETER_TYPE_Double
+	);
+}
+
+
+//---------------------------------------------------------
+CCollect_Points::~CCollect_Points(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CCollect_Points::On_Execute(void)
+{
+	m_pSource	= Parameters("REF_SOURCE")	->asShapes();
+	m_pSource	->Create(SHAPE_TYPE_Point, _TL("Reference Points (Origin)"));
+	m_pSource	->Add_Field("X", SG_DATATYPE_Double);
+	m_pSource	->Add_Field("Y", SG_DATATYPE_Double);
+
+	if( (m_pTarget = Parameters("REF_TARGET")->asShapes()) != NULL )
+	{
+		m_pTarget	->Create(SHAPE_TYPE_Point, _TL("Reference Points (Projection)"));
+		m_pTarget	->Add_Field("X", SG_DATATYPE_Double);
+		m_pTarget	->Add_Field("Y", SG_DATATYPE_Double);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CCollect_Points::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	if( Mode == MODULE_INTERACTIVE_LUP && Dlg_Parameters("REFERENCE") )
+	{
+		double	xSource, ySource, xTarget, yTarget;
+		CSG_Shape	*pShape;
+
+		xSource	= ptWorld.Get_X();
+		ySource	= ptWorld.Get_Y();
+
+		xTarget	= Get_Parameters("REFERENCE")->Get_Parameter("X")->asDouble();
+		yTarget	= Get_Parameters("REFERENCE")->Get_Parameter("Y")->asDouble();
+
+		pShape	= m_pSource->Add_Shape();
+		pShape	->Add_Point(xSource, ySource);
+		pShape	->Set_Value(0, xTarget);
+		pShape	->Set_Value(1, yTarget);
+
+		DataObject_Update(m_pSource);
+
+		if( m_pTarget )
+		{
+			pShape	= m_pTarget->Add_Shape();
+			pShape	->Add_Point(xTarget, yTarget);
+			pShape	->Set_Value(0, xSource);
+			pShape	->Set_Value(1, ySource);
+
+			DataObject_Update(m_pTarget);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Collect_Points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Grid_Georeference                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Collect_Points.h                   //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Collect_Points_H
+#define HEADER_INCLUDED__Collect_Points_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CCollect_Points : public CSG_Module_Interactive
+{
+public:
+	CCollect_Points(void);
+	virtual ~CCollect_Points(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	CSG_Shapes					*m_pSource, *m_pTarget;
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Collect_Points_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,346 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    pj_Georeference                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Georef_Engine.cpp                   //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+// cminpak usage is based on earlier codings of A.Ringeler...
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Georef_Engine.h"
+
+#include "dpmpar.h"
+#include "cminpak.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGeoref_Engine::CGeoref_Engine(void)
+{
+	m_nParms	= 6;
+}
+
+//---------------------------------------------------------
+CGeoref_Engine::~CGeoref_Engine(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Engine::Get_Converted(TSG_Point &Point, bool bInverse)
+{
+	return( Get_Converted(Point.x, Point.y, bInverse) );
+}
+
+//---------------------------------------------------------
+bool CGeoref_Engine::Get_Converted(double &x, double &y, bool bInverse)
+{
+	double	x_;
+
+	if( !bInverse )
+	{
+		x_	= x * m_x    [0] + y * m_x    [1] + m_x    [2]; 
+		y	= x * m_x    [3] + y * m_x    [4] + m_x    [5];
+	}
+	else
+	{
+		x_	= x * m_x_inv[0] + y * m_x_inv[1] + m_x_inv[2]; 
+		y	= x * m_x_inv[3] + y * m_x_inv[4] + m_x_inv[5];
+	}
+
+	x	= x_;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Engine::Set_Engine(CSG_Shapes *pSource, CSG_Shapes *pTarget)
+{
+	int				iShape, iPart, iPoint;
+	TSG_Point		Point;
+	CSG_Points	Pts_Source, Pts_Target;
+	CSG_Shape			*pShape;
+
+	if( pSource && pTarget )
+	{
+		for(iShape=0; iShape<pSource->Get_Count(); iShape++)
+		{
+			pShape	= pSource->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					Point	= pShape->Get_Point(iPoint, iPart);
+					Pts_Source.Add(Point.x, Point.y);
+				}
+			}
+		}
+
+		for(iShape=0; iShape<pTarget->Get_Count(); iShape++)
+		{
+			pShape	= pTarget->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					Point	= pShape->Get_Point(iPoint, iPart);
+					Pts_Target.Add(Point.x, Point.y);
+				}
+			}
+		}
+
+		return( _Set_Engine(&Pts_Source, &Pts_Target) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGeoref_Engine::Set_Engine(CSG_Shapes *pSource, int xField, int yField)
+{
+	int				iShape;
+	TSG_Point		Point;
+	CSG_Points	Pts_Source, Pts_Target;
+	CSG_Shape			*pShape;
+
+	if( pSource && pSource->Get_Type() == SHAPE_TYPE_Point
+	&&	xField >= 0 && xField < pSource->Get_Field_Count()
+	&&	yField >= 0 && yField < pSource->Get_Field_Count()	)
+	{
+		for(iShape=0; iShape<pSource->Get_Count(); iShape++)
+		{
+			pShape	= pSource->Get_Shape(iShape);
+			Point	= pShape->Get_Point(0);
+			Pts_Source.Add(Point.x, Point.y);
+			Pts_Target.Add(
+				pShape->asDouble(xField),
+				pShape->asDouble(yField)
+			);
+		}
+
+		return( _Set_Engine(&Pts_Source, &Pts_Target) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Points	*g_pPts_Source, *g_pPts_Target;
+
+//---------------------------------------------------------
+void fcn_linear(int m, int n, double x[], double fv[], int *iflag)
+{
+	for(int i=0; i<m/2; i++) 
+	{
+		fv[i * 2 + 0]	= g_pPts_Source->Get_X(i) * x[0] + g_pPts_Source->Get_Y(i) * x[1] + x[2] - g_pPts_Target->Get_X(i);
+		fv[i * 2 + 1]	= g_pPts_Source->Get_X(i) * x[3] + g_pPts_Source->Get_Y(i) * x[4] + x[5] - g_pPts_Target->Get_Y(i);
+    }
+}
+
+//---------------------------------------------------------
+void fcn_linear_inverse(int m, int n, double x[], double fv[], int *iflag)
+{
+	for(int i=0; i<m/2; i++) 
+	{
+		fv[i * 2 + 0]	= g_pPts_Target->Get_X(i) * x[0] + g_pPts_Target->Get_Y(i) * x[1] + x[2] - g_pPts_Source->Get_X(i);
+		fv[i * 2 + 1]	= g_pPts_Target->Get_X(i) * x[3] + g_pPts_Target->Get_Y(i) * x[4] + x[5] - g_pPts_Source->Get_Y(i);
+	}
+}
+
+//---------------------------------------------------------
+void fcn_linear_2(int m, int n, double x[], double fv[], int *iflag)
+{
+	for(int i=0; i<m/2; i++) 
+	{
+		fv[i * 2 + 0]	= (g_pPts_Source->Get_X(i) * x[0] + g_pPts_Source->Get_Y(i) * x[1] + x[2]) 
+						/ (g_pPts_Source->Get_X(i) * x[3] + g_pPts_Source->Get_Y(i) * x[4]) - g_pPts_Target->Get_X(i);
+
+		fv[i * 2 + 1]	= (g_pPts_Source->Get_X(i) * x[5] + g_pPts_Source->Get_Y(i) * x[6] + x[7])
+						/ (g_pPts_Source->Get_X(i) * x[8] + g_pPts_Source->Get_Y(i) * x[9] + 1) - g_pPts_Target->Get_Y(i);
+	}
+}
+
+//---------------------------------------------------------
+void fcn_linear_2_inverse(int m, int n, double x[], double fv[], int *iflag)
+{
+	for(int i=0; i<m/2; i++) 
+	{
+		fv[i * 2 + 0]	= (g_pPts_Target->Get_X(i) * x[0] + g_pPts_Target->Get_Y(i) * x[1] + x[2]) 
+						/ (g_pPts_Target->Get_X(i) * x[3] + g_pPts_Target->Get_Y(i) * x[4]) - g_pPts_Source->Get_X(i);
+
+		fv[i * 2 + 1]	= (g_pPts_Target->Get_X(i) * x[5] + g_pPts_Target->Get_Y(i) * x[6] + x[7])
+						/ (g_pPts_Target->Get_X(i) * x[8] + g_pPts_Target->Get_Y(i) * x[9] + 1) - g_pPts_Source->Get_Y(i);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Engine::_Set_Engine(CSG_Points *pPts_Source, CSG_Points *pPts_Target)
+{
+	int			*msk, info, ecode, nfev, nData, i;
+	double		*fvec;
+
+	//-----------------------------------------------------
+	m_Message.Clear();
+
+	g_pPts_Source	= pPts_Source;
+	g_pPts_Target	= pPts_Target;
+
+	if( g_pPts_Source == NULL || g_pPts_Target == NULL )
+	{
+		m_Message.Printf(_TL("Error: invalid source and target references.") );
+
+		return( false );
+	}
+
+	if( g_pPts_Source->Get_Count() != g_pPts_Target->Get_Count() )
+	{
+		m_Message.Printf(_TL("Error: source and target references differ in number of points.") );
+
+		return( false );
+	}
+
+	if( g_pPts_Source->Get_Count() < 3 )
+	{
+		m_Message.Printf(_TL("Error: not enough reference points. The transformation requires at least 3 reference points."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	nData	= 2 * pPts_Source->Get_Count();
+	fvec	= (double *)SG_Calloc(nData, sizeof(double));
+
+	for(i=0; i<nData; i++)
+	{
+		fvec[i]	= 0.0;
+	}
+
+	msk		= (int    *)SG_Malloc(m_nParms * sizeof(int));
+
+	for(i=0; i<m_nParms; i++)
+	{
+		msk[i]	= 1;
+		m_x[i]	= m_x_inv[i]	= 0.0;
+	}
+
+	//-----------------------------------------------------
+	ecode	= lmdif0(fcn_linear        , nData, m_nParms, m_x    , msk, fvec, sqrt(2.220446049250313e-16), &info, &nfev);
+
+	m_Message.Append(CSG_String::Format(SG_T("\n%d %s\n"), nfev, _TL("function evaluations")));
+	m_Message.Append(CSG_String::Format(SG_T("x\n")));
+	m_Message.Append(CSG_String::Format(SG_T("%lf %lf %lf %lf %lf %lf\n"), m_x[0], m_x[1], m_x[2], m_x[3], m_x[4], m_x[5]));
+	m_Message.Append(CSG_String::Format(SG_T("%s\n"), _TL("fvec")));
+	m_Message.Append(CSG_String::Format(SG_T("%lg %lg %lg %lg %lg %lg\n"), fvec[0], fvec[1], fvec[2], fvec[3], fvec[4], fvec[5]));
+	m_Message.Append(CSG_String::Format(SG_T("%s = %.15e\n"), _TL("function norm"), enorm(nData, fvec)));
+
+	//-----------------------------------------------------
+	ecode	= lmdif0(fcn_linear_inverse, nData, m_nParms, m_x_inv, msk, fvec, sqrt(2.220446049250313e-16), &info, &nfev);
+
+	m_Message.Append(CSG_String::Format(SG_T("\n%d inverse function evaluations\n"), nfev));
+	m_Message.Append(CSG_String::Format(SG_T("x\n")));
+	m_Message.Append(CSG_String::Format(SG_T("%lf %lf %lf %lf %lf %lf\n"), m_x_inv[0], m_x_inv[1], m_x_inv[2], m_x_inv[3], m_x_inv[4], m_x_inv[5]));
+	m_Message.Append(CSG_String::Format(SG_T("%s\n"), _TL("fvec")));
+	m_Message.Append(CSG_String::Format(SG_T("%lg %lg %lg %lg %lg %lg\n"), fvec[0], fvec[1], fvec[2], fvec[3], fvec[4], fvec[5]));
+	m_Message.Append(CSG_String::Format(SG_T("%s = %.15e\n"), _TL("function norm"), enorm(nData, fvec)));
+
+	//-----------------------------------------------------
+	SG_Free(fvec);
+	SG_Free(msk);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Engine.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    pj_georeference                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Georef_Engine.h                    //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Georef_Engine_H
+#define HEADER_INCLUDED__Georef_Engine_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGeoref_Engine
+{
+public:
+	CGeoref_Engine(void);
+	virtual ~CGeoref_Engine(void);
+
+	bool			Set_Engine			(CSG_Shapes *pSource, CSG_Shapes *pTarget);
+	bool			Set_Engine			(CSG_Shapes *pSource, int xField, int yField);
+
+	bool			Get_Converted		(TSG_Point &Point   , bool bInverse = false);
+	bool			Get_Converted		(double &x, double &y, bool bInverse = false);
+
+	CSG_String		Get_Message			(void)	{	return( m_Message );	}
+
+
+private:
+
+	int				m_nParms;
+
+	double			m_x[10], m_x_inv[10];
+
+	CSG_String		m_Message;
+
+
+	bool			_Set_Engine			(CSG_Points *pPts_Source, CSG_Points *pPts_Target);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Georef_Engine_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,720 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Grid_Georeference                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Georef_Grid.cpp                    //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+// Widely rearranged by O.Conrad April 2006 !!!
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Georef_Grid.h"
+
+#include <string.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGeoref_Grid::CGeoref_Grid(void)
+{
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+
+	Set_Name		(_TL("Georeferencing - Grids"));
+
+	Set_Author		(SG_T("(c) 2004 Ringeler, (c) 2006 O.Conrad"));
+
+	Set_Description	(_TW(
+		"Georeferencing of grids. Either choose the attribute fields (x/y) "
+		"with the projected coordinates for the reference points (origin) or supply a "
+		"additional points layer with correspondend points in the target projection. "
+		"\n"
+		"This library uses the Minpack routines for solving the nonlinear equations and "
+		"nonlinear least squares problem. You find minpack and more information "
+		"about minpack at:\n"
+		"  <a target=\"_blank\" href=\"http://www.netlib.org/minpack\">"
+		"  http://www.netlib.org/minpack</a>\n"
+		"\n"
+		"or download the C source codes:\n"
+		"  <a target=\"_blank\" href=\"http://www.netlib.org/minpack/cminpack.tar\">"
+		"  http://www.netlib.org/minpack/cminpack.tar</a>\n"
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "SHAPES"	, _TL("Shapes"),
+		_TL("")
+	);
+
+
+	CSG_Parameter	*pSource	= Parameters.Add_Shapes(
+		NULL	, "REF_SOURCE"	, _TL("Reference Points (Origin)"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "REF_TARGET"	, _TL("Reference Points (Projection)"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Table_Field(
+		pSource	, "XFIELD"		, _TL("x Position"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pSource	, "YFIELD"		, _TL("y Position"),
+		_TL("")
+	);
+
+
+	Parameters.Add_Grid(
+		Parameters("SOURCE_NODE"),
+		"SOURCE"		, _TL("Source"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		Parameters("TARGET_NODE"),
+		"TARGET_TYPE"	, _TL("Target"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("User defined"),
+			_TL("Automatic fit"),
+			_TL("Grid Project"),
+			_TL("Grid"),
+			_TL("Shapes")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		Parameters("TARGET_NODE")	, "INTERPOLATION"	, _TL("Grid Interpolation"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neigbhor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_AUTOFIT"	, _TL("Automatic fit")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "GRIDSIZE"	, _TL("Grid Size")	, _TL(""), PARAMETER_TYPE_Double, 10000.0, 0.0, true
+	);
+
+	pParameters->Add_Choice(
+		NULL, "AUTOEXTMODE"	, _TL("Fit Size")	, _TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Extent only (fast)"),
+			_TL("Check each point")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_USER"		, _TL("User defined")		, _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "XMIN"		, _TL("Left")		, _TL(""), PARAMETER_TYPE_Double
+	);
+	pParameters->Add_Value(
+		NULL, "XMAX"		, _TL("Right")		, _TL(""), PARAMETER_TYPE_Double
+	);
+	pParameters->Add_Value(
+		NULL, "YMIN"		, _TL("Bottom")		, _TL(""), PARAMETER_TYPE_Double
+	);
+	pParameters->Add_Value(
+		NULL, "YMAX"		, _TL("Top")		, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "SIZE"		, _TL("Grid Size")	, _TL(""), PARAMETER_TYPE_Double, 10000.0, 0.0, true
+	);
+
+	pParameters->Add_Info_Value(
+		NULL, "NX"			, _TL("Columns")	, _TL(""), PARAMETER_TYPE_Int
+	);
+	pParameters->Add_Info_Value(
+		NULL, "NY"			, _TL("Rows")		, _TL(""), PARAMETER_TYPE_Int
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_SYSTEM"	, _TL("Choose Grid Project"), _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL, "SYSTEM"		, _TL("System")		, _TL("")
+	);
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_GRID"		, _TL("Choose Grid")		, _TL(""));
+
+	pParameters->Add_Grid(
+		NULL, "GRID"		, _TL("Grid")		, _TL(""), PARAMETER_INPUT	, false
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_SHAPES"	, _TL("Choose Shapes")		, _TL(""));
+
+	pParameters->Add_Shapes(
+		NULL, "SHAPES"		, _TL("Shapes")		, _TL(""), PARAMETER_OUTPUT	, SHAPE_TYPE_Point
+	);
+}
+
+//---------------------------------------------------------
+CGeoref_Grid::~CGeoref_Grid(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CGeoref_Grid::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	double	xMin, xMax, yMin, yMax, size;
+
+	if( !SG_STR_CMP(pParameters->Get_Identifier(), SG_T("GET_USER")) )
+	{
+		xMin	= pParameters->Get_Parameter("XMIN")->asDouble();
+		xMax	= pParameters->Get_Parameter("XMAX")->asDouble();
+		yMin	= pParameters->Get_Parameter("YMIN")->asDouble();
+		yMax	= pParameters->Get_Parameter("YMAX")->asDouble();
+		size	= pParameters->Get_Parameter("SIZE")->asDouble();
+
+		if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("SIZE")) )
+		{
+			pParameters->Get_Parameter("XMAX")->Set_Value((xMax = xMin + ((int)((xMax - xMin) / size)) * size));
+			pParameters->Get_Parameter("YMAX")->Set_Value((yMax = yMin + ((int)((yMax - yMin) / size)) * size));
+		}
+		else 
+		{
+			if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMIN")) )
+			{
+				if( xMin >= xMax )
+				{
+					xMin	= xMax - pParameters->Get_Parameter("NX")->asInt() * size;
+					pParameter->Set_Value(xMin);
+				}
+
+				pParameters->Get_Parameter("XMAX")->Set_Value(xMin + ((int)((xMax - xMin) / size)) * size);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMAX")) )
+			{
+				if( xMin >= xMax )
+				{
+					xMax	= xMin + pParameters->Get_Parameter("NX")->asInt() * size;
+					pParameter->Set_Value(xMax);
+				}
+
+				pParameters->Get_Parameter("XMIN")->Set_Value(xMax - ((int)((xMax - xMin) / size)) * size);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMIN")) )
+			{
+				if( yMin >= yMax )
+				{
+					yMin	= yMax - pParameters->Get_Parameter("NY")->asInt() * size;
+					pParameter->Set_Value(yMin);
+				}
+
+				pParameters->Get_Parameter("YMAX")->Set_Value(yMin + ((int)((yMax - yMin) / size)) * size);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMAX")) )
+			{
+				if( yMin >= yMax )
+				{
+					yMax	= yMin + pParameters->Get_Parameter("NY")->asInt() * size;
+					pParameter->Set_Value(yMax);
+				}
+
+				pParameters->Get_Parameter("YMIN")->Set_Value(yMax - ((int)((yMax - yMin) / size)) * size);
+			}
+		}
+
+		pParameters->Get_Parameter("NX")->Set_Value(1 + (int)((xMax - xMin) / size));
+		pParameters->Get_Parameter("NY")->Set_Value(1 + (int)((yMax - yMin) / size));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Grid::On_Execute(void)
+{
+	int		xField, yField;
+	CSG_Shapes	*pShapes_A, *pShapes_B;
+
+	//-----------------------------------------------------
+	pShapes_A	= Parameters("REF_SOURCE")	->asShapes();
+	pShapes_B	= Parameters("REF_TARGET")	->asShapes();
+	xField		= Parameters("XFIELD")		->asInt();
+	yField		= Parameters("YFIELD")		->asInt();
+
+	//-----------------------------------------------------
+	if( ( pShapes_B && m_Engine.Set_Engine(pShapes_A, pShapes_B))
+	||	(!pShapes_B && m_Engine.Set_Engine(pShapes_A, xField, yField))	)
+	{
+		Message_Add(m_Engine.Get_Message());
+
+		return( Get_Conversion() );
+	}
+
+	Error_Set(m_Engine.Get_Message());
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Grid::Get_Conversion(void)
+{
+	int				Interpolation;
+	TSG_Data_Type	Type;
+	CSG_Grid		*pSource, *pGrid;
+	CSG_Shapes		*pShapes;
+
+	//-----------------------------------------------------
+	pSource			= Parameters("SOURCE")->asGrid();
+
+	pGrid			= NULL;
+	pShapes			= NULL;
+
+	Interpolation	= Parameters("INTERPOLATION")->asInt();
+	Type			= Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float;
+
+	//-----------------------------------------------------
+	switch( Parameters("TARGET_TYPE")->asInt() )
+	{
+	case 0:	// create new user defined grid...
+		pGrid	= Get_Target_Userdef(pSource, Type);
+		break;
+
+	case 1:	// create new with chosen grid size and fitted extent...
+		if( Dlg_Parameters("GET_AUTOFIT") )
+		{
+			pGrid	= Get_Target_Autofit(
+						pSource,
+						Get_Parameters("GET_AUTOFIT")->Get_Parameter("GRIDSIZE")		->asDouble(),
+						Get_Parameters("GET_AUTOFIT")->Get_Parameter("AUTOEXTMODE")	->asInt(),
+						Type
+					);
+		}
+		break;
+
+	case 2:	// select grid project...
+		if( Dlg_Parameters("GET_SYSTEM") )
+		{
+			pGrid	= SG_Create_Grid(
+						*Get_Parameters("GET_SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System()
+					);
+		}
+		break;
+
+	case 3:	// select grid...
+		if( Dlg_Parameters("GET_GRID") )
+		{
+			pGrid	= Get_Parameters("GET_GRID")->Get_Parameter("GRID")->asGrid();
+		}
+		break;
+
+	case 4:	// shapes...
+		if( Dlg_Parameters("GET_SHAPES") )
+		{
+			pShapes	= Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->asShapes();
+		}
+		break;
+
+	default:
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( pShapes )
+	{
+		Set_Shapes	(pSource, pShapes);
+
+		Parameters("SHAPES")	->Set_Value(pShapes);
+	}
+
+
+	//-----------------------------------------------------
+	if( pGrid )
+	{
+		Set_Grid	(pSource, pGrid, Interpolation);
+
+		Parameters("GRID")		->Set_Value(pGrid);
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid * CGeoref_Grid::Get_Target_Userdef(CSG_Grid *pSource, TSG_Data_Type Type)
+{
+	int			x, y;
+	double		xMin, yMin, xMax, yMax, size;
+	TSG_Point	Pt_Source;
+	CSG_Grid		*pTarget;
+	CSG_Parameters	*pParameters;
+
+	pTarget	= NULL;
+
+	if( pSource )
+	{
+		//-------------------------------------------------
+		xMin	= yMin	= 1.0;
+		xMax	= yMax	= 0.0;
+
+		for(y=0, Pt_Source.y=0; y<pSource->Get_NY(); y++, Pt_Source.y+=1)
+		{
+			Pt_Source.x	= 0;
+			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+
+			Pt_Source.x	= pSource->Get_NX();
+			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+		}
+
+		for(x=0, Pt_Source.x=0; x<pSource->Get_NX(); x++, Pt_Source.x+=1)
+		{
+			Pt_Source.y	= 0;
+			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+
+			Pt_Source.y	= pSource->Get_NY();
+			Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+		}
+
+		//-------------------------------------------------
+		if( xMin < xMax && yMin < yMax )
+		{
+			pParameters	= Get_Parameters("GET_USER");
+
+			pParameters->Get_Parameter("XMIN")->Set_Value(xMin);
+			pParameters->Get_Parameter("XMAX")->Set_Value(xMax);
+			pParameters->Get_Parameter("YMIN")->Set_Value(yMin);
+			pParameters->Get_Parameter("YMAX")->Set_Value(yMax);
+			size	= (yMax - yMin) / pSource->Get_NY();
+			pParameters->Get_Parameter("SIZE")->Set_Value(size);
+			pParameters->Get_Parameter("NX")->Set_Value(1 + (int)((xMax - xMin) / size));
+			pParameters->Get_Parameter("NY")->Set_Value(1 + (int)((yMax - yMin) / size));
+
+			if( Dlg_Parameters("GET_USER") )
+			{
+				size	= pParameters->Get_Parameter("SIZE")->asDouble();
+
+				pTarget	= SG_Create_Grid(
+					Type,
+					pParameters->Get_Parameter("NX")->asInt(),
+					pParameters->Get_Parameter("NY")->asInt(),
+					size,
+					pParameters->Get_Parameter("XMIN")->asDouble(),
+					pParameters->Get_Parameter("YMIN")->asDouble()
+				);
+			}
+		}
+	}
+
+	return( pTarget );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CGeoref_Grid::Get_Target_Autofit(CSG_Grid *pSource, double Grid_Size, int AutoExtMode, TSG_Data_Type Type)
+{
+	int			x, y;
+	double		xMin, yMin, xMax, yMax;
+	TSG_Point	Pt_Source;
+	CSG_Grid		*pTarget;
+
+	pTarget	= NULL;
+
+	if( pSource )
+	{
+		xMin	= yMin	= 1.0;
+		xMax	= yMax	= 0.0;
+
+		//---------------------------------------------
+		switch( AutoExtMode )
+		{
+		case 0:	default:
+			for(y=0, Pt_Source.y=0; y<pSource->Get_NY(); y++, Pt_Source.y+=1)
+			{
+				Pt_Source.x	= 0;
+				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+
+				Pt_Source.x	= pSource->Get_NX();
+				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+			}
+
+			for(x=0, Pt_Source.x=0; x<pSource->Get_NX(); x++, Pt_Source.x+=1)
+			{
+				Pt_Source.y	= 0;
+				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+
+				Pt_Source.y	= pSource->Get_NY();
+				Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+			}
+
+			break;
+
+		//---------------------------------------------
+		case 1:
+			for(y=0, Pt_Source.y=0; y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=1)
+			{
+				for(x=0, Pt_Source.x=0; x<pSource->Get_NX(); x++, Pt_Source.x+=1)
+				{
+					if( !pSource->is_NoData(x, y) )
+					{
+						Get_MinMax(xMin, xMax, yMin, yMax, Pt_Source);
+					}
+				}
+			}
+
+			break;
+		}
+
+		//---------------------------------------------
+		if( is_Progress() && xMin < xMax && yMin < yMax )
+		{
+			pTarget	= SG_Create_Grid(
+				Type,
+				1 + (int)((xMax - xMin) / Grid_Size),
+				1 + (int)((yMax - yMin) / Grid_Size),
+				Grid_Size,
+				xMin, yMin
+			);
+		}
+	}
+
+	return( pTarget );
+}
+
+//---------------------------------------------------------
+inline void CGeoref_Grid::Get_MinMax(double &xMin, double &xMax, double &yMin, double &yMax, TSG_Point Point)
+{
+	if( m_Engine.Get_Converted(Point) )
+	{
+		if( xMin > xMax )
+		{
+			xMin	= xMax	= Point.x;
+		}
+		else if( xMin > Point.x )
+		{
+			xMin	= Point.x;
+		}
+		else if( xMax < Point.x )
+		{
+			xMax	= Point.x;
+		}
+
+		if( yMin > yMax )
+		{
+			yMin	= yMax	= Point.y;
+		}
+		else if( yMin > Point.y )
+		{
+			yMin	= Point.y;
+		}
+		else if( yMax < Point.y )
+		{
+			yMax	= Point.y;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Grid::Set_Grid(CSG_Grid *pSource, CSG_Grid *pTarget, int Interpolation)
+{
+	int			x, y;
+	double		z;
+	TSG_Point	Pt_Source, Pt_Target;
+
+	if( pSource && pTarget )
+	{
+		pTarget->Set_NoData_Value_Range(pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue());
+		pTarget->Set_ZFactor(pSource->Get_ZFactor());
+		pTarget->Set_Name	(pSource->Get_Name());
+		pTarget->Set_Unit	(pSource->Get_Unit());
+
+		pTarget->Assign_NoData();
+
+		//-------------------------------------------------
+		for(y=0, Pt_Target.y=pTarget->Get_YMin(); y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++, Pt_Target.y+=pTarget->Get_Cellsize())
+		{
+			for(x=0, Pt_Target.x=pTarget->Get_XMin(); x<pTarget->Get_NX(); x++, Pt_Target.x+=pTarget->Get_Cellsize())
+			{
+				Pt_Source	= Pt_Target;
+
+				if( m_Engine.Get_Converted(Pt_Source, true) )
+				{
+					z	= pSource->Get_Value(
+							pSource->Get_XMin() + Pt_Source.x * pSource->Get_Cellsize(),
+							pSource->Get_YMin() + Pt_Source.y * pSource->Get_Cellsize(),
+							Interpolation
+						);
+
+					if( !pSource->is_NoData_Value(z) )
+					{
+						pTarget->Set_Value(x, y, z);
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGeoref_Grid::Set_Shapes(CSG_Grid *pSource, CSG_Shapes *pTarget)
+{
+	int			x, y;
+	TSG_Point	Pt_Source, Pt_Target;
+	CSG_Shape		*pShape;
+
+	if( pSource && pTarget )
+	{
+		pTarget->Create(SHAPE_TYPE_Point, pSource->Get_Name());
+		pTarget->Add_Field("Z", SG_DATATYPE_Double);
+
+		for(y=0, Pt_Source.y=0; y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=1)
+		{
+			for(x=0, Pt_Source.x=0; x<pSource->Get_NX(); x++, Pt_Source.x+=1)
+			{
+				if( !pSource->is_NoData(x, y) )
+				{
+					Pt_Target	= Pt_Source;
+
+					if( m_Engine.Get_Converted(Pt_Target) )
+					{
+						pShape		= pTarget->Add_Shape();
+						pShape->Add_Point(Pt_Target);
+						pShape->Set_Value(0, pSource->asDouble(x, y));
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Grid_Georeference                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Georef_Grid.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at saga-gis.org                   //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Georef_Grid_H
+#define HEADER_INCLUDED__Georef_Grid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include "Georef_Engine.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGeoref_Grid : public CSG_Module 
+{
+public:
+	CGeoref_Grid(void);
+	virtual ~CGeoref_Grid(void);
+
+
+protected:
+
+	virtual int				On_Parameter_Changed		(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool			On_Execute					(void);
+
+private:
+
+	CGeoref_Engine			m_Engine;
+
+
+	bool					Get_Conversion				(void);
+
+	void					Get_MinMax					(double &xMin, double &xMax, double &yMin, double &yMax, TSG_Point Point);
+	CSG_Grid *					Get_Target_Userdef			(CSG_Grid *pSource, TSG_Data_Type Type);
+	CSG_Grid *					Get_Target_Autofit			(CSG_Grid *pSource, double Grid_Size, int AutoExtMode, TSG_Data_Type Type);
+
+	bool					Set_Grid					(CSG_Grid *pSource, CSG_Grid   *pTarget, int Interpolation);
+	bool					Set_Shapes					(CSG_Grid *pSource, CSG_Shapes *pTarget);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Georef_Grid_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,197 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    pj_Georeference                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Georef_Shapes.cpp                   //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at gwdg.de                        //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Georef_Shapes.h"
+#include "Georef_Engine.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGeoref_Shapes::CGeoref_Shapes(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Georeferencing - Shapes"));
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+	Set_Description	(_TW(
+		"Georeferencing of shapes layers. Either choose the attribute fields (x/y) "
+		"with the projected coordinates for the reference points (origin) or supply a "
+		"additional points layer with correspondend points in the target projection. "
+		"\n"
+		"This library uses the Minpack routines for solving the nonlinear equations and "
+		"nonlinear least squares problem. You find minpack and more information "
+		"about minpack at:\n"
+		"  <a target=\"_blank\" href=\"http://www.netlib.org/minpack\">"
+		"  http://www.netlib.org/minpack</a>\n"
+		"\n"
+		"or download the C source codes:\n"
+		"  <a target=\"_blank\" href=\"http://www.netlib.org/minpack/cminpack.tar\">"
+		"  http://www.netlib.org/minpack/cminpack.tar</a>\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Shapes(
+		NULL	, "INPUT"		, _TL("Input"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "OUTPUT"		, _TL("Output"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	CSG_Parameter	*pSource	= Parameters.Add_Shapes(
+		NULL	, "REF_SOURCE"	, _TL("Reference Points (Origin)"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "REF_TARGET"	, _TL("Reference Points (Projection)"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Table_Field(
+		pSource	, "XFIELD"		, _TL("x Position"),
+		_TL("")
+	);
+
+	Parameters.Add_Table_Field(
+		pSource	, "YFIELD"		, _TL("y Position"),
+		_TL("")
+	);
+}
+
+//---------------------------------------------------------
+CGeoref_Shapes::~CGeoref_Shapes(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Shapes::On_Execute(void)
+{
+	int				iShape, iPart, iPoint, xField, yField;
+	TSG_Point		Point;
+	CSG_Shapes			*pShapes_A, *pShapes_B;
+	CSG_Shape			*pShape_A, *pShape_B;
+	CGeoref_Engine	Engine;
+
+	//-----------------------------------------------------
+	pShapes_A	= Parameters("REF_SOURCE")	->asShapes();
+	pShapes_B	= Parameters("REF_TARGET")	->asShapes();
+	xField		= Parameters("XFIELD")		->asInt();
+	yField		= Parameters("YFIELD")		->asInt();
+
+	//-----------------------------------------------------
+	if( ( pShapes_B && Engine.Set_Engine(pShapes_A, pShapes_B))
+	||	(!pShapes_B && Engine.Set_Engine(pShapes_A, xField, yField))	)
+	{
+		pShapes_A	= Parameters("INPUT")	->asShapes();
+		pShapes_B	= Parameters("OUTPUT")	->asShapes();
+
+		pShapes_B->Create(pShapes_A->Get_Type(), pShapes_A->Get_Name(), pShapes_A);
+
+		for(iShape=0; iShape<pShapes_A->Get_Count() && Set_Progress(iShape, pShapes_A->Get_Count()); iShape++)
+		{
+			pShape_A	= pShapes_A->Get_Shape(iShape);
+			pShape_B	= pShapes_B->Add_Shape(pShape_A, SHAPE_COPY_ATTR);
+
+			for(iPart=0; iPart<pShape_A->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape_A->Get_Point_Count(iPart); iPoint++)
+				{
+					Point	= pShape_A->Get_Point(iPoint, iPart);
+
+					if( Engine.Get_Converted(Point) )
+					{
+						pShape_B->Add_Point(Point);
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/Georef_Shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    pj_georeference                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Georef_Shapes.h                    //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Georef_Shapes_H
+#define HEADER_INCLUDED__Georef_Shapes_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGeoref_Shapes : public CSG_Module 
+{
+public:
+	CGeoref_Shapes(void);
+	virtual ~CGeoref_Shapes(void);
+
+
+protected:
+
+	virtual bool			On_Execute					(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Georef_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Library Template                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                        Author                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     author at email.de                        //
+//                                                       //
+//    contact:    Author                                 //
+//                Sesame Street. 7                       //
+//                12345 Metropolis                       //
+//                Nirwana                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Projection - Georeferencing") );
+
+	case MLB_INFO_Author:
+		return( _TL("(c) 2004 A.Ringeler, (c) 2008 O.Conrad") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the georeferencing of spatial data (grids/shapes).") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Projection|Georeferencing") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Collect_Points.h"
+#include "Georef_Grid.h"
+#include "Georef_Shapes.h"
+#include "georef_grid_move.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CCollect_Points );
+	case 1:		return( new CGeoref_Grid );
+	case 2:		return( new CGeoref_Shapes );
+	case 3:		return( new CGeoref_Grid_Move );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,78 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Library Template                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                        Author                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     author at email.de                        //
+//                                                       //
+//    contact:    Author                                 //
+//                Sesame Street. 7                       //
+//                12345 Metropolis                       //
+//                Nirwana                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__pj_georeference_H
+#define HEADER_INCLUDED__pj_georeference_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef pj_georeference_EXPORTS
+	#define	pj_georeference_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	pj_georeference_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__pj_georeference_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,237 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Grid_Georeference                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Georef_Grid_Move.cpp                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at geowiss.uni-hamburg.de         //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "georef_grid_move.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGeoref_Grid_Move::CGeoref_Grid_Move(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Georeferencing - Move Grid"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SOURCE"	, _TL("Source"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	//-----------------------------------------------------
+	Set_Drag_Mode(MODULE_INTERACTIVE_DRAG_LINE);
+}
+
+//---------------------------------------------------------
+CGeoref_Grid_Move::~CGeoref_Grid_Move(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Grid_Move::On_Execute(void)
+{
+	m_pGrid		= Parameters("SOURCE")->asGrid();
+	m_pSource	= NULL;
+	m_bModified	= m_pGrid->is_Modified();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGeoref_Grid_Move::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	if( Mode == MODULE_INTERACTIVE_LDOWN )
+	{
+		m_Down	= ptWorld;
+	}
+	else if( Mode == MODULE_INTERACTIVE_LUP )
+	{
+		if( m_Down != ptWorld )
+		{
+			if( m_pSource == NULL )
+			{
+				m_pSource	= new CSG_Grid(*m_pGrid);
+				m_pSource	->Set_Name(m_pGrid->Get_Name());
+
+				m_Move		= m_Down - ptWorld;
+			}
+			else
+			{
+				m_Move	+= m_Down - ptWorld;
+			}
+
+			//---------------------------------------------
+			int		x, y, ix, iy, dx, dy;
+
+			dx		= (int)(0.5 + m_Move.Get_X() / m_pSource->Get_Cellsize());
+			dy		= (int)(0.5 + m_Move.Get_Y() / m_pSource->Get_Cellsize());
+
+			for(y=0, iy=dy; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, iy++)
+			{
+				if( iy >= 0 && iy < m_pSource->Get_NY() )
+				{
+					for(x=0, ix=dx; x<m_pGrid->Get_NX(); x++, ix++)
+					{
+						if( ix >= 0 && ix < m_pSource->Get_NX() )
+						{
+							m_pGrid->Set_Value(x, y, m_pSource->asDouble(ix, iy));
+						}
+						else
+						{
+							m_pGrid->Set_NoData(x, y);
+						}
+					}
+				}
+				else
+				{
+					for(x=0; x<m_pGrid->Get_NX(); x++)
+					{
+						m_pGrid->Set_NoData(x, y);
+					}
+				}
+			}
+
+			DataObject_Update(m_pGrid);
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGeoref_Grid_Move::On_Execute_Finish(void)
+{
+	if( m_pSource )
+	{
+		m_pGrid->Assign(m_pSource);
+		m_pGrid->Set_Modified(m_bModified);
+		DataObject_Update(m_pGrid);
+
+		if( m_Move.Get_X() == 0.0 && m_Move.Get_Y() == 0.0 )
+		{
+			Message_Add(_TL("No translation set by user"));
+		}
+		else if( Message_Dlg_Confirm(_TL("Apply Move"), _TL("Move Grid")) )
+		{
+			m_pGrid	= new CSG_Grid(m_pSource->Get_Type(), m_pSource->Get_NX(), m_pSource->Get_NY(), m_pSource->Get_Cellsize(),
+				m_pSource->Get_XMin() - m_Move.Get_X(),
+				m_pSource->Get_YMin() - m_Move.Get_Y()
+			);
+
+			m_pGrid->Set_Name   (m_pSource->Get_Name());
+			m_pGrid->Set_Unit   (m_pSource->Get_Unit());
+			m_pGrid->Set_ZFactor(m_pSource->Get_ZFactor());
+
+			for(int y=0; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++)
+			{
+				for(int x=0; x<m_pGrid->Get_NX(); x++)
+				{
+					m_pGrid->Set_Value(x, y, m_pSource->asDouble(x, y));
+				}
+			}
+
+			Parameters("GRID")->Set_Value(m_pGrid);
+
+			return( true );
+		}
+
+		delete(m_pSource);
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_georeference/pj_georeference/georef_grid_move.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Grid_Georeference                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Georef_Grid_Move.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at geowiss.uni-hamburg.de         //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Georef_Grid_Move_H
+#define HEADER_INCLUDED__Georef_Grid_Move_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGeoref_Grid_Move : public CSG_Module_Interactive
+{
+public:
+	CGeoref_Grid_Move(void);
+	virtual ~CGeoref_Grid_Move(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+	virtual bool				On_Execute_Position		(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+	virtual bool				On_Execute_Finish		(void);
+
+
+
+private:
+
+	bool						m_bModified;
+
+	CSG_Point					m_Down, m_Move;
+
+	CSG_Grid					*m_pGrid, *m_pSource;
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Georef_Grid_Move_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,133 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Projection - Proj.4") );
+
+	case MLB_INFO_Author:
+		return( SG_T("O. Conrad (c) 2004-8") );
+
+	case MLB_INFO_Description:
+		return( _TW(
+			"Coordinate transformation based on the "
+			"<a target=\"_blank\" href=\"http://trac.osgeo.org/proj/\">Proj.4</a> library."
+		));
+
+	case MLB_INFO_Version:
+		return( _TL("2.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Projection") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "PROJ4_Shapes.h"
+#include "PROJ4_Grid.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:	return( new CPROJ4_Shapes	(PROJ4_INTERFACE_SIMPLE, false) );
+	case 1:	return( new CPROJ4_Shapes	(PROJ4_INTERFACE_DIALOG, false) );
+	case 2:	return( new CPROJ4_Grid		(PROJ4_INTERFACE_SIMPLE, false) );
+	case 3:	return( new CPROJ4_Grid		(PROJ4_INTERFACE_DIALOG, false) );
+	case 4:	return( new CPROJ4_Shapes	(PROJ4_INTERFACE_SIMPLE, true) );
+	case 5:	return( new CPROJ4_Shapes	(PROJ4_INTERFACE_DIALOG, true) );
+	case 6:	return( new CPROJ4_Grid		(PROJ4_INTERFACE_SIMPLE, true) );
+	case 7:	return( new CPROJ4_Grid		(PROJ4_INTERFACE_DIALOG, true) );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__pj_proj4_H
+#define HEADER_INCLUDED__pj_proj4_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef pj_proj4_EXPORTS
+	#define	pj_proj4_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	pj_proj4_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__pj_proj4_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,952 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    PROJ4_Base.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "PROJ4_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define PRM_ADD_BOL(key, name, val)	pParms->Add_Value(NULL, key, name, _TL(""), PARAMETER_TYPE_Bool  , val);
+#define PRM_ADD_INT(key, name, val)	pParms->Add_Value(NULL, key, name, _TL(""), PARAMETER_TYPE_Int   , val);
+#define PRM_ADD_FLT(key, name, val)	pParms->Add_Value(NULL, key, name, _TL(""), PARAMETER_TYPE_Double, val);
+
+//---------------------------------------------------------
+#define STR_ADD_BOL(key, val)		(val ? CSG_String::Format(SG_T("+%s "), key) : SG_T(""))
+#define STR_ADD_INT(key, val)		CSG_String::Format(SG_T("+%s=%d "), key, val)
+#define STR_ADD_FLT(key, val)		CSG_String::Format(SG_T("+%s=%f "), key, val)
+#define STR_ADD_STR(key, val)		CSG_String::Format(SG_T("+%s=%s "), key, val)
+
+//---------------------------------------------------------
+#define BESSEL_A					6377397.16
+#define BESSEL_B					6356078.76
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPROJ4_Base::CPROJ4_Base(int Interface, bool bInputList)
+{
+	CSG_Parameter	*pNode;
+
+	m_Interface		= Interface;
+	m_bInputList	= bInputList;
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "SOURCE_NODE"	, _TL("Source Parameters"),
+		_TL("")
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "TARGET_NODE"	, _TL("Target Parameters"),
+		_TL("")
+	);
+
+	pNode	= Parameters.Add_Node(
+		NULL	, "GENERAL_NODE", _TL("General Settings"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "INVERSE"		, _TL("Inverse"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+
+	//-----------------------------------------------------
+	switch( m_Interface )
+	{
+	//-----------------------------------------------------
+	case PROJ4_INTERFACE_SIMPLE:	default:
+
+		Parameters.Add_String(
+			Parameters("SOURCE_NODE")	, "SOURCE_PROJ"	, _TL("Source Projection Parameters"),
+			_TL(""),
+			SG_T("+proj=tmerc +datum=potsdam +lon_0=9 +x_0=3500000")
+		);
+
+		Parameters.Add_String(
+			Parameters("TARGET_NODE")	, "TARGET_PROJ"	, _TL("Target Projection Parameters"),
+			_TL(""),
+			SG_T("+proj=tmerc +datum=potsdam +lon_0=12 +x_0=4500000")
+		);
+
+		break;
+
+	//-----------------------------------------------------
+	case PROJ4_INTERFACE_DIALOG:
+
+		pNode	= Parameters.Add_Parameters(
+			Parameters("SOURCE_NODE")	, "SOURCE_PROJ"	, _TL("Source Projection Parameters"),
+			_TL("")
+		);
+
+		_Init_Projection(*pNode->asParameters());
+
+		pNode	= Parameters.Add_Parameters(
+			Parameters("TARGET_NODE")	, "TARGET_PROJ"	, _TL("Target Projection Parameters"),
+			_TL("")
+		);
+
+		_Init_Projection(*pNode->asParameters());
+
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Base::On_Execute(void)
+{
+	bool		bResult	= false;
+
+	CSG_String	sSrc, sDst;
+
+	//-----------------------------------------------------
+	if( _Get_Projections(sSrc, sDst) )
+	{
+		if( (m_pPrjSrc = pj_init_plus(sSrc.b_str())) == NULL )
+		{
+			Error_Set(CSG_String::Format(SG_T("%s:\n%s"), _TL("projection initialization failure"), SG_STR_MBTOSG(pj_strerrno(pj_errno))));
+		}
+
+		if( (m_pPrjDst = pj_init_plus(sDst.b_str())) == NULL )
+		{
+			Error_Set(CSG_String::Format(SG_T("%s:\n%s"), _TL("projection initialization failure"), SG_STR_MBTOSG(pj_strerrno(pj_errno))));
+		}
+
+		Message_Add(CSG_String::Format(SG_T("\n%s: %s\n"), _TL("Source"), sSrc.c_str()), false);
+		Message_Add(CSG_String::Format(SG_T("\n%s: %s\n"), _TL("Target"), sDst.c_str()), false);
+
+		//-------------------------------------------------
+		if(	m_pPrjSrc && m_pPrjDst )
+		{
+			if( Parameters("INVERSE")->asBool() )
+			{
+				PJ	*tmp	= m_pPrjSrc;
+				m_pPrjSrc	= m_pPrjDst;
+				m_pPrjDst	= tmp;
+			}
+
+			if( m_pPrjSrc->inv == NULL )
+			{
+				Error_Set(_TL("Inverse transformation not available for selected projection type."));
+			}
+			else
+			{
+				m_bInverse	= false;
+
+				bResult		= On_Execute_Conversion();
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_pPrjSrc )
+		{
+			pj_free(m_pPrjSrc);
+		}
+
+		if( m_pPrjDst )
+		{
+			pj_free(m_pPrjDst);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Base::Set_Inverse(bool bOn)
+{
+	if( m_bInverse == bOn )
+	{
+		return( true );
+	}
+
+	if( m_pPrjDst && m_pPrjDst->inv )
+	{
+		m_bInverse	= bOn;
+
+		PJ	*tmp	= m_pPrjSrc;
+		m_pPrjSrc	= m_pPrjDst;
+		m_pPrjDst	= tmp;
+
+		return( true );
+	}
+
+	Error_Set(_TL("Inverse transformation not available for selected projection type."));
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CPROJ4_Base::Get_Proj_Name(void)
+{
+	if( m_pPrjDst )
+	{
+		return( CSG_String(m_pPrjDst->descr).BeforeFirst('\n') );
+	}
+
+	return( _TL("") );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Base::Get_Converted(TSG_Point &Point)
+{
+	return( Get_Converted(Point.x, Point.y) );
+}
+
+bool CPROJ4_Base::Get_Converted(double &x, double &y)
+{
+	if( m_pPrjSrc && m_pPrjDst )
+	{
+		double	z	= 0.0;
+
+		if( pj_is_latlong(m_pPrjSrc) )
+		{
+			x	*= DEG_TO_RAD;
+			y	*= DEG_TO_RAD;
+		}
+
+		if( pj_transform(m_pPrjSrc, m_pPrjDst, 1, 0, &x, &y, &z) == 0 )
+		{
+			if( pj_is_latlong(m_pPrjDst) )
+			{
+				x	*= RAD_TO_DEG;
+				y	*= RAD_TO_DEG;
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Base::_Get_Projections(CSG_String &sPrjSrc, CSG_String &sPrjDst)
+{
+	switch( m_Interface )
+	{
+	//-----------------------------------------------------
+	case PROJ4_INTERFACE_SIMPLE:	default:
+
+		sPrjSrc	= Parameters("SOURCE_PROJ")->asString();
+		sPrjDst	= Parameters("TARGET_PROJ")->asString();
+
+		return( true );
+
+	//-----------------------------------------------------
+	case PROJ4_INTERFACE_DIALOG:
+
+		return(
+			_Get_Projection(sPrjSrc, *Parameters("SOURCE_PROJ")->asParameters()),
+			_Get_Projection(sPrjDst, *Parameters("TARGET_PROJ")->asParameters())
+		);
+	}
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Base::_Get_Projection(CSG_String &sPrj, CSG_Parameters &P)
+{
+	//-----------------------------------------------------
+	sPrj	.Clear();
+
+	sPrj	+= STR_ADD_STR(SG_T("proj")	, SG_STR_MBTOSG(pj_list[P("PROJ_TYPE")->asInt()].id));
+
+	sPrj	+= STR_ADD_FLT(SG_T("lon_0")	, P("LON_0")->asDouble());
+	sPrj	+= STR_ADD_FLT(SG_T("lat_0")	, P("LAT_0")->asDouble());
+
+	sPrj	+= STR_ADD_FLT(SG_T("x_0")		, P("X_0"  )->asDouble());
+	sPrj	+= STR_ADD_FLT(SG_T("y_0")		, P("Y_0"  )->asDouble());
+
+	if( P("K_0")->asDouble() != 1.0 && P("K_0")->asDouble() > 0.0 )
+	{
+		sPrj	+= STR_ADD_FLT(SG_T("k_0")	, P("K_0"  )->asDouble());
+	}
+
+	sPrj	+= STR_ADD_STR(SG_T("units")	, SG_STR_MBTOSG(pj_units[P("UNIT")->asInt()].id));
+
+	//-----------------------------------------------------
+	if( P("DATUM_DEF")->asInt() == 0 )	// predefined datum
+	{
+		sPrj	+= STR_ADD_STR(SG_T("datum")	, SG_STR_MBTOSG(pj_datums[P("DATUM")->asInt()].id));
+	}
+
+	//-----------------------------------------------------
+	else								// user defined datum
+	{
+		switch( P("ELLIPSOID")->asInt() )
+		{
+		case 0:	// Predefined Ellipsoid
+			sPrj	+= STR_ADD_STR(SG_T("ellps")	, SG_STR_MBTOSG(pj_ellps[P("ELLPS_PREDEF")->asInt()].id));
+			break;
+
+		case 1:	// Semiminor axis
+			sPrj	+= STR_ADD_FLT(SG_T("a")		, P("ELLPS_A" )->asDouble());
+			sPrj	+= STR_ADD_FLT(SG_T("b")		, P("ELLPS_B" )->asDouble());
+			break;
+
+		case 2:	// Flattening
+			sPrj	+= STR_ADD_FLT(SG_T("a")		, P("ELLPS_A" )->asDouble());
+			sPrj	+= STR_ADD_FLT(SG_T("f")		, P("ELLPS_F" )->asDouble());
+			break;
+
+		case 3:	// Reciprocal Flattening
+			sPrj	+= STR_ADD_FLT(SG_T("a")		, P("ELLPS_A" )->asDouble());
+			sPrj	+= STR_ADD_FLT(SG_T("rf")		, P("ELLPS_RF")->asDouble());
+			break;
+
+		case 4:	// Eccentricity
+			sPrj	+= STR_ADD_FLT(SG_T("a")		, P("ELLPS_A" )->asDouble());
+			sPrj	+= STR_ADD_FLT(SG_T("e")		, P("ELLPS_E" )->asDouble());
+			break;
+
+		case 5:	// Eccentricity Squared
+			sPrj	+= STR_ADD_FLT(SG_T("a")		, P("ELLPS_A" )->asDouble());
+			sPrj	+= STR_ADD_FLT(SG_T("es")		, P("ELLPS_ES")->asDouble());
+			break;
+		}
+
+		switch( P("DATUM_SHIFT")->asInt() )
+		{
+		case 1:	// 3 parameters
+			sPrj	+= CSG_String::Format(SG_T("+towgs84=%f,%f,%f "),
+				P("DS_DX")->asDouble(),
+				P("DS_DY")->asDouble(),
+				P("DS_DZ")->asDouble()
+			);
+			break;
+
+		case 2:	// 7 parameters
+			sPrj	+= CSG_String::Format(SG_T("+towgs84=%f,%f,%f,%f,%f,%f,%f "),
+				P("DS_DX")->asDouble(),
+				P("DS_DY")->asDouble(),
+				P("DS_DZ")->asDouble(),
+				P("DS_RX")->asDouble(),
+				P("DS_RY")->asDouble(),
+				P("DS_RZ")->asDouble(),
+				P("DS_SC")->asDouble()
+			);
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	CSG_Parameters	*pParms	= Get_Parameters(SG_STR_MBTOSG(pj_list[P("PROJ_TYPE")->asInt()].id));
+
+	if( pParms == NULL || pParms->Get_Count() <= 0 )
+	{
+		return( true );
+	}
+
+	if( Dlg_Parameters(SG_STR_MBTOSG(pj_list[P("PROJ_TYPE")->asInt()].id)) )
+	{
+		for(int i=0; i<pParms->Get_Count(); i++)
+		{
+			CSG_Parameter	*p	= pParms->Get_Parameter(i);
+
+			switch( p->Get_Type() )
+			{
+			case PARAMETER_TYPE_Bool:	sPrj	+= STR_ADD_BOL(p->Get_Identifier(), p->asBool());	break;
+			case PARAMETER_TYPE_Int:	sPrj	+= STR_ADD_INT(p->Get_Identifier(), p->asInt());	break;
+			case PARAMETER_TYPE_Double:	sPrj	+= STR_ADD_FLT(p->Get_Identifier(), p->asDouble());	break;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Initializations						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Base::_Init_Projection(CSG_Parameters &P)
+{
+	CSG_String		sList, sName, sDesc, sArgs;
+	CSG_Parameter	*pNode_0, *pNode_1, *pNode_2, *pNode_3;
+
+	pNode_0	= NULL;
+
+
+	//-----------------------------------------------------
+	// Projections...
+
+	sDesc	= _TL("Available Projections:");
+
+	sList.Clear();
+
+	for(struct PJ_LIST *pProjection=pj_list; pProjection->id; ++pProjection)
+	{
+		sArgs	= *pProjection->descr;
+		sName	= sArgs.BeforeFirst('\n');
+		sArgs	= sArgs.AfterFirst ('\n').AfterFirst('\n').AfterFirst('\t');
+
+		sList	+= CSG_String::Format(SG_T("%s|"), sName.c_str());
+		sDesc	+= CSG_String::Format(SG_T("\n[%s] %s (%s)"), SG_STR_MBTOSG(pProjection->id), sName.c_str(), sArgs.c_str());
+
+		_Init_Projection(pProjection->id, sName, sArgs);
+	}
+
+	if( sList.Length() > 0 )
+	{
+		P.Add_Choice(NULL, "PROJ_TYPE", _TL("Projection Type"), sDesc, sList);
+	}
+
+
+	//-----------------------------------------------------
+	// Datums...
+
+	pNode_1	= P.Add_Choice(
+		pNode_0, "DATUM_DEF"		, _TL("Datum Definition"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Predefined Datum"),
+			_TL("User Defined Datum")
+		)
+	);
+
+	//-----------------------------------------------------
+	sList.Clear();
+
+	for(struct PJ_DATUMS *pDatum=pj_datums; pDatum->id; ++pDatum)
+	{
+		sList	+= CSG_String::Format(SG_T("[%s]"), SG_STR_MBTOSG(pDatum->id));
+
+		if( SG_STR_MBTOSG(pDatum->comments) != NULL && SG_STR_MBTOSG(*pDatum->comments) != NULL )
+		{
+			sList	+= CSG_String::Format(SG_T(" %s"), SG_STR_MBTOSG(pDatum->comments));
+		}
+
+		sList	+= '|';
+	}
+
+	if( sList.Length() > 0 )
+	{
+		pNode_2	= P.Add_Choice(pNode_1, "DATUM", _TL("Predefined Datum"), _TL(""), sList);
+	}
+
+
+	//-----------------------------------------------------
+	// User defined ellipsoid and datum shift...
+
+	pNode_2	= P.Add_Node(
+		pNode_1, "NODE_USER_DATUM"	, _TL("User Defined Datum"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	pNode_3	= P.Add_Choice(
+		pNode_2, "ELLIPSOID"		, _TL("Ellipsoid Definition"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Predefined Standard Ellipsoids"),
+			_TL("Semimajor Axis and Semiminor Axis"),
+			_TL("Semimajor Axis and Flattening"),
+			_TL("Semimajor Axis and Reciprocal Flattening"),
+			_TL("Semimajor Axis and Eccentricity"),
+			_TL("Semimajor Axis and Eccentricity Squared")
+		)
+	);
+
+	//-----------------------------------------------------
+	sList.Clear();
+
+	for(struct PJ_ELLPS *pEllipse=pj_ellps; pEllipse->id; ++pEllipse)
+	{
+		sList	+= CSG_String::Format(SG_T("[%s] %s (%s, %s)|"), SG_STR_MBTOSG(pEllipse->id), SG_STR_MBTOSG(pEllipse->name), SG_STR_MBTOSG(pEllipse->major), SG_STR_MBTOSG(pEllipse->ell));
+	}
+
+	if( sList.Length() > 0 )
+	{
+		P.Add_Choice(pNode_3, "ELLPS_PREDEF", _TL("Predefined Standard Ellipsoids"), _TL(""), sList);
+	}
+
+	//-----------------------------------------------------
+	P.Add_Value(
+		pNode_3, "ELLPS_A"		, _TL("Semimajor Axis (a)"),
+		_TL("Semimajor axis or equatorial radius."),
+		PARAMETER_TYPE_Double	, BESSEL_A
+	);
+
+	P.Add_Value(
+		pNode_3, "ELLPS_B"		, _TL("Semiminor Axis (b)"),
+		_TL("Semiminor axis or polar radius."),
+		PARAMETER_TYPE_Double	, BESSEL_B
+	);
+
+	P.Add_Value(
+		pNode_3, "ELLPS_F"		, _TL("Flattening (f)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, (BESSEL_A - BESSEL_B) / BESSEL_A
+	);
+
+	P.Add_Value(
+		pNode_3, "ELLPS_RF"		, _TL("Reciprocal Flattening (rf)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, BESSEL_A / (BESSEL_A - BESSEL_B)
+	);
+
+	P.Add_Value(
+		pNode_3, "ELLPS_E"		, _TL("Eccentricity (e)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, sqrt(BESSEL_A*BESSEL_A + BESSEL_B*BESSEL_B)
+	);
+
+	P.Add_Value(
+		pNode_3, "ELLPS_ES"		, _TL("Squared Eccentricity (es)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, BESSEL_A*BESSEL_A + BESSEL_B*BESSEL_B
+	);
+
+
+	//-----------------------------------------------------
+	pNode_3	= P.Add_Choice(
+		pNode_2, "DATUM_SHIFT"	, _TL("Datum Shift"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("none"),
+			_TL("3 parameters (translation only)"),
+			_TL("7 parameters")
+		)
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_DX"		, _TL("Translation X"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_DY"		, _TL("Translation Y"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_DZ"		, _TL("Translation Z"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_RX"		, _TL("Rotation X"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_RY"		, _TL("Rotation Y"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_RZ"		, _TL("Rotation Z"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	P.Add_Value(
+		pNode_3, "DS_SC"		, _TL("Scaling"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+
+
+	//-----------------------------------------------------
+	// General Settings...
+
+	pNode_1	= P.Add_Node(
+		pNode_0, "NODE_GENERAL"	, _TL("General Settings"),
+		_TL("")
+	);
+
+	//-----------------------------------------------------
+	P.Add_Value(
+		pNode_1, "LON_0"		, _TL("Central Meridian"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	P.Add_Value(
+		pNode_1, "LAT_0"		, _TL("Central Parallel"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	P.Add_Value(
+		pNode_1, "X_0"			, _TL("False Easting"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	P.Add_Value(
+		pNode_1, "Y_0"			, _TL("False Northing"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	P.Add_Value(
+		pNode_1, "K_0"			, _TL("Scale Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	sList.Clear();
+
+	for(struct PJ_UNITS *pUnit=pj_units; pUnit->id; ++pUnit)
+	{
+		sList	+= CSG_String::Format(SG_T("%s (%s)|"), SG_STR_MBTOSG(pUnit->name), SG_STR_MBTOSG(pUnit->to_meter));
+	}
+
+	if( sList.Length() > 0 )
+	{
+		P.Add_Choice(pNode_1, "UNIT", _TL("Unit"), _TL(""), sList, 1);
+	}
+
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Base::_Init_Projection(const CSG_String &sID, const CSG_String &sName, const CSG_String &sArgs)
+{
+	if( sArgs.Length() == 0 )
+	{
+		return( false );
+	}
+
+	CSG_Parameters	*pParms	= Add_Parameters(sID, sName, sArgs);
+
+	//-----------------------------------------------------
+	// Cylindrical Projections...
+
+	if(	!sID.CmpNoCase(SG_T("cea"))			// Equal Area Cylindrical
+	||	!sID.CmpNoCase(SG_T("eqc"))			// Equidistant Cylindrical (Plate Caree) 
+	||	!sID.CmpNoCase(SG_T("merc")) )		// Mercator 
+	{
+		PRM_ADD_FLT("lat_ts"	, _TL("True Scale Latitude")	, 0.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("utm")) )		// Universal Transverse Mercator (UTM)
+	{
+		PRM_ADD_INT("zone"		, _TL("Zone")					, 32);
+		PRM_ADD_BOL("south"		, _TL("South")					, false);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("omerc")) )		// Oblique Mercator 
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 40.0);
+		PRM_ADD_FLT("lon_1"		, _TL("Longitude 1"	)			,-20.0);
+		PRM_ADD_FLT("lat_2"		, _TL("Latitude 2")				, 50.0);
+		PRM_ADD_FLT("lon_2"		, _TL("Longitude 2"	)			, 20.0);
+	}
+
+	//-----------------------------------------------------
+	// Pseudocylindrical Projections...
+
+	if(	!sID.CmpNoCase(SG_T("gn_sinu")) )	// General Sinusoidal Series
+	{
+		PRM_ADD_FLT("m"			, SG_T("m")						, 0.5);
+		PRM_ADD_FLT("n"			, SG_T("n")						, 1.0 + M_PI_045);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("loxim")) )		// Loximuthal
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 40.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("urmfps")) )	// Urmaev Flat-Polar Sinusoidal
+	{
+		PRM_ADD_FLT("n"			, SG_T("n")						, 1.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("urm5")) )		// Urmaev V
+	{
+		PRM_ADD_FLT("n"			, SG_T("n")						, 1.0);
+		PRM_ADD_FLT("q"			, SG_T("q")						, 1.0);
+		PRM_ADD_FLT("alphi"		, SG_T("alphi")					, 45.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("wink1"))		// Winkel I
+	||	!sID.CmpNoCase(SG_T("wag3")) )		// Wagner III
+	{
+		PRM_ADD_FLT("lat_ts"	, _TL("True Scale Latitude")	, 45.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("wink2")) )		// Winkel II
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 40.0);
+	}
+
+
+	//-----------------------------------------------------
+	// Conic Projections...
+
+	if(	!sID.CmpNoCase(SG_T("aea"))			// Albers Equal Area
+	||	!sID.CmpNoCase(SG_T("eqdc"))		// Equidistant Conic
+	||	!sID.CmpNoCase(SG_T("euler"))		// Euler 
+	||	!sID.CmpNoCase(SG_T("imw_p"))		// International Map of the World Polyconic 
+	||	!sID.CmpNoCase(SG_T("murd1"))		// Murdoch I 
+	||	!sID.CmpNoCase(SG_T("murd2"))		// Murdoch II 
+	||	!sID.CmpNoCase(SG_T("murd3"))		// Murdoch III 
+	||	!sID.CmpNoCase(SG_T("pconic"))		// Perspective Conic 
+	||	!sID.CmpNoCase(SG_T("tissot"))		// Tissot 
+	||	!sID.CmpNoCase(SG_T("vitk1")) )		// Vitkovsky I 
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 33.0);
+		PRM_ADD_FLT("lat_2"		, _TL("Latitude 2")				, 45.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("lcc")) )		// Lambert Conformal Conic 
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 33.0);
+		PRM_ADD_FLT("lat_2"		, _TL("Latitude 2")				, 45.0);
+	}
+
+	if( !sID.CmpNoCase(SG_T("leac")) )		// Lambert Equal Area Conic
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 45.0);
+		PRM_ADD_BOL("south"		, _TL("South")					, false);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("rpoly")) )		// Rectangular Polyconic
+	{
+		PRM_ADD_FLT("lat_ts"	, _TL("True Scale Latitude")	, 45.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("mpoly")) )		// Modified Polyconic
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 33.0);
+		PRM_ADD_FLT("lat_2"		, _TL("Latitude 2")				, 45.0);
+		PRM_ADD_BOL("lotsa"		, _TL("Lotsa")					, true);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("bonne")) )		// Bonne
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 45.0);
+	}
+
+
+	//-----------------------------------------------------
+	// Azimuthal Projections...
+
+	if(	!sID.CmpNoCase(SG_T("stere")) )		// Stereographic
+	{
+		PRM_ADD_FLT("lat_ts"	, _TL("True Scale Latitude")	, 45.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("ups")) )		// Universal Polar Stereographic
+	{
+		PRM_ADD_BOL("south"		, _TL("South")					, true);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("airy")) )		// Airy
+	{
+		PRM_ADD_FLT("lat_b"		, _TL("Latitude B")				, 45.0);
+		PRM_ADD_BOL("no_cut"	, _TL("No Cut")					, true);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("nsper")) )		// Near-sided perspective
+	{
+		PRM_ADD_FLT("h"			, _TL("Height of view point")	, 1.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("aeqd")) )		// Azimuthal Equidistant
+	{
+		PRM_ADD_BOL("guam"		, _TL("guam")					, true);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("hammer")) )	// Hammer & Eckert-Greifendorff
+	{
+		PRM_ADD_FLT("W"			, _TL("W")						, 0.5);
+		PRM_ADD_FLT("M"			, _TL("M")						, 1.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("wintri")) )	// Winkel Tripel 
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 40.0);
+	}
+
+
+	//-----------------------------------------------------
+	// Miscellaneous Projections...
+
+	if(	!sID.CmpNoCase(SG_T("ocea"))		// Oblique Cylindrical Equal Area
+	||	!sID.CmpNoCase(SG_T("tpeqd")) )		// Two Point Equidistant 
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 40.0);
+		PRM_ADD_FLT("lon_1"		, _TL("Longitude 1")			,-20.0);
+		PRM_ADD_FLT("lat_2"		, _TL("Latitude 2")				, 50.0);
+		PRM_ADD_FLT("lon_2"		, _TL("Longitude 2"	)			, 20.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("lsat")) )		// Space oblique for LANDSAT
+	{
+		PRM_ADD_INT("lsat"		, _TL("Landsat")				, 1.0);
+		PRM_ADD_INT("path"		, _TL("Path")					, 1.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("labrd")) )		// Laborde
+	{
+		PRM_ADD_FLT("azi"		, _TL("Azimuth"	)				, 19.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("lagrng")) )	// Lagrange
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 0.0);
+		PRM_ADD_FLT("W"			, _TL("W")						, 2.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("chamb")) )		// Chamberlin Trimetric
+	{
+		PRM_ADD_FLT("lat_1"		, _TL("Latitude 1")				, 30.0);
+		PRM_ADD_FLT("lon_1"		, _TL("Longitude 1"	)			,-20.0);
+		PRM_ADD_FLT("lat_2"		, _TL("Latitude 2")				, 40.0);
+		PRM_ADD_FLT("lon_2"		, _TL("Longitude 2")			, 00.0);
+		PRM_ADD_FLT("lat_3"		, _TL("Latitude 3")				, 50.0);
+		PRM_ADD_FLT("lon_3"		, _TL("Longitude 3"	)			, 20.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("oea")) )		// Oblated Equal Area
+	{
+		PRM_ADD_FLT("m"			, _TL("m")						, 1.0);
+		PRM_ADD_FLT("n"			, _TL("n")						, 1.0);
+		PRM_ADD_FLT("theta"		, _TL("theta")					, 45.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("tpers")) )		// Tilted perspective
+	{
+		PRM_ADD_FLT("tilt"		, _TL("Tilt")					, 45.0);
+		PRM_ADD_FLT("azi"		, _TL("Azimuth")				, 45.0);
+		PRM_ADD_FLT("h"			, _TL("h")						, 1000.0);
+	}
+
+	if(	!sID.CmpNoCase(SG_T("ob_tran")) )	// General Oblique Transformation
+	{
+		PRM_ADD_FLT("o_lat_p"	, _TL("Latitude Pole")			, 40.0);
+		PRM_ADD_FLT("o_lon_p"	, _TL("Longitude Pole")			, 40.0);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     PROJ4_Base.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PROJ4_Base_H
+#define HEADER_INCLUDED__PROJ4_Base_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include <projects.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	PROJ4_INTERFACE_SIMPLE	= 0,
+	PROJ4_INTERFACE_DIALOG
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class pj_proj4_EXPORT CPROJ4_Base : public CSG_Module
+{
+public:
+	CPROJ4_Base(int Interface, bool bInputList);
+
+
+protected:
+
+	bool				m_bInputList;
+
+
+	virtual bool		On_Execute					(void);
+	virtual bool		On_Execute_Conversion		(void)	= 0;
+
+	bool				Set_Inverse					(bool bOn = true);
+
+	CSG_String			Get_Proj_Name				(void);
+
+	bool				Get_Converted				(double &x, double &y);
+	bool				Get_Converted				(TSG_Point &Point);
+
+
+private:
+
+	bool				m_bInverse;
+
+	int					m_Interface;
+
+	PJ					*m_pPrjSrc, *m_pPrjDst;
+
+
+	bool				_Get_Projections			(CSG_String &sPrjSrc, CSG_String &sPrjDst);
+	bool				_Get_Projection				(CSG_String &sPrj, CSG_Parameters &P);
+
+	bool				_Init_Projection			(CSG_Parameters &P);
+	bool				_Init_Projection			(const CSG_String &sID, const CSG_String &sName, const CSG_String &sArgs);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PROJ4_Base_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,762 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    PROJ4_Grid.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "PROJ4_Grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPROJ4_Grid::CPROJ4_Grid(int Interface, bool bInputList)
+	: CPROJ4_Base(Interface, bInputList)
+{
+	CSG_Parameters	*pParameters;
+
+	//-----------------------------------------------------
+	Set_Name		(CSG_String::Format(SG_T("%s (%s, %s)"),
+		_TL("Proj.4"),
+		Interface == PROJ4_INTERFACE_DIALOG ? _TL("Dialog") : _TL("Command Line Arguments"),
+		m_bInputList ? _TL("List of Grids") : _TL("Grid")
+	));
+
+	Set_Author		(SG_T("O. Conrad (c) 2004-8"));
+
+	Set_Description	(_TW(
+		"Coordinate Transformation for Grids.\n"
+		"Based on the PROJ.4 Cartographic Projections library originally written by Gerald Evenden "
+		"and later continued by the United States Department of the Interior, Geological Survey (USGS).\n"
+		"<a target=\"_blank\" href=\"http://trac.osgeo.org/proj/\">Proj.4 Homepage</a>\n"
+	));
+
+
+	//-----------------------------------------------------
+	if( m_bInputList )
+	{
+		Parameters.Add_Grid_List(
+			Parameters("SOURCE_NODE"),
+			"SOURCE"		, _TL("Source"),
+			_TL(""),
+			PARAMETER_INPUT, false
+		);
+
+		Parameters.Add_Grid_List(
+			NULL,
+			"TARGET"		, _TL("Target"),
+			_TL(""),
+			PARAMETER_OUTPUT_OPTIONAL
+		);
+	}
+	else
+	{
+		Parameters.Add_Grid(
+			Parameters("SOURCE_NODE"),
+			"SOURCE"		, _TL("Source"),
+			_TL(""),
+			PARAMETER_INPUT
+		);
+
+		Parameters.Add_Grid_Output(
+			NULL,
+			"TARGET"		, _TL("Target"),
+			_TL("")
+		);
+
+		Parameters.Add_Shapes_Output(
+			NULL,
+			"SHAPES"		, _TL("Shapes"),
+			_TL("")
+		);
+	}
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "OUT_X"		, _TL("X Coordinates"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "OUT_Y"		, _TL("Y Coordinates"),
+		_TL("")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		Parameters("TARGET_NODE"),
+		"CREATE_XY"		, _TL("Create X/Y Grids"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Choice(
+		Parameters("TARGET_NODE"),
+		"TARGET_TYPE"	, _TL("Target"),
+		_TL(""),
+		CSG_String::Format(m_bInputList ? SG_T("%s|%s|%s|") : SG_T("%s|%s|%s|%s|%s|"),
+			_TL("user defined"),
+			_TL("automatic fit"),
+			_TL("grid system"),
+			_TL("grid"),
+			_TL("shapes")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		Parameters("TARGET_NODE")	, "INTERPOLATION"	, _TL("Interpolation"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Nearest Neigbhor"),
+			_TL("Bilinear Interpolation"),
+			_TL("Inverse Distance Interpolation"),
+			_TL("Bicubic Spline Interpolation"),
+			_TL("B-Spline Interpolation")
+		), 4
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_AUTOFIT"	, _TL("Automatic fit")	, _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "GRIDSIZE"	, _TL("Grid Size")	, _TL(""), PARAMETER_TYPE_Double, 10000.0, 0.0, true
+	);
+
+	pParameters->Add_Choice(
+		NULL, "AUTOEXTMODE"	, _TL("Fit Size")	, _TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Extent only (fast)"),
+			_TL("Check each point|")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_USER"		, _TL("User defined")		, _TL(""));
+
+	pParameters->Add_Value(
+		NULL, "XMIN"		, _TL("Left")		, _TL(""), PARAMETER_TYPE_Double
+	);
+	pParameters->Add_Value(
+		NULL, "XMAX"		, _TL("Right")		, _TL(""), PARAMETER_TYPE_Double
+	);
+	pParameters->Add_Value(
+		NULL, "YMIN"		, _TL("Bottom")		, _TL(""), PARAMETER_TYPE_Double
+	);
+	pParameters->Add_Value(
+		NULL, "YMAX"		, _TL("Top")		, _TL(""), PARAMETER_TYPE_Double
+	);
+
+	pParameters->Add_Value(
+		NULL, "SIZE"		, _TL("Grid Size")	, _TL(""), PARAMETER_TYPE_Double, 10000.0, 0.0, true
+	);
+
+	pParameters->Add_Info_Value(
+		NULL, "NX"			, _TL("Columns")	, _TL(""), PARAMETER_TYPE_Int
+	);
+	pParameters->Add_Info_Value(
+		NULL, "NY"			, _TL("Rows")		, _TL(""), PARAMETER_TYPE_Int
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_SYSTEM"	, _TL("Choose Grid Project"), _TL(""));
+
+	pParameters->Add_Grid_System(
+		NULL, "SYSTEM"		, _TL("System")		, _TL("")
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_GRID"		, _TL("Choose Grid")		, _TL(""));
+
+	pParameters->Add_Grid(
+		NULL, "GRID"		, _TL("Grid")		, _TL(""), PARAMETER_INPUT	, false
+	);
+
+
+	//-----------------------------------------------------
+	pParameters	= Add_Parameters("GET_SHAPES"	, _TL("Choose Shapes")		, _TL(""));
+
+	pParameters->Add_Shapes(
+		NULL, "SHAPES"		,_TL("Shapes")		, _TL(""), PARAMETER_OUTPUT	, SHAPE_TYPE_Point
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::On_Execute_Conversion(void)
+{
+	CSG_Grid_System	System;
+
+	m_Interpolation	= Parameters("INTERPOLATION")->asInt();
+
+	//-----------------------------------------------------
+	if( m_bInputList )
+	{
+		CSG_Parameter_Grid_List	*pSources	= Parameters("SOURCE")->asGridList();
+		CSG_Parameter_Grid_List	*pTargets	= Parameters("TARGET")->asGridList();
+
+		if( pSources->Get_Count() > 0 && Get_Target_System(pSources->asGrid(0)->Get_System(), System) )
+		{
+			return( Set_Grids(System, pSources, pTargets) );
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		CSG_Grid	*pSource, *pTarget;
+
+		pSource		= Parameters("SOURCE")->asGrid();
+
+		switch( Parameters("TARGET_TYPE")->asInt() )
+		{
+		default:	// create new grid...
+			if( Get_Target_System(pSource->Get_System(), System) )
+			{
+				Parameters("TARGET")->Set_Value(pTarget	= SG_Create_Grid(System, m_Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float));
+
+				return( Set_Grid(pSource, pTarget) );
+			}
+			break;
+
+		case 3:		// select existing grid...
+			if( Dlg_Parameters("GET_GRID") )
+			{
+				Parameters("TARGET")->Set_Value(pTarget	= Get_Parameters("GET_GRID")->Get_Parameter("GRID")->asGrid());
+
+				return( Set_Grid(pSource, pTarget) );
+			}
+			break;
+
+		case 4:		// create grid points as shapes...
+			if( Dlg_Parameters("GET_SHAPES") )
+			{
+				CSG_Shapes	*pShapes;
+
+				Parameters("SHAPES")->Set_Value(pShapes	= Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->asShapes());
+
+				return( Set_Shapes(pSource, pShapes) );
+			}
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Set_Grids(const CSG_Grid_System &System, CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets)
+{
+	if( pSources && pSources->Get_Count() > 0 && pTargets && System.is_Valid() && Set_Inverse() )
+	{
+		int			x, y, i;
+		double		z;
+		TSG_Point	Pt_Source, Pt_Target;
+		CSG_Grid	*pX, *pY;
+
+		Init_XY(System, &pX, &pY);
+
+		pTargets->Del_Items();
+
+		for(i=0; i<pSources->Get_Count(); i++)
+		{
+			pTargets->Add_Item(SG_Create_Grid(System, pSources->asGrid(i)->Get_Type()));
+
+			Init_Target(pSources->asGrid(i), pTargets->asGrid(i));
+		}
+
+		//-------------------------------------------------
+		for(y=0, Pt_Target.y=System.Get_YMin(); y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y++, Pt_Target.y+=System.Get_Cellsize())
+		{
+			for(x=0, Pt_Target.x=System.Get_XMin(); x<System.Get_NX(); x++, Pt_Target.x+=System.Get_Cellsize())
+			{
+				Pt_Source	= Pt_Target;
+
+				if( Get_Converted(Pt_Source) )
+				{
+					if( pX )	pX->Set_Value(x, y, Pt_Source.x);
+					if( pY )	pY->Set_Value(x, y, Pt_Source.y);
+
+					for(i=0; i<pSources->Get_Count(); i++)
+					{
+						if( pSources->asGrid(i)->Get_Value(Pt_Source, z, m_Interpolation) )
+						{
+							pTargets->asGrid(i)->Set_Value(x, y, z);
+						}
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Set_Grid(CSG_Grid *pSource, CSG_Grid *pTarget)
+{
+	if( pSource && pTarget && Set_Inverse() )
+	{
+		int			x, y;
+		double		z;
+		TSG_Point	Pt_Source, Pt_Target;
+		CSG_Grid	*pX, *pY;
+
+		Init_XY(pTarget->Get_System(), &pX, &pY);
+
+		Init_Target(pSource, pTarget);
+
+		//-------------------------------------------------
+		for(y=0, Pt_Target.y=pTarget->Get_YMin(); y<pTarget->Get_NY() && Set_Progress(y, pTarget->Get_NY()); y++, Pt_Target.y+=pTarget->Get_Cellsize())
+		{
+			for(x=0, Pt_Target.x=pTarget->Get_XMin(); x<pTarget->Get_NX(); x++, Pt_Target.x+=pTarget->Get_Cellsize())
+			{
+				Pt_Source	= Pt_Target;
+
+				if( Get_Converted(Pt_Source) )
+				{
+					if( pX )	pX->Set_Value(x, y, Pt_Source.x);
+					if( pY )	pY->Set_Value(x, y, Pt_Source.y);
+
+					if( pSource->Get_Value(Pt_Source, z, m_Interpolation) )
+					{
+						pTarget->Set_Value(x, y, z);
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Set_Shapes(CSG_Grid *pSource, CSG_Shapes *pTarget)
+{
+	int			x, y;
+	TSG_Point	Pt_Source, Pt_Target;
+	CSG_Shape	*pShape;
+
+	if( pSource && pTarget )
+	{
+		pTarget->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pSource->Get_Name(), Get_Proj_Name().c_str()));
+		pTarget->Add_Field("Z", SG_DATATYPE_Double);
+
+		for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=pSource->Get_Cellsize())
+		{
+			for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize())
+			{
+				if( !pSource->is_NoData(x, y) )
+				{
+					Pt_Target	= Pt_Source;
+
+					if( Get_Converted(Pt_Target) )
+					{
+						pShape	= pTarget->Add_Shape();
+						pShape->Add_Point(Pt_Target);
+						pShape->Set_Value(0, pSource->asDouble(x, y));
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Init_XY(const CSG_Grid_System &System, CSG_Grid **ppX, CSG_Grid **ppY)
+{
+	if( Parameters("CREATE_XY")->asBool() )
+	{
+		Parameters("OUT_X")->Set_Value(*ppX	= SG_Create_Grid(System, SG_DATATYPE_Float));
+		(*ppX)->Assign_NoData();
+		(*ppX)->Set_Name(_TL("X-Coordinate"));
+
+		Parameters("OUT_Y")->Set_Value(*ppY	= SG_Create_Grid(System, SG_DATATYPE_Float));
+		(*ppY)->Assign_NoData();
+		(*ppY)->Set_Name(_TL("Y-Coordinate"));
+
+		return( true );
+	}
+
+	*ppX	= *ppY	= NULL;
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Init_Target(CSG_Grid *pSource, CSG_Grid *pTarget)
+{
+	if( pSource && pTarget )
+	{
+		pTarget->Set_NoData_Value_Range(pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue());
+		pTarget->Set_ZFactor(pSource->Get_ZFactor());
+		pTarget->Set_Name	(CSG_String::Format(SG_T("%s [%s]"), pSource->Get_Name(), Get_Proj_Name().c_str()));
+		pTarget->Set_Unit	(pSource->Get_Unit());
+		pTarget->Assign_NoData();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CPROJ4_Grid::Get_MinMax(TSG_Rect &r, TSG_Point p)
+{
+	if( Get_Converted(p) )
+	{
+		if( r.xMin > r.xMax )
+		{
+			r.xMin	= r.xMax	= p.x;
+		}
+		else if( r.xMin > p.x )
+		{
+			r.xMin	= p.x;
+		}
+		else if( r.xMax < p.x )
+		{
+			r.xMax	= p.x;
+		}
+
+		if( r.yMin > r.yMax )
+		{
+			r.yMin	= r.yMax	= p.y;
+		}
+		else if( r.yMin > p.y )
+		{
+			r.yMin	= p.y;
+		}
+		else if( r.yMax < p.y )
+		{
+			r.yMax	= p.y;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Get_Target_System(const CSG_Grid_System &Source, CSG_Grid_System &Target)
+{
+	switch( Parameters("TARGET_TYPE")->asInt() )
+	{
+	case 0:	// create new user defined grid...
+		return( Get_Target_Userdef(Source, Target) );
+
+	case 1:	// create new with chosen cell size and fitted extent...
+		return( Get_Target_Autofit(Source, Target) );
+
+	case 2:	// select grid system...
+		if( Dlg_Parameters("GET_SYSTEM") )
+		{
+			Target	= *Get_Parameters("GET_SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System();
+
+			return( true );
+		}
+		break;
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Get_Target_Userdef(const CSG_Grid_System &Source, CSG_Grid_System &Target)
+{
+	int			x, y;
+	TSG_Point	p;
+	TSG_Rect	r;
+
+	r.xMin	= r.yMin	= 1.0;	r.xMax	= r.yMax	= 0.0;
+
+	//-------------------------------------------------
+	for(y=0, p.y=Source.Get_YMin(); y<Source.Get_NY(); y++, p.y+=Source.Get_Cellsize())
+	{
+		p.x	= Source.Get_XMin();	Get_MinMax(r, p);
+		p.x	= Source.Get_XMax();	Get_MinMax(r, p);
+	}
+
+	for(x=0, p.x=Source.Get_XMin(); x<Source.Get_NX(); x++, p.x+=Source.Get_Cellsize())
+	{
+		p.y	= Source.Get_YMin();	Get_MinMax(r, p);
+		p.y	= Source.Get_YMax();	Get_MinMax(r, p);
+	}
+
+	//-------------------------------------------------
+	if( r.xMin < r.xMax && r.yMin < r.yMax )
+	{
+		CSG_Parameters	*pParameters	= Get_Parameters("GET_USER");
+		double			Cellsize		= (r.yMax - r.yMin) / Source.Get_NY();
+
+		pParameters->Get_Parameter("XMIN")	->Set_Value(r.xMin);
+		pParameters->Get_Parameter("XMAX")	->Set_Value(r.xMax);
+		pParameters->Get_Parameter("YMIN")	->Set_Value(r.yMin);
+		pParameters->Get_Parameter("YMAX")	->Set_Value(r.yMax);
+		pParameters->Get_Parameter("SIZE")	->Set_Value(Cellsize);
+		pParameters->Get_Parameter("NX")	->Set_Value(1 + (int)((r.xMax - r.xMin) / Cellsize));
+		pParameters->Get_Parameter("NY")	->Set_Value(1 + (int)((r.yMax - r.yMin) / Cellsize));
+
+		if( Dlg_Parameters("GET_USER") )
+		{
+			Target.Assign(
+				pParameters->Get_Parameter("SIZE")	->asDouble(),
+				pParameters->Get_Parameter("XMIN")	->asDouble(),
+				pParameters->Get_Parameter("YMIN")	->asDouble(),
+				pParameters->Get_Parameter("NX")	->asInt(),
+				pParameters->Get_Parameter("NY")	->asInt()
+			);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CPROJ4_Grid::Get_Target_Autofit(const CSG_Grid_System &Source, CSG_Grid_System &Target)
+{
+	int			x, y;
+	TSG_Point	p;
+	TSG_Rect	r;
+
+	double	Cellsize	= Get_Parameters("GET_AUTOFIT")->Get_Parameter("GRIDSIZE")		->asDouble();
+	int		AutoExtMode	= Get_Parameters("GET_AUTOFIT")->Get_Parameter("AUTOEXTMODE")	->asInt();
+
+	r.xMin	= r.yMin	= 1.0;	r.xMax	= r.yMax	= 0.0;
+
+	//---------------------------------------------
+	switch( AutoExtMode )
+	{
+	case 0:	default:
+		for(y=0, p.y=Source.Get_YMin(); y<Source.Get_NY(); y++, p.y+=Source.Get_Cellsize())
+		{
+			p.x	= Source.Get_XMin();	Get_MinMax(r, p);
+			p.x	= Source.Get_XMax();	Get_MinMax(r, p);
+		}
+
+		for(x=0, p.x=Source.Get_XMin(); x<Source.Get_NX(); x++, p.x+=Source.Get_Cellsize())
+		{
+			p.y	= Source.Get_YMin();	Get_MinMax(r, p);
+			p.y	= Source.Get_YMax();	Get_MinMax(r, p);
+		}
+
+		break;
+
+	//---------------------------------------------
+	case 1:
+		for(y=0, p.y=Source.Get_YMin(); y<Source.Get_NY() && Set_Progress(y, Source.Get_NY()); y++, p.y+=Source.Get_Cellsize())
+		{
+			for(x=0, p.x=Source.Get_XMin(); x<Source.Get_NX(); x++, p.x+=Source.Get_Cellsize())
+			{
+				Get_MinMax(r, p);
+			}
+		}
+
+		break;
+	}
+
+	//---------------------------------------------
+	if( is_Progress() && r.xMin < r.xMax && r.yMin < r.yMax )
+	{
+		Target.Assign(
+			Cellsize,
+			r.xMin, r.yMin,
+			1 + (int)((r.xMax - r.xMin) / Cellsize),
+			1 + (int)((r.yMax - r.yMin) / Cellsize)
+		);
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+//---------------------------------------------------------
+int CPROJ4_Grid::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	double	xMin, xMax, yMin, yMax, Cellsize;
+
+	if( !SG_STR_CMP(pParameters->Get_Identifier(), SG_T("GET_USER")) )
+	{
+		xMin		= pParameters->Get_Parameter("XMIN")->asDouble();
+		xMax		= pParameters->Get_Parameter("XMAX")->asDouble();
+		yMin		= pParameters->Get_Parameter("YMIN")->asDouble();
+		yMax		= pParameters->Get_Parameter("YMAX")->asDouble();
+		Cellsize	= pParameters->Get_Parameter("SIZE")->asDouble();
+
+		if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("SIZE")) )
+		{
+			pParameters->Get_Parameter("XMAX")->Set_Value((xMax = xMin + ((int)((xMax - xMin) / Cellsize)) * Cellsize));
+			pParameters->Get_Parameter("YMAX")->Set_Value((yMax = yMin + ((int)((yMax - yMin) / Cellsize)) * Cellsize));
+		}
+		else 
+		{
+			if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMIN")) )
+			{
+				if( xMin >= xMax )
+				{
+					xMin	= xMax - pParameters->Get_Parameter("NX")->asInt() * Cellsize;
+					pParameter->Set_Value(xMin);
+				}
+
+				pParameters->Get_Parameter("XMAX")->Set_Value(xMin + ((int)((xMax - xMin) / Cellsize)) * Cellsize);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("XMAX")) )
+			{
+				if( xMin >= xMax )
+				{
+					xMax	= xMin + pParameters->Get_Parameter("NX")->asInt() * Cellsize;
+					pParameter->Set_Value(xMax);
+				}
+
+				pParameters->Get_Parameter("XMIN")->Set_Value(xMax - ((int)((xMax - xMin) / Cellsize)) * Cellsize);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMIN")) )
+			{
+				if( yMin >= yMax )
+				{
+					yMin	= yMax - pParameters->Get_Parameter("NY")->asInt() * Cellsize;
+					pParameter->Set_Value(yMin);
+				}
+
+				pParameters->Get_Parameter("YMAX")->Set_Value(yMin + ((int)((yMax - yMin) / Cellsize)) * Cellsize);
+			}
+			else if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("YMAX")) )
+			{
+				if( yMin >= yMax )
+				{
+					yMax	= yMin + pParameters->Get_Parameter("NY")->asInt() * Cellsize;
+					pParameter->Set_Value(yMax);
+				}
+
+				pParameters->Get_Parameter("YMIN")->Set_Value(yMax - ((int)((yMax - yMin) / Cellsize)) * Cellsize);
+			}
+		}
+
+		pParameters->Get_Parameter("NX")->Set_Value(1 + (int)((xMax - xMin) / Cellsize));
+		pParameters->Get_Parameter("NY")->Set_Value(1 + (int)((yMax - yMin) / Cellsize));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,117 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     PROJ4_Grid.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PROJ4_Grid_H
+#define HEADER_INCLUDED__PROJ4_Grid_H
+
+//---------------------------------------------------------
+#include "PROJ4_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class pj_proj4_EXPORT CPROJ4_Grid : public CPROJ4_Base
+{
+public:
+	CPROJ4_Grid(int Interface, bool bInputList);
+
+	virtual const SG_Char *	Get_MenuPath			(void)	{	return( _TL("R:Grid") );	}
+
+
+protected:
+
+	virtual bool			On_Execute_Conversion	(void);
+
+	virtual int				On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+
+private:
+
+	int						m_Interpolation;
+
+
+	bool					Set_Grids				(const CSG_Grid_System &System, CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets);
+	bool					Set_Grid				(CSG_Grid *pSource, CSG_Grid   *pTarget);
+	bool					Set_Shapes				(CSG_Grid *pSource, CSG_Shapes *pTarget);
+
+	bool					Init_XY					(const CSG_Grid_System &System, CSG_Grid **ppX, CSG_Grid **ppY);
+	bool					Init_Target				(CSG_Grid *pSource, CSG_Grid *pTarget);
+
+	bool					Get_MinMax				(TSG_Rect &r, TSG_Point p);
+	bool					Get_Target_System		(const CSG_Grid_System &Source, CSG_Grid_System &Target);
+	bool					Get_Target_Userdef		(const CSG_Grid_System &Source, CSG_Grid_System &Target);
+	bool					Get_Target_Autofit		(const CSG_Grid_System &Source, CSG_Grid_System &Target);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PROJ4_Grid_H

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,259 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   PROJ4_Shapes.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "PROJ4_Shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPROJ4_Shapes::CPROJ4_Shapes(int Interface, bool bInputList)
+	: CPROJ4_Base(Interface, bInputList)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name		(CSG_String::Format(SG_T("%s (%s, %s)"),
+		_TL("Proj.4"),
+		Interface == PROJ4_INTERFACE_DIALOG ? _TL("Dialog") : _TL("Command Line Arguments"),
+		m_bInputList ? _TL("List of Shapes Layers") : _TL("Shapes")
+	));
+
+	Set_Author		(SG_T("O. Conrad (c) 2004-8"));
+
+	Set_Description	(_TW(
+		"Coordinate Transformation for Shapes.\n"
+		"Based on the PROJ.4 Cartographic Projections library originally written by Gerald Evenden "
+		"and later continued by the United States Department of the Interior, Geological Survey (USGS).\n"
+		"<a target=\"_blank\" href=\"http://trac.osgeo.org/proj/\">Proj.4 Homepage</a>\n"
+	));
+
+
+	//-----------------------------------------------------
+	// 2. In-/Output...
+
+	if( m_bInputList )
+	{
+		Parameters.Add_Shapes_List(
+			Parameters("SOURCE_NODE")	, "SOURCE", _TL("Source"),
+			_TL(""),
+			PARAMETER_INPUT
+		);
+
+		Parameters.Add_Shapes_List(
+			NULL						, "TARGET", _TL("Target"),
+			_TL(""),
+			PARAMETER_OUTPUT_OPTIONAL
+		);
+	}
+	else
+	{
+		Parameters.Add_Shapes(
+			Parameters("SOURCE_NODE")	, "SOURCE", _TL("Source"),
+			_TL(""),
+			PARAMETER_INPUT
+		);
+
+		Parameters.Add_Shapes(
+			Parameters("TARGET_NODE")	, "TARGET", _TL("Target"),
+			_TL(""),
+			PARAMETER_OUTPUT
+		);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Shapes::On_Execute_Conversion(void)
+{
+	bool	bResult	= false;
+
+	CSG_Shapes	*pSource, *pTarget;
+
+	//-----------------------------------------------------
+	if( m_bInputList )
+	{
+		CSG_Parameter_Shapes_List	*pSources, *pTargets;
+
+		pSources	= Parameters("SOURCE")->asShapesList();
+		pTargets	= Parameters("TARGET")->asShapesList();
+
+		pTargets->Del_Items();
+
+		for(int i=0; i<pSources->Get_Count() && Process_Get_Okay(false); i++)
+		{
+			pSource	= pSources->asShapes(i);
+			pTarget	= SG_Create_Shapes();
+
+			if( _Get_Conversion(pSource, pTarget) )
+			{
+				bResult	= true;
+				pTargets->Add_Item(pTarget);
+			}
+			else
+			{
+				delete( pTarget );
+			}
+		}
+	}
+	else
+	{
+		bool	bCopy;
+
+		pSource	= Parameters("SOURCE")->asShapes();
+		pTarget	= Parameters("TARGET")->asShapes();
+
+		if( (bCopy = pSource == pTarget) == true )
+		{
+			pTarget	= SG_Create_Shapes();
+		}
+
+		//-------------------------------------------------
+		bResult	= _Get_Conversion(pSource, pTarget);
+
+		//-------------------------------------------------
+		if( bCopy )
+		{
+			pSource->Assign(pTarget);
+			delete( pTarget );
+		}
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPROJ4_Shapes::_Get_Conversion(CSG_Shapes *pSource, CSG_Shapes *pTarget)
+{
+	if( pSource && pSource->is_Valid() && pTarget )
+	{
+		int		nDropped	= 0;
+
+		Process_Set_Text(CSG_String::Format(SG_T("%s: %s"), _TL("Processing"), pSource->Get_Name()));
+
+		pTarget->Create(pSource->Get_Type(), CSG_String::Format(SG_T("%s [%s]"), pSource->Get_Name(), Get_Proj_Name().c_str()), pSource);
+
+		for(int iShape=0; iShape<pSource->Get_Count() && Set_Progress(iShape, pSource->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape_Source	= pSource->Get_Shape(iShape);
+			CSG_Shape	*pShape_Target	= pTarget->Add_Shape(pShape_Source, SHAPE_COPY_ATTR);
+
+			bool	bDropped	= false;
+
+			for(int iPart=0; iPart<pShape_Source->Get_Part_Count() && !bDropped; iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape_Source->Get_Point_Count(iPart) && !bDropped; iPoint++)
+				{
+					TSG_Point	Point	= pShape_Source->Get_Point(iPoint, iPart);
+
+					if( Get_Converted(Point.x, Point.y) )
+					{
+						pShape_Target->Add_Point(Point.x, Point.y, iPart);
+					}
+					else
+					{
+						bDropped	= true;
+					}
+				}
+			}
+
+			if( bDropped )
+			{
+				nDropped++;
+				pTarget->Del_Shape(pShape_Target);
+			}
+		}
+
+		if( nDropped > 0 )
+		{
+			Message_Add(CSG_String::Format(SG_T("%d %s"), nDropped, _TL("shapes have been dropped")));
+		}
+
+		return( pTarget->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_projection/pj_proj4/pj_proj4/PROJ4_Shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Projection_Proj4                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    PROJ4_Shapes.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__PROJ4_Shapes_H
+#define HEADER_INCLUDED__PROJ4_Shapes_H
+
+//---------------------------------------------------------
+#include "PROJ4_Base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class pj_proj4_EXPORT CPROJ4_Shapes : public CPROJ4_Base
+{
+public:
+	CPROJ4_Shapes(int Interface, bool bInputList);
+
+	virtual const SG_Char *	Get_MenuPath			(void)	{	return( _TL("R:Shapes") );	}
+
+
+protected:
+
+	virtual bool			On_Execute_Conversion	(void);
+
+
+private:
+
+	bool					_Get_Conversion			(CSG_Shapes *pSource, CSG_Shapes *pTarget);
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__PROJ4_Shapes_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,146 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Bifurcation.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Bifurcation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CBifurcation::CBifurcation(void)
+{
+	Set_Name(_TL("Bifurcation"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW("Feigenbaum's Bifurcation"));
+
+	Parameters.Add_Table(	NULL, "TABLE"		, _TL("Output")				, _TL(""), PARAMETER_OUTPUT);
+
+	Parameters.Add_Value(	NULL, "ITERATIONS"	, _TL("Value Count")		, _TL(""), PARAMETER_TYPE_Int, 100);
+	Parameters.Add_Value(	NULL, "NVALUES"		, _TL("Value Count")		, _TL("Number of the last x Iteration to be plotted."), PARAMETER_TYPE_Int, 8);
+	Parameters.Add_Value(	NULL, "SEED"		, _TL("Seed Value")			, _TL(""), PARAMETER_TYPE_Double	, 0.66, 0, true, 1.0, true);
+	Parameters.Add_Range(	NULL, "RANGE"		, _TL("Range")				, _TL(""), 1.0, 4.0, 0.0, true, 4.0, true);
+	Parameters.Add_Value(	NULL, "STEP"		, _TL("Number of Steps")	, _TL(""), PARAMETER_TYPE_Int		, 1000, 2, true);
+
+}
+
+//---------------------------------------------------------
+CBifurcation::~CBifurcation(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CBifurcation::On_Execute(void)
+{
+	int					i;
+	double				p, r, dr, max, min, seed, nValues, nPreIterations;
+	CSG_Table_Record		*pRecord;
+	CSG_Table				*pTable;
+
+	nPreIterations	= Parameters("ITERATIONS")->asInt();
+	nValues			= Parameters("NVALUES")->asInt();
+	seed			= Parameters("SEED")->asDouble();
+	min				= Parameters("RANGE")->asRange()->Get_LoVal();
+	max				= Parameters("RANGE")->asRange()->Get_HiVal();
+	dr				= (max - min) / 1000.0;
+
+	pTable			= Parameters("TABLE")->asTable();
+	pTable->Destroy();
+	pTable->Set_Name(_TL("Feigenbaum's Bifurcation"));
+
+	pTable->Add_Field("Growth"	, SG_DATATYPE_Double);
+
+	for(i=0; i<nValues; i++)
+	{
+		pTable->Add_Field(CSG_String::Format(SG_T("VALUE_%d"), i + 1), SG_DATATYPE_Double);
+	}
+
+	for(r=min; r<=max; r+=dr)
+	{
+		pRecord	= pTable->Add_Record();
+		pRecord->Set_Value(0, r);
+
+		p		= seed;
+
+		for(i=0; i<nPreIterations; i++)
+		{
+			p		= r * p * (1.0 - p);
+		}
+
+		for(i=0; i<nValues; i++)
+		{
+			p	= r * p * (1.0 - p);
+			pRecord->Set_Value(i + 1, p);
+		}
+	}
+
+	return( true );
+}

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Bifurcation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Bifurcation.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__BIFURCATION_H
+#define HEADER_INCLUDED__BIFURCATION_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CBifurcation : public CSG_Module  
+{
+public:
+	CBifurcation(void);
+	virtual ~CBifurcation(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__BIFURCATION_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,249 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Gaussian_Landscapes.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Gaussian_Landscapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define RANDOM(x)		(rand() % x)
+#define RANDOMIZE()		(srand((unsigned int)time(NULL)))
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGaussian_Landscapes::CGaussian_Landscapes(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Gaussian Landscapes"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Generates Gaussian landscapes.\n\n"
+		"References:\n"
+		"- Halling, H., Moeller, R. (1995): 'Mathematik fuers Auge', Heidelberg, 144p.\n"
+		"- Mandelbrot, B.B. (1983): 'The Fractal Geometry of Nature', New York, 490p.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NX"		, _TL("Width (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NY"		, _TL("Height (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "H"		, _TL("Roughness/Smoothness"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.75, 0.0, true, 1.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Simple"),
+			_TL("Flattening")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "M"		, _TL("Flattening"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 2.0
+	);
+}
+
+//---------------------------------------------------------
+CGaussian_Landscapes::~CGaussian_Landscapes(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGaussian_Landscapes::On_Execute(void)
+{
+	int		nx, ny, n;
+	double	h, s, r;
+
+	//-----------------------------------------------------
+	nx			= Parameters("NX")->asInt();
+	ny			= Parameters("NY")->asInt();
+
+	m_pGrid		= SG_Create_Grid(SG_DATATYPE_Float, nx, ny, 1.0, 0.0, 0.0);
+	m_pGrid->Set_Name(_TL("Gaussian Landscape"));
+	m_pGrid->Assign_NoData();
+	Parameters("GRID")->Set_Value(m_pGrid);
+
+	m_Method	= Parameters("METHOD")	->asInt();
+	m_M			= Parameters("M")		->asDouble();
+
+	//-----------------------------------------------------
+	nx			= nx > ny ? nx : ny;
+	ny			= 1;
+	do	{	n	= (int)pow(2.0, ny++);	}	while( n < nx );
+
+	h			= Parameters("H")		->asDouble();
+	r			= 1.0 / pow(2.0, h);
+	s			= n * r;
+
+	//-----------------------------------------------------
+	Set_Values(0, 0, n, n, 0.0, 0.0, 0.0, 0.0, s, r);
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CGaussian_Landscapes::Set_Value(int x, int y, double Value)
+{
+	if( m_pGrid->is_InGrid(x, y, false) )
+	{
+		switch( m_Method )
+		{
+		case 0:	default:
+			m_pGrid->Set_Value(x, y, Value);
+			break;
+
+		case 1:
+			m_pGrid->Set_Value(x, y, pow(Value, m_M));
+			break;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CGaussian_Landscapes::Set_Values(int x_0, int y_0, int x_1, int y_1, double z_00, double z_10, double z_11, double z_01, double s, double r)
+{
+	int		x_n, y_n;
+	double	z_n, z_n1, z_n2, z_n3, z_n4;
+
+	//-----------------------------------------------------
+	x_n		= (x_0 + x_1) / 2;
+	y_n		= (y_0 + y_1) / 2;
+	z_n		= (z_00 + z_10 + z_11 + z_01) / 4.0 + s * (double)(RANDOM(17) - 8) / 8.0;
+
+	Set_Value(x_n, y_n, z_n);
+
+	//-----------------------------------------------------
+	if( x_0 != x_n && x_n != x_1 )
+	{
+		z_n1	= (z_00 + z_10) / 2.0;
+		z_n2	= (z_10 + z_11) / 2.0;
+		z_n3	= (z_11 + z_01) / 2.0;
+		z_n4	= (z_01 + z_00) / 2.0;
+
+		s		*= r;
+
+		Set_Values(x_n, y_0, x_1, y_n, z_n1, z_10, z_n2, z_n , s, r);
+		Set_Values(x_0, y_0, x_n, y_n, z_00, z_n1, z_n , z_n4, s, r);
+		Set_Values(x_n, y_n, x_1, y_1, z_n , z_n2, z_11, z_n3, s, r);
+		Set_Values(x_0, y_n, x_n, y_1, z_n4, z_n , z_n3, z_01, s, r);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Gaussian_Landscapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,109 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Gaussian_Landscapes.h                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Gaussian_Landscapes_H
+#define HEADER_INCLUDED__Gaussian_Landscapes_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGaussian_Landscapes : public CSG_Module
+{
+public:
+	CGaussian_Landscapes(void);
+	virtual ~CGaussian_Landscapes(void);
+
+
+protected:
+
+	virtual bool				On_Execute	(void);
+
+
+private:
+
+	int							m_Method;
+
+	double						m_M;
+
+	CSG_Grid						*m_pGrid;
+
+
+	void						Set_Value	(int x, int y, double Value);
+	void						Set_Values	(int x_0, int y_0, int x_1, int y_1, double z_00, double z_10, double z_11, double z_01, double s, double r);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Gaussian_Landscapes_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,285 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_FractalDimension.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_FractalDimension.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_FractalDimension::CGrid_FractalDimension(void)
+{
+	Set_Name(_TL("Fractal Dimension of Grid Surface"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates surface areas for increasing mesh sizes.")
+	);
+
+	Parameters.Add_Grid(	NULL, "INPUT"	, _TL("Input")		, _TL(""), PARAMETER_INPUT);
+	Parameters.Add_Table(	NULL, "RESULT"	, _TL("Result")		, _TL(""), PARAMETER_OUTPUT);
+}
+
+//---------------------------------------------------------
+CGrid_FractalDimension::~CGrid_FractalDimension(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_FractalDimension::On_Execute(void)
+{
+	int				i;
+	CSG_Table			*pTable;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	pGrid		= Parameters("INPUT")	->asGrid();
+	pTable		= Parameters("RESULT")	->asTable();
+
+	dimCount	= pGrid->Get_NX() > pGrid->Get_NY() ? pGrid->Get_NX() - 1 : pGrid->Get_NY() - 1;
+
+	//-----------------------------------------------------
+	if( dimCount > 0 )
+	{
+		dimAreas	= (double *)SG_Calloc(dimCount, sizeof(double));
+
+		for(i=0; i<dimCount && Set_Progress(i, dimCount); i++)
+		{
+			Get_Surface(i);
+		}
+
+		//-------------------------------------------------
+		pTable->Destroy();
+		pTable->Set_Name(_TL("Fractal Dimension"));
+
+		pTable->Add_Field(_TL("Class")		, SG_DATATYPE_Int);
+		pTable->Add_Field(_TL("Scale")		, SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Area")		, SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Ln(Area)")	, SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Dim01")		, SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Dim02")		, SG_DATATYPE_Double);
+
+		for(i=0; i<dimCount-1; i++)
+		{
+			pRecord	= pTable->Add_Record();
+
+			pRecord->Set_Value(0,  i + 1);
+			pRecord->Set_Value(1, (i + 1) * Get_Cellsize());
+			pRecord->Set_Value(2,     dimAreas[i]);
+			pRecord->Set_Value(3, log(dimAreas[i]));
+			pRecord->Set_Value(4,     dimAreas[i]  -     dimAreas[i + 1]);
+			pRecord->Set_Value(5, log(dimAreas[i]) - log(dimAreas[i + 1]));
+		}
+
+		//-------------------------------------------------
+		SG_Free(dimAreas);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CGrid_FractalDimension::Get_Surface(int Step)
+{
+	int		ya, yb, xStep, yStep;
+
+	xStep	= Step + 1;
+	yStep	= Step + 1;
+
+	for(ya=0, yb=yStep; yb<Get_NY(); ya+=yStep, yb+=yStep)
+	{
+		Get_SurfaceRow(Step, xStep, yStep, ya, yb);
+	}
+
+	//---Rest----------------------------------------------
+	if( Get_NY() % yStep )
+	{
+		yStep	= Get_NY() % yStep;
+	}
+
+	Get_SurfaceRow(Step, xStep, yStep, ya, Get_NY() - 1);
+}
+
+//---------------------------------------------------------
+void CGrid_FractalDimension::Get_SurfaceRow(int Step, int xStep, int yStep, int ya, int yb)
+{
+	int		xa, xb;
+	double	xdist, ydist;
+
+	xdist	= xStep * Get_Cellsize();
+	ydist	= yStep * Get_Cellsize();
+
+	if( xStep == yStep )
+	{
+		for(xa=0, xb=xStep; xb<Get_NX(); xa+=xStep, xb+=xStep)
+		{
+			dimAreas[Step]	+= Get_Area(xdist,
+								pGrid->asDouble(xa, ya), pGrid->asDouble(xb, ya),
+								pGrid->asDouble(xb, yb), pGrid->asDouble(xa, yb)
+							);
+		}
+	}
+	else
+	{
+		for(xa=0, xb=xStep; xb<Get_NX(); xa+=xStep, xb+=xStep)
+		{
+			dimAreas[Step]	+= Get_Area(xdist, ydist,
+								pGrid->asDouble(xa, ya), pGrid->asDouble(xb, ya),
+								pGrid->asDouble(xb, yb), pGrid->asDouble(xa, yb)
+							);
+		}
+	}
+
+	//---Rest----------------------------------------------
+	if( Get_NX() % xStep )
+	{
+		xStep	= Get_NX() % xStep;
+	}
+
+	dimAreas[Step]	+= Get_Area(xStep * Get_Cellsize(), ydist,
+						pGrid->asDouble(xa          , ya), pGrid->asDouble(Get_NX() - 1, ya),
+						pGrid->asDouble(Get_NX() - 1, yb), pGrid->asDouble(xa          , yb)
+					);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CGrid_FractalDimension::Get_Distance(double za, double zb, double dist)
+{
+	za	= fabs(za - zb);
+
+	return( sqrt(za*za + dist*dist) );
+}
+
+//---------------------------------------------------------
+double CGrid_FractalDimension::Get_Area(double dist, double z1, double z2, double z3, double z4)
+{
+	int		i;
+	double	z[4]	= { z1, z2, z3, z4 },
+			Area	= 0,
+			mz		= (z[0] + z[1] + z[2] + z[3]) / 4,
+			mdist	= dist * sqrt(2.0) / 2.0,
+			ab, am, bm, am2, k;
+
+	bm		= Get_Distance(z[3],mz,mdist);
+
+	for(i=0; i<4; i++)
+	{
+		am		= bm;
+		bm		= Get_Distance(z[i], mz, mdist);
+		ab		= Get_Distance(z[i], z[(i+3)%4], dist);
+		am2		= am*am;
+		k		= (am2 - bm*bm + ab*ab) / (2*ab);
+		Area	+= ab * sqrt(am2 - k*k) / 2;
+	}
+
+	return( Area );
+}
+
+//---------------------------------------------------------
+double CGrid_FractalDimension::Get_Area(double xdist, double ydist, double z1, double z2, double z3, double z4)
+{
+	int		i;
+	double	z[4]	= { z1, z2, z3, z4 },
+			Area	= 0,
+			mz		= (z[0] + z[1] + z[2] + z[3]) / 4,
+			mdist	= sqrt(xdist*xdist + ydist*ydist) / 2,
+			ab, am, bm, am2, k;
+
+	bm		= Get_Distance(z[3],mz,mdist);
+
+	for(i=0; i<4; i++)
+	{
+		am		= bm;
+		bm		= Get_Distance(z[i],mz,mdist);
+		ab		= Get_Distance(z[i],z[(i+3)%4],i%2 ? xdist : ydist);
+		am2		= am*am;
+		k		= (am2 - bm*bm + ab*ab) / (2*ab);
+		Area	+= ab * sqrt(am2 - k*k) / 2;
+	}
+
+	return(Area);
+}

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Grid_FractalDimension.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,91 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_FractalDimension.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+#ifndef HEADER_INCLUDED__GC_MEASUREFRACTDIM_H
+#define HEADER_INCLUDED__GC_MEASUREFRACTDIM_H
+
+
+
+#include "MLB_Interface.h"
+
+class CGrid_FractalDimension : public CSG_Module_Grid
+{
+public:
+	CGrid_FractalDimension(void);
+	virtual ~CGrid_FractalDimension(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	int						dimCount;
+
+	double					*dimAreas;
+
+	CSG_Grid					*pGrid;
+
+
+	void					Get_Surface(int Step);
+	void					Get_SurfaceRow(int Step, int xStep, int yStep, int ya, int yb);
+
+	double					Get_Area(double dist, double z1, double z2, double z3, double z4);
+	double					Get_Area(double xdist, double ydist, double z1, double z2, double z3, double z4);
+
+	double					Get_Distance(double z1, double z2, double dist);
+};
+
+#endif // #ifndef HEADER_INCLUDED__GC_MEASUREFRACTDIM_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,160 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Recreations - Fractals") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Fractals") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Recreations|Fractals") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Bifurcation.h"
+#include "Grid_FractalDimension.h"
+#include "Mandelbrot.h"
+#include "Pythagoras_Tree.h"
+#include "Newton.h"
+#include "Gaussian_Landscapes.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CBifurcation;
+		break;
+
+	case 1:
+		pModule	= new CPythagoras_Tree;
+		break;
+
+	case 2:
+		pModule	= new CMandelbrot;
+		break;
+
+	case 3:
+		pModule	= new CGrid_FractalDimension;
+		break;
+
+	case 4:
+		pModule	= new CNewton;
+		break;
+
+	case 5:
+		pModule	= new CGaussian_Landscapes;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__fractals_H
+#define HEADER_INCLUDED__fractals_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef fractals_EXPORTS
+	#define	fractals_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	fractals_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__fractals_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,347 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Mandelbrot.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Mandelbrot.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CMandelbrot::CMandelbrot(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Mandelbrot Set"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates Mandelbrot and Julia sets.\n\n"
+		"References:\n"
+		"- Mandelbrot, B.B. (1983): 'The Fractal Geometry of Nature', New York, 490p.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NX"		, _TL("Width (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NY"		, _TL("Height (Cells)"),
+		_TL(""), PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Range(
+		NULL	, "XRANGE"	, _TL("X-Range"),
+		_TL(""), -2.0, 1.0
+	);
+
+	Parameters.Add_Range(
+		NULL	, "YRANGE"	, _TL("Y-Range"),
+		_TL(""),
+		-1.5, 1.5
+	);
+
+	Parameters.Add_Value(
+		NULL	, "JULIA_X"	, _TL("Julia - X"),
+		_TL(""), PARAMETER_TYPE_Double, -0.7
+	);
+
+	Parameters.Add_Value(
+		NULL	, "JULIA_Y"	, _TL("Julia - Y"),
+		_TL(""), PARAMETER_TYPE_Double,  0.3
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MAXITER"	, _TL("Maximum Iterations"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 300, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Fractal Type"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Mandelbrot"),
+			_TL("Julia")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CMandelbrot::~CMandelbrot(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMandelbrot::On_Execute(void)
+{
+	//-----------------------------------------------------
+	m_Extent.Assign(
+		Parameters("XRANGE")->asRange()->Get_LoVal(),
+		Parameters("YRANGE")->asRange()->Get_LoVal(),
+		Parameters("XRANGE")->asRange()->Get_HiVal(),
+		Parameters("YRANGE")->asRange()->Get_HiVal()
+	);
+
+	m_maxIterations	= Parameters("MAXITER")	->asInt();
+	m_maxDistance	= 4.0;
+
+	m_Method		= Parameters("METHOD")	->asInt();
+
+	m_xJulia		= Parameters("JULIA_X")	->asDouble();
+	m_yJulia		= Parameters("JULIA_Y")	->asDouble();
+
+	m_pGrid			= SG_Create_Grid(SG_DATATYPE_Int, Parameters("NX")->asInt(), Parameters("NY")->asInt());
+	m_pGrid->Set_Name(m_Method == 0 ? _TL("Mandelbrot Set") : _TL("Julia Set"));
+	Parameters("GRID")->Set_Value(m_pGrid);
+
+	//-----------------------------------------------------
+	Calculate();
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+#define GET_POS(p)		p.Assign(\
+						m_Extent.Get_XMin() + m_Extent.Get_XRange() * (ptWorld.Get_X() - m_pGrid->Get_XMin()) / m_pGrid->Get_XRange(),\
+						m_Extent.Get_YMin() + m_Extent.Get_YRange() * (ptWorld.Get_Y() - m_pGrid->Get_YMin()) / m_pGrid->Get_YRange());
+
+#define SET_POS(a, b)	if( a.Get_X() > b.Get_X() )	{	d	= a.m_point.x; a.m_point.x	= b.m_point.x; b.m_point.x	= d;	}\
+						if( a.Get_Y() > b.Get_Y() )	{	d	= a.m_point.y; a.m_point.y	= b.m_point.y; b.m_point.y	= d;	}
+
+//---------------------------------------------------------
+bool CMandelbrot::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	double	d;
+
+	switch( Mode )
+	{
+	default:
+		break;
+
+	case MODULE_INTERACTIVE_LDOWN:
+	case MODULE_INTERACTIVE_RDOWN:
+		GET_POS(m_Down);
+
+		return( true );
+
+	case MODULE_INTERACTIVE_LUP:
+		GET_POS(m_Up);
+		SET_POS(m_Up, m_Down);
+
+		if( m_Up.Get_X() >= m_Down.Get_X() || m_Up.Get_Y() >= m_Down.Get_Y() )
+		{
+			m_Extent.Inflate(50.0);
+			m_Extent.Move(m_Up - m_Extent.Get_Center());
+		}
+		else
+		{
+			m_Extent.Assign(m_Up, m_Down);
+		}
+
+		Calculate();
+
+		return( true );
+
+	case MODULE_INTERACTIVE_RUP:
+		GET_POS(m_Up);
+		SET_POS(m_Up, m_Down);
+
+		if( m_Up.Get_X() >= m_Down.Get_X() || m_Up.Get_Y() >= m_Down.Get_Y() )
+		{
+			m_Extent.Deflate(50.0);
+			m_Extent.Move(m_Up - m_Extent.Get_Center());
+		}
+		else
+		{
+			m_Extent.Deflate(100.0 * (m_Down.Get_X() - m_Up.Get_X()) / m_Extent.Get_XRange());
+			m_Extent.Move(m_Up - m_Extent.Get_Center());
+		}
+
+		Calculate();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CMandelbrot::Calculate(void)
+{
+	int		x, y, i;
+	double	xPos, yPos, dx, dy;
+
+	dx	= m_Extent.Get_XRange() / (m_pGrid->Get_NX() - 1.0);
+	dy	= m_Extent.Get_YRange() / (m_pGrid->Get_NY() - 1.0);
+
+	for(y=0, yPos=m_Extent.Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, yPos+=dy)
+	{
+		for(x=0, xPos=m_Extent.Get_XMin(); x<m_pGrid->Get_NX(); x++, xPos+=dx)
+		{
+			switch( m_Method )
+			{
+			default:
+			case 0:	i	= Get_Mandelbrot	(xPos, yPos);	break;
+			case 1:	i	= Get_Julia			(xPos, yPos);	break;
+			}
+
+			if( i >= m_maxIterations )
+			{
+				m_pGrid->Set_NoData(x, y);
+			}
+			else
+			{
+				m_pGrid->Set_Value(x, y, i);
+			}
+		}
+	}
+
+	DataObject_Update(m_pGrid, true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CMandelbrot::Get_Mandelbrot(double xPos, double yPos)
+{
+	int		i;
+	double	x, y, k;
+
+	for(i=0, x=0.0, y=0.0; i<m_maxIterations; i++)
+	{
+		k	= xPos + x*x - y*y;
+		y	= yPos + 2.0 * x * y;
+		x	= k;
+
+		if( m_maxDistance < x*x + y*y )
+		{
+			return( i );
+		}
+	}
+
+	return( i );
+}
+
+//---------------------------------------------------------
+int CMandelbrot::Get_Julia(double xPos, double yPos)
+{
+	int		i;
+	double	x, y, k;
+
+	for(i=0, x=xPos, y=yPos; i<m_maxIterations; i++)
+	{
+		k	= m_xJulia + x*x - y*y;
+		y	= m_yJulia + 2.0 * x * y;
+		x	= k;
+
+		if( m_maxDistance < x*x + y*y )
+		{
+			return( i );
+		}
+	}
+
+	return( i );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Mandelbrot.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,123 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Mandelbrot.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Mandelbrot_H
+#define HEADER_INCLUDED__Mandelbrot_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CMandelbrot : public CSG_Module_Grid_Interactive
+{
+public:
+	CMandelbrot(void);
+	virtual ~CMandelbrot(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	int						m_Method, m_maxIterations;
+
+	double					m_maxDistance, m_xJulia, m_yJulia;
+
+	CSG_Point				m_Down, m_Up;
+
+	CSG_Rect				m_Extent;
+
+	CSG_Grid					*m_pGrid;
+
+
+	void					Calculate			(void);
+
+	int						Get_Mandelbrot		(double xPos, double yPos);
+	int						Get_Julia			(double xPos, double yPos);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Mandelbrot_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,307 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                      $$modul$$                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Newton.cpp                       //
+//                                                       //
+//            Copyright (C) 2003 Your Name               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     your at e-mail.abc                        //
+//                                                       //
+//    contact:    Your Name                              //
+//                And Address                            //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#pragma warning(disable: 4275)
+
+#include "Newton.h"
+#include <complex> 
+
+using namespace std;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CNewton::CNewton(void)
+{
+	//-----------------------------------------------------
+	// Place information about your module here...
+
+	Set_Name(_TL("Newton-Raphson"));
+
+	Set_Author(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+
+	Set_Description	(_TW(
+		"Newton-Raphson Fractals")
+	);
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "RESULT"	, _TL("Result"),
+		_TL("")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "SHADE"	, _TL("Shade"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(	NULL	, "NX"		, _TL("Width (Cells)")		, _TL(""), PARAMETER_TYPE_Int, 400, 1, true);
+	Parameters.Add_Value(	NULL	, "NY"		, _TL("Height (Cells)")		, _TL(""), PARAMETER_TYPE_Int, 400, 1, true);
+
+	Parameters.Add_Range(	NULL	, "XRANGE"	, _TL("X-Range"	)			, _TL(""), -2.0, 2.0);
+	Parameters.Add_Range(	NULL	, "YRANGE"	, _TL("Y-Range"	)			, _TL(""), -2.0, 2.0);
+
+	Parameters.Add_Choice(	NULL	, "METHOD"	, _TL("Equation")		, _TL(""), 
+						_TW("z^3-1|"
+							"z^4-1|"
+							"z^5-1|"
+							"z^6-1|"
+							"z^10 + 0.2 i * z^5 - 1|"), 0);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(	NULL, "MAXITER"	, _TL("Max Iterations")	, _TL("Maximum Iterations")		, PARAMETER_TYPE_Double	, 50);
+}
+
+//---------------------------------------------------------
+CNewton::~CNewton(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CNewton::On_Execute(void)
+{
+	int		x, y;
+		
+	x				= Parameters("NX")->asInt();
+	xMin			= Parameters("XRANGE")->asRange()->Get_LoVal();
+	dx	 =	xMax	= Parameters("XRANGE")->asRange()->Get_HiVal();
+	dx				= (dx - xMin) / (x - 1.0);
+
+	y				= Parameters("NY")->asInt();
+	yMin			= Parameters("YRANGE")->asRange()->Get_LoVal();
+	dy	=	yMax	= Parameters("YRANGE")->asRange()->Get_HiVal();
+	dy				= (dy - yMin) / (y - 1.0);
+
+	method			= Parameters("METHOD")->asInt();
+
+	pResult			= SG_Create_Grid(SG_DATATYPE_Double, x, y, dx, xMin, yMin);
+	pResult->Set_Name(_TL("Newton [A]"));
+	Parameters("RESULT")->Set_Value(pResult);
+
+	pShade			= SG_Create_Grid(SG_DATATYPE_Double, x, y, dx, xMin, yMin);
+	pShade->Set_Name(_TL("Newton [B]"));
+	Parameters("SHADE")	->Set_Value(pShade);
+
+	Get_System()->Assign(pShade->Get_System());
+
+	//-----------------------------------------------------
+	iMax		= Parameters("MAXITER")->asInt();
+
+	if( doNewton() )
+	{
+		DataObject_Update(pResult, true);
+		DataObject_Update(pShade , true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CNewton::doNewton()
+{
+	int		x, y, n;
+	double	i, r;
+	complex<double> z , old;
+
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			r	= (double) x / Get_NX()*(xMax-xMin) + xMin;
+			i	= (double) y / Get_NY()*(yMax-yMin) + yMin;
+
+// MinGW ERROR:
+// Newton.cpp:181: error: no matching function for call to `std::complex<double>::real(double&)'
+// error: candidates are: double std::complex<double>::real() const
+#ifdef _SAGA_VC
+			z.real(r);
+			z.imag(i);
+#endif
+			
+			for (n = 0 ;n< iMax; n++)
+			{
+				old = z;
+				switch( method )
+				{
+					case 0:	default:
+
+									
+						z = z - ( z * z * z- 1.0 ) / (3.0  * z *z);
+						break;
+
+
+					case 1:	
+									
+						z = z - ( z * z * z * z- 1.0 ) / (4.0 * z * z *z);
+						break;
+
+					case 2:
+						z = z - (z * z * z * z * z- 1.0 ) / (5.0 * z * z * z *z);
+						break;
+
+					case 3:
+						//							"z^10 + 0.2 i * z^5 - 1", 0);
+						{
+							complex<double> z5;
+							
+							z5= z*z; z5= z5 * z5; 
+
+							z5= z5*z;
+							
+							z =z - (z5*z - 1.0 ) / ( 6.0 * z5);
+						
+						break;
+						}
+
+					case 4:
+						{
+
+							complex<double> z9 , z4, wert(0,0.2);
+							z4 = z*z, z4= z4*z4;
+							z9 = z4*z4*z;
+
+							z = z -(z9*z + wert * z4*z -1.0 ) / (10.0 * z9 + 5.0 * wert * z4);
+						}
+
+				}
+
+				if ( abs(old - z)< 0.05 ) break;
+			
+			}
+			
+			if(n < iMax )
+			pResult->Set_Value(x, y, z.real());
+			else
+			pResult->Set_NoData(x,y);
+
+			pShade->Set_Value(x,y, exp (-(double) ((n - iMax/2)*(n - iMax/2))/(double)(iMax*iMax))  );
+		}
+	}
+
+	//-----------------------------------------------------
+	
+	 return( true );
+}
+
+
+
+bool CNewton::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	//-----------------------------------------------------
+	if(	Mode != MODULE_INTERACTIVE_LDOWN && Mode != MODULE_INTERACTIVE_RDOWN )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int ok = true;
+
+	int x= Get_xGrid(); 	int y = Get_yGrid();
+	
+	double xpos, ypos;
+	double deltax, deltay;
+
+	xpos = (double ) x / Get_NX()*(xMax-xMin) + xMin;
+
+	ypos = (double ) y / Get_NY()*(yMax-yMin) + yMin;
+
+	deltax = (xMax-xMin);
+
+	deltay = (yMax-yMin);
+
+	if(Mode == MODULE_INTERACTIVE_LDOWN)
+	{
+		deltax/=4.0;
+		deltay/=4.0;
+
+		xMin = xpos - deltax;
+		xMax = xpos + deltax;
+
+		yMin = ypos - deltay;
+		yMax = ypos + deltay;
+
+	}
+
+	if(Mode == MODULE_INTERACTIVE_RDOWN)
+	{
+		
+		xMin = xpos - deltax;
+		xMax = xpos + deltax;
+
+		yMin = ypos - deltay;
+		yMax = ypos + deltay;
+
+	}
+
+	doNewton();
+
+	DataObject_Update(pResult,pResult->Get_ZMin(), pResult->Get_ZMax());
+	DataObject_Update(pShade ,pShade ->Get_ZMin(), pShade ->Get_ZMax());
+
+	return true;
+}

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Newton.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                      $$modul$$                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Newton.h                        //
+//                                                       //
+//            Copyright (C) 2003 Your Name               //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     your at e-mail.abc                        //
+//                                                       //
+//    contact:    Your Name                              //
+//                And Address                            //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Newton_H
+#define HEADER_INCLUDED__Newton_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CNewton : public CSG_Module_Grid_Interactive
+{
+public:
+	CNewton(void);
+	virtual ~CNewton(void);
+
+	bool					doNewton();
+
+protected:
+
+	virtual bool			On_Execute(void);
+	virtual bool			On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+	double xMin, xMax, yMin, yMax;
+	int    iMax, method;
+	double dx, dy;
+
+
+	CSG_Grid	 *pResult, *pShade;
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Newton_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,297 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Pythagoras_Tree.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Pythagoras_Tree.h"
+#include <time.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPythagoras_Tree::CPythagoras_Tree(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Pythagoras' Tree"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW("Pythagoras' Tree."));
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "RESULT"		, _TL("Pythagoras' Tree"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "TYPE"		, _TL("Shape Type"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Lines"),
+			_TL("Polygons")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ANGLE"		, _TL("Angle [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 55.0, 0.0, true, 90.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MINSIZE"		, _TL("Minimum Size [%]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 2.0, 0.001, true, 100.0, true
+	);
+
+	pNode	= Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Fixed angle"),
+			_TL("Constant variation range"),
+			_TL("Low variation for low sizes"),
+			_TL("High variation for low sizes")
+		), 0
+	);
+
+	Parameters.Add_Range(
+		pNode	, "VARRANGE"	, _TL("Constant Variation Range [Degree]"),
+		_TL(""),
+		0.0, 90.0, 0.0, true, 90.0, true
+	);
+}
+
+//---------------------------------------------------------
+CPythagoras_Tree::~CPythagoras_Tree(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//	Run													 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPythagoras_Tree::On_Execute(void)
+{
+	TSG_Point	pt_A, pt_B;
+
+	pShapes		= Parameters("RESULT")	->asShapes();
+	pShapes->Create(Parameters("TYPE")->asInt() == 0 ? SHAPE_TYPE_Line : SHAPE_TYPE_Polygon, _TL("Pythagoras' Tree"));
+	pShapes->Add_Field(_TL("Iteration")	, SG_DATATYPE_Int);
+	pShapes->Add_Field(_TL("Size")		, SG_DATATYPE_Double);
+
+	Min_Size	= Parameters("MINSIZE")	->asDouble() / 100.0;
+
+	switch( (Method = Parameters("METHOD")->asInt()) )
+	{
+	case 0:	// Standard...
+		sin_Angle	= sin(Parameters("ANGLE")->asDouble() * M_DEG_TO_RAD);
+		cos_Angle	= cos(Parameters("ANGLE")->asDouble() * M_DEG_TO_RAD);
+		break;
+
+	case 1:	// Variation Range...
+		var_Min		= Parameters("VARRANGE")->asRange()->Get_LoVal() * M_DEG_TO_RAD;
+		var_Range	= Parameters("VARRANGE")->asRange()->Get_HiVal() * M_DEG_TO_RAD;
+		var_Range	= (var_Range - var_Min) / (double)RAND_MAX;
+		break;
+	}
+
+	srand((unsigned)time(NULL));
+
+	Iteration	= 0;
+
+	pt_A.x		= 0.0;
+	pt_B.x		= 1.0;
+	pt_A.y		= pt_B.y	= 0.0;
+
+	Set_Quadrat(pt_A, pt_B);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPythagoras_Tree::Set_Quadrat(TSG_Point pt_A0, TSG_Point pt_B0)
+{
+	double		dx, dy;
+	TSG_Point	pt_A1, pt_B1;
+
+	if( Process_Get_Okay(false) )
+	{
+		Iteration++;
+
+		dx		= pt_B0.x - pt_A0.x;
+		dy		= pt_B0.y - pt_A0.y;
+		Size	= sqrt(dx*dx + dy*dy);
+
+		pt_A1.x	= pt_A0.x - dy;
+		pt_A1.y	= pt_A0.y + dx;
+
+		pt_B1.x	= pt_B0.x - dy;
+		pt_B1.y	= pt_B0.y + dx;
+
+		Add_Shape(pt_A0, pt_B0, pt_B1, pt_A1);
+
+		if( Size > Min_Size )
+		{
+			switch( Method )
+			{
+			case 1:	// Variation Range...
+				var_Angle	= var_Min + (double)rand() * var_Range;
+				sin_Angle	= sin(var_Angle);
+				cos_Angle	= cos(var_Angle);
+				break;
+
+			case 2:	// High Variation for low sizes...
+				var_Range	= Size * M_PI_090;
+				var_Angle	= (M_PI_045 - var_Range / 2.0) + (double)rand() * var_Range / (double)RAND_MAX;
+				sin_Angle	= sin(var_Angle);
+				cos_Angle	= cos(var_Angle);
+				break;
+
+			case 3:	// Low Variation for low sizes...
+				var_Range	= (1.0 - Size) * M_PI_090;
+				var_Angle	= (M_PI_045 - var_Range / 2.0) + (double)rand() * var_Range / (double)RAND_MAX;
+				sin_Angle	= sin(var_Angle);
+				cos_Angle	= cos(var_Angle);
+				break;
+			}
+
+			pt_A0.x	= pt_A1.x + cos_Angle * (cos_Angle * dx - sin_Angle * dy);
+			pt_A0.y	= pt_A1.y + cos_Angle * (sin_Angle * dx + cos_Angle * dy);
+
+			Add_Shape(pt_A1, pt_B1, pt_A0);
+
+			Set_Quadrat(pt_A1, pt_A0);
+			Set_Quadrat(pt_A0, pt_B1);
+		}
+
+		Iteration--;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPythagoras_Tree::Add_Shape(TSG_Point pt_A, TSG_Point pt_B, TSG_Point pt_C, TSG_Point pt_D)
+{
+	CSG_Shape	*pShape;
+
+	pShape	= pShapes->Add_Shape();
+	pShape->Set_Value(0, Iteration);
+	pShape->Set_Value(1, Size);
+
+	pShape->Add_Point(pt_A);
+	pShape->Add_Point(pt_B);
+	pShape->Add_Point(pt_C);
+	pShape->Add_Point(pt_D);
+
+	if( pShapes->Get_Type() == SHAPE_TYPE_Line )
+	{
+		pShape->Add_Point(pt_A);
+	}
+}
+
+//---------------------------------------------------------
+void CPythagoras_Tree::Add_Shape(TSG_Point pt_A, TSG_Point pt_B, TSG_Point pt_C)
+{
+	CSG_Shape	*pShape;
+
+	pShape	= pShapes->Add_Shape();
+	pShape->Set_Value(0, Iteration);
+	pShape->Set_Value(1, Size);
+
+	pShape->Add_Point(pt_A);
+	pShape->Add_Point(pt_B);
+	pShape->Add_Point(pt_C);
+
+	if( pShapes->Get_Type() == SHAPE_TYPE_Line )
+	{
+		pShape->Add_Point(pt_A);
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_fractals/Pythagoras_Tree.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,105 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                       Fractals                        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Pythagoras_Tree.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Pythagoras_Tree_H
+#define HEADER_INCLUDED__Pythagoras_Tree_H
+
+
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CPythagoras_Tree : public CSG_Module
+{
+public:
+	CPythagoras_Tree(void);
+	virtual ~CPythagoras_Tree(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	int						Iteration, Method;
+
+	double					Min_Size, Size, sin_Angle, cos_Angle, var_Min, var_Range, var_Angle;
+
+	CSG_Shapes					*pShapes;
+
+
+	void					Set_Quadrat	(TSG_Point pt_A, TSG_Point pt_B);
+
+	void					Add_Shape	(TSG_Point pt_A, TSG_Point pt_B, TSG_Point pt_C, TSG_Point pt_D);
+	void					Add_Shape	(TSG_Point pt_A, TSG_Point pt_B, TSG_Point pt_C);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Pythagoras_Tree_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,136 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Library Template                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                        Author                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     author at email.de                        //
+//                                                       //
+//    contact:    Author                                 //
+//                Sesame Street. 7                       //
+//                12345 Metropolis                       //
+//                Nirwana                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Recreations - Games") );
+
+	case MLB_INFO_Author:
+		return( _TL("SAGA User Group Associaton, (c) 2003") );
+
+	case MLB_INFO_Description:
+		return( _TL("Games"));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Recreations|Games") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Mine_Sweeper.h"
+#include "Sudoku.h"
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule = new CMine_Sweeper;
+		break;
+
+	case 1:
+		pModule = new CSudoku;
+		break;
+	
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,78 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Library Template                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                        Author                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     author at email.de                        //
+//                                                       //
+//    contact:    Author                                 //
+//                Sesame Street. 7                       //
+//                12345 Metropolis                       //
+//                Nirwana                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__games_H
+#define HEADER_INCLUDED__games_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef games_EXPORTS
+	#define	games_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	games_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__games_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,496 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                     Mine_Sweeper                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Mine_Sweeper.cpp                    //
+//                                                       //
+//            Copyright (C) 2003 Andre Ringeler          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at gwdg.de                        //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//														 //	
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Mine_Sweeper.h"
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Import Resourcen	   					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+extern unsigned char	mine_res[];
+extern unsigned char	mine_res_color[];
+extern unsigned int		SPRITE_SIZE;
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Defines				   					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+#define FLAG				1
+#define QUESTION			2
+
+#define isBomb				1
+#define isOpen				8
+#define isBumm				16
+
+#define SPRITE_CLOSE		0
+#define SPRITE_FLAG			1
+#define SPRITE_QUESTION		2
+#define SPRITE_BOMB_BUMM	3
+#define SPRITE_BOMB_NO		4
+#define SPRITE_BOMB			5
+#define SPRITE_OPEN			15
+
+#define SPRITE_NUMMER(x)    (15-x)
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CMine_Sweeper::CMine_Sweeper(void)
+{
+	Set_Name	(_TL("Mine Sweeper"));
+
+	Set_Author	(_TL("Copyrights (c) 2003 by Andre Ringeler"));
+
+	Set_Description	(_TW(
+		"A Mine Sweeper Clone\n"
+		"(created by Andre Ringeler).")
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Choice(
+		NULL	,"LEVEL"	,_TL("Level"),
+		_TL("Game Level"),
+		_TW(	
+		"Beginer|"
+		"Advanced|"
+		"Profi|")	,1
+	);	
+}
+
+//---------------------------------------------------------
+CMine_Sweeper::~CMine_Sweeper(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMine_Sweeper::MakeBoard(int level)
+{
+	int		i, x, y;
+	CSG_Colors	Colors;
+
+	switch( level )
+	{
+		case 0:	Mine_NX = 8;	Mine_NY = 8;	N_Mines=10;
+			break;
+		
+		case 1: Mine_NX = 16;	Mine_NY = 16;	N_Mines=40;
+			break;
+		
+		case 2: Mine_NX = 30;	Mine_NY = 16;	N_Mines=99;
+			break;
+	}
+
+	pInput	= SG_Create_Grid(SG_DATATYPE_Int,SPRITE_SIZE*Mine_NX, SPRITE_SIZE*Mine_NY);
+	pInput->Set_Name(_TL("Mine Sweeper"));
+	Parameters("GRID")->Set_Value(pInput);
+
+	Colors.Set_Count(16);
+	for ( i=0;i<16; i++)
+	{
+		Colors.Set_Color(i, SG_GET_RGB(mine_res_color[i*3],	mine_res_color[i*3+1],	mine_res_color[i*3+2]));
+	}
+	DataObject_Set_Colors(pInput, Colors);
+	DataObject_Update(pInput, 0.0, 15.0, true);
+
+	for(  y = 0; y <  Mine_NY; y++)	
+	for(  x = 0; x <  Mine_NX; x++)
+	{
+		SetSprite(x,y,SPRITE_CLOSE);
+	}
+
+	pInput->Set_Value(0, 0);
+
+	return true;			
+}
+
+bool CMine_Sweeper::On_Execute(void)
+{
+	MakeBoard(Parameters("LEVEL")->asInt());
+
+	GameBoard	= (CSG_Grid *) new CSG_Grid(SG_DATATYPE_Int,Mine_NX,Mine_NY);
+	FlagBoard	= (CSG_Grid *) new CSG_Grid(SG_DATATYPE_Int,Mine_NX,Mine_NY);
+
+	First_Click	= true;
+	Time		= NULL;	
+
+	return( true );
+}
+
+
+bool CMine_Sweeper::On_Execute_Finish(void)
+{
+	delete GameBoard;
+	delete FlagBoard;
+
+	if (Time) delete Time;
+
+	return true;
+}
+
+	
+void CMine_Sweeper::ResetBoard(int xpos, int ypos)
+{
+	OpenFields = 0;			MarkedMines = 0;
+
+	FlagBoard->Assign();	GameBoard->Assign();
+
+	if(Time) delete Time;
+
+	Make_GameBoard( xpos , ypos);
+
+	Time = new CTimer();
+}
+
+//---------------------------------------------------------
+bool CMine_Sweeper::Get_Grid_Pos(int &x, int &y)
+{
+	bool	bResult;
+
+	if( pInput && pInput->is_Valid() )
+	{
+		bResult	= true;
+
+		//-------------------------------------------------
+		x		= (int)(0.5 + (Get_xPosition() - pInput->Get_XMin()) / pInput->Get_Cellsize());
+
+		if( x < 0 )
+		{
+			bResult	= false;
+			x		= 0;
+		}
+		else if( x >= pInput->Get_NX() )
+		{
+			bResult	= false;
+			x		= pInput->Get_NX() - 1;
+		}
+
+		//-------------------------------------------------
+		y		= (int)(0.5 + (Get_yPosition() - pInput->Get_YMin()) / pInput->Get_Cellsize());
+
+		if( y < 0 )
+		{
+			bResult	= false;
+			y		= 0;
+		}
+		else if( y >= pInput->Get_NY() )
+		{
+			bResult	= false;
+			y		= pInput->Get_NY() - 1;
+		}
+
+		return( bResult );
+	}
+
+	//-----------------------------------------------------
+	x		= 0;
+	y		= 0;
+
+	return( false );
+}
+
+
+bool CMine_Sweeper::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	int ok = true;
+	
+	int time;
+	int redraw = false;
+	int xpos; 	int ypos;
+
+	if( !Get_Grid_Pos(xpos, ypos) )
+		return( false );
+
+	xpos/=SPRITE_SIZE; 	ypos/=SPRITE_SIZE;
+
+	ypos=Mine_NY-1-ypos;
+	
+	switch( Mode )
+	{
+	default:
+		return( false );
+
+	case MODULE_INTERACTIVE_LDOWN:
+		if(First_Click)
+		{
+			ResetBoard(xpos, ypos);
+			First_Click=false;
+		}
+
+		ok = Play(xpos, ypos, false);
+		redraw = true;
+		break;
+
+	case MODULE_INTERACTIVE_RDOWN:
+		Mark(xpos, ypos);
+		redraw = true;
+		break;
+	}
+
+	if (redraw)
+	{
+		if(ok)
+		{
+			Show_GameBoard(false);
+			
+			time= Time->Time();
+			
+			Message_Add(CSG_String::Format(SG_T(":-) Time:%ds Mines:%d\n"),time,N_Mines-MarkedMines));
+			
+			if (OpenFields == Mine_NX*Mine_NY-N_Mines  )
+			{
+				Message_Add(CSG_String::Format(_TL(":-) :-) you are a winner :-) :-) Time:%ds\n"),time));
+				Message_Dlg(CSG_String::Format(_TL(":-) :-) you are a winner :-) :-) Time:%ds\n"),time));
+			
+				Show_GameBoard(true);
+
+				First_Click=true;
+			}
+		}
+		else 
+		{
+			Show_GameBoard(true);
+
+			Message_Dlg(CSG_String::Format(_TL(":-( :-( you are a loser :-( :-(")));
+			Message_Add(CSG_String::Format(_TL(":-( :-( you are a loser :-( :-(")));
+
+			First_Click=true;
+		}
+	}
+	return true;
+}
+
+
+
+void CMine_Sweeper::Make_GameBoard(int xpos,int ypos)
+{
+	int mines = 0;
+
+	srand( (unsigned)time( NULL ) );
+
+	while(mines < N_Mines)
+	{
+		int mx,my;
+
+		mx = rand()%Mine_NX;
+		my = rand()%Mine_NY;
+
+		if( !(GameBoard->asInt(mx, my) & isBomb) && !((mx==xpos)&&(my==ypos)) )
+		{
+			GameBoard->Set_Value(mx,my,isBomb);
+			mines ++;
+		}
+	}
+}
+
+
+void CMine_Sweeper::Show_GameBoard(bool ShowMines)
+{
+	int x,y;
+
+	if (ShowMines)
+	{
+		for(  y = 0; y <  Mine_NY; y++)	
+		for(  x = 0; x <  Mine_NX; x++)
+		{
+			if(GameBoard->asInt(x, y) & isBomb)
+			{
+				if (FlagBoard->asInt(x,y) == FLAG)
+					SetSprite(x,y,SPRITE_FLAG);
+				else
+					SetSprite(x,y,SPRITE_BOMB);
+			}
+			else
+			{
+				if (GameBoard->asInt(x, y) == isOpen )
+					SetSprite(x,y,SPRITE_NUMMER(Get_Number_of_Bombs(x,y)));
+				else			
+					SetSprite(x,y,SPRITE_CLOSE);
+			}
+			
+			if (GameBoard->asInt(x, y) & isBumm) SetSprite(x,y,SPRITE_BOMB_BUMM);
+
+			if ( !(GameBoard->asInt(x, y) & isBomb) && (FlagBoard->asInt(x,y) == FLAG)) 
+				SetSprite(x,y,SPRITE_BOMB_NO);
+		}
+	}
+	else
+	for(  y = 0; y <  Mine_NY; y++)	
+	for(  x = 0; x <  Mine_NX; x++)
+	{
+		if(GameBoard->asInt(x, y) == isOpen)
+		{
+			SetSprite(x,y,SPRITE_NUMMER(Get_Number_of_Bombs(x,y)));
+		}
+		else
+		{
+			if(FlagBoard->asInt(x,y))
+			SetSprite(x,y,FlagBoard->asInt(x,y));
+			else
+			SetSprite(x,y,SPRITE_CLOSE);
+		}
+	}
+
+	DataObject_Update(pInput, 0.0, 15.0);
+}
+
+
+void CMine_Sweeper::SetSprite(int xpos, int ypos, int nr)
+{
+	unsigned int x,y;
+	
+	for(y=0;y<SPRITE_SIZE;y++)
+	for(x=0;x<SPRITE_SIZE;x++)
+		pInput->Set_Value( xpos * SPRITE_SIZE + x, pInput->Get_NY() - ypos * SPRITE_SIZE - y -1,
+		                   mine_res[ y * SPRITE_SIZE + x + nr * SPRITE_SIZE * SPRITE_SIZE]);
+}
+
+
+int CMine_Sweeper::Get_Number_of_Bombs(int xpos, int ypos)
+{ 
+	int i;
+	int number = 0;
+
+	for( i = 0; i<8; i++) 
+		if (GameBoard->is_InGrid(pInput->Get_System().Get_xTo(i,xpos),pInput->Get_System().Get_yTo(i,ypos)))
+			if (GameBoard->asInt(pInput->Get_System().Get_xTo(i,xpos),pInput->Get_System().Get_yTo(i,ypos)) & isBomb)
+				number ++;
+		
+	return number;
+}
+
+bool CMine_Sweeper::Play(int xpos, int ypos,bool computer_move)
+{
+	int i;
+
+	if ( (!GameBoard->is_InGrid(xpos,ypos))||
+	   (FlagBoard->asInt(xpos, ypos)==1) ||	
+       ((GameBoard->asInt(xpos, ypos)) & isBomb && (computer_move))
+	)
+	{
+		return true;
+	}
+
+	if ( (GameBoard->asInt(xpos, ypos)) & isBomb && (!computer_move) )
+	{
+		GameBoard->Set_Value(xpos, ypos,isBomb|isBumm);
+		return false;
+	}
+
+	if (  GameBoard->asInt(xpos, ypos) == 0 )
+	{
+		GameBoard->Set_Value(xpos, ypos, isOpen);
+		
+		OpenFields ++;
+
+		if (Get_Number_of_Bombs(xpos, ypos) )
+			return true;
+
+		for( i = 0; i<8; i++) 
+			Play(pInput->Get_System().Get_xTo(i,xpos),pInput->Get_System().Get_yTo(i,ypos) ,true);
+	}
+	return true;
+}
+
+
+void CMine_Sweeper::Mark(int xpos, int ypos)
+{ 
+	int val;
+
+	val = FlagBoard->asInt(xpos , ypos);
+	
+	if (val == FLAG) MarkedMines --;
+	
+	val ++;	val%=3;
+
+	if (val == FLAG) MarkedMines ++ ;
+
+	FlagBoard->Set_Value(xpos, ypos, val);
+}
+
+
+CTimer::CTimer()
+{
+	time(&starttime);
+}
+
+CTimer::~CTimer()
+{
+}
+
+int CTimer::Time()
+{
+	time_t nowtime;
+	
+	time(&nowtime);
+
+	return (int) (nowtime-starttime);
+}

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Mine_Sweeper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,137 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                     Mine_Sweeper                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Mine_Sweeper.h                     //
+//                                                       //
+//           Copyright (C) 2003 by Andre Ringeler        //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     your at e-mail.abc                        //
+//                                                       //
+//    contact:    Your Name                              //
+//                And Address                            //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Mine_Sweeper_H
+#define HEADER_INCLUDED__Mine_Sweeper_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+#include <time.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+class CTimer
+{
+public:
+
+	CTimer(void);
+	~CTimer(void);
+
+	int Time(void);
+
+protected:
+
+	time_t starttime;
+
+};
+
+
+class CMine_Sweeper : public CSG_Module_Interactive
+{
+public:
+	CMine_Sweeper(void);
+	virtual ~CMine_Sweeper(void);
+
+
+	CSG_Grid	*pInput;
+
+protected:
+
+	virtual bool			On_Execute(void);
+	virtual bool			On_Execute_Finish	(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+	bool					Get_Grid_Pos(int &x, int &y);
+
+	void SetSprite(int xpos, int ypos, int nr);
+
+	bool	MakeBoard(int level);
+
+	void Make_GameBoard(int xpos,int ypos);
+
+	void Show_GameBoard(bool ShowMines);
+
+	int Get_Number_of_Bombs(int xpos, int ypos);
+
+	bool Play(int xpos, int ypos,bool computer_move);
+
+	void Mark(int xpos, int ypos);
+
+	void ResetBoard(int xpos, int ypos);
+	
+	int Mine_NX,Mine_NY, N_Mines;
+
+	int OpenFields, MarkedMines;
+
+	CSG_Grid *GameBoard, *FlagBoard;
+
+	bool First_Click;
+
+	CTimer *Time; 
+
+private:
+
+};
+
+
+
+#endif // #ifndef HEADER_INCLUDED__Mine_Sweeper_H

Added: packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Sudoku.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Sudoku.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_recreations/recreations/recreations_games/Sudoku.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library                     //
+//                                                       //
+//                        Sudoku                         //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Sudoku.h                        //
+//                                                       //
+//           Copyright (C) 2006 by Victor Olaya          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     your at e-mail.abc                        //
+//                                                       //
+//    contact:    Your Name                              //
+//                And Address                            //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Sudoku_H
+#define HEADER_INCLUDED__Sudoku_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+class CSudoku : public CSG_Module_Grid_Interactive
+{
+public:
+	CSudoku(void);
+	virtual ~CSudoku(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Finish	(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	bool					**m_pFixedCells;
+
+	int						**m_pSudoku;
+
+	CSG_Grid					*m_pBoard;
+
+
+	bool					Get_Grid_Pos		(int &x, int &y);
+
+	void DrawBoard();
+	void DrawCell(int iXCell, int iYCell, bool *pIsPossible);
+	void CreateSudoku();
+	void DrawSquare(int iX, int iY, int iColor, int iSize);
+	void GetPossibleValues(int iX, int iY, bool *pIsPossible);
+
+};
+
+#endif // #ifndef HEADER_INCLUDED__Sudoku_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,287 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cellular_Automata                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Life.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Life.h"
+#include <time.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CLife::CLife(void)
+{
+	//-----------------------------------------------------
+	// 1. Info...
+
+	Set_Name(_TL("Conway's Life"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Conway's Life - a cellular automat.\n\n"
+
+		"Reference:\n"
+		"- Eigen, M., Winkler, R. (1985): "
+		"'Das Spiel - Naturgesetze steuern den Zufall', "
+		"Muenchen, 404p.\n")
+	);
+
+
+	//-----------------------------------------------------
+	// 2. Grids...
+
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"	, _TL("Grid"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NX"		, _TL("Width (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NY"		, _TL("Height (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "FADECOLOR"	, _TL("Fade Color Count"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 63, 1, true, 255, true
+	);
+}
+
+//---------------------------------------------------------
+CLife::~CLife(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLife::On_Execute(void)
+{
+	int		x, y, i;
+
+	//-----------------------------------------------------
+	pLife	= SG_Create_Grid(SG_DATATYPE_Byte, Parameters("NX")->asInt(), Parameters("NY")->asInt());
+	pLife->Set_Name(_TL("Conway's Life"));
+	Parameters("GRID")->Set_Value(pLife);
+
+	nColors	= Parameters("FADECOLOR")->asInt();
+	DataObject_Set_Colors(pLife, nColors, SG_COLORS_YELLOW_BLUE);
+
+	pCount	= SG_Create_Grid(pLife);
+
+	//-----------------------------------------------------
+	srand((unsigned)time(NULL));
+
+	pLife->Assign(0.0);
+
+	for(y=0; y<pLife->Get_NY(); y++)
+	{
+		for(x=0; x<pLife->Get_NX(); x++)
+		{
+			if( rand() > RAND_MAX / 2 )
+			{
+				pLife->Set_Value(x, y, 1);
+			}
+		}
+	}
+
+	Next_Cycle();
+	DataObject_Update(pLife, 0, nColors, true);
+
+	//-----------------------------------------------------
+	for(i=1; Process_Get_Okay(true) && Next_Cycle(); i++)
+	{
+		DataObject_Update(pLife);
+
+		Process_Set_Text(CSG_String::Format(_TL("%d. Life Cycle"), i));
+	}
+
+	//-----------------------------------------------------
+	delete(pCount);
+
+	if( is_Progress() )
+	{
+		Message_Add(CSG_String::Format(_TL("Dead after %d Life Cycles\n"), i));
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLife::Next_Cycle(void)
+{
+	bool	bContinue;
+	int		x, y, i, ix, iy;
+
+	//-----------------------------------------------------
+	bContinue	= false;
+
+	pCount->Assign();
+
+	//-----------------------------------------------------
+	for(y=0; y<pLife->Get_NY(); y++)
+	{
+		for(x=0; x<pLife->Get_NX(); x++)
+		{
+			if( (i = pLife->asByte(x, y)) == 0 )
+			{
+				for(i=0; i<8; i++)
+				{
+					ix	= pLife->Get_System().Get_xTo(i, x);
+					if( ix < 0 )
+					{
+						ix	= pLife->Get_NX() - 1;
+					}
+					else if( ix >= pLife->Get_NX() )
+					{
+						ix	= 0;
+					}
+
+					iy	= pLife->Get_System().Get_yTo(i, y);
+					if( iy < 0 )
+					{
+						iy	= pLife->Get_NY() - 1;
+					}
+					else if( iy >= pLife->Get_NY() )
+					{
+						iy	= 0;
+					}
+
+					pCount->Add_Value(ix, iy, 1);
+				}
+			}
+			else if( i > 1 && i < nColors )
+			{
+				bContinue	= true;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<pLife->Get_NY(); y++)
+	{
+		for(x=0; x<pLife->Get_NX(); x++)
+		{
+			i	= pCount->asByte(x, y);
+
+			switch( i )
+			{
+			case 2:
+				i	= pLife->asByte(x, y);
+
+				if( i > 0 && i < nColors )
+				{
+					pLife->Add_Value(x, y, 1);
+				}
+				break;
+
+			case 3:
+				pLife->Set_Value(x, y, 0);
+				break;
+
+			default:
+				i	= pLife->asByte(x, y);
+
+				if( i < 1 )
+				{
+					pLife->Set_Value(x, y, 1);
+				}
+				else if( i < nColors )
+				{
+					pLife->Add_Value(x, y, 1);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( bContinue );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Life.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cellular_Automata                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Life.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__LIFE_H
+#define HEADER_INCLUDED__LIFE_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CLife : public CSG_Module
+{
+public:
+	CLife(void);
+	virtual ~CLife(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	int						nColors;
+
+	CSG_Grid					*pLife, *pCount;
+
+
+	bool					Next_Cycle(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__LIFE_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,140 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cellular_Automata                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Simulation - Cellular Automata") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2002") );
+
+	case MLB_INFO_Description:
+		return( _TL("Cellular Automata") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Simulation|Cellular Automata") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Life.h"
+#include "Wator.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CLife;
+		break;
+
+	case 1:
+		pModule	= new CWator;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cellular_Automata                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__sim_cellular_automata_H
+#define HEADER_INCLUDED__sim_cellular_automata_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef sim_cellular_automata_EXPORTS
+	#define	sim_cellular_automata_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	sim_cellular_automata_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__sim_cellular_automata_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,494 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cellular_Automata                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Wator.cpp                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Wator.h"
+#include <time.h>
+
+//---------------------------------------------------------
+#define FISH	1
+#define SHARK	2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWator::CWator(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Wa-Tor"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Wa-Tor - an ecological simulation of predator-prey populations - "
+		"is based upon A. K. Dewdney's 'Computer Recreations' article "
+		"in the December 1984 issue of Scientific American."
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid_Output(
+		NULL	, "GRID"			, _TL("Grid"),
+		_TL("")
+	);
+
+	pNode_0	= Parameters.Add_Node(
+		NULL	, "NODE_GRID"		, _TL("New Grid Dimensions"),
+		_TL("If grid is not set, a new one will be created using chosen width and height.")
+	);
+
+	Parameters.Add_Value(
+		pNode_0	, "NX"				, _TL("Width (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Value(
+		pNode_0	, "NY"				, _TL("Height (Cells)"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	pNode_0	= Parameters.Add_Grid(
+		NULL	, "RESULT"			, _TL("Wa-Tor"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL	, true, SG_DATATYPE_Byte
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "REFRESH"			, _TL("Refresh"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "INIT_FISH"		, _TL("Initial Number of Fishes [%]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 30.0, 0.0, true, 100.0, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "INIT_SHARK"		, _TL("Initial Number of Sharks [%]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 7.5, 0.0, true, 100.0, true
+	);
+
+	pNode_0	= Parameters.Add_Table(
+		NULL	, "TABLE"			, _TL("Cycles"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "FISH_BIRTH"		, _TL("Birth Rate of Fishes"),
+		_TL(""),
+		PARAMETER_TYPE_Int			,  3.0, 0.0, true
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "SHARK_BIRTH"		, _TL("Birth Rate of Sharks"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 12.0, 0.0, true
+	);
+
+	pNode_0	= Parameters.Add_Value(
+		NULL	, "SHARK_STARVE"	, _TL("Max. Starvation Time for Sharks"),
+		_TL(""),
+		PARAMETER_TYPE_Int			,  4.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CWator::~CWator(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWator::On_Execute(void)
+{
+	bool			bRefresh;
+	int				x, y, i;
+	double			perc, Fish_perc, Shark_perc;
+	CSG_Colors			Colors;
+	CSG_Table			*pTable;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	if( (pWator = Parameters("RESULT")->asGrid()) == NULL )
+	{
+		bRefresh	= true;
+		pWator		= SG_Create_Grid(SG_DATATYPE_Byte, Parameters("NX")->asInt(), Parameters("NY")->asInt());
+		Parameters("GRID")->Set_Value(pWator);
+	}
+	else
+	{
+		bRefresh	= Parameters("REFRESH")->asBool();
+	}
+
+	pWator->Set_Name(_TL("Wa-Tor"));
+
+	Colors.Set_Count(3);
+	Colors.Set_Color(0, SG_GET_RGB(  0,   0,   0));
+	Colors.Set_Color(1, SG_GET_RGB(  0, 255,   0));
+	Colors.Set_Color(2, SG_GET_RGB(255,   0,   0));
+	DataObject_Set_Colors(pWator, Colors);
+	DataObject_Update(pWator, 0, 3, SG_UI_DATAOBJECT_SHOW);
+
+	//-----------------------------------------------------
+	Fish_Birth		= Parameters("FISH_BIRTH")	->asInt();
+	Shark_Birth		= Parameters("SHARK_BIRTH")	->asInt();
+	Shark_Starve	= Parameters("SHARK_STARVE")->asInt();
+
+	pTable			= Parameters("TABLE")		->asTable();
+	pTable->Destroy();
+	pTable->Set_Name(_TL("Wa-Tor"));
+	pTable->Add_Field("Cycle"	, SG_DATATYPE_Int);
+	pTable->Add_Field("Fishes"	, SG_DATATYPE_Int);
+	pTable->Add_Field("Sharks"	, SG_DATATYPE_Int);
+
+	pNext			= SG_Create_Grid(pWator, SG_DATATYPE_Byte);
+	pAge			= SG_Create_Grid(pWator, SG_DATATYPE_Byte);
+	pStarve			= SG_Create_Grid(pWator, SG_DATATYPE_Byte);
+
+	srand((unsigned)time(NULL));
+
+	//-----------------------------------------------------
+	if( bRefresh )
+	{
+		pWator->Assign(0.0);
+
+		Fish_perc		= Parameters("INIT_FISH" )->asDouble();
+		Shark_perc		= Parameters("INIT_SHARK")->asDouble() + Fish_perc;
+
+		for(y=0; y<pWator->Get_NY(); y++)
+		{
+			for(x=0; x<pWator->Get_NX(); x++)
+			{
+				perc	= 100.0 * (double)rand() / (double)RAND_MAX;
+
+				if( perc <= Fish_perc )
+				{
+					pWator	->Set_Value(x, y, FISH);
+				}
+				else if( perc <= Shark_perc )
+				{
+					pWator	->Set_Value(x, y, SHARK);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	pAge	->Assign();
+	pStarve	->Assign();
+
+	for(y=0; y<pWator->Get_NY(); y++)
+	{
+		for(x=0; x<pWator->Get_NX(); x++)
+		{
+			switch( pWator->asByte(x, y) )
+			{
+			case FISH:
+				pAge	->Set_Value(x, y, Fish_Birth	* (double)rand() / (double)RAND_MAX);
+				break;
+
+			case SHARK:
+				pAge	->Set_Value(x, y, Shark_Birth	* (double)rand() / (double)RAND_MAX);
+				pStarve	->Set_Value(x, y, Shark_Starve	* (double)rand() / (double)RAND_MAX);
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_UI_Progress_Lock(true);
+
+	for(i=1; Process_Get_Okay(true) && Next_Cycle(); i++)
+	{
+		Process_Set_Text(CSG_String::Format(_TL("%d. Life Cycle"), i));
+
+		pRecord	= pTable->Add_Record();
+		pRecord->Set_Value(0, i);
+		pRecord->Set_Value(1, nFishes);
+		pRecord->Set_Value(2, nSharks);
+
+		DataObject_Update(pWator, 0, 3);
+		DataObject_Update(pTable);
+	}
+
+	SG_UI_Progress_Lock(false);
+
+	//-----------------------------------------------------
+	delete(pNext);
+	delete(pAge);
+	delete(pStarve);
+
+	if( is_Progress() )
+	{
+		Message_Add(CSG_String::Format(_TL("Dead after %d Life Cycles\n"), i));
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_NEIGHBOR			{	ix = pWator->Get_System().Get_xTo(i, x); if( ix < 0 ) ix = pWator->Get_NX() - 1; else if( ix >= pWator->Get_NX() ) ix = 0;\
+									iy = pWator->Get_System().Get_yTo(i, y); if( iy < 0 ) iy = pWator->Get_NY() - 1; else if( iy >= pWator->Get_NY() ) iy = 0;	}
+
+#define GET_NEIGHBOR_RANDOMLY	{	i = iNeighbor[(int)((double)rand() * nNeighbors / (double)RAND_MAX)];\
+									ix = pWator->Get_System().Get_xTo(i, x); if( ix < 0 ) ix = pWator->Get_NX() - 1; else if( ix >= pWator->Get_NX() ) ix = 0;\
+									iy = pWator->Get_System().Get_yTo(i, y); if( iy < 0 ) iy = pWator->Get_NY() - 1; else if( iy >= pWator->Get_NY() ) iy = 0;	}
+
+//---------------------------------------------------------
+bool CWator::Next_Cycle(void)
+{
+	static int	iDir	= 0;
+
+	int		x, y, i, ix, iy, xx, yy, ax, ay, dx, dy,
+			iNeighbor[8], nNeighbors,
+			Age, Starve;
+
+	//-----------------------------------------------------
+	nFishes	= 0;
+	nSharks	= 0;
+
+	pNext->Assign(0.0);
+
+	switch( iDir )
+	{
+	default:
+	case 3:	ay	= pWator->Get_NY() - 1;	dy	= -1;	ax	= pWator->Get_NX() - 1;	dx	= -1;	iDir=0;	break;
+	case 2:	ay	= 0;					dy	=  1;	ax	= pWator->Get_NX() - 1;	dx	= -1;	iDir++;	break;
+	case 1:	ay	= pWator->Get_NY() - 1;	dy	= -1;	ax	= 0;					dx	=  1;	iDir++;	break;
+	case 0:	ay	= 0;					dy	=  1;	ax	= 0;					dx	=  1;	iDir++;	break;
+	}
+
+	//-----------------------------------------------------
+	for(yy=0, y=ay; yy<pWator->Get_NY(); yy++, y+=dy)
+	{
+		for(xx=0, x=ax; xx<pWator->Get_NX(); xx++, x+=dx)
+		{
+			if( pWator->asByte(x, y) == FISH )
+			{
+				nFishes++;
+
+				Age		= pAge->asInt(x, y) + 1;
+				pAge->Set_Value(x, y, 0);
+
+				for(i=0, nNeighbors=0; i<8; i++)
+				{
+					GET_NEIGHBOR;
+
+					if( pWator->asByte(ix, iy) == 0 && pNext->asByte(ix, iy) == 0 )
+					{
+						iNeighbor[nNeighbors++]	= i;
+					}
+				}
+
+				if( nNeighbors > 0 )
+				{
+					GET_NEIGHBOR_RANDOMLY;
+
+					pNext	->Set_Value(ix, iy, FISH);
+					pAge	->Set_Value(ix, iy, Age >= Fish_Birth ? 0 : Age);
+
+					if( Age >= Fish_Birth )
+					{
+						pNext	->Set_Value( x,  y, FISH);
+						pAge	->Set_Value( x,  y, Fish_Birth * (double)rand() / (double)RAND_MAX);
+					}
+					else
+					{
+						pWator	->Set_Value( x,  y, 0);
+					}
+				}
+				else
+				{
+					pNext	->Set_Value( x,  y, FISH);
+					pAge	->Set_Value( x,  y, Age >= Fish_Birth ? 0 : Fish_Birth);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(yy=0, y=ay; yy<pWator->Get_NY(); yy++, y+=dy)
+	{
+		for(xx=0, x=ax; xx<pWator->Get_NX(); xx++, x+=dx)
+		{
+			if( pWator->asByte(x, y) == SHARK )
+			{
+				nSharks++;
+
+				Age		= pAge->asInt(x, y) + 1;
+				pAge->Set_Value(x, y, 0);
+
+				Starve	= pStarve->asInt(x, y) + 1;
+				pStarve->Set_Value(x, y, 0);
+
+				for(i=0, nNeighbors=0; i<8; i++)
+				{
+					GET_NEIGHBOR;
+
+					if( pNext->asByte(ix, iy) == FISH )
+					{
+						iNeighbor[nNeighbors++]	= i;
+					}
+				}
+
+				if( nNeighbors > 0 )
+				{
+					GET_NEIGHBOR_RANDOMLY;
+
+					nFishes--;
+					pWator	->Set_Value(ix, iy, 0);
+
+					pNext	->Set_Value(ix, iy, SHARK);
+					pAge	->Set_Value(ix, iy, Age >= Shark_Birth ? 0 : Age);
+					pStarve	->Set_Value(ix, iy, 0);
+
+					if( Age >= Shark_Birth )
+					{
+						pNext	->Set_Value( x,  y, SHARK);
+						pAge	->Set_Value( x,  y, Shark_Birth * (double)rand() / (double)RAND_MAX);
+						pStarve	->Set_Value( x,  y, 0);
+					}
+					else
+					{
+						pWator	->Set_Value( x,  y, 0);
+					}
+				}
+				else if( Starve <= Shark_Starve )
+				{
+					for(i=0, nNeighbors=0; i<8; i++)
+					{
+						GET_NEIGHBOR;
+
+						if( pWator->asByte(ix, iy) == 0 && pNext->asByte(ix, iy) == 0 )
+						{
+							iNeighbor[nNeighbors++]	= i;
+						}
+					}
+
+					if( nNeighbors > 0 )
+					{
+						GET_NEIGHBOR_RANDOMLY;
+
+						pNext	->Set_Value(ix, iy, SHARK);
+						pAge	->Set_Value(ix, iy, Age >= Shark_Birth ? 0 : Age);
+						pStarve	->Set_Value(ix, iy, Starve);
+
+						if( Age >= Shark_Birth )
+						{
+							pNext	->Set_Value( x,  y, SHARK);
+							pAge	->Set_Value( x,  y, Shark_Birth * (double)rand() / (double)RAND_MAX);
+							pStarve	->Set_Value( x,  y, Starve);
+						}
+						else
+						{
+							pWator	->Set_Value( x,  y, 0);
+						}
+					}
+					else
+					{
+						pNext	->Set_Value( x,  y, SHARK);
+						pAge	->Set_Value( x,  y, Age >= Shark_Birth ? 0 : Shark_Birth);
+						pStarve	->Set_Value( x,  y, Starve);
+					}
+				}
+				else
+				{
+					nSharks--;
+				}
+			}
+		}
+	}
+
+	pWator->Assign(pNext);
+
+	return( (nFishes > 0 && nFishes < pWator->Get_NCells()) || nSharks > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/cellular_automata/sim_cellular_automata/Wator.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Cellular_Automata                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Wator.h                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Wator_H
+#define HEADER_INCLUDED__Wator_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWator : public CSG_Module
+{
+public:
+	CWator(void);
+	virtual ~CWator(void);
+
+
+protected:
+
+	virtual bool			On_Execute(void);
+
+
+private:
+
+	int						Fish_Birth, Shark_Birth, Shark_Starve, nFishes, nSharks;
+
+	CSG_Grid					*pWator, *pNext, *pAge, *pStarve;
+
+
+	bool					Next_Cycle(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Wator_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,213 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Hugget_01.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Hugget_01.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CHugget_01::CHugget_01(void)
+{
+	Set_Name	(_TL("01: A Simple Litter System"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"A simple litter system model using the euler method. "
+		"Carbon storage C is calculated in dependency of litter fall rate (Cinput) "
+		"and rate constant for litter loss (Closs) as:\n"
+		"C(t + 1) = C(t) + (Cinput - Closs * C(t)) * dt\n"
+
+		"\nTypical values:\n"
+		"\n- Tropical Rainforest:\n"
+		"-- Litter fall rate: 500 [g/m²/a]\n"
+		"-- Litter loss rate: 2.0 [1/a]\n"
+
+		"\n- Temperate forest:\n"
+		"-- Litter fall rate: 240 [g/m²/a]\n"
+		"-- Litter loss rate: 0.4 [1/a]\n"
+
+		"\n- Boreal forest:\n"
+		"-- Litter fall rate: 50 [g/m²/a]\n"
+		"-- Litter loss rate: 0.05 [1/a]\n"
+
+		"\nReference:"
+		"\nHugget, R.J. (1993): 'Modelling the Human Impact on Nature', Oxford University Press.\n")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Results"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_SPAN"	, _TL("Time Span"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_STEP"	, _TL("Time Interval [a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "C_INIT"		, _TL("Initial Litter Storage [g/m\xc2\xb2]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "C_INPUT"		, _TL("Litterfall Rate [g/m\xc2\xb2/a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 240.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "C_OUTPUT"	, _TL("Rate Constant for Litter Loss [1/a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.4, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CHugget_01::~CHugget_01(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define WRITE_RECORD	pRecord	= pTable->Add_Record();\
+						pRecord->Set_Value(0, iStep);\
+						pRecord->Set_Value(1, iStep * dTime);\
+						pRecord->Set_Value(2, C);
+
+//---------------------------------------------------------
+bool CHugget_01::On_Execute(void)
+{
+	int				iStep, nSteps;
+	double			sTime, dTime, C, C_Input, C_Loss;
+	CSG_Table_Record	*pRecord;
+	CSG_Table			*pTable;
+
+	//-----------------------------------------------------
+	sTime	= Parameters("TIME_SPAN")	->asDouble();
+	dTime	= Parameters("TIME_STEP")	->asDouble();
+	nSteps	= (int)(sTime / dTime);
+
+	C		= Parameters("C_INIT")		->asDouble();
+	C_Input	= Parameters("C_INPUT")		->asDouble();
+	C_Loss	= Parameters("C_OUTPUT")	->asDouble();
+
+	pTable	= Parameters("TABLE")		->asTable();
+	pTable->Destroy();
+	pTable->Set_Name(_TL("A Simple Litter System"));
+	pTable->Add_Field("STEP"	, SG_DATATYPE_Int);
+	pTable->Add_Field("TIME"	, SG_DATATYPE_Double);
+	pTable->Add_Field("CARBON"	, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	if( C_Loss <= 0.0 )
+	{
+		C_Loss	= M_ALMOST_ZERO;
+	}
+
+	if( dTime >= 1.0 / C_Loss )
+	{
+		if( !Error_Set(_TL("Time interval is to large for a stable solution.")) )
+		{
+			return( false );
+		}
+	}
+
+	//-----------------------------------------------------
+	for(iStep=0; iStep<nSteps && Set_Progress(iStep, nSteps); iStep++)
+	{
+		WRITE_RECORD;
+
+		C	= C + (C_Input - C_Loss * C) * dTime;
+	}
+
+	WRITE_RECORD;
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_01.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Hugget_01.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Hugget_01_H
+#define HEADER_INCLUDED__Hugget_01_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CHugget_01 : public CSG_Module
+{
+public:
+	CHugget_01(void);
+	virtual ~CHugget_01(void);
+
+
+protected:
+
+	virtual bool		On_Execute	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Hugget_01_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,314 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Hugget_02.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Hugget_02.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CHugget_02::CHugget_02(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name	(_TL("02: Carbon Cycle Simulation for Terrestrial Biomes"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Simulation of the Carbon Cycle in Terrestrial Biomes. "
+
+		"\nReference:"
+		"\nHugget, R.J. (1993): 'Modelling the Human Impact on Nature', Oxford University Press.\n")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Results"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_SPAN"	, _TL("Time Span"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_STEP"	, _TL("Time Interval [a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "PRIMPROD"	, _TL("Net Primary Production [Gt Carbon / a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 27.8, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CHUMIFY"		, _TL("Humification Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.4, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CCARBON"		, _TL("Carbonization Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.05, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "NODE_1", _TL("Partition Coefficients"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "P_LEAV"		, _TL("Leaves"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.3, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "P_BRAN"		, _TL("Branches"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.2, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "P_STEM"		, _TL("Stems"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.3, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "P_ROOT"		, _TL("Roots"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.2, 0.0, true
+	);
+
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "NODE_2", _TL("Transfer Coefficients"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "K_LEAV_LITT"		, _TL("Leaves to Litter"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "K_BRAN_LITT"		, _TL("Branches to Litter"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "K_STEM_LITT"		, _TL("Stems to Litter"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.033, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "K_ROOT_HUMU"		, _TL("Roots to Humus"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "K_LITT_HUMU"		, _TL("Litter to Humus"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "K_HUMU_COAL"		, _TL("Humus to Charcoal"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "K_COAL_ENVI"		, _TL("Charcoal to Environment"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.002, 0.0, true
+	);
+
+}
+
+//---------------------------------------------------------
+CHugget_02::~CHugget_02(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define WRITE_RECORD	pRecord	= pTable->Add_Record();\
+						pRecord->Set_Value(0, iStep);\
+						pRecord->Set_Value(1, iStep * dTime);\
+						pRecord->Set_Value(2, C_Leav);\
+						pRecord->Set_Value(3, C_Bran);\
+						pRecord->Set_Value(4, C_Stem);\
+						pRecord->Set_Value(5, C_Root);\
+						pRecord->Set_Value(6, C_Litt);\
+						pRecord->Set_Value(7, C_Humu);\
+						pRecord->Set_Value(8, C_Coal);
+
+//---------------------------------------------------------
+bool CHugget_02::On_Execute(void)
+{
+	int				iStep, nSteps;
+	double			sTime, dTime, PrimProd, cHumify, cCarbon,
+					C_Leav, C_Bran, C_Stem, C_Root, C_Litt, C_Humu, C_Coal,
+					P_Leav, P_Bran, P_Stem, P_Root,
+					K_Leav_Litt, K_Bran_Litt, K_Stem_Litt,
+					K_Root_Humu, K_Litt_Humu, K_Humu_Coal, K_Coal_Envi,
+					d_Leav_Litt, d_Bran_Litt, d_Stem_Litt,
+					d_Root_Humu, d_Litt_Humu, d_Humu_Coal, d_Coal_Envi;
+	CSG_Table_Record	*pRecord;
+	CSG_Table			*pTable;
+
+	//-----------------------------------------------------
+	sTime	= Parameters("TIME_SPAN")		->asDouble();
+	dTime	= Parameters("TIME_STEP")		->asDouble();
+	nSteps	= (int)(sTime / dTime);
+
+	PrimProd	= Parameters("PRIMPROD")	->asDouble();
+	cHumify		= Parameters("CHUMIFY")		->asDouble();
+	cCarbon		= Parameters("CCARBON")		->asDouble();
+
+	P_Leav		= Parameters("P_LEAV")		->asDouble();
+	P_Bran		= Parameters("P_BRAN")		->asDouble();
+	P_Stem		= Parameters("P_STEM")		->asDouble();
+	P_Root		= Parameters("P_ROOT")		->asDouble();
+
+	K_Leav_Litt	= Parameters("K_LEAV_LITT")	->asDouble();
+	K_Bran_Litt	= Parameters("K_BRAN_LITT")	->asDouble();
+	K_Stem_Litt	= Parameters("K_STEM_LITT")	->asDouble();
+	K_Root_Humu	= Parameters("K_ROOT_HUMU")	->asDouble();
+	K_Litt_Humu	= Parameters("K_LITT_HUMU")	->asDouble();
+	K_Humu_Coal	= Parameters("K_HUMU_COAL")	->asDouble();
+	K_Coal_Envi	= Parameters("K_COAL_ENVI")	->asDouble();
+
+	pTable		= Parameters("TABLE")		->asTable();
+	pTable->Destroy();
+	pTable->Set_Name(_TL("Carbon Cycle Simulation"));
+	pTable->Add_Field("STEP"	, SG_DATATYPE_Int);
+	pTable->Add_Field("TIME"	, SG_DATATYPE_Double);
+	pTable->Add_Field("LEAVES"	, SG_DATATYPE_Double);
+	pTable->Add_Field("BRANCHES", SG_DATATYPE_Double);
+	pTable->Add_Field("STEMS"	, SG_DATATYPE_Double);
+	pTable->Add_Field("ROOTS"	, SG_DATATYPE_Double);
+	pTable->Add_Field("LITTER"	, SG_DATATYPE_Double);
+	pTable->Add_Field("HUMUS"	, SG_DATATYPE_Double);
+	pTable->Add_Field("CHARCOAL", SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	C_Leav		= 0.0;
+	C_Bran		= 0.0;
+	C_Stem		= 0.0;
+	C_Root		= 0.0;
+	C_Litt		= 0.0;
+	C_Humu		= 0.0;
+	C_Coal		= 0.0;
+
+	//-----------------------------------------------------
+	for(iStep=0; iStep<nSteps && Set_Progress(iStep, nSteps); iStep++)
+	{
+		WRITE_RECORD;
+
+		d_Leav_Litt	= K_Leav_Litt * C_Leav;
+		d_Bran_Litt	= K_Bran_Litt * C_Bran;
+		d_Stem_Litt	= K_Stem_Litt * C_Stem;
+		d_Root_Humu	= K_Root_Humu * C_Root;
+		d_Litt_Humu	= K_Litt_Humu * C_Litt;
+		d_Humu_Coal	= K_Humu_Coal * C_Humu;
+		d_Coal_Envi	= K_Coal_Envi * C_Coal;
+
+		C_Leav	= C_Leav + dTime * (-d_Leav_Litt + P_Leav * PrimProd);
+		C_Bran	= C_Bran + dTime * (-d_Bran_Litt + P_Bran * PrimProd);
+		C_Stem	= C_Stem + dTime * (-d_Stem_Litt + P_Stem * PrimProd);
+		C_Root	= C_Root + dTime * (-d_Root_Humu + P_Root * PrimProd);
+		C_Litt	= C_Litt + dTime * (-d_Litt_Humu + d_Leav_Litt + d_Bran_Litt + d_Stem_Litt);
+		C_Humu	= C_Humu + dTime * (-d_Humu_Coal + cHumify * (d_Root_Humu + d_Litt_Humu));
+		C_Coal	= C_Coal + dTime * (-d_Coal_Envi + cCarbon * (d_Humu_Coal));
+	}
+
+	WRITE_RECORD;
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_02.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,103 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Hugget_02.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Hugget_02_H
+#define HEADER_INCLUDED__Hugget_02_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CHugget_02 : public CSG_Module
+{
+public:
+	CHugget_02(void);
+	virtual ~CHugget_02(void);
+
+
+protected:
+
+	virtual bool		On_Execute	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Hugget_02_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,294 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Hugget_03.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Hugget_03.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CHugget_03::CHugget_03(void)
+{
+	Set_Name	(_TL("03: Spatially Distributed Simulation of Soil Nitrogen Dynamics"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Spatially Distributed Simulation of Soil Nitrogen Dynamics. "
+
+		"\nReference:"
+		"\nHugget, R.J. (1993): 'Modelling the Human Impact on Nature', Oxford University Press.\n")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "NSTORE"		, _TL("Soil Nitrogen"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "TIME_SPAN"	, _TL("Time Span [a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_STEP"	, _TL("Time Interval [a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "UPDATE"		, _TL("Update View"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "NINIT"		, _TL("Initial Nitrogen Content [kg/ha]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 5000.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NRAIN"		, _TL("Nitrogen in Rainfall [kg/ha/a]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 16.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CHugget_03::~CHugget_03(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CHugget_03::On_Execute(void)
+{
+	bool		bUpdate;
+	int			iStep, nSteps;
+	double		sTime, dTime, N_Init, N_Rain;
+	CSG_Grid	*pDEM, *pN, N_1, S[8];
+	CSG_String	s;
+
+	//-----------------------------------------------------
+	sTime	= Parameters("TIME_SPAN")	->asDouble();
+	dTime	= Parameters("TIME_STEP")	->asDouble();
+	nSteps	= (int)(sTime / dTime);
+
+	bUpdate	= Parameters("UPDATE")		->asBool();
+
+	N_Init	= Parameters("NINIT")		->asDouble();
+	N_Rain	= Parameters("NRAIN")		->asDouble();
+
+	pDEM	= Parameters("DEM")			->asGrid();
+
+	pN		= Parameters("NSTORE")		->asGrid();
+	pN->Assign(N_Init);
+
+	DataObject_Set_Colors(pN, 100, SG_COLORS_YELLOW_GREEN);
+
+	N_1.Create(pN, SG_DATATYPE_Float);
+
+	Init_Slopes(pDEM, S);
+
+	//-----------------------------------------------------
+	for(iStep=0; iStep<=nSteps && Set_Progress(iStep, nSteps); iStep++)
+	{
+		s.Printf(SG_T("%s: %f (%f)"), _TL("Time [a]"), dTime * iStep, sTime);
+		Process_Set_Text(s);
+
+		if( bUpdate )
+		{
+			DataObject_Update(pN, pN->Get_ZMin(), pN->Get_ZMax(), true);
+		}
+
+		//-------------------------------------------------
+		Step(S, pN, &N_1, N_Rain, dTime);
+
+		//-------------------------------------------------
+		pN->Assign(&N_1);
+	}
+
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CHugget_03::Init_Slopes(CSG_Grid *pDEM, CSG_Grid S[8])
+{
+	int		x, y, i, ix, iy;
+	double	z;
+
+	//-----------------------------------------------------
+	for(i=0; i<8; i++)
+	{
+		S[i].Create(pDEM, SG_DATATYPE_Float);
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDEM->is_NoData(x, y) )
+			{
+				for(i=0; i<8; i++)
+				{
+					S[i].Set_NoData(x, y);
+				}
+			}
+			else
+			{
+				z	= pDEM->asDouble(x, y);
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( pDEM->is_InGrid(ix, iy) )
+					{
+						S[i].Set_Value(x, y, (pDEM->asDouble(ix, iy) - z) / Get_Length(i));
+					}
+					else
+					{
+						S[i].Set_Value(x, y, 0.0);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CHugget_03::Step(CSG_Grid S[8], CSG_Grid *pN, CSG_Grid *pN_1, double N_Rain, double dTime)
+{
+	int		x, y, i;
+	double	s, dN;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !S[0].is_NoData(x, y) )
+			{
+				for(i=0, dN=0.0; i<8; i++)
+				{
+					if( (s = S[i].asDouble(x, y)) != 0.0 )
+					{
+						if( s < 0.0 )
+						{
+							dN	+= s * pN->asDouble(x, y);
+						}
+						else
+						{
+							dN	+= s * pN->asDouble(Get_xTo(i, x), Get_yTo(i, y));
+						}
+					}
+				}
+
+				s	= pN->asDouble(x, y) + (dN + N_Rain) * dTime;
+
+				if( s < 0.0 )
+				{
+					s	= N_Rain * dTime;
+				}
+
+				pN_1->Set_Value(x, y, s);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/Hugget_03.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Hugget_03.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Hugget_03_H
+#define HEADER_INCLUDED__Hugget_03_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CHugget_03 : public CSG_Module_Grid
+{
+public:
+	CHugget_03(void);
+	virtual ~CHugget_03(void);
+
+
+protected:
+
+	virtual bool		On_Execute	(void);
+
+
+private:
+
+	bool				Init_Slopes	(CSG_Grid *pDEM, CSG_Grid S[8]);
+
+	bool				Step		(CSG_Grid S[8], CSG_Grid *pN, CSG_Grid *pN_1, double N_Rain, double dTime);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Hugget_03_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,144 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char *	Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Simulation - Modelling the Human Impact on Nature") );
+
+	case MLB_INFO_Author:
+		return( SG_T("Olaf Conrad (c) 2003") );
+
+	case MLB_INFO_Description:
+		return( _TW(
+			"Numerical models for ecological processes. "
+			"Examples have been taken from:\n"
+			"Hugget, R.J. (1993): 'Modelling the Human Impact on Nature', Oxford University Press."
+		));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Simulation|Ecology|Modelling the Human Impact on Nature") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "Hugget_01.h"
+#include "Hugget_02.h"
+#include "Hugget_03.h"
+
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CHugget_01;
+		break;
+
+	case 1:
+		pModule	= new CHugget_02;
+		break;
+
+	case 2:
+		pModule	= new CHugget_03;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/ecosystems/sim_ecosystems_hugget/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                 sim_ecosystems_hugget                 //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__sim_lectures_hugget_H
+#define HEADER_INCLUDED__sim_lectures_hugget_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef sim_ecosystems_hugget_EXPORTS
+	#define	sim_ecosystems_hugget_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	sim_ecosystems_hugget_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__sim_lectures_hugget_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//    System for an Automated Geo-Scientific Analysis    //
+//                                                       //
+//                    Module Library:                    //
+//                      Fire_Spreading                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for an Automated  //
+// Geo-Scientific Analysis'. SAGA is free software; you  //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volaya at saga-gis.org                    //
+//                                                       //
+//    contact:    Victor Olaya                           //
+//                Spain                                  //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+#include "MLB_Interface.h"
+
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Simulation - Fire Spreading Analysis") );
+
+	case MLB_INFO_Author:
+		return( _TL("Victor Olaya (c) 2004") );
+
+	case MLB_INFO_Description:
+		return( _TW(
+			"Fire spreading analyses based on the BEHAVE fire modeling system "
+			"supported by the U.S. Forest Service, Fire and Aviation Management. "
+			"Find more information on BEHAVE at the <i>Public Domain Software for the Wildland Fire Community</i> at "
+			"<a target=\"_blank\" href=\"http://fire.org\">http://fire.org</a>\n"
+			"\n"
+			"Reference:\n"
+			"Andrews, P.L. (1986): BEHAVE: Fire Behavior Prediction and Fuel Modeling System - "
+			"Burn Subsystem, Part 1. U.S. Department of Agriculture, Forest Service General, Technical Report INT-194. "
+		));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Simulation|Fire Spreading") );
+	}
+}
+
+#include "Simulate.h"
+#include "Forecasting.h"
+
+CSG_Module *		Create_Module(int i)
+{
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CForecasting;
+		break;
+
+	case 1:
+		pModule	= new CSimulate;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/fire/sim_fire_spreading/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,69 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Terrain_Analysis                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__MLB_INTERFACE_H
+#define HEADER_INCLUDED__MLB_INTERFACE_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__MLB_INTERFACE_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,570 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 DVWK_SoilMoisture.cpp                 //
+//                                                       //
+//                 Copyright (C) 2002 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "DVWK_SoilMoisture.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDVWK_SoilMoisture::CDVWK_SoilMoisture(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name	(_TL("Soil Moisture Content"));
+
+	Set_Author		(SG_T("(c) 2002 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"The WEELS (Wind Erosion on European Light Soils) soil moisture "
+		"model dynamically calculates the soil moisture based on the rules "
+		"proposed by the DVWK (1996) with input data about:\n"
+		"- soil properties (grids: field capacity and permanent wilting point)\n"
+		"- land use (grid: crop types)\n"
+		"- climate (table: daily values of precipitation, temperature, air humidity)\n\n"
+
+		"References:\n"
+
+		"- DVWK - Deutscher Verband fuer Wasserwirtschaft und Kulturbau e.V. (1996): "
+		"'Ermittlung der Verdunstung von Land- und Wasserflaechen', "
+		"DVWK Merkblaetter 238/1996, Bonn, 135p.\n"
+
+		"- Boehner, J., Schaefer, W., Conrad, O., Gross, J., Ringeler, A. (2001): "
+		"'The WEELS Model: methods, results and limits of wind erosion modelling', "
+		"In: Catena, Special Issue\n")
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Grid(
+		NULL	, "STA_FC"		, _TL("Field Capacity [mm]"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		pNode	, "STA_FC_DEF"	, _TL("Default"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 20.0	, 0.0, true
+	);
+
+	pNode	= Parameters.Add_Grid(
+		NULL	, "STA_PWP"		, _TL("Permanent Wilting Point [mm]"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		pNode	, "STA_PWP_DEF"	, _TL("Default"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 2.0	, 0.0, true
+	);
+
+	pNode	= Parameters.Add_Grid(
+		NULL	, "LANDUSE"		, _TL("Land Use"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		pNode	, "LANDUSE_DEF"	, _TL("Default"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, -1.0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Grid(
+		NULL	, "DYN_W"		, _TL("Soil Moisture"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_FixedTable(
+		NULL	, "DYN_CLIMATE"	, _TL("Climate Data"),
+		_TL("")
+	);
+
+	pClimate	= pNode->asTable();
+	pClimate->Set_Name(_TL("Climate Data"));
+	pClimate->Add_Field(_TL("Precipitation [mm]")	, SG_DATATYPE_Double);
+	pClimate->Add_Field(_TL("Temperature (2pm) [DegreeC]"), SG_DATATYPE_Double);
+	pClimate->Add_Field(_TL("Air Humidity (2pm) [%%]"), SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_FixedTable(
+		NULL	, "STA_KC"		, _TL("Crop Coefficients"),
+		_TL("")
+	);
+
+	pCropCoeff	= pNode->asTable();
+	pCropCoeff->Set_Name(_TL("Crop Coefficients"));
+	pCropCoeff->Add_Field(_TL("Land Use ID")	, SG_DATATYPE_Int);
+	pCropCoeff->Add_Field(_TL("Name")		, SG_DATATYPE_String);
+	pCropCoeff->Add_Field(_TL("January")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("February")	, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("March")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("April")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("May")			, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("June")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("July")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("August")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("September")	, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("October")		, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("November")	, SG_DATATYPE_Double);
+	pCropCoeff->Add_Field(_TL("December")	, SG_DATATYPE_Double);
+
+	CSG_Table_Record	*pRec;
+
+#define ADD_RECORD(ID, NAME, m01, m02, m03, m04, m05, m06, m07, m08, m09, m10, m11, m12)	pRec = pCropCoeff->Add_Record();\
+	pRec->Set_Value( 0, ID);  pRec->Set_Value( 1, NAME);\
+	pRec->Set_Value( 2, m01); pRec->Set_Value( 3, m02); pRec->Set_Value( 4, m03); pRec->Set_Value( 5, m04);\
+	pRec->Set_Value( 6, m05); pRec->Set_Value( 7, m06); pRec->Set_Value( 8, m07); pRec->Set_Value( 9, m08);\
+	pRec->Set_Value(10, m09); pRec->Set_Value(11, m10); pRec->Set_Value(12, m11); pRec->Set_Value(13, m12);
+
+	//         ID   NAME              Jan   Feb   Mar   Apr   Mai   Jun   Jul   Aug   Sep   Okt   Nov   Dec
+	ADD_RECORD(1.0, _TL("Maehweide")		, 1   , 1   , 1   , 1   , 1.05, 1.10, 1.10, 1.05, 1.05, 1   , 1   , 1   );
+	ADD_RECORD(2.0, _TL("Winterweizen")	, 0.65, 0.65, 0.80, 0.85, 1.15, 1.45, 1.40, 1   , 0.80, 0.70, 0.65, 0.65);
+	ADD_RECORD(3.0, _TL("Wintergerste")	, 1   , 1   , 0.85, 0.95, 1.30, 1.35, 1.25, 1   , 1   , 1   , 1   , 1   );
+	ADD_RECORD(4.0, _TL("Sommergerste")	, 1   , 1   , 0.80, 0.90, 1.20, 1.35, 1.20, 1   , 1   , 1   , 1   , 1   );
+	ADD_RECORD(5.0, _TL("Winterroggen")	, 0.65, 0.65, 0.85, 0.90, 1.20, 1.30, 1.25, 0.95, 0.80, 0.70, 0.65, 0.65);
+	ADD_RECORD(6.0, _TL("Hafer"	)		, 1   , 1   , 0.65, 0.70, 1.10, 1.45, 1.35, 0.95, 1   , 1   , 1   , 1   );
+	ADD_RECORD(7.0, _TL("Zuckerrueben")	, 1   , 1   , 1   , 0.50, 0.75, 1.05, 1.40, 1.30, 1.10, 0.85, 1   , 1   );
+	ADD_RECORD(8.0, _TL("Kartoffeln")	, 1   , 1   , 1   , 0.50, 0.90, 1.05, 1.45, 1.20, 0.90, 1   , 1   , 1   );
+	ADD_RECORD(9.0, _TL("Winterraps")	, 0.65, 0.65, 0.85, 1   , 1.35, 1.35, 1.10, 0.85, 1   , 1   , 0.65, 0.65);
+	ADD_RECORD(0.0, _TL("Unknown")		, 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   );
+#undef ADD_RECORD
+}
+
+//---------------------------------------------------------
+CDVWK_SoilMoisture::~CDVWK_SoilMoisture(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CDVWK_SoilMoisture::On_Execute(void)
+{
+	int			Day, x, y, i, LandUseID;
+	CSG_Grid	*pGrid;
+
+	//-----------------------------------------------------
+	if( pClimate->Get_Record_Count() > 0 )
+	{
+		pFK_mm		= Parameters("STA_FC")		->asGrid();
+		FK_mm_Def	= Parameters("STA_FC_DEF")	->asDouble();
+
+		pPWP_mm		= Parameters("STA_PWP")		->asGrid();
+		PWP_mm_Def	= Parameters("STA_PWP_DEF")	->asDouble();
+
+		pWi_mm		= Parameters("DYN_W")		->asGrid();
+		DataObject_Set_Colors(pWi_mm, 100, SG_COLORS_YELLOW_BLUE);
+
+		//-------------------------------------------------
+		pLandUse	= SG_Create_Grid(pWi_mm, pCropCoeff->Get_Record_Count() < 127 ? SG_DATATYPE_Char : SG_DATATYPE_Int);
+		pLandUse->Assign(Parameters("LANDUSE_DEF")->asInt());
+
+		if( (pGrid = Parameters("LANDUSE")->asGrid()) != NULL )
+		{
+			for(y=0; y<Get_NY(); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					LandUseID	= pGrid->asInt(x, y);
+
+					for(i=0; i<pCropCoeff->Get_Record_Count(); i++)
+					{
+						if( LandUseID == pCropCoeff->Get_Record(i)->asInt(0) )
+						{
+							pLandUse->Set_Value(x, y, i);
+							break;
+						}
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		DataObject_Update(pWi_mm, 0, pFK_mm ? pFK_mm->Get_ZMax() : FK_mm_Def, true);
+
+		for(Day=0; Day<365 && Set_Progress(Day, 365); Day++)
+		{
+			Step_Day(Day);
+
+			DataObject_Update(pWi_mm, true);
+		}
+
+		//-------------------------------------------------
+		delete(pLandUse);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CDVWK_SoilMoisture::Get_Month(int Day)
+{
+	const int	Days[]	=
+	//	Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez
+	{	31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31	};
+
+	int		iMonth, nDays;
+
+	Day		%= 365;
+
+	if( Day < 0 )
+	{
+		Day 	+= 365;
+	}
+
+	for(iMonth=0, nDays=0; iMonth<12; iMonth++)
+	{
+		nDays	+= Days[iMonth];
+
+		if( Day < nDays )
+		{
+			return( iMonth + 1 );
+		}
+	}
+
+	return( 12 );
+}
+
+//---------------------------------------------------------
+// VKR 4.10:	Bestandeskoeffizient z.Ber.d.pot.Verdunstung d.Pflbest. (kc)
+//
+//		Bestand		: Typ (als ENUM) des Pflanzenbestandes
+//		Month		: 1=Jan, 2=Feb... 0=NA;
+//
+double CDVWK_SoilMoisture::Get_kc(int Bestand, int Day)
+{
+	if( Bestand >= 0 && Bestand < pCropCoeff->Get_Record_Count() )
+	{
+		return( pCropCoeff->Get_Record(Bestand)->asDouble(1 + Get_Month(Day)) );
+	}
+
+	return( 1.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CDVWK_SoilMoisture::Get_ETP_Haude(int Day)
+{
+	const double	f[]	=
+	//	---   Jan   Feb   Mar   Apr   Mai   Jun   Jul   Aug   Sep   Okt   Nov   Dez
+	{	0.00, 0.22, 0.22, 0.22, 0.29, 0.29, 0.28, 0.26, 0.25, 0.23, 0.22, 0.22, 0.22	};
+
+	double	T14, U14, es, e, ETP_Haude;
+
+	//-----------------------------------------------------
+	CSG_Table_Record	*pRecord;
+
+	if( (pRecord = pClimate->Get_Record(Day)) == NULL )
+	{
+		return( 0 );
+	}
+
+	T14		= pRecord->asDouble(1);
+	U14		= pRecord->asDouble(2);
+
+
+	//-----------------------------------------------------
+	// VKR 4.6:		Berechnung des Saettigungsdampfdruckes (es [hPa])
+	//
+	//					               17,62 * T14
+	//		es(T14)		= 6,11 * exp( -------------- );		bei T14 > 0
+	//					               243,12 + T14
+	//
+	//					               22,46 * T14
+	//		es(T14)		= 6,11 * exp( -------------- );		bei T14 < 0
+	//					               272,62 + T14
+	//
+	//		T14			: Temperatur 14 Uhr [DegreeC]
+	//
+
+	if( T14 < 0 )
+	{
+		es	= 6.11 * exp( (22.46 * T14) / (272.62 + T14) );
+	}
+	else
+	{
+		es	= 6.11 * exp( (17.62 * T14) / (243.12 + T14) );
+	}
+
+
+	//-----------------------------------------------------
+	// VKR 4.7:		Berechnung des aktuellen Dampfdruckes (e [hPa])
+	//
+	//		e		= es(T14) * U14 / 100
+	//
+	//		es(T14)		: Saettigungsdampfdruck 14 Uhr [hPa]
+	//		U14			: relative Luftfeuchte 14 Uhr [%] (Dampfdruck in % des Saettigungsdampfdruckes)
+	//
+
+	e	= es * U14 / 100.0;
+
+
+	//-----------------------------------------------------
+	// VKR 4.8:		Berechnung der potentiellen Verdunstung nach Haude (ETPhaude [mm/d])
+	//
+	//		ETPhaude	= f(m) * (es - e)
+	//
+	//		f(m)		: Monatsfaktor [mm/mbar/d]
+	//		e			: aktueller Dampfdruck [hPa]
+	//		es			: Saettigungsdampfdruck
+	//
+
+	ETP_Haude	= f[Get_Month(Day)] * (es - e);
+
+	return( ETP_Haude );
+}
+
+//---------------------------------------------------------
+double CDVWK_SoilMoisture::Get_Pi(int Day)
+{
+	const double Messfehler[]	=
+	//	---    Jan    Feb    Mar    Apr    Mai    Jun    Jul    Aug    Sep    Okt    Nov    Dez
+	{	0.000, 0.228, 0.236, 0.200, 0.160, 0.120, 0.103, 0.105, 0.103, 0.115, 0.136, 0.162, 0.189	};
+
+	double	P, Pi;
+
+	//-----------------------------------------------------
+	CSG_Table_Record	*pRecord;
+
+	if( (pRecord = pClimate->Get_Record(Day)) == NULL )
+	{
+		return( 0 );
+	}
+
+	P		= pRecord->asDouble(0);
+
+
+	//-----------------------------------------------------
+	// VKR 4.11:	Berechnung der korrigierten Niederschlaege (Pi [mm/d])
+	//
+	//		Pi	= N * kn
+	//
+	//		N		: Niederschlag gemessen [mm/d]
+	//		kn		: Korrekturfaktor ergibt sich aus den prozentualen Meßfehlern...
+	//		Month	: 1=Jan, 2=Feb... 0=NA;
+	//
+
+	Pi			= P + P * Messfehler[Get_Month(Day)];
+
+	return( Pi );
+}
+
+//---------------------------------------------------------
+double CDVWK_SoilMoisture::Get_Wi(double Wi, double Pi, double ETP, double kc, double FK, double PWP)
+{
+	double	Ri, d, ETPi, ETAi;
+
+
+	//-----------------------------------------------------
+	// VKR 4.9:		Berechnung des Reduktionsfaktors f.Verdunstung (Ri)
+	//
+	//			        PWP
+	//			   1 - -----
+	//			        Wi               ETP		Ri = 1	bei Pi > ETPi
+	//		Ri	= ------------- + 0,1 * ------;		Ri = 1	bei Ri > 1,0
+	//			        PWP              ETPi		Ri = 0	bei Ri < 0,0
+	//			   1 - -----
+	//			        FK
+	//
+	//		Pi			: korrigierter Niederschlag [mm/d]
+	//		Wi			: Bodenwassergehalt
+	//		PWP			: Permanenter Welkepunkt
+	//		FK			: Feldkapazitaet
+	//		kc			: Koeffizient f.d. Pflz.Bestand
+	//
+
+	ETPi	= ETP * kc;
+
+	if( Pi > ETPi )
+	{
+		Ri	= 1.0;
+	}
+	else if( ETPi <= 0.0 || Wi <= 0.0 || FK <= 0.0 )
+	{
+		Ri	= 0.0;
+	}
+	else
+	{
+		d	= 1.0 - PWP / FK;
+
+		if( d == 0.0 )
+		{
+			Ri	= 0.0;
+		}
+		else
+		{
+			Ri	= (1.0 - PWP / Wi) / d + 0.1 * ETP / ETPi;
+
+			if( Ri > 1.0 )
+			{
+				Ri	= 1.0;
+			}
+			else if( Ri < 0.0 )
+			{
+				Ri	= 0.0;
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// VKR 4.13:	Berechnung der tatsaechlichen Verdunstung (ETa [mm/d])
+	//
+	//		ETai	= Pi - (Pi - (ETPhaude * kc)) * Ri
+	//
+	//		Pi			: korrigierter Niederschlag [mm/d]
+	//		ETPhaude	: potentielle Verdunstung nach Haude [mm/d]
+	//		kc			: Bestandeskoeffizient
+	//		Ri			: Reduktionsfaktor
+	//
+
+	ETAi	= Pi - (Pi - ETPi) * Ri;
+
+
+	//-----------------------------------------------------
+	// VKR 4.14:	Berechnung des Bodenwasservorrats (Wi [mm/d])
+	//
+	//		Wi+1	= Wi + Pi - ETai - SRi + KR
+	//
+	//		Pi		: korrigierter Niederschlag [mm/d]
+	//		ETai	: tatsaechliche Verdunstung [mm/d]
+	//		SRi		: taegliche Sickerwaserrate [mm/d]
+	//					SRi	= 0					bei Wi+1 <= FK * ku
+	//					SRi	= Wi+1 - FK * ku	bei Wi+1 >  FK * ku;
+	//		FK		: Feldkapazitaet [mm]
+	//		ku		: moegliche Uebersaettigung ueber FK	:= 1 (findet keine Beruecksichtigung)
+	//		KR		: kapillare Aufstiegsrate			:= 0 (findet keine Beruecksichtigung)
+	//
+
+	Wi		+= Pi - ETAi;
+
+	if( Wi > FK )
+	{
+		Wi	= FK;	// -= SRi...
+	}
+	else if( Wi < PWP )
+	{
+		Wi	= PWP;
+	}
+
+
+	return( Wi );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDVWK_SoilMoisture::Step_Day(int Day)
+{
+	int		x, y;
+	double	Wi, Pi, ETP, kc, FK, PWP;
+
+	ETP		= Get_ETP_Haude(Day);
+	Pi		= Get_Pi(Day);
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			kc		= Get_kc(pLandUse->asInt(x, y), Day);
+
+			FK		= pFK_mm	? pFK_mm	->asDouble(x, y) : FK_mm_Def;
+			PWP		= pPWP_mm	? pPWP_mm	->asDouble(x, y) : PWP_mm_Def;
+
+			Wi		= pWi_mm->asDouble(x, y);
+			Wi		= Get_Wi(Wi, Pi, ETP, kc, FK, PWP);
+			pWi_mm->Set_Value(x, y, Wi);
+		}
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/DVWK_SoilMoisture.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DVWK_SoilMoisture.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__DVWK_SoilMoisture_H
+#define HEADER_INCLUDED__DVWK_SoilMoisture_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDVWK_SoilMoisture : public CSG_Module_Grid  
+{
+public:
+	CDVWK_SoilMoisture(void);
+	virtual ~CDVWK_SoilMoisture(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	double				FK_mm_Def, PWP_mm_Def;
+
+	CSG_Grid				*pWi_mm, *pFK_mm, *pPWP_mm, *pLandUse;
+
+	CSG_Table				*pClimate, *pCropCoeff;
+
+
+	int					Get_Month		(int Day);
+	double				Get_kc			(int Bestand, int Day);
+
+	double				Get_ETP_Haude	(int Day);
+	double				Get_Pi			(int Day);
+	double				Get_Wi			(double Wi, double Pi, double ETP, double kc, double FK, double PWP);
+
+	void				Step_Day		(int Day);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__DVWK_SoilMoisture_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,547 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    Kinematic_Wave                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    KinWav_D8.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "KinWav_D8.h"
+
+//---------------------------------------------------------
+#define Beta_0		(3.0 / 5.0)
+#define Beta_1		(3.0 / 5.0 - 1.0)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CKinWav_D8::CKinWav_D8(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name		(_TL("Overland Flow - Kinematic Wave D8"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2003"));
+
+	Set_Description	(_TW(
+		"Overland Flow - Kinematic Wave D8"
+		"\n\n"
+		"Reference:\n"
+		"Johnson, D.L., Miller, A.C. (1997):"
+		" A spatially distributed hydrological model utilizing raster data structures,"
+		" Computers & Geosciences, Vol.23, No.3, pp.267-272"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "FLOW"		, _TL("Runoff"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "GAUGES"		, _TL("Gauges"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Table(
+		NULL	, "GAUGES_FLOW"	, _TL("Flow at Gauges"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "TIME_SPAN"	, _TL("Simulation Time [h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 24.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TIME_STEP"	, _TL("Simulation Time Step [h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double,  0.1, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ROUGHNESS"	, _TL("Manning's Roughness"),
+		_TL(""),
+		PARAMETER_TYPE_Double,  0.03, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "NEWTON", _TL("Newton-Raphson"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "NEWTON_MAXITER"	, _TL("Max. Iterations"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 100		, 1		, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "NEWTON_EPSILON"	, _TL("Epsilon"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0001	, 0.0	, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Choice(
+		NULL	, "PRECIP"		, _TL("Precipitation"),
+		_TL("Kind of initializing Precipitation Event"),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Homogenous"),
+			_TL("Above Elevation"),
+			_TL("Left Half")
+		)
+	);
+
+	Parameters.Add_Value(
+		pNode	, "THRESHOLD"	, _TL("Threshold Elevation"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKinWav_D8::On_Execute(void)
+{
+	double	Roughness;
+
+	//-----------------------------------------------------
+	m_pDEM				= Parameters("DEM")				->asGrid();
+	m_pFlow				= Parameters("FLOW")			->asGrid();
+
+	m_pGauges			= Parameters("GAUGES")			->asShapes();
+	m_pGauges_Flow		= Parameters("GAUGES_FLOW")		->asTable();
+
+	Newton_MaxIter		= Parameters("NEWTON_MAXITER")	->asInt();
+	Newton_Epsilon		= Parameters("NEWTON_EPSILON")	->asDouble();
+
+	Roughness			= Parameters("ROUGHNESS")		->asDouble();
+
+	//-----------------------------------------------------
+	if( Initialize(Roughness) )
+	{
+		int		x, y, n;
+		double	Time, Time_Span;
+
+		Gauges_Initialise();
+
+		Time_Span		= Parameters("TIME_SPAN")		->asDouble();
+		m_dTime			= Parameters("TIME_STEP")		->asDouble();
+
+		for(Time=0.0; Time<=Time_Span && Process_Get_Okay(false); Time+=m_dTime)
+		{
+			Process_Set_Text(CSG_String::Format(SG_T("%s [h]: %f (%f)"), _TL("Simulation Time"), Time, Time_Span));
+
+			Get_Precipitation(Time);
+
+			m_Flow_Last.Assign(m_pFlow);
+
+			m_pFlow->Assign(0.0);
+
+			for(n=0; n<m_pDEM->Get_NCells() && Process_Get_Okay(false); n++)
+			{
+				if( m_pDEM->Get_Sorted(n, x, y) )
+				{
+					Get_Runoff(x, y);
+				}
+				else
+				{
+					m_pFlow->Set_NoData(x, y);
+				}
+			}
+
+			DataObject_Update(m_pFlow, 0.0, 100.0);
+
+			Gauges_Set_Flow(Time);
+		}
+
+		//-------------------------------------------------
+		Finalize();
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CKinWav_D8::Get_Runoff(int x, int y)
+{
+	int		Direction	= m_Direction.asChar(x, y);
+
+	if( Direction >= 0 )
+	{
+		m_pFlow->Set_Value(x, y, 
+			Get_Runoff(
+				m_pFlow		->asDouble(x, y),
+				m_Flow_Last	 .asDouble(x, y),
+				m_Alpha		 .asDouble(x, y),
+				Get_UnitLength(Direction), 0.0, 0.0
+			)
+		);
+
+		m_pFlow->Add_Value(Get_xTo(Direction, x), Get_yTo(Direction, y), m_Flow_Last.asDouble(x, y));
+	}
+}
+
+//---------------------------------------------------------
+double CKinWav_D8::Get_Runoff(double q_Up, double q_Last, double alpha, double dL, double r, double r_Last)
+{
+	double	dTdL, d, c, q, Res, dRes, dR;
+
+	//-----------------------------------------------------
+	dTdL	= m_dTime / dL;
+	dR		= m_dTime / 2.0 * (r + r_Last);
+
+
+	//-----------------------------------------------------
+	// 1. Initial estimation of q...
+
+	if( q_Last + q_Up != 0.0 )
+	{
+		d	= alpha * Beta_0 * pow((q_Last + q_Up) / 2.0, Beta_1);
+		q	= ( dTdL * q_Up + q_Last * d + dR ) / ( dTdL + d );
+	}
+	else
+	{
+		q	= dR;
+	}
+
+
+	//-----------------------------------------------------
+	// 2. Newton-Raphson...
+
+	c	= dTdL * q_Up + alpha * pow(q_Last, Beta_0) + dR;
+
+	for(int i=0; i<Newton_MaxIter; i++)
+	{
+		if( q <= 0 )
+		{
+			return( dR );
+		}
+
+		Res		= dTdL * q + alpha		    * pow(q, Beta_0) - c;
+		dRes	= dTdL     + alpha * Beta_0 * pow(q, Beta_1);
+//		if( dRes == 0.0 )	{	return( 0.0 );	}
+
+		d		= Res / dRes;
+		q		-= d;
+
+		if( fabs(d) < Newton_Epsilon )
+		{
+			break;
+		}
+	}
+
+	return( q < 0.0 ? 0.0 : q );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKinWav_D8::Initialize(double Roughness)
+{
+	m_Flow_Last	.Create(*Get_System(), SG_DATATYPE_Float);
+	m_Alpha		.Create(*Get_System(), SG_DATATYPE_Float);
+	m_Direction	.Create(*Get_System(), SG_DATATYPE_Char);
+	m_Direction	.Set_NoData_Value(-1);
+
+	m_pFlow->Assign(0.0);
+	DataObject_Set_Colors(m_pFlow, 100, SG_COLORS_WHITE_BLUE);
+	DataObject_Update(m_pFlow, 0.0, 100.0, SG_UI_DATAOBJECT_SHOW);
+
+	//-----------------------------------------------------
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( !m_pDEM->is_NoData(x, y) )
+			{
+				int		i, ix, iy, iMax;
+				double	z, d, dMax;
+
+				for(i=0, iMax=-1, dMax=0.0, z=m_pDEM->asDouble(x, y); i<8; i++)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( is_InGrid(ix, iy) && (d = (z - m_pDEM->asDouble(ix, iy)) / Get_Length(i)) > dMax )
+					{
+						dMax	= d;
+						iMax	= i;
+					}
+				}
+
+				if( iMax < 0 )
+				{
+					m_Direction	 .Set_NoData(x, y);
+				}
+				else
+				{
+					m_Direction	.Set_Value(x, y, iMax);
+
+					m_Alpha		.Set_Value(x, y, pow(Roughness / sqrt(dMax), Beta_0));
+
+					if( m_Alpha.asDouble(x, y) > 10 )
+						m_Alpha.Set_Value(x, y, 10);
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CKinWav_D8::Finalize(void)
+{
+	m_Direction	.Destroy();
+	m_Alpha		.Destroy();
+	m_Flow_Last	.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CKinWav_D8::Gauges_Initialise(void)
+{
+	if( m_pGauges_Flow != NULL )
+	{
+		if( m_pGauges == NULL )
+		{
+			DataObject_Add(m_pGauges = SG_Create_Shapes(SHAPE_TYPE_Point, _TL("Gauges")));
+
+			Parameters("GAUGES")->Set_Value(m_pGauges);
+
+			m_pGauges->Add_Field(_TL("ID"), SG_DATATYPE_Int);
+
+			for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+			{
+				for(int x=0; x<Get_NX(); x++)
+				{
+					bool	bBorder	= false;
+					bool	bLowest	= true;
+
+					for(int i=0; i<8; i++)
+					{
+						int	ix	= Get_xTo(i, x);
+						int	iy	= Get_yTo(i, y);
+
+						if( !m_pDEM->is_InGrid(ix, iy) )
+						{
+							bBorder	= true;
+						}
+						else if( m_pDEM->asDouble(ix, iy) < m_pDEM->asDouble(x, y) )
+						{
+							bLowest	= false;
+						}
+					}
+
+					if( bLowest && bBorder )
+					{
+						CSG_Shape	*pGauge	= m_pGauges->Add_Shape();
+
+						pGauge->Add_Point(Get_System()->Get_Grid_to_World(x, y));
+						pGauge->Set_Value(0, m_pGauges->Get_Count() + 1);
+					}
+				}
+			}
+		}
+
+		m_pGauges_Flow->Destroy();
+		m_pGauges_Flow->Set_Name(_TL("Outlet Hydrographs"));
+		m_pGauges_Flow->Add_Field("TIME", SG_DATATYPE_Double);
+
+		for(int i=0; i<m_pGauges->Get_Count(); i++)
+		{
+			m_pGauges_Flow->Add_Field(CSG_String::Format(SG_T("GAUGE_%02d"), i + 1), SG_DATATYPE_Double);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CKinWav_D8::Gauges_Set_Flow(double Time)
+{
+	if( m_pGauges_Flow && m_pGauges_Flow->Get_Field_Count() == m_pGauges->Get_Count() + 1 )
+	{
+		CSG_Table_Record	*pRecord	= m_pGauges_Flow->Add_Record();
+
+		pRecord->Set_Value(0, Time);
+
+		for(int i=0; i<m_pGauges->Get_Count(); i++)
+		{
+			double	Flow;
+
+			if( m_pFlow->Get_Value(m_pGauges->Get_Shape(i)->Get_Point(0), Flow) )
+			{
+				pRecord->Set_Value(i + 1, Flow);
+			}
+		}
+
+		DataObject_Update(m_pGauges_Flow);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CKinWav_D8::Get_Precipitation(double Time)
+{
+	if( Time == 0.0 )
+	{
+		int		x, y;
+		double	t;
+
+		switch( Parameters("PRECIP")->asInt() )
+		{
+		case 0:
+			(*m_pFlow)	+= 100.0;
+			break;
+
+		case 1:
+			t	= Parameters("THRESHOLD")->asDouble();
+
+			for(y=0; y<m_pDEM->Get_NY(); y++)
+			{
+				for(x=0; x<m_pDEM->Get_NX(); x++)
+				{
+					if( !m_pDEM->is_NoData(x, y) && m_pDEM->asDouble(x, y) > t )
+					{
+						m_pFlow->Add_Value(x, y, 100.0);
+					}
+				}
+			}
+			break;
+
+		case 2:
+			for(y=0; y<m_pDEM->Get_NY(); y++)
+			{
+				for(x=0; x<m_pDEM->Get_NX() / 2; x++)
+				{
+					if( !m_pDEM->is_NoData(x, y) )
+					{
+						m_pFlow->Add_Value(x, y, 100.0);
+					}
+				}
+			}
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/KinWav_D8.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     KinWav_D8.h                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__KinWav_D8_H
+#define HEADER_INCLUDED__KinWav_D8_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CKinWav_D8 : public CSG_Module_Grid  
+{
+public:
+	CKinWav_D8(void);
+
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+	double				m_dTime, Newton_MaxIter, Newton_Epsilon;
+
+	CSG_Grid			*m_pDEM, *m_pFlow, m_Direction, m_Alpha, m_Flow_Last;
+
+	CSG_Table			*m_pGauges_Flow;
+
+	CSG_Shapes			*m_pGauges;
+
+
+	void				Get_Runoff			(int x, int y);
+	double				Get_Runoff			(double q_Up, double q_Last, double alpha, double dL, double r, double r_Last);
+
+	bool				Initialize			(double Roughness);
+	bool				Finalize			(void);
+
+	bool				Gauges_Initialise	(void);
+	bool				Gauges_Set_Flow		(double Time);
+
+	void				Get_Precipitation	(double Time);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__KinWav_D8_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,149 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// 1. Include the appropriate SAGA-API header...
+
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+// 2. Place general module library informations here...
+
+const SG_Char *	Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Simulation - Hydrology") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2001") );
+
+	case MLB_INFO_Description:
+		return( _TL("Modelling hydrological processes.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Simulation|Hydrology") );
+	}
+}
+
+
+//---------------------------------------------------------
+// 3. Include the headers of your modules here...
+
+#include "DVWK_SoilMoisture.h"
+#include "KinWav_D8.h"
+#include "topmodel.h"
+#include "WaterRetentionCapacity.h"
+
+//---------------------------------------------------------
+// 4. Allow your modules to be created here...
+
+CSG_Module *		Create_Module(int i)
+{
+	// Don't forget to continuously enumerate the case switches
+	// when adding new modules! Also bear in mind that the
+	// enumeration always has to start with [case 0:] and
+	// that [default:] must return NULL!...
+
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CDVWK_SoilMoisture;
+		break;
+
+	case 1:
+		pModule	= new CKinWav_D8;
+		break;
+
+	case 2:
+		pModule	= new CTOPMODEL;
+		break;
+	
+	case 3:
+		pModule = new CWaterRetentionCapacity;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__sim_hydrology_H
+#define HEADER_INCLUDED__sim_hydrology_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef sim_hydrology_EXPORTS
+	#define	sim_hydrology_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	sim_hydrology_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__sim_hydrology_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,677 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     topmodel.cpp                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "topmodel.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTOPMODEL::CTOPMODEL(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	// Place information about your module here...
+
+	Set_Name		(_TL("TOPMODEL"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Simple Subcatchment Version of TOPMODEL\n\n"
+
+		"Based on the 'TOPMODEL demonstration program v95.02' by Keith Beven "
+		"(Centre for Research on Environmental Systems and Statistics, "
+		"Institute of Environmental and Biological Sciences, "
+		"Lancaster University, Lancaster LA1 4YQ, UK) "
+		"and the C translation of the Fortran source codes implementated in GRASS.\n\n"
+
+		"This program allows single or multiple subcatchment calculations "
+		"but with single average rainfall and potential evapotranspiration "
+		"inputs to the whole catchment.  Subcatchment discharges are routed "
+		"to the catchment outlet using a linear routing algorithm with "
+		"constant main channel velocity and internal subcatchment "
+		"routing velocity.  The program requires ln(a/tanB) distributions "
+		"for each subcatchment.  These may be calculated using the "
+		"GRIDATB program which requires raster elevation data as input. "
+		"It is recommended that those data should be 50 m resolution or "
+		"better.\n\n"
+
+		"NOTE that TOPMODEL is not intended to be a traditional model "
+		"package but is more a collection of concepts that can be used "
+		"**** where appropriate ****. It is up to the user to verify that "
+		"the assumptions are appropriate (see discussion in "
+		"Beven et al.(1994).   This version of the model  will be "
+		"best suited to catchments with shallow soils and moderate "
+		"topography which do not suffer from excessively long dry "
+		"periods.  Ideally predicted contributing areas should be "
+		"checked against what actually happens in the catchment.\n\n"
+
+		"It includes infiltration excess calculations and parameters "
+		"based on the exponential conductivity Green-Ampt model of "
+		"Beven (HSJ, 1984) but if infiltration excess does occur it "
+		"does so over whole area of a subcatchment.  Spatial variability "
+		"in conductivities can however be handled by specifying "
+		"Ko parameter values for different subcatchments, even if they "
+		"have the same ln(a/tanB) and routing parameters, ie. to "
+		"represent different parts of the area.\n\n"
+
+		"Note that time step calculations are explicit ie. SBAR "
+		"at start of time step is used to determine contributing area. "
+		"Thus with long (daily) time steps contributing area depends on "
+		"initial value together with any volume filling effect of daily "
+		"inputs.  Also baseflow at start of time step is used to update "
+		"SBAR at end of time step."
+
+		"\n\nReferences\n"
+		"- Beven, K., Kirkby, M.J., Schofield, N., Tagg, A.F. (1984): "
+		"  Testing a physically-based flood forecasting model (TOPMODEL) for threee U.K. catchments, "
+		"  Journal of Hydrology, H.69, S.119-143.\n"
+		"\n"
+		"- Beven, K. (1997): "
+		"  TOPMODEL - a critique, "
+		"  Hydrological Processes, Vol.11, pp.1069-1085.\n"
+	));
+
+
+	//-----------------------------------------------------
+
+	Parameters.Add_Grid(
+		NULL	, "ATANB"		, _TL("A / tan(\xc3\x9f)"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	pNode	= Parameters.Add_Grid(
+		NULL	, "MOIST"		, _TL("Soil Moisture Deficit"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Table(
+		NULL	, "CLIMATE"		, _TL("Climate Data (P, EP)"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Simulation Output"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DTIME"		, _TL("Time Step [h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NCLASSES"	, _TL("Number of Classes"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 30	, 1	, true
+	);
+
+	pNode	= NULL;
+	Parameters.Add_Value(
+		pNode, "P_QS0"			, _TL("Initial subsurface flow per unit area [m/h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 3.28e-05
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_LNTE"			, _TL("Areal average of ln(T0) = ln(Te) [ln(m^2/h)]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 5.0
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_MODEL"		, _TL("Model parameter [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.032
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_SR0"			, _TL("Initial root zone storage deficit [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.002
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_SRZMAX"		, _TL("Maximum root zone storage deficit [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.05
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_SUZ_TD"		, _TL("Unsaturated zone time delay per unit storage deficit [h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 50.0
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_VCH"			, _TL("Main channel routing velocity [m/h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 3600.0
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_VR"			, _TL("Internal subcatchment routing velocity [m/h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 3600.0
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_K0"			, _TL("Surface hydraulic conductivity [m/h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_PSI"			, _TL("Wetting front suction [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.02
+	);
+
+	Parameters.Add_Value(
+		pNode, "P_DTHETA"		, _TL("Water content change across the wetting front"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.1
+	);
+
+	Parameters.Add_Value(
+		pNode, "BINF"			, _TL("Green-Ampt Infiltration"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+}
+
+//---------------------------------------------------------
+CTOPMODEL::~CTOPMODEL(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTOPMODEL::On_Execute(void)
+{
+	bool			bInfiltration;
+	int				iClass, nClasses, iTime, nTimeSteps, n, k;
+	double			Precipitation, Evaporation, Infiltration, Infiltration_Excess;
+	CSG_Grid			*pAtanB, *pMoist, gClass;
+	CSG_Table_Record	*pRecord;
+	CSG_Table			*pTable;
+
+
+	//-----------------------------------------------------
+	// Get user inputs from the 'Parameters' object...
+
+	pAtanB			= Parameters("ATANB")		->asGrid();
+	pClimate		= Parameters("CLIMATE")		->asTable();
+	dTime			= Parameters("DTIME")		->asDouble();
+	nClasses		= Parameters("NCLASSES")	->asInt();
+	bInfiltration	= Parameters("BINF")		->asBool();
+
+	nTimeSteps		= pClimate->Get_Record_Count();
+
+	if( (pMoist = Parameters("MOIST")->asGrid()) != NULL )
+	{
+		pMoist->Set_Name(_TL("Soil Moisture Deficit"));
+		DataObject_Set_Colors(pMoist, 100, SG_COLORS_RED_GREY_BLUE, true);
+	}
+
+
+	//-----------------------------------------------------
+	pTable			= Parameters("TABLE")->asTable();
+	pTable->Destroy();
+	pTable->Set_Name(_TL("TOPMODEL - Simulation Output"));
+	pTable->Add_Field(_TL("Total flow (in watershed) [m\xc2\xb3/dt]")			, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Total flow [m/dt]")							, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Saturation overland flow [m/dt]")			, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Subsurface flow [m/dt]")						, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Vertical (drainage) flux [m/dt]")			, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Mean saturation deficit (in watershed) [m]")	, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Infiltration rate [m/dt]")					, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Infiltration excess runoff [m/dt]")			, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	Vals.Create(dTime, nTimeSteps, &Parameters, pAtanB, nClasses, &gClass);
+
+	//-----------------------------------------------------
+	inf_bPonding	= false;
+	inf_cumf		= 0.0;
+
+	for(iTime=0; iTime<nTimeSteps && Set_Progress(iTime, nTimeSteps); iTime++)
+	{
+		Get_Climate(iTime, Precipitation, Evaporation);
+
+		if( bInfiltration && Precipitation > 0.0 )
+		{
+			Infiltration		= dTime * Get_Infiltration((iTime + 1) * dTime, Precipitation / dTime);
+			Infiltration_Excess	= Precipitation - Infiltration;
+			Precipitation		= Infiltration;
+		}
+		else
+		{
+			Infiltration		= 0.0;
+			Infiltration_Excess	= 0.0;
+		}
+
+		Run(Evaporation, Precipitation, Infiltration_Excess);
+
+		for(iClass=0; iClass<Vals.nreach_; iClass++)
+		{
+			k		= iTime + iClass + Vals.ndelay_;
+			if( k > nTimeSteps - 1 )
+				break;
+
+			Vals.Qt_[k]	+= Vals.qt_Total * Vals.Add[iClass];
+		}
+
+		if( pMoist )
+		{
+			for(n=0; n<gClass.Get_NCells(); n++)
+			{
+				iClass	= gClass.asInt(n);
+
+				if( iClass >= 0 && iClass < nClasses )
+				{
+					pMoist->Set_Value(n, Vals.Get_Class(iClass)->S_);
+				}
+				else
+				{
+					pMoist->Set_NoData(n);
+				}
+			}
+
+		//	DataObject_Update(pMoist);
+			DataObject_Update(pMoist, 0, 0.35, true);
+		}
+
+		pRecord	= pTable->Add_Record();
+		pRecord->Set_Value(0, Vals.Qt_[iTime]);		// QT
+		pRecord->Set_Value(1, Vals.qt_Total);		// qt
+		pRecord->Set_Value(2, Vals.qo_Total);		// q0
+		pRecord->Set_Value(3, Vals.qs_Total);		// qs
+		pRecord->Set_Value(4, Vals.qv_Total);		// qv
+		pRecord->Set_Value(5, Vals.Sbar_);			// SBar
+		pRecord->Set_Value(6, Infiltration);		// Infiltration
+		pRecord->Set_Value(7, Infiltration_Excess);	// Infiltration Excess
+		DataObject_Update(pTable);
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CTOPMODEL::Run(double Evaporation, double Precipitation, double Infiltration_Excess)
+{
+	int				iClass;
+	double			d, Excess;
+	CTOPMODEL_Class	*pClass;
+
+	Vals.qo_Total	= 0.0;
+	Vals.qv_Total	= 0.0;
+	Vals.qs_Total	= Vals._qs_ * exp(-Vals.Sbar_ / Vals.p_Model);
+
+	for(iClass=0; iClass<Vals.Get_Count(); iClass++)
+	{
+		pClass			= Vals.Get_Class(iClass);
+
+
+		//-------------------------------------------------
+		//  CALCULATE LOCAL STORAGE DEFICIT
+
+		pClass->S_		= Vals.Sbar_ + Vals.p_Model * (Vals.Get_Lambda() - pClass->AtanB);
+
+		if( pClass->S_ < 0.0 )
+		{
+			pClass->S_		= 0.0;
+		}
+
+
+		//-------------------------------------------------
+		//  ROOT ZONE CALCULATIONS
+
+		pClass->Srz_	-= Precipitation;
+
+		if( pClass->Srz_ < 0.0 )
+		{
+			pClass->Suz_	-= pClass->Srz_;
+			pClass->Srz_	= 0.0;
+		}
+
+
+		//-------------------------------------------------
+		//  UNSATURATED ZONE CALCULATIONS
+
+		if( pClass->Suz_ > pClass->S_ )
+		{
+			Excess			= pClass->Suz_ - pClass->S_;
+			pClass->Suz_	= pClass->S_;
+		}
+		else
+		{
+			Excess			= 0.0;
+		}
+
+
+		//-------------------------------------------------
+		//  CALCULATE DRAINAGE FROM SUZ (Vertical Soil Water Flux (qv))...
+
+		if( pClass->S_ > 0.0 )
+		{
+			if( Vals.p_Suz_TimeDelay > 0.0 )
+			{	// Methode 1...
+				d			= pClass->Suz_ / (pClass->S_ * Vals.p_Suz_TimeDelay) * dTime;	// GRASS
+			}
+			else
+			{	// Methode 2...
+				d			= -Vals.p_Suz_TimeDelay * Vals.p_K0 * exp(-pClass->S_ / Vals.p_Model);
+			}
+
+			if( d > pClass->Suz_ )
+			{
+				d			= pClass->Suz_;
+			}
+
+			pClass->Suz_	-= d;
+
+			if( pClass->Suz_ < 0.0000001 )
+			{
+				pClass->Suz_	= 0.0;
+			}
+
+			pClass->qv_		= d * pClass->Area_Rel;
+			Vals.qv_Total	+= pClass->qv_;
+		}
+		else
+		{
+			pClass->qv_		= 0.0;
+		}
+
+
+		//-------------------------------------------------
+		//  CALCULATE EVAPOTRANSPIRATION FROM ROOT ZONE DEFICIT
+
+		if( Evaporation > 0.0 )
+		{
+			d		= Evaporation * (1.0 - pClass->Srz_ / Vals.p_Srz_Max);
+
+			if( d > Vals.p_Srz_Max - pClass->Srz_ )
+			{
+				d		= Vals.p_Srz_Max - pClass->Srz_;
+			}
+
+			pClass->Srz_	+= d;
+		}
+
+
+		//-------------------------------------------------
+		pClass->qo_		= Excess * pClass->Area_Rel;
+		Vals.qo_Total	+= pClass->qo_;
+
+		pClass->qt_		= pClass->qo_ + Vals.qs_Total;
+	}
+
+	Vals.qo_Total	+= Infiltration_Excess;
+
+	Vals.qt_Total	= Vals.qo_Total + Vals.qs_Total;
+
+	Vals.Sbar_		+= Vals.qs_Total - Vals.qv_Total;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTOPMODEL::Get_Climate(int iTimeStep, double &Precipitation, double &Evaporation)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( pClimate && pClimate->Get_Field_Count() >= 2 && (pRecord = pClimate->Get_Record(iTimeStep)) != NULL )
+	{
+		Precipitation	= pRecord->asDouble(0);
+		Evaporation		= pRecord->asDouble(1);
+
+		return( true );
+	}
+	else
+	{
+		Precipitation	= 0.0;
+		Evaporation		= 0.0;
+
+		return( false );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define NEWTON_EPSILON		0.001
+#define NEWTON_MAXITER		100
+#define	NEWTON_NTERMS		10
+
+//---------------------------------------------------------
+double CTOPMODEL::Get_Infiltration(double t, double R)
+{
+	int		i, j, factorial;
+
+	double	f, f_, f1, f2, fc, R2, cnst, pt, psi_dtheta, sum;
+
+
+	if( R <= 0.0 )
+	{
+		inf_cumf		= 0.0;
+		inf_bPonding	= 0;
+
+		return( 0.0 );
+	}
+
+	psi_dtheta	= Vals.p_Psi * Vals.p_dTheta;
+
+	if( !inf_bPonding )
+	{
+		if( inf_cumf )
+		{
+			f1				= inf_cumf;
+			R2				= -Vals.p_K0 / Vals.p_Model * (psi_dtheta + f1) / (1 - exp(f1 / Vals.p_Model));
+
+			if( R2 < R )
+			{
+				f_				= inf_cumf;
+				pt				= t - dTime;
+				inf_bPonding	= 1;
+
+				goto cont1;
+			}
+		}
+
+		f2				= inf_cumf + R * dTime;
+		R2				= -Vals.p_K0 / Vals.p_Model * (psi_dtheta + f2) / (1 - exp(f2 / Vals.p_Model));
+
+		if( f2 == 0.0 || R2 > R )
+		{
+			f				= R;
+			inf_cumf		+= f * dTime;
+			inf_bPonding	= 0;
+
+			return( f );
+		}
+
+		f_				= inf_cumf + R2 * dTime;
+
+		for(i=0; i<NEWTON_MAXITER; i++)
+		{
+			R2				= -Vals.p_K0 / Vals.p_Model * (psi_dtheta + f_) / (1 - exp(f_ / Vals.p_Model));
+
+			if( R2 > R )
+			{
+				f1				= f_;
+				f_				= (f_ + f2) / 2.0;
+				f				= f_ - f1;
+			}
+			else
+			{
+				f2				= f_;
+				f_				= (f_ + f1) / 2.0;
+				f				= f_ - f2;
+			}
+
+			if( fabs(f) < NEWTON_EPSILON )
+				break;
+		}
+
+		if( i == NEWTON_MAXITER )
+		{
+			// G_set_d_null_value(&f, 1);
+			return( 0.0 );
+		}
+
+		pt				= t - dTime + (f_ - inf_cumf) / R;
+
+		if( pt > t )
+		{
+			f				= R;
+			inf_cumf		+= f * dTime;
+			inf_bPonding	= 0;
+
+			return( f );
+		}
+
+cont1:
+		cnst			= 0.0;
+		factorial		= 1;
+		fc				= (f_ + psi_dtheta);
+
+		for(j=1; j<=NEWTON_NTERMS; j++)
+		{
+			factorial		*= j;
+			cnst			+= pow(fc / Vals.p_Model, (double) j) / (double) (j * factorial);
+		}
+
+		cnst			= log(fc) - (log(fc) + cnst) / exp(psi_dtheta / Vals.p_Model);
+		f_				+= R * (t - pt) / 2.0;
+		inf_bPonding	= 1;
+	}
+
+	for(i=0; i<NEWTON_MAXITER; i++)
+	{
+		fc				= f_ + psi_dtheta;
+		sum				= 0.0;
+		factorial		= 1;
+
+		for(j=1; j<=NEWTON_NTERMS; j++)
+		{
+			factorial		*= j;
+			sum				+= pow(fc / Vals.p_Model, (double) j) / (double) (j * factorial);
+		}
+
+		f1				= - (log(fc) - (log(fc) + sum) / exp(psi_dtheta / Vals.p_Model) - cnst) / (Vals.p_K0 / Vals.p_Model) - (t - pt);
+		f2				= (exp(f_ / Vals.p_Model) - 1.0) / (fc * Vals.p_K0 / Vals.p_Model);
+		f				= - f1 / f2;
+		f_				+= f;
+
+		if( fabs(f) < NEWTON_EPSILON )
+			break;
+	}
+
+	if( i == NEWTON_MAXITER )
+	{
+		// G_set_d_null_value(&f, 1);
+		return( 0.0 );
+	}
+
+	if( f_ < inf_cumf + R )
+	{
+		f				= (f_ - inf_cumf) / dTime;
+		inf_cumf		= f_;
+		f_				+= f * dTime;
+	}
+
+	return( f );
+}

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      topmodel.h                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__topmodel_H
+#define HEADER_INCLUDED__topmodel_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "topmodel_values.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTOPMODEL : public CSG_Module_Grid
+{
+public:
+	CTOPMODEL(void);
+	virtual ~CTOPMODEL(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	double				dTime, inf_cumf, inf_bPonding;
+
+	CSG_Table				*pClimate;
+
+	CTOPMODEL_Values	Vals;
+
+
+	void				Run(double Evaporation, double Infiltration, double Infiltration_Excess);
+
+	bool				Get_Climate(int iTimeStep, double &Precipitation, double &Evaporation);
+	double				Get_Infiltration(double t, double R);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__topmodel_H

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,342 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  topmodel_values.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "topmodel_values.h"
+
+//---------------------------------------------------------
+#define RESET_ARRAY(a)		if( a ) { free(a); a = NULL; }
+#define RESET_MATRIX(n, m)	if( n > 0 && m ) { for(int i=0; i<n; i++) { if( m[i] ) { free(m[i]); } } free(m); m = NULL; }
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTOPMODEL_Class::CTOPMODEL_Class(double Srz_Init)
+{
+	Srz_		= Srz_Init;
+	Suz_		= 0.0;
+	S_			= 0.0;
+
+	qt_			= 0.0;
+	qo_			= 0.0;
+	qv_			= 0.0;
+
+	AtanB		= 0.0;
+	Area_Rel	= 0.0;
+}
+
+//---------------------------------------------------------
+CTOPMODEL_Class::~CTOPMODEL_Class(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTOPMODEL_Values::CTOPMODEL_Values(void)
+{
+	nClasses	= 0;
+	Lambda		= 0;
+
+	Add			= NULL;
+	Qt_			= NULL;
+
+	//-----------------------------------------------------
+	Channel_Count			= 3;
+
+	Channel_Distance		= (double *)malloc(Channel_Count * sizeof(double));
+	Channel_AreaRatio		= (double *)malloc(Channel_Count * sizeof(double));
+
+	Channel_Distance[0]		= 500;
+	Channel_AreaRatio[0]	= 0.0;
+
+	Channel_Distance[1]		= 1000;
+	Channel_AreaRatio[1]	= 0.5;
+
+	Channel_Distance[2]		= 1500;
+	Channel_AreaRatio[2]	= 1.0;
+}
+
+//---------------------------------------------------------
+CTOPMODEL_Values::~CTOPMODEL_Values(void)
+{
+	Destroy();
+
+	free(Channel_Distance);
+	free(Channel_AreaRatio);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CTOPMODEL_Values::Destroy(void)
+{
+	int		iClass;
+
+	if( nClasses > 0 )
+	{
+		for(iClass=0; iClass<nClasses; iClass++)
+		{
+			delete( Classes[iClass] );
+		}
+
+		free(Classes);
+
+		nClasses	= 0;
+	}
+
+	qt_Total	= 0.0;
+	qo_Total	= 0.0;
+	qv_Total	= 0.0;
+
+	RESET_ARRAY(Add);
+	RESET_ARRAY(Qt_);
+}
+
+//---------------------------------------------------------
+void CTOPMODEL_Values::Create(double dTime, int anTimeSteps, CSG_Parameters *pParameters, CSG_Grid *pAtanB, int anClasses, CSG_Grid *pClass)
+{
+	int		n, iClass, nCells;
+
+	double	zMin, zRange, dz;
+
+	Destroy();
+
+	if( pAtanB && anClasses > 0 )
+	{
+		//-------------------------------------------------
+		// 1. Topographic Index Classification etc...
+
+		nClasses	= anClasses;
+
+		Classes		= (CTOPMODEL_Class **)calloc(nClasses, sizeof(CTOPMODEL_Class *));
+
+		for(iClass=0; iClass<nClasses; iClass++)
+		{
+			Classes[iClass]	= new CTOPMODEL_Class(pParameters->Get_Parameter("P_SR0")->asDouble());
+		}
+
+		zMin		= pAtanB->Get_ZMin();
+		zRange		= pAtanB->Get_ZMax() - zMin;
+		dz			= zRange / (nClasses + 1);
+		nCells		= 0;
+
+		pClass->Create(pAtanB, SG_DATATYPE_Short);
+		pClass->Set_NoData_Value(-9999);
+
+		for(n=0; n<pAtanB->Get_NCells(); n++)
+		{
+			if( !pAtanB->is_NoData(n) )
+			{
+				nCells++;
+
+				iClass			= (int)((nClasses - 1.0) * (pAtanB->asDouble(n) - zMin) / zRange);
+
+				Classes[iClass]->Area_Rel++;
+
+				pClass->Set_Value(n, iClass);
+			}
+			else
+			{
+				pClass->Set_NoData(n);
+			}
+		}
+
+		Area_Total	= (double)nCells * pAtanB->Get_Cellsize() * pAtanB->Get_Cellsize();
+
+		for(iClass=0; iClass<nClasses; iClass++)
+		{
+			Classes[iClass]->AtanB		= zMin + dz * (iClass + 0.5);	// mid of class -> + 0.5...
+			Classes[iClass]->Area_Rel	/= (double)nCells;
+		}
+
+
+		//-------------------------------------------------
+		// 2. Calculate Lambda, the catchment average topographic index...
+
+		for(iClass=0, Lambda=0.0; iClass<nClasses; iClass++)
+		{
+			Lambda	+= Classes[iClass]->Area_Rel * Classes[iClass]->AtanB;
+		}
+
+
+		//-------------------------------------------------
+		// 3. Parameter Initialisation...
+
+		//-------------------------------------------------
+		p_Srz_Max		= pParameters->Get_Parameter("P_SRZMAX")->asDouble();
+		p_Model			= pParameters->Get_Parameter("P_MODEL")->asDouble();
+		p_Suz_TimeDelay	= pParameters->Get_Parameter("P_SUZ_TD")->asDouble();
+		p_K0			= pParameters->Get_Parameter("P_K0")->asDouble();
+		p_Psi			= pParameters->Get_Parameter("P_PSI")->asDouble();
+		p_dTheta		= pParameters->Get_Parameter("P_DTHETA")->asDouble();
+
+
+		//-------------------------------------------------
+		int		i, j, t;
+
+		double	A1, A2,
+				qs0_,	// Initial subsurface flow per unit area [m/h], "The first streamflow input is assumed to represent only the subsurface flow contribution in the watershed."
+				vch_,	// Main channel routing velocity [m/h]
+				vr_,	// Internal subcatchment routing velocity [m/h]
+				*tch_;	// params.nch's
+
+		//-------------------------------------------------
+		lnTe_		= log(dTime)	+ pParameters->Get_Parameter("P_LNTE")->asDouble();
+		vch_		= dTime			* pParameters->Get_Parameter("P_VCH")->asDouble();
+		vr_			= dTime			* pParameters->Get_Parameter("P_VR")->asDouble();
+		qs0_		= dTime			* pParameters->Get_Parameter("P_QS0")->asDouble();
+		_qs_		= exp(lnTe_ - Lambda);
+
+		//-------------------------------------------------
+		tch_		= (double *)malloc(Channel_Count * sizeof(double));
+		tch_[0]		= Channel_Distance[0] / vch_;
+
+		for(i=1; i<Channel_Count; i++)
+		{
+			tch_[i]		= tch_[0] + (Channel_Distance[i] - Channel_Distance[0]) / vr_;
+		}
+
+		//-------------------------------------------------
+		nreach_		= (int)tch_[Channel_Count - 1];
+		if( (double)nreach_ < tch_[Channel_Count - 1] )
+		{
+			nreach_++;
+		}
+
+		ndelay_		= (int)tch_[0];
+		nreach_		-= ndelay_;
+
+		//-------------------------------------------------
+		Add			= (double *)malloc(nreach_ * sizeof(double));
+
+		for(i=0; i<nreach_; i++)
+		{
+			t			= ndelay_ + i + 1;
+			if( t > tch_[Channel_Count - 1])
+			{
+				Add[i]		= 1.0;
+			}
+			else
+			{
+				for(j=1; j<Channel_Count; j++)
+				{
+					if( t <= tch_[j] )
+					{
+						Add[i]		= Channel_AreaRatio[j - 1]
+									+ (Channel_AreaRatio[j] - Channel_AreaRatio[j - 1])
+									* (t - tch_[j - 1]) / (tch_[j] - tch_[j - 1]);
+						break;
+					}
+				}
+			}
+		}
+
+		A1			= Add[0];
+		Add[0]		*= Area_Total;
+
+		for(i=1; i<nreach_; i++)
+		{
+			A2			= Add[i];
+			Add[i]		= A2 - A1;
+			A1			= A2;
+			Add[i]		*= Area_Total;
+		}
+
+		//-------------------------------------------------
+		Sbar_		= -p_Model * log(qs0_ / _qs_);
+
+		//-------------------------------------------------
+		Qt_			= (double *)calloc(anTimeSteps, sizeof(double));
+		for(i=0; i<anTimeSteps; i++)
+		{
+			Qt_[i]		= 0.0;
+		}
+
+		for(i=0; i<ndelay_; i++)
+		{
+			Qt_[i] = qs0_ * Area_Total;
+		}
+
+		A1			= 0.0;
+
+		for(i=0; i<nreach_; i++)
+		{
+			A1					+= Add[i];
+			Qt_[ndelay_ + i]	= qs0_ * (Area_Total - A1);
+		}
+
+		//-------------------------------------------------
+		RESET_ARRAY(tch_);
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_simulation/hydrology/sim_hydrology/topmodel_values.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,183 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     sim_hydrology                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   topmodel_values.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__topmodel_values_H
+#define HEADER_INCLUDED__topmodel_values_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTOPMODEL_Class
+{
+public:
+	CTOPMODEL_Class(double Srz_Init);
+	virtual ~CTOPMODEL_Class(void);
+
+	double				qt_, qo_, qv_,
+						Srz_, Suz_, S_,
+						AtanB, Area_Rel;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTOPMODEL_Values
+{
+public:
+	CTOPMODEL_Values(void);
+	virtual ~CTOPMODEL_Values(void);
+
+	int					ndelay_, nreach_;
+
+	double				qt_Total, qo_Total, qv_Total,
+						qs_Total,
+
+						lnTe_,
+						_qs_,
+
+						*Add,				// nreach_'s:
+
+						*Qt_,				// input.ntimestep's:
+
+						Sbar_,
+
+						p_Srz_Max,			// Maximum root zone storage deficit [m]
+						p_Model,			// Model parameter m...
+						p_Suz_TimeDelay,	// Unsaturated zone time delay per unit storage deficit ( > 0.0) [h]
+											// OR -alpha: Effective vertical hydraulic gradient ( <= 0.0); -10 means that alpha = 10
+						p_K0,				// Surface hydraulic conductivity [m/h]
+						p_Psi,				// Wetting front suction [m]
+						p_dTheta;			// Water content change across the wetting front
+
+
+	void				Create(double dTime, int anTimeSteps, CSG_Parameters *pParameters, CSG_Grid *pAtanB, int anClasses, CSG_Grid *pClass);
+	void				Destroy(void);
+
+	//-----------------------------------------------------
+	int					Get_Count(void)
+	{
+		return( nClasses );
+	}
+
+	//-----------------------------------------------------
+	double				Get_Area_Total(void)
+	{
+		return( Area_Total );
+	}
+
+	//-----------------------------------------------------
+	CTOPMODEL_Class *	Get_Class(int iClass)
+	{
+		if( iClass >= 0 && iClass < nClasses )
+		{
+			return( Classes[iClass] );
+		}
+
+		return( NULL );
+	}
+
+	//-----------------------------------------------------
+	double				Get_Lambda(void)
+	{
+		return( Lambda );
+	}
+
+
+private:
+
+	int					nClasses, Channel_Count;
+
+	double				Lambda, *Channel_Distance, *Channel_AreaRatio,
+						Area_Total;		// Total catchment area [m^2]
+
+	CTOPMODEL_Class		**Classes;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__topmodel_values_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,802 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  ChannelNetwork.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ChannelNetwork.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CChannelNetwork::CChannelNetwork(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Channel Network"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This module derives a channel network based on gridded digital elevation data.\n"
+		"Use the initiation options to determine under which conditions channels shall start.\n"
+		"\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL("A grid that contains elevation data."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SINKROUTE"	, _TL("Flow Direction"),
+		_TW(
+		"An optional grid that provides information about flow directions. \n"
+		"Values between 1 to 8 force the flow of a cell to be given to one its adjacent neighbor cells "
+		"(1->NE, 2->E, 3->SE, 4->S, 5->SW, 6->W, 7->NW, 8->N). "
+		"In case of other values the algorithm will use its own routing scheme. \n"
+		"This option is in particular useful to supply the algorithm with routes that lead the flow through closed depression. "),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "CHNLNTWRK"	, _TL("Channel Network"),
+		_TW("If a cell is part of a channel its value equals the channel order. "
+		"Otherwise the cell is marked as no-data."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CHNLROUTE"	, _TL("Channel Direction"),
+		_TW("If a cell is part of a channel then its value shows the flow direction of the channel "
+		"(1->NE, 2->E, 3->SE, 4->S, 5->SW, 6->W, 7->NW, 8->N). "
+		"Otherwise the cell is marked as no-data."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "SHAPES"		, _TL("Channel Network"),
+		_TL("This shapes layer will contain the resulting channel network in vector format (lines)."),
+		PARAMETER_OUTPUT		, SHAPE_TYPE_Line
+	);
+
+
+	//-----------------------------------------------------
+	// Initiation...
+
+	pNode	= Parameters.Add_Grid(
+		NULL	, "INIT_GRID"	, _TL("Initiation Grid"),
+		_TW("Dependent on the chosen 'Initiation Type' and 'Initiation Threshold' "
+		"the values of this grid control where a channel is initiated."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "INIT_METHOD"	, _TL("Initiation Type"),
+		_TL("Options:\n - Less than\n - Equals\n - Greater than\nControls under which condition a channel is initiated."),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Less than"),
+			_TL("Equals"),
+			_TL("Greater than")
+		), 2
+	);
+
+	Parameters.Add_Value(
+		pNode	, "INIT_VALUE"	, _TL("Initiation Threshold"),
+		_TL("Dependent on the chosen 'Initiation Grid' and 'Initiation Type' this value controls under which condition a channel is initiated."),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Grid(
+		NULL	, "DIV_GRID"	, _TL("Divergence"),
+		_TL("Tracing: Convergence"),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DIV_CELLS"	, _TL("Tracing: Max. Divergence"),
+		_TL("Tracing: Stop after x cells with divergent flow"),
+		PARAMETER_TYPE_Int		, 5, 1, true
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "TRACE_WEIGHT", _TL("Tracing: Weight"),
+		_TL("Tracing: Weight"),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MINLEN"		, _TL("Min. Segment Length"),
+		_TL("Minimum Segment Length (Cells)"),
+		PARAMETER_TYPE_Int		, 10
+	);
+}
+
+//---------------------------------------------------------
+CChannelNetwork::~CChannelNetwork(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CChannelNetwork::On_Execute(void)
+{
+	int		x, y, ID, Trace_Method, Init_Method;
+	long	n;
+	double	Init_Threshold;
+	CSG_Grid	*Trace_pRoute, *Trace_pWeight, *Init_pGrid;
+
+
+	//-----------------------------------------------------
+	pDTM				= Parameters("ELEVATION")	->asGrid();
+	pConvergence		= Parameters("DIV_GRID")	->asGrid();
+
+	pChannels			= Parameters("CHNLNTWRK")	->asGrid();
+	pChannelRoute		= Parameters("CHNLROUTE")	->asGrid();
+	pShapes				= Parameters("SHAPES")		->asShapes();
+
+	minLength			= Parameters("MINLEN")		->asInt();
+
+	maxDivCells			= Parameters("DIV_GRID")->asGrid() ? Parameters("DIV_CELLS")->asInt() : -1;
+
+
+	//-----------------------------------------------------
+	// 1. Flow Direction...
+
+	Process_Set_Text(_TL("Channel Network: Pass 1"));
+
+	pChannels->Assign();
+
+	Trace_pRoute		= Parameters("SINKROUTE")	->asGrid();
+	Trace_pWeight		= Parameters("TRACE_WEIGHT")->asGrid();
+	Trace_Method		= Trace_pWeight ? 1 : 0;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( Trace_pRoute && (ID = Trace_pRoute->asChar(x, y)) >= 1 && ID <= 8 )
+			{
+				pChannels->Set_Value(x, y, ID);
+			}
+			else
+			{
+				switch( Trace_Method )
+				{
+				default:
+					Set_Route_Standard(x, y);
+					break;
+
+				case 1:
+					Set_Route_Weighted(x, y, Trace_pWeight, 0.0);
+					break;
+				}
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// 2. Initiation...
+
+	Process_Set_Text(_TL("Channel Network: Pass 2"));
+
+	pStart				= SG_Create_Grid(pDTM, SG_DATATYPE_Char);
+	Init_pGrid			= Parameters("INIT_GRID")	->asGrid();
+	Init_Method			= Parameters("INIT_METHOD")	->asInt();
+	Init_Threshold		= Parameters("INIT_VALUE")	->asDouble();
+
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		switch( Init_Method )
+		{
+		case 0:
+			if( Init_pGrid->asDouble(n) <= Init_Threshold )
+				pStart->Set_Value(n, 1);
+			break;
+
+		case 1:
+			if( Init_pGrid->asDouble(n) == Init_Threshold )
+				pStart->Set_Value(n, 1);
+			break;
+
+		case 2:
+			if( Init_pGrid->asDouble(n) >= Init_Threshold )
+				pStart->Set_Value(n, 1);
+			break;
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// 3. Trace Channel Routes...
+
+	Process_Set_Text(_TL("Channel Network: Pass 3"));
+
+	pChannelRoute->Assign();
+
+	Direction			= NULL;
+	Direction_Buffer	= 0;
+
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( pDTM->Get_Sorted(n,x,y) )
+		{
+			Set_Channel_Route(x,y);
+		}
+	}
+
+	if( Direction )
+	{
+		SG_Free( Direction );
+	}
+
+	pChannels->Assign();
+
+	delete(pStart);
+
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Channel Network: Pass 4"));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Set_Channel_Order(x,y);
+		}
+	}
+
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Channel Network: Pass 5"));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Set_Channel_Mouth(x,y);
+		}
+	}
+
+
+	//-----------------------------------------------------
+	if( pShapes )
+	{
+		Process_Set_Text(_TL("Channel Network: Pass 6"));
+
+		pShapes->Create(SHAPE_TYPE_Line, _TL("Channel Network"));
+
+		pShapes->Add_Field("SegmentID"	,SG_DATATYPE_Int);
+		pShapes->Add_Field("Order"		,SG_DATATYPE_Int);
+		pShapes->Add_Field("Length"		,SG_DATATYPE_Double);
+
+		Lock_Create();
+
+		for(y=0, ID=1; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				Set_Vector(x, y, ID++);
+			}
+		}
+
+		Lock_Destroy();
+	}
+
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells(); n++)
+	{
+		if( pChannels->asInt(n) == 0 )
+		{
+			pChannels->Set_NoData(n);
+			pChannelRoute->Set_NoData(n);
+		}
+	}
+
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork::Set_Route_Standard(int x, int y)
+{
+	int		i, ix, iy, iMin;
+
+	double	z, dz, dzMin;
+
+	z		= pDTM->asDouble(x,y);
+	iMin	= 0;
+
+	for(i=1; i<=8; i++)
+	{
+		ix		= Get_xTo(i,x);
+		iy		= Get_yTo(i,y);
+
+		if( !pDTM->is_InGrid(ix,iy) )
+		{
+			iMin	= i;
+			break;
+		}
+		else
+		{
+			dz		= (z - pDTM->asDouble(ix,iy)) / Get_Length(i);
+
+			if( iMin <= 0 || dzMin < dz )
+			{
+				iMin	= i;
+				dzMin	= dz;
+			}
+		}
+	}
+
+	pChannels->Set_Value(x,y, iMin );
+}
+
+//---------------------------------------------------------
+void CChannelNetwork::Set_Route_Weighted(int x, int y, CSG_Grid *pWeight, double Weight_Threshold)
+{
+	bool	bMin;
+
+	int		i, ix, iy, iMin;
+
+	double	z, dz, dzMin, w, wMin;
+
+	z		= pDTM->asDouble(x,y);
+	iMin	= 0;
+
+	for(i=1; i<=8; i++)
+	{
+		ix		= Get_xTo(i,x);
+		iy		= Get_yTo(i,y);
+
+		if( !pDTM->is_InGrid(ix, iy) )
+		{
+			iMin	= i;
+			break;
+		}
+		else
+		{
+			dz		= (z - pDTM->asDouble(ix,iy)) / Get_Length(i);
+
+			if( dz > 0 )
+			{
+				bMin	= false;
+				w		= pWeight->asDouble(ix,iy);
+
+				if(	iMin <= 0 )
+				{
+					bMin	= true;
+				}
+				else if( Weight_Threshold > 0 )
+				{
+					if( w > Weight_Threshold && wMin > Weight_Threshold )
+					{
+						if( dzMin < dz )
+						{
+							bMin	= true;
+						}
+					}
+					else if( wMin < w )
+					{
+						bMin	= true;
+					}
+				}
+				else if( wMin < w )
+				{
+					bMin	= true;
+				}
+
+				if( bMin )
+				{
+					iMin	= i;
+					wMin	= w;
+					dzMin	= dz;
+				}
+			}
+		}
+	}
+
+	pChannels->Set_Value(x,y, iMin );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork::Set_Channel_Route(int x, int y)
+{
+	const int	BUFFER_GROWSIZE	= 256;
+
+	int		xStart, yStart, i, ix, iy, goDir, m, n, nDiv;
+
+	double	z, dz, dzMin, Length;
+
+	//-----------------------------------------------------
+	if( pStart->asChar(x,y) && !pChannelRoute->asChar(x,y) )
+	{
+		Lock_Create();
+
+		n		= 0;
+		nDiv	= 0;
+		Length	= 0;
+		xStart	= x;
+		yStart	= y;
+
+		do
+		{
+			//---------------------------------------------
+			// 1. Divergence ?!...
+
+			if( pConvergence )
+			{
+				if( pConvergence->asDouble(x,y) > -1.0 )
+				{
+					nDiv++;
+				}
+				else
+				{
+					nDiv	= 0;
+				}
+			}
+
+			if( pConvergence && nDiv > maxDivCells )
+			{
+				goDir	= -1;
+			}
+			else
+			{
+				//-----------------------------------------
+				// 2. Is there any channel around ?!...
+
+				goDir	= 0;
+				z		= pDTM->asDouble(x,y);
+
+				for(i=1; i<=8; i++)
+				{
+					ix		= Get_xTo(i,x);
+					iy		= Get_yTo(i,y);
+
+					if( pDTM->is_InGrid(ix,iy) && !is_Locked(ix,iy) && pChannelRoute->asChar(ix,iy) )
+					{
+						dz		= (z - pDTM->asDouble(ix,iy)) / Get_Length(i);
+
+						if( goDir <= 0 || dzMin < dz )
+						{
+							goDir	= i;
+							dzMin	= dz;
+						}
+					}
+				}
+
+				if( goDir <= 0 )	// ...if not then go as usual...
+				{
+					goDir	= pChannels->asInt(x,y);
+				}
+
+
+				//-----------------------------------------
+				// 3. Go to Drainage Direction !...
+
+				if(	goDir > 0 )
+				{
+					Lock_Set(x,y);
+
+					x		= Get_xTo(goDir,x);
+					y		= Get_yTo(goDir,y);
+
+					Length	+= Get_UnitLength(goDir);
+
+					if( n >= Direction_Buffer )
+					{
+						Direction_Buffer	+= BUFFER_GROWSIZE;
+						Direction			= (int *)SG_Realloc(Direction, Direction_Buffer * sizeof(int));
+					}
+
+					Direction[n++]	= goDir;
+				}
+			}
+		}
+		while( goDir > 0 && pDTM->is_InGrid(x,y) && !is_Locked(x,y) && !pChannelRoute->asChar(x,y) );
+
+
+		//-------------------------------------------------
+		if( Length >= minLength )
+		{
+			x	= xStart;
+			y	= yStart;
+
+			if( goDir < 0 )
+			{
+				n	-= nDiv;
+			}
+
+			for(m=0; m<n; m++)
+			{
+				goDir	= Direction[m];
+
+				pChannelRoute->Set_Value(x,y,goDir);
+
+				for(i=0; i<8; i++)	// Don't start new channels beside existing ones...
+				{
+					ix		= Get_xTo(i,x);
+					iy		= Get_yTo(i,y);
+
+					if( pDTM->is_InGrid(ix,iy) )
+					{
+						pStart->Set_Value(ix,iy,0);
+					}
+				}
+
+				x	= Get_xTo(goDir,x);
+				y	= Get_yTo(goDir,y);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork::Set_Channel_Order(int x, int y)
+{
+	int		i, ix, iy, j, n;
+
+	//-----------------------------------------------------
+	if( pChannelRoute->asChar(x,y) > 0 )
+	{
+		for(i=n=0, j=4; i<8; i++, j=(j+1)%8)
+		{
+			ix	= Get_xTo(i,x);
+			iy	= Get_yTo(i,y);
+
+			if( pDTM->is_InGrid(ix,iy) && pChannelRoute->asChar(ix,iy) && j == pChannelRoute->asChar(ix,iy) % 8 )
+			{
+				n++;
+			}
+		}
+
+		//-----------------------------------------------------
+		if( n == 0 )
+		{
+			Lock_Create();
+
+			do
+			{
+				Lock_Set(x,y);
+
+				pChannels->Add_Value(x,y, 1 );
+
+				i	= pChannelRoute->asChar(x,y);
+
+				if( i > 0 )
+				{
+					x	= Get_xTo(i,x);
+					y	= Get_yTo(i,y);
+				}
+			}
+			while( pDTM->is_InGrid(x,y) && i > 0 && !is_Locked(x,y) );
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CChannelNetwork::Set_Channel_Mouth(int x, int y)
+{
+	int		Order, goDir, ix, iy;
+
+	Order	= pChannels->asInt(x,y);
+
+	if( Order > 0 )
+	{
+		goDir	= pChannelRoute->asChar(x,y);
+
+		if( goDir > 0 )
+		{
+			ix	= Get_xTo(goDir,x);
+			iy	= Get_yTo(goDir,y);
+
+			if( !pDTM->is_InGrid(ix,iy) || (pChannels->asInt(ix,iy) > 0 && Order != pChannels->asInt(ix,iy)) )
+			{
+				pChannels->Set_Value(x,y, -1 );
+			}
+		}
+		else
+		{
+			pChannels->Set_Value(x,y, -1 );
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork::Set_Vector(int x, int y, int ID)
+{
+	bool	bContinue;
+
+	int		i, ix, iy, j, Order;
+
+	double	xMin, yMin, Length;
+
+	CSG_Shape	*pShape;
+
+	//-----------------------------------------------------
+	if( (Order = pChannels->asInt(x,y)) > 0 )
+	{
+		bContinue	= true;
+
+		for(i=0, j=4; i<8 && bContinue; i++, j=(j+1)%8)
+		{
+			ix	= Get_xTo(i,x);
+			iy	= Get_yTo(i,y);
+
+			if(	pDTM->is_InGrid(ix,iy)
+			&&	pChannels->asInt(ix,iy) == Order
+			&&	pChannelRoute->asChar(ix,iy) && j == pChannelRoute->asChar(ix,iy) % 8 )
+			{
+				bContinue	= false;
+			}
+		}
+
+		//-------------------------------------------------
+		if( bContinue )	// Startpunkt gefunden...
+		{
+			xMin	= pDTM->Get_XMin(),
+			yMin	= pDTM->Get_YMin();
+			ID		= 1;
+
+			pShape	= pShapes->Add_Shape();
+
+			do
+			{
+				bContinue	= false;
+				Length		= 0;
+
+				Lock_Set(x,y);
+
+				pShape->Add_Point(xMin + x * Get_Cellsize(), yMin + y * Get_Cellsize());
+
+				i	= pChannelRoute->asChar(x,y);
+
+				if( i > 0 )
+				{
+					ix		= Get_xTo(i,x);
+					iy		= Get_yTo(i,y);
+
+					Length	+= Get_Length(i);
+
+					if( pDTM->is_InGrid(ix,iy) )
+					{
+						if(	!is_Locked(ix,iy)
+						&&	(	pChannels->asInt(ix,iy) == Order
+							||	pChannels->asInt(ix,iy) < 0) )
+						{
+							x			= ix;
+							y			= iy;
+							bContinue	= true;
+						}
+						else
+						{
+							pShape->Add_Point(xMin + ix * Get_Cellsize(), yMin + iy * Get_Cellsize());
+						}
+					}
+				}
+			}
+			while( bContinue );
+
+			pShape->Set_Value(0, ID );
+			pShape->Set_Value(1, Order );
+			pShape->Set_Value(2, Length );
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   ChannelNetwork.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ChannelNetwork_H
+#define HEADER_INCLUDED__ChannelNetwork_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_channels_EXPORT CChannelNetwork : public CSG_Module_Grid
+{
+public:
+	CChannelNetwork(void);
+	virtual ~CChannelNetwork(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	int						*Direction, Direction_Buffer, minLength, maxDivCells;
+
+	CSG_Grid					*pDTM, *pStart, *pTrace, *pConvergence, *pChannels, *pChannelRoute;
+
+	CSG_Shapes					*pShapes;
+
+
+	void					Set_Route_Standard	(int x, int y);
+	void					Set_Route_Weighted	(int x, int y, CSG_Grid *pWeight, double Weight_Threshold);
+
+	void					Set_Channel_Route	(int x, int y);
+	void					Set_Channel_Order	(int x, int y);
+	void					Set_Channel_Mouth	(int x, int y);
+
+	void					Set_Vector			(int x, int y, int ID);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ChannelNetwork_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,381 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              ChannelNetwork_Altitude.cpp              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ChannelNetwork_Altitude.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CChannelNetwork_Altitude::CChannelNetwork_Altitude(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Vertical Distance to Channel Network"));
+
+	Set_Author		(SG_T("(c) 2002 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This module calculates the vertical distance to a channel network base level. "
+		"The algorithm consists of two major steps:\n"
+		" 1. Interpolation of a channel network base level elevation grid\n"
+		" 2. Subtraction of this grid from the original elevations\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL, "ELEVATION"	, _TL("Elevation"),
+		_TL("A grid that contains elevation data."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "CHANNELS"	, _TL("Channel Network"),
+		_TW("A grid providing information about the channel network. It is assumed that no-data cells are not part "
+		"of the channel network. Vice versa all others cells are recognised as channel network members."),
+		PARAMETER_INPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL, "ALTITUDE"	, _TL("Vertical Distance to Channel Network"),
+		_TL("The resulting grid gives the altitude above the channel network in the same units as the elevation data."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "BASELEVEL"	, _TL("Channel Network Base Level"),
+		_TL("This optional grid output contains the interpolated channel network base level elevations."),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL, "THRESHOLD"	, _TL("Tension Threshold [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 0.1
+	);
+
+	Parameters.Add_Value(
+		NULL, "NOUNDERGROUND", _TL("Keep Base Level below Surface"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, true
+	);
+}
+
+//---------------------------------------------------------
+CChannelNetwork_Altitude::~CChannelNetwork_Altitude(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CChannelNetwork_Altitude::On_Execute(void)
+{
+	int			n, nCells, nCells_Start, iStep, nSteps;
+	double		max_Change, Threshold;
+
+	//-----------------------------------------------------
+	pDTM				= Parameters("ELEVATION")		->asGrid();
+	pChannels			= Parameters("CHANNELS")		->asGrid();
+
+	pResult				= Parameters("ALTITUDE")		->asGrid();
+
+	Threshold			= Parameters("THRESHOLD")		->asDouble();
+	m_bNoUnderground	= Parameters("NOUNDERGROUND")	->asBool();
+
+	//-----------------------------------------------------
+	nCells			= Get_NX() > Get_NY() ? Get_NX() : Get_NY();
+	for(nSteps=0; pow(2.0, nSteps + 1) < nCells; nSteps++);
+	nCells_Start	= (int)pow(2.0, nSteps);
+
+	//-----------------------------------------------------
+	pResult->Assign_NoData();
+
+	pT_Chnl			= SG_Create_Grid(pResult, SG_DATATYPE_Byte);
+	pT_Temp			= SG_Create_Grid(pResult);
+
+	for(nCells=nCells_Start, iStep=1; nCells>0; nCells/=2, iStep++)
+	{
+		Process_Set_Text(CSG_String::Format(SG_T("%d [%d]"), iStep, nSteps + 1));
+
+		Initialize_Surface(nCells);
+
+		do
+		{
+			max_Change	= Set_Surface(nCells);
+		}
+		while( max_Change > Threshold && Process_Get_Okay(true) );
+	}
+
+	delete(pT_Chnl);
+	delete(pT_Temp);
+
+	//-----------------------------------------------------
+	if( Parameters("BASELEVEL")->asGrid() )
+	{
+		Parameters("BASELEVEL")->asGrid()->Assign(pResult);
+	}
+
+	for(n=0; n<Get_NCells(); n++)
+	{
+		if( pResult->is_NoData(n) || pDTM->is_NoData(n) )
+		{
+			pResult->Set_NoData(n);
+		}
+		else
+		{
+			pResult->Set_Value(n, pDTM->asDouble(n) - pResult->asDouble(n));
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork_Altitude::Initialize_Surface(int nCells)
+{
+	int		x, y, i, ix, iy, nx, ny, nz;
+
+	double	z;
+
+	//-----------------------------------------------------
+	// 1. Channels...
+
+	pT_Temp->Assign_NoData();
+	pT_Chnl->Assign();
+
+	for(y=0; y<Get_NY(); y+=nCells)
+	{
+		ny	= y + nCells < Get_NY() ? y + nCells : Get_NY();
+
+		for(x=0; x<Get_NX(); x+=nCells)
+		{
+			nx	= x + nCells < Get_NX() ? x + nCells : Get_NX();
+			nz	= 0;
+			z	= 0.0;
+
+			for(iy=y; iy<ny; iy++)
+			{
+				for(ix=x; ix<nx; ix++)
+				{
+					if( pChannels->is_InGrid(ix, iy) )
+					{
+						z	+= pDTM->asDouble(ix, iy);
+						nz++;
+					}
+				}
+			}
+
+			if( nz > 0 )
+			{
+				pT_Temp->Set_Value(x, y, z / (double)nz );
+				pT_Chnl->Set_Value(x, y, 1.0);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	// 2. Previous Iteration...
+
+	for(y=0; y<Get_NY(); y+=nCells)
+	{
+		for(x=0; x<Get_NX(); x+=nCells)
+		{
+			if( pT_Chnl->asByte(x, y) == false )
+			{
+				if( !pResult->is_NoData(x, y) )
+				{
+					pT_Temp->Set_Value(x, y, pResult->asDouble(x, y));
+				}
+				else
+				{
+					nz	= 0;
+					z	= 0.0;
+
+					for(i=0; i<8; i++)
+					{
+						ix	= x + nCells * Get_xTo(i);
+						iy	= y + nCells * Get_yTo(i);
+
+						if( pResult->is_InGrid(ix, iy) )
+						{
+							z	+= pResult->asDouble(ix, iy);
+							nz++;
+						}
+					}
+
+					if( nz > 0.0 )
+					{
+						pT_Temp->Set_Value(x, y, z / (double)nz);
+					}
+					else
+					{
+						pT_Temp->Set_Value(x, y, pDTM->asDouble(x, y));
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	// 3. ...
+
+	pResult->Assign(pT_Temp);
+}
+
+//---------------------------------------------------------
+double CChannelNetwork_Altitude::Set_Surface(int nCells)
+{
+	int		x, y;
+
+	double	d, dMax;
+
+	dMax	= 0.0;
+
+	for(y=0; y<Get_NY(); y+=nCells)
+	{
+		for(x=0; x<Get_NX(); x+=nCells)
+		{
+			if( pT_Chnl->asByte(x, y) == false )
+			{
+				d	= Get_Changed(x, y, nCells);
+
+				pT_Temp->Set_Value(x, y, d);
+
+				d	= fabs(d - pResult->asDouble(x, y));
+
+				if( d > dMax )
+				{
+					dMax	= d;
+				}
+			}
+		}
+	}
+
+	for(y=0; y<Get_NY(); y+=nCells)
+	{
+		for(x=0; x<Get_NX(); x+=nCells)
+		{
+			if( pT_Chnl->asByte(x, y) == false )
+			{
+				pResult->Set_Value(x, y, pT_Temp->asDouble(x, y));
+			}
+		}
+	}
+
+	return( dMax );
+}
+
+
+//---------------------------------------------------------
+double CChannelNetwork_Altitude::Get_Changed(int x, int y, int nCells)
+{
+	int		i, ix, iy;
+
+	double	n, d, dz;
+
+	for(i=0, d=0.0, n=0.0; i<8; i++)
+	{
+		ix	= x + nCells * Get_xTo(i);
+		iy	= y + nCells * Get_yTo(i);
+
+		if( pResult->is_InGrid(ix, iy) )
+		{
+			dz	= 1.0 / Get_UnitLength(i);
+			d	+= dz * pResult->asDouble(ix, iy);
+			n	+= dz;
+		}
+	}
+
+	if( n > 0.0 )
+	{
+		d	/= n;
+
+		return( m_bNoUnderground && d > pDTM->asDouble(x, y) ? pDTM->asDouble(x, y) : d );
+	}
+
+	return( pResult->asDouble(x, y) );
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Altitude.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               ChannelNetwork_Altitude.h               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ChannelNetwork_Altitude_H
+#define HEADER_INCLUDED__ChannelNetwork_Altitude_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_channels_EXPORT CChannelNetwork_Altitude : public CSG_Module_Grid  
+{
+public:
+	CChannelNetwork_Altitude(void);
+	virtual ~CChannelNetwork_Altitude(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	bool					m_bNoUnderground;
+
+	CSG_Grid				*pDTM, *pChannels, *pResult, *pT_Chnl, *pT_Temp;
+
+
+	void					Initialize_Surface	(int nCells);
+	double					Set_Surface			(int nCells);
+	double					Get_Changed			(int x, int y, int nCells);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ChannelNetwork_Altitude_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,414 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              ChannelNetwork_Distance.cpp              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "ChannelNetwork_Distance.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CChannelNetwork_Distance::CChannelNetwork_Distance(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Overland Flow Distance to Channel Network"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This module calculates overland flow distances to a channel network "
+		"based on gridded digital elevation data and channel network information.\n"
+		"The flow algorithm may be either Deterministic 8 (O'Callaghan & Mark 1984) or Multiple Flow Direction (Freeman 1991)\n"
+		"\n\nReferences:\n"
+		"\n- Freeman, G.T., 1991: 'Calculating catchment area with divergent flow based on a regular grid', Computers and Geosciences, 17:413-22\n"
+		"\n- O'Callaghan, J.F., Mark, D.M., 1984: 'The extraction of drainage networks from digital elevation data', Computer Vision, Graphics and Image Processing, 28:323-344\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL("A grid that contains elevation data."),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CHANNELS"	, _TL("Channel Network"),
+		_TW("A grid providing information about the channel network. It is assumed that no-data cells are not part "
+		"of the channel network. Vice versa all others cells are recognised as channel network members."),
+		PARAMETER_INPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "DISTANCE"	, _TL("Overland Flow Distance"),
+		_TW("The overland flow distance in map units. "
+		"It is assumed that the (vertical) elevation data use the same units as the (horizontal) grid coordinates."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "DISTVERT"	, _TL("Vertical Overland Flow Distance"),
+		_TL("This is the vertical component of the overland flow"),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "DISTHORZ"	, _TL("Horizontal Overland Flow Distance"),
+		_TL("This is the horizontal component of the overland flow"),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Flow Algorithm"),
+		_TL("Choose a flow routing algorithm that shall be used for the overland flow distance calculation:\n- D8\n- MFD"),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("D8"),
+			_TL("MFD")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CChannelNetwork_Distance::~CChannelNetwork_Distance(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CChannelNetwork_Distance::On_Execute(void)
+{
+	int		x, y, n, Method;
+
+	CSG_Grid	*pChannels;
+
+	//-----------------------------------------------------
+	pDTM		= Parameters("ELEVATION")->asGrid();
+	pChannels	= Parameters("CHANNELS")->asGrid();
+
+	pDistance	= Parameters("DISTANCE")->asGrid();
+	pDistVert	= Parameters("DISTVERT")->asGrid();
+	pDistHorz	= Parameters("DISTHORZ")->asGrid();
+
+	pDistance->Assign_NoData();
+	pDistVert->Assign_NoData();
+	pDistHorz->Assign_NoData();
+
+	Method		= Parameters("METHOD")->asInt();
+
+	//-----------------------------------------------------
+	switch( Method )
+	{
+	case 0:	default:
+		Initialize_D8();
+		break;
+
+	case 1:
+		Initialize_MFD();
+		break;
+	}
+
+	pDTM->Set_Index(true);
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		pDTM->Get_Sorted(n, x, y, false, false);
+
+		if( pDTM->is_NoData(x, y) )
+		{
+			pDistance->Set_NoData(x, y);
+			pDistVert->Set_NoData(x, y);
+			pDistHorz->Set_NoData(x, y);
+		}
+		else if( !(pChannels->is_NoData(x, y) && pDistance->is_NoData(x, y)) )
+		{
+			if( !pChannels->is_NoData(x, y) )
+			{
+				pDistance->Set_Value(x, y, 0.0);
+				pDistVert->Set_Value(x, y, 0.0);
+				pDistHorz->Set_Value(x, y, 0.0);
+			}
+
+			switch( Method )
+			{
+			case 0:	default:
+				Execute_D8(x, y);
+				break;
+
+			case 1:
+				Execute_MFD(x, y);
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	switch( Method )
+	{
+	case 0:	default:
+		Finalize_D8();
+		break;
+
+	case 1:
+		Finalize_MFD();
+		break;
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork_Distance::Initialize_D8(void)
+{
+	int		x, y;
+
+	pFlow	= SG_Create_Grid(pDTM, SG_DATATYPE_Char);
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			pFlow->Set_Value(x, y, pDTM->Get_Gradient_NeighborDir(x, y));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CChannelNetwork_Distance::Finalize_D8(void)
+{
+	delete(pFlow);
+}
+
+//---------------------------------------------------------
+void CChannelNetwork_Distance::Execute_D8(int x, int y)
+{
+	int		i, ix, iy;
+
+	double	zDist, zVert, zHorz, dVert, dHorz;
+
+	zDist	= pDistance->asDouble(x, y);
+	zVert	= pDistVert->asDouble(x, y);
+	zHorz	= pDistHorz->asDouble(x, y);
+
+	for(i=0; i<8; i++)
+	{
+		ix		= Get_xFrom(i, x);
+		iy		= Get_yFrom(i, y);
+
+		if( pDTM->is_InGrid(ix, iy) && pFlow->asInt(ix, iy) == i )
+		{
+			dVert	= pDTM->asDouble(ix, iy) - pDTM->asDouble(x, y);
+			dHorz	= Get_Length(i);
+
+			pDistVert->Set_Value(ix, iy, zVert + dVert);
+			pDistHorz->Set_Value(ix, iy, zHorz + dHorz);
+			pDistance->Set_Value(ix, iy, zDist + sqrt(dVert*dVert + dHorz*dHorz));
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CChannelNetwork_Distance::Initialize_MFD(void)
+{
+	const double	MFD_Convergence	= 1.1;
+
+	int		x, y, i, ix, iy;
+
+	double	*Flow, z, dz, zSum;
+
+	pFlow	= SG_Create_Grid(pDTM, SG_DATATYPE_Int);
+	Flow	= (double *)SG_Calloc(8 * Get_NCells(), sizeof(double));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++, Flow+=8)
+		{
+			if( pDTM->is_NoData(x, y) )
+			{
+				pFlow->Set_Value(x, y, NULL);
+			}
+			else
+			{
+				pFlow->Set_Value(x, y, (long)Flow);
+
+				z		= pDTM->asDouble(x, y);
+				zSum	= 0.0;
+
+				for(i=0; i<8; i++)
+				{
+					ix		= Get_xTo(i, x);
+					iy		= Get_yTo(i, y);
+
+					if( pDTM->is_InGrid(ix, iy) && z > (dz = pDTM->asDouble(ix, iy)) )
+					{
+						zSum	+= (Flow[i]	= pow((z - dz) / Get_Length(i), MFD_Convergence));
+					}
+				}
+
+				if( zSum > 0.0 )
+				{
+					for(i=0; i<8; i++)
+					{
+						Flow[i]	/= zSum;
+					}
+				}
+			}
+		}
+	}
+
+	pMFDSum	= SG_Create_Grid(pDTM, SG_DATATYPE_Float);
+}
+
+//---------------------------------------------------------
+void CChannelNetwork_Distance::Finalize_MFD(void)
+{
+	SG_Free((double *)pFlow->asInt(0));
+
+	delete(pFlow);
+
+	delete(pMFDSum);
+}
+
+//---------------------------------------------------------
+void CChannelNetwork_Distance::Execute_MFD(int x, int y)
+{
+	int		i, ix, iy;
+
+	double	zDist, zVert, zHorz, dDist, dVert, dHorz, dFlow;
+
+	dDist	= pMFDSum->asDouble(x, y);
+
+	if( dDist > 0.0 )
+	{
+		dDist	= 1.0 / dDist;
+		pDistance->Mul_Value(x, y, dDist);
+		pDistVert->Mul_Value(x, y, dDist);
+		pDistHorz->Mul_Value(x, y, dDist);
+	}
+
+	zDist	= pDistance->asDouble(x, y);
+	zVert	= pDistVert->asDouble(x, y);
+	zHorz	= pDistHorz->asDouble(x, y);
+
+	for(i=0; i<8; i++)
+	{
+		ix		= Get_xTo(i, x);
+		iy		= Get_yTo(i, y);
+
+		if( pDTM->is_InGrid(ix, iy) && (dFlow = ((double *)pFlow->asInt(ix, iy))[(i + 4) % 8]) > 0.0 )
+		{
+			dVert	= pDTM->asDouble(ix, iy) - pDTM->asDouble(x, y);
+			dHorz	= Get_Length(i);
+
+			dDist	= dFlow * (zDist + sqrt(dVert*dVert + dHorz*dHorz));
+			dVert	= dFlow * (zVert + dVert);
+			dHorz	= dFlow * (zHorz + dHorz);
+
+			if( pDistance->is_NoData(ix, iy) )
+			{
+				pDistVert->Set_Value(ix, iy, dVert);
+				pDistHorz->Set_Value(ix, iy, dHorz);
+				pDistance->Set_Value(ix, iy, dDist);
+				pMFDSum->Set_Value(ix, iy, dFlow);
+			}
+			else
+			{
+				pDistVert->Add_Value(ix, iy, dVert);
+				pDistHorz->Add_Value(ix, iy, dHorz);
+				pDistance->Add_Value(ix, iy, dDist);
+				pMFDSum->Add_Value(ix, iy, dFlow);
+			}
+		}
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/ChannelNetwork_Distance.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,117 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               ChannelNetwork_Distance.h               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ChannelNetwork_Distance_H
+#define HEADER_INCLUDED__ChannelNetwork_Distance_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_channels_EXPORT CChannelNetwork_Distance : public CSG_Module_Grid  
+{
+public:
+	CChannelNetwork_Distance(void);
+	virtual ~CChannelNetwork_Distance(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid					*pDTM, *pFlow, *pMFDSum, *pDistance, *pDistVert, *pDistHorz;
+
+
+	void					Initialize_D8	(void);
+	void					Finalize_D8		(void);
+	void					Execute_D8		(int x, int y);
+
+	void					Initialize_MFD	(void);
+	void					Finalize_MFD	(void);
+	void					Execute_MFD		(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ChannelNetwork_Distance_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,279 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  D8_Flow_Analysis.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "D8_Flow_Analysis.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CD8_Flow_Analysis::CD8_Flow_Analysis(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("D8 Flow Analysis"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Deterministic 8 based flow network analysis\n")
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("DEM"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "DIRECTION"	, _TL("Flow Direction"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CONNECTION"	, _TL("Flow Connectivity"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL	, "NETWORK"		, _TL("Flow Network"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MINCON"		, _TL("Minimum Connectivity"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 0, 0, true, 8, true
+	);
+}
+
+//---------------------------------------------------------
+CD8_Flow_Analysis::~CD8_Flow_Analysis(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CD8_Flow_Analysis::On_Execute(void)
+{
+	//-----------------------------------------------------
+	m_pDEM		= Parameters("DEM")			->asGrid();
+
+	m_MinCon	= Parameters("MINCON")		->asInt();
+
+	m_pDir		= Parameters("DIRECTION")	->asGrid();
+	m_pCon		= Parameters("CONNECTION")	->asGrid();
+
+	m_pNet		= Parameters("NETWORK")		->asShapes();
+	m_pNet->Create(SHAPE_TYPE_Line, _TL("D8 Flow Network"));
+	m_pNet->Add_Field("ID"		, SG_DATATYPE_Int);
+	m_pNet->Add_Field(_TL("LENGTH")	, SG_DATATYPE_Double);
+
+	//-----------------------------------------------------
+	//Process_Set_Text("Channel Network: Pass 1");
+
+	Set_Direction();
+	Set_Connectivity();
+
+	//-----------------------------------------------------
+	Lock_Create();
+
+	//-----------------------------------------------------
+	Set_Network();
+
+	//-----------------------------------------------------
+	Lock_Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CD8_Flow_Analysis::Set_Direction(void)
+{
+	bool	bResult	= false;
+	int		x, y, i;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDEM->is_InGrid(x, y) && (i = m_pDEM->Get_Gradient_NeighborDir(x, y)) >= 0 )
+			{
+				bResult	= true;
+
+				m_pDir->Set_Value(x, y, i);
+			}
+			else
+			{
+				m_pDir->Set_Value(x, y, -1);
+			}
+		}
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CD8_Flow_Analysis::Set_Connectivity(void)
+{
+	int		x, y, i, ix, iy;
+
+	m_pCon->Assign(0.0);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( (i = m_pDir->asInt(x, y)) >= 0 && Get_System()->Get_Neighbor_Pos(i, x, y, ix, iy) )
+			{
+				m_pCon->Add_Value(ix, iy, 1);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CD8_Flow_Analysis::Set_Network(void)
+{
+	int		x, y, i, n;
+	CSG_Shape	*pLine;
+
+	for(y=0, n=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !is_Locked(x, y) && (i = m_pCon->asInt(x, y)) != 1 && i >= m_MinCon )
+			{
+				pLine	= m_pNet->Add_Shape();
+				pLine->Set_Value(0, ++n);
+
+				Set_Network(x, y, pLine);
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CD8_Flow_Analysis::Set_Network(int x, int y, CSG_Shape *pLine)
+{
+	int		i, ix, iy;
+
+	Lock_Set(x, y);
+
+	pLine->Add_Point(Get_XMin() + x * Get_Cellsize(), Get_YMin() + y * Get_Cellsize());
+
+	if( (i = m_pDir->asInt(x, y)) >= 0 )
+	{
+		pLine->Add_Value(1, Get_Length(i));
+
+		ix	= Get_xTo(i, x);
+		iy	= Get_yTo(i, y);
+
+		if( is_InGrid(ix, iy) && !is_Locked(ix, iy) && m_pCon->asInt(ix, iy) == 1 )
+		{
+			Set_Network(ix, iy, pLine);
+		}
+		else
+		{
+			pLine->Add_Point(Get_XMin() + ix * Get_Cellsize(), Get_YMin() + iy * Get_Cellsize());
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/D8_Flow_Analysis.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,119 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  D8_Flow_Analysis.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__D8_Flow_Analysis_H
+#define HEADER_INCLUDED__D8_Flow_Analysis_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_channels_EXPORT CD8_Flow_Analysis : public CSG_Module_Grid
+{
+public:
+	CD8_Flow_Analysis(void);
+	virtual ~CD8_Flow_Analysis(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+	int							m_MinCon;
+
+	CSG_Grid						*m_pDEM, *m_pDir, *m_pCon;
+
+	CSG_Shapes						*m_pNet;
+
+
+	bool						Set_Direction		(void);
+	bool						Set_Connectivity	(void);
+
+	bool						Set_Network			(void);
+	bool						Set_Network			(int x, int y, CSG_Shape *pLine);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__D8_Flow_Analysis_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,152 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Terrain Analysis - Channels") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Victor Olaya (c) 2001-4") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for (grid based) digital terrain analysis.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Terrain Analysis|Channels") );
+	}
+}
+
+
+//---------------------------------------------------------
+#include "ChannelNetwork.h"
+#include "Watersheds.h"
+#include "Watersheds_ext.h"
+#include "ChannelNetwork_Altitude.h"
+#include "ChannelNetwork_Distance.h"
+#include "D8_Flow_Analysis.h"
+#include "Strahler.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CChannelNetwork;
+		break;
+
+	case 1:
+		pModule	= new CWatersheds;
+		break;
+	
+	case 2:
+		pModule	= new CWatersheds_ext;
+		break;
+
+	case 3:
+		pModule	= new CChannelNetwork_Altitude;
+		break;
+
+	case 4:
+		pModule	= new CChannelNetwork_Distance;
+		break;
+
+	case 5:
+		pModule	= new CD8_Flow_Analysis;
+		break;
+
+	case 6:
+		pModule	= new CStrahler;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ta_channels_H
+#define HEADER_INCLUDED__ta_channels_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef ta_channels_EXPORTS
+	#define	ta_channels_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	ta_channels_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ta_channels_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,227 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Watersheds.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Watersheds.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWatersheds::CWatersheds(void)
+{
+	Set_Name(_TL("Watershed Basins"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description(_TL(""));
+
+	Parameters.Add_Grid(
+		NULL, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "CHANNELS"	, _TL("Channel Network"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "SINKROUTE"	, _TL("Sink Route"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "BASINS"		, _TL("Watershed Basins"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "MINSIZE"		, _TL("Min. Size"),
+		_TL("Minimum size of basin (cells)"),
+		PARAMETER_TYPE_Int
+	);
+}
+
+//---------------------------------------------------------
+CWatersheds::~CWatersheds(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define	NO_BASIN	-1
+
+//---------------------------------------------------------
+bool CWatersheds::On_Execute(void)
+{
+	int		x, y, n, nCells, nCells_Min, nBasins;
+	CSG_Grid	*pDTM, *pSeed, *pRoute;
+
+	//-----------------------------------------------------
+	pDTM		= Parameters("ELEVATION")	->asGrid();
+	pSeed		= Parameters("CHANNELS")	->asGrid();
+	pRoute		= Parameters("SINKROUTE")	->asGrid();
+	nCells_Min	= Parameters("MINSIZE")		->asInt();
+	m_pBasins	= Parameters("BASINS")		->asGrid();
+
+	m_pBasins->Set_NoData_Value(NO_BASIN);
+	m_pBasins->Assign_NoData();
+
+	m_Direction.Create(m_pBasins, SG_DATATYPE_Char);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDTM->is_NoData(x, y) )
+			{
+				m_Direction.Set_NoData(x, y);
+			}
+			else
+			{
+				if( !pRoute || (n = pRoute->asChar(x, y)) <= 0 )
+				{
+					n	= pDTM->Get_Gradient_NeighborDir(x, y);
+				}
+
+				m_Direction.Set_Value(x, y, n < 0 ? -1 : (n + 4) % 8);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(n=0, m_nBasins=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		pDTM->Get_Sorted(n, x, y, true, false);
+
+		if( !pSeed->is_NoData(x, y) && pSeed->asInt(x, y) < 0 )
+		{
+			m_nBasins++;
+
+			if( (nCells = Get_Basin(x, y)) < nCells_Min )
+			{
+				nBasins		= m_nBasins - 1;
+				m_nBasins	= NO_BASIN;
+				Get_Basin(x, y);
+				m_nBasins	= nBasins;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	m_Direction.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWatersheds::Get_Basin(int x, int y)
+{
+	int		i, ix, iy, nCells;
+
+	if( m_pBasins->is_NoData(x, y) && !m_Direction.is_NoData(x, y) )
+	{
+		m_pBasins->Set_Value(x, y, m_nBasins);
+
+		for(i=0, nCells=1; i<8; i++)
+		{
+			ix	= Get_xTo(i, x);
+			iy	= Get_yTo(i, y);
+
+			if( is_InGrid(ix,iy) && m_Direction.asInt(ix, iy) == i )
+			{
+				nCells	+= Get_Basin(ix, iy);
+			}
+		}
+
+		return( nCells );
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_channels/Watersheds.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_channels                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Watersheds.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Watersheds_H
+#define HEADER_INCLUDED__Watersheds_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_channels_EXPORT CWatersheds : public CSG_Module_Grid
+{
+public:
+	CWatersheds(void);
+	virtual ~CWatersheds(void);
+
+
+protected:
+
+	virtual bool			On_Execute	(void);
+
+
+private:
+
+	int						m_nBasins;
+
+	CSG_Grid					*m_pBasins, m_Direction;
+
+
+	int						Get_Basin	(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Watersheds_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,466 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Flow.cpp                        //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow::CFlow(void)
+{
+	pCatch_AspectY	= NULL;
+	bPoint			= false;
+
+	//-----------------------------------------------------
+	Set_Description	(_TW(
+		"(c) 2001 by Olaf Conrad, Goettingen.\nemail: oconrad at gwdg.de")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SINKROUTE"	, _TL("Sink Routes"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "WEIGHT"		, _TL("Weight"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "CAREA"		, _TL("Catchment Area"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CHEIGHT"		, _TL("Catchment Height"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CSLOPE"		, _TL("Catchment Slope"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "STEP"		, _TL("Step"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+}
+
+//---------------------------------------------------------
+CFlow::~CFlow(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow::Set_Point(int x, int y)
+{
+	bPoint	= true;
+	xPoint	= x;
+	yPoint	= y;
+}
+
+//---------------------------------------------------------
+bool CFlow::On_Execute(void)
+{
+	bool	bResult	= false;
+	long	n;
+	double	d;
+
+	//-------------------------------------------------
+	pDTM			= Parameters("ELEVATION")	->asGrid();
+	pRoute			= Parameters("SINKROUTE")	->asGrid();
+	pWeight			= Parameters("WEIGHT")		->asGrid();
+
+	pCatch			= Parameters("CAREA")		->asGrid();
+	DataObject_Set_Colors(pCatch, 100, SG_COLORS_WHITE_BLUE);
+
+	pCatch_Height	= NULL;
+	pCatch_Slope	= NULL;
+	pCatch_Aspect	= NULL;
+	pFlowPath		= NULL;
+
+	Step			= Parameters("STEP")		->asInt();
+
+	//-------------------------------------------------
+	On_Initialize();
+
+	//-------------------------------------------------
+	if( pCatch )
+	{
+		pCatch			->Assign(0.0);
+	}
+
+	if( pCatch_Height )
+	{
+		pCatch_Height	->Assign(0.0);
+	}
+
+	if( pCatch_Slope )
+	{
+		pCatch_Slope	->Assign(0.0);
+	}
+
+	if( pCatch_Aspect )
+	{
+		pCatch_Aspect	->Assign(0.0);
+		pCatch_AspectY	 = SG_Create_Grid(pCatch_Aspect);
+	}
+
+	if( pFlowPath )
+	{
+		pFlowPath		->Assign(0.0);
+	}
+
+	//-------------------------------------------------
+	if( bPoint )
+	{
+		bPoint	= false;
+
+		if( is_InGrid(xPoint, yPoint) )
+		{
+			Calculate(xPoint, yPoint);
+
+			On_Finalize();
+
+			for(n=0; n<Get_NCells(); n++)
+			{
+				d	= pCatch->asDouble(n);
+				pCatch->Set_Value(n, 100.0 * d);
+			}
+
+			bResult		= true;
+		}
+	}
+	else
+	{
+		pCatch_Height	= Parameters("CHEIGHT")	->asGrid();
+		pCatch_Slope	= Parameters("CSLOPE")	->asGrid();
+
+		Calculate();
+
+		On_Finalize();
+		Finalize();
+
+		bResult			= true;
+	}
+
+	//-------------------------------------------------
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow::Init_Cell(int x, int y)
+{
+	double	Weight, Slope, Aspect;
+
+	Weight	= pWeight ? pWeight->asDouble(x, y) : 1.0;
+
+	if( pCatch )
+	{
+		pCatch			->Add_Value(x, y, Weight);
+	}
+
+	if( pCatch_Height )
+	{
+		pCatch_Height	->Add_Value(x, y, Weight * pDTM->asDouble(x,y));
+	}
+
+	if( pCatch_Slope )
+	{
+		Get_Gradient(x, y, Slope, Aspect);
+
+		pCatch_Slope	->Add_Value(x, y, Weight * Slope);
+	}
+
+	if( pCatch_Aspect && pCatch_AspectY )
+	{
+		Get_Gradient(x, y, Slope, Aspect);
+
+		pCatch_Aspect	->Add_Value(x, y, Weight * sin(Aspect));
+		pCatch_AspectY	->Add_Value(x, y, Weight * cos(Aspect));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow::Finalize(void)
+{
+	long	n;
+	double	z, CellSize, Catch, Contour, dContour, G, H;
+
+	//-----------------------------------------------------
+	CellSize	= Get_Cellsize() * Get_Cellsize();
+	Contour		= 1.0;
+	dContour	= 0.02 * M_PI * sqrt(CellSize / M_PI);
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( pDTM->is_NoData(n) )
+		{
+			if( pCatch )
+			{
+				pCatch			->Set_NoData(n);
+			}
+
+			if( pCatch_Height )
+			{
+				pCatch_Height	->Set_NoData(n);
+			}
+
+			if( pCatch_Slope )
+			{
+				pCatch_Slope	->Set_NoData(n);
+			}
+
+			if( pCatch_Aspect )
+			{
+				pCatch_Aspect	->Set_NoData(n);
+			}
+
+			if( pFlowPath )
+			{
+				pFlowPath		->Set_NoData(n);
+			}
+		}
+		else
+		{
+			z		= pDTM->asDouble(n);
+
+			//---------------------------------------------
+			Catch	= 1.0 / pCatch->asDouble(n);
+
+			if( pCatch_Height )
+			{
+				pCatch_Height	->Set_Value(n, Catch * pCatch_Height->asDouble(n) - z);
+			}
+
+			if( pCatch_Slope )
+			{
+				pCatch_Slope	->Mul_Value(n, Catch);
+			}
+
+			if( pFlowPath )
+			{
+				pFlowPath		->Mul_Value(n, Catch);
+			}
+
+			//---------------------------------------------
+			Catch	= CellSize / Catch;
+
+			if( pCatch )
+			{
+				pCatch			->Set_Value(n, Catch);
+			}
+
+			//---------------------------------------------
+			if( pCatch_Aspect && pCatch_AspectY )
+			{
+				G	= pCatch_Aspect	->asDouble(n);
+				H	= pCatch_AspectY->asDouble(n);
+
+				pCatch_Aspect	->Set_Value(n, G ? fmod(M_PI_270 + atan2(H, G), M_PI_360) : (H > 0 ? M_PI_270 : (H < 0 ? M_PI_090 : -1)));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pCatch_AspectY )
+	{
+		delete(pCatch_AspectY);
+		pCatch_AspectY	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow::Get_Gradient(int x, int y, double &Slope, double &Aspect)
+{
+	pDTM->Get_Gradient(x, y, Slope, Aspect);
+}
+
+//---------------------------------------------------------
+void CFlow::Add_Fraction(int x, int y, int Direction, double Fraction)
+{
+	int		ix, iy;
+
+	if( is_InGrid(x, y) )
+	{
+		ix	= Get_xTo(Direction, x);
+		iy	= Get_yTo(Direction, y);
+
+		if( is_InGrid(ix, iy) )
+		{
+			if( pCatch )
+			{
+				pCatch			->Add_Value(ix, iy, Fraction * pCatch			->asDouble(x, y));
+			}
+
+			if( pCatch_Height )
+			{
+				pCatch_Height	->Add_Value(ix, iy, Fraction * pCatch_Height	->asDouble(x, y));
+			}
+
+			if( pCatch_Slope )
+			{
+				pCatch_Slope	->Add_Value(ix, iy, Fraction * pCatch_Slope		->asDouble(x, y));
+			}
+
+			if( pFlowPath )
+			{
+				pFlowPath		->Add_Value(ix, iy, Fraction * (pFlowPath		->asDouble(x, y) + Get_Length(Direction)));
+			}
+
+			if( pCatch_Aspect && pCatch_AspectY )
+			{
+				pCatch_Aspect	->Add_Value(ix, iy, Fraction * pCatch_Aspect	->asDouble(x, y));
+				pCatch_AspectY	->Add_Value(ix, iy, Fraction * pCatch_AspectY	->asDouble(x, y));
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow::Add_Portion(int x, int y, int ix, int iy)
+{
+	if( is_InGrid(x, y) && is_InGrid(ix, iy) )
+	{
+		if( pCatch )
+		{
+			pCatch			->Add_Value(ix, iy, pCatch			->asDouble(x, y));
+		}
+
+		if( pCatch_Height )
+		{
+			pCatch_Height	->Add_Value(ix, iy, pCatch_Height	->asDouble(x, y));
+		}
+
+		if( pCatch_Slope )
+		{
+			pCatch_Slope	->Add_Value(ix, iy, pCatch_Slope	->asDouble(x, y));
+		}
+
+		if( pFlowPath )
+		{
+			pFlowPath		->Add_Value(ix, iy, pFlowPath		->asDouble(x, y));
+		}
+
+		if( pCatch_Aspect && pCatch_AspectY )
+		{
+			pCatch_Aspect	->Add_Value(ix, iy, pCatch_Aspect	->asDouble(x, y));
+			pCatch_AspectY	->Add_Value(ix, iy, pCatch_AspectY	->asDouble(x, y));
+		}
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,164 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        Flow.h                         //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_H
+#define HEADER_INCLUDED__Flow_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	flow_D8		= 0,
+	flow_Rho8,
+	flow_DInf,
+	flow_MFD,
+	flow_BRM,
+	flow_KRA,
+	flow_DEMON
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CFlow : public CSG_Module_Grid  
+{
+public:
+	CFlow(void);
+	virtual ~CFlow(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Catchment Area" ));	}
+
+	void					Set_Point		(int x, int y);
+
+
+protected:
+
+	bool					bKill_Slope, bKill_Aspect;
+
+	int						Step;
+
+	double					MFD_Converge;
+
+	CSG_Grid					*pDTM, *pRoute, *pWeight,
+							*pCatch,
+							*pCatch_Slope,
+							*pCatch_Height,
+							*pCatch_Aspect,
+							*pFlowPath,
+							*pCatch_AspectY;
+
+
+	virtual bool			On_Execute(void);
+
+	virtual void			On_Initialize	(void)			= 0;
+	virtual void			On_Finalize		(void)			{}
+
+	virtual void			Calculate		(void)			= 0;
+	virtual void			Calculate		(int x, int y)	= 0;
+
+	void					Init_Cell		(int x, int y);
+
+	void					Get_Gradient	(int x, int y, double &Slope, double &Aspect);
+
+	void					Add_Fraction	(int x, int y, int Direction, double Fraction = 1);
+	void					Add_Portion		(int x, int y, int ix, int iy);
+
+
+private:
+
+	bool					bPoint;
+
+	int						xPoint, yPoint;
+
+
+	void					Finalize		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,295 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Flow_AreaDownslope.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow_AreaDownslope.h"
+#include "Flow_Parallel.h"
+#include "Flow_RecursiveDown.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_AreaDownslope::CFlow_AreaDownslope(void)
+{
+	Set_Name(_TL("Downslope Area"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This interactive module allows you to specify source cells (with a left mouse click), "
+		"for which the downslope area shall be identified. "
+		"For the 'Deterministic Infinity' and 'Multiple Flow Direction' algorithms, "
+		"which are able to simulate flow divergence, the result will give "
+		"the percentage of the source cell's flow that drains through each cell.\n\n"
+
+		"References:\n\n"
+
+		"Deterministic 8\n"
+		"- O'Callaghan, J.F. / Mark, D.M. (1984):\n"
+		"    'The extraction of drainage networks from digital elevation data',\n"
+		"    Computer Vision, Graphics and Image Processing, 28:323-344\n\n"
+
+		"Rho 8:\n"
+		"- Fairfield, J. / Leymarie, P. (1991):\n"
+		"    'Drainage networks from grid digital elevation models',\n"
+		"    Water Resources Research, 27:709-717\n\n"
+
+		"Braunschweiger Reliefmodell:\n"
+		"- Bauer, J. / Rohdenburg, H. / Bork, H.-R. (1985):\n"
+		"    'Ein Digitales Reliefmodell als Vorraussetzung fuer ein deterministisches Modell der Wasser- und Stoff-Fluesse',\n"
+		"    Landschaftsgenese und Landschaftsoekologie, H.10, Parameteraufbereitung fuer deterministische Gebiets-Wassermodelle,\n"
+		"    Grundlagenarbeiten zu Analyse von Agrar-Oekosystemen, (Eds.: Bork, H.-R. / Rohdenburg, H.), p.1-15\n\n"
+
+		"Deterministic Infinity:\n"
+		"- Tarboton, D.G. (1997):\n"
+		"    'A new method for the determination of flow directions and upslope areas in grid digital elevation models',\n"
+		"    Water Ressources Research, Vol.33, No.2, p.309-319\n\n"
+
+		"Multiple Flow Direction:\n"
+		"- Freeman, G.T. (1991):\n"
+		"    'Calculating catchment area with divergent flow based on a regular grid',\n"
+		"    Computers and Geosciences, 17:413-22\n\n"
+
+		"- Quinn, P.F. / Beven, K.J. / Chevallier, P. / Planchon, O. (1991):\n"
+		"    'The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models',\n"
+		"    Hydrological Processes, 5:59-79\n\n"
+
+		"Kinematic Routing Algorithm:\n"
+		"- Lea, N.L. (1992):\n"
+		"    'An aspect driven kinematic routing algorithm',\n"
+		"    in: Parsons, A.J., Abrahams, A.D. (Eds.), 'Overland Flow: hydraulics and erosion mechanics', London, 147-175\n\n"
+
+		"DEMON:\n"
+		"- Costa-Cabral, M. / Burges, S.J. (1994):\n"
+		"    'Digital Elevation Model Networks (DEMON): a model of flow over hillslopes for computation of contributing and dispersal areas',\n"
+		"    Water Resources Research, 30:1681-1692\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SINKROUTE"	, _TL("Sink Routes"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "AREA"		, _TL("Downslope Area"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Method...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("Deterministic 8"),
+			_TL("Rho 8"),
+			_TL("Braunschweiger Reliefmodell"),
+			_TL("Deterministic Infinity"),
+			_TL("Multiple Flow Direction"),
+			_TL("Kinematic Routing Algorithm"),
+			_TL("DEMON")
+		), 4
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "CONVERG"		, _TL("Convergence"),
+		_TL("Convergence factor for Multiple Flow Direction algorithm"),
+		PARAMETER_TYPE_Double, 1.1, 0.001, true
+	);
+
+
+	//-----------------------------------------------------
+	// Initialisations...
+
+	pFlow	= NULL;
+}
+
+//---------------------------------------------------------
+CFlow_AreaDownslope::~CFlow_AreaDownslope(void)
+{
+	On_Execute_Finish();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFlow_AreaDownslope::On_Execute(void)
+{
+	CSG_Parameters	*pParameters;
+
+	if( On_Execute_Finish() )
+	{
+		switch( Parameters("METHOD")->asInt() )
+		{
+		// Parallel...
+		case 0:	// Deterministic 8...
+			pFlow	= new CFlow_Parallel;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(0.0);
+			break;
+
+		case 1:	// Rho 8...
+			pFlow	= new CFlow_RecursiveDown;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(0.0);
+			break;
+
+		case 2:	// BRM...
+			pFlow	= new CFlow_Parallel;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(2);
+			break;
+
+		case 3:	// Deterministic Infinity...
+			pFlow	= new CFlow_Parallel;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(3);
+			break;
+
+		case 4:	// MFD...
+			pFlow	= new CFlow_Parallel;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(4);
+			break;
+
+		// Downward Recursive...
+		case 5:	// KRA...
+			pFlow	= new CFlow_RecursiveDown;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(1);
+			break;
+
+		case 6:	// DEMON...
+			pFlow	= new CFlow_RecursiveDown;
+			pFlow->Get_Parameters()->Get_Parameter("Method")->Set_Value(2);
+			//pFlow->Parameters(DEMON_minDQV)-Set_Value(0)	 = 0;
+			break;
+		}
+
+		//-------------------------------------------------
+		if( pFlow )
+		{
+			pParameters	= pFlow->Get_Parameters();
+
+			pFlow->Get_System()->Assign(Parameters("ELEVATION")->asGrid()->Get_System());
+
+			pParameters->Get_Parameter("ELEVATION")	->Set_Value(Parameters("ELEVATION")	->asGrid());
+			pParameters->Get_Parameter("SINKROUTE")	->Set_Value(Parameters("SINKROUTE")	->asGrid());
+			pParameters->Get_Parameter("CAREA")		->Set_Value(Parameters("AREA")		->asGrid());
+		}
+	}
+
+	return( pFlow != NULL );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaDownslope::On_Execute_Finish(void)
+{
+	if( pFlow )
+	{
+		delete( pFlow );
+
+		pFlow	= NULL;
+	}
+
+	return( pFlow == NULL );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaDownslope::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	if( pFlow && Mode == MODULE_INTERACTIVE_LDOWN )
+	{
+		pFlow->Set_Point(Get_xGrid(), Get_yGrid());
+
+		pFlow->Execute();
+
+		DataObject_Update(Parameters("AREA")->asGrid(), 0.0, 100.0, true);
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaDownslope.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Flow_AreaDownslope.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_AreaDownslope_H
+#define HEADER_INCLUDED__Flow_AreaDownslope_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFlow_AreaDownslope : public CSG_Module_Grid_Interactive
+{
+public:
+	CFlow_AreaDownslope(void);
+	virtual ~CFlow_AreaDownslope(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Finish	(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	CFlow					*pFlow;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_AreaDownslope_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,569 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Flow_AreaUpslope.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow_AreaUpslope.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_AreaUpslope::CFlow_AreaUpslope(void)
+{
+	m_pDTM		= NULL;
+	m_pRoute	= NULL;
+	m_pFlow		= NULL;
+}
+
+//---------------------------------------------------------
+CFlow_AreaUpslope::~CFlow_AreaUpslope(void)
+{
+	Finalise();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CFlow_AreaUpslope::Get_Description(void)
+{
+	return(
+		_TW(
+			"This module allows you to specify target cells, "
+			"for which the upslope contributing area shall be identified. "
+			"The result will give "
+			"for each cell the percentage of its flow that reaches the target cell(s).\n\n"
+
+			"References:\n\n"
+
+			"Deterministic 8\n"
+			"- O'Callaghan, J.F. / Mark, D.M. (1984):\n"
+			"    'The extraction of drainage networks from digital elevation data',\n"
+			"    Computer Vision, Graphics and Image Processing, 28:323-344\n\n"
+
+			"Deterministic Infinity:\n"
+			"- Tarboton, D.G. (1997):\n"
+			"    'A new method for the determination of flow directions and upslope areas in grid digital elevation models',\n"
+			"    Water Ressources Research, Vol.33, No.2, p.309-319\n\n"
+
+			"Multiple Flow Direction:\n"
+			"- Freeman, G.T. (1991):\n"
+			"    'Calculating catchment area with divergent flow based on a regular grid',\n"
+			"    Computers and Geosciences, 17:413-22\n\n"
+
+			"- Quinn, P.F. / Beven, K.J. / Chevallier, P. / Planchon, O. (1991):\n"
+			"    'The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models',\n"
+			"    Hydrological Processes, 5:59-79\n\n"
+		)
+	);
+}
+
+//---------------------------------------------------------
+CSG_String CFlow_AreaUpslope::Get_Methods(void)
+{
+	return( CSG_String::Format(SG_T("%s|%s|%s|"),
+		_TL("Deterministic 8"),
+		_TL("Deterministic Infinity"),
+		_TL("Multiple Flow Direction")
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope::Initialise(int Method, CSG_Grid *pDTM, CSG_Grid *pRoute, CSG_Grid *pFlow, double MFD_Converge)
+{
+	Finalise();
+
+	if( pDTM && pDTM->is_Valid() && pFlow && pFlow->is_Valid() && pFlow->Get_System() == pDTM->Get_System() )
+	{
+		m_Method		= Method;
+		m_pDTM			= pDTM;
+		m_pFlow			= pFlow;
+		m_MFD_Converge	= MFD_Converge;
+
+		if( pRoute && pRoute->is_Valid() && pRoute->Get_System() == pDTM->Get_System() )
+		{
+			m_pRoute	= pRoute;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope::Finalise(void)
+{
+	m_pDTM		= NULL;
+	m_pRoute	= NULL;
+	m_pFlow		= NULL;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope::Add_Target(int x, int y)
+{
+	if( m_pFlow && m_pFlow->is_InGrid(x, y, false) )
+	{
+		m_pFlow->Set_Value(x, y, 100.0);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope::Clr_Target(void)
+{
+	if( m_pFlow )
+	{
+		m_pFlow->Assign(0.0);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope::Get_Area(int x, int y)
+{
+	return( Clr_Target() && Add_Target(x, y) && Get_Area() );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope::Get_Area(void)
+{
+	int		i, x, y;
+
+	if( m_pDTM && m_pFlow )
+	{
+		for(i=0; i<m_pDTM->Get_NCells() && SG_UI_Process_Set_Progress(i, m_pDTM->Get_NCells()); i++)
+		{
+			m_pDTM->Get_Sorted(i, x, y, false, false);
+
+			if( m_pFlow->asDouble(x, y) > 0.0 )
+			{
+				break;
+			}
+		}
+
+		for(i++; i<m_pDTM->Get_NCells() && SG_UI_Process_Set_Progress(i, m_pDTM->Get_NCells()); i++)
+		{
+			m_pDTM->Get_Sorted(i, x, y, false, false);
+
+			Set_Value(x, y);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_AreaUpslope::Set_Value(int x, int y)
+{
+	int		i;
+
+	if( m_pRoute && (i = m_pRoute->asChar(x, y)) >= 0 )
+	{
+		int		ix, iy;
+		double	Flow;
+
+		ix	= m_pDTM->Get_System().Get_xTo(i, x);
+		iy	= m_pDTM->Get_System().Get_yTo(i, y);
+
+		if( m_pDTM->is_InGrid(ix, iy, true) && (Flow = m_pFlow->asDouble(ix, iy)) > 0.0 )
+		{
+			m_pFlow->Set_Value(x, y, Flow);
+		}
+	}
+	else if( !m_pDTM->is_NoData(x, y) )
+	{
+		switch( m_Method )
+		{
+		case 0:	Set_D8		(x, y);	break;
+		case 1:	Set_DInf	(x, y);	break;
+		case 2:	Set_MFD		(x, y);	break;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_AreaUpslope::Set_D8(int x, int y)
+{
+	int		i;
+
+	if( (i = m_pDTM->Get_Gradient_NeighborDir(x, y, true)) >= 0 )
+	{
+		int		ix, iy;
+		double	Flow;
+
+		ix	= m_pDTM->Get_System().Get_xTo(i, x);
+		iy	= m_pDTM->Get_System().Get_yTo(i, y);
+
+		if( m_pDTM->is_InGrid(ix, iy, true) && (Flow = m_pFlow->asDouble(ix, iy)) > 0.0 )
+		{
+			m_pFlow->Set_Value(x, y, Flow);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_AreaUpslope::Set_DInf(int x, int y)
+{
+	double	Slope, Aspect;
+
+	if( m_pDTM->Get_Gradient(x, y, Slope, Aspect) )	// && Aspect >= 0.0 )
+	{
+		int		i, ix, iy, jx, jy;
+		double	Flow;
+
+		i		= (int)(Aspect / M_PI_045);
+		ix		= m_pDTM->Get_System().Get_xTo(i, x);
+		iy		= m_pDTM->Get_System().Get_yTo(i, y);
+
+		i++;
+		jx		= m_pDTM->Get_System().Get_xTo(i, x);
+		jy		= m_pDTM->Get_System().Get_yTo(i, y);
+
+		if(	m_pDTM->is_InGrid(ix, iy) && m_pDTM->asDouble(ix, iy) < m_pDTM->asDouble(x, y)
+		&&	m_pDTM->is_InGrid(jx, jy) && m_pDTM->asDouble(jx, jy) < m_pDTM->asDouble(x, y) )
+		{
+			Aspect	= fmod(Aspect,  M_PI_045) / M_PI_045;
+
+			Flow	= m_pFlow->asDouble(ix, iy) * (1.0 - Aspect)
+					+ m_pFlow->asDouble(jx, jy) * (      Aspect);
+
+			if( Flow > 0.0 )
+			{
+				m_pFlow->Set_Value(x, y, Flow);
+			}
+
+			return;
+		}
+	}
+
+	Set_D8(x, y);
+}
+
+//---------------------------------------------------------
+void CFlow_AreaUpslope::Set_MFD(int x, int y)
+{
+	int		i, ix, iy;
+	double	z, d, f, dzSum, dz[8];
+
+	for(i=0, dzSum=0.0, z=m_pDTM->asDouble(x, y); i<8; i++)
+	{
+		dz[i]	= 0.0;
+
+		ix		= m_pDTM->Get_System().Get_xTo(i, x);
+		iy		= m_pDTM->Get_System().Get_yTo(i, y);
+
+		if( m_pDTM->is_InGrid(ix, iy) && (d = z - m_pDTM->asDouble(ix, iy)) > 0.0 )
+		{
+			dzSum	+= (d = pow(d / m_pDTM->Get_System().Get_Length(i), m_MFD_Converge));
+
+			if( (f = m_pFlow->asDouble(ix, iy)) > 0.0 )
+			{
+				dz[i]	= d * f;
+			}
+		}
+	}
+
+	if( dzSum > 0.0 )
+	{
+		for(i=0, d=0.0; i<8; i++)
+		{
+			if( dz[i] > 0.0 )
+			{
+				d	+= dz[i] / dzSum;
+			}
+		}
+
+		m_pFlow->Set_Value(x, y, d);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_AreaUpslope_Interactive::CFlow_AreaUpslope_Interactive(void)
+{
+	Set_Name		(_TL("Upslope Area"));
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(CSG_String::Format(SG_T("%s_______\n%s"), m_Calculator.Get_Description().c_str(),
+		_TL("Interactive version (left mouse clicks will trigger the calculation for the selected cell).")
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SINKROUTE"	, _TL("Sink Routes"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "AREA"		, _TL("Upslope Area"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		m_Calculator.Get_Methods(), 2
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CONVERGE"	, _TL("Convergence"),
+		_TL("Convergence factor for Multiple Flow Direction algorithm"),
+		PARAMETER_TYPE_Double	, 1.1, 0.001, true
+	);
+}
+
+//---------------------------------------------------------
+CFlow_AreaUpslope_Interactive::~CFlow_AreaUpslope_Interactive(void)
+{}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope_Interactive::On_Execute(void)
+{
+	if( m_Calculator.Initialise(
+		Parameters("METHOD")	->asInt(),
+		Parameters("ELEVATION")	->asGrid(),
+		Parameters("SINKROUTE")	->asGrid(),
+		Parameters("AREA")		->asGrid(),
+		Parameters("CONVERGE")	->asDouble()	) )
+	{
+		DataObject_Set_Colors(Parameters("AREA")->asGrid(), 100, SG_COLORS_WHITE_BLUE);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope_Interactive::On_Execute_Finish(void)
+{
+	return( m_Calculator.Finalise() );
+}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope_Interactive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	if(	Mode == MODULE_INTERACTIVE_LDOWN && m_Calculator.Get_Area(Get_xGrid(), Get_yGrid()) )
+	{
+		DataObject_Update(Parameters("AREA")->asGrid(), 0.0, 100.0, true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_AreaUpslope_Area::CFlow_AreaUpslope_Area(void)
+{
+	Set_Name		(_TL("Upslope Area"));
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(CSG_String::Format(SG_T("%s_______\n%s"), m_Calculator.Get_Description().c_str(),
+		_TL("This version uses all valid cells (not \'no data\' values) of given target grid to determine the contributing area.")
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "TARGET"		, _TL("Target Area"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SINKROUTE"	, _TL("Sink Routes"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "AREA"		, _TL("Upslope Area"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		m_Calculator.Get_Methods(), 2
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CONVERGE"	, _TL("Convergence"),
+		_TL("Convergence factor for Multiple Flow Direction algorithm"),
+		PARAMETER_TYPE_Double	, 1.1, 0.001, true
+	);
+}
+
+//---------------------------------------------------------
+CFlow_AreaUpslope_Area::~CFlow_AreaUpslope_Area(void)
+{}
+
+//---------------------------------------------------------
+bool CFlow_AreaUpslope_Area::On_Execute(void)
+{
+	bool	bResult	= false;
+
+	//-----------------------------------------------------
+	if( m_Calculator.Initialise(
+		Parameters("METHOD")	->asInt(),
+		Parameters("ELEVATION")	->asGrid(),
+		Parameters("SINKROUTE")	->asGrid(),
+		Parameters("AREA")		->asGrid(),
+		Parameters("CONVERGE")	->asDouble()	) )
+	{
+		if( m_Calculator.Clr_Target() )
+		{
+			int		x, y;
+			CSG_Grid	*pTarget	= Parameters("TARGET")->asGrid();
+
+			for(y=0; y<Get_NY() && Set_Progress(y); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					if( !pTarget->is_NoData(x, y) && m_Calculator.Add_Target(x, y) )
+					{
+						bResult	= true;
+					}
+				}
+			}
+
+			if( bResult )
+			{
+				m_Calculator.Get_Area();
+
+				DataObject_Set_Colors(Parameters("AREA")->asGrid(), 100, SG_COLORS_WHITE_BLUE);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	m_Calculator.Finalise();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_AreaUpslope.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,176 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Flow_AreaUpslope.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_AreaUpslope_H
+#define HEADER_INCLUDED__Flow_AreaUpslope_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFlow_AreaUpslope
+{
+public:
+	CFlow_AreaUpslope(void);
+	virtual ~CFlow_AreaUpslope(void);
+
+	CSG_String				Get_Description		(void);
+	CSG_String				Get_Methods			(void);
+
+	bool					Initialise			(int Method, CSG_Grid *pDTM, CSG_Grid *pRoute, CSG_Grid *pFlow, double MFD_Converge);
+	bool					Finalise			(void);
+
+	bool					Add_Target			(int x, int y);
+	bool					Clr_Target			(void);
+
+	bool					Get_Area			(int x, int y);
+	bool					Get_Area			(void);
+
+
+private:
+
+	int						m_Method;
+
+	double					m_MFD_Converge;
+
+	CSG_Grid					*m_pDTM, *m_pRoute, *m_pFlow;
+
+
+	void					Set_Value			(int x, int y);
+	void					Set_D8				(int x, int y);
+	void					Set_DInf			(int x, int y);
+	void					Set_MFD				(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFlow_AreaUpslope_Interactive : public CSG_Module_Grid_Interactive
+{
+public:
+	CFlow_AreaUpslope_Interactive(void);
+	virtual ~CFlow_AreaUpslope_Interactive(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Finish	(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	CFlow_AreaUpslope		m_Calculator;
+
+};
+
+//---------------------------------------------------------
+class CFlow_AreaUpslope_Area : public CSG_Module_Grid
+{
+public:
+	CFlow_AreaUpslope_Area(void);
+	virtual ~CFlow_AreaUpslope_Area(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	CFlow_AreaUpslope		m_Calculator;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_AreaUpslope_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_BRM.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_BRM.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_BRM.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,228 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Flow_BRM.h                       //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_BRM_H
+#define HEADER_INCLUDED__Flow_BRM_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const int BRM_BitMtrx[][8]		=
+{
+	{	0, 0, 0, 0, 1, 1, 1, 1	},
+	{	0, 0, 1, 1, 0, 0, 1, 1	},
+	{	0, 1, 0, 1, 0, 1, 0, 1	}
+};
+
+//---------------------------------------------------------
+const double BRM_g[][6][9][9]	=
+{
+	{
+		{
+			{0.345491,0.330817,0.308609,0.280762,0.250000,0.219238,0.191391,0.169183,0.154509,},
+			{0.264419,0.258082,0.250888,0.238153,0.219238,0.196386,0.172987,0.152978,0.140142,},
+			{0.187701,0.191733,0.200746,0.201406,0.191391,0.172987,0.149627,0.126499,0.112621,},
+			{0.104968,0.129630,0.160199,0.172795,0.169183,0.152978,0.126499,0.092593,0.069122,},
+			{0.000000,0.078549,0.109329,0.119501,0.118034,0.108228,0.090155,0.059574,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,}
+		},
+		{
+			{0.345491,0.330817,0.308609,0.280762,0.250000,0.219238,0.191391,0.169183,0.154509,},
+			{0.440699,0.416145,0.374720,0.327309,0.280762,0.238153,0.201406,0.172795,0.154740,},
+			{0.563105,0.521569,0.448881,0.374720,0.308609,0.250888,0.200746,0.160199,0.136573,},
+			{0.734773,0.648148,0.521569,0.416145,0.330817,0.258082,0.191733,0.129630,0.091137,},
+			{1.000000,0.633284,0.450774,0.340339,0.263932,0.204204,0.150258,0.090469,0.000000,},
+			{0.734773,0.648148,0.521569,0.416145,0.330817,0.258082,0.191733,0.129630,0.091137,},
+			{0.563105,0.521569,0.448881,0.374720,0.308609,0.250888,0.200746,0.160199,0.136573,},
+			{0.440699,0.416145,0.374720,0.327309,0.280762,0.238153,0.201406,0.172795,0.154740,},
+			{0.345491,0.330817,0.308609,0.280762,0.250000,0.219238,0.191391,0.169183,0.154509,}
+		},
+		{
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.078549,0.109329,0.119501,0.118034,0.108228,0.090155,0.059574,0.000000,},
+			{0.104968,0.129630,0.160199,0.172795,0.169183,0.152978,0.126499,0.092593,0.069122,},
+			{0.187701,0.191733,0.200746,0.201406,0.191391,0.172987,0.149627,0.126499,0.112621,},
+			{0.264419,0.258082,0.250888,0.238153,0.219238,0.196386,0.172987,0.152978,0.140142,},
+			{0.345491,0.330817,0.308609,0.280762,0.250000,0.219238,0.191391,0.169183,0.154509,}
+		},
+		{
+			{0.154509,0.169183,0.191391,0.219238,0.250000,0.280762,0.308609,0.330817,0.345491,},
+			{0.140142,0.152978,0.172987,0.196386,0.219238,0.238153,0.250888,0.258082,0.264419,},
+			{0.112621,0.126499,0.149627,0.172987,0.191391,0.201406,0.200746,0.191733,0.187701,},
+			{0.069122,0.092593,0.126499,0.152978,0.169183,0.172795,0.160199,0.129630,0.104968,},
+			{0.000000,0.059574,0.090155,0.108228,0.118034,0.119501,0.109329,0.078549,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,}
+		},
+		{
+			{0.154509,0.169183,0.191391,0.219238,0.250000,0.280762,0.308609,0.330817,0.345491,},
+			{0.154740,0.172795,0.201406,0.238153,0.280762,0.327309,0.374720,0.416145,0.440699,},
+			{0.136573,0.160199,0.200746,0.250888,0.308609,0.374720,0.448881,0.521569,0.563105,},
+			{0.091137,0.129630,0.191733,0.258082,0.330817,0.416145,0.521569,0.648148,0.734773,},
+			{0.000000,0.090469,0.150258,0.204204,0.263932,0.340339,0.450774,0.633284,1.000000,},
+			{0.091137,0.129630,0.191733,0.258082,0.330817,0.416145,0.521569,0.648148,0.734773,},
+			{0.136573,0.160199,0.200746,0.250888,0.308609,0.374720,0.448881,0.521569,0.563105,},
+			{0.154740,0.172795,0.201406,0.238153,0.280762,0.327309,0.374720,0.416145,0.440699,},
+			{0.154509,0.169183,0.191391,0.219238,0.250000,0.280762,0.308609,0.330817,0.345491,}
+		},
+		{
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,},
+			{0.000000,0.059574,0.090155,0.108228,0.118034,0.119501,0.109329,0.078549,0.000000,},
+			{0.069122,0.092593,0.126499,0.152978,0.169183,0.172795,0.160199,0.129630,0.104968,},
+			{0.112621,0.126499,0.149627,0.172987,0.191391,0.201406,0.200746,0.191733,0.187701,},
+			{0.140142,0.152978,0.172987,0.196386,0.219238,0.238153,0.250888,0.258082,0.264419,},
+			{0.154509,0.169183,0.191391,0.219238,0.250000,0.280762,0.308609,0.330817,0.345491,}
+		}
+	},
+	{
+		{
+			{0.184954, 0.195678, 0.206211, 0.218885, 0.237326, 0.264926, 0.302961, 0.350137, 0.403465, },
+			{0.187304, 0.205676, 0.224237, 0.244886, 0.270252, 0.302863, 0.344245, 0.394455, 0.452059, },
+			{0.187375, 0.212801, 0.238204, 0.265388, 0.296596, 0.334049, 0.379489, 0.433875, 0.497181, },
+			{0.187123, 0.218448, 0.249297, 0.281563, 0.317339, 0.358716, 0.407592, 0.465548, 0.533783, },
+			{0.151145, 0.174340, 0.197249, 0.221815, 0.250000, 0.283866, 0.325671, 0.378026, 0.444182, },
+			{0.186204, 0.217967, 0.249127, 0.281652, 0.317687, 0.359370, 0.408659, 0.467227, 0.536440, },
+			{0.185979, 0.212089, 0.238006, 0.265632, 0.297289, 0.335277, 0.381436, 0.436861, 0.501737, },
+			{0.185904, 0.205012, 0.224165, 0.245341, 0.271250, 0.304513, 0.346764, 0.398187, 0.457497, },
+			{0.183850, 0.195258, 0.206368, 0.219565, 0.238548, 0.266808, 0.305723, 0.354090, 0.408980, }
+		},
+		{
+			{0.407523, 0.450476, 0.487960, 0.514650, 0.525349, 0.517453, 0.492761, 0.456235, 0.413422, },
+			{0.357530, 0.397162, 0.429535, 0.451236, 0.459496, 0.453069, 0.432803, 0.401272, 0.361916, },
+			{0.313086, 0.351332, 0.380898, 0.399862, 0.406807, 0.401119, 0.383189, 0.354296, 0.316329, },
+			{0.277300, 0.314518, 0.342082, 0.359218, 0.365322, 0.360114, 0.343738, 0.316699, 0.279720, },
+			{0.201455, 0.223136, 0.238093, 0.246948, 0.250000, 0.247324, 0.238810, 0.224130, 0.202635, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, }
+		},
+		{
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.201455, 0.223136, 0.238093, 0.246948, 0.250000, 0.247324, 0.238810, 0.224130, 0.202635, },
+			{0.275564, 0.313320, 0.341185, 0.358475, 0.364626, 0.359370, 0.342839, 0.315497, 0.277975, },
+			{0.309928, 0.349057, 0.379149, 0.398390, 0.405421, 0.399645, 0.381436, 0.352013, 0.313152, },
+			{0.353491, 0.394089, 0.427084, 0.449129, 0.457500, 0.450961, 0.430347, 0.398187, 0.357854, },
+			{0.403100, 0.446932, 0.485032, 0.512085, 0.522904, 0.514889, 0.489833, 0.452683, 0.408980, }
+		},
+		{
+			{0.407523, 0.353846, 0.305829, 0.266465, 0.237326, 0.217621, 0.204277, 0.193627, 0.183113, },
+			{0.455166, 0.397162, 0.346228, 0.303878, 0.270252, 0.244068, 0.222952, 0.204274, 0.186025, },
+			{0.499538, 0.435867, 0.380898, 0.334749, 0.296596, 0.264832, 0.237322, 0.211829, 0.186491, },
+			{0.535577, 0.467034, 0.408621, 0.359218, 0.317339, 0.281170, 0.248670, 0.217753, 0.186496, },
+			{0.445945, 0.379388, 0.326565, 0.284288, 0.250000, 0.221487, 0.196709, 0.173714, 0.150548, },
+			{0.538232, 0.468713, 0.409688, 0.359872, 0.317687, 0.281259, 0.248501, 0.217276, 0.185584, },
+			{0.504093, 0.438854, 0.382846, 0.335978, 0.297289, 0.265078, 0.237129, 0.211126, 0.185110, },
+			{0.460605, 0.400899, 0.348751, 0.305529, 0.271250, 0.244525, 0.222889, 0.203625, 0.184649, },
+			{0.413049, 0.357811, 0.308599, 0.268350, 0.238548, 0.218303, 0.204444, 0.193227, 0.182039, }
+		},
+		{
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, }
+		},
+		{
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, },
+			{0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, }
+		}
+	}
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_BRM_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,302 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Flow_Distance.cpp                   //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow_Distance.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_Distance::CFlow_Distance(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Flow Path Length"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"This module calculates the average flow path length starting from the seeds, "
+		"that are given by the optional \'Seeds\' grid and optionally from cells without upslope contributing areas "
+		"(i.e. summits, ridges). Seeds will be all grid cells, that "
+		"are not \'no data\' values. If seeds are not given, only summits and ridges as given by the flow routing will be taken into account. "
+		"Available flow routing methods are based on the "
+		"\'Deterministic 8 (D8)\' (Callaghan and Mark 1984) and the \'Multiple Flow Direction (FD8)\' "
+		"(Freeman 1991, Quinn et al. 1991) algorithms.\n\n"
+
+		"References:\n\n"
+
+		"Deterministic 8\n"
+		"- O'Callaghan, J.F. / Mark, D.M. (1984):\n"
+		"    'The extraction of drainage networks from digital elevation data',\n"
+		"    Computer Vision, Graphics and Image Processing, 28:323-344\n\n"
+
+		"- Freeman, G.T. (1991):\n"
+		"    'Calculating catchment area with divergent flow based on a regular grid',\n"
+		"    Computers and Geosciences, 17:413-22\n\n"
+
+		"- Quinn, P.F. / Beven, K.J. / Chevallier, P. / Planchon, O. (1991):\n"
+		"    'The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models',\n"
+		"    Hydrological Processes, 5:59-79\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SEED"		, _TL("Seeds"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "LENGTH"		, _TL("Flow Path Length"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "SEEDS_ONLY"	, _TL("Seeds Only"),
+		_TL("Use only seed cells as starting points."),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Flow Routing Algorithm"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Deterministic 8 (D8)"),
+			_TL("Multiple Flow Direction (FD8)")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CONVERGENCE"	, _TL("Convergence (FD8)"),
+		_TL("Convergence factor for the \'Multiple Flow Direction\' algorithm (after Freeman 1991)"),
+		PARAMETER_TYPE_Double	, 1.1, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CFlow_Distance::~CFlow_Distance(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFlow_Distance::On_Execute(void)
+{
+	bool		bSeeds;
+	int			x, y, n, Method;
+	CSG_Grid	*pSeed;
+
+	//-------------------------------------------------
+	m_pDTM		= Parameters("ELEVATION")	->asGrid();
+	pSeed		= Parameters("SEED")		->asGrid();
+	m_pLength	= Parameters("LENGTH")		->asGrid();
+
+	m_Converge	= Parameters("CONVERGENCE")	->asDouble();
+	bSeeds		= Parameters("SEEDS_ONLY")	->asBool();
+	Method		= Parameters("METHOD")		->asInt();
+
+	m_pWeight	= SG_Create_Grid(m_pLength, SG_DATATYPE_Float);
+	m_pWeight	->Assign(0.0);
+	m_pLength	->Assign(0.0);
+
+	//-------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		m_pDTM->Get_Sorted(n, x, y, true, false);
+
+		if( pSeed && !pSeed->is_NoData(x, y) )
+		{
+			m_pLength->Set_Value(x, y, 0.0);
+			m_pWeight->Set_Value(x, y, 0.0);
+		}
+		else if( m_pWeight->asDouble(x, y) > 0.0 )
+		{
+			m_pLength->Set_Value(x, y, m_pLength->asDouble(x, y) / m_pWeight->asDouble(x, y));
+		}
+		else if( bSeeds )
+		{
+			m_pLength->Set_NoData(x, y);
+
+			continue;
+		}
+
+		switch( Method )
+		{
+		case 0:	Set_Length_D8	(x, y);	break;
+		case 1:	Set_Length_MFD	(x, y);	break;
+		}
+	}
+
+	//-------------------------------------------------
+	delete(m_pWeight);
+
+	DataObject_Set_Colors(m_pLength, 100, SG_COLORS_WHITE_BLUE);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Distance::Set_Length_D8(int x, int y)
+{
+	int		i, ix, iy;
+
+	if( m_pDTM->is_InGrid(x, y) && (i = m_pDTM->Get_Gradient_NeighborDir(x, y, true)) >= 0 )
+	{
+		ix	= Get_xTo(i, x);
+		iy	= Get_yTo(i, y);
+
+		if( m_pDTM->is_InGrid(ix, iy) )
+		{
+			m_pLength->Add_Value(ix, iy, m_pLength->asDouble(x, y) + Get_Length(i));
+			m_pWeight->Add_Value(ix, iy, 1.0);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_Distance::Set_Length_MFD(int x, int y)
+{
+	int		i, ix, iy;
+	double	z, d, dzSum, dz[8];
+
+	if( m_pDTM->is_InGrid(x, y) )
+	{
+		z		= m_pDTM->asDouble(x, y);
+		dzSum	= 0.0;
+
+		for(i=0; i<8; i++)
+		{
+			ix		= Get_xTo(i, x);
+			iy		= Get_yTo(i, y);
+
+			if( m_pDTM->is_InGrid(ix, iy) && (d = z - m_pDTM->asDouble(ix, iy)) > 0.0 )
+			{
+				dz[i]	= pow(d / Get_Length(i), m_Converge);
+				dzSum	+= dz[i];
+			}
+			else
+			{
+				dz[i]	= 0.0;
+			}
+		}
+
+		if( dzSum > 0.0 )
+		{
+			d	 = m_pLength->asDouble(x, y);
+
+			for(i=0; i<8; i++)
+			{
+				if( dz[i] > 0.0 )
+				{
+					ix		= Get_xTo(i, x);
+					iy		= Get_yTo(i, y);
+
+					dz[i]	/= dzSum;
+
+					m_pLength->Add_Value(ix, iy, dz[i] * (d + Get_Length(i)));
+					m_pWeight->Add_Value(ix, iy, dz[i]);
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Distance.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Flow_Distance.h                    //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_Distance_H
+#define HEADER_INCLUDED__Flow_Distance_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CFlow_Distance : public CSG_Module_Grid  
+{
+public:
+	CFlow_Distance(void);
+	virtual ~CFlow_Distance(void);
+
+//	virtual const SG_Char *	Get_MenuPath	(void)	{	return( "R:Catchment Area" );	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	double					m_Converge;
+
+	CSG_Grid					*m_pDTM, *m_pLength, *m_pWeight;
+
+
+	void					Set_Length_D8	(int x, int y);
+	void					Set_Length_MFD	(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_Distance_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1084 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Flow_Parallel.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow_Parallel.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_Parallel::CFlow_Parallel(void)
+{
+	Set_Name		(_TL("Parallel Processing"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Parallel processing of cells for calculation of flow accumulation and related parameters. "
+		"This set of algorithms processes a DEM downwards from the highest to the lowest cell.\n\n"
+
+		"References:\n\n"
+
+		"Deterministic 8\n"
+		"- O'Callaghan, J.F. / Mark, D.M. (1984):\n"
+		"    'The extraction of drainage networks from digital elevation data',\n"
+		"    Computer Vision, Graphics and Image Processing, 28:323-344\n\n"
+
+		"Rho 8:\n"
+		"- Fairfield, J. / Leymarie, P. (1991):\n"
+		"    'Drainage networks from grid digital elevation models',\n"
+		"    Water Resources Research, 27:709-717\n\n"
+
+		"Braunschweiger Reliefmodell:\n"
+		"- Bauer, J. / Rohdenburg, H. / Bork, H.-R. (1985):\n"
+		"    'Ein Digitales Reliefmodell als Vorraussetzung fuer ein deterministisches Modell der Wasser- und Stoff-Fluesse',\n"
+		"    Landschaftsgenese und Landschaftsoekologie, H.10, Parameteraufbereitung fuer deterministische Gebiets-Wassermodelle,\n"
+		"    Grundlagenarbeiten zu Analyse von Agrar-Oekosystemen, (Eds.: Bork, H.-R. / Rohdenburg, H.), p.1-15\n\n"
+
+		"Deterministic Infinity:\n"
+		"- Tarboton, D.G. (1997):\n"
+		"    'A new method for the determination of flow directions and upslope areas in grid digital elevation models',\n"
+		"    Water Ressources Research, Vol.33, No.2, p.309-319\n\n"
+
+		"Multiple Flow Direction:\n"
+		"- Freeman, G.T. (1991):\n"
+		"    'Calculating catchment area with divergent flow based on a regular grid',\n"
+		"    Computers and Geosciences, 17:413-22\n\n"
+
+		"- Quinn, P.F. / Beven, K.J. / Chevallier, P. / Planchon, O. (1991):\n"
+		"    'The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models',\n"
+		"    Hydrological Processes, 5:59-79\n\n"
+		
+		"Triangular Multiple Flow Direction\n"
+		"- Seibert, J. / McGlynn, B. (2007):\n"
+		"    'A new triangular multiple flow direction algorithm for computing upslope areas from gridded digital elevation models',\n"
+		"    Water Ressources Research, Vol. 43, W04501\n"
+		"    C++ Implementation into SAGA by Thomas Grabs, Copyrights (c) 2007\n"
+		"    Contact: thomas.grabs at natgeo.su.se, jan.seibert at natgeo.su.se \n\n"
+	));
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "CASPECT"		, _TL("Catchment Aspect"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "FLWPATH"		, _TL("Flow Path Length"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Method...
+
+	Parameters.Add_Choice(
+		NULL	, "Method"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Deterministic 8"),
+			_TL("Rho 8"),
+			_TL("Braunschweiger Reliefmodell"),
+			_TL("Deterministic Infinity"),
+			_TL("Multiple Flow Direction"),
+			_TL("Multiple Triangular Flow Directon")
+		), 4
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "DOLINEAR"	, _TL("Linear Flow"),
+		_TL("Use D8 if catchment area becomes higher than specified threshold."),
+		PARAMETER_TYPE_Bool
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LINEARTHRS"	, _TL("Linear Flow Threshold"),
+		_TL("Use D8 if catchment area becomes higher than specified threshold (Cells)."),
+		PARAMETER_TYPE_Double	,	500
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CONVERGENCE"	, _TL("Convergence"),
+		_TL("Convergence factor for Multiple Flow Direction Algorithm after Freeman (1991) and Multiple Triangular Flow Directon Algorithm after Seibert/Glynn (2007)."),
+		PARAMETER_TYPE_Double	, 1.1, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CFlow_Parallel::~CFlow_Parallel(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::On_Initialize(void)
+{
+	pCatch_Aspect	= Parameters("CASPECT")->asGrid();
+	pFlowPath		= Parameters("FLWPATH")->asGrid();
+
+	TH_LinearFlow	= Parameters("DOLINEAR")->asBool() && pDTM
+					? Parameters("LINEARTHRS")->asDouble() // (pDTM->Get_NX() * pDTM->Get_NY())
+					: -1.0;
+
+	MFD_Converge	= Parameters("CONVERGENCE")->asDouble();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Calculate(void)
+{
+	int		x, y;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y+=Step)
+	{
+		for(x=0; x<Get_NX(); x+=Step)
+		{
+			Init_Cell(x, y);
+		}
+	}
+
+	Set_Flow();
+}
+
+//---------------------------------------------------------
+void CFlow_Parallel::Calculate(int x, int y)
+{
+	Init_Cell(x, y);
+
+	Set_Flow();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_Flow(void)
+{
+	int		Method, x, y;
+
+	long	n;
+
+	//-----------------------------------------------------
+	Method	= Parameters("Method")->asInt();
+
+	if( Method == 2 )
+	{
+		BRM_Init();
+	}
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		pDTM->Get_Sorted(n,x,y, true, false);
+
+		//if( !(n%(4*Get_NX())) )DataObject_Update(pFlow);
+
+		if( TH_LinearFlow > 0.0 && pCatch->asDouble(x, y) >= TH_LinearFlow )
+		{
+			Set_D8(x, y);
+		}
+		else
+		{
+			switch( Method )
+			{
+			case 0:		Set_D8		(x, y);		break;
+			case 1:		Set_Rho8	(x, y);		break;
+			case 3:		Set_DInf	(x, y);		break;
+			case 4:		Set_MFD		(x, y);		break;
+			case 5:		Set_MDInf	(x, y);		break;				
+			case 2:		Set_BRM		(x, y);		break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pRoute )
+	{
+		for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+		{
+			if( pDTM->Get_Sorted(n, x, y, false) )
+			{
+				Check_Route(x, y);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_Parallel::Check_Route(int x, int y)
+{
+	bool	bSink;
+	int		i, ix, iy;
+	double	z;
+
+	if( pRoute->asChar(x, y) > 0 )
+	{
+		z	= pDTM->asDouble(x, y);
+
+		for(i=0, bSink=true; i<8 && bSink; i++)
+		{
+			ix	= Get_xTo(i, x);
+			iy	= Get_yTo(i, y);
+
+			if( !is_InGrid(ix, iy) || z > pDTM->asDouble(ix, iy) )
+			{
+				bSink	= false;
+			}
+		}
+
+		//-------------------------------------------------
+		if( bSink )
+		{
+			i	= pRoute->asChar(x, y);
+
+			ix	= Get_xTo(i, ix);
+			iy	= Get_yTo(i, iy);
+
+			//---------------------------------------------
+			while( is_InGrid(ix, iy) )
+			{
+				Add_Portion(x, y, ix, iy);
+
+				i	= pRoute->asChar(ix, iy);
+
+				if( i > 0 )
+				{
+					ix	= Get_xTo(i, ix);
+					iy	= Get_yTo(i, iy);
+				}
+				else
+				{
+					i	= pDTM->Get_Gradient_NeighborDir(ix, iy);
+
+					if( i >= 0 )
+					{
+						ix	= Get_xTo(i, ix);
+						iy	= Get_yTo(i, iy);
+					}
+					else
+					{
+						ix	= -1;
+					}
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Deterministic 8						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_D8(		int x, int y )
+{
+	int		Direction;
+
+	Direction	= pDTM->Get_Gradient_NeighborDir(x, y);
+
+	if( Direction >= 0 )
+	{
+		Add_Fraction(x, y, Direction);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Rho 8							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_Rho8(	int x, int y )
+{
+	int		i, ix, iy, iMax;
+
+	double	z, d, dMax;
+
+	z		= pDTM->asDouble(x, y);
+	iMax	= -1;
+
+	for(i=0; i<8; i++)
+	{
+		ix		= Get_xTo(i, x);
+		iy		= Get_yTo(i, y);
+
+		if( !pDTM->is_InGrid(ix, iy) )
+		{
+			return;
+		}
+		else
+		{
+			d		= z - pDTM->asDouble(ix, iy);
+
+			if( i % 2 == 1 )
+			{
+				d		/= 1.0 + rand() / (double)RAND_MAX;
+			}
+
+			if( iMax < 0 || (iMax >= 0 && d > dMax) )
+			{
+				iMax	= i;
+				dMax	= d;
+			}
+		}
+	}
+
+	if( iMax >= 0 )
+	{
+		Add_Fraction(x, y, iMax);
+	}
+}
+
+/*void CFlow_Parallel::Set_Rho8(	int x, int y )
+{
+	int		Direction, ix, iy;
+
+	double 	Slope, Aspect;
+
+	Get_Gradient(x, y, Slope, Aspect);
+
+	if( Aspect >= 0 )
+	{
+		Direction	= (int)(Aspect / M_PI_045);
+
+		if( fmod(Aspect, M_PI_045) / M_PI_045 > rand() / (double)RAND_MAX )
+		{
+			Direction++;
+		}
+
+		Direction	%= 8;
+
+		ix			= Get_xTo(Direction, x);
+		iy			= Get_yTo(Direction, y);
+
+		if( is_InGrid(ix, iy) && pDTM->asDouble(ix, iy) >= pDTM->asDouble(x, y) )
+		{
+			Direction	= Get_Direction_Lowest(pDTM, x, y);
+		}
+
+		Add_Fraction(x, y, Direction);
+	}
+}/**/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Deterministic Infinity					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_DInf(	int x, int y )
+{
+	int		Direction, x1, y1, x2, y2;
+
+	double	Slope, Aspect, z;
+
+	Get_Gradient(x, y, Slope, Aspect);
+
+	if( Aspect >= 0.0 )
+	{
+		Direction	= (int)(Aspect / M_PI_045);
+		Aspect		=  fmod(Aspect , M_PI_045) / M_PI_045;
+
+		z			= pDTM->asDouble(x, y);
+		x1			= Get_xTo(Direction + 0, x);
+		y1			= Get_yTo(Direction + 0, y);
+		x2			= Get_xTo(Direction + 1, x);
+		y2			= Get_yTo(Direction + 1, y);
+
+		if( (!is_InGrid(x1, y1) || z > pDTM->asDouble(x1, y1))
+		&&	(!is_InGrid(x2, y2) || z > pDTM->asDouble(x2, y2)) )
+		{
+			Add_Fraction(x, y,  Direction			, 1.0 - Aspect);
+			Add_Fraction(x, y, (Direction + 1) % 8	,       Aspect);
+		}
+		else
+		{
+			Add_Fraction(x, y, pDTM->Get_Gradient_NeighborDir(x, y));
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Multiple Flow Direction					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_MFD(	int x, int y )
+{
+	int		i, ix, iy;
+
+	double	z, d, dzSum, dz[8];
+
+	z		= pDTM->asDouble(x, y);
+	dzSum	= 0.0;
+
+	for(i=0; i<8; i++)
+	{
+		ix		= Get_xTo(i, x);
+		iy		= Get_yTo(i, y);
+
+		if( pDTM->is_InGrid(ix, iy) )
+		{
+			d		= z - pDTM->asDouble(ix, iy);
+		}
+		else
+		{
+			ix		= Get_xTo(i + 4, x);
+			iy		= Get_yTo(i + 4, y);
+
+			if( pDTM->is_InGrid(ix, iy) )
+			{
+				d		= pDTM->asDouble(ix, iy) - z;
+			}
+			else
+			{
+				d		= 0.0;
+			}
+		}
+
+		if( d > 0.0 )
+		{
+			dzSum	+= (dz[i]	= pow(d / Get_Length(i), MFD_Converge));
+		}
+		else
+		{
+			dz[i]	= 0.0;
+		}
+	}
+
+	if( dzSum )
+	{
+		for(i=0; i<8; i++)
+		{
+			if( dz[i] )
+			{
+				Add_Fraction(x, y, i, dz[i] / dzSum );
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			Multiple Triangular Flow Directon			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_MDInf(	int x, int y )
+{
+	int		i, ii, ix, iy;
+	double	z, dzSum, dz[8];
+	double	hs, hr, s_facet[8], r_facet[8];
+	double	valley[8], portion[8];
+	double  cellsize, cellarea;
+	double	nx, ny, nz, n_norm;
+	bool	Dir_inGrid[8];
+
+	z			= pDTM->asDouble(x, y);
+	cellsize	= Get_Cellsize();
+	cellarea	= cellsize * cellsize;
+
+	for(i=0; i<8; i++)
+	{
+		ix		= Get_xTo(i, x);
+		iy		= Get_yTo(i, y);
+		
+//	???
+//		if( x == 6 && y == 7 )
+//		{
+//			int k = 1;
+//		}
+//	???
+
+		s_facet[i] = r_facet[i] = -999.0;
+
+		if( pDTM->is_InGrid(ix, iy) )
+		{
+			dz[i]			= z - pDTM->asDouble(ix, iy);
+			Dir_inGrid[i]	= true;
+		}
+		else
+		{
+			dz[i]			= 0.0;
+			Dir_inGrid[i]	= false;
+		}
+	}
+
+	for(i=0; i<8; i++)
+	{
+		hr = hs = -999.0;
+
+		if( Dir_inGrid[i] )
+		{
+			ii = (i < 7) ? i+1 : 0;
+
+			if( Dir_inGrid[ii] )
+			{
+				nx = ( dz[ii] * Get_yTo( i  ) - dz[i ] * Get_yTo( ii )) * cellsize;
+				ny = ( dz[i ] * Get_xTo( ii ) - dz[ii] * Get_xTo( i  )) * cellsize;
+
+				nz = ( Get_xTo( i ) * Get_yTo( ii ) - Get_xTo( ii ) * Get_yTo( i )) * cellarea;
+
+				n_norm = sqrt( nx*nx + ny*ny +nz*nz );
+
+				if( nx == 0.0 )
+				{
+					hr = (ny >= 0.0)? 0.0 : M_PI;
+				} 
+				else if( nx < 0.0 )
+				{
+					hr = M_PI_270 - atan(ny / nx);
+				} 
+				else
+				{
+					hr = M_PI_090 - atan(ny / nx);
+				}
+
+				hs = -tan( acos( nz/n_norm ) );
+
+				if( hr < i * M_PI_045 || hr > (i+1) * M_PI_045 )
+				{
+					if( dz[i] > dz[ii] )
+					{
+						hr = i * M_PI_045;
+						hs = dz[i] / Get_Length(i);
+					}
+					else
+					{
+						hr = ii * M_PI_045;
+						hs = dz[ii] / Get_Length(ii);						
+					}
+				}
+				
+			}
+			else if( dz[i] > 0.0 )
+			{
+				hr = i * M_PI_045;
+				hs = dz[i] / Get_Length(i);
+			}
+			
+			s_facet[i] = hs;
+			r_facet[i] = hr;
+		}
+	}
+	
+	dzSum		= 0.0;
+	
+	for(i=0; i<8; i++)
+	{		
+		valley[i]	= 0.0;
+		ii = (i < 7)? i+1 : 0;
+		
+		if( s_facet[i] > 0.0 )
+		{
+			if( r_facet[i] > i * M_PI_045 && r_facet[i] < (i+1) * M_PI_045 )
+			{
+				valley[i] = s_facet[i];
+			}
+			else if( r_facet[i] == r_facet[ii] )
+			{
+				valley[i] = s_facet[i];
+			}
+			else if( s_facet[ii] == -999.0 && r_facet[i] == (i+1) * M_PI_045)
+			{
+				valley[i] = s_facet[i];
+			}
+			else
+			{
+				ii = (i > 0)? i-1 : 7;
+
+				if( s_facet[ii] == -999.0 && r_facet[i] == i * M_PI_045 )
+				{
+					valley[i] = s_facet[i];
+				}
+			}
+			
+			valley[i] = pow(valley[i], MFD_Converge);
+			dzSum += valley[i];
+		} 
+		
+		portion[i] = 0.0;
+	}
+
+	if( dzSum )
+	{
+		for(i=0; i<8; i++)
+		{
+			if (i < 7)
+			{
+				ii = i+1;
+			}
+			else
+			{
+				ii = 0;
+
+				if( r_facet[i] == 0.0)
+				{
+					r_facet[i] = M_PI_360;
+				}
+			}
+
+			if( valley[i] )
+			{
+				valley[i] /= dzSum;
+
+				portion[i] += valley[i] * ((i+1) * M_PI_045 - r_facet[i]) / M_PI_045;
+
+				portion[ii] += valley[i] * (r_facet[i] - i * M_PI_045) / M_PI_045;
+			}
+		}
+
+		for(i=0; i<8; i++)
+		{
+			Add_Fraction(x, y, i, portion[i]);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Braunschweiger Reliefmodell				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow_BRM.h"
+
+#define BRM_nint(x)		((int)(x >= 0 ? x + 0.5 : x - 0.5))
+
+
+//---------------------------------------------------------
+void CFlow_Parallel::Set_BRM(	int x, int y )
+{
+	int		Dir, QBinaer,
+			ix[3], iy[3],
+			nexp[6];
+
+	double	QLinks, QMitte, QRecht,
+			nnei[6];
+
+	//-----------------------------------------------------
+	if( is_InGrid(x, y, 1) ) // Rand !!!
+	{
+		Dir	= BRM_InitRZ(x,y,ix,iy);
+
+		if( Dir >= 0 )
+		{
+			if( Dir % 2 )
+			{
+				BRM_GetDiago(Dir,x,y,ix,iy,nnei,nexp);
+				BRM_QStreuung(4,1,nnei,nexp,QBinaer,QLinks,QMitte,QRecht);
+			}
+			else
+			{
+				BRM_GetOrtho(Dir,x,y,ix,iy,nnei,nexp);
+				BRM_QStreuung(6,0,nnei,nexp,QBinaer,QLinks,QMitte,QRecht);
+			}
+
+			Add_Fraction(x,y,(Dir+1)%8,BRM_BitMtrx[0][QBinaer] ? QLinks : 0);
+			Add_Fraction(x,y,(Dir+0)%8,BRM_BitMtrx[1][QBinaer] ? QMitte : 0);
+			Add_Fraction(x,y,(Dir+7)%8,BRM_BitMtrx[2][QBinaer] ? QRecht : 0);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_Parallel::BRM_Init(void)
+{
+	int 	i;
+
+	double	DXT	= Get_Cellsize()/2,
+			DYT	= Get_Cellsize()/2;
+
+	//-----------------------------------------------------
+	BRM_kgexp[0]	= (int)(atan2(DXT     , Get_Cellsize()) * M_RAD_TO_DEG);
+	BRM_kgexp[1]	= (int)(atan2(Get_Cellsize(), DYT     ) * M_RAD_TO_DEG) + 1;
+	BRM_kgexp[2]	= (int)(atan2(Get_Cellsize(),-DYT     ) * M_RAD_TO_DEG);
+	BRM_kgexp[3]	= (int)(atan2(DXT     ,-Get_Cellsize()) * M_RAD_TO_DEG) + 1;
+
+	for(i=0; i<4; i++)
+		BRM_kgexp[i+4]	= BRM_kgexp[i] + 180;
+
+	//-----------------------------------------------------
+	for(i=0; i<=360; i++)
+	{
+		BRM_sinus[i]	= -sin(i * M_DEG_TO_RAD);
+		BRM_cosin[i]	= -cos(i * M_DEG_TO_RAD);
+	}
+
+	//---BRM_idreh---------------------------------------------
+	BRM_idreh[0]	= 180;
+	BRM_idreh[1]	= 180 -	BRM_nint(atan2(Get_Cellsize(), Get_Cellsize()) * M_RAD_TO_DEG);
+	BRM_idreh[2]	=  90;
+	BRM_idreh[3]	=		BRM_nint(atan2(Get_Cellsize(), Get_Cellsize()) * M_RAD_TO_DEG);
+	BRM_idreh[4]	=   0;
+
+	for(i=1; i<4; i++)
+		BRM_idreh[i+4]	= BRM_idreh[i] + 180;
+}
+
+//---------------------------------------------------------
+int CFlow_Parallel::BRM_InitRZ(int x, int y, int ix[3], int iy[3])
+{
+	int		i, j, Dir;
+
+	double	Slope, Aspect;
+
+	Get_Gradient(x, y, Slope, Aspect);
+
+	Aspect	*= M_RAD_TO_DEG;
+
+	if( Aspect < 0 )
+	{
+		return( -1 );
+	}
+
+	//---Kategorisierte-Exposition-------------------------
+	Dir	= 0;
+	while( Aspect > BRM_kgexp[Dir] && Dir < 8 )
+		Dir++;
+	Dir	%=8;
+
+    //---Finde-Die-3-ZielRasterZellen----------------------
+	for(i=0; i<3; i++)	// zxy[]: 0=Recht, 1=Mitte, 2=Links
+	{
+		j		= (Dir + 7 + i) % 8;
+		ix[2-i]	= Get_xTo(j,x);
+		iy[2-i]	= Get_yTo(j,y);
+	}
+
+	return(Dir);
+}
+
+//---------------------------------------------------------
+void CFlow_Parallel::BRM_GetOrtho(int Dir, int x, int y, int ix[3], int iy[3], double nnei[6], int nexp[6])
+{
+	int		jx, jy, i,
+			i0	= (Dir + 2) % 8,
+			i4	= (Dir + 6) % 8;
+
+	double	Slope, Aspect;
+
+	for(i=0; i<3; i++)
+	{
+		jx		= ix[i];
+		jy		= iy[i];
+
+		Get_Gradient(jx, jy, Slope, Aspect);
+
+		nnei[i]	= M_RAD_TO_DEG * Slope;
+		nexp[i]	= (int)(M_RAD_TO_DEG * Aspect);
+	}
+
+	jx		= Get_xTo(i0,x);
+	jy		= Get_yTo(i0,y);
+
+	Get_Gradient(jx, jy, Slope, Aspect);
+
+	nnei[3]	= M_RAD_TO_DEG * Slope;
+	nexp[3]	= (int)(M_RAD_TO_DEG * Aspect);
+
+	jx		= Get_xTo(i4,x);
+	jy		= Get_yTo(i4,y);
+
+	Get_Gradient(jx, jy, Slope, Aspect);
+
+	nnei[5]	= M_RAD_TO_DEG * Slope;
+	nexp[5]	= (int)(M_RAD_TO_DEG * Aspect);
+
+	Get_Gradient(x, y, Slope, Aspect);
+
+	nnei[4]	= M_RAD_TO_DEG * Slope;
+	nexp[4]	= (int)(M_RAD_TO_DEG * Aspect);	//[jy][jx]) ????!!!!...;
+
+	for(i=0; i<6; i++)
+		if(nexp[i]<0)
+			nexp[i]	= nexp[4];
+
+	for(i=0; i<6; i++)
+	{
+		nexp[i]	+= BRM_idreh[Dir];
+
+		if(nexp[i]>360)
+			nexp[i]	-= 360;
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_Parallel::BRM_GetDiago(int Dir, int x, int y, int ix[3], int iy[3], double nnei[6], int nexp[6])
+{
+	int		i;
+
+	double	Slope, Aspect;
+
+	Get_Gradient( x   ,  y   , Slope, Aspect);
+	nexp[0]	= (int)(M_RAD_TO_DEG * Aspect);
+	nnei[0]	= M_RAD_TO_DEG * Slope;
+
+	Get_Gradient(ix[0], iy[0], Slope, Aspect);
+	nexp[1]	= (int)(M_RAD_TO_DEG * Aspect);
+	nnei[1]	= M_RAD_TO_DEG * Slope;
+
+	Get_Gradient(ix[2], iy[2], Slope, Aspect);
+	nexp[2]	= (int)(M_RAD_TO_DEG * Aspect);
+	nnei[2]	= M_RAD_TO_DEG * Slope;
+
+	Get_Gradient(ix[1], iy[1], Slope, Aspect);
+	nexp[3]	= (int)(M_RAD_TO_DEG * Aspect);
+	nnei[3]	= M_RAD_TO_DEG * Slope;
+
+	for(i=1; i<4; i++)
+		if(nexp[i]<0)
+			nexp[i]	= nexp[0];
+
+	for(i=0; i<4; i++)
+	{
+		nexp[i]	+= BRM_idreh[Dir];
+
+		if(nexp[i]>360)
+			nexp[i]	-= 360;
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_Parallel::BRM_QStreuung(int i64, int g64, double nnei[6], int nexp[6], int &QBinaer, double &QLinks, double &QMitte, double &QRecht)
+{
+	int		i, j, ix, iy,
+			ALinks, AMitte=2, ARecht;
+
+	double	x=1, y=1, sg=0, a,
+			s[6], c[6];
+
+	ALinks	= ARecht	= 0;
+	QLinks	= QRecht	= 0.0;
+
+	for(i=0; i<i64; i++)
+		sg	+= nnei[i];
+
+	sg	= i64 / sg;
+
+	for(i=0; i<i64; i++)
+	{
+		a		= sg * nnei[i];
+		j		= nexp[i];
+		s[i]	= a * BRM_sinus[j];
+		c[i]	= a * BRM_cosin[j];
+	}
+
+    //---QLinks-ermitteln----------------------------------
+	for(i=0; i<100; i++)
+	{
+		ix	= BRM_nint(x) - 1;
+		iy	= BRM_nint(y) - 1;
+
+		for(j=0; j<i64; j++)
+		{
+			a		= BRM_g[g64][j][ix][iy];
+			x		+= s[j] * a;
+			y		+= c[j] * a;
+		}	 
+
+		if(x<1)
+		{
+			ALinks	= 0;
+			QLinks	= 0;
+			break;
+		}
+
+		if( x>8.99 || y<1 )
+		{
+			ALinks	= 4;
+			QLinks	= 1;			
+			break;
+		}
+
+		if(y>8.95)
+		{
+			if(x<1.02)
+			{
+				ALinks	= 0;
+				QLinks	= 0;
+			}
+			else
+			{
+				ALinks	= 4;
+				QLinks	= (x - 1) / 8;
+
+				if(i64==4)
+				{
+					if(QLinks<0.5)
+						QLinks	= QLinks * (1.67 - QLinks * 1.078);
+					else
+						QLinks	= QLinks * 0.869 + 0.131;
+				}
+			}
+			break;
+		}
+	}
+
+
+    //---QRechts-ermitteln---------------------------------
+	x	= 9;
+	y	= 1;
+
+	for(i=0; i<100; i++)
+	{
+		ix	= BRM_nint(x) - 1;
+		iy	= BRM_nint(y) - 1;
+
+		for(j=0; j<i64; j++)
+		{
+			a	= BRM_g[g64][j][ix][iy];
+			x	+= s[j] * a;
+			y	+= c[j] * a;
+		}
+
+		if(x>9)
+		{
+			ARecht	= 0;
+			QRecht	= 0;
+			break;
+		}
+
+		if( x<1.01 || y<1 )
+		{
+			ARecht	= 1;
+			QRecht	= 1;
+			break;
+		}
+
+		if(y>8.95)
+		{
+			if(x>8.98)
+			{
+				ARecht	= 0;
+				QRecht	= 0;
+			}
+			else
+			{
+				ARecht	= 1;
+				QRecht	= 1 - (x - 1) / 8;
+
+				if(i64==4)					
+				{
+					if(QRecht<0.5)
+						QRecht	= QRecht * (1.67 - QRecht * 1.078);
+					else
+						QRecht	= QRecht * 0.869 + 0.131;
+				}
+			}
+			break;
+		}
+	}
+
+	//---QMitte-ist-Rest-/-QBinaer'Bits-setzen-------------
+	QMitte	= 1 - QLinks - QRecht;
+	QBinaer	= ALinks + AMitte + ARecht;
+
+	if(QMitte<=0.01)
+	{
+		a		= QLinks + QRecht;
+		QLinks	/= a;
+		QRecht	/= a;
+		QMitte	= 0;
+		QBinaer	-= 2;
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_Parallel.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,129 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Flow_Parallel.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_Parallel_H
+#define HEADER_INCLUDED__Flow_Parallel_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CFlow_Parallel : public CFlow  
+{
+public:
+	CFlow_Parallel(void);
+	virtual ~CFlow_Parallel(void);
+
+
+protected:
+
+	virtual void			On_Initialize	(void);
+
+	virtual void			Calculate		(void);
+	virtual void			Calculate		(int x, int y);
+
+
+private:
+
+	int						BRM_kgexp[8], BRM_idreh[8];
+
+	double					TH_LinearFlow, BRM_sinus[361], BRM_cosin[361];
+
+
+	void					Set_Flow		(void);
+	void					Check_Route		(int x, int y);
+
+	void					Set_D8			(int x, int y);
+	void					Set_Rho8		(int x, int y);
+	void					Set_DInf		(int x, int y);
+	void					Set_MFD			(int x, int y);
+	void					Set_MDInf		(int x, int y);
+	void					Set_BRM			(int x, int y);
+
+	void					BRM_Init		(void);
+	int						BRM_InitRZ		(int x, int y, int ix[3], int iy[3]);
+	void					BRM_GetOrtho	(int Dir, int x, int y, int ix[3], int iy[3], double nnei[6], int nexp[6]);
+	void					BRM_GetDiago	(int Dir, int x, int y, int ix[3], int iy[3], double nnei[6], int nexp[6]);
+	void					BRM_QStreuung	(int i64, int g64, double nnei[6], int nexp[6], int &QBinaer, double &QLinks, double &QMitte, double &QRecht);
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_Parallel_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,734 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Flow_RecursiveDown.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow_RecursiveDown.h"
+
+//---------------------------------------------------------
+#define GET_OUTLET_DIAG__1(in, angle)		(1.0 - (1.0 - in) * tan(M_PI_090 - angle))
+#define GET_OUTLET_CROSS_1(in, angle)		(in + tan(angle))
+
+#define GET_OUTLET_DIAG__2(in, angle)		(in * tan(angle))
+#define GET_OUTLET_CROSS_2(in, angle)		(in - tan(M_PI_090 - angle))
+
+#define GET_LENGTH(a, b)					(sqrt((a)*(a) + (b)*(b)))
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_RecursiveDown::CFlow_RecursiveDown(void)
+{
+	Set_Name(_TL("Flow Tracing"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Flow tracing algorithms for calculations of flow accumulation and related parameters. "
+		"These algorithms trace the flow of each cell in a DEM separately until it finally leaves the DEM or ends in a sink.\n\n"
+
+		"References:\n\n"
+
+		"Rho 8 (this implementation adopted the original algorithm only for the flow routing and will give quite different results):\n"
+		"- Fairfield, J. / Leymarie, P. (1991):\n"
+		"    'Drainage networks from grid digital elevation models',\n"
+		"    Water Resources Research, 27:709-717\n\n"
+
+		"Kinematic Routing Algorithm:\n"
+		"- Lea, N.L. (1992):\n"
+		"    'An aspect driven kinematic routing algorithm',\n"
+		"    in: Parsons, A.J., Abrahams, A.D. (Eds.), 'Overland Flow: hydraulics and erosion mechanics', London, 147-175\n\n"
+
+		"DEMON:\n"
+		"- Costa-Cabral, M. / Burges, S.J. (1994):\n"
+		"    'Digital Elevation Model Networks (DEMON): a model of flow over hillslopes for computation of contributing and dispersal areas',\n"
+		"    Water Resources Research, 30:1681-1692\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Method...
+
+	Parameters.Add_Choice(
+		NULL	, "Method"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Rho 8"),
+			_TL("Kinematic Routing Algorithm"),
+			_TL("DEMON")
+		), 1
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "MINDQV"		, _TL("DEMON - Min. DQV"),
+		_TL("DEMON - Minium Drainage Quota Volume (DQV) for traced flow tubes"),
+		PARAMETER_TYPE_Double	,	0.0, 0.0, true, 1.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CORRECT"		, _TL("Flow Correction"),
+		_TL(""),
+		PARAMETER_TYPE_Bool
+	);
+}
+
+//---------------------------------------------------------
+CFlow_RecursiveDown::~CFlow_RecursiveDown(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::On_Initialize(void)
+{
+	int		x, y;
+	double	Slope, Aspect;
+
+	//-----------------------------------------------------
+	Method			= Parameters("Method"	)->asInt();
+	DEMON_minDQV	= Parameters("MINDQV"	)->asDouble();
+	bFlowPathWeight	= Parameters("CORRECT"	)->asBool();
+
+	pLinear			= 1 ? SG_Create_Grid(pDTM, SG_DATATYPE_Float) : NULL;
+
+	//-----------------------------------------------------
+	Lock_Create();
+
+	//-----------------------------------------------------
+	switch( Method )
+	{
+	case 0: default:	// Rho 8...
+
+		pDir		= NULL;
+		pDif		= NULL;
+
+		break;
+
+	//-----------------------------------------------------
+	case 1:	case 2:		// KRA, DEMON...
+
+		pDir		= SG_Create_Grid(pDTM, SG_DATATYPE_Char);
+		pDif		= SG_Create_Grid(pDTM, SG_DATATYPE_Float);
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !pDTM->is_NoData(x, y) )
+				{
+					Get_Gradient(x, y, Slope, Aspect);
+
+					if( Aspect >= 0.0 )
+					{
+						pDir->Set_Value(x, y, 2 * (((int)(Aspect / M_PI_090)) % 4));
+						pDif->Set_Value(x, y, fmod(Aspect, M_PI_090));
+					}
+				}
+			}
+		}
+
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::On_Finalize(void)
+{
+	int		x, y, dir;
+	long	n;
+	double	qFlow;
+
+	//-----------------------------------------------------
+	if( pDir )
+	{
+		delete(pDir);
+	}
+
+	if( pDif )
+	{
+		delete(pDif);
+	}
+
+	Lock_Destroy();
+
+	//-----------------------------------------------------
+	if( pLinear )
+	{
+		for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+		{
+			;
+
+			if( pDTM->Get_Sorted(n, x, y) && (qFlow = pLinear->asDouble(x, y)) > 0.0 )
+			{
+				Add_Flow(x, y, qFlow);
+
+				if( (dir = pDTM->Get_Gradient_NeighborDir(x, y)) >= 0 )
+				{
+					x	= Get_xTo(dir, x);
+					y	= Get_yTo(dir, y);
+
+					if( pDTM->is_InGrid(x, y) )
+					{
+						pLinear->Add_Value(x, y, qFlow);
+					}
+				}
+			}
+		}
+
+		delete(pLinear);
+
+		pLinear	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::Calculate(void)
+{
+	int		x, y;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y+=Step)
+	{
+		//if( !(y%2) )DataObject_Update(pFlow);
+
+		for(x=0; x<Get_NX(); x+=Step)
+		{
+			Calculate(x, y);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::Calculate(int x, int y)
+{
+	double 	Slope, Aspect, qFlow;
+
+	if( !pDTM->is_NoData(x, y) && (qFlow = pWeight ? pWeight->asDouble(x, y) : 1.0) > 0.0 )
+	{
+		Get_Gradient(x, y, Slope, Aspect);
+
+		Src_Height	= pDTM->asDouble(x,y);
+		Src_Slope	= Slope;
+
+		Add_Flow(x, y, qFlow);
+		Lock_Set(x, y, 1);
+
+		//-------------------------------------------------
+		switch( Method )
+		{
+		case 0:
+			Rho8_Start(		x, y, qFlow );
+			break;
+
+		case 1:
+			KRA_Start(		x, y, qFlow );
+			break;
+
+		case 2:
+			DEMON_Start(	x, y, qFlow );
+			break;
+		}
+
+		Lock_Set(x, y, 0);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::Add_Flow(int x, int y, double Fraction)
+{
+	if( pCatch )
+	{
+		pCatch			->Add_Value(x, y, Fraction );
+	}
+
+	if( pCatch_Height )
+	{
+		pCatch_Height	->Add_Value(x, y, Fraction * Src_Height );
+	}
+
+	if( pCatch_Slope )
+	{
+		pCatch_Slope	->Add_Value(x, y, Fraction * Src_Slope );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::Rho8_Start(int x, int y, double qFlow)
+{
+	int		dir, ix, iy;
+	double 	Slope, Aspect;
+
+	//-----------------------------------------------------
+	Get_Gradient(x, y, Slope, Aspect);
+
+	if( Aspect >= 0.0 )
+	{
+		dir		= (int)(Aspect / M_PI_045);
+
+		if( fmod(Aspect, M_PI_045) / M_PI_045 > rand() / (double)RAND_MAX )
+		{
+			dir++;
+		}
+
+		dir	%= 8;
+
+		ix		= Get_xTo(dir, x);
+		iy		= Get_yTo(dir, y);
+
+		//-------------------------------------------------
+		if( is_InGrid(ix, iy) )
+		{
+			if( is_Locked(ix, iy) )
+			{
+				if( pLinear )
+				{
+					pLinear->Add_Value(x, y, qFlow);
+				}
+			}
+			else
+			{
+				Lock_Set( x,  y, 1);
+				Add_Flow(ix, iy, qFlow);
+				Rho8_Start(ix, iy, qFlow);
+				Lock_Set( x,  y, 0);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::KRA_Start(int x, int y, double qFlow)
+{
+	int		dir;
+	double	dif;
+
+	if( (dif = pDif->asDouble(x, y)) > M_PI_045 )	// to the right...
+	{
+		dir		= pDir->asInt(x, y) + 2;
+		dif		= 0.5 - tan(M_PI_090 - dif) / 2.0;
+	}
+	else											// to the top...
+	{
+		dir		= pDir->asInt(x, y) + 0;
+		dif		= 0.5 + tan(dif) / 2.0;
+	}
+
+	KRA_Trace(x, y, qFlow, dir, dif);
+}
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::KRA_Trace(int x, int y, double qFlow, int Direction, double from)
+{
+	bool	bLinear;
+	int		dir;
+	double	dif, to, weight;
+
+	Direction	%= 8;
+
+	x	= Get_xTo(Direction, x);
+	y	= Get_yTo(Direction, y);
+
+	//-----------------------------------------------------
+	if( pDTM->is_InGrid(x, y) && !is_Locked(x, y) )
+	{
+		Lock_Set(x, y, 1);
+
+		bLinear	= false;
+		weight	= 1.0;
+
+		dir		= pDir->asInt(x, y);
+		dif		= pDif->asDouble(x, y);
+
+		//-------------------------------------------------
+		if( Direction == dir )						// entering from the bottom...
+		{
+			if( from > 1.0 - tan(dif) )				// 1. to the right...
+			{
+				to		= GET_OUTLET_DIAG__1(from, dif);
+
+				KRA_Trace(x, y, qFlow, dir + 2, to);
+
+				if( bFlowPathWeight )
+				{
+					weight	= GET_LENGTH(1.0 - from, 1.0 - to);
+				}
+			}
+			else									// 2. to the top...
+			{
+				to		= GET_OUTLET_CROSS_1(from, dif);
+
+				KRA_Trace(x, y, qFlow, dir + 0, to);
+
+				if( bFlowPathWeight )
+				{
+					weight	= GET_LENGTH(1.0, to - from);
+				}
+			}
+		}
+		else if( (8 + Direction - dir) % 8 == 2 )	// entering from the left...
+		{
+			if( from < tan(M_PI_090 - dif) )		// 1. to the top...
+			{
+				to		= GET_OUTLET_DIAG__2(from, dif);
+
+				KRA_Trace(x, y, qFlow, dir + 0, to);
+
+				if( bFlowPathWeight )
+				{
+					weight	= GET_LENGTH(from, to);
+				}
+			}
+			else									// 2. to the right...
+			{
+				to		= GET_OUTLET_CROSS_2(from, dif);
+
+				KRA_Trace(x, y, qFlow, dir + 2, to);
+
+				if( bFlowPathWeight )
+				{
+					weight	= GET_LENGTH(1.0, from - to);
+				}
+			}
+		}
+		else										// go linear...
+		{
+			bLinear	= true;
+		}
+
+		//-------------------------------------------------
+		if( bLinear && pLinear )
+		{
+			pLinear->Add_Value(x, y, qFlow);
+		}
+		else
+		{
+			Add_Flow(x, y, weight * qFlow);
+		}
+
+		Lock_Set(x, y, 0);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//		DEMON - Digital Elevation MOdel Network			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::DEMON_Start(int x, int y, double qFlow)
+{
+	double	dif, flow_A, flow_B;
+
+	if( (dif = pDif->asDouble(x, y)) < M_PI_045 )	// mostly to the top...
+	{
+		flow_B	= tan(dif) / 2.0;
+		flow_A	= 1.0 - flow_B;
+	}
+	else											// mostly to the right...
+	{
+		flow_A	= tan(M_PI_090 - dif) / 2.0;
+		flow_B	= 1.0 - flow_A;
+	}
+
+	flow_A	*= qFlow;
+	flow_B	*= qFlow;
+
+	if( flow_A <= DEMON_minDQV )
+	{
+		DEMON_Trace(x, y, qFlow , pDir->asInt(x, y) + 2, 0.0, 1.0);	// all to the right...
+	}
+	else if( flow_B <= DEMON_minDQV )
+	{
+		DEMON_Trace(x, y, qFlow , pDir->asInt(x, y) + 0, 0.0, 1.0);	// all to the top...
+	}
+	else
+	{
+		DEMON_Trace(x, y, flow_A, pDir->asInt(x, y) + 0, 0.0, 1.0);	// to the top...
+		DEMON_Trace(x, y, flow_B, pDir->asInt(x, y) + 2, 0.0, 1.0);	// to the right...
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_RecursiveDown::DEMON_Trace(int x, int y, double qFlow, int Direction, double from_A, double from_B)
+{
+	bool	bLinear;
+	int		dir;
+	double	dif, to_A, to_B, flow_A, flow_B, weight;
+
+	Direction	%= 8;
+
+	x	= Get_xTo(Direction, x);
+	y	= Get_yTo(Direction, y);
+
+	//-----------------------------------------------------
+	if( pDTM->is_InGrid(x, y) && !is_Locked(x, y) )
+	{
+		Lock_Set(x, y, 1);
+
+		bLinear	= false;
+		weight	= 1.0;
+
+		dir		= pDir->asInt(x, y);
+		dif		= pDif->asDouble(x, y);
+
+		//-------------------------------------------------
+		if( Direction == dir )						// entering from the bottom...
+		{
+			if( from_A >= 1.0 - tan(dif) )			// 1. completely to the right...
+			{
+				to_A	= GET_OUTLET_DIAG__1(from_A, dif);
+				to_B	= GET_OUTLET_DIAG__1(from_B, dif);
+
+				DEMON_Trace(x, y, qFlow, dir + 2, to_A, to_B);
+
+				if( bFlowPathWeight )
+				{
+					//weight	= ((1.0 - from_A) * (1.0 - to_A) - (1.0 - from_B) * (1.0 - to_B)) / 2.0;	// area...
+					weight	= GET_LENGTH(1.0 - (from_B + from_A) / 2.0, 1.0 - (to_B + to_A) / 2.0);
+				}
+			}
+			else if( from_B < 1.0 - tan(dif) )		// 2. completely to the top...
+			{
+				to_A	= GET_OUTLET_CROSS_1(from_A, dif);
+				to_B	= GET_OUTLET_CROSS_1(from_B, dif);
+
+				DEMON_Trace(x, y, qFlow, dir + 0, to_A, to_B);
+
+				if( bFlowPathWeight )
+				{
+					//weight	= from_B - from_A;	// area...
+					weight	= GET_LENGTH(1.0, to_A - from_A);
+				}
+			}
+			else									// 3. partly to the right, partly to the top...
+			{
+				to_A	= GET_OUTLET_CROSS_1(from_A, dif);
+				to_B	= GET_OUTLET_DIAG__1(from_B, dif);
+
+				dif		= 1.0 - tan(dif);
+
+				flow_A	= dif - from_A;
+				flow_B	= from_B - dif;
+				flow_A	= qFlow * flow_A / (flow_A + flow_B);
+				flow_B	= qFlow - flow_A;
+
+				if( bFlowPathWeight )
+				{
+					//weight	= (dif - from_A) + ((1.0 - dif) - (1.0 - from_B) * (1.0 - to_B)) / 2.0;	// area...
+					if( (weight = (from_A + from_B) / 2.0) < dif )	// to the top...
+					{
+						weight	= GET_LENGTH(1.0, to_A - from_A);
+					}
+					else											// to the right...
+					{
+						weight	= (1.0 - weight) / (1.0 - dif) * GET_LENGTH(1.0, to_A - from_A);
+					}
+				}
+
+				if( flow_A <= DEMON_minDQV )
+				{
+					DEMON_Trace(x, y, qFlow, dir + 2, 0.0, to_B);
+				}
+				else if( flow_B <= DEMON_minDQV )
+				{
+					DEMON_Trace(x, y, qFlow, dir + 0, to_A, 1.0);
+				}
+				else
+				{
+					DEMON_Trace(x, y, flow_A, dir + 0, to_A, 1.0);
+					DEMON_Trace(x, y, flow_B, dir + 2, 0.0, to_B);
+				}
+			}
+		}
+		else if( (8 + Direction - dir) % 8 == 2 )	// entering from the left...
+		{
+			if( from_B <= tan(M_PI_090 - dif) )		// 1. completely to the top...
+			{
+				to_A	= GET_OUTLET_DIAG__2(from_A, dif);
+				to_B	= GET_OUTLET_DIAG__2(from_B, dif);
+
+				DEMON_Trace(x, y, qFlow, dir + 0, to_A, to_B);
+
+				if( bFlowPathWeight )
+				{
+					//weight	= (from_B * to_B - from_A * to_A) / 2.0;	// area...
+					weight	= GET_LENGTH((from_A + from_B) / 2.0, (to_A + to_B) / 2.0);
+				}
+			}
+			else if( from_A > tan(M_PI_090 - dif) )	// 2. completely to the right...
+			{
+				to_A	= GET_OUTLET_CROSS_2(from_A, dif);
+				to_B	= GET_OUTLET_CROSS_2(from_B, dif);
+
+				DEMON_Trace(x, y, qFlow, dir + 2, to_A, to_B);
+
+				if( bFlowPathWeight )
+				{
+					//weight	= from_B - from_A;	// area...
+					weight	= GET_LENGTH(1.0, from_A - to_A);
+				}
+			}
+			else									// 3. partly to the top, partly to the right...
+			{
+				to_A	= GET_OUTLET_DIAG__2(from_A, dif);
+				to_B	= GET_OUTLET_CROSS_2(from_B, dif);
+
+				dif		= tan(M_PI_090 - dif);
+
+				flow_A	= dif - from_A;
+				flow_B	= from_B - dif;
+				flow_A	= qFlow * flow_A / (flow_A + flow_B);
+				flow_B	= qFlow - flow_A;
+
+				if( bFlowPathWeight )
+				{
+					//weight	= (from_B - dif) + (dif - (from_A * to_A)) / 2.0;	// area...
+					if( (weight = (from_A + from_B) / 2.0) > dif )
+					{
+						weight	= GET_LENGTH(1.0, from_B - to_B);
+					}
+					else
+					{
+						weight	= weight / dif * GET_LENGTH(1.0, from_B - to_B);
+					}
+				}
+
+				if( flow_A <= DEMON_minDQV )
+				{
+					DEMON_Trace(x, y, qFlow, dir + 2, 0.0, to_B);
+				}
+				else if( flow_B <= DEMON_minDQV )
+				{
+					DEMON_Trace(x, y, qFlow, dir + 0, to_A, 1.0);
+				}
+				else
+				{
+					DEMON_Trace(x, y, flow_A, dir + 0, to_A, 1.0);
+					DEMON_Trace(x, y, flow_B, dir + 2, 0.0, to_B);
+				}
+			}
+		}
+		else
+		{
+			bLinear	= true;
+		}
+
+		//-------------------------------------------------
+		if( bLinear && pLinear )
+		{
+			pLinear->Add_Value(x, y, qFlow);
+		}
+		else
+		{
+			if( bFlowPathWeight )
+			{
+				Add_Flow(x, y, weight * qFlow);
+				//Add_Flow(x, y, weight >= qFlow ? qFlow : weight * qFlow);
+			}
+			else
+			{
+				Add_Flow(x, y, qFlow);
+			}
+		}
+
+		Lock_Set(x, y, 0);
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveDown.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Flow_RecursiveDown.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_RecursiveDown_H
+#define HEADER_INCLUDED__Flow_RecursiveDown_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CFlow_RecursiveDown : public CFlow  
+{
+public:
+	CFlow_RecursiveDown(void);
+	virtual ~CFlow_RecursiveDown(void);
+
+
+protected:
+
+	virtual void			On_Initialize	(void);
+	virtual void			On_Finalize		(void);
+
+	virtual void			Calculate		(void);
+	virtual void			Calculate		(int x, int y);
+
+
+private:
+
+	bool					bFlowPathWeight;
+
+	int						Method;
+
+	double					Src_Height, Src_Slope, DEMON_minDQV;
+
+	CSG_Grid					*pLinear, *pDir, *pDif;
+
+
+	void					Add_Flow		(int x, int y, double qFlow);
+
+	void					Rho8_Start		(int x, int y, double qFlow);
+
+	void					KRA_Start		(int x, int y, double qFlow);
+	void					KRA_Trace		(int x, int y, double qFlow, int Direction, double from);
+
+	void					DEMON_Start		(int x, int y, double qFlow);
+	void					DEMON_Trace		(int x, int y, double qFlow, int Direction, double from_A, double from_B);
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_RecursiveDown_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,467 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Flow_RecursiveUp.cpp                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "Flow_RecursiveUp.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_RecursiveUp::CFlow_RecursiveUp(void)
+{
+	Set_Name(_TL("Recursive Upward Processing"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Recursive upward processing of cells for calculation of flow accumulation and related parameters. "
+		"This set of algorithms processes recursively all upwards connected cells until each cell of the DEM has been processed.\n\n"
+
+		"References:\n\n"
+
+		"Deterministic 8\n"
+		"- O'Callaghan, J.F. / Mark, D.M. (1984):\n"
+		"    'The extraction of drainage networks from digital elevation data',\n"
+		"    Computer Vision, Graphics and Image Processing, 28:323-344\n\n"
+
+		"Rho 8:\n"
+		"- Fairfield, J. / Leymarie, P. (1991):\n"
+		"    'Drainage networks from grid digital elevation models',\n"
+		"    Water Resources Research, 27:709-717\n\n"
+
+		"Deterministic Infinity:\n"
+		"- Tarboton, D.G. (1997):\n"
+		"    'A new method for the determination of flow directions and upslope areas in grid digital elevation models',\n"
+		"    Water Ressources Research, Vol.33, No.2, p.309-319\n\n"
+
+		"Multiple Flow Direction:\n"
+		"- Freeman, G.T. (1991):\n"
+		"    'Calculating catchment area with divergent flow based on a regular grid',\n"
+		"    Computers and Geosciences, 17:413-22\n\n"
+
+		"- Quinn, P.F. / Beven, K.J. / Chevallier, P. / Planchon, O. (1991):\n"
+		"    'The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models',\n"
+		"    Hydrological Processes, 5:59-79\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "TARGETS"		, _TL("Target Areas"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "FLOWLEN"		, _TL("Flow Path Length"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Method...
+
+	Parameters.Add_Choice(
+		NULL	, "Method"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Deterministic 8"),
+			_TL("Rho 8"),
+			_TL("Deterministic Infinity"),
+			_TL("Multiple Flow Direction")
+		), 3
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "CONVERGENCE"	, _TL("Convergence"),
+		_TL("Convergence factor for Multiple Flow Direction Algorithm (Freeman 1991)"),
+		PARAMETER_TYPE_Double	, 1.1
+	);
+
+	
+	//-----------------------------------------------------
+	// Initialisations...
+
+	Flow	= NULL;
+}
+
+//---------------------------------------------------------
+CFlow_RecursiveUp::~CFlow_RecursiveUp(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::On_Create(void)
+{
+	int		x, y, Method;
+
+	double	*p;
+
+	//-----------------------------------------------------
+	On_Destroy();
+
+	Flow	= (double ***)SG_Malloc(    Get_NY()  * sizeof(double **));
+	p		= (double   *)SG_Malloc(8 * Get_NCells() * sizeof(double   ));
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		Flow[y]	= (double **)SG_Malloc( Get_NX()  * sizeof(double  *));
+
+		for(x=0; x<Get_NX(); x++, p+=8)
+		{
+			Flow[y][x]	= p;
+		}
+	}
+
+	//-----------------------------------------------------
+	Lock_Create();
+
+	Method	= Parameters("Method")->asInt();
+
+	memset(Flow[0][0], 0, 8 * Get_NCells() * sizeof(double) );
+
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pRoute && pRoute->asChar(x,y) > 0 )
+			{
+				Flow[y][x][pRoute->asChar(x,y) % 8]	= 1.0;
+			}
+			else
+			{
+				switch( Method )
+				{
+					case 0:
+						Set_D8(x,y);
+						break;
+
+					case 1:
+						Set_Rho8(x,y);
+						break;
+
+					case 2:
+						Set_DInf(x,y);
+						break;
+
+					case 3:
+						Set_MFD(x,y);
+						break;
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::On_Destroy(void)
+{
+	int		y;
+
+	if( Flow )
+	{
+		SG_Free(Flow[0][0]);
+
+		for(y=0; y<Get_NY(); y++)
+		{
+			SG_Free(Flow[y]);
+		}
+
+		SG_Free(Flow);
+
+		Flow	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::On_Initialize(void)
+{
+	pFlowPath			= Parameters("FLOWLEN")->asGrid();
+
+	MFD_Converge		= Parameters("CONVERGENCE")->asDouble();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Calculate(void)
+{
+	int		x, y;
+	CSG_Grid	*pTargets	= Parameters("TARGETS")->asGrid();
+
+	On_Create();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pTargets || !pTargets->is_NoData(x, y) )
+			{
+				Get_Flow(x, y);
+			}
+		}
+	}
+
+	On_Destroy();
+}
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Calculate(int x, int y)
+{
+	On_Create();
+
+	Get_Flow(x,y);
+
+	On_Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Get_Flow(int x, int y)
+{
+	int		i, ix, iy, j;
+
+	double	jFlow;
+
+	if( !is_Locked(x,y) )
+	{
+		Lock_Set(x,y);
+
+		Init_Cell(x,y);
+
+		for(i=0, j=4; i<8; i++, j=(j+1)%8)
+		{
+			ix	= Get_xTo(i,x);
+			iy	= Get_yTo(i,y);
+
+			if( is_InGrid(ix,iy) )
+			{
+				jFlow	= Flow[iy][ix][j];
+
+				if( jFlow > 0 )
+				{
+					Get_Flow(ix,iy);
+
+					Add_Fraction(ix,iy,j,jFlow);
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Set_D8(int x, int y)
+{
+	int		Direction;
+
+	Direction	= pDTM->Get_Gradient_NeighborDir(x,y);
+
+	if( Direction >= 0 )
+	{
+		Flow[y][x][Direction % 8]	= 1.0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Set_Rho8(int x, int y)
+{
+	int		Direction;
+
+	double 	Slope, Aspect;
+
+	Get_Gradient(x, y, Slope, Aspect);
+
+	Aspect	*= M_RAD_TO_DEG;
+
+	if( Aspect >= 0 )
+	{
+		Direction	= (int)(Aspect / 45.0);
+
+		if( fmod(Aspect,45) / 45.0 > rand() / (double)RAND_MAX )
+			Direction++;
+
+		Direction	%= 8;
+
+		Flow[y][x][Direction]	= 1.0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Set_DInf(int x, int y)
+{
+	int		Direction;
+
+	double 	Slope, Aspect;
+
+	Get_Gradient(x, y, Slope, Aspect);
+
+	Aspect	*= M_RAD_TO_DEG;
+
+	if( Aspect >= 0 )
+	{
+		Direction	= (int)(Aspect / 45.0);
+		Aspect		= fmod(Aspect,45) / 45.0;
+
+		Flow[y][x][(Direction    ) % 8]	= 1 - Aspect;
+		Flow[y][x][(Direction + 1) % 8]	=     Aspect;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CFlow_RecursiveUp::Set_MFD(int x, int y)
+{
+	int		i, ix, iy;
+
+	double	z, d, *dz, dzSum;
+
+	z		= pDTM->asDouble(x,y);
+	dz		= Flow[y][x];
+	dzSum	= 0;
+
+	for(i=0; i<8; i++)
+	{
+		ix	= Get_xTo(i,x);
+		iy	= Get_yTo(i,y);
+
+		if( is_InGrid(ix,iy) )
+		{
+			d	= z - pDTM->asDouble(ix,iy);
+
+			if( d > 0 )
+				dzSum	+= dz[i]	= pow(d / Get_Length(i), MFD_Converge);
+		}
+	}
+
+	if( dzSum )
+	{
+		for(i=0; i<8; i++)
+			if( dz[i] > 0 )
+				dz[i]	/= dzSum;
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/Flow_RecursiveUp.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Flow_RecursiveUp.h                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Flow_RecursiveUp_H
+#define HEADER_INCLUDED__Flow_RecursiveUp_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Flow.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CFlow_RecursiveUp : public CFlow
+{
+public:
+	CFlow_RecursiveUp(void);
+	virtual ~CFlow_RecursiveUp(void);
+
+
+protected:
+
+	virtual void			On_Initialize	(void);
+
+	virtual void			Calculate		(void);
+	virtual void			Calculate		(int x, int y);
+
+
+private:
+
+	double					***Flow;
+
+
+	void					On_Create		(void);
+	void					On_Destroy		(void);
+
+	void					Get_Flow		(int x, int y );
+
+	void					Set_D8			(int x, int y );
+	void					Set_Rho8		(int x, int y );
+	void					Set_DInf		(int x, int y );
+	void					Set_MFD			(int x, int y );
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Flow_RecursiveUp_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,195 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     LakeFlood.cpp                     //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de                         //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "LakeFlood.h"
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+CLakeFlood::CLakeFlood(void)
+{
+	// Parameter Settings for input dialog of the module
+
+	Parameters.Set_Name(_TL("Lake Flood"));
+	Set_Author(_TL("Copyrights (c) 2005 by Volker Wichmann"));
+	Parameters.Set_Description(_TW(
+		"This module can be used to simulate the extent and volume of a lake for a specified water depth in a seed cell.\r\n"
+	));
+
+
+	Parameters.Add_Grid(	
+		NULL, "ELEV", _TL("DEM"), 
+		_TL("digital elevation model [m]"),
+		PARAMETER_INPUT
+	);
+	Parameters.Add_Grid(	
+		NULL, "INDEPTH", _TL("Water Depth"),
+		_TL("seed cell coded with local water depth [m], all other cells NoData"),
+		PARAMETER_INPUT
+	);
+	Parameters.Add_Grid(	
+		NULL, "OUTDEPTH", _TL("Lake"), 
+		_TL("extent of lake, coded with water depth [m]"),
+		PARAMETER_OUTPUT
+	);
+
+}
+
+//---------------------------------------------------------
+CLakeFlood::~CLakeFlood(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+bool CLakeFlood::On_Execute(void)		
+{
+	CSG_Grid	*pElev, *pIdepth, *pOdepth;
+	CTraceOrder	*newCell, *firstCell, *iterCell, *lastCell;
+	int			x, y, ix, iy, i;
+	double		wzSeed, z, d;
+
+	pElev		= Parameters("ELEV")->asGrid();
+	pIdepth		= Parameters("INDEPTH")->asGrid();
+	pOdepth		= Parameters("OUTDEPTH")->asGrid();
+
+
+	// Initialize Grids
+	pOdepth->Assign(0.0);
+
+	
+	// Get seed cell and water depth
+	for(y=0; y<Get_NY(); y++)									
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pIdepth->is_NoData(x, y) )
+			{
+				if( !pElev->is_NoData(x, y) )
+				{
+					newCell = new CTraceOrder();
+					newCell->x = x;
+					newCell->y = y;
+					firstCell = newCell;
+					wzSeed = pIdepth->asDouble(x, y);
+					pOdepth->Set_Value(x, y, wzSeed);
+					wzSeed +=  pElev->asDouble(x, y);
+					// terminate search
+				}
+				else
+					firstCell = NULL;
+			}
+		}
+	}
+
+	// main
+	//-----------------------------------------------------
+	iterCell = firstCell;
+	lastCell = firstCell;
+
+	while( iterCell != NULL ) 
+	{
+		x	= iterCell->x;
+		y	= iterCell->y;
+
+		z		= pElev->asDouble(x, y);
+
+		for(i=0; i<8; i++)												
+		{
+			ix	= Get_xTo(i, x);			
+			iy	= Get_yTo(i, y);			
+						
+			if(	is_InGrid(ix, iy) && !pElev->is_NoData(ix, iy) && pOdepth->asDouble(ix, iy) == 0.0 )
+			{ 
+				d	= pElev->asDouble(ix, iy);
+				if( d < wzSeed )
+				{
+					pOdepth->Set_Value(ix, iy, (wzSeed - d));
+					newCell = new CTraceOrder();
+					newCell->x = ix;
+					newCell->y = iy;
+					newCell->prev = lastCell;
+					lastCell->next = newCell;
+					lastCell = newCell;
+				}
+			}
+		}
+	
+		newCell = firstCell;
+
+		if( newCell->next == NULL )
+		{
+			firstCell = NULL;
+			delete (newCell);
+		}
+		else
+		{
+			newCell->next->prev = NULL;
+			firstCell = newCell->next;
+			newCell->next = NULL;
+			delete (newCell);
+		}
+
+		iterCell = firstCell;
+	}
+
+	//-----------------------------------------------------
+
+	return( true );
+}
+

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFlood.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,156 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      LakeFlood.h                      //
+//                                                       //
+//                 Copyright (C) 2005-6 by               //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     volkerwichmann at ku-eichstaett.de        //
+//                                                       //
+//    contact:    Volker Wichmann                        //
+//                Research Associate                     //
+//                Chair of Physical Geography		     //
+//				  KU Eichstätt-Ingolstadt				 //
+//                Ostenstr. 18                           //
+//                85072 Eichstätt                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__LakeFlood_H
+#define HEADER_INCLUDED__LakeFlood_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTraceOrder
+{
+public:
+	CTraceOrder(void)
+	{
+		x = y = 0;
+		prev = NULL;
+		next = NULL;
+	};
+
+	~CTraceOrder(void)
+	{
+		if(next != NULL)
+			delete (next);
+		next = NULL;
+	};
+
+	int		x;
+	int		y;
+	CTraceOrder *prev;
+	CTraceOrder	*next;
+
+};
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CLakeFlood : public CSG_Module_Grid
+{
+public:
+	CLakeFlood(void);
+	virtual ~CLakeFlood(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Lakes") );	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+
+
+};
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CLakeFloodInteractive : public CSG_Module_Grid_Interactive
+{
+public:
+	CLakeFloodInteractive(void);
+	virtual ~CLakeFloodInteractive(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Lakes") );	}
+
+
+protected:
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Finish	(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+private:
+	CSG_Grid				*pElev, *pOdepth;
+	CTraceOrder				*newCell, *firstCell, *iterCell, *lastCell;
+	double					wzSeed;
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__LakeFlood_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFloodInteractive.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFloodInteractive.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/LakeFloodInteractive.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,202 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               LakeFloodInteractive.cpp                //
+//                                                       //
+//                Copyright (C) 2005-6 by                //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de                         //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "LakeFlood.h"
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+CLakeFloodInteractive::CLakeFloodInteractive(void)
+{
+	// Parameter Settings for input dialog of the module
+
+	Parameters.Set_Name(_TL("Lake Flood"));
+	Set_Author(_TL("Copyrights (c) 2005-6 by Volker Wichmann"));
+	Parameters.Set_Description(_TW(
+		"This module works interactively and can be used to simulate the extent and volume of a lake for a given water depth. "
+		"Execute the module and use the action tool on a cell of the digital elevation model to fill the lake starting from this "
+		"location. Execute the module again to terminate module operation.\r\n")
+	);
+
+
+	Parameters.Add_Grid(	
+		NULL, "ELEV", _TL("DEM"), 
+		_TL("digital elevation model [m]"),
+		PARAMETER_INPUT
+	);
+	Parameters.Add_Value(
+		NULL, "INDEPTH", _TL("Water Depth"),
+		_TL("water depth at the user specified cell [m]"),
+		PARAMETER_TYPE_Double,
+		2.5
+	); 
+	Parameters.Add_Grid(	
+		NULL, "OUTDEPTH", _TL("Lake"), 
+		_TL("extent of lake, coded with local water depth [m]"),
+		PARAMETER_OUTPUT
+	);
+
+}
+
+//---------------------------------------------------------
+CLakeFloodInteractive::~CLakeFloodInteractive(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+bool CLakeFloodInteractive::On_Execute(void)									
+{
+	pElev		= Parameters("ELEV")->asGrid();
+	pOdepth		= Parameters("OUTDEPTH")->asGrid();
+	wzSeed		= Parameters("INDEPTH")->asDouble();
+
+	return (true);
+}
+
+//---------------------------------------------------------
+bool CLakeFloodInteractive::On_Execute_Finish(void)
+{
+	return( true );
+}
+
+
+//---------------------------------------------------------
+bool CLakeFloodInteractive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	//-----------------------------------------------------
+	if(  Mode == MODULE_INTERACTIVE_LDOWN )
+	{
+		int			x, y, ix, iy, i;
+		double		z, d, wz;
+
+		wz	= wzSeed;
+	
+		x	= Get_System()->Get_xWorld_to_Grid(ptWorld.Get_X());
+		y	= Get_System()->Get_yWorld_to_Grid(ptWorld.Get_Y());
+	
+		if( pElev && pElev->is_InGrid(x, y) )
+		{
+			pOdepth->Assign(0.0);
+
+			newCell = new CTraceOrder();
+			newCell->x = x;
+			newCell->y = y;
+			firstCell = newCell;
+			
+			pOdepth->Set_Value(x, y, wzSeed);
+			wz +=  pElev->asDouble(x, y);
+		
+
+			iterCell = firstCell;
+			lastCell = firstCell;
+
+			while( iterCell != NULL ) 
+			{
+				x	= iterCell->x;
+				y	= iterCell->y;
+
+				z		= pElev->asDouble(x, y);
+
+				for(i=0; i<8; i++)												
+				{
+					ix	= Get_xTo(i, x);			
+					iy	= Get_yTo(i, y);			
+						
+					if(	is_InGrid(ix, iy) && !pElev->is_NoData(ix, iy) && pOdepth->asDouble(ix, iy) == 0.0 )
+					{ 
+						d	= pElev->asDouble(ix, iy);
+						if( d < wz )
+						{
+							pOdepth->Set_Value(ix, iy, (wz - d));
+							newCell = new CTraceOrder();
+							newCell->x = ix;
+							newCell->y = iy;
+							newCell->prev = lastCell;
+							lastCell->next = newCell;
+							lastCell = newCell;
+						}
+					}
+				}
+	
+				newCell = firstCell;
+
+				if( newCell->next == NULL )
+				{
+					firstCell = NULL;
+					delete (newCell);
+				}
+				else
+				{
+					newCell->next->prev = NULL;
+					firstCell = newCell->next;
+					newCell->next = NULL;
+					delete (newCell);
+				}
+
+				iterCell = firstCell;
+			}
+			Message_Add(_TL("ready"), false);
+			DataObject_Update(pOdepth, pOdepth->Get_ZMin(), pOdepth->Get_ZMax());
+
+			return( true );
+		}
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,158 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Terrain Analysis - Hydrology") );
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Victor Olaya (c) 2001-4") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for digital terrain analysis.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Terrain Analysis|Hydrology") );
+	}
+}
+
+
+//---------------------------------------------------------
+#include "Flow_Parallel.h"
+#include "Flow_RecursiveUp.h"
+#include "Flow_RecursiveDown.h"
+#include "Flow_AreaUpslope.h"
+#include "Flow_AreaDownslope.h"
+
+#include "Flow_Distance.h"
+#include "SlopeLength.h"
+
+#include "EdgeContamination.h"
+
+#include "IsochronesConst.h"
+#include "IsochronesVar.h"
+
+#include "CellBalance.h"
+#include "Sinuosity.h"
+
+#include "FlowDepth.h"
+
+#include "TopographicIndices.h"
+#include "SAGA_Wetness_Index.h"
+
+#include "LakeFlood.h"
+
+#include "flow_massflux.h"
+#include "flow_width.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case  0:	return( new CFlow_Parallel );
+	case  1:	return( new CFlow_RecursiveUp );
+	case  2:	return( new CFlow_RecursiveDown );
+	case  3:	return( new CFlow_AreaUpslope_Interactive );
+	case  4:	return( new CFlow_AreaUpslope_Area );
+	case  5:	return( new CFlow_AreaDownslope );
+	case  6:	return( new CFlow_Distance );
+	case  7:	return( new CSlopeLength );
+	case  8:	return( new CIsochronesConst );
+	case  9:	return( new CIsochronesVar );
+	case 10:	return( new CCellBalance );
+	case 11:	return( new CSinuosity );
+	case 12:	return( new CFlowDepth );
+	case 13:	return( new CEdgeContamination );
+	case 14:	return( new CTopographicIndices );
+	case 15:	return( new CSAGA_Wetness_Index );
+	case 16:	return( new CLakeFlood );
+	case 17:	return( new CLakeFloodInteractive );
+	case 18:	return( new CFlow_MassFlux );
+	case 19:	return( new CFlow_Width );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ta_hydrology_H
+#define HEADER_INCLUDED__ta_hydrology_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef ta_hydrology_EXPORTS
+	#define	ta_hydrology_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	ta_hydrology_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ta_hydrology_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1008 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 SAGA_Wetness_Index.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "SAGA_Wetness_Index.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSAGA_Wetness_Index::CSAGA_Wetness_Index(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("SAGA Wetness Index"));
+
+	Set_Author		(SG_T("(c) 2001 by J.Boehner, O.Conrad"));
+
+	Set_Description	(_TW(
+		"The 'SAGA Wetness Index' is, as the name says, similar to the "
+		"'Topographic Wetness Index' (TWI), but it is based on a modified "
+		"catchment area calculation ('Modified Catchment Area'), which does "
+		"not think of the flow as very thin film. As result it predicts for "
+		"cells situated in valley floors with a small vertical distance to "
+		"a channel a more realistic, higher potential soil moisture compared "
+		"to the standard TWI calculation.\n\n"
+
+		"References\n"
+
+		"- Boehner, J., Koethe, R. Conrad, O., Gross, J., Ringeler, A., Selige, T. (2002): "
+		"Soil Regionalisation by Means of Terrain Analysis and Process Parameterisation. "
+		"In: Micheli, E., Nachtergaele, F., Montanarella, L. [Ed.]: Soil Classification 2001. "
+		"European Soil Bureau, Research Report No. 7, EUR 20398 EN, Luxembourg. pp.213-222."
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "C"			, _TL("Catchment area"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GN"			, _TL("Catchment slope"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CS"			, _TL("Modified catchment area"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SB"			, _TL("Wetness index"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T"			, _TL("t"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 10.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CSAGA_Wetness_Index::~CSAGA_Wetness_Index(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSAGA_Wetness_Index::On_Execute(void)
+{
+	double	a, t;
+	CSG_Grid	*pDEM, *pC, *pGN, *pCS, *pSB;
+
+	//-----------------------------------------------------
+	pDEM	= Parameters("DEM")	->asGrid();
+	pC		= Parameters("C")	->asGrid();
+	pGN		= Parameters("GN")	->asGrid();
+	pCS		= Parameters("CS")	->asGrid();
+	pSB		= Parameters("SB")	->asGrid();
+
+	t		= Parameters("T")	->asDouble();
+	a		= 0.0174532;
+
+	//-----------------------------------------------------
+	Get_Area_Catchment	(pDEM, pC, pGN);
+
+	Get_Area_Modified	(pDEM, pC, pCS, t);
+
+	Get_Wetness_Index	(pDEM, pCS, pSB, a);
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// Im Unterschied zu Freeman's urspruenglichen Verfahren
+// wird der Winkel (atan(dz / dx)) und nicht das Gefaelle
+// (dz / dx) fuer die Gewichtung der Abfluszanteile benutzt!
+
+//---------------------------------------------------------
+bool CSAGA_Wetness_Index::Get_Area_Catchment(CSG_Grid *pDEM, CSG_Grid *pC, CSG_Grid *pS)
+{
+	const double	MFD_Converge	= 1.1;
+
+	int		n, x, y, i, ix, iy;
+	double	z, d, dz[8], dzSum, c, s;
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Catchment area calculation..."));
+
+	pC->Assign(1.0);
+	pS->Assign(0.0);
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		pDEM->Get_Sorted(n, x, y, true, false);
+
+		if( pDEM->is_NoData(x, y) )
+		{
+			pC->Set_NoData(x, y);
+		}
+		else
+		{
+			pDEM->Get_Gradient(x, y, s, c);
+
+			c	= pC->asDouble(x, y);
+			s	= pS->asDouble(x, y) + s;
+
+			pC->Set_Value(x, y, c);
+			pS->Set_Value(x, y, s / c);
+
+			for(i=0, dzSum=0.0, z=pDEM->asDouble(x, y); i<8; i++)
+			{
+				ix		= Get_xTo(i, x);
+				iy		= Get_yTo(i, y);
+
+				if( is_InGrid(ix, iy) && !pDEM->is_NoData(ix, iy) && (d = z - pDEM->asDouble(ix, iy)) > 0.0 )
+				{
+					dzSum	+= (dz[i] = pow(atan(d / Get_Length(i)), MFD_Converge));
+				}
+				else
+				{
+					dz[i]	= 0.0;
+				}
+			}
+
+			if( dzSum > 0.0 )
+			{
+				for(i=0; i<8; i++)
+				{
+					if( dz[i] > 0.0 )
+					{
+						ix		= Get_xTo(i, x);
+						iy		= Get_yTo(i, y);
+
+						d		= dz[i] / dzSum;
+
+						pC->Add_Value(ix, iy, d * c);
+						pS->Add_Value(ix, iy, d * s);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	*pC	*= pC->Get_Cellarea();
+
+	return( true );
+}
+
+/*/---------------------------------------------------------
+bool CSAGA_Wetness_Index::Get_Area_Catchment(CSG_Grid *pDEM, CSG_Grid *pC, CSG_Grid *pGN)
+{
+	int		n, x, y, i, ix, iy;
+	double	z, d, dz[8], dzSum, c, w, sw, sn, Slope, Azimuth,
+			Weight	= 0.5,
+			a		= Get_Cellsize() * Get_Cellsize(),
+			MFD_Converge	= 1.1;
+	CSG_Grid	W, SW, SN;
+
+	//-----------------------------------------------------
+	Process_Set_Text("Catchment area/slope calculation...");
+
+	pC ->Assign(0.0);
+	pGN->Assign(0.0);
+
+	W .Create(pDEM);
+	SW.Create(pDEM);
+	SN.Create(pDEM);
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		pDEM->Get_Sorted(n, x, y, true, false);
+
+		if( pDEM->is_NoData(x, y) )
+		{
+			pC ->Set_NoData(x, y);
+			pGN->Set_NoData(x, y);
+		}
+		else
+		{
+			pDEM->Get_Gradient(x, y, Slope, Azimuth);
+
+			z		= pDEM->asDouble(x, y);
+			c		= pC  ->asDouble(x, y) + a;
+			w		= W    .asDouble(x, y) + pow(c, Weight);	//{ W[p] = C[p]^w;}
+			sw		= SW   .asDouble(x, y) + w;					//{SW[p] = W[p];}
+			sn		= SN   .asDouble(x, y) + w * Slope;			//{SN[p] = W[p] * N[p];}
+
+			for(i=0, dzSum=0.0; i<8; i++)
+			{
+				ix		= Get_xTo(i, x);
+				iy		= Get_yTo(i, y);
+
+				if( is_InGrid(ix, iy) && !pDEM->is_NoData(ix, iy) && (d = z - pDEM->asDouble(ix, iy)) > 0.0 )
+				{
+					dzSum	+= (dz[i] = pow(atan(d / Get_Length(i)), MFD_Converge));
+				}
+				else
+				{
+					dz[i]	= 0.0;
+				}
+			}
+
+			if( dzSum > 0.0 )
+			{
+				for(i=0; i<8; i++)
+				{
+					if( dz[i] > 0.0 )
+					{
+						ix		= Get_xTo(i, x);
+						iy		= Get_yTo(i, y);
+
+						d		= dz[i] / dzSum;
+
+						pC->Add_Value(ix, iy, d * c);
+						W  .Add_Value(ix, iy, d * w);	//{ W[p] =  W[p] +  W[p+pul] * UL[p] +  W[p+pl] * LL[p] +  W[p+pol] * OL[p] +  W[p+po] * OO[p] +  W[p+por] * OR[p] +  W[p+pr] * RR[p] +  W[p+pur] * UR[p] +  W[p+pu] * UU[p]; gefunden = 1;}
+						SW .Add_Value(ix, iy, d * sw);	//{SW[p] = SW[p] + SW[p+pul] * UL[p] + SW[p+pl] * LL[p] + SW[p+pol] * OL[p] + SW[p+po] * OO[p] + SW[p+por] * OR[p] + SW[p+pr] * RR[p] + SW[p+pur] * UR[p] + SW[p+pu] * UU[p]; gefunden = 1;}
+						SN .Add_Value(ix, iy, d * sn);	//{SN[p] = SN[p] + SN[p+pul] * UL[p] + SN[p+pl] * LL[p] + SN[p+pol] * OL[p] + SN[p+po] * OO[p] + SN[p+por] * OR[p] + SN[p+pr] * RR[p] + SN[p+pur] * UR[p] + SN[p+pu] * UU[p]; gefunden = 1;}
+					}
+				}
+			}
+		}
+
+		pC ->Set_Value(x, y, c);
+		pGN->Set_Value(x, y, sn / sw);	//{GN[p] = SN[p] / SW[p];}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}/**/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// in den folgenden drei Schritten wird die gesaugte
+// Einzugsgebietsgroeße CS ermittelt, wobei der t-Parameter
+// die Staerke der Saugung steuert. Werte unter 10 (z.B.  5)
+// fuehren zu einer starken Saugung, Werte ueber 10 (z.B. 15)
+// zu einer schwachen Saugung. Die gesaugte
+// Einzugsgebietsgroeße selbst stellt bereits einen Parameter
+// dar, der die raeumliche Relief-bedingte Feuchteverteilung
+// in guter Weise annaehert
+
+//---------------------------------------------------------
+bool CSAGA_Wetness_Index::Get_Area_Modified(CSG_Grid *pDEM, CSG_Grid *pC, CSG_Grid *pCS, double t)
+{
+	bool	bRecalculate;
+	int		x, y, i, ix, iy, n;
+	double	z, d;
+	CSG_Grid	C, C_Last, T;
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Modify: pre-processing..."));
+
+	T.Create(pC);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pDEM->is_NoData(x, y) && !pC->is_NoData(x, y) )
+			{
+				pDEM->Get_Gradient(x, y, z, d);
+				z	= pow(t, z);
+				z	= pow(1.0 / z, exp(z));
+				T.Set_Value(x, y, z);
+			}
+			else
+			{
+				T.Set_NoData(x, y);
+			}
+		}
+	}
+
+	C     .Create(pC);
+	C     .Assign(pC);
+	C_Last.Create(pC);
+	C_Last.Assign(pC);
+
+	//-----------------------------------------------------
+	for(i=0, n=1; n>0; i++)
+	{
+		for(y=0, n=0; y<Get_NY() && Process_Get_Okay(false); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !T.is_NoData(x, y) )
+				{
+					z	= T.asDouble(x, y) * Get_Local_Maximum(&C, x, y);
+
+					if( z  > C.asDouble(x, y) )
+					{
+						n++;
+
+						C.Set_Value(x, y, z);
+					}
+				}
+			}
+		}
+
+		if( n > 0 )
+		{
+			for(y=0, n=0; y<Get_NY() && Process_Get_Okay(false); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					if( C.asDouble(x, y) != C_Last.asDouble(x, y) )
+					{
+						n++;
+
+						C_Last.Set_Value(x, y, C.asDouble(x, y));
+					}
+				}
+			}
+		}
+
+		Process_Set_Text(CSG_String::Format(SG_T("Modify: %d. iteration [%d > 0]"), i, n));
+	}
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Modify: post-processing..."));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pC->is_NoData(x, y) )
+			{
+				pCS->Set_NoData(x, y);
+			}
+			else
+			{
+				for(iy=y-1, bRecalculate=false; iy<=y+1 && !bRecalculate; iy++)
+				{
+					for(ix=x-1; ix<=x+1 && !bRecalculate; ix++)
+					{
+						if( C.is_InGrid(ix, iy) && pC->is_InGrid(ix, iy) && C.asDouble(ix, iy) > pC->asDouble(ix, iy) )
+						{
+							bRecalculate	= true;
+						}
+					}
+				}
+
+				if( bRecalculate )
+				{
+					for(iy=y-1, z=0.0, n=0; iy<=y+1; iy++)
+					{
+						for(ix=x-1; ix<=x+1; ix++)
+						{
+							if( C.is_InGrid(ix, iy) )
+							{
+								n++;
+								z	+= C.asDouble(ix, iy);
+							}
+						}
+					}
+
+					z	= z / (double)n;
+				}
+				else	
+				{
+					z	= C.asDouble(x, y);
+				}
+
+				pCS->Set_Value(x, y, z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+double CSAGA_Wetness_Index::Get_Local_Maximum(CSG_Grid *pGrid, int x, int y)
+{
+	int		i, ix, iy;
+	double	z	= pGrid->asDouble(x, y);
+
+	for(i=0; i<8; i++)
+	{
+		ix	= Get_xTo(i, x);
+		iy	= Get_yTo(i, y);
+
+		if( pGrid->is_InGrid(ix, iy) && pGrid->asDouble(ix, iy) > z )
+		{
+			z	= pGrid->asDouble(ix, iy);
+		}
+	}
+
+	return( z );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// in den folgenden zwei Schritten wird der SAGA
+// Bodenfeuchteindex SB ermittelt. Der a-Parameter muss
+// bei den Settings definiert werden und sorgt dafuer,
+// das nicht durch 0 dividiert wird
+
+//---------------------------------------------------------
+bool CSAGA_Wetness_Index::Get_Wetness_Index(CSG_Grid *pDEM, CSG_Grid *pCS, CSG_Grid *pSB, double a)
+{
+	int		x, y;
+	double	Slope, Azimuth;
+
+	Process_Set_Text(_TL("Wetness index calculation..."));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pDEM->is_NoData(x, y) && !pCS->is_NoData(x, y) )
+			{
+				pDEM->Get_Gradient(x, y, Slope, Azimuth);
+
+				pSB->Set_Value(x, y, log(pCS->asDouble(x, y) / tan(a + Slope)));
+			}
+			else
+			{
+				pSB->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//        The original BSL script by J.Boehner
+//---------------------------------------------------------
+
+/*
+Matrix Loop, O("sch-hoe.grd"), N("sch-nei.grd"), M, R, UL, LL, OL, OO, OR, RR, UR, UU, X, Y, Z, C, CS, SB;
+Point ploop, p, pul, pu, pur, pl, pr, pol, po, por;
+Float a, wul, wll, wol, woo, wor, wrr, wur, wuu;
+Integer t, h, i, j, gefunden;
+
+a = 0.0174532;
+t = 10; 
+pul.x = -1;	pul.y = -1; 
+pu.x = 0;	pu.y = -1;
+pur.x = 1;	pur.y = -1;
+pl.x = -1;	pl.y = 0;
+pr.x = 1;	pr.y = 0;
+pol.x = -1;	pol.y = 1;
+po.x = 0;	po.y = 1;
+por.x = 1;	por.y = 1;
+
+M = O;
+R = O;
+UL = O;
+LL = O;
+OL = O;
+OO = O;
+OR = O;
+RR = O;
+UR = O;
+UU = O;
+X = O;
+Y = O;
+Z = O;
+C = O;
+CS = O;
+SB = O;
+
+Loop.xanz = 100000;
+Loop.yanz = 1;
+h = 0;
+i = 0;
+j = 0;
+
+// hier wird eine Hilfsmatrix X erzeugt, die in der folgenden Schleife fafuer sorgt, dass noch nicht attributisierte Rasterzellen in Ihrer Position identifiziert werden koennen //
+foreach p in X do
+{	if (p.x == 0 || p.x == M.xanz - 1 || p.y == 0 || p.y == M.yanz - 1)
+	{X[p] = -10000;}
+	else
+	{X[p] = M[p];}
+}
+// hier wird eine Matrix R erzeugt, die ausgehend von lokalen Maxima fortlaufend Rangplatzziffernerzeugt //
+foreach ploop in Loop do
+{	ploop.x = 1;
+	h = h +1;
+	gefunden = 0;
+	foreach p in X do
+	{
+	if (X[p] == max9(p, X) && X[p] > -10000)
+	{X[p] = -10000; R[p] = h; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(R);
+// hier wird eine Hilfsmatrix R erzeugt, die Rangplatzziffern am Rand duch 0 ersetzt //
+foreach p in R do
+{	if (p.x == 0 || p.x == M.xanz - 1 || p.y == 0 || p.y == M.yanz - 1)
+	{R[p] = 0;}
+	else
+	{R[p] = R[p];}
+}
+// hier wird eine Matrix Z erzeugt, die die positiven Winkel zu den 8 Nachbarzellen aufsummiert //
+foreach p in Z do
+{
+if(p.x == 0 && p.y == 0)
+	{
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((woo + wor + wrr) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = woo + wor + wrr;}
+	}
+else
+{
+if(p.x == 0 && p.y == (M.yanz - 1))
+	{
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wrr + wur + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1 && p.y == M.yanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1 && p.y == 0)
+	{
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((wll + wol + woo) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wll + wol + woo;}
+	}
+else	
+{
+if(p.x == 0)
+	{
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((woo + wor + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = woo + wor + wrr + wur + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wol + woo + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wol + woo + wuu;}
+	}
+else	
+{
+if(p.y == 0)
+	{
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((wll + wol + woo + wor + wrr) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wll + wol + woo + wor + wrr;}
+	}
+else	
+{
+if(p.y == M.yanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wrr + wur + wuu;}
+	}
+else	
+{	
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wol + woo + wor + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wol + woo + wor + wrr + wur + wuu;}
+	}
+}}}}}}}}
+// hier werden Grids UL bis UU (im Uhrzeigersinn) erzeugt, die angeben, welchen Anteil des Inhalts einer benachbarten Rasterzelle in die Zielrasterzelle (zentrale Rasterzelle im 9er Feld) uebergen wird //
+foreach p in UL do
+{	if (p.x == 0 || p.y == 0)
+	{UL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pul]) < 0 && Z[p+pul] > 0) 
+		{UL[p] = (atan((M[p+pul] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pul];}
+		else
+		{UL[p] = 0;}
+		}
+}
+foreach p in LL do
+{	if (p.x == 0)
+	{LL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pl]) < 0 && Z[p+pl] > 0) 
+		{LL[p] = (atan((M[p+pl] - M[p])/M.dxy))/Z[p+pl];}
+		else
+		{LL[p] = 0;}
+		}
+}
+foreach p in OL do
+{	if (p.x == 0 || p.y == M.yanz - 1)
+	{OL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pol]) < 0 && Z[p+pol] > 0) 
+		{OL[p] = (atan((M[p+pol] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pol];}
+		else
+		{OL[p] = 0;}
+		}
+}
+foreach p in OO do
+{	if (p.y == M.yanz - 1)
+	{OO[p] = 0;}
+	else	{
+		if((M[p] - M[p+po]) < 0 && Z[p+po] > 0) 
+		{OO[p] = (atan((M[p+po] - M[p])/M.dxy))/Z[p+po];}
+		else
+		{OO[p] = 0;}
+		}
+}
+foreach p in OR do
+{	if (p.x == M.xanz - 1 || p.y == M.yanz - 1)
+	{OR[p] = 0;}
+	else	{
+		if((M[p] - M[p+por]) < 0 && Z[p+por] > 0) 
+		{OR[p] = (atan((M[p+por] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+por];}
+		else
+		{OR[p] = 0;}
+		}
+}
+foreach p in RR do
+{	if (p.x == M.xanz - 1)
+	{RR[p] = 0;}
+	else	{
+		if((M[p] - M[p+pr]) < 0 && Z[p+pr] > 0) 
+		{RR[p] = (atan((M[p+pr] - M[p])/M.dxy))/Z[p+pr];}
+		else
+		{RR[p] = 0;}
+		}
+}
+foreach p in UR do
+{	if (p.x == M.xanz - 1 || p.y == 0)
+	{UR[p] = 0;}
+	else	{
+		if((M[p] - M[p+pur]) < 0 && Z[p+pur] > 0) 
+		{UR[p] = (atan((M[p+pur] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pur];}
+		else
+		{UR[p] = 0;}
+		}
+}
+foreach p in UU do
+{	if (p.y == 0)
+	{UU[p] = 0;}
+	else	{
+		if((M[p] - M[p+pu]) < 0 && Z[p+pu] > 0) 
+		{UU[p] = (atan((M[p+pu] - M[p])/M.dxy))/Z[p+pu];}
+		else
+		{UU[p] = 0;}
+		}
+}
+// in den folgenden drei Schritten wird nach der "multiple flow methode" die Einzugsgebietsgroeße C ermittelt //
+foreach p in Z do
+{Z[p] = 1;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	i = i +1;
+	gefunden = 0;
+	foreach p in Z do
+	{	if (R[p] == i)
+		{Z[p] = 1 + Z[p+pul] * UL[p] + Z[p+pl] * LL[p] + Z[p+pol] * OL[p] + Z[p+po] * OO[p] + Z[p+por] * OR[p] + Z[p+pr] * RR[p] + Z[p+pur] * UR[p] + Z[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(Z);
+foreach p in C do
+{C[p] = Z[p] * O.dxy^2;}
+// in den folgenden drei Schritten wird die gesaugte Einzugsgebietsgroeße CS ermittelt, wobei der t-Parameter die Staerke der Saugung steuert. Werte unter 10 (z.B.: 5) fuehren zu einer starken Saugung, Werte ueber 10 (z.B. 15) zu einer schwachen Saugung. Die gesaugte Einzugsgebietsgroeße selbst stellt bereits einen Parameter Dar, der die raeumliche Relief-bedingte Feuchteverteilung in guter Weise annaehert //
+foreach p in X do
+{X[p] = C[p];}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	j = j +1;
+	gefunden = 0;
+	foreach p in X do
+	{
+	if ((((1/t^N[p])^exp(t^N[p])) * max9(p, X)) > X[p])
+	{X[p] = (((1/t^N[p])^exp(t^N[p])) * max9(p, X)); gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+foreach p in CS do
+{	if (isRand(p, M) == 0)
+	{
+	if(X[p] > C[p] || X[p+pul] > C[p+pul] || X[p+pl] > X[p+pl] || X[p+pol] > C[p+pol] || X[p+po] > C[p+po] || X[p+por] > C[p+por] || X[p+pr] > C[p+pr] || X[p+pur] > C[p+pur] || X[p+pu] > C[p+pu])
+	{CS[p] = ln((X[p] + X[p+pul] + X[p+pu] + X[p+pur] + X[p+pl] + X[p+pr] + X[p+pol] + X[p+po] + X[p+por])/9);}
+	else	
+	{CS[p] = ln(X[p]);}
+	}
+}
+setRandN (CS);	
+showMatrix(CS);
+// in den folgenden zwei Schritten wird der SAGA Bodenfeuchteindex SB ermittelt. Der a-Parameter muss bei den Settings definiert werden und sorgt dafuer, das nicht durch 0 dividiert wird //
+foreach p in SB do
+{SB[p] = exp(CS[p])/tan(N[p] + a);}
+foreach p in SB do
+{SB[p] = ln(SB[p]);}	
+showMatrix(SB);
+/**/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/SAGA_Wetness_Index.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  SAGA_Wetness_Index.h                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_Wetness_Index_H
+#define HEADER_INCLUDED__SAGA_Wetness_Index_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSAGA_Wetness_Index : public CSG_Module_Grid
+{
+public:
+	CSAGA_Wetness_Index(void);
+	virtual ~CSAGA_Wetness_Index(void);
+
+	virtual const SG_Char *		Get_MenuPath		(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+	bool						Get_Area_Catchment	(CSG_Grid *pDEM, CSG_Grid *pC, CSG_Grid *pGN);
+	bool						Get_Area_Modified	(CSG_Grid *pDEM, CSG_Grid *pC, CSG_Grid *pCS, double t);
+	double						Get_Local_Maximum	(CSG_Grid *pGrid, int x, int y);
+	bool						Get_Wetness_Index	(CSG_Grid *pDEM, CSG_Grid *pCS, CSG_Grid *pSB, double a);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_Wetness_Index_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,450 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                TopographicIndices.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "TopographicIndices.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTopographicIndices::CTopographicIndices(void)
+{
+	CSG_Parameter	*pNode, *pSNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Topographic Indices"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculation of slope and catchment area based topographic indices "
+		"Topograhic Wetness Index (TWI), USLE LS factor, Stream Power Index.\n"
+		"\n"
+		"References:\n"
+		"\n"
+		"Boehner, J., Selige, T. (2006):\n"
+		"Spatial Prediction of Soil Attributes Using Terrain Analysis and Climate Regionalisation'\n"
+		"In: Boehner, J., McCloy, K.R., Strobl, J.: 'SAGA – Analysis and Modelling Applications', "
+		"Goettinger Geographische Abhandlungen, Vol.115, p.13-27\n"
+		"\n"
+		"Desmot & Govers (1996):\n"
+		"'A GIS Procedure for Automatically Calculating the USLE LS Factor on Topographically Complex Landscape Units'\n"
+		"Journal of Soil and Water Conservation, 51(5):427.433\n"
+		"\n"
+		"Kinnell, P.I.A. (2005):\n"
+		"'Alternative Approaches for Determining the USLE-M Slope Length Factor for Grid Cells.'\n"
+		"<a href=\"http://soil.scijournals.org/cgi/content/full/69/3/674\">http://soil.scijournals.org/cgi/content/full/69/3/674</a>\n"
+		"\n"
+		"Moore, I.D., Grayson, R.B., Ladson, A.R. (1991):\n"
+		"'Digital terrain modelling: a review of hydrogical, geomorphological, and biological applications'\n"
+		"Hydrological Processes, Vol.5, No.1\n"
+		"\n"
+		"Wischmeier, W.H., Smith, D.D. (1978):\n"
+		"'Predicting rainfall erosion losses – A guide to conservation planning'\n"
+		"Agriculture Handbook No. 537: US Department of Agriculture, Washington DC.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "SLOPE"		, _TL("Slope"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "AREA"		, _TL("Catchment Area"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "TRANSMISS"	, _TL("Transmissivity"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL, "WETNESS"		, _TL("Topographic Wetness Index"),
+		_TL("The Topographic Wetness Index: ln( Area / tan(Slope) )"),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "STREAMPOW"	, _TL("Stream Power Index"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "LSFACTOR"	, _TL("LS-Factor"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	/*/-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "TWI", _TL("Topgraphic Wetness Index"), _TL(""));
+
+	Parameters.Add_Choice(
+		pNode	, "TWI_METHOD"	, _TL("Method (TWI)"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Standard"),
+			_TL("TOPMODEL")
+		), 0
+	);/**/
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(NULL, "LS", _TL("LS-Factor"), _TL(""));
+
+	Parameters.Add_Choice(
+		pNode	, "LS_METHOD"		, _TL("Method (LS)"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Moore et al. 1991"),
+			_TL("Desmot & Govers 1996"),
+			_TL("Boehner & Selige 2006")
+		), 0
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "LS_AREA"			, _TL("Area to Length Conversion"),
+		_TL("Derivation of slope lengths from catchment areas. These are rough approximations! Applies not to Desmot & Govers' method."),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("no conversion (areas already given as specific catchment area)"),
+			_TL("1 / cell size (specific catchment area)"),
+			_TL("square root (catchment length)")
+		), 0
+	);
+
+	pSNode	= Parameters.Add_Node(pNode, "LS_DG", _TL("Desmot & Govers"), _TL(""));
+
+	Parameters.Add_Value(
+		pSNode	, "DG_EROSIVITY"	, _TL("Rill/Interrill Erosivity"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 1.0, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		pSNode	, "DG_STABILITY"	, _TL("Stability"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("stable"),
+			_TL("instable (thawing)")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CTopographicIndices::~CTopographicIndices(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTopographicIndices::On_Execute(void)
+{
+	bool		bTopmodel;
+	int			x, y;
+	double		Area, Slope, tan_Slope, Kf, Mean_Kf, Mean_TWI;
+	CSG_Grid	*pArea, *pSlope, *pKf, *pTWI, *pSPI, *pLSF;
+
+	//-----------------------------------------------------
+	pSlope			= Parameters("SLOPE")		->asGrid();
+	pArea			= Parameters("AREA")		->asGrid();
+	pKf				= Parameters("TRANSMISS")	->asGrid();
+
+	pTWI			= Parameters("WETNESS")		->asGrid();
+	pSPI			= Parameters("STREAMPOW")	->asGrid();
+	pLSF			= Parameters("LSFACTOR")	->asGrid();
+
+	bTopmodel		= false; // Parameters("TWI_METHOD")	->asInt() == 1;
+
+	m_Method_LS		= Parameters("LS_METHOD")	->asInt();
+	m_DG_Erosivity	= Parameters("DG_EROSIVITY")->asInt();
+	m_DG_Stability	= Parameters("DG_STABILITY")->asInt();
+
+	m_Method_Area	= Parameters("LS_AREA")		->asInt();
+
+	//-----------------------------------------------------
+	Kf		= 1.0;
+
+	if( pTWI )
+	{
+		DataObject_Set_Colors(pTWI, 100, SG_COLORS_RED_GREY_BLUE);
+	}
+
+	if( pSPI )
+	{
+		DataObject_Set_Colors(pSPI, 100, SG_COLORS_RED_GREY_GREEN, true);
+	}
+
+	if( pLSF )
+	{
+		DataObject_Set_Colors(pLSF, 100, SG_COLORS_RED_GREY_GREEN, true);
+	}
+
+	//-----------------------------------------------------
+	if( bTopmodel )
+	{
+		Mean_TWI	= 0.0;
+		Mean_Kf		= 0.0;
+		Area		= 0.0;
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !pArea->is_NoData(x, y) && !pSlope->is_NoData(x, y) )
+				{
+					if( pKf )
+					{
+						if( !pKf->is_NoData(x, y) )
+						{
+							Kf	= pKf->asDouble(x, y);
+							if( Kf < M_ALMOST_ZERO )	Kf	= M_ALMOST_ZERO;
+							Kf	= log(Kf);
+						}
+						else
+						{
+							Kf	= 0.0;
+						}
+					}
+
+					tan_Slope	= tan(pSlope->asDouble(x, y));
+					if( tan_Slope < M_ALMOST_ZERO )	tan_Slope	= M_ALMOST_ZERO;
+
+					Mean_TWI	+= log(pArea->asDouble(x, y) / tan_Slope);
+					Mean_Kf		+= Kf;
+					Area++;
+				}
+			}
+		}
+
+		if( Area > 0.0 )
+		{
+			Area		*= pArea->Get_Cellarea();
+			Mean_TWI	/= Area;
+			Mean_Kf		/= Area;
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pArea->is_NoData(x, y) || pSlope->is_NoData(x, y) || (pKf && pKf->is_NoData(x, y)) )
+			{
+				if( pLSF )	pLSF->Set_NoData(x, y);
+				if( pSPI )	pSPI->Set_NoData(x, y);
+				if( pTWI )	pTWI->Set_NoData(x, y);
+			}
+			else
+			{
+				//-----------------------------------------
+				Area		= _Get_Area(pArea->asDouble(x, y));	// specific catchment area...
+				Slope		= pSlope->asDouble(x, y);			// slope as radians...
+				tan_Slope	= tan(Slope);
+				if( tan_Slope < M_ALMOST_ZERO )	tan_Slope	= M_ALMOST_ZERO;
+
+				if( pKf )
+				{
+					Kf		= pKf->asDouble(x, y);
+					if( Kf < M_ALMOST_ZERO )	Kf	= M_ALMOST_ZERO;
+				}
+
+				//-----------------------------------------
+				if( pLSF )
+				{
+					pLSF->Set_Value(x, y,
+						_Get_LS(Slope, pArea->asDouble(x, y))
+					);
+				}
+
+				if( pSPI )
+				{
+					pSPI->Set_Value(x, y,
+						Area * tan_Slope
+					);
+				}
+
+				if( pTWI )
+				{
+					pTWI->Set_Value(x, y, bTopmodel
+						? (log(Area / (     tan_Slope)) - Mean_TWI) - (log(Kf) - Mean_Kf)
+						:  log(Area / (Kf * tan_Slope))
+					);
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline double CTopographicIndices::_Get_Area(double Area)
+{
+	switch( m_Method_Area )
+	{
+	default:	return( Area );						// no conversion...
+	case 1:		return( Area / Get_Cellsize() );	// pseudo specific catchment area...
+	case 2:		return( sqrt(Area) );				// pseudo slope length...
+	}
+}
+
+//---------------------------------------------------------
+double CTopographicIndices::_Get_LS(double Slope, double Area)
+{
+	double	LS, sinSlope;
+
+	switch( m_Method_LS )
+	{
+	//-----------------------------------------------------
+	case 0:	default:
+		{
+			LS			= (0.4 + 1) * pow(_Get_Area(Area) / 22.13, 0.4) * pow(sin(Slope) / 0.0896, 1.3);
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 1:
+		{
+			double	L, S, m, x, d;
+
+			sinSlope	= sin(Slope);
+
+			d			= Get_Cellsize();
+
+			m			= m_DG_Erosivity * (sinSlope / 0.0896) / (3.0 * pow(sinSlope, 0.8) + 0.56);
+			m			= m / (1.0 + m);
+
+		//	x			= Aspect < 0.0 ? 0.0 : fmod(Aspect, M_PI_090);
+		//	x			= sin(x) + cos(x);
+			x			= 1.0;
+
+			// x : coefficient that adjusts for width of flow at the center of the cell.
+			//     It has a value of 1.0 when the flow is toward a side and sqrt(2.0) when
+			//     the flow is toward a corner.
+			//     (Peter I. A. Kinnell: 'ALTERNATIVE APPROACHES FOR DETERMINING THE
+			//     USLE-M SLOPE LENGTH FACTOR FOR GRID CELLS'
+			//     http://soil.scijournals.org/cgi/content/full/69/3/674)
+
+			L			= (pow(Area + d*d, m + 1.0) - pow(Area, m + 1.0))
+						/ (pow(d, m + 2.0) * pow(22.13, m) * pow(x, m));
+
+			//-----------------------------------------------------
+			if( Slope < 0.08975817419 )		// < 9% Steigung := atan(0.09), ca. 5 Degree
+			{
+				S		= 10.8 * sinSlope + 0.03;	
+			}
+			else if( m_DG_Stability == 0 )	// >= 9% Steigung, stabil
+			{
+				S		= 16.8 * sinSlope - 0.5;
+			}
+			else							// >= 9% Steigung, tauend u. instabil
+			{
+				S		= pow(sinSlope / 0.896, 0.6);
+			}
+
+			LS			= L * S;
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 2:
+		{
+			sinSlope	= sin(Slope);
+
+			if( Slope > 0.0505 )	// >  ca. 3 Degree
+			{
+				LS		= sqrt(_Get_Area(Area) / 22.13)
+						* (65.41 * sinSlope * sinSlope + 4.56 * sinSlope + 0.065);
+			}
+			else					// <= ca. 3 Degree
+			{
+				LS		= pow (_Get_Area(Area) / 22.13, 3.0 * pow(Slope, 0.6))
+						* (65.41 * sinSlope * sinSlope + 4.56 * sinSlope + 0.065);
+			}
+		}
+		break;
+	}
+
+	return( LS );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/TopographicIndices.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,117 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 TopographicIndices.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__TopographicIndices_H
+#define HEADER_INCLUDED__TopographicIndices_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_hydrology_EXPORT CTopographicIndices : public CSG_Module_Grid
+{
+public:
+	CTopographicIndices(void);
+	virtual ~CTopographicIndices(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						m_Method_LS, m_DG_Stability, m_Method_Area;
+
+
+	double					m_DG_Erosivity;
+
+
+	double					_Get_Area		(double Area);
+	double					_Get_LS			(double Slope, double Area);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__TopographicIndices_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,420 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   flow_massflux.cpp                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "flow_massflux.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const int	xDir[4]	= {	1, 1, 0, 0	};
+const int	yDir[4]	= {	1, 0, 0, 1	};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_MassFlux::CFlow_MassFlux(void)
+{
+	Set_Name		(_TL("Flow Accumulation, Mass-Flux Method"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"The Mass-Flux Method (MFM) for the DEM based calculation of flow accumulation "
+		"as proposed by Gruber and Peckham (2008).\n"
+		"\n"
+		"!!!UNDER DEVELOPMENT!!! To be done: solving the streamline resolution problem\n"
+		"\n"
+		"References:\n"
+		"Gruber, S., Peckham, S. (2008): Land-Surface Parameters and Objects in Hydrology. "
+		"In: Hengl, T. and Reuter, H.I. [Eds.]: Geomorphometry: Concepts, Software, Applications. "
+		"Developments in Soil Science, Elsevier, Bd.33, S.293-308.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"		, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "AREA"	, _TL("Flow Accumulation"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Flow Split Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("flow width (original)"),
+			_TL("cell area")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode	= Parameters.Add_Node(NULL, "NODE_QUARTERS", _TL("Create Output of Quarter Cell Grids"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "B_SLOPE"	, _TL("Slope"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "G_SLOPE"	, _TL("Slope")	, _TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "B_ASPECT", _TL("Aspect"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "G_ASPECT", _TL("Aspect")	, _TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "B_AREA"	, _TL("Flow Accumulation"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Grid_Output(
+		NULL	, "G_AREA"	, _TL("Flow Accumulation")	, _TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "B_FLOW"	, _TL("Flow Lines"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Shapes_Output(
+		NULL	, "G_FLOW"	, _TL("Flow Lines")	, _TL("")
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFlow_MassFlux::On_Execute(void)
+{
+	int			x, y, i, ix, iy;
+	CSG_Grid	*pArea;
+
+	//-----------------------------------------------------
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	pArea		= Parameters("AREA")	->asGrid();
+	m_Method	= Parameters("METHOD")	->asInt();
+
+	//-----------------------------------------------------
+	if( 1 )
+	{
+		CSG_Grid_System	System(0.5 * Get_Cellsize(), Get_XMin() - 0.25 * Get_Cellsize(), Get_YMin() - 0.25 * Get_Cellsize(), 2 * Get_NX(), 2 * Get_NY());
+
+		m_Area	.Create(System, SG_DATATYPE_Float);
+		m_dir	.Create(System, SG_DATATYPE_Byte);
+		m_dif	.Create(System, SG_DATATYPE_Float);
+
+		m_dir	.Assign(-1.0);
+		m_Area	.Assign( 0.0);
+		m_Area	.Set_NoData_Value(0.0);
+
+		Parameters("G_SLOPE" )->Set_Value(m_pSlope  = !Parameters("B_SLOPE" )->asBool() ? NULL : SG_Create_Grid(System, SG_DATATYPE_Float));
+		Parameters("G_ASPECT")->Set_Value(m_pAspect = !Parameters("B_ASPECT")->asBool() ? NULL : SG_Create_Grid(System, SG_DATATYPE_Float));
+		Parameters("G_FLOW"  )->Set_Value(m_pFlow   = !Parameters("B_FLOW"  )->asBool() ? NULL : SG_Create_Shapes(SHAPE_TYPE_Line, _TL("Flow Lines")));
+
+		//-------------------------------------------------
+		// Calculate flow portions...
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				for(i=0; i<4; i++)
+				{
+					Set_Flow(x, y, i);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		// Check for consistent flow directions...
+
+		// still missing...
+
+
+		//-------------------------------------------------
+		// Calculate flow accumulation...
+		for(y=0, iy=0; y<Get_NY() && Set_Progress(y); y++, iy+=2)
+		{
+			for(x=0, ix=0; x<Get_NX(); x++, ix+=2)
+			{
+				for(i=0; i<4; i++)
+				{
+					Get_Area(ix + xDir[i], iy + yDir[i]);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		// Scale flow accumulation to original cell size...
+		for(y=0, iy=0; y<Get_NY() && Set_Progress(y); y++, iy+=2)
+		{
+			for(x=0, ix=0; x<Get_NX(); x++, ix+=2)
+			{
+				double	Area	= 0.0, d;
+
+				for(i=0; i<4; i++)
+				{
+					if( (d = m_Area.asDouble(ix + xDir[i], iy + yDir[i])) > 0.0 )
+					{
+						Area	+= d;
+					}
+				}
+
+				if( Area > 0.0 )
+				{
+					pArea->Set_Value(x, y, Area * m_Area.Get_Cellarea());
+				}
+				else
+				{
+					pArea->Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( Parameters("B_AREA")->asBool() )
+		{
+			Parameters("G_AREA")->Set_Value(SG_Create_Grid(m_Area));
+		}
+
+		m_Area	.Destroy();
+		m_dif	.Destroy();
+		m_dir	.Destroy();
+
+		DataObject_Set_Colors(pArea, 100, SG_COLORS_WHITE_BLUE);
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFlow_MassFlux::Set_Flow(int x, int y, int Direction)
+{
+	int		dir, ix, iy, jx, jy;
+	double	dif, Z, A, B;
+
+	if( m_pDEM->is_InGrid(x, y)
+	&&	m_pDEM->is_InGrid(ix = Get_xTo(2 * Direction    , x), iy = Get_yTo(2 * Direction    , y))
+	&&	m_pDEM->is_InGrid(jx = Get_xTo(2 * Direction + 2, x), jy = Get_yTo(2 * Direction + 2, y)) )
+	{
+		Z	=  m_pDEM->asDouble( x,  y);
+		A	= (m_pDEM->asDouble(ix, iy) - Z) / Get_Cellsize();
+		B	= (m_pDEM->asDouble(jx, jy) - Z) / Get_Cellsize();
+
+		dif	= A != 0.0 ? M_PI_180 + atan2(B, A) : (B > 0.0 ? M_PI_270 : (B < 0.0 ? M_PI_090 : -1.0));
+
+		if( dif >= 0.0 )
+		{
+			x	= 2 * x + xDir[Direction];
+			y	= 2 * y + yDir[Direction];
+
+			dif	= fmod(dif + M_PI_090 * Direction, M_PI_360);
+
+			if( m_pFlow )
+			{
+				double		dScale	= 0.50 * m_dir.Get_System().Get_Cellsize();
+				TSG_Point	Point	= m_dir.Get_System().Get_Grid_to_World(x, y);
+				CSG_Shape	*pLine	= m_pFlow->Add_Shape();
+
+				pLine->Add_Point(
+					Point.x - dScale * sin(dif),
+					Point.y - dScale * cos(dif), 0
+				);
+				pLine->Add_Point(Point, 0);
+
+				dScale	= 0.20 * m_dir.Get_System().Get_Cellsize();
+				pLine->Add_Point(
+					Point.x - dScale * sin(dif + 25.0 * M_DEG_TO_RAD),
+					Point.y - dScale * cos(dif + 25.0 * M_DEG_TO_RAD), 1
+				);
+				pLine->Add_Point(Point, 1);
+				pLine->Add_Point(
+					Point.x - dScale * sin(dif - 25.0 * M_DEG_TO_RAD),
+					Point.y - dScale * cos(dif - 25.0 * M_DEG_TO_RAD), 1
+				);
+			}
+
+			if( m_pSlope )	m_pSlope ->Set_Value(x, y, atan(sqrt(A*A + B*B)));
+			if( m_pAspect )	m_pAspect->Set_Value(x, y, dif);
+
+			dir	= (int)(dif / M_PI_090);
+
+			dif	= dif - dir * M_PI_090;
+
+			switch( m_Method )
+			{
+			case 0:
+				dif	= cos(dif) / (cos(dif) + sin(dif));
+				break;
+
+			case 1:
+				dif	= dif < M_PI_045 ? 1.0 - tan(dif) / 2.0 : tan(M_PI_090 - dif) / 2.0;
+				break;
+			}
+
+			m_dir.Set_Value(x, y, dir * 2);
+			m_dif.Set_Value(x, y, dif);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CFlow_MassFlux::Get_Flow(int x, int y, int Direction)
+{
+	if( m_dir.is_InGrid(x, y) )
+	{
+		int		i	= m_dir.asInt(x, y);
+
+		if( Direction == i )
+		{
+			return( m_dif.asDouble(x, y) );
+		}
+
+		if( Direction == (i + 2) % 8 )
+		{
+			return( 1.0 - m_dif.asDouble(x, y) );
+		}
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CFlow_MassFlux::Get_Area(int x, int y)
+{
+	if( m_Area.is_NoData(x, y) )		// cell has not been processed yet...
+	{
+		int		i, ix, iy;
+		double	d;
+
+		m_Area.Set_Value(x, y, 1.0);	// add this cell's contribution...
+
+		for(i=0; i<8; i+=2)
+		{
+			ix	= Get_xFrom(i, x);
+			iy	= Get_yFrom(i, y);
+
+			d	= Get_Flow(ix, iy, i);
+
+			if( d > 0.0 )				// which portion drains ith neigbour into this cell???
+			{
+				m_Area.Add_Value(x, y, d * Get_Area(ix, iy));	// then recursive call of this function...
+			}
+		}
+	}
+
+	return( m_Area.asDouble(x, y) );	// return this cell's area...
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_massflux.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,105 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    flow_massflux.h                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__flow_massflux_H
+#define HEADER_INCLUDED__flow_massflux_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+class CFlow_MassFlux : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CFlow_MassFlux(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool			On_Execute		(void);
+
+
+private: ///// private members and functions: /////////////
+
+	int						m_Method;
+
+	CSG_Grid				*m_pDEM, *m_pSlope, *m_pAspect, m_Area, m_dir, m_dif;
+
+	CSG_Shapes				*m_pFlow;
+
+
+	bool					Set_Flow		(int x, int y, int Direction);
+
+	double					Get_Flow		(int x, int y, int Direction);
+	double					Get_Area		(int x, int y);
+
+	bool					Check_Flow		(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__flow_massflux_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,267 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    flow_width.cpp                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "flow_width.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFlow_Width::CFlow_Width(void)
+{
+	Set_Name		(_TL("Flow Width"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2009"));
+
+	Set_Description	(_TW(
+		"Flow width and specific catchment area (SCA) calculation.\n"
+		"\n"
+		"References:\n"
+		"Gruber, S., Peckham, S. (2008): Land-Surface Parameters and Objects in Hydrology. "
+		"In: Hengl, T. and Reuter, H.I. [Eds.]: Geomorphometry: Concepts, Software, Applications. "
+		"Developments in Soil Science, Elsevier, 33:293-308.\n"
+		"\n"
+		"Quinn, P.F., Beven, K.J., Chevallier, P., Planchon, O. (1991): "
+		"The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models. "
+		"Hydrological Processes, 5:59-79\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"		, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "WIDTH"	, _TL("Flow Width"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "TCA"		, _TL("Total Catchment Area (TCA)"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SCA"		, _TL("Specific Catchment Area (SCA)"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"	, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Deterministic 8"),
+			_TL("Multiple Flow Direction (Quinn et al. 1991)"),
+			_TL("Aspect")
+		), 2
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CFlow_Width::On_Execute(void)
+{
+	int			x, y, Method;
+	double		Width;
+	CSG_Grid	*pWidth, *pTCA, *pSCA;
+
+	//-----------------------------------------------------
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	pWidth		= Parameters("WIDTH")	->asGrid();
+	pTCA		= Parameters("TCA")		->asGrid();
+	pSCA		= Parameters("SCA")		->asGrid();
+	Method		= Parameters("METHOD")	->asInt();
+
+	if( pTCA )
+	{
+		if( pSCA == NULL )
+		{
+			Parameters("SCA")->Set_Value(pSCA = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float));
+		}
+
+		pSCA->Set_Name(_TL("Specific Catchment Area"));
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			switch( Method )
+			{
+			case 0:				// Deterministic 8
+				Width	= Get_D8	(x, y);
+				break;
+
+			case 1:				// Multiple Flow Direction (Quinn et al. 1991)
+				Width	= Get_MFD	(x, y);
+				break;
+
+			case 2:	default:	// Aspect
+				Width	= Get_Aspect(x, y);
+				break;
+			}
+
+			//---------------------------------------------
+			if( Width > 0.0 )
+			{
+				pWidth->Set_Value(x, y, Width);
+			}
+			else
+			{
+				pWidth->Set_NoData(x, y);
+			}
+
+			if( pTCA && pSCA )
+			{
+				if( Width > 0.0 && !pTCA->is_NoData(x, y) )
+				{
+					pSCA->Set_Value(x, y, pTCA->asDouble(x, y) / Width);
+				}
+				else
+				{
+					pSCA->Set_NoData(x, y);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CFlow_Width::Get_D8(int x, int y)
+{
+	int		Direction;
+
+	if( (Direction = m_pDEM->Get_Gradient_NeighborDir(x, y)) >= 0 )
+	{
+		return( Get_Length(Direction) );
+	}
+
+	return( -1.0 );
+}
+
+//---------------------------------------------------------
+inline double CFlow_Width::Get_MFD(int x, int y)
+{
+	if( m_pDEM->is_InGrid(x, y) )
+	{
+		double	Width	= 0.0;
+		double	z		= m_pDEM->asDouble(x, y);
+
+		for(int i=0; i<8; i++)
+		{
+			int	ix	= Get_xTo(i, x);
+			int	iy	= Get_yTo(i, y);
+
+			if( m_pDEM->is_InGrid(ix, iy, true) && z > m_pDEM->asDouble(ix, iy) )
+			{
+				Width	+= 0.5 * Get_Cellsize() / Get_System()->Get_UnitLength(i);
+			}
+		}
+
+		return( Width );
+	}
+
+	return( -1.0 );
+}
+
+//---------------------------------------------------------
+inline double CFlow_Width::Get_Aspect(int x, int y)
+{
+	double	Slope, Aspect;
+
+	if( m_pDEM->Get_Gradient(x, y, Slope, Aspect) )
+	{
+		return( (fabs(sin(Aspect)) + fabs(cos(Aspect))) * Get_Cellsize() );
+	}
+
+	return( -1.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_hydrology/flow_width.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,98 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_hydrology                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     flow_width.h                      //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__flow_width_H
+#define HEADER_INCLUDED__flow_width_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+class CFlow_Width : public CSG_Module_Grid
+{
+public: ////// public members and functions: //////////////
+
+	CFlow_Width(void);
+
+	virtual const SG_Char *	Get_MenuPath	(void)	{	return( _TL("R:Catchment Area" ));	}
+
+
+protected: /// protected members and functions: ///////////
+
+	virtual bool			On_Execute		(void);
+
+
+private: ///// private members and functions: /////////////
+
+	CSG_Grid				*m_pDEM;
+
+
+	double					Get_D8			(int x, int y);
+	double					Get_MFD			(int x, int y);
+	double					Get_Aspect		(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__flow_width_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,345 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     HillShade.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "HillShade.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CHillShade::CHillShade(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Analytical Hillshading"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description(
+		_TL("Analytical hillshading calculation.")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"		, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "SHADE"			, _TL("Analytical Hillshading"),
+		_TL("The angle between the surface and the incoming light beams, measured in radians."),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"			, _TL("Shading Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Standard"),
+			_TL("Standard (max. 90Degree)"),
+			_TL("Combined Shading"),
+			_TL("Ray Tracing")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "AZIMUTH"			, _TL("Azimuth [Degree]"),
+		_TL("Direction of the light source, measured in degree clockwise from the north direction."),
+		PARAMETER_TYPE_Double		, 315
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DECLINATION"		, _TL("Declination [Degree]"),
+		_TL("Declination of the light source, measured in degree above the horizon."),
+		PARAMETER_TYPE_Double		, 45
+	);
+
+	Parameters.Add_Value(
+		NULL	, "EXAGGERATION"	, _TL("Exaggeration"),
+		_TL("The terrain exaggeration factor allows to increase the shading contrasts in flat areas."),
+		PARAMETER_TYPE_Double		, 4
+	);
+}
+
+//---------------------------------------------------------
+CHillShade::~CHillShade(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CHillShade::On_Execute(void)
+{
+	double	Azimuth, Declination;
+
+	//-----------------------------------------------------
+	pDTM			= Parameters("ELEVATION")	->asGrid();
+
+	pHillShade		= Parameters("SHADE")		->asGrid();
+
+	Azimuth			= Parameters("AZIMUTH")		->asDouble() * M_DEG_TO_RAD;
+	Declination		= Parameters("DECLINATION")	->asDouble() * M_DEG_TO_RAD;
+	Exaggeration	= Parameters("EXAGGERATION")->asDouble();
+
+	//-----------------------------------------------------
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:
+		Get_Shading	(Azimuth, Declination, false, false);
+		break;
+
+	case 1:
+		Get_Shading	(Azimuth, Declination, true , false);
+		break;
+
+	case 2:
+		Get_Shading	(Azimuth, Declination, false, true);
+		break;
+
+	case 3:
+		RayTrace	(Azimuth, Declination);
+		break;
+	}
+
+	//-----------------------------------------------------
+	pHillShade->Set_ZFactor(M_RAD_TO_DEG);
+
+	DataObject_Set_Colors(pHillShade, 100, SG_COLORS_BLACK_WHITE, true);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CHillShade::Get_Shading(double Azimuth, double Declination, bool bDelimit, bool bCombine)
+{
+	int		x, y;
+	double	s, a, sinDec, cosDec, d;
+
+	//-----------------------------------------------------
+	sinDec	= sin(Declination);
+	cosDec	= cos(Declination);
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pDTM->Get_Gradient(x, y, s, a) )
+			{
+				pHillShade->Set_NoData(x, y);
+			}
+			else
+			{
+				s	= tan(s);
+				d	= M_PI_090 - atan(Exaggeration * s);
+				d	= acos(sin(d) * sinDec + cos(d) * cosDec * cos(a - Azimuth));
+
+				if( bDelimit && d > M_PI_090 )
+				{
+					d	= M_PI_090;
+				}
+
+				if( bCombine )
+				{
+					d	*= s / M_PI_090;
+				}
+
+				pHillShade->Set_Value(x, y, d);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CHillShade::RayTrace(double Azimuth, double Declination)
+{
+	int		x, y, ix, iy, xStart, yStart, xStep, yStep;
+	double	dx, dy, dz;
+
+	//-----------------------------------------------------
+	Get_Shading(Azimuth, Declination, true, false);
+
+	//-----------------------------------------------------
+	Azimuth	= Azimuth + M_PI_180;
+
+	if( sin(Azimuth) > 0.0 )
+	{
+		xStart	= 0;
+		xStep	= 1;
+	}
+	else
+	{
+		xStart	= Get_NX() - 1;
+		xStep	= -1;
+	}
+
+	if( cos(Azimuth) > 0.0 )
+	{
+		yStart	= 0;
+		yStep	= 1;
+	}
+	else
+	{
+		yStart	= Get_NY() - 1;
+		yStep	= -1;
+	}
+
+	//-----------------------------------------------------
+	dx		= sin(Azimuth);
+	dy		= cos(Azimuth);
+
+	if( fabs(dx) > fabs(dy) )
+	{
+		dy	/= fabs(dx);
+		dx	= dx < 0 ? -1 : 1;
+	}
+	else if( fabs(dy) > fabs(dx) )
+	{
+		dx	/= fabs(dy);
+		dy	= dy < 0 ? -1 : 1;
+	}
+	else
+	{
+		dx	= dx < 0 ? -1 : 1;
+		dy	= dy < 0 ? -1 : 1;
+	}
+
+	dz		= tan(Declination) * sqrt(dx*dx + dy*dy) * Get_Cellsize();
+
+	//-----------------------------------------------------
+	for(iy=0, y=yStart; iy<Get_NY() && Set_Progress(iy); iy++, y+=yStep)
+	{
+		for(ix=0, x=xStart; ix<Get_NX(); ix++, x+=xStep)
+		{
+			RayTrace_Trace(x, y, dx, dy, dz);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CHillShade::RayTrace_Trace(int x, int y, double dx, double dy, double dz)
+{
+	double	ix, iy, iz;
+
+	if( !pDTM->is_NoData(x, y) )
+	{
+		for(ix=x+0.5, iy=y+0.5, iz=pDTM->asDouble(x, y); ; )
+		{
+			ix	+= dx;
+			iy	+= dy;
+			iz	-= dz;
+
+			x	= (int)ix;
+			y	= (int)iy;
+
+			if( !is_InGrid(x, y) || pDTM->asDouble(x, y) > iz )
+			{
+				break;
+			}
+			else if( pDTM->is_InGrid(x, y) )
+			{
+				pHillShade->Set_Value(x, y, M_PI_090);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/HillShade.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,119 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      HillShade.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__HillShade_H
+#define HEADER_INCLUDED__HillShade_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_lighting_EXPORT CHillShade : public CSG_Module_Grid
+{
+public:
+	CHillShade(void);
+	virtual ~CHillShade(void);
+
+
+protected:
+
+	virtual bool		On_Execute			(void);
+
+
+private:
+
+	int					RT_Dir_Top, RT_Dir_Right;
+
+	double				Exaggeration,
+						RT_Tan, RT_Cot, RT_Dz;
+
+	CSG_Grid				*pDTM, *pHillShade;
+
+
+	void				Get_Shading			(double Azimuth, double Declination, bool bDelimit, bool bCombine);
+
+	void				RayTrace			(double Azimuth, double Declination);
+	void				RayTrace_Trace		(int x, int y, double dx, double dy, double dz);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__HillShade_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Terrain Analysis - Lighting, Visibility" ));
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad, Goettingen (c) 2003" ));
+
+	case MLB_INFO_Description:
+		return( _TL("Lighting and visibility calculations for digital terrain models." ));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Terrain Analysis|Lighting" ));
+	}
+}
+
+//---------------------------------------------------------
+#include "HillShade.h"
+#include "Visibility_Point.h"
+#include "SolarRadiation.h"
+#include "SADO_SolarRadiation.h"
+#include "view_shed.h"
+#include "topographic_correction.h"
+
+//---------------------------------------------------------
+CSG_Module * Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CHillShade );
+	case 1:		return( new CVisibility_Point );
+	case 2:		return( new CSolarRadiation );
+	case 3:		return( new CSADO_SolarRadiation );
+	case 4:		return( new CView_Shed );
+	case 5:		return( new CTopographic_Correction );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ta_lighting_H
+#define HEADER_INCLUDED__ta_lighting_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef ta_lighting_EXPORTS
+	#define	ta_lighting_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	ta_lighting_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ta_lighting_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1166 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_lighting                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                SADO_SolarRadiation.cpp                //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "SADO_SolarRadiation.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSADO_SolarRadiation::CSADO_SolarRadiation(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Insolation"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculation of incoming solar radiation (insolation). "
+		"Based on the SADO (System for the Analysis of Discrete Surfaces) routines "
+		"developed by Boehner & Trachinow. "
+		"\n\n"
+		"References:\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "GRD_DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRD_VAPOUR"		, _TL("Water Vapour Pressure [mbar]"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRD_LAT"			, _TL("Latitude [degree]"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRD_LON"			, _TL("Longitude [degree]"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRD_DIRECT"		, _TL("Direct Insolation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRD_DIFFUS"		, _TL("Diffuse Insolation"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRD_TOTAL"		, _TL("Total Insolation"),
+		_TL("Total insolation, the sum of direct and diffuse incoming solar radiation."),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	//-----------------------------------------------------
+	Parameters.Add_Value(
+		NULL	, "BHORIZON"		, _TL("Horizontal Projection"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "SOLARCONST"		, _TL("Solar Constant [J]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 8.164, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ATMOSPHERE"		, _TL("Height of Atmosphere [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 12000.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "VAPOUR"			, _TL("Water Vapour Pressure [mbar]"),
+		_TL("This value is used as constant if no vapour pressure grid is given."),
+		PARAMETER_TYPE_Double		, 10, 0.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_TIME"		, _TL("Time"),
+		_TL("")
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "PERIOD"			, _TL("Time Period"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("moment"),
+			_TL("day"),
+			_TL("range of days"),
+			_TL("same moment for a range of days")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DHOUR"			, _TL("Daily Time Resolution [h]"),
+		_TL("Time resolution for a day's calculation."),
+		PARAMETER_TYPE_Double		, 1.0, 0.0, true, 24.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DDAYS"			, _TL("Range of Days Time Resolution [days]"),
+		_TL("Time resolution for a range of days calculation."),
+		PARAMETER_TYPE_Int			, 1, 1, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DAY_A"			, _TL("Day of Year"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 81
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DAY_B"			, _TL("Day of Year (Range End)"),
+		_TL(""),
+		PARAMETER_TYPE_Int			, 87
+	);
+
+	Parameters.Add_Value(
+		pNode	, "MOMENT"			, _TL("Moment [h]"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 12.0, 0.0, true, 24.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_LOCATION"	, _TL("Location"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "LATITUDE"		, _TL("Latitude"),
+		_TL(""),
+		PARAMETER_TYPE_Degree		, 53.0, -90.0, true, 90.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "BENDING"			, _TL("Planetery Bending"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+
+	Parameters.Add_Value(
+		pNode	, "RADIUS"			, _TL("Planetary Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 6366737.96, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "LAT_OFFSET"		, _TL("Latitude relates to grid's..."),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("bottom"),
+			_TL("center"),
+			_TL("top"),
+			_TL("user defined reference")
+		), 3
+	);
+
+	Parameters.Add_Choice(
+		pNode	, "LON_OFFSET"		, _TL("Local time relates to grid's..."),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("left"),
+			_TL("center"),
+			_TL("right"),
+			_TL("user defined reference")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		pNode	, "LAT_REF_USER"	, _TL("Latitude (user defined reference)"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0
+	);
+
+	Parameters.Add_Value(
+		pNode	, "LON_REF_USER"	, _TL("Local Time (user defined reference)"),
+		_TL(""),
+		PARAMETER_TYPE_Double		, 0.0
+	);
+
+	//-----------------------------------------------------
+	pNode	= Parameters.Add_Node(
+		NULL	, "NODE_UPDATEVIEW"	, _TL("Update View"),
+		_TL("")
+	);
+
+	Parameters.Add_Value(
+		pNode	, "UPD_DIRECT"		, _TL("Direct Insolation"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+
+	Parameters.Add_Value(
+		pNode	, "UPD_DIFFUS"		, _TL("Diffuse Insolation"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+
+	Parameters.Add_Value(
+		pNode	, "UPD_TOTAL"		, _TL("Total Insolation"),
+		_TL(""),
+		PARAMETER_TYPE_Bool			, false
+	);
+}
+
+//---------------------------------------------------------
+CSADO_SolarRadiation::~CSADO_SolarRadiation(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::On_Execute(void)
+{
+	//-----------------------------------------------------
+	m_pDEM			= Parameters("GRD_DEM")		->asGrid();
+	m_pVP			= Parameters("GRD_VAPOUR")	->asGrid();
+
+	m_pSumDirect	= Parameters("GRD_DIRECT")	->asGrid();
+	m_bUpdateDirect	= Parameters("UPD_DIRECT")	->asBool() && m_pSumDirect;
+	m_pSumDiffus	= Parameters("GRD_DIFFUS")	->asGrid();
+	m_bUpdateDiffus	= Parameters("UPD_DIFFUS")	->asBool() && m_pSumDiffus;
+	m_pSumTotal		= Parameters("GRD_TOTAL")	->asGrid();
+	m_bUpdateTotal	= Parameters("UPD_TOTAL")	->asBool() && m_pSumTotal;
+
+	m_Solar_Const	= Parameters("SOLARCONST")	->asDouble();
+	m_Atmosphere	= Parameters("ATMOSPHERE")	->asDouble();
+	m_VP			= Parameters("VAPOUR")		->asDouble();
+	m_bHorizon		= Parameters("BHORIZON")	->asBool();
+
+	m_Latitude		= Parameters("LATITUDE")	->asDouble() * M_DEG_TO_RAD;
+	m_bBending		= Parameters("BENDING")		->asBool();
+
+	m_Hour			= Parameters("MOMENT")		->asDouble();
+	m_dHour			= Parameters("DHOUR")		->asDouble();
+	m_dDays			= Parameters("DDAYS")		->asInt();
+	m_Day_A			= Parameters("DAY_A")		->asInt();
+	m_Day_B			= Parameters("DAY_B")		->asInt();
+
+	switch( Parameters("PERIOD")->asInt() )
+	{
+	case 0:	// moment
+		m_bMoment		= true;
+		m_bUpdateDirect	= m_bUpdateDiffus	= m_bUpdateTotal	= false;
+		break;
+
+	case 1:	// day
+		m_bMoment		= false;
+		m_Day_B			= m_Day_A;
+		m_Hour			= 0.0;
+		break;
+
+	case 2:	// range of days
+		m_bMoment		= false;
+		m_Hour			= 0.0;
+		break;
+
+	case 3:	// same moment for a range of days
+		m_bMoment		= false;
+		m_dHour			= 24.0;
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( !m_pSumDirect && !m_pSumDiffus && !m_pSumTotal )
+	{
+		Message_Dlg(_TL("No output grid has been choosen."), Get_Name());
+	}
+	else if( m_pSumDirect == m_pDEM || m_pSumDiffus == m_pDEM || m_pSumTotal == m_pDEM )
+	{
+		Message_Dlg(_TL("Output must not overwrite elevation grid."), Get_Name());
+	}
+	else
+	{
+		return( Get_Insolation() );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Initialise(void)
+{
+	int		x, y;
+
+	Process_Set_Text(_TL("initialising..."));
+
+	//-----------------------------------------------------
+	CSG_Colors	c(100, SG_COLORS_YELLOW_RED, true);
+
+	c.Set_Ramp(SG_GET_RGB(  0,   0,  64), SG_GET_RGB(255, 159,   0),  0, 50);
+	c.Set_Ramp(SG_GET_RGB(255, 159,   0), SG_GET_RGB(255, 255, 255), 50, 99);
+
+	if( m_pSumDirect )
+	{
+		m_pSumDirect->Assign(0.0);
+		m_pSumDirect->Set_Unit(_TL("Joule"));
+		DataObject_Set_Colors(m_pSumDirect, c);
+
+		if( m_bUpdateDirect )
+		{
+			m_TmpDirect.Create(*Get_System(), SG_DATATYPE_Float);
+			DataObject_Update(m_pSumDirect, true);
+		}
+	}
+
+	if( m_pSumDiffus )
+	{
+		m_pSumDiffus->Assign(0.0);
+		m_pSumDiffus->Set_Unit(_TL("Joule"));
+		DataObject_Set_Colors(m_pSumDiffus, c);
+
+		if( m_bUpdateDiffus )
+		{
+			m_TmpDiffus.Create(*Get_System(), SG_DATATYPE_Float);
+			DataObject_Update(m_pSumDiffus, true);
+		}
+	}
+
+	if( m_pSumTotal )
+	{
+		m_pSumTotal ->Assign(0.0);
+		m_pSumTotal ->Set_Unit(_TL("Joule"));
+		DataObject_Set_Colors(m_pSumTotal , c);
+
+		if( m_bUpdateTotal )
+		{
+			m_TmpTotal.Create(*Get_System(), SG_DATATYPE_Float);
+			DataObject_Update(m_pSumTotal , true);
+		}
+	}
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("initialising gradient..."));
+
+	m_Shade .Create(*Get_System(), SG_DATATYPE_Byte);
+	m_Slope .Create(*Get_System(), SG_DATATYPE_Float);
+	m_Aspect.Create(*Get_System(), SG_DATATYPE_Float);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			double	s, a;
+
+			if( m_pDEM->Get_Gradient(x, y, s, a) )
+			{
+				m_Slope .Set_Value(x, y, s);
+				m_Aspect.Set_Value(x, y, a);
+			}
+			else
+			{
+				m_Slope .Set_NoData(x, y);
+				m_Aspect.Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_bBending )
+	{
+		Process_Set_Text(_TL("initialising planetary bending..."));
+
+		CSG_Grid	*pLat	= Parameters("GRD_LAT")->asGrid(),
+				*pLon	= Parameters("GRD_LON")->asGrid();
+
+		m_Lat		.Create(*Get_System(), SG_DATATYPE_Float);
+		m_Lon		.Create(*Get_System(), SG_DATATYPE_Float);
+		m_Decline	.Create(*Get_System(), SG_DATATYPE_Float);
+		m_Azimuth	.Create(*Get_System(), SG_DATATYPE_Float);
+
+		if( pLat || pLon )
+		{
+			if( pLat )
+			{
+				m_Lat	= *pLat;
+				m_Lat	*= M_DEG_TO_RAD;
+			}
+
+			if( pLon )
+			{
+				m_Lon	= *pLon;
+				m_Lon	*= M_DEG_TO_RAD;
+			}
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			double	d, dx, dy, dxA, dyA;
+
+			d	= M_DEG_TO_RAD / (Parameters("RADIUS")->asDouble() * M_PI / 180.0);
+
+			switch( Parameters("LON_OFFSET")->asInt() )
+			{
+			case 0:	dxA	= Get_System()->Get_Extent().Get_XMin();	break;	// left
+			case 1:	dxA	= Get_System()->Get_Extent().Get_XCenter();	break;	// center
+			case 2:	dxA	= Get_System()->Get_Extent().Get_XMax();	break;	// right
+			case 3:	dxA	= Parameters("LON_REF_USER")->asDouble();	break;	// user defined coordinate
+			}
+
+			switch( Parameters("LAT_OFFSET")->asInt() )
+			{
+			case 0:	dyA	= Get_System()->Get_Extent().Get_YMin();	break;	// bottom
+			case 1:	dyA	= Get_System()->Get_Extent().Get_YCenter();	break;	// center
+			case 2:	dyA	= Get_System()->Get_Extent().Get_YMax();	break;	// top
+			case 3:	dyA	= Parameters("LAT_REF_USER")->asDouble();	break;	// user defined coordinate
+			}
+
+			dxA	 = d * (Get_XMin() - dxA);
+			dyA	 = d * (Get_YMin() - dyA) + m_Latitude;
+			d	*= Get_Cellsize();
+
+			for(y=0, dy=dyA; y<Get_NY() && Set_Progress(y); y++, dy+=d)
+			{
+				for(x=0, dx=dxA; x<Get_NX(); x++, dx+=d)
+				{
+					m_Lat.Set_Value(x, y, dy);
+					m_Lon.Set_Value(x, y, dx);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Finalise(double SumFactor)
+{
+	//-----------------------------------------------------
+	if( m_pSumDirect )
+	{
+		if( m_bUpdateDirect )	m_pSumDirect->Assign(&m_TmpDirect);
+		if( SumFactor != 1.0 )	*m_pSumDirect	*= SumFactor;
+	}
+
+	if( m_pSumDiffus )
+	{
+		if( m_bUpdateDiffus )	m_pSumDiffus->Assign(&m_TmpDiffus);
+		if( SumFactor != 1.0 )	*m_pSumDiffus	*= SumFactor;
+	}
+
+	if( m_pSumTotal )
+	{
+		if( m_bUpdateTotal )	m_pSumTotal->Assign(&m_TmpTotal);
+		if( SumFactor != 1.0 )	*m_pSumTotal	*= SumFactor;
+	}
+
+	//-----------------------------------------------------
+	m_Shade		.Destroy();
+	m_Slope		.Destroy();
+	m_Aspect	.Destroy();
+
+	m_Lat		.Destroy();
+	m_Lon		.Destroy();
+	m_Decline	.Destroy();
+	m_Azimuth	.Destroy();
+
+	m_TmpDirect	.Destroy();
+	m_TmpDiffus	.Destroy();
+	m_TmpTotal	.Destroy();
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Get_Insolation(void)
+{
+	//-----------------------------------------------------
+	if( Initialise() )
+	{
+		if( m_bMoment )
+		{
+			Get_Insolation(m_Day_A, m_Hour);
+
+			Finalise();
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			for(int Day=m_Day_A; Day<=m_Day_B && Process_Get_Okay(false); Day+=m_dDays)
+			{
+				for(double Hour=m_Hour; Hour<24.0 && Process_Get_Okay(false); Hour+=m_dHour)
+				{
+					Process_Set_Text(CSG_String::Format(SG_T("%s: %d(%d-%d), %s: %f"), _TL("Day"), Day, m_Day_A, m_Day_B, _TL("Hour"), Hour));
+
+					if( m_bUpdateDirect )	m_pSumDirect->Assign(0.0);
+					if( m_bUpdateDiffus )	m_pSumDiffus->Assign(0.0);
+					if( m_bUpdateTotal )	m_pSumTotal ->Assign(0.0);
+
+					if( Get_Insolation(Day, Hour) )
+					{
+						if( m_bUpdateDirect )
+						{
+							m_TmpDirect	+= *m_pSumDirect;
+							DataObject_Update(m_pSumDirect);
+						}
+
+						if( m_bUpdateDiffus )
+						{
+							m_TmpDiffus	+= *m_pSumDiffus;
+							DataObject_Update(m_pSumDiffus);
+						}
+
+						if( m_bUpdateTotal )
+						{
+							m_TmpTotal	+= *m_pSumTotal;
+							DataObject_Update(m_pSumTotal);
+						}
+					}
+				}
+			}
+
+			Finalise(m_dHour / (24.0 * (1 + m_Day_B - m_Day_A)));	// *m_pSumDirect	*= m_dHour / D->size();
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Get_Insolation(int Day, double Hour)
+{
+	double	Azimuth, Decline;
+
+	if( m_bBending )
+	{
+		bool	bGo	= false;
+
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				Get_Solar_Position(Day, Hour, m_Lat.asDouble(x, y), m_Lon.asDouble(x, y), Decline, Azimuth);
+
+				m_Azimuth.Set_Value(x, y, Azimuth);
+				m_Decline.Set_Value(x, y, Decline);
+
+				if( Decline > 0.0 )
+				{
+					bGo	= true;
+				}
+			}
+		}
+
+		if( bGo )
+		{
+			return( Set_Insolation(Decline, Azimuth) );
+		}
+	}
+	else if( Get_Solar_Position(Day, Hour, m_Latitude, 0.0, Decline, Azimuth) )
+	{
+		return( Set_Insolation(Decline, Azimuth) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CSADO_SolarRadiation::Get_Vapour_Exponent(double VapourPressure)
+{
+	return( 0.916  - (VapourPressure > 0.0 ? 0.05125 * sqrt(VapourPressure) : 0.0) );
+}
+
+//---------------------------------------------------------
+inline double CSADO_SolarRadiation::Get_Vapour_A(double VapourPressure)
+{
+	return( 0.4158 + (VapourPressure > 0.0 ? 0.0399  * sqrt(VapourPressure) : 0.0) );
+}
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Set_Insolation(double Decline, double Azimuth)
+{
+	int		x, y;
+	double	a, e, Direct, Diffus;
+
+	Get_Shade(Decline, Azimuth);
+
+	e	= Get_Vapour_Exponent	(m_VP);
+	a	= Get_Vapour_A			(m_VP);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDEM->is_NoData(x, y) )
+			{
+				if( m_pSumDirect )	m_pSumDirect->Set_NoData(x, y);
+				if( m_pSumDiffus )	m_pSumDiffus->Set_NoData(x, y);
+				if( m_pSumTotal )	m_pSumTotal ->Set_NoData(x, y);
+			}
+			else
+			{
+				if( m_pVP != NULL )
+				{
+					e	= Get_Vapour_Exponent	(m_pVP->asDouble(x, y));
+					a	= Get_Vapour_A			(m_pVP->asDouble(x, y));
+				}
+
+				if( m_bBending )
+				{
+					Azimuth	= m_Azimuth.asDouble(x, y);
+					Decline	= m_Decline.asDouble(x, y);
+				}
+
+				if( Decline > 0.0 )
+				{
+					Direct	= Get_Solar_Direct(x, y, Decline, Azimuth, e);
+					Diffus	= Get_Solar_Diffus(x, y, Decline, a      , e);
+
+					if( m_pSumDirect )	m_pSumDirect->Add_Value(x, y, Direct);
+					if( m_pSumDiffus )	m_pSumDiffus->Add_Value(x, y, Diffus);
+					if( m_pSumTotal  )	m_pSumTotal ->Add_Value(x, y, Direct + Diffus);
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CSADO_SolarRadiation::Get_Solar_Reduction(double Elevation, double Decline, double Reduction)
+{
+	return( Decline > 0.0 ? (m_Solar_Const * pow(Reduction, (1.0 - Elevation / m_Atmosphere) / sin(Decline))) : 0.0 );
+}
+
+//---------------------------------------------------------
+inline double CSADO_SolarRadiation::Get_Solar_Direct(int x, int y, double Decline, double Azimuth, double Exponent)
+{
+	if( m_Shade.asInt(x, y) == 0 )
+	{
+		double	Angle, Slope;
+
+		Slope	= m_bHorizon ? 0.0 : m_Slope.asDouble(x, y);
+
+		Angle	= cos(Slope) * cos(Decline - M_PI_090)
+				+ sin(Slope) * sin(M_PI_090 - Decline)
+				* cos(Azimuth - m_Aspect.asDouble(x, y));
+
+		if( Angle > 0.0 )
+		{
+			return( Angle * Get_Solar_Reduction(m_pDEM->asDouble(x, y), Decline, Exponent) );
+		}
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+inline double CSADO_SolarRadiation::Get_Solar_Diffus(int x, int y, double Decline, double A, double Exponent)
+{
+	double	Dh, Ih, d, Slope, srad;
+
+	Ih		= Get_Solar_Reduction(m_pDEM->asDouble(x, y), Decline, Exponent) * sin(Decline);
+//	Decline	*= M_RAD_TO_DEG;	// Fehler in SADO ????!!!!!
+	d		= m_Atmosphere / (m_Atmosphere - m_pDEM->asDouble(x, y))
+			* (0.0001165 * Decline*Decline - 0.0152 * Decline + A);
+	d		= 1.0 - d;
+	Dh		= Ih / d - Ih;
+
+	Slope	= m_bHorizon ? 0.0 : m_Slope.asDouble(x, y);
+
+	srad	= (Dh + Dh * cos(Slope)) / 2.0;
+
+	return( srad < 0.0 || srad > m_Solar_Const ? m_Solar_Const : srad );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Get_Shade(double Decline, double Azimuth)
+{
+	//-----------------------------------------------------
+	m_Shade.Assign(0.0);
+
+	if( !m_bBending )
+	{
+		int		i, x, y;
+		double	dx, dy, dz;
+
+		Get_Shade_Params(Decline, Azimuth, dx, dy, dz);
+
+		for(i=0; i<Get_NCells() && Set_Progress_NCells(i); i++)
+		{
+			if( m_pDEM->Get_Sorted(i, x, y) && !Get_Shade_Complete(x, y) )
+			{
+				Set_Shade(x, y, dx, dy, dz);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		int		i, x, y, iLock;
+
+		for(i=0, iLock=1; i<Get_NCells() && Set_Progress_NCells(i); i++, iLock++)
+		{
+			if( m_pDEM->Get_Sorted(i, x, y) && !Get_Shade_Complete(x, y) )
+			{
+				if( iLock >= 255 )
+					iLock	= 1;
+
+				if( iLock == 1 )
+					Lock_Create();
+
+				Set_Shade_Bended(x, y, iLock);
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CSADO_SolarRadiation::Set_Shade(int x, int y, double dx, double dy, double dz)
+{
+	for(double ix=x+0.5, iy=y+0.5, iz=m_pDEM->asDouble(x, y); ; )
+	{
+		x	= (int)(ix	+= dx);
+		y	= (int)(iy	+= dy);
+					iz	-= dz;
+
+		if( !is_InGrid(x, y) || m_pDEM->asDouble(x, y) > iz )
+		{
+			return;
+		}
+
+		m_Shade.Set_Value(x, y, 1);
+	}
+}
+
+//---------------------------------------------------------
+void CSADO_SolarRadiation::Set_Shade_Bended(int x, int y, char iLock)
+{
+	double	dx, dy, dz;
+
+	Get_Shade_Params(m_Decline.asDouble(x, y), m_Azimuth.asDouble(x, y), dx, dy, dz);
+
+	for(double ix=x+0.5, iy=y+0.5, iz=m_pDEM->asDouble(x, y); ; )
+	{
+		x	= (int)(ix	+= dx);
+		y	= (int)(iy	+= dy);
+					iz	-= dz;
+
+		if( !is_InGrid(x, y) || m_pDEM->asDouble(x, y) > iz || Lock_Get(x, y) == iLock )
+		{
+			return;
+		}
+
+		m_Shade.Set_Value(x, y, 1);
+
+		//---------------------------------------------
+		Lock_Set(x, y, iLock);
+
+		Get_Shade_Params(m_Decline.asDouble(x, y), m_Azimuth.asDouble(x, y), dx, dy, dz);
+	}
+}
+
+//---------------------------------------------------------
+inline bool CSADO_SolarRadiation::Get_Shade_Complete(int x, int y)
+{
+	if( m_Shade.asInt(x, y) == 1 )
+	{
+		for(int iy=y-1; iy<=y+1; iy++)
+		{
+			for(int ix=x-1; ix<x+1; ix++)
+			{
+				if( is_InGrid(ix, iy) && m_Shade.asInt(ix, iy) == 0 )
+				{
+					return( false );
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline void CSADO_SolarRadiation::Get_Shade_Params(double Decline, double Azimuth, double &dx, double &dy, double &dz)
+{
+	dz	= Azimuth + M_PI_180;
+	dx	= sin(dz);
+	dy	= cos(dz);
+
+	if( fabs(dx) > fabs(dy) )
+	{
+		dy	/= fabs(dx);
+		dx	= dx < 0 ? -1 : 1;
+	}
+	else if( fabs(dy) > fabs(dx) )
+	{
+		dx	/= fabs(dy);
+		dy	= dy < 0 ? -1 : 1;
+	}
+	else
+	{
+		dx	= dx < 0 ? -1 : 1;
+		dy	= dy < 0 ? -1 : 1;
+	}
+
+	dz	= tan(Decline) * sqrt(dx*dx + dy*dy) * Get_Cellsize();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CSADO_SolarRadiation::Get_Solar_Position(int Day, double Hour, double LAT, double LON, double &Declination, double &Azimuth)
+{
+	static const int	Day2Month[13]	= {	0, 31, 49, 80, 109, 140, 170, 201, 232, 272, 303, 333, 366 };
+
+	static const double	ECLIPTIC_OBL	= M_DEG_TO_RAD * 23.43999;	// obliquity of ecliptic
+
+	int		i;
+
+	double	JD, T, M, L, X, Y, Z, R, UTime,
+			DEC, RA, theta, tau,
+			Month, Year		= 2000;
+
+	//-----------------------------------------------------
+
+	for(Month=1, i=0; i<=12; i++)
+	{
+		if( Day < Day2Month[i] )
+		{
+			Month	= i;
+			Day		-= Day2Month[i - 1];
+			break;
+		}
+	}
+
+	if( Month < 1 || Month > 12 )	// nur Tag (1 - 365) zaehlt...
+	{
+		Month		= 1;
+	}
+
+	if( Month <= 2 )
+	{
+		Month		+= 12;
+		Year		-= 1;
+	}
+
+
+	//-----------------------------------------------------
+
+//	UTime		= Hour - LON * 12.0 / M_PI;
+	UTime		= Hour;
+
+
+	//-----------------------------------------------------
+	// 1. Julian Date...
+
+	JD			= (int)(365.25 * Year) + (int)(30.6001 * (Month + 1)) - 15 + 1720996.5 + Day + UTime / 24.0;
+	T			= (JD - 2451545.0 ) / 36525.0;	// number of Julian centuries since 2000/01/01 at 12 UT (JD = 2451545.0)
+
+
+	//-----------------------------------------------------
+	// 2. Solar Coordinates (according to: Jean Meeus: Astronomical Algorithms), accuracy of 0.01 degree
+
+	M			= M_DEG_TO_RAD * (357.52910 + 35999.05030 * T - 0.0001559 * T * T - 0.00000048 * T * T * T);	// mean anomaly
+	L			= M_DEG_TO_RAD * (	(280.46645 + 36000.76983 * T + 0.0003032 * T * T)						// mean longitude
+							+	(	(1.914600 - 0.004817 * T - 0.000014  * T * T) * sin(M)
+								+	(0.019993 - 0.000101 * T) * sin(2 * M) + 0.000290 * sin(3 * M)		// true longitude
+								)
+							);
+
+
+	//-----------------------------------------------------
+	// 3. convert ecliptic longitude to right ascension RA and declination delta
+
+	X			= cos(L);
+	Y			= cos(ECLIPTIC_OBL) * sin(L);
+	Z			= sin(ECLIPTIC_OBL) * sin(L);
+	R			= sqrt(1.0 - Z*Z); 
+
+	DEC			= atan2(Z, R);
+	RA			= 2.0 * atan2(Y, (X + R));
+
+
+	//-----------------------------------------------------
+	// 4. compute sidereal time (degree) at Greenwich local sidereal time at longitude (Degree)
+
+	theta		= LON + M_DEG_TO_RAD * (280.46061837 + 360.98564736629 * (JD - 2451545.0) + T*T * (0.000387933 - T / 38710000.0));
+
+
+	//-----------------------------------------------------
+	// 5. compute local hour angle (degree)
+
+	tau			= theta - RA;
+
+
+	//-----------------------------------------------------
+	// 6. convert (tau, delta) to horizon coordinates (h, az) of the observer
+
+	Declination	= asin ( sin(LAT) * sin(DEC) + cos(LAT) * cos(DEC) * cos(tau) );
+
+	Azimuth		= atan2( -sin(tau) * cos(DEC), cos(LAT) * sin(DEC) - sin(LAT) * cos(DEC) * cos(tau) );
+//	Azimuth		= atan2( -sin(Tau), cos(LAT) * tan(DEC) - sin(LAT) * cos(Tau) );	// previous formula gives same result but is better because of division by zero effects...
+
+	return( Declination > 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+/*/---------------------------------------------------------
+#define CHECK_SHADOW(X, Y)	if( (d = SG_Get_Distance(x, y, X, Y) * Get_Cellsize()) > 0.0 )\
+							{\
+								if( (t = (m_pDEM->asDouble(X, Y) - z) / d) > tMax )\
+								{\
+									tMax	= t;\
+								}\
+								\
+								if( (d = zMax / d) < tanDec || d < tMax )\
+								{\
+									return( false );\
+								}\
+								else if( tMax > tanDec )\
+								{\
+									return( true );\
+								}\
+							}
+
+//---------------------------------------------------------
+bool CSADO_SolarRadiation::Get_Solar_Shadow(int x, int y, double Decline, double Azimuth)
+{
+	static double	Zenith	= 89.9999 * M_DEG_TO_RAD;
+
+	//-----------------------------------------------------
+	if( Decline >= Zenith || Decline > m_Slope.Get_ZMax() )
+	{
+		return( false );
+	}
+
+	if( Decline <= 0.0 )
+	{
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	bool	bGo;
+	int		dx, nx, ix, iy, iy_Last, jy;
+	double	dy, d, t, tMax, z, zMax, tanDec;
+
+	//-----------------------------------------------------
+	Azimuth	= fmod(Azimuth, M_PI_360);	if( Azimuth < 0.0 )	Azimuth	+= M_PI_360;
+
+	if( Azimuth < M_PI_180 )
+	{
+		dx	= 1;
+		nx	= Get_NX() - 1;
+	}
+	else
+	{
+		dx	= -1;
+		nx	= 0;
+	}
+
+	Azimuth	= M_PI_090 - Azimuth;
+
+	if(		 Azimuth	==  M_PI_090 )
+			 Azimuth	=   89.9999 * M_DEG_TO_RAD;
+	else if( Azimuth	== -M_PI_090 )
+			 Azimuth	= - 89.9999 * M_DEG_TO_RAD;
+	else if( Azimuth	== -M_PI_180 )
+			 Azimuth	= -179.9999 * M_DEG_TO_RAD;
+	else if( Azimuth	== -M_PI_270)
+			 Azimuth	= -269.9999 * M_DEG_TO_RAD;
+
+	dy		= tan(Azimuth);
+
+	//-----------------------------------------------------
+	z		= m_pDEM->asDouble(x, y);
+	zMax	= m_pDEM->Get_ZMax();
+	tanDec	= tan(Decline);
+	tMax	= 0.0;
+  
+	//-----------------------------------------------------
+	for(ix=x, iy=y, bGo=true; ix!=nx && bGo; ix+=dx)
+	{
+		iy_Last	= iy;
+		iy		= y + (int)floor(dy * (ix - x + (dx > 0 ? 0.5 : -0.5)));
+
+		if( iy < 0 )
+		{
+			bGo	= false;
+			iy	= 0;
+		}
+		else if( iy >= Get_NY() )
+		{
+			bGo	= false;
+			iy	= Get_NY() - 1;
+		}
+
+		//-------------------------------------------------
+		if( iy_Last < iy )
+		{
+			for(jy=iy_Last+1; jy<=iy; jy++)
+			{
+				CHECK_SHADOW(ix, jy);
+			}
+		}
+		else if( iy_Last > iy )
+		{
+			for(jy=iy_Last; jy>iy; jy--)
+			{
+				CHECK_SHADOW(ix, jy);
+			}
+		}
+		else if( iy_Last == iy ) 
+		{
+			CHECK_SHADOW(ix, iy);
+		}
+	}
+
+	return( false );
+}/**/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SADO_SolarRadiation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,135 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_lighting                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 SADO_SolarRadiation.h                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SADO_SolarRadiation_H
+#define HEADER_INCLUDED__SADO_SolarRadiation_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_lighting_EXPORT CSADO_SolarRadiation : public CSG_Module_Grid
+{
+public:
+	CSADO_SolarRadiation(void);
+	virtual ~CSADO_SolarRadiation(void);
+
+//	virtual const SG_Char *	Get_MenuPath			(void)	{	return( _TL("R:Lighting") );	}
+
+
+protected:
+
+	virtual bool			On_Execute				(void);
+
+
+private:
+
+	bool					m_bMoment, m_bHorizon, m_bBending,
+							m_bUpdateDirect, m_bUpdateDiffus, m_bUpdateTotal;
+
+	int						m_Day_A, m_Day_B, m_dDays;
+
+	double					m_Solar_Const, m_Atmosphere, m_VP, m_Latitude, m_Hour, m_dHour;
+
+	CSG_Grid					*m_pDEM, *m_pVP, *m_pSumDirect, *m_pSumDiffus, *m_pSumTotal,
+							m_TmpDirect, m_TmpDiffus, m_TmpTotal,
+							m_Slope, m_Aspect, m_Shade, m_Lat, m_Lon, m_Decline, m_Azimuth;
+
+
+	bool					Initialise				(void);
+	bool					Finalise				(double SumFactor = 1.0);
+
+	bool					Get_Insolation			(void);
+	bool					Get_Insolation			(int Day, double Hour);
+
+	double					Get_Vapour_Exponent		(double VapourPressure);
+	double					Get_Vapour_A			(double VapourPressure);
+	bool					Set_Insolation			(double Decline, double Azimuth);
+
+	double					Get_Solar_Reduction		(double Elevation, double Decline, double Reduction);
+	double					Get_Solar_Direct		(int x, int y, double Decline, double Azimuth, double Exponent);
+	double					Get_Solar_Diffus		(int x, int y, double Decline, double A      , double Exponent);
+
+	bool					Get_Shade				(double Azimuth, double Decline);
+	void					Set_Shade				(int x, int y, double dx, double dy, double dz);
+	void					Set_Shade_Bended		(int x, int y, char iLock);
+	bool					Get_Shade_Complete		(int x, int y);
+	void					Get_Shade_Params		(double Decline, double Azimuth, double &dx, double &dy, double &dz);
+
+	bool					Get_Solar_Position		(int Day, double Hour, double Lat, double Lon, double &Dec, double &Azi);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SADO_SolarRadiation_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,796 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  SolarRadiation.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "SolarRadiation.h"
+#include "HillShade.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSolarRadiation::CSolarRadiation(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1, *pNode_2;
+
+	//-----------------------------------------------------
+	Set_Name(_TL("Incoming Solar Radiation"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculation of the potential incoming solar radiation.\n\n"
+		"Reference:\n"
+		"- Wilson, J.P., Gallant, J.C., (Eds.), 2000:\n"
+		"    'Terrain analysis - principles and applications',\n"
+		"    New York, John Wiley & Sons, Inc.")
+	);
+
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Grid(
+		NULL	, "INSOLAT"		, _TL("Solar Radiation"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	pNode_0	= Parameters.Add_Grid(
+		NULL	, "DURATION"	, _TL("Duration of Insolation"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "UPDATE"		, _TL("Update View"),
+		_TL("Show each time step during calculation."),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	pNode_1	= Parameters.Add_Choice(
+		pNode_0	, "UNIT"		, _TL("Unit"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("kWh/m\xc2\xb2"),
+			_TL("J/m\xc2\xb2")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	pNode_0	= Parameters.Add_Node(
+		NULL	, "NODE_SOLAR"	, _TL("Solar Radiation"),
+		_TL("")
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "SOLCONST"	, _TL("Solar Constant [W/m\xc2\xb2]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1367
+	);
+
+	pNode_1	= Parameters.Add_Choice(
+		pNode_0	, "METHOD"		, _TL("Atmospheric Effects"),
+		_TL("Account for atmospheric effects using either a lumped atmospheric transmittance approach or by calculating the components (water and dust)."),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Lumped atmospheric transmittance"),
+			_TL("Calculating the components")
+		), 0
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "TRANSMITT"	, _TL("Lumped Transmittance [%]"),
+		_TL("The transmittance of the atmosphere (usually between 60 and 80%)"),
+		PARAMETER_TYPE_Double	, 70,
+		0.0		, true,
+		100.0	, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "PRESSURE"	, _TL("Atmospheric Pressure [mb]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1013,
+		0.0		, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "WATER"		, _TL("Water Content [cm]"),
+		_TL("Water content of a vertical slice of atmosphere in cm: 1.5 to 1.7, average=1.68"),
+		PARAMETER_TYPE_Double	, 1.68,
+		0.0		, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "DUST"		, _TL("Dust [ppm]"),
+		_TL("Dust factor: 100 ppm (standard)"),
+		PARAMETER_TYPE_Double	, 100,
+		0.0		, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "LATITUDE"	, _TL("Latitude [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 53.5,
+		-90.0	, true,
+		90.0	, true
+	);
+
+
+	//-----------------------------------------------------
+	// Daily Time Resolution...
+
+	pNode_0	= Parameters.Add_Node(
+		NULL	, "NODE_HOUR"	, _TL("Daily Time Resolution"),
+		_TL("")
+	);
+
+	pNode_1	= Parameters.Add_Range(
+		pNode_0	, "HOUR_RANGE"	, _TL("Time Span [h]"),
+		_TL("Time span used for the calculation of daily radiation sums."),
+		 0.0	, 24.0,
+		 0.0	, true,
+		24.0	, true
+	);
+
+	pNode_1	= Parameters.Add_Value(
+		pNode_0	, "HOUR_STEP"	, _TL("Time Step [h]"),
+		_TL("Time step size used for the calculation of daily radiation sums."),
+		PARAMETER_TYPE_Double	, 1.0,
+		0.001	, true,
+		12.0	, true
+	);
+
+
+	//-----------------------------------------------------
+	// Time Settings...
+
+	pNode_0	= Parameters.Add_Choice(
+		NULL	, "TIMESPAN"	, _TL("Simulation Time"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Single Day"),
+			_TL("Range of Days"),
+			_TL("One Year")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	pNode_1	= Parameters.Add_Node(
+		pNode_0	, "NODE_SINGLE_DAY"		, _TL("Single Day"),
+		_TL("")
+	);
+
+	pNode_2	= Parameters.Add_Choice(
+		pNode_1	, "SINGLE_DAY_DAY"		, _TL("Day"),
+		_TL(""),
+
+		SG_T("  1|  2|  3|  4|  5|  6|  7|  8|  9| 10|")
+		SG_T(" 11| 12| 13| 14| 15| 16| 17| 18| 19| 20|")
+		SG_T(" 21| 22| 23| 24| 25| 26| 27| 28| 29| 30|")
+		SG_T(" 31|"), 20
+	);
+
+	pNode_2	= Parameters.Add_Choice(
+		pNode_1	, "SINGLE_DAY_MONTH"	, _TL("Month"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("January"),
+			_TL("February"),
+			_TL("March"),
+			_TL("April"),
+			_TL("May"),
+			_TL("June"),
+			_TL("July"),
+			_TL("August"),
+			_TL("September"),
+			_TL("October"),
+			_TL("November"),
+			_TL("December")
+		), 2
+	);
+
+
+	//-----------------------------------------------------
+	// Range of Days...
+
+	pNode_1	= Parameters.Add_Node(
+		pNode_0	, "NODE_DAY_RANGE"		, _TL("Range of Days"),
+		_TL("")
+	);
+
+	pNode_2	= Parameters.Add_Range(
+		pNode_1	, "DAY_RANGE"			, _TL("Time Span [day of year]"),
+		_TL(""),
+		   1	, 31,
+		-365	, true,
+		 366	, true
+	);
+
+	pNode_2	= Parameters.Add_Value(
+		pNode_1	, "DAY_STEP"			, _TL("Time Step [number of days]"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 5,
+		1		, true,
+		100		, true
+	);
+}
+
+//---------------------------------------------------------
+CSolarRadiation::~CSolarRadiation(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSolarRadiation::On_Execute(void)
+{
+	static const int	Month2Day[12]	= {	0, 31, 49, 80, 109, 140, 170, 201, 232, 272, 303, 333 };
+
+	//-----------------------------------------------------
+	int			Day_Step, Day_Start, Day_Stop;
+	double		Latitude, Hour_Step, Hour_Start, Hour_Stop;
+	CSG_Colors	Colors;
+
+	//-----------------------------------------------------
+	m_pDTM			= Parameters("ELEVATION")	->asGrid();
+	m_pRadiation	= Parameters("INSOLAT")		->asGrid();
+	m_pDuration		= Parameters("DURATION")	->asGrid();
+
+	m_SolarConstant	= Parameters("SOLCONST")	->asDouble() / 1000.0;	// [kW / m²]
+
+	m_Method		= Parameters("METHOD")		->asInt();
+	m_Transmittance	= Parameters("TRANSMITT")	->asDouble() / 100.0;
+	m_Pressure		= Parameters("PRESSURE")	->asDouble();
+	m_Water			= Parameters("WATER")		->asDouble();
+	m_Dust			= Parameters("DUST")		->asDouble();
+
+	Latitude		= Parameters("LATITUDE")	->asDouble() * M_DEG_TO_RAD;
+
+	Day_Step		= Parameters("DAY_STEP")	->asInt();
+	Hour_Step		= Parameters("HOUR_STEP")	->asDouble();
+	Hour_Start		= Parameters("HOUR_RANGE")	->asRange()->Get_LoVal();
+	Hour_Stop		= Parameters("HOUR_RANGE")	->asRange()->Get_HiVal();
+
+	//-----------------------------------------------------
+	m_pSum			= SG_Create_Grid(m_pDTM);
+
+	//-----------------------------------------------------
+	switch( Parameters("TIMESPAN")->asInt() )
+	{
+	case 0:	// single day...
+		Day_Start		= Parameters("SINGLE_DAY_MONTH")->asInt();
+		Day_Start		= Parameters("SINGLE_DAY_DAY")	->asInt() + (Day_Start >= 0 && Day_Start < 12 ? Month2Day[Day_Start] : 0);
+
+		Execute_DailySum (Latitude, Hour_Step, Hour_Start, Hour_Stop, Day_Start);
+		break;
+
+	case 1:	// range of days...
+		Day_Start		= (int)Parameters("DAY_RANGE")	->asRange()->Get_LoVal() - 1;
+		Day_Stop		= (int)Parameters("DAY_RANGE")	->asRange()->Get_HiVal() - 1;
+
+		Execute_SumOfDays(Latitude, Hour_Step, Hour_Start, Hour_Stop, Day_Step, Day_Start, Day_Stop);
+		break;
+
+	case 2:	// one year...
+		Day_Start		= -10;	// winter solstitute...
+		Day_Stop		= 173;	// until half year has passed...
+
+		Execute_SumOfDays(Latitude, Hour_Step, Hour_Start, Hour_Stop, Day_Step, Day_Start, Day_Stop);
+
+		*m_pRadiation	*= 2.0;	// two times...
+		*m_pDuration	*= 2.0;	// two times...
+		break;
+	}
+
+	//-----------------------------------------------------
+	delete( m_pSum );
+
+	Colors.Set_Count(100);
+	Colors.Set_Ramp(SG_GET_RGB(  0,   0,  64), SG_GET_RGB(255, 159,   0),  0, 50);
+	Colors.Set_Ramp(SG_GET_RGB(255, 159,   0), SG_GET_RGB(255, 255, 255), 50, 99);
+
+	DataObject_Set_Colors(m_pRadiation, Colors);
+	DataObject_Set_Colors(m_pDuration , Colors);
+
+	m_pDuration->Set_Unit(_TL("h"));
+
+	if( Parameters("UNIT")->asInt() == 1 )	// Joule...
+	{
+		*m_pRadiation	*= 10.0 / 36.0;	// 1 J = 1 Ws = 1/(60*60) Wh = 1/3600 Wh >> 1 J = 1000/3600 kWh = 10/36 kWh
+
+		m_pRadiation->Set_Unit(_TL("J/m\xc2\xb2"));
+	}
+	else
+	{
+		m_pRadiation->Set_Unit(_TL("kWh/m\xc2\xb2"));
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSolarRadiation::Execute_DailySum(double Latitude_RAD, double Hour_Step, double Hour_Start, double Hour_Stop, int Day)
+{
+	Get_DailySum(Latitude_RAD, Hour_Step, Hour_Start, Hour_Stop, Day);
+
+	m_pRadiation->Assign(m_pSum);
+}
+
+//---------------------------------------------------------
+void CSolarRadiation::Execute_SumOfDays(double Latitude_RAD, double Hour_Step, double Hour_Start, double Hour_Stop, int Day_Step, int Day_Start, int Day_Stop)
+{
+	int		Day, nDays;
+	CSG_Grid	*pSumOfDays, *pDur_Total;
+
+	//-----------------------------------------------------
+	nDays	= Day_Stop - Day_Start;
+
+	if( nDays < 1 )
+	{
+		Execute_DailySum(Latitude_RAD, Hour_Step, Hour_Start, Hour_Stop, Day_Start);
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		pSumOfDays		= SG_Create_Grid(m_pDTM);
+		pDur_Total		= SG_Create_Grid(m_pDTM);
+
+		if( Day_Step < 1 || Day_Step > nDays )
+		{
+			Day_Step		= 1;
+		}
+
+		//-------------------------------------------------
+		for(Day=Day_Start; Day<Day_Stop && Set_Progress(Day - Day_Start, nDays); Day+=Day_Step)
+		{
+			Get_DailySum(Latitude_RAD, Hour_Step, Hour_Start, Hour_Stop, Day, false);
+
+			*m_pSum			*= Day_Step;
+			*pSumOfDays		+= *m_pSum;
+
+			*m_pDuration	*= Day_Step;
+			*pDur_Total		+= *m_pDuration;
+		}
+
+		if( (Day_Step = Day_Stop - Day) > 0 )	// Rest...
+		{
+			Get_DailySum(Latitude_RAD, Hour_Step, Hour_Start, Hour_Stop, Day, false);
+
+			*m_pSum			*= Day_Step;
+			*pSumOfDays		+= *m_pSum;
+
+			*m_pDuration	*= Day_Step;
+			*pDur_Total		+= *m_pDuration;
+		}
+
+		//-------------------------------------------------
+		m_pRadiation	->Assign(pSumOfDays);
+		delete(pSumOfDays);
+
+		m_pDuration		->Assign(pDur_Total);
+		delete(pDur_Total);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Daily Sum						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSolarRadiation::Get_DailySum(double Latitude_RAD, double Hour_Step, double Hour_Start, double Hour_Stop, int Day, bool bProgressBar)
+{
+	bool		bNight;
+	double		time, Sol_Height, Sol_Azimuth, Solar_Angle, RDIRN, RDIFN, d;
+	CHillShade	HillShade;
+
+	//-----------------------------------------------------
+	Day			%= 366;
+
+	if( Day < 0 )
+	{
+		Day		+= 366;
+	}
+
+	Hour_Start	+= Hour_Step / 2.0;
+
+	m_pSum		->Assign(0.0);
+	m_pDuration	->Assign(0.0);
+
+	HillShade.Get_Parameters()->Set_Parameter(SG_T("ELEVATION")		, PARAMETER_TYPE_Grid	, m_pDTM);
+	HillShade.Get_Parameters()->Set_Parameter(SG_T("SHADE")			, PARAMETER_TYPE_Grid	, m_pRadiation);
+	HillShade.Get_Parameters()->Set_Parameter(SG_T("METHOD")		, PARAMETER_TYPE_Choice	, 3);
+	HillShade.Get_Parameters()->Set_Parameter(SG_T("EXAGGERATION")	, PARAMETER_TYPE_Double	, 1.0);
+	HillShade.Set_Show_Progress(false);
+
+	//-----------------------------------------------------
+	for(time=Hour_Start, bNight=false; time<Hour_Stop && is_Progress(); time+=Hour_Step)
+	{
+		Process_Set_Text(CSG_String::Format(_TL("%d. Day of Year, Local Time: %dh %02dm"), Day + 1, (int)time, (int)(60.0 * fmod(time, 1.0))));
+
+		if( bProgressBar )
+		{
+			Set_Progress(time, 24.0);
+		}
+		else
+		{
+			Process_Get_Okay(false);
+		}
+
+		//-------------------------------------------------
+		if( Get_SolarPosition(Day, time, Latitude_RAD, 0.0, Sol_Azimuth, Sol_Height, false) )
+		{
+			bNight	= false;
+
+			HillShade.Get_Parameters()->Set_Parameter(SG_T("AZIMUTH")		, PARAMETER_TYPE_Double, (double)M_RAD_TO_DEG * Sol_Azimuth);
+			HillShade.Get_Parameters()->Set_Parameter(SG_T("DECLINATION")	, PARAMETER_TYPE_Double, (double)M_RAD_TO_DEG * Sol_Height);
+			HillShade.Execute();
+
+			for(int n=0; n<Get_NCells(); n++)
+			{
+				if( m_pRadiation->is_NoData(n) )
+				{
+					m_pSum		->Set_NoData(n);
+					m_pDuration	->Set_NoData(n);
+				}
+				else
+				{
+					Solar_Angle	= m_pRadiation->asDouble(n);
+
+					if( Solar_Angle < M_PI_090 )
+					{
+						Get_SolarCorrection(M_PI_090 - Sol_Height, m_pDTM->asDouble(n), RDIRN, RDIFN);
+
+						d	= m_SolarConstant * Hour_Step * RDIRN * cos(Solar_Angle);
+						// Dir[q,a] = SConst * SunDuration[q,a] * t^m(q) * cos(AngIn[q,a]) 
+
+						m_pSum		->Add_Value(n, d);
+						m_pDuration	->Add_Value(n, Hour_Step);
+					}
+				}
+			}
+
+			if( Parameters("UPDATE")->asBool() )
+			{
+				DataObject_Update(m_pRadiation, 20 * M_DEG_TO_RAD, 90.0 * M_DEG_TO_RAD, true);
+			}
+		}
+
+		//-------------------------------------------------
+		else if( !bNight )
+		{
+			bNight	= true;
+
+			if( Parameters("UPDATE")->asBool() )
+			{
+				m_pRadiation->Assign(M_PI_090);
+
+				DataObject_Update(m_pRadiation, 0, 90.0 * M_DEG_TO_RAD, true);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Atmosphere						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSolarRadiation::Get_SolarCorrection(double ZenithAngle, double Elevation, double &RDIRN, double &RDIFN)
+{
+	const double	AM[32]	=	// AM    Optical air mass in 1 degree increments for zenith angles >=60 [after LIST, 1968; p. 422]
+	{
+		 2.00,  2.06,  2.12,  2.19,  2.27,  2.36,  2.45,  2.55,
+		 2.65,  2.77,  2.90,  3.05,  3.21,  3.39,  3.59,  3.82,
+		 4.07,  4.37,  4.72,  5.12,  5.60,  6.18,  6.88,  7.77,
+		 8.90, 10.39, 12.44, 15.36, 19.79, 26.96, 26.96, 26.96
+	};
+
+	const double	Pressure_0	= 1013.0;	// Standard atmospheric pressure = 1013 mb
+
+	int		i;
+	double	z, AMASS, AMASS2, AW, TW, TD, TDC;
+
+	//-----------------------------------------------------
+	z		= M_RAD_TO_DEG * ZenithAngle;
+
+	if( z <= 60.0 )
+	{
+		AMASS	= 1.0 / cos(ZenithAngle);
+	}
+	else
+	{
+		z		-= 60.0;
+		i		= (int)z;
+		AMASS	= AM[i] + (z - i) * (AM[i + 1] - AM[i]);
+	}
+
+	z		= m_Pressure / pow(10.0, Elevation * 5.4667E-05);	// P     Barometric pressure in mb
+	AMASS2	= AMASS * z / Pressure_0;
+
+	//-----------------------------------------------------
+	switch( m_Method )
+	{
+	case 0:	default:
+		RDIRN	= pow(m_Transmittance, AMASS2);
+		RDIFN	= 0.271 - 0.294 * RDIRN;
+		break;
+
+	case 1:
+		AW		= 1.0 - 0.077 * pow(m_Water * AMASS2, 0.3);		// AW    Accounts for absorption by water vapour
+		TW		= pow(0.975, m_Water * AMASS);					// TW    Accounts for scattering by water vapour
+		TD		= pow(0.950, m_Water * m_Dust / 100.0);			// TD    Accounts for scattering by dust
+		TDC		= pow(0.900, AMASS2) + 0.026 * (AMASS2 - 1.0);	// TDC   Accounts for scattering by a dust free atmosphere
+
+		RDIRN	= AW * TW * TD * TDC;
+		RDIFN	= 0.5 * (AW - RDIRN);
+		break;
+	}
+
+	// Optical Pathlength (solar zenith angle < 80Degree) =>
+	// m(t)		= exp(-0.000118 * Elevation - 1.638 * 10e-9 * Elevation) / cos(SolarZenithAngle)
+	// if( Method == 2 && Zenithangle < 80 )	// nach bla...
+	// RDIRN	= pow(m_Transmittance, exp((-0.000118 - 1.638e-8 * Elevation) * Elevation) / cos(ZenithAngle));
+}
+
+/* The original TAPES-G source code for the optical air mass computation
+C ==================================================================
+      SUBROUTINE SOLAR(ZA,RDIRN,RDIFN,ITEST)
+      COMMON/SOL1/U,D,P,TRANSM
+      PARAMETER (PI=3.14159265358979323846)
+      PARAMETER (DTOR=PI/180.)
+      DIMENSION AM(32)
+      DATA AM/2.0,2.06,2.12,2.19,2.27,2.36,2.45,2.55,2.65,2.77,2.9,
+     *  3.05,3.21,3.39,3.59,3.82,4.07,4.37,4.72,5.12,5.6,6.18,6.88,
+     *  7.77,8.9,10.39,12.44,15.36,19.79,26.96,26.96,26.96/
+      DATA PO/1013./
+C     ***************************************************************
+C     AM    Optical air mass in 1 degree increments for zenith angles
+C           >=60 [LIST, 1968; p. 422]
+C     U     Water content of a vertical slice of atmosphere in cm: 
+C           1.5 to 1.7, average=1.68
+C     D     Dust factor: 1=100 ppm (standard); 2=300 ppm
+C     P     Barometric pressure in mb
+C     PO    Standard atmospheric pressure = 1013 mb
+C     TRANSM  Transmittance of the atmosphere (0.6-0.8)
+C     AW    Accounts for absorption by water vapour
+C     TW    Accounts for scattering by water vapour
+C     TD    Accounts for scattering by dust
+C     TDC   Accounts for scattering by a dust free atmosphere
+C     **************************************************************
+C     Compute optical air mass
+C
+      IF(ZA.LE.60.) THEN
+         AMASS=1./COS(ZA*DTOR)
+      ELSE
+         Y=ZA-59.
+         I=INT(Y)
+         AMASS=AM(I)+(Y-FLOAT(I))*(AM(I+1)-AM(I))
+      ENDIF
+      AMASS2=AMASS*P/PO
+C     --------------------------------------------------------------
+C     Account for atmospheric effects using either a lumped atmos-
+C     pheric transmittance approach (ITEST=1) or by calculating the
+C     components (ITEST=2)
+C
+      IF(ITEST.EQ.1) THEN
+         RDIRN=TRANSM**AMASS2
+         RDIFN=0.271-0.294*RDIRN
+      ELSE
+         AW=1.0-0.077*(U*AMASS2)**0.3
+         TW=0.975**(U*AMASS)
+         TD=0.95**(U*D)
+         TDC=0.9**AMASS2+0.026*(AMASS2-1.0)
+         RDIRN=AW*TW*TD*TDC
+         RDIFN=0.5*(AW-RDIRN)
+      ENDIF
+      RETURN
+      END
+C ====================================================================*/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Solar Position						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSolarRadiation::Get_SolarPosition(int Day, double Time, double LAT, double LON, double &Azimuth, double &Declination, bool bDegree)
+{
+	static const int	Day2Month[13]	= {	0, 31, 49, 80, 109, 140, 170, 201, 232, 272, 303, 333, 366 };
+
+	static const double	ECLIPTIC_OBL	= M_DEG_TO_RAD * 23.43999;	// obliquity of ecliptic
+
+	int		i;
+
+	double	JD, T, M, L, X, Y, Z, R, UTime,
+			DEC, RA, theta, tau,
+			Month, Year		= 2000;
+
+	//-----------------------------------------------------
+
+	for(Month=1, i=0; i<=12; i++)
+	{
+		if( Day < Day2Month[i] )
+		{
+			Month	= i;
+			Day		-= Day2Month[i - 1];
+			break;
+		}
+	}
+
+	if( Month < 1 || Month > 12 )	// nur Tag (1 - 365) zaehlt...
+	{
+		Month		= 1;
+	}
+
+	if( Month <= 2 )
+	{
+		Month		+= 12;
+		Year		-= 1;
+	}
+
+
+	//-----------------------------------------------------
+
+//	UTime		= Time - LON * 12.0 / M_PI;
+	UTime		= Time;
+
+
+	//-----------------------------------------------------
+	// 1. Julian Date...
+
+	JD			= (int)(365.25 * Year) + (int)(30.6001 * (Month + 1)) - 15 + 1720996.5 + Day + UTime / 24.0;
+	T			= (JD - 2451545.0 ) / 36525.0;	// number of Julian centuries since 2000/01/01 at 12 UT (JD = 2451545.0)
+
+
+	//-----------------------------------------------------
+	// 2. Solar Coordinates (according to: Jean Meeus: Astronomical Algorithms), accuracy of 0.01 degree
+
+	M			= M_DEG_TO_RAD * (357.52910 + 35999.05030 * T - 0.0001559 * T * T - 0.00000048 * T * T * T);	// mean anomaly
+	L			= M_DEG_TO_RAD * (	(280.46645 + 36000.76983 * T + 0.0003032 * T * T)						// mean longitude
+							+	(	(1.914600 - 0.004817 * T - 0.000014  * T * T) * sin(M)
+								+	(0.019993 - 0.000101 * T) * sin(2 * M) + 0.000290 * sin(3 * M)		// true longitude
+								)
+							);
+
+
+	//-----------------------------------------------------
+	// 3. convert ecliptic longitude to right ascension RA and declination delta
+
+	X			= cos(L);
+	Y			= cos(ECLIPTIC_OBL) * sin(L);
+	Z			= sin(ECLIPTIC_OBL) * sin(L);
+	R			= sqrt(1.0 - Z*Z); 
+
+	DEC			= atan2(Z, R);
+	RA			= 2 * atan2(Y, (X + R));
+
+
+	//-----------------------------------------------------
+	// 4. compute sidereal time (degree) at Greenwich local sidereal time at longitude (DegreeE)
+
+	theta		= LON + M_DEG_TO_RAD * (280.46061837 + 360.98564736629 * (JD - 2451545.0) + T * T * (0.000387933 - T / 38710000.0));
+
+
+	//-----------------------------------------------------
+	// 5. compute local hour angle (degree)
+
+	tau			= theta - RA;
+
+
+	//-----------------------------------------------------
+	// 6. convert (tau, delta) to horizon coordinates (h, az) of the observer
+
+	Declination	= asin( sin(LAT) * sin(DEC) + cos(LAT) * cos(DEC) * cos(tau) );
+	Azimuth		= atan2( -sin(tau) * cos(DEC), cos(LAT) * sin(DEC) - sin(LAT) * cos(DEC) * cos(tau) );
+	//Azimuth	= atan2( -sin(Tau), cos(LAT) * tan(DEC) - sin(LAT) * cos(Tau) );	// erstere ist besser wegen division by zero effects...
+
+	if( bDegree )
+	{
+		Declination	*= M_RAD_TO_DEG;
+		Azimuth		*= M_RAD_TO_DEG;
+	}
+
+	return( Declination >= 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/SolarRadiation.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   SolarRadiation.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SolarRadiation_H
+#define HEADER_INCLUDED__SolarRadiation_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_lighting_EXPORT CSolarRadiation : public CSG_Module_Grid
+{
+public:
+	CSolarRadiation(void);
+	virtual ~CSolarRadiation(void);
+
+
+protected:
+
+	virtual bool		On_Execute				(void);
+
+
+private:
+
+	int					m_Method;
+
+	double				m_SolarConstant, m_Transmittance, m_Pressure, m_Water, m_Dust;
+
+	CSG_Grid				*m_pDTM, *m_pSum, *m_pRadiation, *m_pDuration;
+
+
+	void				Execute_DailySum		(double Latitude_RAD, double Hour_Step, double Hour_Start, double Hour_Stop, int Day);
+	void				Execute_SumOfDays		(double Latitude_RAD, double Hour_Step, double Hour_Start, double Hour_Stop, int Day_Step, int Day_Start, int Day_Stop);
+
+	void				Get_DailySum			(double Latitude_RAD, double Hour_Step, double Hour_Start, double Hour_Stop, int Day, bool bProgressBar = true);
+
+	void				Get_SolarCorrection		(double ZenithAngle, double Elevation, double &RDIRN, double &RDIFN);
+
+	bool				Get_SolarPosition		(int Day, double Time, double LAT, double LON, double &Azimuth, double &Declination, bool bDegree = true);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SolarRadiation_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,340 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Visibility_Point.cpp                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Visibility_Point.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVisibility_Point::CVisibility_Point(void)
+{
+	Set_Name(_TL("Visibility (single point)"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description(
+		_TL("")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "VISIBILITY"	, _TL("Visibility"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "HEIGHT"		, _TL("Height"),
+		_TL("Height of the light source above ground."),
+		PARAMETER_TYPE_Double, 100.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Unit"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			_TL("Visibility"),
+			_TL("Shade"),
+			_TL("Distance"),
+			_TL("Size")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CVisibility_Point::~CVisibility_Point(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVisibility_Point::On_Execute(void)
+{
+	CSG_Colors	Colors;
+
+	m_pDTM			= Parameters("ELEVATION")	->asGrid();
+	m_pVisibility	= Parameters("VISIBILITY")	->asGrid();
+	m_Height		= Parameters("HEIGHT")		->asDouble();
+	m_Method		= Parameters("METHOD")		->asInt();
+
+	switch( m_Method )
+	{
+	case 0:		// Visibility
+		m_pVisibility->Set_ZFactor(1.0);
+		Colors.Set_Count(2);
+		Colors.Set_Ramp(SG_GET_RGB(0, 0, 0), SG_GET_RGB(255, 255, 255));
+		break;
+
+	case 1:		// Shade
+		m_pVisibility->Set_ZFactor(M_RAD_TO_DEG);
+		Colors.Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB(0, 0, 0));
+		break;
+
+	case 2:		// Distance
+		m_pVisibility->Set_ZFactor(1.0);
+		Colors.Set_Ramp(SG_GET_RGB(255, 255, 191), SG_GET_RGB(0, 95, 0));
+		break;
+
+	case 3:		// Size
+		m_pVisibility->Set_ZFactor(M_RAD_TO_DEG);
+		Colors.Set_Ramp(SG_GET_RGB(0, 95, 0), SG_GET_RGB(255, 255, 191));
+		break;
+	}
+
+	DataObject_Set_Colors(m_pVisibility, Colors);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CVisibility_Point::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	int		x, y, x_Pos, y_Pos;
+
+	double	z_Pos,
+			aziDTM, decDTM,
+			aziSrc, decSrc,
+			d, dx, dy, dz,
+			Exaggeration	= 1.0;
+
+	//-----------------------------------------------------
+	if(	Mode != MODULE_INTERACTIVE_LDOWN
+	||	!m_pDTM->is_InGrid_byPos(Get_xPosition(), Get_yPosition()) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	x_Pos	= Get_xGrid();
+	y_Pos	= Get_yGrid();;
+	z_Pos	= m_pDTM->asDouble(x_Pos, y_Pos) + m_Height;
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDTM->is_NoData(x, y) )
+			{
+				m_pVisibility->Set_NoData(x, y);
+			}
+			else
+			{
+				dx		= x_Pos - x;
+				dy		= y_Pos - y;
+				dz		= z_Pos - m_pDTM->asDouble(x, y);
+
+				//-----------------------------------------
+				if( Trace_Point(x, y, dx, dy, dz) )
+				{
+					switch( m_Method )
+					{
+					case 0:		// Visibility
+						m_pVisibility->Set_Value(x, y, 1);
+						break;
+
+					case 1:		// Shade
+						m_pDTM->Get_Gradient(x, y, decDTM, aziDTM);
+						decDTM	= M_PI_090 - atan(Exaggeration * tan(decDTM));
+
+						decSrc	= atan2(dz, sqrt(dx*dx + dy*dy));
+						aziSrc	= atan2(dx, dy);
+
+						d		= acos(sin(decDTM) * sin(decSrc) + cos(decDTM) * cos(decSrc) * cos(aziDTM - aziSrc));
+
+						m_pVisibility->Set_Value(x, y, d < M_PI_090 ? d : M_PI_090);
+						break;
+
+					case 2:		// Distance
+						m_pVisibility->Set_Value(x, y, Get_Cellsize() * sqrt(dx*dx + dy*dy));
+						break;
+
+					case 3:		// Size
+						if( (d = Get_Cellsize() * sqrt(dx*dx + dy*dy)) > 0.0 )
+						{
+							m_pVisibility->Set_Value(x, y, atan2(m_Height, d));
+						}
+						else
+						{
+							m_pVisibility->Set_NoData(x, y);
+						//	m_pVisibility->Set_Value(x, y, 0);
+						}
+						break;
+					}
+				}
+
+				//-----------------------------------------
+				else
+				{
+					switch( m_Method )
+					{
+					case 0:		// Visibility
+						m_pVisibility->Set_Value(x, y, 0);
+						break;
+
+					case 1:		// Shade
+						m_pVisibility->Set_Value(x, y, M_PI_090);
+						break;
+
+					case 2:		// Distance
+					case 3:		// Size
+						m_pVisibility->Set_NoData(x, y);
+						break;
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	switch( m_Method )
+	{
+	case 0:		// Visibility
+		DataObject_Update(m_pVisibility, 0.0, 1.0, true);
+		break;
+
+	case 1:		// Shade
+		DataObject_Update(m_pVisibility, 0.0, M_PI_090, true);
+		break;
+
+	case 2:		// Distance
+	case 3:		// Size
+		DataObject_Update(m_pVisibility, true);
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CVisibility_Point::Trace_Point(int x, int y, double dx, double dy, double dz)
+{
+	double	ix, iy, iz, id, d, dist;
+
+	d		= fabs(dx) > fabs(dy) ? fabs(dx) : fabs(dy);
+
+	if( d > 0 )
+	{
+		dist	= sqrt(dx*dx + dy*dy);
+
+		dx		/= d;
+		dy		/= d;
+		dz		/= d;
+
+		d		= dist / d;
+
+		id		= 0.0;
+		ix		= x + 0.5;
+		iy		= y + 0.5;
+		iz		= m_pDTM->asDouble(x, y);
+
+		while( id < dist )
+		{
+			id	+= d;
+
+			ix	+= dx;
+			iy	+= dy;
+			iz	+= dz;
+
+			x	= (int)ix;
+			y	= (int)iy;
+
+			if( !is_InGrid(x, y) )
+			{
+				return( true );
+			}
+			else if( iz < m_pDTM->asDouble(x, y) )
+			{
+				return( false );
+			}
+			else if( iz > m_pDTM->Get_ZMax() )
+			{
+				return( true );
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/Visibility_Point.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Visibility_Point.h                  //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Visibility_Point_H
+#define HEADER_INCLUDED__Visibility_Point_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVisibility_Point : public CSG_Module_Grid_Interactive
+{
+public:
+	CVisibility_Point(void);
+	virtual ~CVisibility_Point(void);
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+	virtual bool			On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	int						m_Method;
+
+	double					m_Height;
+
+	CSG_Grid					*m_pDTM, *m_pVisibility;
+
+
+	bool					Trace_Point			(int x, int y, double dx, double dy, double dz);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Visibility_Point_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,352 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               topographic_correction.cpp              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "topographic_correction.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CTopographic_Correction::CTopographic_Correction(void)
+{
+	CSG_Parameter	*pNode;
+
+	//-----------------------------------------------------
+	Set_Name		(_TL("Topographic Correction"));
+
+	Set_Author		(_TL("Copyrights (c) 2008 by Olaf Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+		"References:\n"
+		"Civco, D. L. (1989): "
+		"'Topographic Normalization of Landsat Thematic Mapper Digital Imagery', "
+		"Photogrammetric Engineering and Remote Sensing, 55(9), pp.1303-1309.\n"
+		"\n"
+		"Law, K.H., Nichol, J. (2004): "
+		"'Topographic Correction for Differential Illumination Effects on Ikonos Satellite Imagery', "
+		"ISPRS 2004 International Society for Photogrammetry and Remote Sensing, "
+		"<a href=\"http://www.cartesia.org/geodoc/isprs2004/comm3/papers/347.pdf\">pdf</a>.\n"
+		"\n"
+		"Phua, M.-H., Saito, H. (2003): "
+		"'Estimation of biomass of a mountainous tropical forest using Landsat TM data', "
+		"Canadian Journal of Remote Sensing, 29(4), pp.429-440.\n"
+		"\n"
+		"Riano, D., Chuvieco, E. Salas, J., Aguado, I. (2003): "
+		"'Assessment of Different Topographic Corrections in Landsat-TM Data for Mapping Vegetation Types', "
+		"IEEE Transactions on Geoscience and Remote Sensing, 41(5), pp.1056-1061, "
+		"<a href=\"http://www.geogra.uah.es/~emilio/pdf/Riano2003b.pdf\">pdf</a>.\n"
+		"\n"
+		"Teillet, P.M., Guindon, B., Goodenough, D.G. (1982): "
+		"'On the slope-aspect correction of multispectral scanner data', "
+		"Canadian Journal of Remote Sensing, 8(2), pp.1537-1540.\n"
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ORIGINAL"	, _TL("Original Image"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CORRECTED"	, _TL("Corrected Image"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	pNode	= Parameters.Add_Node(NULL, "NODE_SOLAR", _TL("Solar Position"), _TL(""));
+
+	Parameters.Add_Value(
+		pNode	, "AZI"			, _TL("Azimuth [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 180.0, 0.0, true, 360.0, true
+	);
+
+	Parameters.Add_Value(
+		pNode	, "DEC"			, _TL("Declination [Degree]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	,  45.0, 0.0, true,  90.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"),
+			_TL("Cosine Correction (Teillet et al. 1982)"),
+			_TL("Cosine Correction (Civco 1989)"),
+			_TL("Minnaert Correction"),
+			_TL("Minnaert Correction with Slope (Riano et al. 2003)"),
+			_TL("Minnaert Correction with Slope (Law & Nichol 2004)"),
+			_TL("C Correction")
+		), 4
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MINNAERT"	, _TL("Minnaert Correction"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.5, 0.0, true, 1.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MAXCELLS"	, _TL("Maximum Cells (C Correction Analysis)"),
+		_TL("Maximum number of grid cells used for trend analysis as required by C correction."),
+		PARAMETER_TYPE_Int		, 1000.0, 10.0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTopographic_Correction::On_Execute(void)
+{
+	//-----------------------------------------------------
+	if( Initialise() )
+	{
+		Process_Set_Text(_TL("topographic correction"));
+
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( !m_pOriginal->is_NoData(x, y) )
+				{
+					if( !m_Incidence.is_NoData(x, y) )
+					{
+						m_pCorrected->Set_Value(x, y, Get_Correction(
+							m_Slope		.asDouble(x, y),
+							m_Incidence	.asDouble(x, y),
+							m_pOriginal->asDouble(x, y)
+						));
+					}
+					else
+					{
+						m_pCorrected->Set_Value(x, y, m_pOriginal->asDouble(x, y));
+					}
+				}
+				else
+				{
+					m_pCorrected->Set_NoData(x, y);
+				}
+			}
+		}
+
+		return( Finalise() );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CTopographic_Correction::Initialise(void)
+{
+	int			x, y;
+	double		Azimuth, Declination, Slope, Aspect;
+	CSG_Grid	*pDEM;
+
+	//-----------------------------------------------------
+	Azimuth			= Parameters("AZI")			->asDouble() * M_DEG_TO_RAD;
+	Declination		= Parameters("DEC")			->asDouble() * M_DEG_TO_RAD;
+	m_cosDec		= cos(Declination);
+	m_sinDec		= sin(Declination);
+
+	m_Minnaert		= Parameters("MINNAERT")	->asDouble();
+	m_Method		= Parameters("METHOD")		->asInt();
+
+	pDEM			= Parameters("DEM")			->asGrid();
+	m_pOriginal		= Parameters("ORIGINAL")	->asGrid();
+	m_pCorrected	= Parameters("CORRECTED")	->asGrid();
+
+	m_pCorrected->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pOriginal->Get_Name(), _TL("Topographic Correction")));
+
+	m_Slope		.Create(*Get_System());
+	m_Incidence	.Create(*Get_System());
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("incidence calculation"));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDEM->Get_Gradient(x, y, Slope, Aspect) )
+			{
+				m_Slope		.Set_Value(x, y, Slope);
+				m_Incidence	.Set_Value(x, y, cos(Slope) * m_sinDec + sin(Slope) * m_cosDec * cos(Aspect - Azimuth));
+			}
+			else
+			{
+				m_Slope		.Set_NoData(x, y);
+				m_Incidence	.Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_Method == 5 )	// C Correction
+	{
+		Process_Set_Text(_TL("regression analysis"));
+
+		CSG_Regression	R;
+
+		int	n		= Parameters("MAXCELLS")->asInt();
+		int	nStep	= Get_NCells() < n ? 1 : (int)(Get_NCells() / n);
+
+		for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n+=nStep)
+		{
+			R.Add_Values(m_pOriginal->asDouble(n), m_Incidence.asDouble(n));
+		}
+
+		if( !R.Calculate() || !R.Get_Constant() )
+		{
+			Finalise();
+
+			return( false );
+		}
+
+		m_C	= R.Get_Coefficient() / R.Get_Constant();
+
+		Message_Add(R.asString());
+	}
+
+	if( m_Method == 6 )	// Normalization (after Civco, modified by Law & Nichol)
+	{
+		m_C	= 1.0;
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CTopographic_Correction::Finalise(void)
+{
+	m_Slope		.Destroy();
+	m_Incidence	.Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CTopographic_Correction::Get_Correction(double Slope, double Incidence, double Value)
+{
+	switch( m_Method )
+	{
+	case 0:	// Cosine Correction (Teillet et al. 1982)
+		return( Value * m_sinDec / Incidence );
+
+	case 1:	// Cosine Correction (Civco 1989)
+		return( Value + (Value * ((m_Incidence.Get_ArithMean() - Incidence) / m_Incidence.Get_ArithMean())) );
+
+	case 2:	// Minnaert Correction
+		return( Value * pow(m_sinDec / Incidence, m_Minnaert) );
+
+	case 3:	// Minnaert Correction with Slope (Riano et al. 2003)
+		return( Value * cos(Slope) * pow(m_sinDec / (Incidence * cos(Slope)), m_Minnaert) );
+
+	case 4:	// Minnaert Correction with Slope (Law & Nichol 2004)
+		return( Value * cos(Slope) / pow(Incidence * cos(Slope), m_Minnaert) );
+
+	case 5:	// C Correction
+		return( Value * (m_sinDec + m_C) / (Incidence + m_C) );
+
+	case 6:	// Normalization
+		return( Value + ((Value * ((m_Incidence.Get_ArithMean() - Incidence) / m_Incidence.Get_ArithMean())) * m_C) );
+	}
+
+	return( Value );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/topographic_correction.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                topographic_correction.h               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__topographic_correction_H
+#define HEADER_INCLUDED__topographic_correction_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CTopographic_Correction : public CSG_Module_Grid
+{
+public:
+	CTopographic_Correction(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	int							m_Method;
+
+	double						m_Minnaert, m_cosDec, m_sinDec, m_C;
+
+	CSG_Grid					*m_pOriginal, *m_pCorrected, m_Slope, m_Incidence;
+
+
+	bool						Initialise				(void);
+	bool						Finalise				(void);
+
+	double						Get_Correction			(double Slope, double Incidence, double Value);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__topographic_correction_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,428 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     View_Shed.cpp                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_shed.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CView_Shed::CView_Shed(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Sky View Factor"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+		"\n"
+		"References:\n"
+		"Boehner, J., Antonic, O. (2008): "
+		"'Land-suface parameters specific to topo-climatology'. "
+		"in: Hengl, T., Reuter, H. (Eds.): 'Geomorphometry - Concepts, Software, Applications', in press\n"
+		"\n"
+		"Hantzschel, J., Goldberg, V., Bernhofer, C. (2005): "
+		"'GIS-based regionalisation of radiation, temperature and coupling measures in complex terrain for low mountain ranges'. "
+		"Meteorological Applications, V.12:01, p.33–42, doi:10.1017/S1350482705001489\n"
+		"\n"
+		"Oke, T.R. (2000): "
+		"'Boundary Layer Climates'. "
+		"Taylor & Francis, New York. 435pp.\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "VISIBLE"		, _TL("Visible Sky"),
+		_TL("The unobstructed hemisphere given as percentage."),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SVF"			, _TL("Sky View Factor"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SIMPLE"		, _TL("Sky View Factor (Simplified)"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "TERRAIN"		, _TL("Terrain View Factor"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MAXRADIUS"	, _TL("Maximum Search Radius"),
+		_TL("This value is ignored if set to zero."),
+		PARAMETER_TYPE_Double	, 10000.0, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("multi scale"),
+			_TL("sectors")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LEVEL_INC"	, _TL("Multi Scale Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 3.0, 1.25, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "NDIRS"		, _TL("Number of Sectors"),
+		_TL(""),
+		PARAMETER_TYPE_Int	, 8.0, 3, true
+	);
+}
+
+//---------------------------------------------------------
+CView_Shed::~CView_Shed(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CView_Shed::On_Execute(void)
+{
+	bool		bResult	= false;
+	int			nDirections;
+	double		Visible, SVF, Simple, Terrain, Level_Inc;
+	CSG_Grid	*pVisible, *pSVF, *pSimple, *pTerrain;
+
+	m_pDEM		= Parameters("DEM")			->asGrid();
+
+	pVisible	= Parameters("VISIBLE")		->asGrid();
+	pSVF		= Parameters("SVF")			->asGrid();
+	pSimple		= Parameters("SIMPLE")		->asGrid();
+	pTerrain	= Parameters("TERRAIN")		->asGrid();
+
+	m_MaxRadius	= Parameters("MAXRADIUS")	->asDouble();
+	m_Method	= Parameters("METHOD")		->asInt();
+
+	Level_Inc	= Parameters("LEVEL_INC")	->asDouble();
+	nDirections	= Parameters("NDIRS")		->asInt();
+
+	DataObject_Set_Colors(pVisible	, 100, SG_COLORS_BLACK_WHITE);
+	DataObject_Set_Colors(pSVF		, 100, SG_COLORS_BLACK_WHITE);
+	DataObject_Set_Colors(pSimple	, 100, SG_COLORS_BLACK_WHITE);
+	DataObject_Set_Colors(pTerrain	, 100, SG_COLORS_BLACK_WHITE, true);
+
+	//-----------------------------------------------------
+	switch( m_Method )
+	{
+	case 0:	// multi scale
+		if( m_Pyramid.Create(m_pDEM, Level_Inc, GRID_PYRAMID_Mean) )
+		{
+			m_MaxLevel	= m_Pyramid.Get_Count();
+
+			if( m_MaxRadius > 0.0 )
+			{
+				while( m_MaxLevel > 0 && m_Pyramid.Get_Grid(m_MaxLevel - 1)->Get_Cellsize() > m_MaxRadius )
+				{
+					m_MaxLevel--;
+				}
+			}
+
+			bResult	= Initialise(8);
+		}
+		break;
+
+	case 1:	// sectors
+		bResult		= Initialise(nDirections);
+		break;
+	}
+
+	if( m_Method != 0 && m_MaxRadius <= 0.0 )
+	{
+		m_MaxRadius	= Get_Cellsize() * M_GET_LENGTH(Get_NX(), Get_NY());
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( Get_View_Shed(x, y, Visible, SVF, Simple, Terrain) )
+				{
+					if( pVisible )	pVisible->Set_Value (x, y, Visible);
+					if( pSVF )		pSVF	->Set_Value (x, y, SVF);
+					if( pSimple )	pSimple	->Set_Value (x, y, Simple);
+					if( pTerrain )	pTerrain->Set_Value (x, y, Terrain);
+				}
+				else
+				{
+					if( pVisible )	pVisible->Set_NoData(x, y);
+					if( pSVF )		pSVF	->Set_NoData(x, y);
+					if( pSimple )	pSimple	->Set_NoData(x, y);
+					if( pTerrain )	pTerrain->Set_NoData(x, y);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	m_Pyramid	.Destroy();
+	m_Angles	.Destroy();
+	m_Direction	.Clear();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CView_Shed::Initialise(int nDirections)
+{
+	m_Angles	.Create		(nDirections);
+	m_Direction	.Set_Count	(nDirections);
+
+	for(int iDirection=0; iDirection<nDirections; iDirection++)
+	{
+		m_Direction[iDirection].z	= (M_PI_360 * iDirection) / nDirections;
+		m_Direction[iDirection].x	= sin(m_Direction[iDirection].z);
+		m_Direction[iDirection].y	= cos(m_Direction[iDirection].z);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CView_Shed::Get_View_Shed(int x, int y, double &Sky_Visible, double &Sky_Factor, double &Sky_Simple, double &Sky_Terrain)
+{
+	double	slope, aspect;
+
+	if( m_pDEM->Get_Gradient(x, y, slope, aspect) )
+	{
+		bool	bResult;
+
+		switch( m_Method )
+		{
+		case 0:		bResult	= Get_Angles_Multi_Scale(x, y);	break;
+		default:	bResult	= Get_Angles_Sectoral   (x, y);	break;
+		}
+
+		if( bResult )
+		{
+			double	sinSlope, cosSlope, Phi, sinPhi, cosPhi;
+
+			Sky_Visible	= 0.0;
+			Sky_Factor	= 0.0;
+
+			sinSlope	= sin(slope);
+			cosSlope	= cos(slope);
+
+			for(int iDirection=0; iDirection<m_Angles.Get_N(); iDirection++)
+			{
+				Phi			= atan(m_Angles[iDirection]);
+				cosPhi		= cos(Phi);
+				sinPhi		= sin(Phi);
+
+				Sky_Visible	+= (M_PI_090 - Phi) * 100.0 / M_PI_090;
+				Sky_Factor	+= cosSlope * cosPhi*cosPhi + sinSlope * cos(m_Direction[iDirection].z - aspect) * ((M_PI_090 - Phi) - sinPhi * cosPhi);
+			}
+
+			Sky_Visible	/= m_Angles.Get_N();
+			Sky_Factor	/= m_Angles.Get_N();
+
+			Sky_Simple	= (1.0 + cosSlope) / 2.0;
+			Sky_Terrain	= Sky_Simple - Sky_Factor;
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CView_Shed::Get_Angles_Multi_Scale(int x, int y)
+{
+	if( !m_pDEM->is_NoData(x, y) )
+	{
+		double		z, d;
+		TSG_Point	p, q;
+
+		z	= m_pDEM->asDouble(x, y);
+		p	= Get_System()->Get_Grid_to_World(x, y);
+
+		m_Angles.Assign(0.0);
+
+		//-------------------------------------------------
+		for(int iGrid=-1; iGrid<m_MaxLevel; iGrid++)
+		{
+			CSG_Grid	*pGrid	= m_Pyramid.Get_Grid(iGrid);
+
+			for(int iDirection=0; iDirection<8; iDirection++)
+			{
+				q.x	= p.x + pGrid->Get_Cellsize() * m_Direction[iDirection].x;
+				q.y	= p.y + pGrid->Get_Cellsize() * m_Direction[iDirection].y;
+
+				if( pGrid->Get_Value(q, d) && (d = (d - z) / pGrid->Get_Cellsize()) > m_Angles[iDirection] )
+				{
+					m_Angles[iDirection]	= d;
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CView_Shed::Get_Angles_Sectoral(int x, int y)
+{
+	if( !m_pDEM->is_NoData(x, y) )
+	{
+		m_Angles.Assign(0.0);
+
+		//-------------------------------------------------
+		for(int iDirection=0; iDirection<m_Angles.Get_N(); iDirection++)
+		{
+			m_Angles[iDirection]	= Get_Angle_Sectoral(x, y, m_Direction[iDirection].x, m_Direction[iDirection].y);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CView_Shed::Get_Angle_Sectoral(int x, int y, double dx, double dy)
+{
+	double	Angle, Distance, dDistance, ix, iy, d, z;
+
+	z			= m_pDEM->asDouble(x, y);
+	ix			= x;
+	iy			= y;
+	Angle		= 0.0;
+	Distance	= 0.0;
+	dDistance	= Get_Cellsize() * M_GET_LENGTH(dx, dy);
+
+	while( is_InGrid(x, y) && Distance <= m_MaxRadius )
+	{
+		ix	+= dx;	x	= (int)(0.5 + ix);
+		iy	+= dy;	y	= (int)(0.5 + iy);
+		Distance	+= dDistance;
+
+		if( m_pDEM->is_InGrid(x, y) && (d = (m_pDEM->asDouble(x, y) - z) / Distance) > Angle )
+		{
+			Angle	= d;
+		}
+	}
+
+	return( Angle );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_lighting/view_shed.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,120 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                      ta_lighting                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     View_Shed.h                       //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__View_Shed_H
+#define HEADER_INCLUDED__View_Shed_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CView_Shed : public CSG_Module_Grid
+{
+public:
+	CView_Shed(void);
+	virtual ~CView_Shed(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	int						m_Method, m_MaxLevel;
+
+	double					m_MaxRadius;
+
+	CSG_Points_3D			m_Direction;
+
+	CSG_Vector				m_Angles;
+
+	CSG_Grid				*m_pDEM;
+
+	CSG_Grid_Pyramid		m_Pyramid;
+
+
+	bool					Initialise				(int nDirections);
+
+	bool					Get_Angles_Multi_Scale	(int x, int y);
+	bool					Get_Angles_Sectoral		(int x, int y);
+	double					Get_Angle_Sectoral		(int x, int y, double dx, double dy);
+
+	bool					Get_View_Shed			(int x, int y, double &Sky_Visible, double &Sky_Factor, double &Sky_Simple, double &Sky_Terrain);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__View_Shed_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,242 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Convergence.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Convergence.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CConvergence::CConvergence(void)
+{
+	Set_Name(_TL("Convergence Index"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Reference:\n"
+		"Koethe, R. / Lehmeier, F. (1996):\n'SARA – System zur Automatischen Relief-Analyse',\n"
+		"Benutzerhandbuch, 2. Auflage [Geogr. Inst. Univ. Goettingen, unveroeffentl.]\n")
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Convergence Index"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Aspect"),
+			_TL("Gradient")
+		),0
+	);
+}
+
+//---------------------------------------------------------
+CConvergence::~CConvergence(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CConvergence::On_Execute(void)
+{
+	pDTM			= Parameters("ELEVATION")	->asGrid();
+	pConvergence	= Parameters("RESULT")		->asGrid();
+
+	pConvergence->Assign_NoData();
+
+	DataObject_Set_Colors(pConvergence, 100, SG_COLORS_RED_GREY_BLUE, true);
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:	Do_Aspect();	break;
+	case 1:	Do_Gradient();	break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CConvergence::Do_Aspect(void)
+{
+	int		x, y, i, ix, iy, n;
+	double	Slope, Aspect, iAspect, d, dSum;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDTM->is_InGrid(x, y) )
+			{
+				for(i=0, n=0, dSum=0.0, iAspect=-M_PI_180; i<8; i++, iAspect+=M_PI_045)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( pDTM->is_InGrid(ix, iy) && pDTM->Get_Gradient(ix, iy, Slope, Aspect) && Aspect >= 0.0 )
+					{
+						d		= Aspect - iAspect;
+
+						//---------------------------------
+						d		= fmod(d, M_PI_360);
+
+						if( d < -M_PI_180 )
+						{
+							d	+= M_PI_360;
+						}
+						else if( d > M_PI_180 )
+						{
+							d	-= M_PI_360;
+						}
+
+						//---------------------------------
+						dSum	+= fabs(d);
+						n++;
+					}
+				}
+
+				pConvergence->Set_Value(x, y, n > 0 ? (dSum / (double)n - M_PI_090) * 100.0 / M_PI_090 : 0.0);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CConvergence::Do_Gradient(void)
+{
+	int		x, y, i, ix, iy, n;
+	double	z, Slope, Aspect, iSlope, iAspect, d, dSum;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDTM->is_InGrid(x, y) )
+			{
+				z	= pDTM->asDouble(x, y);
+
+				for(i=0, n=0, dSum=0.0, iAspect=-M_PI_180; i<8; i++, iAspect+=M_PI_045)
+				{
+					ix	= Get_xTo(i, x);
+					iy	= Get_yTo(i, y);
+
+					if( pDTM->is_InGrid(ix, iy) && pDTM->Get_Gradient(ix, iy, Slope, Aspect) && Aspect >= 0.0 )
+					{
+						iSlope	= atan((pDTM->asDouble(ix, iy) - z) / Get_Length(i));
+
+						// Nach dem Seiten-Kosinus-Satz...
+						d		= acos(sin(Slope) * sin(iSlope) + cos(Slope) * cos(iSlope) * cos(iAspect - Aspect));
+
+						//---------------------------------
+						d		= fmod(d, M_PI_360);
+
+						if( d < -M_PI_180 )
+						{
+							d	+= M_PI_360;
+						}
+						else if( d > M_PI_180 )
+						{
+							d	-= M_PI_360;
+						}
+
+						//---------------------------------
+						dSum	+= fabs(d);
+						n++;
+					}
+				}
+
+				pConvergence->Set_Value(x, y, n > 0 ? (dSum / (double)n - M_PI_090) * 100.0 / M_PI_090 : 0.0);
+			}
+		}
+	}
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Convergence.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Convergence_H
+#define HEADER_INCLUDED__Convergence_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_morphometry_EXPORT CConvergence : public CSG_Module_Grid
+{
+public:
+	CConvergence(void);
+	virtual ~CConvergence(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid					*pDTM, *pConvergence;
+
+
+	void					Do_Aspect		(void);
+	void					Do_Gradient		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Convergence_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,384 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Convergence_Radius.cpp                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "Convergence_Radius.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CConvergence_Radius::CConvergence_Radius(void)
+{
+	Set_Name	(_TL("Convergence Index (Search Radius)"));
+
+	Set_Author		(SG_T("(c) 2003 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Reference:\n"
+		"Koethe, R. / Lehmeier, F. (1996):\n'SARA – System zur Automatischen Relief-Analyse',\n"
+		"User Manual, 2. Edition [Dept. of Geography, University of Goettingen, unpublished]\n"
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Convergence_Radius Index"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "RADIUS"		, _TL("Radius"),
+		_TL(""),
+		PARAMETER_TYPE_Int		, 10, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("Standard"),
+			_TL("Distance Weighted (Linear)"),
+			_TL("Distance Weighted (Inverse)")
+		), 0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "SLOPE"		, _TL("Gradient"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, 0.0
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "DIFF"		, _TL("Difference"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("direction to the center cell"),
+			_TL("center cell's aspect direcion")
+		), 0
+	);
+}
+
+//---------------------------------------------------------
+CConvergence_Radius::~CConvergence_Radius(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CConvergence_Radius::On_Execute(void)
+{
+	CSG_Grid	*pDTM, *pConvergence_Radius;
+
+	pDTM				= Parameters("ELEVATION")	->asGrid();
+	pConvergence_Radius	= Parameters("RESULT")		->asGrid();
+
+	if( Initialize(pDTM, Parameters("RADIUS")->asInt()) )
+	{
+		DataObject_Set_Colors(pConvergence_Radius, 100, SG_COLORS_RED_GREY_BLUE, true);
+
+		pConvergence_Radius->Assign_NoData();
+
+		Get_Convergence_Radius(
+			pDTM,
+			pConvergence_Radius,
+			Parameters("SLOPE")	->asBool(),
+			Parameters("DIFF")	->asInt() == 0 ? true : false,
+			Parameters("METHOD")->asInt()
+		);
+
+		Finalize();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CConvergence_Radius::Initialize(CSG_Grid *pDTM, int Radius)
+{
+	int		x, y, ix, iy;
+	double	Slope, Aspect, d;
+
+	if( Radius > 0 )
+	{
+		//-------------------------------------------------
+		m_Radius	= Radius;
+		m_Diameter	= 1 + 2 * Radius;
+
+		m_Dir.Create(SG_DATATYPE_Double, m_Diameter, m_Diameter);
+		m_Dst.Create(SG_DATATYPE_Double, m_Diameter, m_Diameter);
+
+		for(iy=0, y=-m_Radius; iy<m_Diameter; iy++, y++)
+		{
+			for(ix=0, x=-m_Radius; ix<m_Diameter; ix++, x++)
+			{
+				d	= M_GET_LENGTH(x, y);
+
+				if( d < 1 || d > m_Radius )
+				{
+					m_Dir.Set_NoData(ix, iy);
+					m_Dst.Set_Value	(ix, iy, 0);
+				}
+				else
+				{
+					m_Dir.Set_Value	(ix, iy, y != 0.0 ? M_PI_180 + atan2((double)x, (double)y) : (x > 0.0 ? M_PI_270 : M_PI_090));
+					m_Dst.Set_Value	(ix, iy, d - 1);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		m_Slope	.Create(pDTM, SG_DATATYPE_Float);
+		m_Aspect.Create(pDTM, SG_DATATYPE_Float);
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( pDTM->is_InGrid(x, y) && pDTM->Get_Gradient(x, y, Slope, Aspect) && Aspect >= 0.0 )
+				{
+					m_Slope	.Set_Value(x, y, Slope);
+					m_Aspect.Set_Value(x, y, Aspect);
+				}
+				else
+				{
+					m_Slope	.Set_NoData(x, y);
+					m_Aspect.Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		m_iSum		= (double *)malloc(m_Radius * sizeof(double));
+		m_iCnt		= (int    *)malloc(m_Radius * sizeof(int   ));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CConvergence_Radius::Finalize(void)
+{
+	m_Dir	.Destroy();
+	m_Dst	.Destroy();
+
+	m_Slope	.Destroy();
+	m_Aspect.Destroy();
+
+	free(m_iSum);
+	free(m_iCnt);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define PI2PERC	(100.0 / M_PI_090)
+
+//---------------------------------------------------------
+void CConvergence_Radius::Get_Convergence_Radius(CSG_Grid *pDTM, CSG_Grid *pConvergence_Radius, bool bSlope, bool bCenterDiff, int Method)
+{
+	int		x, y, ix, iy, jx, jy, iDst;
+	double	Slope, Aspect, d, dSum, dCnt, z, dSlope, Dir;
+
+	dSlope	= Get_Cellsize();
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_Aspect.is_InGrid(x, y) )
+			{
+				z		= pDTM->asDouble(x, y);
+
+				memset(m_iSum, 0, m_Radius * sizeof(double));
+				memset(m_iCnt, 0, m_Radius * sizeof(int   ));
+
+				for(iy=0, jy=y-m_Radius; iy<m_Diameter; iy++, jy++)
+				{
+					for(ix=0, jx=x-m_Radius; ix<m_Diameter; ix++, jx++)
+					{
+						if( m_Dir.is_InGrid(ix, iy) && m_Aspect.is_InGrid(jx, jy) && (Aspect = m_Aspect.asDouble(jx, jy)) >= 0.0 )
+						{
+							Dir	= bCenterDiff
+								? m_Dir		.asDouble(ix, iy)
+								: m_Aspect	.asDouble( x,  y) + M_PI_360;
+
+							if( bSlope )
+							{
+								Slope	= bCenterDiff
+										? m_Slope.asDouble(jx, jy)
+										: m_Slope.asDouble(jx, jy) - m_Slope.asDouble(x, y) + M_PI_360;
+
+								d		= atan((pDTM->asDouble(jx, jy) - z) / (dSlope * m_Dst.asDouble(ix, iy)));
+								d		= acos(sin(Slope) * sin(d) + cos(Slope) * cos(d) * cos(Dir - Aspect));
+							}
+							else
+							{
+								d		= Aspect - Dir;
+							}
+
+							//-----------------------------
+							d		= fmod(d, M_PI_360);
+
+							if( d < -M_PI_180 )
+							{
+								d	+= M_PI_360;
+							}
+							else if( d > M_PI_180 )
+							{
+								d	-= M_PI_360;
+							}
+
+							//-----------------------------
+							iDst			= m_Dst.asInt(ix, iy);
+							m_iSum[iDst]	+= fabs(d);
+							m_iCnt[iDst]++;
+						}
+					}
+				}
+
+				//-----------------------------------------
+				for(iDst=1; iDst<m_Radius; iDst++)
+				{
+					m_iCnt[iDst]	+= m_iCnt[iDst - 1];
+					m_iSum[iDst]	+= m_iSum[iDst - 1];
+				}
+
+				switch( Method )
+				{
+				case 0:	// Standard
+					if( (dCnt = m_iCnt[m_Radius - 1]) > 0 )
+					{
+						pConvergence_Radius->Set_Value(x, y, PI2PERC * (m_iSum[m_Radius - 1] / dCnt - M_PI_090));
+					}
+					break;
+
+				case 1:	// Distance Weighted (Linear)
+					for(iDst=0, dSum=0.0; iDst<m_Radius; iDst++)
+					{
+						if( m_iCnt[iDst] > 0 )
+						{
+							dSum	+=  PI2PERC * (m_iSum[iDst] / (double)m_iCnt[iDst] - M_PI_090);
+						}
+					}
+
+					pConvergence_Radius->Set_Value(x, y, dSum / (double)m_Radius);
+					break;
+
+				case 2:	// Distance Weighted (Inverse)
+					for(iDst=0, dSum=0.0, dCnt=0.0; iDst<m_Radius; iDst++)
+					{
+						if( m_iCnt[iDst] > 0 )
+						{
+							d		= 1.0 / (1.0 + iDst);
+
+							dCnt	+= d;
+							dSum	+= d * PI2PERC * (m_iSum[iDst] / (double)m_iCnt[iDst] - M_PI_090);
+						}
+					}
+
+					pConvergence_Radius->Set_Value(x, y, dSum / (double)dCnt);
+					break;
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Convergence_Radius.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Convergence_Radius.h                 //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Convergence_Radius_H
+#define HEADER_INCLUDED__Convergence_Radius_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CConvergence_Radius : public CSG_Module_Grid
+{
+public:
+	CConvergence_Radius(void);
+	virtual ~CConvergence_Radius(void);
+
+
+protected:
+
+	virtual bool		On_Execute				(void);
+
+
+private:
+
+	int					m_Radius, m_Diameter, *m_iCnt;
+
+	double				*m_iSum;
+
+	CSG_Grid				m_Slope, m_Aspect, m_Dir, m_Dst;
+
+
+	bool				Initialize				(CSG_Grid *pDTM, int Radius);
+	void				Finalize				(void);
+
+	void				Get_Convergence_Radius	(CSG_Grid *pDTM, CSG_Grid *pConvergence_Radius, bool bSlope, bool bCenterDiff, int Method);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Convergence_Radius_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,157 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             Curvature_Classification.cpp              //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Curvature_Classification.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CCurvature_Classification::CCurvature_Classification(void)
+{
+	Set_Name(_TL("Curvature Classification"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Surface curvature based terrain classification.\n"
+		"Reference:\n"
+		"Dikau, R. (1988):\n'Entwurf einer geomorphographisch-analytischen Systematik von Reliefeinheiten',\n"
+		"Heidelberger Geographische Bausteine, Heft 5\n\n"
+		"0 - V  / V\n"
+		"1 - GE / V\n"
+		"2 - X  / V\n"
+		"3 - V  / GR\n"
+		"4 - GE / GR\n"
+		"5 - X  / GR\n"
+		"6 - V  / X\n"
+		"7 - GE / X\n"
+		"8 - X  / X\n")
+	);
+
+	Parameters.Add_Grid(	NULL, "CPLAN"		, _TL("Plan Curvature")			, _TL(""), PARAMETER_INPUT);
+	Parameters.Add_Grid(	NULL, "CPROF"		, _TL("Profile Curvature")		, _TL(""), PARAMETER_INPUT);
+
+	Parameters.Add_Value(	NULL, "THRESHOLD"	, _TL("Threshold for plane")		, _TL(""), PARAMETER_TYPE_Double, 0.001, 0.0, true);
+
+	Parameters.Add_Grid(	NULL, "CLASS"		, _TL("Curvature Classification"), _TL(""), PARAMETER_OUTPUT);
+
+}
+
+//---------------------------------------------------------
+CCurvature_Classification::~CCurvature_Classification(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CCurvature_Classification::On_Execute(void)
+{
+	int		x, y, Class;
+	double	Threshold, dPlan, dProf;
+	CSG_Grid	*pPlan, *pProf, *pClass;
+
+	Threshold	= Parameters("THRESHOLD")->asDouble();
+
+	pPlan		= Parameters("CPLAN")->asGrid();
+	pProf		= Parameters("CPROF")->asGrid();
+
+	pClass		= Parameters("CLASS")->asGrid();
+
+	pClass->Create(pPlan, SG_DATATYPE_Char);
+	pClass->Set_NoData_Value(-1);
+
+	if( 1 )
+	{
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( pPlan->is_NoData(x, y) || pProf->is_NoData(x, y) )
+				{
+					pClass->Set_NoData(x, y);
+				}
+				else
+				{
+					dPlan	= pPlan->asDouble(x, y);
+					dProf	= pProf->asDouble(x, y);
+
+					Class	 = dPlan < -Threshold ? 0 : (dPlan <= Threshold ? 3 : 6);
+					Class	+= dProf < -Threshold ? 0 : (dProf <= Threshold ? 1 : 2);
+
+					pClass->Set_Value(x, y, Class);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Curvature_Classification.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,105 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Curvature_Classification.h               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Curvature_Classification_H
+#define HEADER_INCLUDED__Curvature_Classification_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_morphometry_EXPORT CCurvature_Classification : public CSG_Module_Grid
+{
+public:
+	CCurvature_Classification(void);
+	virtual ~CCurvature_Classification(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Classification" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Curvature_Classification_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,370 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Hypsometry.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Hypsometry.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CHypsometry::CHypsometry(void)
+{
+	//-----------------------------------------------------
+	Set_Name(_TL("Hypsometry"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates the hypsometric curve for a given DEM.\n\n"
+		"References:\n"
+		"- Harlin, J.M (1978):\n"
+		"    'Statistical moments of the hypsometric curve and its density function',\n"
+		"    J. Int. Assoc. Math. Geol., Vol.10, p.59-72\n\n"
+		"- Luo, W. (2000):\n"
+		"    'Quantifying groundwater-sapping landforms with a hypsometric technique',\n"
+		"    J. of Geophysical Research, Vol.105, No.E1, p.1685-1694\n\n")
+	);
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Table(
+		NULL	, "TABLE"		, _TL("Hypsometry"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Value(
+		NULL	, "COUNT"		, _TL("Number of Classes"),
+		_TL(""),
+		PARAMETER_TYPE_Int, 100, 1, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "SORTING"		, _TL("Sort"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("up"),
+			_TL("down")
+		), 1
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Classification Constant"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("height"),
+			_TL("area")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "BZRANGE"		, _TL("Use Z-Range"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	Parameters.Add_Range(
+		NULL	, "ZRANGE"		, _TL("Z-Range"),
+		_TL(""),
+		0.0, 1000.0
+	);
+}
+
+//---------------------------------------------------------
+CHypsometry::~CHypsometry(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CHypsometry::On_Execute(void)
+{
+	bool	bDown;
+	int		nClasses;
+	double	zMin, zMax;
+	CSG_Grid	*pDEM;
+	CSG_Table	*pTable;
+
+	pDEM		= Parameters("ELEVATION")	->asGrid();
+	pTable		= Parameters("TABLE")		->asTable();
+	bDown		= Parameters("SORTING")		->asInt() == 1;
+	nClasses	= Parameters("COUNT")		->asInt();
+	zMin		= Parameters("BZRANGE")		->asBool() ? Parameters("ZRANGE")->asRange()->Get_LoVal() : 0.0;
+	zMax		= Parameters("BZRANGE")		->asBool() ? Parameters("ZRANGE")->asRange()->Get_HiVal() : 0.0;
+	
+	pTable->Destroy();
+	pTable->Set_Name(CSG_String::Format(SG_T("%s: %s"), _TL("Hypsometric Curve"), pDEM->Get_Name()));
+	pTable->Add_Field(_TL("Relative Height"), SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Relative Area")	, SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Absolute Height"), SG_DATATYPE_Double);
+	pTable->Add_Field(_TL("Absolute Area")	, SG_DATATYPE_Double);
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:				return( Calculate_A(pDEM, pTable, bDown, nClasses) );
+	case 1:	default:	return( Calculate_B(pDEM, pTable, bDown, nClasses, zMin, zMax) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CHypsometry::Calculate_A(CSG_Grid *pDEM, CSG_Table *pTable, bool bDown, int nClasses)
+{
+	int		i;
+	long	n, *Cells_Count;
+	double	z, dz, A, a, Min, Max, za, zb;
+
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	// 1. Min, Max, Area...
+
+	A	= 0;
+
+	for(n=0; n<pDEM->Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( !pDEM->is_NoData(n) )
+		{
+			if( A <= 0 )
+			{
+				Min	= Max	= pDEM->asDouble(n);
+			}
+			else
+			{
+				z	= pDEM->asDouble(n);
+
+				if( Min > z )
+				{
+					Min	= z;
+				}
+				else if( Max < z )
+				{
+					Max	= z;
+				}
+			}
+
+			A++;
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// 2. Hypsometric Curve...
+
+	if( A > 0 && Min < Max )
+	{
+		Cells_Count	= (long *)SG_Calloc(nClasses + 1, sizeof(long));
+
+		for(n=0; n<pDEM->Get_NCells() && Set_Progress_NCells(n); n++)
+		{
+			if( !pDEM->is_NoData(n) )
+			{
+				i	= (int)(nClasses * (Max - pDEM->asDouble(n)) / (Max - Min));
+
+				Cells_Count[i]++;
+			}
+		}
+
+		dz	= (Max - Min) / nClasses;
+		a	= A;
+
+		for(i=nClasses; i>=0; i--)
+		{
+			za	= a / A;
+			a	-= Cells_Count[bDown ? i : nClasses - i];
+			zb	= a / A;
+
+			pRecord	= pTable->Add_Record();
+			pRecord->Set_Value(0, 100.0 * i * dz / (Max - Min));	// Relative Height
+			pRecord->Set_Value(1, 100.0 * za);						// Relative Area
+			pRecord->Set_Value(2, Min +   i * dz);					// Absolute Height
+			pRecord->Set_Value(3, a * pDEM->Get_Cellarea());		// Absolute Area
+		}
+
+		SG_Free(Cells_Count);
+
+		return( false );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CHypsometry::Calculate_B(CSG_Grid *pDEM, CSG_Table *pTable, bool bDown, int nClasses, double zMin, double zMax)
+{
+	int		x, y, i, n, nStep, nMin, nMax, nRange;
+	double	z, zRange;
+
+	//-----------------------------------------------------
+	if( zMin < zMax && zMin < pDEM->Get_ZMax() && zMax > pDEM->Get_ZMin() )
+	{
+		for(nMin=0; nMin<pDEM->Get_NCells() && Set_Progress_NCells(nMin); nMin++)
+		{
+			if( pDEM->Get_Sorted(nMin, x, y, !bDown) && zMin <= pDEM->asDouble(x, y) )
+			{
+				zMin	= pDEM->asDouble(x, y);
+				break;
+			}
+		}
+
+		for(nMax=pDEM->Get_NCells() - 1; nMax > nMin && Set_Progress_NCells(nMax); nMax--)
+		{
+			if( pDEM->Get_Sorted(nMax, x, y, !bDown) && zMax >= pDEM->asDouble(x, y) )
+			{
+				zMax	= pDEM->asDouble(x, y);
+				break;
+			}
+		}
+	}
+	else
+	{
+		zMin	= pDEM->Get_ZMin();
+		zMax	= pDEM->Get_ZMax();
+		nMin	= 0;
+		nMax	= pDEM->Get_NCells() - 1;
+	}
+
+	//-----------------------------------------------------
+	if( (nRange = nMax - nMin) > 0 && (zRange = zMax - zMin) > 0 )
+	{
+		CSG_Table_Record	*pRecord;
+
+		pTable->Destroy();
+
+		pTable->Add_Field(_TL("Relative Height"), SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Relative Area")	, SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Absolute Height"), SG_DATATYPE_Double);
+		pTable->Add_Field(_TL("Absolute Area")	, SG_DATATYPE_Double);
+
+		pTable->Set_Name(CSG_String::Format(SG_T("%s: %s"), _TL("Hypsometric Curve"), pDEM->Get_Name()));
+
+		//-------------------------------------------------
+		nStep	= nRange / nClasses;
+
+		for(i=0, n=nMax; i<=nClasses; i++, n-=nStep)
+		{
+			if( pDEM->Get_Sorted(n, x, y, !bDown) )
+			{
+				z	= pDEM->asDouble(x, y);
+
+				pRecord	= pTable->Add_Record();
+				pRecord->Set_Value(0, 100.0 * i / nClasses);				// Relative Area
+				pRecord->Set_Value(1, 100.0 * (z - zMin) / zRange);			// Relative Height
+				pRecord->Set_Value(2, z);									// Absolute Height
+				pRecord->Set_Value(3, i * nStep * pDEM->Get_Cellarea());	// Absolute Area
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Hypsometry.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,109 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Hypsometry.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Hypsometry_H
+#define HEADER_INCLUDED__Hypsometry_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_morphometry_EXPORT CHypsometry : public CSG_Module_Grid  
+{
+public:
+	CHypsometry(void);
+	virtual ~CHypsometry(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	bool				Calculate_A		(CSG_Grid *pDGM, CSG_Table *pTable, bool bDown, int nClasses);
+	bool				Calculate_B		(CSG_Grid *pDEM, CSG_Table *pTable, bool bDown, int nClasses, double zMin, double zMax);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Hypsometry_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,144 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Terrain Analysis - Morphometry") );
+
+	case MLB_INFO_Author:
+		return( SG_T("Various Authors") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for (grid based) digital terrain analysis.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Terrain Analysis|Morphometry") );
+	}
+}
+
+
+//---------------------------------------------------------
+#include "Morphometry.h"
+#include "Convergence.h"
+#include "Convergence_Radius.h"
+#include "SurfaceSpecificPoints.h"
+#include "Curvature_Classification.h"
+#include "Hypsometry.h"
+#include "RealArea.h"
+#include "ProtectionIndex.h"
+#include "mrvbf.h"
+#include "distance_gradient.h"
+#include "mass_balance_index.h"
+#include "air_flow_height.h"
+#include "anisotropic_heating.h"
+#include "land_surface_temperature.h"
+#include "relative_heights.h"
+#include "wind_effect.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:		return( new CMorphometry );
+	case 1:		return( new CConvergence );
+	case 2:		return( new CConvergence_Radius );
+	case 3:		return( new CSurfaceSpecificPoints );
+	case 4:		return( new CCurvature_Classification );
+	case 5:		return( new CHypsometry );
+	case 6:		return( new CRealArea );
+	case 7:		return( new CProtectionIndex );
+	case 8:		return( new CMRVBF );
+	case 9:		return( new CDistance_Gradient );
+	case 10:	return( new CMass_Balance_Index );
+	case 11:	return( new CAir_Flow_Height );
+	case 12:	return( new CAnisotropic_Heating );
+	case 13:	return( new CLand_Surface_Temperature );
+	case 14:	return( new CRelative_Heights );
+	case 15:	return( new CWind_Effect );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ta_morphometry_H
+#define HEADER_INCLUDED__ta_morphometry_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef ta_morphometry_EXPORTS
+	#define	ta_morphometry_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	ta_morphometry_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ta_morphometry_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,878 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Morphometry.cpp                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Morphometry.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CMorphometry::CMorphometry(void)
+{
+	Set_Name		(_TL("Local Morphometry"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculates local morphometric terrain attributes (i.e. slope, aspect and curvatures).\n\n"
+		"References:\n\n"
+
+		"Maximum Slope\n"
+		"- Travis, M.R. / Elsner, G.H. / Iverson, W.D. / Johnson, C.G. (1975):\n"
+		"    'VIEWIT: computation of seen areas, slope, and aspect for land-use planning',\n"
+		"    USDA F.S. Gen. Tech. Rep. PSW-11/1975, 70p. Berkeley, California, U.S.A.\n\n"
+
+		"Maximum Triangle Slope\n"
+		"- Tarboton, D.G. (1997):\n"
+		"    'A new method for the determination of flow directions and upslope areas in grid digital elevation models',\n"
+		"    Water Ressources Research, Vol.33, No.2, p.309-319\n\n"
+
+		"Least Squares or Best Fitted Plane\n"
+		"- Horn, B. K. (1981):\n"
+		"    'Hill shading and the relectance map',\n"
+		"    Proceedings of the IEEE, v. 69, no. 1, p. 14-47.\n\n"
+
+		"- Beasley, D.B. / Huggins, L.F. (1982):\n"
+		"    'ANSWERS: User’s manual',\n"
+		"    U.S. EPA-905/9-82-001, Chicago, IL. 54pp.\n\n"
+
+		"- Costa-Cabral, M., and Burges, S.J., (1994):\n"
+		"    'Digital Elevation Model Networks (DEMON): a model of flow over hillslopes for computation of contributing and dispersal areas',\n"
+		"    Water Resources Research, v. 30, no. 6, p. 1681-1692.\n\n"
+
+		"Fit 2.Degree Polynom\n"
+		"- Bauer, J. / Rohdenburg, H. / Bork, H.-R. (1985):\n"
+		"    'Ein Digitales Reliefmodell als Vorraussetzung fuer ein deterministisches Modell der Wasser- und Stoff-Fluesse',\n"
+		"    Landschaftsgenese und Landschaftsoekologie, H.10, Parameteraufbereitung fuer deterministische Gebiets-Wassermodelle,\n"
+		"    Grundlagenarbeiten zu Analyse von Agrar-Oekosystemen, (Eds.: Bork, H.-R. / Rohdenburg, H.), p.1-15\n\n"
+
+		"- Heerdegen, R.G. / Beran, M.A. (1982):\n"
+		"    'Quantifying source areas through land surface curvature',\n"
+		"    Journal of Hydrology, Vol.57\n\n"
+
+		"- Zevenbergen, L.W. / Thorne, C.R. (1987):\n"
+		"    'Quantitative analysis of land surface topography',\n"
+		"    Earth Surface Processes and Landforms, 12: 47-56.\n\n"
+
+		"Fit 3.Degree Polynom\n"
+		"- R.M. Haralick (1983):\n"
+		"    'Ridge and valley detection on digital images',\n"
+		"    Computer Vision, Graphics and Image Processing, Vol.22, No.1, p.28-38\n\n"
+	));
+
+
+	//-----------------------------------------------------
+	// Input...
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+
+	//-----------------------------------------------------
+	// Output...
+
+	Parameters.Add_Grid(
+		NULL	, "SLOPE"		, _TL("Slope"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "ASPECT"		, _TL("Aspect"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CURV"		, _TL("Curvature"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "HCURV"		, _TL("Plan Curvature"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "VCURV"		, _TL("Profile Curvature"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+
+	//-----------------------------------------------------
+	// Options...
+
+	Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|"),
+			_TL("Maximum Slope (Travis et al. 1975)"),
+			_TL("Maximum Triangle Slope (Tarboton 1997)"),
+			_TL("Least Squares Fitted Plane (Horn 1981, Costa-Cabral & Burgess 1996)"),
+			_TL("Fit 2.Degree Polynom (Bauer, Rohdenburg, Bork 1985)"),
+			_TL("Fit 2.Degree Polynom (Heerdegen & Beran 1982)"),
+			_TL("Fit 2.Degree Polynom (Zevenbergen & Thorne 1987)"),
+			_TL("Fit 3.Degree Polynom (Haralick 1983)")
+		), 5
+	);
+}
+
+//---------------------------------------------------------
+CMorphometry::~CMorphometry(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMorphometry::On_Execute(void)
+{
+	int			x, y, Method;
+	CSG_Colors	Colors;
+
+	//-----------------------------------------------------
+	Method		= Parameters("METHOD"   )->asInt();
+
+	pDTM		= Parameters("ELEVATION")->asGrid();
+	pSlope		= Parameters("SLOPE"    )->asGrid();
+	pAspect		= Parameters("ASPECT"   )->asGrid();
+	pCurvature	= Parameters("CURV"     )->asGrid();
+	pCurv_Horz	= Parameters("HCURV"    )->asGrid();
+	pCurv_Vert	= Parameters("VCURV"    )->asGrid();
+	pCurv_Tang	= NULL;//Parameters("TCURV"    )->asGrid();
+
+	//-----------------------------------------------------
+	pSlope->Set_ZFactor	(M_RAD_TO_DEG);
+	pSlope->Set_Unit	(_TL("Degree"));
+	DataObject_Set_Colors(pSlope	, 100, SG_COLORS_YELLOW_RED);
+
+	pAspect->Set_ZFactor(M_RAD_TO_DEG);
+	pAspect->Set_Unit	(_TL("Degree"));
+	Colors.Set_Count(3);
+	Colors.Set_Color(0,	SG_GET_RGB(255, 255, 190));
+	Colors.Set_Color(1, SG_GET_RGB( 64,   0,   0));
+	Colors.Set_Color(2, SG_GET_RGB(255, 255, 190));
+	Colors.Set_Count(100);
+	DataObject_Set_Colors(pAspect	, Colors);
+
+	DataObject_Set_Colors(pCurvature, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pCurv_Vert, 100, SG_COLORS_RED_GREY_BLUE, true);
+	DataObject_Set_Colors(pCurv_Horz, 100, SG_COLORS_RED_GREY_BLUE, true);
+
+	//-----------------------------------------------------
+	_DX_2		= Get_Cellsize() * Get_Cellsize();
+	_4DX_2		= 4.0 * _DX_2;
+	_6DX		= 6.0 * Get_Cellsize();
+	_2DX		= 2.0 * Get_Cellsize();
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			switch( Method )
+			{
+			case 0:
+				Do_MaximumSlope(	x, y );
+				break;
+
+			case 1:
+				Do_Tarboton(		x, y );
+				break;
+
+			case 2:
+				Do_LeastSquare(		x, y );
+				break;
+
+			case 3:
+				Do_FD_BRM(			x, y );
+				break;
+
+			case 4:
+				Do_FD_Heerdegen(	x, y );
+				break;
+
+			case 5:
+				Do_FD_Zevenbergen(	x, y );
+				break;
+
+			case 6:
+				Do_FD_Haralick(		x, y );
+				break;
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CMorphometry::Set_Parameters(int x, int y, double Slope, double Aspect, double Curv, double vCurv, double hCurv, double tCurv)
+{
+	if( pSlope )
+	{
+		pSlope->Set_Value(		x, y, Slope );
+	}
+
+	if( pAspect )
+	{
+		pAspect->Set_Value(		x, y, Aspect );
+	}
+
+	if( pCurvature )
+	{
+		pCurvature->Set_Value(	x, y,  Curv );
+	}
+
+	if( pCurv_Vert )
+	{
+		pCurv_Vert->Set_Value(	x, y, vCurv );
+	}
+
+	if( pCurv_Horz )
+	{
+		pCurv_Horz->Set_Value(	x, y, hCurv );
+	}
+
+	if( pCurv_Tang )
+	{
+		pCurv_Tang->Set_Value(	x, y, tCurv );
+	}
+}
+
+//---------------------------------------------------------
+inline void CMorphometry::Set_Parameters_Derive(int x, int y, double D, double E, double F, double G, double H)
+{
+	double	k1, k2, Curv, vCurv, hCurv, tCurv;
+
+	k1		= F * G * H;
+	k2		= G*G + H*H;
+
+	if( k2 )
+	{
+		Curv	= -2.0 * (E + D);
+		vCurv	= -2.0 * (D * G*G + E * H*H + k1) /  k2;
+		hCurv	= -2.0 * (D * H*H + E * G*G - k1) /  k2;
+		tCurv	= -2.0 * (D * H*H + E * G*G - k1) / (k2 * sqrt(k2 + 1.0));
+
+//		Curv	= -2.0 * (E + D + F*F);
+//		vCurv	= -2.0 * (D * G*G + E * H*H + k1) / (k2 *  pow(k2 + 1.0, 3.0 / 2.0));
+//		hCurv	= -2.0 * (D * H*H + E * G*G - k1) / (      pow(k2      , 3.0 / 2.0));
+//		tCurv	= -2.0 * (D * H*H + E * G*G - k1) / (k2 * sqrt(k2 + 1.0)           );
+	}
+	else
+	{
+		Curv	= vCurv	= hCurv	= tCurv	= 0.0;
+	}
+
+	if( G != 0.0 )
+	{
+		Set_Parameters(x, y, atan(sqrt(k2)), M_PI_180 + atan2(H, G)	, Curv, vCurv, hCurv, tCurv);
+	}
+	else if( H > 0.0 )
+	{
+		Set_Parameters(x, y, atan(sqrt(k2)), M_PI_270				, Curv, vCurv, hCurv, tCurv);
+	}
+	else if( H < 0.0 )
+	{
+		Set_Parameters(x, y, atan(sqrt(k2)), M_PI_090				, Curv, vCurv, hCurv, tCurv);
+	}
+	else
+	{
+		Set_Parameters(x, y, atan(sqrt(k2)), 0.0					, Curv, vCurv, hCurv, tCurv);
+
+		if( pAspect )
+		{
+			pAspect->Set_NoData(x, y);
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CMorphometry::Set_Parameters_NoData(int x, int y, bool bCompletely)
+{
+	if( bCompletely )
+	{
+		if( pSlope )
+		{
+			pSlope->Set_NoData(		x, y );
+		}
+
+		if( pAspect )
+		{
+			pAspect->Set_NoData(	x, y );
+		}
+
+		if( pCurvature )
+		{
+			pCurvature->Set_NoData(	x, y );
+		}
+
+		if( pCurv_Vert )
+		{
+			pCurv_Vert->Set_NoData(	x, y );
+		}
+
+		if( pCurv_Horz )
+		{
+			pCurv_Horz->Set_NoData(	x, y );
+		}
+
+		if( pCurv_Tang )
+		{
+			pCurv_Tang->Set_NoData(	x, y );
+		}
+	}
+	else
+	{
+		Set_Parameters(x, y, 0.0, 0.0, 0.0, 0.0, 0.0);
+
+		if( pAspect )
+		{
+			pAspect->Set_NoData(	x, y );
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// Indexing of the Submatrix:
+//
+//  +-------+    +-------+
+//  | 7 0 1 |    | 2 5 8 |
+//  | 6 * 2 | => | 1 4 7 |
+//  | 5 4 3 |    | 0 3 6 |
+//  +-------+    +-------+
+//
+//---------------------------------------------------------
+inline bool CMorphometry::Get_SubMatrix3x3(int x, int y, double SubMatrix[9])
+{
+	static int	iSub[]	= { 5, 8, 7, 6, 3, 0, 1, 2 };
+
+	int		i, ix, iy;
+	double	z;
+
+	if( pDTM->is_NoData(x, y) )
+	{
+		Set_Parameters_NoData(x, y, true);
+	}
+	else
+	{
+		z				= pDTM->asDouble(x, y);
+		SubMatrix[4]	= 0.0;
+
+		for(i=0; i<8; i++)
+		{
+			ix	= Get_xTo(i, x);
+			iy	= Get_yTo(i, y);
+
+			if( pDTM->is_InGrid(ix, iy) )
+			{
+				SubMatrix[iSub[i]]	= pDTM->asDouble(ix, iy) - z;
+			}
+			else
+			{
+				ix	= Get_xTo(i + 4, x);
+				iy	= Get_yTo(i + 4, y);
+
+				if( pDTM->is_InGrid(ix, iy) )
+				{
+					SubMatrix[iSub[i]]	= z - pDTM->asDouble(ix, iy);
+				}
+				else
+				{
+					SubMatrix[iSub[i]]	= 0.0;
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline bool CMorphometry::Get_SubMatrix5x5(int x, int y, double SubMatrix[25])
+{
+	int		i, ix, iy, jx, jy;
+	double	z;
+
+	if( pDTM->is_NoData(x, y) )
+	{
+		Set_Parameters_NoData(x, y, true);
+	}
+	else
+	{
+		z	= pDTM->asDouble(x,y);
+
+		for(i=0, iy=y-2; iy<=y+2; iy++)
+		{
+			jy	= iy < 0 ? 0 : ( iy >= Get_NY() ? Get_NY() - 1 : iy );
+
+			for(ix=x-2; ix<=x+2; ix++, i++)
+			{
+				jx	= ix < 0 ? 0 : ( ix >= Get_NX() ? Get_NX() - 1 : ix );
+
+				SubMatrix[i]	= pDTM->is_InGrid(jx, jy) ? pDTM->asDouble(jx, jy) - z : 0.0;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					The Methods							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// Maximum Slope (Travis et al., 1975, Peucker & Douglas, 1975))
+//
+// Travis, M.R., Elsner, G.H., Iverson, W.D., and Johnson, C.G. 1975:
+//		VIEWIT: computation of seen areas, slope, and aspect for land-use planning.
+//		USDA F.S. Gen. Tech. Rep. PSW-11/1975, 70p. Berkeley, California, U.S.A.
+//
+//---------------------------------------------------------
+void CMorphometry::Do_MaximumSlope(int x, int y)
+{
+	int		i, ix, iy, j, Aspect;
+
+	double	z, zm[8], Slope, Curv, hCurv, a, b;
+
+	//-----------------------------------------------------
+	if( pDTM->is_NoData(x, y) )
+	{
+		Set_Parameters_NoData(x, y, true);
+	}
+	else
+	{
+		//-------------------------------------------------
+		z		= pDTM->asDouble(x, y);
+        Slope	= Curv	= 0.0;
+
+		for(Aspect=-1, i=0; i<8; i++)
+		{
+			ix		= Get_xTo(i, x);
+			iy		= Get_yTo(i, y);
+
+			if( !pDTM->is_InGrid(ix, iy) )
+			{
+				zm[i]	= 0.0;
+			}
+			else
+			{
+				zm[i]	= atan((z - pDTM->asDouble(ix, iy)) / Get_Length(i));
+				Curv	+= zm[i];
+
+				if( zm[i] > Slope )
+				{
+					Aspect	= i;
+					Slope	= zm[i];
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( Aspect < 0.0 )
+		{
+			Set_Parameters_NoData(x, y);
+		}
+		else
+		{
+			//---------------------------------------------
+			// Let's now estimate the plan curvature...
+
+			for(i=Aspect+1, j=0, a=0.0; i<Aspect+8; i++, j++)
+			{
+				if( zm[i % 8] < 0.0 )
+				{
+					a	= j + zm[(i - 1) % 8] / (zm[(i - 1) % 8] - zm[i % 8]);
+					break;
+				}
+			}
+
+			if( a != 0.0 )
+			{
+				for(i=Aspect+7, j=0, b=0.0; i>Aspect; i--, j++)
+				{
+					if( zm[i % 8] < 0.0 )
+					{
+						b	= j + zm[(i + 1) % 8] / (zm[(i + 1) % 8] - zm[i % 8]);
+						break;
+					}
+				}
+
+				hCurv	=  45.0 * (a + b) - 180.0;
+			}
+			else
+			{
+				hCurv	=  180.0;
+			}
+
+			//---------------------------------------------
+			Set_Parameters(x, y,
+				Slope,
+				Aspect * M_PI_045,
+				Curv,
+				zm[Aspect] + zm[(Aspect + 4) % 8],
+				hCurv
+			);
+		}
+    }
+}
+
+//---------------------------------------------------------
+// Maximum Triangle Slope
+//
+// Tarboton, D.G. (1997):
+//		'A new method for the determination of flow directions and upslope areas in grid digital elevation models',
+//		Water Ressources Research, Vol.33, No.2, p.309-319
+//
+//---------------------------------------------------------
+void CMorphometry::Do_Tarboton(int x, int y)
+{
+	int		i, ix, iy, j;
+	double	z, zm[8], iSlope, iAspect, Slope, Aspect, G, H;
+
+	//-----------------------------------------------------
+	if( pDTM->is_NoData(x, y) )
+	{
+		Set_Parameters_NoData(x, y, true);
+	}
+	else
+	{
+		z		= pDTM->asDouble(x, y);
+
+		for(i=0; i<8; i++)
+		{
+			ix		= Get_xTo(i, x);
+			iy		= Get_yTo(i, y);
+
+			if( pDTM->is_InGrid(ix, iy) )
+			{
+				zm[i]	=  pDTM->asDouble(ix, iy);
+			}
+			else
+			{
+				ix		= Get_xTo(i + 4, x);
+				iy		= Get_yTo(i + 4, y);
+
+				if( pDTM->is_InGrid(ix, iy) )
+				{
+					zm[i]	=  z - (pDTM->asDouble(ix, iy) - z);
+				}
+				else
+				{
+					zm[i]	=  z;
+				}
+			}
+		}
+
+		//---------------------------------------------
+        Slope	=  0.0;
+		Aspect	= -1.0;
+
+		for(i=0, j=1; i<8; i++, j=(j+1)%8)
+		{
+			if( i % 2 )	// i => diagonal
+			{
+				G		= (z		- zm[j]) / Get_Cellsize();
+				H		= (zm[j]	- zm[i]) / Get_Cellsize();
+			}
+			else		// i => orthogonal
+			{
+				G		= (z		- zm[i]) / Get_Cellsize();
+				H		= (zm[i]	- zm[j]) / Get_Cellsize();
+			}
+
+			if( H < 0.0 )
+			{
+				iAspect	= 0.0;
+				iSlope	= G;
+			}
+			else if( H > G )
+			{
+				iAspect	= M_PI_045;
+				iSlope	= (z - zm[i % 2 ? i : j]) / (sqrt(2.0) * Get_Cellsize());
+			}
+			else
+			{
+				iAspect	= atan(H / G);
+				iSlope	= sqrt(G*G + H*H);
+			}
+
+			if( iSlope > Slope )
+			{
+				Aspect	= i * M_PI_045 + (i % 2 ? M_PI_045 - iAspect : iAspect);
+				Slope	= iSlope;
+			}
+		}
+
+		//---------------------------------------------
+		if( Aspect < 0.0 )
+		{
+			Set_Parameters_NoData(x, y);
+		}
+		else
+		{
+			Set_Parameters(x, y, atan(Slope), Aspect);
+		}
+	}
+}
+
+//---------------------------------------------------------
+// Least Squares or Best Fit Plane (Horn 1981, Beasley & Huggins 1982, Costa-Cabral & Burgess 1994)
+//
+// Horn, B. K. (1981):
+//      Hill shading and the relectance map.
+//      Proceedings of the IEEE, v. 69, no. 1, p 14-47.
+//
+// Beasley, D.B. and Huggins, L.F. 1982:
+//		ANSWERS: User’s manual.
+//		U.S. EPA-905/9-82-001, Chicago, IL. 54pp.
+//
+// Costa-Cabral, M., and Burges, S.J., 1994:
+//		Digital Elevation Model Networks (DEMON): a model of flow over hillslopes for computation of contributing and dispersal areas
+//		Water Resources Research, v. 30, no. 6, p. 1681-1692.
+//
+//---------------------------------------------------------
+void CMorphometry::Do_LeastSquare(int x, int y)
+{
+	double	zm[9], a, b;
+
+	if( Get_SubMatrix3x3(x, y, zm) )
+	{
+		a = ((zm[2] + 2 * zm[5] + zm[8]) - (zm[0] + 2 * zm[3] + zm[6])) / (8 * Get_Cellsize());
+		b = ((zm[6] + 2 * zm[7] + zm[8]) - (zm[0] + 2 * zm[1] + zm[2])) / (8 * Get_Cellsize());
+
+		if( a != 0.0 )
+		{
+			Set_Parameters(x, y, atan( sqrt(a*a + b*b) ), M_PI_180 + atan2(b, a));
+		}
+		else if( b > 0.0 )
+		{
+			Set_Parameters(x, y, atan( sqrt(a*a + b*b) ), M_PI_270);
+		}
+		else if( b < 0.0 )
+		{
+			Set_Parameters(x, y, atan( sqrt(a*a + b*b) ), M_PI_090);
+		}
+		else
+		{
+			Set_Parameters_NoData(x, y);
+		}
+	}
+}
+
+//---------------------------------------------------------
+// Quadratic Function Approximation (Bauer, Rohdenburg & Bork, 1985)
+//
+// Bauer, J. / Rohdenburg, H. / Bork, H.-R., (1985):
+//		'Ein Digitales Reliefmodell als Vorraussetzung fuer ein deterministisches Modell der Wasser- und Stoff-Fluesse',
+//		Landschaftsgenese und Landschaftsoekologie, H.10, Parameteraufbereitung fuer deterministische Gebiets-Wassermodelle,
+//		Grundlagenarbeiten zu Analyse von Agrar-Oekosystemen, (Eds.: Bork, H.-R. / Rohdenburg, H.), p.1-15
+//
+//---------------------------------------------------------
+void CMorphometry::Do_FD_BRM(int x, int y)
+{
+	double	zm[9], D, E, F, G, H;
+
+	if( Get_SubMatrix3x3(x, y, zm) )
+	{
+		D	= ( (zm[0] + zm[2] + zm[3] + zm[5] + zm[6] + zm[8]) - 2 * (zm[1] + zm[4] + zm[7]) )	/ _DX_2;
+		E	= ( (zm[0] + zm[6] + zm[1] + zm[7] + zm[2] + zm[8]) - 2 * (zm[3] + zm[4] + zm[5]) )	/ _DX_2;
+        F	= (  zm[8] + zm[0] - zm[7] )														/ _4DX_2;
+		G	= ( (zm[2] - zm[0]) + (zm[5] - zm[3]) + (zm[8]-zm[6]) )								/ _6DX;
+		H	= ( (zm[6] - zm[0]) + (zm[7] - zm[1]) + (zm[8]-zm[2]) )								/ _6DX;
+
+		Set_Parameters_Derive(x, y, D, E, F, G, H);
+	}
+}
+
+//---------------------------------------------------------
+// Quadratic Function Approximation (Heerdegen & Beran, 1984)
+//
+// Heerdegen, R.G. / Beran, M.A. (1982):
+//		'Quantifying source areas through land surface curvature',
+//		Journal of Hydrology, Vol.57
+//
+//---------------------------------------------------------
+void CMorphometry::Do_FD_Heerdegen(int x, int y)
+{
+	double	zm[9], D, E, F, G, H, a, b;
+
+	//-----------------------------------------------------
+	if( Get_SubMatrix3x3(x, y, zm) )
+	{
+		a	=   zm[0] + zm[2] + zm[3] + zm[5] + zm[6] + zm[8];
+		b	=   zm[0] + zm[1] + zm[2] + zm[6] + zm[7] + zm[8];
+		D	= (0.3 * a - 0.2 * b)								/ _DX_2;
+		E	= (0.3 * b - 0.2 * a)								/ _DX_2;
+		F	= ( zm[0] - zm[2]                 - zm[6] + zm[8])	/ _4DX_2;
+		G	= (-zm[0] + zm[2] - zm[3] + zm[5] - zm[6] + zm[8])	/ _6DX;
+        H	= (-zm[0] - zm[1] - zm[2] + zm[6] + zm[7] + zm[8])	/ _6DX;
+
+		Set_Parameters_Derive(x, y, D, E, F, G, H);
+	}
+}
+
+//---------------------------------------------------------
+// Quadratic Function Approximation (Zevenbergen und Thorne, 1986)
+//
+// Zevenbergen, L.W. and C.R. Thorne. 1987:
+//		Quantitative analysis of land surface topography
+//		Earth Surface Processes and Landforms, 12: 47-56.
+//
+//---------------------------------------------------------
+void CMorphometry::Do_FD_Zevenbergen(int x, int y)
+{
+	double	zm[9], D, E, F, G, H;
+
+	//-----------------------------------------------------
+	if( Get_SubMatrix3x3(x, y, zm) )
+	{
+		D	= ((zm[3] + zm[5]) / 2.0 - zm[4])	/ _DX_2;
+		E	= ((zm[1] + zm[7]) / 2.0 - zm[4])	/ _DX_2;
+		F	=  (zm[0] - zm[2] - zm[6] + zm[8])	/ _4DX_2;
+		G	=  (zm[5] - zm[3])					/ _2DX;
+        H	=  (zm[7] - zm[1])					/ _2DX;
+
+		Set_Parameters_Derive(x, y, D, E, F, G, H);
+	}
+}
+
+//---------------------------------------------------------
+// Cubic Function Approximation (Haralick, 1991)
+//
+// R.M. Haralick (1983):
+//		'Ridge and Valley Detection on digital images',
+//		Computer Vision, Graphics and Image Processing, Vol.22, No.1, p.28-38
+//
+//---------------------------------------------------------
+void CMorphometry::Do_FD_Haralick(int x, int y)
+{
+	//-----------------------------------------------------
+	// Finite Differenzen Methode Matrizen...
+
+	const int 	Mtrx[][5][5]	= {
+	{	{ 31,- 5,-17,- 5, 31}, {-44,-62,-68,-62,-44}, {  0,  0,  0,  0,  0}, { 44, 62, 68, 62, 44}, {-31,  5, 17,  5,-31}	},
+	{	{ 31,-44,  0, 44,-31}, {- 5,-62,  0, 62,  5}, {-17,-68,  0, 68, 17}, {- 5,-62,  0, 62,  5}, { 31,-44,  0, 44,-31}	},
+	{	{  2,  2,  2,  2,  2}, {- 1,- 1,- 1,- 1,- 1}, {- 2,- 2,- 2,- 2,- 2}, {- 1,- 1,- 1,- 1,- 1}, {  2,  2,  2,  2,  2}	},
+	{	{  4,  2,  0,- 2,- 4}, {  2,  1,  0,- 1,- 2}, {  0,  0,  0,  0,  0}, {- 2,- 1,  0,  1,  2}, {- 4,- 2,  0,  2,  4}	},
+	{	{  2,- 1,- 2,- 1,  2}, {  2,- 1,- 2,- 1,  2}, {  2,- 1,- 2,- 1,  2}, {  2,- 1,- 2,- 1,  2}, {  2,- 1,- 2,- 1,  2}	},	};
+
+	const int	QMtrx[]			= { 4200, 4200, 700, 1000, 700 };
+
+	//-----------------------------------------------------
+	int		i, ix, iy, n;
+	double	Sum, zm[25], k[5];
+
+	//-----------------------------------------------------
+	if( Get_SubMatrix5x5(x, y, zm) )
+	{
+		for(i=0; i<5; i++)
+		{
+			for(n=0, Sum=0.0, iy=0; iy<5; iy++)
+			{
+				for(ix=0; ix<5; ix++, n++)
+				{
+					Sum	+= zm[n] * Mtrx[i][ix][iy];
+				}
+			}
+
+			k[i]	= Sum / QMtrx[i];
+		}
+
+		Set_Parameters_Derive(x, y, k[4], k[2], k[3], k[1], k[0]);
+    }
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/Morphometry.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,130 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Morphometry.h                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Morphometry_H
+#define HEADER_INCLUDED__Morphometry_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_morphometry_EXPORT CMorphometry : public CSG_Module_Grid
+{
+public:
+	CMorphometry(void);
+	virtual ~CMorphometry(void);
+
+
+protected:
+
+	virtual bool			On_Execute				(void);
+
+
+private:
+
+	double					_DX_2, _4DX_2, _6DX, _2DX;
+
+	CSG_Grid					*pDTM, *pSlope, *pAspect, *pCurvature, *pCurv_Horz, *pCurv_Vert, *pCurv_Tang;
+
+	//-----------------------------------------------------
+	void					Set_Parameters			(int x, int y, double Slope, double Aspect, double Curv = 0.0, double vCurv = 0.0, double hCurv = 0.0, double tCurv = 0.0);
+	void					Set_Parameters_Derive	(int x, int y, double D, double E, double F, double G, double H);
+	void					Set_Parameters_NoData	(int x, int y, bool bCompletely = false);
+
+	bool					Get_SubMatrix3x3		(int x, int y, double SubMatrix[ 9]);
+	bool					Get_SubMatrix5x5		(int x, int y, double SubMatrix[25]);
+
+	//-----------------------------------------------------
+	void					Do_MaximumSlope			(int x, int y );
+	void					Do_Tarboton				(int x, int y );
+
+	void					Do_LeastSquare			(int x, int y );
+
+	void					Do_FD_BRM				(int x, int y );
+	void					Do_FD_Heerdegen			(int x, int y );
+	void					Do_FD_Zevenbergen		(int x, int y );
+
+	void					Do_FD_Haralick			(int x, int y );
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Morphometry_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,515 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               SurfaceSpecificPoints.cpp               //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "SurfaceSpecificPoints.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSurfaceSpecificPoints::CSurfaceSpecificPoints(void)
+{
+	CSG_Parameter	*pNode;
+
+	Set_Name		(_TL("Surface Specific Points"));
+
+	Set_Author		(SG_T("(c) 2001 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"References:\n"
+		"Peucker, T.K. and Douglas, D.H., 1975:\n"
+		"'Detection of surface-specific points by local parallel processing of discrete terrain elevation data',\n"
+		"Computer Graphics and Image Processing, 4, 375-387\n"
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Result"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	pNode	= Parameters.Add_Choice(
+		NULL	, "METHOD"		, _TL("Method"),
+		_TL("Algorithm for the detection of Surface Specific Points"),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
+			_TL("Mark Highest Neighbour"),
+			_TL("Opposite Neighbours"),
+			_TL("Flow Direction"),
+			_TL("Flow Direction (up and down)"),
+			_TL("Peucker & Douglas")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		pNode	, "THRESHOLD"	, _TL("Threshold"),
+		_TL("Threshold for Peucker & Douglas Algorithm"),
+		PARAMETER_TYPE_Double	, 2
+	);
+}
+
+//---------------------------------------------------------
+CSurfaceSpecificPoints::~CSurfaceSpecificPoints(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSurfaceSpecificPoints::On_Execute(void)
+{
+	CSG_Grid	*pGrid, *pResult;
+
+	pGrid		= Parameters("ELEVATION")	->asGrid();
+	pResult		= Parameters("RESULT")		->asGrid();
+
+	switch( Parameters("METHOD")->asInt() )
+	{
+	case 0:
+		Do_MarkHighestNB	(pGrid, pResult);
+		break;
+
+	case 1:
+		Do_OppositeNB		(pGrid, pResult);
+		break;
+
+	case 2:
+		Do_FlowDirection	(pGrid, pResult);
+		break;
+
+	case 3:
+		Do_FlowDirection2	(pGrid, pResult);
+		break;
+
+	case 4:
+		Do_PeuckerDouglas	(pGrid, pResult, Parameters("THRESHOLD")->asDouble());
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSurfaceSpecificPoints::Do_MarkHighestNB(CSG_Grid *pGrid, CSG_Grid *pResult)	// Band & Lammers...
+{
+	int		i, x, y, ix, iy, xlo, ylo, xhi, yhi;
+
+	double	lo, hi, z;
+
+	CSG_Grid	*clo, *chi;
+
+	clo		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+	chi		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+
+	// Pass 1: Auszaehlen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+        {
+			lo	= hi	= pGrid->asDouble(x,y);
+			xhi	= xlo	= x;
+			yhi	= ylo	= y;
+
+			for(i=0; i<4; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+  
+				if( is_InGrid(ix,iy) )
+				{
+					z	= pGrid->asDouble(ix,iy);
+
+					if( z > hi )
+					{
+						hi	= z;
+						xhi	= ix;
+						yhi	= iy;
+					}
+					else if( z < lo )
+					{
+						lo	= z;
+						xlo	= ix;
+						ylo	= iy;
+					}
+				}
+			}
+
+			clo->Add_Value(xlo,ylo,1);
+			chi->Add_Value(xhi,yhi,1);
+		}
+	}
+
+	// Pass 2: Setzen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !chi->asChar(x,y) )
+			{
+				if( !clo->asChar(x,y) )
+					pResult->Set_Value(x,y, 2);	// Sattel
+				else
+					pResult->Set_Value(x,y, 1);	// Tiefenlinie
+			}
+			else if( !clo->asChar(x,y) )
+				pResult->Set_Value(x,y, -1);	// Wasserscheide
+			else
+				pResult->Set_Value(x,y,  0);	// Nichts...
+		}
+	}
+
+	delete(clo);
+	delete(chi);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSurfaceSpecificPoints::Do_OppositeNB(CSG_Grid *pGrid, CSG_Grid *pResult)
+{
+	int		i, x, y, ix, iy, jx, jy;
+
+	double	z, iz, jz;
+
+	CSG_Grid	*clo, *chi;
+
+	clo		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+	chi		= SG_Create_Grid(pGrid, SG_DATATYPE_Char);
+
+	// Pass 1: Auszaehlen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+        {
+			z	= pGrid->asDouble(x,y);
+
+			for(i=0; i<4; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+
+				if( is_InGrid(ix,iy) )
+				{
+					jx	= Get_xFrom(i,x);
+					jy	= Get_yFrom(i,y);
+  
+					if( is_InGrid(jx,jy) )
+					{
+						iz	= pGrid->asDouble(ix,iy);
+						jz	= pGrid->asDouble(jx,jy);
+
+						if( iz>z && jz>z )
+							chi->Add_Value(x,y,1);
+
+						else if( iz<z && jz<z )
+							clo->Add_Value(x,y,1);
+					}
+				}
+			}
+		}
+	}
+
+	// Pass 2: Setzen...
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( chi->asChar(x,y) )
+			{
+				if( clo->asChar(x,y) )
+					pResult->Set_Value(x,y, 5);					// Sattel
+				else
+					pResult->Set_Value(x,y, chi->asChar(x,y) );	// Tiefenlinie
+			}
+			else if( clo->asChar(x,y) )
+				pResult->Set_Value(x,y, - clo->asChar(x,y) );	// Wasserscheide
+			else
+				pResult->Set_Value(x,y, 0);						// Nichts...
+		}
+	}
+
+	delete(clo);
+	delete(chi);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSurfaceSpecificPoints::Do_FlowDirection(CSG_Grid *pGrid, CSG_Grid *pResult)
+{
+	bool	bLower;
+
+	int		x, y, i, ix, iy, xLow, yLow;
+
+	double	z, iz, zLow;
+
+	pResult->Assign();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+        {
+			z		= pGrid->asDouble(x,y);
+			bLower	= false;
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+  
+				if( is_InGrid(ix,iy) )
+				{
+					iz	= pGrid->asDouble(ix,iy);
+
+					if(iz<z)
+					{
+						if(!bLower)
+						{
+							bLower	= true;
+							zLow	= iz;
+							xLow	= ix;
+							yLow	= iy;
+						}
+						else if(iz<zLow)
+						{
+							zLow	= iz;
+							xLow	= ix;
+							yLow	= iy;
+						}
+					}
+				}
+			}
+
+			if(bLower)
+			{
+				pResult->Add_Value(xLow, yLow, 1);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSurfaceSpecificPoints::Do_FlowDirection2(CSG_Grid *pGrid, CSG_Grid *pResult)
+{
+	CSG_Grid	Grid(*pGrid), Result(*pResult);
+
+	Do_FlowDirection(&Grid, &Result);
+
+	Grid.Invert();
+
+	Do_FlowDirection(&Grid, pResult);
+
+	for(int n=0; n<Get_NCells(); n++)
+	{
+		pResult->Add_Value(n, -Result.asInt(n));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSurfaceSpecificPoints::Do_PeuckerDouglas(CSG_Grid *pGrid, CSG_Grid *pResult, double Threshold)
+{
+	bool	wasPlus;
+
+	int		x, y, i, ix, iy, nSgn;
+
+	double	d, dPlus, dMinus, z, alt[8];
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			z	= pGrid->asDouble(x,y);
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+
+				if( is_InGrid(ix,iy) )
+					alt[i]	= pGrid->asDouble(ix,iy);
+				else
+					alt[i]	= z;
+			}
+
+			dPlus	= dMinus	= 0;
+			nSgn	= 0;
+			wasPlus	= (alt[7] - z > 0) ? true : false;
+			
+			for(i=0; i<8; i++)
+			{
+				d	= alt[i] - z;
+
+				if(d>0)
+				{
+					dPlus	+= d;
+					if(!wasPlus)
+					{
+						nSgn++;
+						wasPlus	= true;
+					}
+				}
+				else if(d<0)
+				{
+					dMinus	-= d;
+					if(wasPlus)
+					{
+						nSgn++;
+						wasPlus	= false;
+					}
+				}
+			}
+
+			i	= 0;
+			if(!dPlus)									// Peak...
+				i	=  9;
+			else if(!dMinus)							// Pit
+				i	= -9;
+			else if(nSgn==4)							// Pass
+				i	= 1;
+			else if(nSgn==2)
+			{
+				i	= nSgn	= 0;
+
+				if(alt[7]>z)
+				{
+					while(alt[i++]>z);
+					do	nSgn++;	while(alt[i++]<z);
+				}
+				else
+				{
+					while(alt[i++]<z);
+					do	nSgn++;	while(alt[i++]>z);
+				}
+
+				i	= 0;
+
+				if(nSgn==4)
+				{
+					if(dMinus-dPlus > Threshold)		// convex break...
+						i	=  2;
+					else if(dPlus-dMinus > Threshold)	// concave break...
+						i	= -2;
+				}
+				else	// lines:
+				{
+					if(dMinus-dPlus>0)					// Ridge
+						i	=  7;
+					else								// Channel
+						i	= -7;
+				}
+			}
+
+			pResult->Set_Value(x,y,i);
+		}
+    }
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/SurfaceSpecificPoints.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                SurfaceSpecificPoints.h                //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SurfaceSpecificPoints_H
+#define HEADER_INCLUDED__SurfaceSpecificPoints_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_morphometry_EXPORT CSurfaceSpecificPoints : public CSG_Module_Grid  
+{
+public:
+	CSurfaceSpecificPoints(void);
+	virtual ~CSurfaceSpecificPoints(void);
+
+	virtual const SG_Char *	Get_MenuPath		(void)	{	return( _TL("R:Classification" ));	}
+
+
+protected:
+
+	virtual bool			On_Execute			(void);
+
+
+private:
+
+	void					Do_MarkHighestNB	(CSG_Grid *pGrid, CSG_Grid *pResult);
+	void					Do_OppositeNB		(CSG_Grid *pGrid, CSG_Grid *pResult);
+	void					Do_FlowDirection	(CSG_Grid *pGrid, CSG_Grid *pResult);
+	void					Do_FlowDirection2	(CSG_Grid *pGrid, CSG_Grid *pResult);
+	void					Do_PeuckerDouglas	(CSG_Grid *pGrid, CSG_Grid *pResult, double Threshold);
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SurfaceSpecificPoints_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,284 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Air_Flow_Height.cpp                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "air_flow_height.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CAir_Flow_Height::CAir_Flow_Height(void)
+{
+	Set_Name		(_TL("Effective Air Flow Heights"));
+
+	Set_Author		(SG_T("J.Boehner, O.Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "RESULT"		, _TL("Effective Air Flow Heights"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DIRECT"		, _TL("Wind Direction (Degree)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 315.0, 0.0, true, 360.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LEEFACT"		, _TL("Lee Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.5
+	);
+
+	Parameters.Add_Value(
+		NULL	, "LUVFACT"		, _TL("Luv Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MAXDIST"		, _TL("Maximum Distance (km)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 300.0
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CAir_Flow_Height::On_Execute(void)
+{
+	int		x, y;
+
+	double	Direction, d, dLuvA, dLuvB, dLee, dx, dy, z;
+
+	//-----------------------------------------------------
+	m_pDEM			= Parameters("ELEVATION")	->asGrid();
+	m_pAFH			= Parameters("RESULT")		->asGrid();
+
+	Direction		= Parameters("DIRECT")		->asDouble() * M_DEG_TO_RAD;
+	m_dLee			= Parameters("LEEFACT")		->asDouble();
+	m_dLuv			= Parameters("LUVFACT")		->asDouble();
+	m_Distance_Max	= Parameters("MAXDIST")		->asDouble() * 1000.0;
+
+	//-----------------------------------------------------
+	dx		= sin(Direction);
+	dy		= cos(Direction);
+
+	if( fabs(dx) > fabs(dy) )
+	{
+		dy	/= fabs(dx);
+		dx	= dx < 0 ? -1 : 1;
+	}
+	else
+	{
+		dx	/= fabs(dy);
+		dy	= dy < 0 ? -1 : 1;
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDEM->is_NoData(x,y) )
+			{
+				m_pAFH->Set_NoData(x,y);
+			}
+			else
+			{
+				dLuvA	= Get_Sum(x, y,  dx,  dy, m_dLuv);
+						  Get_Sum(x, y, -dx, -dy, m_dLuv, dLuvB, m_dLee, dLee);
+
+				d		= dLuvA > dLuvB ? dLuvA - dLuvB : 0;
+				z		= m_pDEM->asDouble(x, y);
+				dLee	= 1.0 + (z - dLee) / (z + dLee);
+				d		= d + z * dLee * dLee / 2.0;
+
+				m_pAFH->Set_Value(x, y, d < 0.0 ? 0.0 : d);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CAir_Flow_Height::Get_Sum(int x, int y, double dx, double dy, double Factor)
+{
+	double	ix, iy, Dist, Sum, dxy, Weight, SumWeight;
+
+	dxy			= Get_Cellsize() * sqrt(dx*dx + dy*dy);
+	Dist		= 0.0;
+	SumWeight	= 0.0;
+	Sum			= 0.0;
+
+	for(ix=x+0.5, iy=y+0.5; ; )
+	{
+		Dist	+= dxy;
+
+		ix		+= dx;
+		iy		+= dy;
+
+		x		= (int)ix;
+		y		= (int)iy;
+
+		if( !is_InGrid(x,y) || Dist > m_Distance_Max )
+		{
+			break;
+		}
+		else if( !m_pDEM->is_NoData(x,y) )
+		{
+			SumWeight	+= Weight	= pow(Dist, -Factor);
+			Sum			+= Weight * m_pDEM->asDouble(x,y);
+		}
+	}
+
+	if( SumWeight > 0 )
+	{
+		Sum		/= SumWeight;
+	}
+
+	return( Sum );
+}
+
+//---------------------------------------------------------
+void CAir_Flow_Height::Get_Sum(int x, int y, double dx, double dy, double FactorA, double &SumA, double FactorB, double &SumB)
+{
+	double	ix, iy, Dist, dxy, WeightA, SumWeightA, WeightB, SumWeightB;
+
+	dxy			= Get_Cellsize() * sqrt(dx*dx + dy*dy);
+	Dist		= 0.0;
+	SumWeightA	= 0.0;
+	SumA		= 0.0;
+	SumWeightB	= 0.0;
+	SumB		= 0.0;
+
+	for(ix=x+0.5, iy=y+0.5; ; )
+	{
+		Dist	+= dxy;
+
+		ix		+= dx;
+		iy		+= dy;
+
+		x		= (int)ix;
+		y		= (int)iy;
+
+		if( !is_InGrid(x,y) || Dist > m_Distance_Max )
+		{
+			break;
+		}
+		else if( !m_pDEM->is_NoData(x,y) )
+		{
+			SumWeightA	+= WeightA	= pow(Dist, -FactorA);
+			SumA		+= WeightA * m_pDEM->asDouble(x,y);
+
+			SumWeightB	+= WeightB	= pow(Dist, -FactorB);
+			SumB		+= WeightB * m_pDEM->asDouble(x,y);
+		}
+	}
+
+	if( SumWeightA > 0 )
+	{
+		SumA		/= SumWeightA;
+	}
+
+	if( SumWeightB > 0 )
+	{
+		SumB		/= SumWeightB;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/air_flow_height.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Air_Flow_Height.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Air_Flow_Height_H
+#define HEADER_INCLUDED__Air_Flow_Height_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CAir_Flow_Height : public CSG_Module_Grid
+{
+public:
+	CAir_Flow_Height(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	double				m_dLee, m_dLuv, m_Distance_Max;
+
+	CSG_Grid			*m_pDEM, *m_pAFH;
+
+
+	double				Get_Sum			(int x, int y, double dx, double dy, double Factor);
+	void				Get_Sum			(int x, int y, double dx, double dy, double FactorA, double &SumA, double FactorB, double &SumB);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Air_Flow_Height_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Anisotropic_Heating.cpp               //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "anisotropic_heating.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CAnisotropic_Heating::CAnisotropic_Heating(void)
+{
+	//-----------------------------------------------------
+	Set_Name	(_TL("Diurnal Anisotropic Heating"));
+
+	Set_Author	(SG_T("J.Boehner, O.Conrad (c) 2008"));
+
+	Set_Description(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "DAH"			, _TL("Diurnal Anisotropic Heating"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "ALPHA_MAX"	, _TL("Alpha Max (Degree)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 202.5, 0.0, true, 360.0, true
+	);
+}
+
+//---------------------------------------------------------
+CAnisotropic_Heating::~CAnisotropic_Heating(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CAnisotropic_Heating::On_Execute(void)
+{
+	double		alpha_max, alpha, slope;
+	CSG_Grid	*pDEM, *pDAH;
+
+	//-----------------------------------------------------
+	pDEM		= Parameters("DEM")			->asGrid();
+	pDAH		= Parameters("DAH")			->asGrid();
+
+	alpha_max	= Parameters("ALPHA_MAX")	->asDouble() * M_DEG_TO_RAD;
+
+	//-----------------------------------------------------
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( pDEM->is_NoData(x, y) || !pDEM->Get_Gradient(x, y, slope, alpha) )
+			{
+				pDAH->Set_NoData(x, y);
+			}
+			else
+			{
+				pDAH->Set_Value(x, y, cos(alpha_max - alpha) * atan(slope));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/anisotropic_heating.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Anisotropic_Heating.h                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Anisotropic_Heating_H
+#define HEADER_INCLUDED__Anisotropic_Heating_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CAnisotropic_Heating : public CSG_Module_Grid
+{
+public:
+	CAnisotropic_Heating(void);
+	virtual ~CAnisotropic_Heating(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Anisotropic_Heating_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,305 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Distance_Gradient.cpp                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "distance_gradient.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDistance_Gradient::CDistance_Gradient(void)
+{
+	Set_Name		(_TL("Downslope Distance Gradient"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculation of a new topographic index to quantify downslope controls on local drainage. "
+		"\n\n"
+		"References:\n"
+		"- Hjerdt, K.N., McDonnell, J.J., Seibert, J. Rodhe, A. (2004): "
+		"  'A new topographic index to quantify downslope controls on local drainage', "
+		"  Water Resources Research, 40\n"
+		"\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "GRADIENT"	, _TL("Gradient"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "DIFFERENCE"	, _TL("Gradient Difference"),
+		_TL("Difference to local gradient."),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Value(
+		NULL	, "DISTANCE"	, _TL("Vertical Distance"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 10.0, 0.0, true
+	);
+
+	Parameters.Add_Choice(
+		NULL	, "OUTPUT"		, _TL("Output"),
+		_TL(""),
+
+		CSG_String::Format(SG_T("%s|%s|%s|"),
+			_TL("distance"),
+			_TL("gradient (tangens)"),
+			_TL("gradient (degree)")
+		), 2
+	);
+}
+
+//---------------------------------------------------------
+CDistance_Gradient::~CDistance_Gradient(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CDistance_Gradient::On_Execute(void)
+{
+	int			x, y, Output;
+	double		vDistance, hDistance, s, a;
+	CSG_Grid	*pGradient, *pDifference;
+
+	//-----------------------------------------------------
+	m_pDEM		= Parameters("DEM")			->asGrid();
+	pGradient	= Parameters("GRADIENT")	->asGrid();
+	pDifference	= Parameters("DIFFERENCE")	->asGrid();
+	vDistance	= Parameters("DISTANCE")	->asDouble();
+	Output		= Parameters("OUTPUT")		->asInt();
+
+	//-----------------------------------------------------
+	if( vDistance > 0.0 )
+	{
+		switch( Output )
+		{
+		case 0:	// distance
+			DataObject_Set_Colors(pGradient, 100, SG_COLORS_WHITE_BLUE	, false);
+			pGradient->Set_Unit(_TL("m"));
+			pGradient->Set_ZFactor(1.0);
+			break;
+
+		case 1:	// gradient (ratio)
+			DataObject_Set_Colors(pGradient, 100, SG_COLORS_WHITE_BLUE	, true);
+			pGradient->Set_Unit(_TL(""));
+			pGradient->Set_ZFactor(1.0);
+			break;
+
+		case 2:	// gradient (degree)
+			DataObject_Set_Colors(pGradient, 100, SG_COLORS_YELLOW_RED	, false);
+			pGradient->Set_Unit(_TL("\xc2\xb0"));
+			pGradient->Set_ZFactor(M_RAD_TO_DEG);
+			break;
+		}
+
+		if( pDifference )
+		{
+			DataObject_Set_Colors(pDifference, 100, SG_COLORS_RED_GREY_BLUE	, false);
+			pDifference->Set_Unit(_TL("\xc2\xb0"));
+			pDifference->Set_ZFactor(M_RAD_TO_DEG);
+		}
+
+		//-------------------------------------------------
+		m_Dir.Create(m_pDEM, SG_DATATYPE_Char);
+
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				m_Dir.Set_Value(x, y, m_pDEM->Get_Gradient_NeighborDir(x, y));
+			}
+		}
+
+		//-------------------------------------------------
+		for(y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( (hDistance = Get_hDistance(x, y, vDistance)) > 0.0 )
+				{
+					switch( Output )
+					{
+					case 0:	// distance
+						pGradient->Set_Value(x, y, hDistance);
+						break;
+
+					case 1:	// gradient (tangens)
+						pGradient->Set_Value(x, y, vDistance / hDistance);
+						break;
+
+					case 2:	// gradient (degree)
+						pGradient->Set_Value(x, y, atan(vDistance / hDistance));
+						break;
+					}
+
+					if( pDifference )
+					{
+						if( m_pDEM->Get_Gradient(x, y, s, a) )
+							pDifference->Set_Value (x, y, s - atan(vDistance / hDistance));
+						else
+							pDifference->Set_NoData(x, y);
+					}
+				}
+				else
+				{
+					pGradient->Set_NoData(x, y);
+
+					if( pDifference )
+						pDifference->Set_NoData(x, y);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		m_Dir.Destroy();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CDistance_Gradient::Get_hDistance(int x, int y, double vDistance)
+{
+	int		Dir;
+	double	zStart, zStop, z, zLast, hDistance;
+
+	hDistance	= 0.0;
+
+	if( m_pDEM->is_InGrid(x, y) )
+	{
+		zStart	= z	= m_pDEM->asDouble(x, y);
+		zStop	= zStart - vDistance;
+
+		while( z > zStop && m_pDEM->is_InGrid(x, y) && (Dir = m_Dir.asInt(x, y)) >= 0 )//&& Process_Get_Okay(false) )
+		{
+			x		+= Get_xTo(Dir);
+			y		+= Get_yTo(Dir);
+
+			if( m_pDEM->is_InGrid(x, y) )
+			{
+				zLast	= z;
+				z		= m_pDEM->asDouble(x, y);
+
+				if( z < zStop )
+				{
+					hDistance	+= Get_Length(Dir) * (zStop - zLast) / (z - zLast);
+				}
+				else
+				{
+					hDistance	+= Get_Length(Dir);
+				}
+			}
+			else
+			{
+				hDistance	+= Get_Length(Dir);
+			}
+		}
+
+		if( !m_pDEM->is_InGrid(x, y) )
+		{
+			if( (z = zStart - z) > 0.0 )
+			{
+				hDistance	*= vDistance / z;
+			}
+			else
+			{
+				hDistance	= SG_Get_Length(m_pDEM->Get_XRange(), m_pDEM->Get_YRange());
+			}
+		}
+	}
+
+	return( hDistance );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/distance_gradient.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,101 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Distance_Gradient.h                  //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Distance_Gradient_H
+#define HEADER_INCLUDED__Distance_Gradient_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDistance_Gradient : public CSG_Module_Grid
+{
+public:
+	CDistance_Gradient(void);
+	virtual ~CDistance_Gradient(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	CSG_Grid					*m_pDEM, m_Dir;
+
+
+	double						Get_hDistance			(int x, int y, double vDistance);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Distance_Gradient_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,206 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Land_Surface_Temperature.cpp             //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "land_surface_temperature.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CLand_Surface_Temperature::CLand_Surface_Temperature(void)
+{
+	//-----------------------------------------------------
+	Set_Name	(_TL("Land Surface Temperature"));
+
+	Set_Author	(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description(_TW(
+		"References:\n"
+		"Bohner, J., Antonic, O. (2008): "
+		"'Land-suface parameters specific to topo-climatology'. "
+		"in: Hengl, T., Reuter, H. (Eds.): 'Geomorphometry - Concepts, Software, Applications', in press\n"
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation [m]"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SWR"			, _TL("Short Wave Radiation [kW/m2]"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "LAI"			, _TL("Leaf Area Index"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "LST"			, _TL("Land Surface Temperature [Deg.Celsius]"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "Z_REFERENCE"	, _TL("Elevation at Reference Station [m]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T_REFERENCE"	, _TL("Temperature at Reference Station [Deg.Celsius]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T_GRADIENT"	, _TL("Temperature Gradient [Deg.Celsius/km]"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 6.5
+	);
+
+	Parameters.Add_Value(
+		NULL	, "C_FACTOR"	, _TL("C Factor"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 1.0
+	);
+}
+
+//---------------------------------------------------------
+CLand_Surface_Temperature::~CLand_Surface_Temperature(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CLand_Surface_Temperature::On_Execute(void)
+{
+	double		Z_reference, T_reference, T_gradient, C_Factor, LAI_max, Z, SWR, LAI, LST;
+	CSG_Grid	*pDEM, *pSWR, *pLAI, *pLST;
+
+	//-----------------------------------------------------
+	pDEM		= Parameters("DEM")			->asGrid();
+	pSWR		= Parameters("SWR")			->asGrid();
+	pLAI		= Parameters("LAI")			->asGrid();
+	pLST		= Parameters("LST")			->asGrid();
+
+	Z_reference	= Parameters("Z_REFERENCE")	->asDouble();
+	T_reference	= Parameters("T_REFERENCE")	->asDouble();
+	T_gradient	= Parameters("T_GRADIENT")	->asDouble();
+	C_Factor	= Parameters("C_FACTOR")	->asDouble();
+
+	LAI_max		= pLAI->Get_ZMax();
+
+	//-----------------------------------------------------
+	if( LAI_max > 0.0 )
+	{
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( pDEM->is_NoData(x, y) || pSWR->is_NoData(x, y) || pLAI->is_NoData(x, y) || (SWR = pSWR->asDouble(x, y)) <= 0.0 )
+				{
+					pLST->Set_NoData(x, y);
+				}
+				else
+				{
+					Z	= pDEM->asDouble(x, y);
+					SWR	= pSWR->asDouble(x, y);
+					LAI	= pLAI->asDouble(x, y);
+
+					LST	= T_reference
+						- (T_gradient * (Z - Z_reference)) / 1000.0
+						+ C_Factor * (SWR - 1.0 / SWR) * (1.0 - LAI / LAI_max);
+
+					pLST->Set_Value(x, y, LST);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/land_surface_temperature.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Land_Surface_Temperature.h              //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Land_Surface_Temperature_H
+#define HEADER_INCLUDED__Land_Surface_Temperature_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CLand_Surface_Temperature : public CSG_Module_Grid
+{
+public:
+	CLand_Surface_Temperature(void);
+	virtual ~CLand_Surface_Temperature(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Land_Surface_Temperature_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,322 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 mass_balance_index.cpp                //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mass_balance_index.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MBI_LEVEL_2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CMass_Balance_Index::CMass_Balance_Index(void)
+{
+	Set_Name		(_TL("Mass Balance Index"));
+
+	Set_Author		(SG_T("(c) 2008 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"\n"
+		"References:\n"
+		"\n"
+		"Friedrich, K. (1996): "
+		"Digitale Reliefgliederungsverfahren zur Ableitung bodenkundlich relevanter Flaecheneinheiten. "
+		"Frankfurter Geowissenschaftliche Arbeiten D 21, Frankfurt/M., "
+		"<a href=\"http://user.uni-frankfurt.de/~relief/fga21/\">online</a>.\n"
+		"\n"
+		"Friedrich, K. (1998): "
+		"Multivariate distance methods for geomorphographic relief classification. "
+		"in Heinecke, H., Eckelmann, W., Thomasson, A., Jones, J., Montanarella, L., Buckley, B. (eds.): "
+		"Land Inforamtion Systems - Developments for planning the sustainable use of land resources. "
+		"European Soil Bureau - Research Report 4, EUR 17729 EN, Office for oficial publications of the European Communities, Ispra, pp. 259-266, "
+		"<a href=\"http://eusoils.jrc.it/ESDB_Archive/eusoils_docs/esb_rr/n04_land_information_systems/contents.html\">online</a>.\n"
+		"\n"
+		"Moeller, M., Volk, M., Friedrich, K., Lymburner, L. (2008): "
+		"Placing soil-genesis and transport processes into a landscape context: A multiscale terrain-analysis approach. "
+		"Journal of Plant Nutrition and Soil Science, 171, pp. 419-430, DOI: 10.1002/jpln.200625039\n"
+		"\n"
+	));
+
+	//-----------------------------------------------------
+#ifdef MBI_LEVEL_2
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+#else
+	Parameters.Add_Grid(
+		NULL	, "SLOPE"		, _TL("Slope"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "CURVE"		, _TL("Curvature"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+#endif
+	Parameters.Add_Grid(
+		NULL	, "HREL"		, _TL("Vertical Distance to Channel Network"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "MBI"			, _TL("Mass Balance Index"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TSLOPE"		, _TL("T Slope"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 15.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "TCURVE"		, _TL("T Curvature"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.01, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THREL"		, _TL("T Vertical Distance to Channel Network"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 15.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CMass_Balance_Index::~CMass_Balance_Index(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMass_Balance_Index::On_Execute(void)
+{
+	int			x, y;
+	double		TSlope, TCurve, THRel, fSlope, fCurve, fHRel;
+
+	//-----------------------------------------------------
+#ifdef MBI_LEVEL_2
+	CSG_Grid	*pDEM		= Parameters("DEM")		->asGrid();
+#else
+	CSG_Grid	*pSlope		= Parameters("SLOPE")	->asGrid();
+	CSG_Grid	*pCurve		= Parameters("CURVE")	->asGrid();
+#endif
+	CSG_Grid	*pHRel		= Parameters("HREL")	->asGrid();
+	CSG_Grid	*pMBI		= Parameters("MBI")		->asGrid();
+
+	TSlope		= Parameters("TSLOPE")	->asDouble();
+	TCurve		= Parameters("TCURVE")	->asDouble();
+	THRel		= Parameters("THREL")	->asDouble();
+
+	//-----------------------------------------------------
+	DataObject_Set_Colors(pMBI, 100, SG_COLORS_RED_GREY_BLUE, true);
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+#ifdef MBI_LEVEL_2
+			if( (pHRel == NULL || !pHRel->is_NoData(x, y)) && Get_Morphometry(x, y, pDEM, fSlope, fCurve) )
+			{
+#else
+			if( (pHRel == NULL || !pHRel->is_NoData(x, y)) && !pSlope->is_NoData(x, y) && pCurve->is_NoData(x, y) )
+			{
+				fSlope	= pSlope->asDouble(x, y);
+				fCurve	= pCurve->asDouble(x, y);
+#endif
+				if( pHRel )
+				{
+					fHRel	= pHRel	->asDouble(x, y);
+
+					fSlope	= Get_Transformed(fSlope, TSlope);
+					fCurve	= Get_Transformed(fCurve, TCurve);
+					fHRel	= Get_Transformed(fHRel	, THRel);
+
+					pMBI	->Set_Value(x, y, fCurve < 0.0
+						? fCurve * (1.0 - fSlope) * (1.0 - fHRel)
+						: fCurve * (1.0 + fSlope) * (1.0 + fHRel)
+					);
+				}
+				else
+				{
+					fSlope	= Get_Transformed(fSlope, TSlope);
+					fCurve	= Get_Transformed(fCurve, TCurve);
+
+					pMBI	->Set_Value(x, y, fCurve < 0.0
+						? fCurve * (1.0 - fSlope)
+						: fCurve * (1.0 + fSlope)
+					);
+				}
+			}
+			else
+			{
+				pMBI	->Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CMass_Balance_Index::Get_Transformed(double x, double t)
+{
+	t	+= fabs(x);
+
+	return( t > 0.0 ? x / t : 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMass_Balance_Index::Get_Morphometry(int x, int y, CSG_Grid *pDEM, double &Slope, double &Curve)
+{
+	int		i, ix, iy;
+	double	z, zm[8], G, H, E, D;
+
+	if( pDEM->is_InGrid(x, y) )
+	{
+		z		= pDEM->asDouble(x, y);
+
+		for(i=0; i<8; i++)
+		{
+			ix		= pDEM->Get_System().Get_xTo(i, x);
+			iy		= pDEM->Get_System().Get_yTo(i, y);
+
+			if( is_InGrid(ix, iy) )
+			{
+				zm[i]	= pDEM->asDouble(ix, iy) - z;
+			}
+			else
+			{
+				ix		= pDEM->Get_System().Get_xFrom(i, x);
+				iy		= pDEM->Get_System().Get_yFrom(i, y);
+
+				if( is_InGrid(ix, iy) )
+				{
+					zm[i]	= z - pDEM->asDouble(ix, iy);
+				}
+				else
+				{
+					zm[i]	= 0.0;
+				}
+			}
+		}
+
+		D		= ((zm[0] + zm[4]) / 2.0) / pDEM->Get_Cellarea();
+		E		= ((zm[2] + zm[6]) / 2.0) / pDEM->Get_Cellarea();
+	//	F		=  (zm[5] - zm[7] - zm[3] + zm[1]) / (4.0 * pDEM->Get_Cellarea());
+		G		=  (zm[0] - zm[4]) / (2.0 * pDEM->Get_Cellsize());
+        H		=  (zm[2] - zm[6]) / (2.0 * pDEM->Get_Cellsize());
+
+		Slope	= atan(sqrt(G*G + H*H));
+		Curve	= -2.0 * (E + D);
+
+		return( true );
+	}
+
+	Slope	= 0.0;
+	Curve	= 0.0;
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mass_balance_index.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,102 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 mass_balance_index.h                  //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__mass_balance_index_H
+#define HEADER_INCLUDED__mass_balance_index_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CMass_Balance_Index : public CSG_Module_Grid
+{
+public:
+	CMass_Balance_Index(void);
+	virtual ~CMass_Balance_Index(void);
+
+//	virtual const SG_Char *		Get_MenuPath			(void)	{	return( _TL("R:Indices" ));	}
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	double						Get_Transformed			(double x, double t);
+
+	bool						Get_Morphometry			(int x, int y, CSG_Grid *pDEM, double &Slope, double &Curve);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__mass_balance_index_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,605 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       MRVBF.cpp                       //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mrvbf.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CMRVBF::CMRVBF(void)
+{
+	Set_Name		(_TL("Multiresolution Index of Valley Bottom Flatness (MRVBF)"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Calculation of the 'multiresolution index of valley bottom flatness' (MRVBF) and "
+		"the complementary 'multiresolution index of the ridge top flatness' (MRRTF). "
+		"\n\n"
+		"References:\n"
+		"- Gallant, J.C., Dowling, T.I. (2003): "
+		"  'A multiresolution index of valley bottom flatness for mapping depositional areas', "
+		"  Water Resources Research, 39/12:1347-1359\n"
+	));
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "MRVBF"		, _TL("MRVBF"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "MRRTF"		, _TL("MRRTF"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T_SLOPE"		, _TL("Initial Threshold for Slope"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 16.0, 0.0, true, 100.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T_PCTL_V"	, _TL("Threshold for Elevation Percentile (Lowness)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.40, 0.0, true, 1.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T_PCTL_R"	, _TL("Threshold for Elevation Percentile (Upness)"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 0.35, 0.0, true, 1.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "P_SLOPE"		, _TL("Shape Parameter for Slope"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 4.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "P_PCTL"		, _TL("Shape Parameter for Elevation Percentile"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 3.0
+	);
+
+	Parameters.Add_Value(
+		NULL	, "UPDATE"		, _TL("Update Views"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "CLASSIFY"	, _TL("Classify"),
+		_TL(""),
+		PARAMETER_TYPE_Bool		, false
+	);
+
+	Parameters.Add_Value(
+		NULL	, "MAX_RES"		, _TL("Maximum Resolution (Percentage)"),
+		_TL("Maximum resolution as percentage of the diameter of the DEM."),
+		PARAMETER_TYPE_Double	, 100.0, 0.0, true, 100.0, true
+	);
+}
+
+//---------------------------------------------------------
+CMRVBF::~CMRVBF(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define UPDATE_VIEWS(b)	if( bUpdate )	{	DataObject_Update(pMRRTF, b);	DataObject_Update(pMRVBF, b);	}
+
+//---------------------------------------------------------
+bool CMRVBF::On_Execute(void)
+{
+	bool		bUpdate;
+	int			Level;
+	double		T_Slope, Resolution, max_Resolution;
+	CSG_Grid	*pDEM, *pMRVBF, *pMRRTF, CF, VF, RF, DEM, Slope, Pctl;
+
+	//-----------------------------------------------------
+	pDEM			= Parameters("DEM")			->asGrid();
+	pMRVBF			= Parameters("MRVBF")		->asGrid();
+	pMRRTF			= Parameters("MRRTF")		->asGrid();
+
+	T_Slope			= Parameters("T_SLOPE")		->asDouble();
+
+	m_T_Pctl_V		= Parameters("T_PCTL_V")	->asDouble();
+	m_T_Pctl_R		= Parameters("T_PCTL_R")	->asDouble();
+
+	m_P_Slope		= Parameters("P_SLOPE")		->asDouble();
+	m_P_Pctl		= Parameters("P_PCTL")		->asDouble();
+
+	bUpdate			= Parameters("UPDATE")		->asBool();
+
+	max_Resolution	= Parameters("MAX_RES")		->asDouble() / 100.0;
+	Resolution		= SG_Get_Length(Get_System()->Get_XRange(), Get_System()->Get_YRange());
+	max_Resolution	= max_Resolution * Resolution;
+
+	//-----------------------------------------------------
+	if( 1 )
+	{
+	//	DataObject_Set_Colors(pMRVBF, 100, SG_COLORS_WHITE_BLUE		, false);
+		DataObject_Set_Colors(pMRVBF, 100, SG_COLORS_RED_GREY_BLUE	, false);
+
+	//	DataObject_Set_Colors(pMRRTF, 100, SG_COLORS_RED_GREY_BLUE	, true);
+		DataObject_Set_Colors(pMRRTF, 100, SG_COLORS_WHITE_RED		, false);
+
+		CSG_Grid	CF, VF, RF, DEM, Slopes, Percentiles;
+
+		VF.Create(*Get_System(), SG_DATATYPE_Float);
+		RF.Create(*Get_System(), SG_DATATYPE_Float);
+		CF.Create(*Get_System(), SG_DATATYPE_Float);
+		CF.Assign(1.0);
+
+		DEM.Create(*pDEM);
+
+		//-------------------------------------------------
+		Level		= 1;
+		Resolution	= Get_Cellsize();
+
+		Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), Level, _TL("step")));
+		Message_Add(CSG_String::Format(SG_T("%s: %d, %s: %.2f, %s %.2f"), _TL("step"), Level, _TL("resolution"), Resolution, _TL("threshold slope"), T_Slope));
+
+		Get_Slopes		(&DEM, &Slopes);
+		Get_Percentiles	(&DEM, &Percentiles, 3);
+		Get_Flatness	(&Slopes, &Percentiles, &CF, pMRVBF, pMRRTF, T_Slope);
+		UPDATE_VIEWS	(true);
+
+		//-------------------------------------------------
+		T_Slope		/= 2.0;
+		Level++;
+
+		Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), Level, _TL("step")));
+		Message_Add(CSG_String::Format(SG_T("%s: %d, %s: %.2f, %s %.2f"), _TL("step"), Level, _TL("resolution"), Resolution, _TL("threshold slope"), T_Slope));
+
+		Get_Percentiles	(&DEM, &Percentiles, 6);
+		Get_Flatness	(&Slopes, &Percentiles, &CF, &VF, &RF, T_Slope);
+		Get_MRVBF		(Level, pMRVBF, &VF, pMRRTF, &RF);
+		UPDATE_VIEWS	(false);
+
+		//-------------------------------------------------
+		while( Process_Get_Okay(false) && Resolution < max_Resolution )
+		{
+			Resolution	*= 3.0;
+			T_Slope		/= 2.0;
+			Level++;
+
+			Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), Level, _TL("step")));
+			Message_Add(CSG_String::Format(SG_T("%s: %d, %s: %.2f, %s %.2f"), _TL("step"), Level, _TL("resolution"), Resolution, _TL("threshold slope"), T_Slope));
+
+			Get_Values		(&DEM, &Slopes, &Percentiles, Resolution);
+			Get_Flatness	(&Slopes, &Percentiles, &CF, &VF, &RF, T_Slope);
+			Get_MRVBF		(Level, pMRVBF, &VF, pMRRTF, &RF);
+			UPDATE_VIEWS	(false);
+		}
+
+		if( Parameters("CLASSIFY")->asBool() )
+		{
+			Get_Classified(pMRVBF);
+			Get_Classified(pMRRTF);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CMRVBF::Get_Transformation(double x, double t, double p)
+{
+	return( 1.0 / (1.0 + pow(x / t, p)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Smoothed(CSG_Grid *pDEM, CSG_Grid *pSmoothed, int Radius, double Smoothing)
+{
+	if( pDEM && pSmoothed )
+	{
+		int		x, y, ix, iy, jx, jy, kx, ky;
+		double	d, s;
+
+		CSG_Grid	Kernel(SG_DATATYPE_Double, 1 + 2 * Radius, 1 + 2 * Radius);
+
+		for(iy=-Radius, ky=0; iy<=Radius; iy++, ky++)
+		{
+			for(ix=-Radius, kx=0; ix<=Radius; ix++, kx++)
+			{
+				Kernel.Set_Value(kx, ky, 4.3565 * exp(-SG_Get_Square(sqrt((double)ix*ix + iy*iy) / 3.0)) );
+			//	Kernel.Set_Value(kx, ky, exp(-(ix*ix + iy*iy) / (2.0 * s)) / (2.0 * M_PI * s));
+			}
+		}
+
+		pSmoothed->Create(pDEM, SG_DATATYPE_Float);
+
+		for(y=0; y<pDEM->Get_NY() && Set_Progress(y, pDEM->Get_NY()); y++)
+		{
+			for(x=0; x<pDEM->Get_NX(); x++)
+			{
+				for(iy=-Radius, jy=y-Radius, ky=0, s=d=0.0; iy<=Radius; iy++, jy++, ky++)
+				{
+					for(ix=-Radius, jx=x-Radius, kx=0; ix<=Radius; ix++, jx++, kx++)
+					{
+						if( pDEM->is_InGrid(jx, jy) )
+						{
+							s	+= Kernel.asDouble(kx, ky) * pDEM->asDouble(jx, jy);
+							d	+= Kernel.asDouble(kx, ky);
+						}
+					}
+				}
+
+				if( d > 0.0 )
+				{
+					pSmoothed->Set_Value(x, y, s / d);
+				}
+				else
+				{
+					pSmoothed->Set_NoData(x, y);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Values(CSG_Grid *pDEM, CSG_Grid *pSlopes, CSG_Grid *pPercentiles, double Resolution)
+{
+	if( pDEM && pDEM->is_Valid() && pSlopes && pPercentiles )
+	{
+		int			nx, ny;
+		CSG_Grid	Smoothed;
+
+		Get_Smoothed(pDEM, &Smoothed, 5, 3.0);
+		Get_Slopes(&Smoothed, pSlopes);
+
+		nx	= 2 + (int)(pDEM->Get_XRange() / Resolution);
+		ny	= 2 + (int)(pDEM->Get_YRange() / Resolution);
+
+		pDEM->Create(SG_DATATYPE_Float, nx, ny, Resolution, pDEM->Get_XMin(), pDEM->Get_YMin());
+		pDEM->Assign(&Smoothed, GRID_INTERPOLATION_NearestNeighbour);
+
+		Get_Percentiles(pDEM, pPercentiles, 6);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Percentile(CSG_Grid *pDEM, int x, int y, double &Percentile)
+{
+	if( pDEM && pDEM->is_Valid() && pDEM->is_InGrid(x, y, true) )
+	{
+		int		iRadius, iPoint, nPoints, nLower, ix, iy;
+		double	z	= pDEM->asDouble(x, y);
+
+		for(iRadius=0, nPoints=0, nLower=0; iRadius<m_Radius.Get_Maximum(); iRadius++)
+		{
+			for(iPoint=0; iPoint<m_Radius.Get_nPoints(iRadius); iPoint++)
+			{
+				m_Radius.Get_Point(iRadius, iPoint, ix, iy);
+
+				ix	+= x;
+				iy	+= y;
+
+				if( pDEM->is_InGrid(ix, iy) )
+				{
+					nPoints++;
+
+					if( pDEM->asDouble(ix, iy) < z )
+					{
+						nLower++;
+					}
+				}
+			}
+		}
+
+		if( nPoints > 1 )
+		{
+			Percentile	= (double)nLower / (double)(nPoints - 1.0);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Percentiles(CSG_Grid *pDEM, CSG_Grid *pPercentiles, int Radius)
+{
+	if( pDEM && pDEM->is_Valid() )
+	{
+		pPercentiles->Create(pDEM->Get_System(), SG_DATATYPE_Float);
+
+		m_Radius.Create(Radius);
+
+		for(int y=0; y<pDEM->Get_NY() && Set_Progress(y, pDEM->Get_NY()); y++)
+		{
+			for(int x=0; x<pDEM->Get_NX(); x++)
+			{
+				double	Percentile;
+
+				if( !Get_Percentile(pDEM, x, y, Percentile) )
+				{
+					pPercentiles->Set_NoData(x, y);
+				}
+				else
+				{
+					pPercentiles->Set_Value (x, y, Percentile);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Slopes(CSG_Grid *pDEM, CSG_Grid *pSlopes)
+{
+	if( pDEM && pDEM->is_Valid() )
+	{
+		pSlopes->Create(pDEM->Get_System(), SG_DATATYPE_Float);
+
+		for(int y=0; y<pDEM->Get_NY() && Set_Progress(y, pDEM->Get_NY()); y++)
+		{
+			for(int x=0; x<pDEM->Get_NX(); x++)
+			{
+				double	Slope, Aspect;
+
+				if( !pDEM->Get_Gradient(x, y, Slope, Aspect) )
+				{
+					pSlopes->Set_NoData(x, y);
+				}
+				else
+				{
+					pSlopes->Set_Value (x, y, 100.0 * tan(Slope));
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Flatness(CSG_Grid *pSlopes, CSG_Grid *pPercentiles, CSG_Grid *pCF, CSG_Grid *pVF, CSG_Grid *pRF, double T_Slope)
+{
+//	const int	Interpolation	= GRID_INTERPOLATION_Bilinear;
+	const int	Interpolation	= GRID_INTERPOLATION_BSpline;
+
+	if( pSlopes && pSlopes->is_Valid() && pPercentiles && pPercentiles->is_Valid() )
+	{
+		int		x, y;
+		double	xp, yp, Slope, Percentile, cf, vf, rf;
+
+		for(y=0, yp=Get_YMin(); y<Get_NY() && Set_Progress(y); y++, yp+=Get_Cellsize())
+		{
+			for(x=0, xp=Get_XMin(); x<Get_NX(); x++, xp+=Get_Cellsize())
+			{
+				if( pSlopes		->Get_Value(xp, yp, Slope     , Interpolation)
+				&&	pPercentiles->Get_Value(xp, yp, Percentile, Interpolation) )
+				{
+					cf	= pCF->asDouble(x, y) * Get_Transformation(Slope, T_Slope, m_P_Slope);
+					vf	= cf * Get_Transformation(      Percentile, m_T_Pctl_V, m_P_Pctl);
+					rf	= cf * Get_Transformation(1.0 - Percentile, m_T_Pctl_R, m_P_Pctl);
+
+					pCF->Set_Value	(x, y, cf);
+					pVF->Set_Value	(x, y, 1.0 - Get_Transformation(vf, 0.3, 4.0));
+					pRF->Set_Value	(x, y, 1.0 - Get_Transformation(rf, 0.3, 4.0));
+				}
+				else
+				{
+					pVF->Set_NoData	(x, y);
+					pRF->Set_NoData	(x, y);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CMRVBF::Get_MRVBF(int Level, CSG_Grid *pMRVBF, CSG_Grid *pVF, CSG_Grid *pMRRTF, CSG_Grid *pRF)
+{
+	if( pMRVBF && pVF && pMRRTF && pRF )
+	{
+		double	d, w, t, p;
+
+		t	= 0.4;
+		p	= log((Level - 0.5) / 0.1) / log(1.5);
+
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( !pMRVBF->is_NoData(x, y) && !pVF->is_NoData(x, y) )
+				{
+					d	= pVF->asDouble(x, y);
+					w	= 1.0 - Get_Transformation(d, t, p);
+					pMRVBF->Set_Value(x, y, w * (Level - 1 + d) + (1.0 - w) * pMRVBF->asDouble(x, y));
+				}
+
+				if( !pMRRTF->is_NoData(x, y) && !pRF->is_NoData(x, y) )
+				{
+					d	= pRF->asDouble(x, y);
+					w	= 1.0 - Get_Transformation(d, t, p);
+					pMRRTF->Set_Value(x, y, w * (Level - 1 + d) + (1.0 - w) * pMRRTF->asDouble(x, y));
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CMRVBF::Get_Classified(CSG_Grid *pMRF)
+{
+	if( pMRF && pMRF->is_Valid() )
+	{
+		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				if( !pMRF->is_NoData(x, y) )
+				{
+					double	d	= pMRF->asDouble(x, y);
+
+					if		( d < 0.5 )
+						pMRF->Set_Value(x, y, 0.0);
+					else if	( d < 1.5 )
+						pMRF->Set_Value(x, y, 1.0);
+					else if	( d < 2.5 )
+						pMRF->Set_Value(x, y, 2.0);
+					else if	( d < 3.5 )
+						pMRF->Set_Value(x, y, 3.0);
+					else if	( d < 4.5 )
+						pMRF->Set_Value(x, y, 4.0);
+					else if	( d < 5.5 )
+						pMRF->Set_Value(x, y, 5.0);
+					else
+						pMRF->Set_Value(x, y, 6.0);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/mrvbf.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        MRVBF.h                        //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__MRVBF_H
+#define HEADER_INCLUDED__MRVBF_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CMRVBF : public CSG_Module_Grid
+{
+public:
+	CMRVBF(void);
+	virtual ~CMRVBF(void);
+
+
+protected:
+
+	virtual bool				On_Execute				(void);
+
+
+private:
+
+	double						m_P_Slope, m_P_Pctl, m_T_Pctl_V, m_T_Pctl_R;
+
+	CSG_Grid_Radius				m_Radius;
+
+
+	double						Get_Transformation		(double x, double t, double p);
+
+	bool						Get_Percentile			(CSG_Grid *pDEM, int x, int y, double &Percentile);
+	bool						Get_Percentiles			(CSG_Grid *pDEM, CSG_Grid *pPercentile, int Radius);
+	bool						Get_Slopes				(CSG_Grid *pDEM, CSG_Grid *pSlope);
+	bool						Get_Smoothed			(CSG_Grid *pDEM, CSG_Grid *pSmoothed, int Radius, double Smoothing);
+	bool						Get_Values				(CSG_Grid *pDEM, CSG_Grid *pSlope, CSG_Grid *pPercentiles, double Resolution);
+
+	bool						Get_Flatness			(CSG_Grid *pSlope, CSG_Grid *pPctl, CSG_Grid *pF, CSG_Grid *pVB, CSG_Grid *pRT, double T_Slope);
+
+	bool						Get_MRVBF				(int Level, CSG_Grid *pMRVBF, CSG_Grid *pVF, CSG_Grid *pMRRTF, CSG_Grid *pRF);
+
+	bool						Get_Classified			(CSG_Grid *pMRF);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__MRVBF_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1475 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Relative_Heights.cpp                 //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "relative_heights.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CRelative_Heights::CRelative_Heights(void)
+{
+	//-----------------------------------------------------
+	Set_Name		(_TL("Relative Heights and Slope Positions"));
+
+	Set_Author		(SG_T("J.Boehner, O.Conrad (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+
+	//-----------------------------------------------------
+	Parameters.Add_Grid(
+		NULL	, "DEM"			, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "HO"			, _TL("Slope Height"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "HU"			, _TL("Valley Depth"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "NH"			, _TL("Normalized Height"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SH"			, _TL("Standardized Height"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "MS"			, _TL("Mid-Slope Positon"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "W"			, _TL("w"),
+		_TL(""),
+		PARAMETER_TYPE_Double	,  0.5, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "T"			, _TL("t"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 10.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL	, "E"			, _TL("e"),
+		_TL(""),
+		PARAMETER_TYPE_Double	,  2.0, 0.0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRelative_Heights::On_Execute(void)
+{
+	double		w, t, e;
+	CSG_Grid	*pDEM, *pHO, *pHU, *pNH, *pSH, *pMS;
+
+	//-----------------------------------------------------
+	pDEM		= Parameters("DEM")	->asGrid();
+
+	pHO			= Parameters("HO")	->asGrid();
+	pHU			= Parameters("HU")	->asGrid();
+	pNH			= Parameters("NH")	->asGrid();
+	pSH			= Parameters("SH")	->asGrid();
+	pMS			= Parameters("MS")	->asGrid();
+
+	w			= Parameters("W")	->asDouble();
+	t			= Parameters("T")	->asDouble();
+	e			= Parameters("E")	->asDouble();
+
+	//-----------------------------------------------------
+	Message_Add(_TL("Pass 1"));
+	Get_Heights(pDEM, pHO, true , w, t, e);
+
+	Message_Add(_TL("Pass 2"));
+	Get_Heights(pDEM, pHU, false, w, t, e);
+
+	Get_Results(pDEM, pHO, pHU, pNH, pSH);
+
+	//-----------------------------------------------------
+	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( pNH->is_NoData(x, y) )
+			{
+				pMS->Set_NoData(x, y);
+			}
+			else
+			{
+				pMS->Set_Value(x, y, fabs(2.0 * pNH->asDouble(x, y) - 1.0));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRelative_Heights::Get_Heights(CSG_Grid *pDEM, CSG_Grid *pH, bool bInverse, double w, double t, double e)
+{
+	CSG_Grid	Inverse;
+
+	//-----------------------------------------------------
+	if( bInverse )
+	{
+		Inverse.Create(pDEM);
+		Inverse.Assign(pDEM);
+		Inverse.Invert();
+		pDEM	= &Inverse;
+	}
+
+	//-----------------------------------------------------
+	Get_Heights_Catchment(pDEM, pH, w);
+
+	Get_Heights_Modified (pDEM, pH, t, e);
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CRelative_Heights::Get_Heights_Catchment(CSG_Grid *pDEM, CSG_Grid *pH, double Weight)
+{
+	const double	MFD_Converge	= 1.1;
+
+	int			n, x, y, i, ix, iy;
+	double		z, d, dz[8], dzSum, c, w, h;
+	CSG_Grid	C, W;
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Relative heights calculation..."));
+
+	C.Create(*Get_System());
+	W.Create(*Get_System());
+
+	C.	Assign(Get_System()->Get_Cellarea());
+	W.	Assign(0.0);
+	pH->Assign(0.0);
+
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( pDEM->is_NoData(n) )
+		{
+			pH->Set_NoData(n);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
+	{
+		if( pDEM->Get_Sorted(n, x, y) )
+		{
+			z		= pDEM->asDouble(x, y);
+			c		= C    .asDouble(x, y);
+			w		= W    .asDouble(x, y) + pow(1.0 / c, Weight);		//{W[p] = (1/C[p])^w;}
+			h		= pH  ->asDouble(x, y) + pow(1.0 / c, Weight) * z;	//{H[p] = (1/C[p])^w * M[p];}
+
+			pH->Set_Value(x, y, h / w - z);	//{H[p] = -1 * (M[p] - H[p]/W[p]);}
+
+			for(i=0, dzSum=0.0; i<8; i++)
+			{
+				ix		= Get_xTo(i, x);
+				iy		= Get_yTo(i, y);
+
+				if( pDEM->is_InGrid(ix, iy) && (d = z - pDEM->asDouble(ix, iy)) > 0.0 )
+				{
+					dzSum	+= (dz[i] = pow(atan(d / Get_Length(i)), MFD_Converge));
+				}
+				else
+				{
+					dz[i]	= 0.0;
+				}
+			}
+
+			if( dzSum > 0.0 )
+			{
+				for(i=0; i<8; i++)
+				{
+					if( dz[i] > 0.0 )
+					{
+						ix		= Get_xTo(i, x);
+						iy		= Get_yTo(i, y);
+
+						d		= dz[i] / dzSum;
+
+						C  .Add_Value(ix, iy, d * c);
+						W  .Add_Value(ix, iy, d * w);	//{W[p] = W[p] + W[p+pul] * UL[p] + W[p+pl] * LL[p] + W[p+pol] * OL[p] + W[p+po] * OO[p] + W[p+por] * OR[p] + W[p+pr] * RR[p] + W[p+pur] * UR[p] + W[p+pu] * UU[p]; gefunden = 1;}
+						pH->Add_Value(ix, iy, d * h);	//{H[p] = H[p] + H[p+pul] * UL[p] + H[p+pl] * LL[p] + H[p+pol] * OL[p] + H[p+po] * OO[p] + H[p+por] * OR[p] + H[p+pr] * RR[p] + H[p+pur] * UR[p] + H[p+pu] * UU[p]; gefunden = 1;}
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// in den folgenden drei Schritten werden Maxima der
+// relativen Höhe H in Abhängigkeit der Neigung gesaugt.
+// Der e-Parameter steuert die stärke der Maximum-Streckung
+
+//---------------------------------------------------------
+bool CRelative_Heights::Get_Heights_Modified(CSG_Grid *pDEM, CSG_Grid *pH, double t, double e)
+{
+	bool		bRecalculate;
+	int			x, y, i, ix, iy, n;
+	double		z, d;
+	CSG_Grid	H, H_Last, T;
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Modify: pre-processing..."));
+
+	T.Create(pH);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDEM->Get_Gradient(x, y, z, d) && !pH->is_NoData(x, y) )
+			{
+				pH->Set_Value(x, y, d = pow(pH->asDouble(x, y), e));	// {X[p] = H[p]^e;}
+				z	= pow(t, z);
+				z	= pow(1.0 / z, exp(z));
+				T.Set_Value(x, y, z);
+			}
+			else
+			{
+				T.Set_NoData(x, y);
+			}
+		}
+	}
+
+	H     .Create(*pH);
+	H_Last.Create(*pH);
+
+	//-----------------------------------------------------
+	for(i=0, n=1; n>0; i++)
+	{
+		for(y=0, n=0; y<Get_NY() && Process_Get_Okay(false); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !T.is_NoData(x, y) )
+				{
+					z	= T.asDouble(x, y) * Get_Local_Maximum(&H, x, y);
+
+					if( z  > H.asDouble(x, y) )
+					{
+						n++;
+
+						H.Set_Value(x, y, z);
+					}
+				}
+			}
+		}
+
+		if( n > 0 )
+		{
+			for(y=0, n=0; y<Get_NY() && Process_Get_Okay(false); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					if( H.asDouble(x, y) != H_Last.asDouble(x, y) )
+					{
+						n++;
+
+						H_Last.Set_Value(x, y, H.asDouble(x, y));
+					}
+				}
+			}
+		}
+
+		Process_Set_Text(CSG_String::Format(SG_T("Modify: %d. iteration [%d > 0]"), i, n));
+	}
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Modify: post-processing..."));
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			for(iy=y-1, bRecalculate=false; iy<=y+1 && !bRecalculate; iy++)
+			{
+				for(ix=x-1; ix<=x+1 && !bRecalculate; ix++)
+				{
+					if( H.is_InGrid(ix, iy) && pH->is_InGrid(ix, iy) && H.asDouble(ix, iy) > pH->asDouble(ix, iy) )
+					{
+						bRecalculate	= true;
+					}
+				}
+			}
+
+			if( bRecalculate )
+			{
+				for(iy=y-1, z=0.0, n=0; iy<=y+1; iy++)
+				{
+					for(ix=x-1; ix<=x+1; ix++)
+					{
+						if( H.is_InGrid(ix, iy) )
+						{
+							n++;
+							z	+= H.asDouble(ix, iy);
+						}
+					}
+				}
+
+				z	= z / (double)n;
+			}
+			else	
+			{
+				z	= H.asDouble(x, y);
+			}
+
+			pH->Set_Value(x, y, pow(z, 1.0 / e));
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+double CRelative_Heights::Get_Local_Maximum(CSG_Grid *pGrid, int x, int y)
+{
+	if( pGrid->is_InGrid(x, y) )
+	{
+		double	z	= pGrid->asDouble(x, y);
+
+		for(int i=0; i<8; i++)
+		{
+			int	ix	= Get_xTo(i, x);
+			int	iy	= Get_yTo(i, y);
+
+			if( pGrid->is_InGrid(ix, iy) && pGrid->asDouble(ix, iy) > z )
+			{
+				z	= pGrid->asDouble(ix, iy);
+			}
+		}
+
+		return( z );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// auf Grundlage von HO und HU wird die Normierte Höhe
+// (NH) mit Höhenwerten zwischen minimal 0 (=unten) und
+// maximal 1 (= oben) wie beim NDVI bestimmt. Die
+// Standardisierte Höhe SH streckt das Relief auf ein
+// Höhenspektrum zwischen theoretisch 0 (=unten) und
+// dem Maximum der jeweiligen Scheitelbereiche, so dass
+// die ursprüngliche Reliefenergie erhalten bleibt.
+// Selbstverständlich muss für Anwendungen überprüft
+// werden, ob und welche relativen Höhen (HU, HO, SH)
+// logarithmiert dargestellt werden. Als Beispiel ist
+// die Standardisierte Höhe logarithmiert berechnet (SHL)
+
+//---------------------------------------------------------
+bool CRelative_Heights::Get_Results(CSG_Grid *pDEM, CSG_Grid *pHO, CSG_Grid *pHU, CSG_Grid *pNH, CSG_Grid *pSH)
+{
+	int		x, y;
+	double	ho, hu, nh, hMin;
+
+	Process_Set_Text(_TL("Final processing..."));
+
+	hMin	= pDEM->Get_ZMin();
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pDEM->is_NoData(x, y) && !pHO->is_NoData(x, y) && !pHU->is_NoData(x, y) )
+			{
+				ho	= pHO->asDouble(x, y);
+				hu	= pHU->asDouble(x, y);
+
+				nh	= 0.5 * (1.0 + (ho - hu) / (ho + hu));
+
+				pNH->Set_Value(x, y, nh);
+				pSH->Set_Value(x, y, nh * (pDEM->asDouble(x, y) - hMin) + hMin);	//, nh * pDEM->asDouble(x, y));
+			}
+			else
+			{
+				pNH->Set_NoData(x, y);
+				pSH->Set_NoData(x, y);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//        The original BSL script by J.Böhner
+//---------------------------------------------------------
+
+/*
+Matrix Loop, O("sch-hoe.grd"), N("sch-nei.grd"), M, R, UL, LL, OL, OO, OR, RR, UR, UU, X, Y, Z, C, W, H, HO, HU, NH, SH, SHL;
+Point ploop, p, pul, pu, pur, pl, pr, pol, po, por;
+Float w, e, wul, wll, wol, woo, wor, wrr, wur, wuu;
+Integer t, h, i, j, k, l, m, n, o, gefunden;
+
+w = 0.5;
+e = 2; 
+t = 10; 
+pul.x = -1;	pul.y = -1; 
+pu.x = 0;	pu.y = -1;
+pur.x = 1;	pur.y = -1;
+pl.x = -1;	pl.y = 0;
+pr.x = 1;	pr.y = 0;
+pol.x = -1;	pol.y = 1;
+po.x = 0;	po.y = 1;
+por.x = 1;	por.y = 1;
+
+M = O;
+R = O;
+UL = O;
+LL = O;
+OL = O;
+OO = O;
+OR = O;
+RR = O;
+UR = O;
+UU = O;
+X = O;
+Y = O;
+Z = O;
+C = O;
+W = O;
+H = O;
+HO = O;
+HU = O;
+NH = O;
+SH = O;
+SHL = O;
+
+Loop.xanz = 100000;
+Loop.yanz = 1;
+h = 0;
+i = 0;
+j = 0;
+k = 0;
+l = 0;
+m = 0;
+n = 0;
+o = 0;
+
+// Das gesamte Verfahren besteht aus zwei identischen Schritten zur Bestimmung von Höhe über Kulmination (HO) und Höhe unter Kulmination (HU). Für HO wird das DGM zunächst umgedreht //
+foreach p in M do 
+{M[p] = -1 * O[p];}
+// hier wird eine Hilfsmatrix X erzeugt, die in der folgenden Schleife fafür sorgt, dass noch nicht attributisierte Rasterzellen in Ihrer Position identifiziert werden können //
+foreach p in X do
+{	if (p.x == 0 || p.x == M.xanz - 1 || p.y == 0 || p.y == M.yanz - 1)
+	{X[p] = -10000;}
+	else
+	{X[p] = M[p];}
+}
+// hier wird eine Matrix R erzeugt, die ausgehend von lokalen Maxima fortlaufend Rangplatzziffernerzeugt //
+foreach ploop in Loop do
+{	ploop.x = 1;
+	h = h +1;
+	gefunden = 0;
+	foreach p in X do
+	{
+	if (X[p] == max9(p, X) && X[p] > -10000)
+	{X[p] = -10000; R[p] = h; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(R);
+// hier wird eine Hilfsmatrix R erzeugt, die Rangplatzziffern am Rand duch 0 ersetzt //
+foreach p in R do
+{	if (p.x == 0 || p.x == M.xanz - 1 || p.y == 0 || p.y == M.yanz - 1)
+	{R[p] = 0;}
+	else
+	{R[p] = R[p];}
+}
+// hier wird eine Matrix Z erzeugt, die die positiven Winkel zu den 8 Nachbarzellen aufsummiert //
+foreach p in Z do
+{
+if(p.x == 0 && p.y == 0)
+	{
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((woo + wor + wrr) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = woo + wor + wrr;}
+	}
+else
+{
+if(p.x == 0 && p.y == (M.yanz - 1))
+	{
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wrr + wur + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1 && p.y == M.yanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1 && p.y == 0)
+	{
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((wll + wol + woo) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wll + wol + woo;}
+	}
+else	
+{
+if(p.x == 0)
+	{
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((woo + wor + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = woo + wor + wrr + wur + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wol + woo + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wol + woo + wuu;}
+	}
+else	
+{
+if(p.y == 0)
+	{
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((wll + wol + woo + wor + wrr) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wll + wol + woo + wor + wrr;}
+	}
+else	
+{
+if(p.y == M.yanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wrr + wur + wuu;}
+	}
+else	
+{	
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wol + woo + wor + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wol + woo + wor + wrr + wur + wuu;}
+	}
+}}}}}}}}
+// hier werden Grids UL bis UU (im Uhrzeigersinn) erzeugt, die angeben, welchen Anteil des Inhalts einer benachbarten Rasterzelle in die Zielrasterzelle (zentrale Rasterzelle im 9er Feld) übergen wird //
+foreach p in UL do
+{	if (p.x == 0 || p.y == 0)
+	{UL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pul]) < 0 && Z[p+pul] > 0) 
+		{UL[p] = (atan((M[p+pul] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pul];}
+		else
+		{UL[p] = 0;}
+		}
+}
+foreach p in LL do
+{	if (p.x == 0)
+	{LL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pl]) < 0 && Z[p+pl] > 0) 
+		{LL[p] = (atan((M[p+pl] - M[p])/M.dxy))/Z[p+pl];}
+		else
+		{LL[p] = 0;}
+		}
+}
+foreach p in OL do
+{	if (p.x == 0 || p.y == M.yanz - 1)
+	{OL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pol]) < 0 && Z[p+pol] > 0) 
+		{OL[p] = (atan((M[p+pol] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pol];}
+		else
+		{OL[p] = 0;}
+		}
+}
+foreach p in OO do
+{	if (p.y == M.yanz - 1)
+	{OO[p] = 0;}
+	else	{
+		if((M[p] - M[p+po]) < 0 && Z[p+po] > 0) 
+		{OO[p] = (atan((M[p+po] - M[p])/M.dxy))/Z[p+po];}
+		else
+		{OO[p] = 0;}
+		}
+}
+foreach p in OR do
+{	if (p.x == M.xanz - 1 || p.y == M.yanz - 1)
+	{OR[p] = 0;}
+	else	{
+		if((M[p] - M[p+por]) < 0 && Z[p+por] > 0) 
+		{OR[p] = (atan((M[p+por] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+por];}
+		else
+		{OR[p] = 0;}
+		}
+}
+foreach p in RR do
+{	if (p.x == M.xanz - 1)
+	{RR[p] = 0;}
+	else	{
+		if((M[p] - M[p+pr]) < 0 && Z[p+pr] > 0) 
+		{RR[p] = (atan((M[p+pr] - M[p])/M.dxy))/Z[p+pr];}
+		else
+		{RR[p] = 0;}
+		}
+}
+foreach p in UR do
+{	if (p.x == M.xanz - 1 || p.y == 0)
+	{UR[p] = 0;}
+	else	{
+		if((M[p] - M[p+pur]) < 0 && Z[p+pur] > 0) 
+		{UR[p] = (atan((M[p+pur] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pur];}
+		else
+		{UR[p] = 0;}
+		}
+}
+foreach p in UU do
+{	if (p.y == 0)
+	{UU[p] = 0;}
+	else	{
+		if((M[p] - M[p+pu]) < 0 && Z[p+pu] > 0) 
+		{UU[p] = (atan((M[p+pu] - M[p])/M.dxy))/Z[p+pu];}
+		else
+		{UU[p] = 0;}
+		}
+}
+// in den folgenden drei Schritten wird nach der "multiple flow methode" die Einzugsgebietsgröße C ermittelt //
+foreach p in Z do
+{Z[p] = 1;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	i = i +1;
+	gefunden = 0;
+	foreach p in Z do
+	{	if (R[p] == i)
+		{Z[p] = 1 + Z[p+pul] * UL[p] + Z[p+pl] * LL[p] + Z[p+pol] * OL[p] + Z[p+po] * OO[p] + Z[p+por] * OR[p] + Z[p+pr] * RR[p] + Z[p+pur] * UR[p] + Z[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(Z);
+foreach p in C do
+{C[p] = Z[p] * M.dxy^2;}
+// in den folgenden zwei Schritten werden Gewichte umgekehrt-proportional zur Einzugsgebietsgröße nach der multiple flow methode aufsummiert. Der w-parameter steuert die stärke der Gewichtung //
+foreach p in W do
+{W[p] = (1/C[p])^w;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	k = k +1;
+	gefunden = 0;
+	foreach p in W do
+	{	if (R[p] == k)
+		{W[p] = W[p] + W[p+pul] * UL[p] + W[p+pl] * LL[p] + W[p+pol] * OL[p] + W[p+po] * OO[p] + W[p+por] * OR[p] + W[p+pr] * RR[p] + W[p+pur] * UR[p] + W[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(W);
+// in den folgenden zwei Schritten werden Höhenwerte und Gewichte nach der multiple flow methode in der Matrix H aufsummiert, wobei lokale Maxima im Einzugsgebiet am stärksten in H eingehen. Der w-Parameter steuert die Stärke der Maximumgewichtung //
+foreach p in H do
+{H[p] = M[p] * (1/C[p])^w;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	l = l +1;
+	gefunden = 0;
+	foreach p in H do
+	{	if (R[p] == l)
+		{H[p] = H[p] + H[p+pul] * UL[p] + H[p+pl] * LL[p] + H[p+pol] * OL[p] + H[p+po] * OO[p] + H[p+por] * OR[p] + H[p+pr] * RR[p] + H[p+pur] * UR[p] + H[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(H);
+// im folgenden Schritt wird eine relative Höhe H über dem gewichteten arithmetischen Mittel der Einzugsgebietsgröße bestimmt //
+foreach p in H do
+{	if (isRand(p, M) == 0)
+	{H[p] = -1 * (M[p] - H[p]/W[p]);}
+}
+setRandN(H);
+// in den folgenden drei Schritten werden Maxima der relativen Höhe H in Abhängigkeit der Neigung gesaugt. Der e-Parameter steuert die stärke der Maximum-Streckung //
+foreach p in X do
+{X[p] = H[p]^e;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	m = m +1;
+	gefunden = 0;
+	foreach p in X do
+	{
+	if ((((1/t^N[p])^exp(t^N[p])) * max9(p, X)) > X[p])
+	{X[p] = (((1/t^N[p])^exp(t^N[p])) * max9(p, X)); gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+foreach p in HO do
+{	if (isRand(p, M) == 0)
+	{
+	if(H[p]^e < X[p] || H[p+pul]^e < X[p+pul] || H[p+pl]^e < X[p+pl] || H[p+pol]^e < X[p+pol] || H[p+po]^e < X[p+po] || H[p+por]^e < X[p+por] || H[p+pr]^e < X[p+pr] || H[p+pur]^e < X[p+pur] || H[p+pu]^e < X[p+pu])
+	{HO[p] = ((X[p] + X[p+pul] + X[p+pu] + X[p+pur] + X[p+pl] + X[p+pr] + X[p+pol] + X[p+po] + X[p+por])/9)^(1/e);}
+	else	
+	{HO[p] = X[p]^(1/e);}
+	}
+}
+setRandN(HO);	
+foreach p in Z do
+{
+h = 0;
+i = 0;
+j = 0;
+k = 0;
+l = 0;
+m = 0;
+}
+// hier wird das DGM nicht umgedreht //
+foreach p in M do 
+{M[p] = O[p];}
+// hier wird eine Hilfsmatrix X erzeugt, die in der folgenden Schleife fafür sorgt, dass noch nicht attributisierte Rasterzellen in Ihrer Position identifiziert werden können //
+foreach p in X do
+{	if (p.x == 0 || p.x == M.xanz - 1 || p.y == 0 || p.y == M.yanz - 1)
+	{X[p] = -10000;}
+	else
+	{X[p] = M[p];}
+}
+// hier wird eine Matrix R erzeugt, die ausgehend von lokalen Maxima fortlaufend Rangplatzziffernerzeugt //
+foreach ploop in Loop do
+{	ploop.x = 1;
+	h = h +1;
+	gefunden = 0;
+	foreach p in X do
+	{
+	if (X[p] == max9(p, X) && X[p] > -10000)
+	{X[p] = -10000; R[p] = h; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(R);
+// hier wird eine Hilfsmatrix R erzeugt, die Rangplatzziffern am Rand duch 0 ersetzt //
+foreach p in R do
+{	if (p.x == 0 || p.x == M.xanz - 1 || p.y == 0 || p.y == M.yanz - 1)
+	{R[p] = 0;}
+	else
+	{R[p] = R[p];}
+}
+// hier wird eine Matrix Z erzeugt, die die positiven Winkel zu den 8 Nachbarzellen aufsummiert //
+foreach p in Z do
+{
+if(p.x == 0 && p.y == 0)
+	{
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((woo + wor + wrr) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = woo + wor + wrr;}
+	}
+else
+{
+if(p.x == 0 && p.y == (M.yanz - 1))
+	{
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wrr + wur + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1 && p.y == M.yanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1 && p.y == 0)
+	{
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((wll + wol + woo) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wll + wol + woo;}
+	}
+else	
+{
+if(p.x == 0)
+	{
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((woo + wor + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = woo + wor + wrr + wur + wuu;}
+	}
+else	
+{
+if(p.x == M.xanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wol + woo + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wol + woo + wuu;}
+	}
+else	
+{
+if(p.y == 0)
+	{
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((wll + wol + woo + wor + wrr) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wll + wol + woo + wor + wrr;}
+	}
+else	
+{
+if(p.y == M.yanz - 1)
+	{
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wrr + wur + wuu;}
+	}
+else	
+{	
+	if((M[p] - M[p+pul]) > 0) 
+	{wul = atan	((M[p] - M[p+pul])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wul = 0;}
+	if((M[p] - M[p+pl]) > 0) 
+	{wll = atan	((M[p] - M[p+pl])	/	M.dxy);}
+	else
+	{wll = 0;}
+	if((M[p] - M[p+pol]) > 0) 
+	{wol = atan	((M[p] - M[p+pol])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wol = 0;}
+	if((M[p] - M[p+po]) > 0) 
+	{woo = atan	((M[p] - M[p+po])	/	M.dxy);}
+	else
+	{woo = 0;}
+	if((M[p] - M[p+por]) > 0) 
+	{wor = atan	((M[p] - M[p+por])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wor = 0;}
+	if((M[p] - M[p+pr]) > 0) 
+	{wrr = atan	((M[p] - M[p+pr])	/	M.dxy);}
+	else
+	{wrr = 0;}
+	if((M[p] - M[p+pur]) > 0) 
+	{wur = atan	((M[p] - M[p+pur])	/	(2 * M.dxy^2)^0.5);}
+	else
+	{wur = 0;}
+	if((M[p] - M[p+pu]) > 0) 
+	{wuu = atan	((M[p] - M[p+pu])	/	M.dxy);}
+	else
+	{wuu = 0;}
+	if((wul + wll + wol + woo + wor + wrr + wur + wuu) == 0)
+	{Z[p] = 0;}
+	else
+	{Z[p] = wul + wll + wol + woo + wor + wrr + wur + wuu;}
+	}
+}}}}}}}}
+// hier werden Grids UL bis UU (im Uhrzeigersinn) erzeugt, die angeben, welchen Anteil des Inhalts einer benachbarten Rasterzelle in die Zielrasterzelle (zentrale Rasterzelle im 9er Feld) übergen wird //
+foreach p in UL do
+{	if (p.x == 0 || p.y == 0)
+	{UL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pul]) < 0 && Z[p+pul] > 0) 
+		{UL[p] = (atan((M[p+pul] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pul];}
+		else
+		{UL[p] = 0;}
+		}
+}
+foreach p in LL do
+{	if (p.x == 0)
+	{LL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pl]) < 0 && Z[p+pl] > 0) 
+		{LL[p] = (atan((M[p+pl] - M[p])/M.dxy))/Z[p+pl];}
+		else
+		{LL[p] = 0;}
+		}
+}
+foreach p in OL do
+{	if (p.x == 0 || p.y == M.yanz - 1)
+	{OL[p] = 0;}
+	else	{
+		if((M[p] - M[p+pol]) < 0 && Z[p+pol] > 0) 
+		{OL[p] = (atan((M[p+pol] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pol];}
+		else
+		{OL[p] = 0;}
+		}
+}
+foreach p in OO do
+{	if (p.y == M.yanz - 1)
+	{OO[p] = 0;}
+	else	{
+		if((M[p] - M[p+po]) < 0 && Z[p+po] > 0) 
+		{OO[p] = (atan((M[p+po] - M[p])/M.dxy))/Z[p+po];}
+		else
+		{OO[p] = 0;}
+		}
+}
+foreach p in OR do
+{	if (p.x == M.xanz - 1 || p.y == M.yanz - 1)
+	{OR[p] = 0;}
+	else	{
+		if((M[p] - M[p+por]) < 0 && Z[p+por] > 0) 
+		{OR[p] = (atan((M[p+por] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+por];}
+		else
+		{OR[p] = 0;}
+		}
+}
+foreach p in RR do
+{	if (p.x == M.xanz - 1)
+	{RR[p] = 0;}
+	else	{
+		if((M[p] - M[p+pr]) < 0 && Z[p+pr] > 0) 
+		{RR[p] = (atan((M[p+pr] - M[p])/M.dxy))/Z[p+pr];}
+		else
+		{RR[p] = 0;}
+		}
+}
+foreach p in UR do
+{	if (p.x == M.xanz - 1 || p.y == 0)
+	{UR[p] = 0;}
+	else	{
+		if((M[p] - M[p+pur]) < 0 && Z[p+pur] > 0) 
+		{UR[p] = (atan((M[p+pur] - M[p])/(2 * M.dxy^2)^0.5))/Z[p+pur];}
+		else
+		{UR[p] = 0;}
+		}
+}
+foreach p in UU do
+{	if (p.y == 0)
+	{UU[p] = 0;}
+	else	{
+		if((M[p] - M[p+pu]) < 0 && Z[p+pu] > 0) 
+		{UU[p] = (atan((M[p+pu] - M[p])/M.dxy))/Z[p+pu];}
+		else
+		{UU[p] = 0;}
+		}
+}
+// in den folgenden drei Schritten wird nach der "multiple flow methode" die Einzugsgebietsgröße C ermittelt //
+foreach p in Z do
+{Z[p] = 1;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	i = i +1;
+	gefunden = 0;
+	foreach p in Z do
+	{	if (R[p] == i)
+		{Z[p] = 1 + Z[p+pul] * UL[p] + Z[p+pl] * LL[p] + Z[p+pol] * OL[p] + Z[p+po] * OO[p] + Z[p+por] * OR[p] + Z[p+pr] * RR[p] + Z[p+pur] * UR[p] + Z[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(Z);
+foreach p in C do
+{C[p] = Z[p] * M.dxy^2;}
+// in den folgenden zwei Schritten werden Gewichte umgekehrt-proportional zur Einzugsgebietsgröße nach der multiple flow methode aufsummiert. Der w-parameter steuert die stärke der Gewichtung //
+foreach p in W do
+{W[p] = (1/C[p])^w;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	k = k +1;
+	gefunden = 0;
+	foreach p in W do
+	{	if (R[p] == k)
+		{W[p] = W[p] + W[p+pul] * UL[p] + W[p+pl] * LL[p] + W[p+pol] * OL[p] + W[p+po] * OO[p] + W[p+por] * OR[p] + W[p+pr] * RR[p] + W[p+pur] * UR[p] + W[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(W);
+// in den folgenden zwei Schritten werden Höhenwerte und Gewichte nach der multiple flow methode in der Matrix H aufsummiert, wobei lokale Maxima im Einzugsgebiet am stärksten in H eingehen. Der w-Parameter steuert die Stärke der Maximumgewichtung //
+foreach p in H do
+{H[p] = M[p] * (1/C[p])^w;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	l = l +1;
+	gefunden = 0;
+	foreach p in H do
+	{	if (R[p] == l)
+		{H[p] = H[p] + H[p+pul] * UL[p] + H[p+pl] * LL[p] + H[p+pol] * OL[p] + H[p+po] * OO[p] + H[p+por] * OR[p] + H[p+pr] * RR[p] + H[p+pur] * UR[p] + H[p+pu] * UU[p]; gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+setRandN(H);
+// im folgenden Schritt wird eine relative Höhe H über dem gewichteten arithmetischen Mittel der Einzugsgebietsgröße bestimmt //
+foreach p in H do
+{	if (isRand(p, M) == 0)
+	{H[p] = -1 * (M[p] - H[p]/W[p]);}
+}
+setRandN(H);
+// in den folgenden drei Schritten werden Maxima der relativen Höhe H in Abhängigkeit der Neigung gesaugt. Der e-Parameter steuert die stärke der Maximum-Streckung //
+foreach p in X do
+{X[p] = H[p]^e;}
+foreach ploop in Loop do
+{	ploop.x = 1;
+	m = m +1;
+	gefunden = 0;
+	foreach p in X do
+	{
+	if ((((1/t^N[p])^exp(t^N[p])) * max9(p, X)) > X[p])
+	{X[p] = (((1/t^N[p])^exp(t^N[p])) * max9(p, X)); gefunden = 1;}
+	}
+	if (gefunden == 0)
+	{ploop.x = 100000;}
+}
+foreach p in HU do
+{	if (isRand(p, M) == 0)
+	{
+	if(H[p]^e < X[p] || H[p+pul]^e < X[p+pul] || H[p+pl]^e < X[p+pl] || H[p+pol]^e < X[p+pol] || H[p+po]^e < X[p+po] || H[p+por]^e < X[p+por] || H[p+pr]^e < X[p+pr] || H[p+pur]^e < X[p+pur] || H[p+pu]^e < X[p+pu])
+	{HU[p] = (((X[p] + X[p+pul] + X[p+pu] + X[p+pur] + X[p+pl] + X[p+pr] + X[p+pol] + X[p+po] + X[p+por])/9)^(1/e));}
+	else	
+	{HU[p] = (X[p]^(1/e));}
+	}
+}
+setRandN (HU);
+showMatrix(HO);
+showMatrix(HU);
+// auf Grundlage von HO und HU wird die Normierte Höhe (NH) mit Höhenwerten zwischen minimal 0 (=unten) und maximal 1 (= oben) wie beim NDVI bestimmt. Die Standardisierte Höhe SH streckt das Relief auf ein Höhenspektrum zwischen theoretisch 0 (=unten) und dem Maximum der jeweiligen Scheitelbereiche, so dass die ursprüngliche Reliefenergie erhalten bleibt. Selbstverständlich muss für Anwendungen überprüft werden, ob und welche relativen Höhen (HU, HO, SH) logarithmiert dargestellt werden. Als Beispiel ist die Standardisierte Höhe logarithmiert berechnet (SHL) //
+foreach p in NH do
+{NH[p] = 0.5 * (1 + ((HO[p] - HU[p])/(HO[p] + HU[p])));}
+showMatrix(NH);
+foreach p in SH do
+{SH[p] = NH[p] * O[p];}
+showMatrix(SH);
+foreach p in SHL do
+{SHL[p] = ln(SH[p]);}
+showMatrix(SHL);
+/**/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/relative_heights.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,104 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Relative_Heights.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     conrad at geowiss.uni-hamburg.de          //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Relative_Heights_H
+#define HEADER_INCLUDED__Relative_Heights_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CRelative_Heights : public CSG_Module_Grid
+{
+public:
+	CRelative_Heights(void);
+
+
+protected:
+
+	virtual bool				On_Execute	(void);
+
+
+private:
+
+	bool						Get_Heights				(CSG_Grid *pDEM, CSG_Grid *pH, bool bInverse, double w, double t, double e);
+	bool						Get_Heights_Catchment	(CSG_Grid *pDEM, CSG_Grid *pH, double w);
+	bool						Get_Heights_Modified	(CSG_Grid *pDEM, CSG_Grid *pH, double t, double e);
+	double						Get_Local_Maximum		(CSG_Grid *pGrid, int x, int y);
+	bool						Get_Results				(CSG_Grid *pDEM, CSG_Grid *pHO, CSG_Grid *pHU, CSG_Grid *pNH, CSG_Grid *pSH);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Relative_Heights_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,263 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    wind_effect.cpp                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                    Andre Ringeler                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringeler at saga-gis.org                 //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wind_effect.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWind_Effect::CWind_Effect(void)
+{
+	Set_Name		(_TL("Wind Effect (Windward/Leeward Index)"));
+
+	Set_Author		(SG_T("J.Boehner, A.Ringeler (c) 2008"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Parameters.Add_Grid(	NULL, "ELEVATION"	, _TL("Elevation")			, _TL(""), PARAMETER_INPUT);
+	Parameters.Add_Grid(	NULL, "RESULT"		, _TL("Wind Effect")		, _TL(""), PARAMETER_OUTPUT);
+
+	Parameters.Add_Value(	NULL, "DIRECT"		, _TL("Wind Direction")		, _TL(""), PARAMETER_TYPE_Double, 135.0);
+	Parameters.Add_Value(	NULL, "MAXDIST"		, _TL("Max. Distance [km]")	, _TL(""), PARAMETER_TYPE_Double, 300.0);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWind_Effect::On_Execute(void)
+{
+	int		x, y;
+
+	double	Direction_RAD, Wr, dLuvB, dLee, dx, dy, LUV, LEE;
+
+	//-----------------------------------------------------
+	pDTM			= Parameters("ELEVATION")	->asGrid();
+	pLeeLuv			= Parameters("RESULT")		->asGrid();
+
+	Direction_RAD	= Parameters("DIRECT")		->asDouble() * M_DEG_TO_RAD;
+	max_Distance	= Parameters("MAXDIST")		->asDouble() * 1000.0;
+
+
+	//-----------------------------------------------------
+	dx		= sin(Direction_RAD);
+	dy		= cos(Direction_RAD);
+
+	if( fabs(dx) > fabs(dy) )
+	{
+		dy	/= fabs(dx);
+		dx	= dx < 0 ? -1 : 1;
+	}
+	else
+	{
+		dx	/= fabs(dy);
+		dy	= dy < 0 ? -1 : 1;
+	}
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( pDTM->is_NoData(x,y) )
+			{
+				pLeeLuv->Set_NoData(x,y);
+			}
+			else
+			{
+				Wr	=	Get_LUV(x,y, dx, dy);
+				Get_LEE_LUV(x,y,-dx,-dy,dLuvB,dLee);
+
+				Wr += dLuvB;
+
+				if(Wr > 0.0)
+					LUV = 1 + log(1+Wr);
+				else
+					LUV = 1.0 / (1 + log(1 - Wr));
+
+				if (dLee>0.0)
+					LEE = sqrt ( 1 + log (1 + dLee));
+				else
+					LEE = 1.0/ sqrt ( 1 + log (1 - dLee));
+
+				pLeeLuv->Set_Value(x,y,sqrt(sqrt( LUV*LEE)));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CWind_Effect::Get_LUV(int x, int y, double dx, double dy)
+{
+	double	ix, iy, Dist, SumDhi, Sum, dxy,  SumWeight ,z;
+
+	dxy			= Get_Cellsize() * sqrt(dx*dx + dy*dy);
+	Dist		= 0.0;
+	SumWeight	= 0.0;
+	Sum			= 0.0;
+	SumDhi      = 0.0;
+
+	z = pDTM->asDouble(x,y);
+
+	for(ix=x+0.5, iy=y+0.5; ; )
+	{
+		Dist	+= dxy;
+
+		ix		+= dx;
+		iy		+= dy;
+
+		x		= (int)ix;
+		y		= (int)iy;
+
+		if( !is_InGrid(x,y) || Dist > max_Distance )
+		{
+			break;
+		}
+		else if( !pDTM->is_NoData(x,y) )
+		{
+			SumDhi += 1/Dist;  
+			
+			Sum			+= 1/Dist * atan2 ( z-pDTM->asDouble(x,y) ,sqrt(Dist));
+		}
+	}
+
+	if( SumDhi > 0 )
+	{
+		Sum		/= SumDhi;
+	}
+
+	return( Sum );
+}
+
+//---------------------------------------------------------
+void CWind_Effect::Get_LEE_LUV(int x, int y, double dx, double dy, double &SumA, double &SumB)
+{
+	double	ix, iy, Dist, dxy, z,
+			SumWeightA,
+			SumWeightB;
+
+	dxy			= Get_Cellsize() * sqrt(dx*dx + dy*dy);
+	Dist		= 0.0;
+	SumWeightA	= 0.0;
+	SumA		= 0.0;
+	SumWeightB	= 0.0;
+	SumB		= 0.0;
+
+					z = pDTM->asDouble(x,y);
+
+	for(ix=x+0.5, iy=y+0.5; ; )
+	{
+		Dist	+= dxy;
+
+		ix		+= dx;
+		iy		+= dy;
+
+		x		= (int)ix;
+		y		= (int)iy;
+		
+		if( !is_InGrid(x,y) || Dist > max_Distance )
+		{
+			break;
+		}
+	
+		else if( !pDTM->is_NoData(x,y) )
+		{
+
+			SumWeightA  += 1 / Dist;  
+			
+			SumA    	+= 1 / Dist * atan2 ( z - pDTM->asDouble(x,y) ,sqrt(Dist));
+
+			
+			SumWeightB	+= 1 / log(Dist);  
+			
+			SumB		+= 1 / log(Dist) * atan2 ( z - pDTM->asDouble(x,y) ,sqrt(Dist));
+		}
+	}
+
+	if( SumWeightA > 0 )
+	{
+		SumA		/= SumWeightA;
+	}
+
+	if( SumWeightB > 0 )
+	{
+		SumB		/= SumWeightB;
+	}
+}
\ No newline at end of file

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_morphometry/wind_effect.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_morphometry                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     wind_effect.h                     //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                     Andre Ringeler                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringeler at saga-gis.org                 //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__LeeLuv_B_H
+#define HEADER_INCLUDED__LeeLuv_B_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWind_Effect : public CSG_Module_Grid
+{
+public:
+	CWind_Effect(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+
+	double				factor_Lee, factor_Luv, max_Distance;
+
+	CSG_Grid			*pDTM, *pLeeLuv;
+
+
+	double				Get_LUV			(int x, int y, double dx, double dy);
+	void				Get_LEE_LUV		(int x, int y, double dx, double dy, double &SumA, double &SumB);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__LeeLuv_B_H
\ No newline at end of file

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,291 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     FillSinks.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de                         //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "FillSinks.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CFillSinks::CFillSinks(void)
+{
+	Set_Name(_TL("Fill Sinks (Planchon/Darboux, 2001)"));
+
+	Set_Author(_TL("Copyrights (c) 2003 by Volker Wichmann"));
+
+	Set_Description	(_TW(
+		"Depression filling algorithm after Olivier Planchon & Frederic Darboux (2001)\n\n"
+		"Planchon, O. & F. Darboux (2001):\n"
+		"  A fast, simple and versatile algorithm to fill the depressions of digital elevation models.\n"
+		"  Catena 46: 159-176\n\n"
+
+		"(c) 2003 Volker Wichmann\n"
+		"email: volker.wichmann at geographie.uni-muenchen.de")
+	);
+
+
+	Parameters.Add_Grid(
+		NULL, "DEM"		, _TL("DEM"),
+		_TL("digital elevation model [m]"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "RESULT"	, _TL("Filled DEM"),
+		_TL("processed DEM"),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "MINSLOPE", _TL("Slope"),
+		_TL("minimum slope angle preserved from one cell to the next, zero results in flat areas [Degree]"),
+		PARAMETER_TYPE_Double, 0.01
+	);
+}
+
+//---------------------------------------------------------
+CFillSinks::~CFillSinks(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+// Sink filling algorithm after:						 //
+// Planchon, O. & F. Darboux (2001): A fast, simple and  //
+// versatile algorithm to fill the depressions of		 //
+// digital elevation models. Catena 46: 159-176			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+bool CFillSinks::On_Execute(void)
+{
+	bool	something_done;
+	int		x, y, scan, ix, iy, i, it;
+	double	z, wz, wzn, minslope;
+
+	pDEM		= Parameters("DEM")->asGrid();
+	pResult		= Parameters("RESULT")->asGrid();
+
+	minslope	= tan(Parameters("MINSLOPE")->asDouble() * M_DEG_TO_RAD);
+
+	pW			= new CSG_Grid(SG_DATATYPE_Double, pDEM->Get_NX(), pDEM->Get_NY(), pDEM->Get_Cellsize(), pDEM->Get_XMin(), pDEM->Get_YMin());
+	pBorder		= new CSG_Grid(SG_DATATYPE_Int   , pDEM->Get_NX(), pDEM->Get_NY(), pDEM->Get_Cellsize(), pDEM->Get_XMin(), pDEM->Get_YMin());
+
+	pW->Assign_NoData();
+	pBorder->Assign_NoData();
+
+	for(i=0; i<8; i++)
+		epsilon[i] = minslope * Get_Length(i);
+
+	R0[0] = 0; R0[1] = Get_NY()-1; R0[2] = 0; R0[3] = Get_NY()-1; R0[4] = 0; R0[5] = Get_NY()-1; R0[6] = 0; R0[7] = Get_NY()-1;
+	C0[0] = 0; C0[1] = Get_NX()-1; C0[2] = Get_NX()-1; C0[3] = 0; C0[4] = Get_NX()-1; C0[5] = 0; C0[6] = 0; C0[7] = Get_NX()-1;
+	dR[0] = 0; dR[1] = 0; dR[2] = 1; dR[3] = -1; dR[4] = 0; dR[5] = 0; dR[6] = 1; dR[7] = -1;
+	dC[0] = 1; dC[1] = -1; dC[2] = 0; dC[3] = 0; dC[4] = -1; dC[5] = 1; dC[6] = 0; dC[7] = 0;
+	fR[0] = 1; fR[1] = -1; fR[2] = -Get_NY()+1; fR[3] = Get_NY()-1; fR[4] = 1; fR[5] = -1; fR[6] = -Get_NY()+1; fR[7] = Get_NY()-1;
+	fC[0] = -Get_NX()+1, fC[1] = Get_NX()-1; fC[2] = -1; fC[3] = 1; fC[4] = Get_NX()-1; fC[5] = -Get_NX()+1; fC[6] = 1; fC[7] = -1;
+
+	Init_Altitude();															// Stage 1
+
+	for(x=0; x<Get_NX(); x++)													// Stage 2, Section 1
+	{
+		for(y=0; y<Get_NY(); y++)
+		{
+			if( pBorder->asInt(x, y) == 1 )
+				Dry_upward_cell(x, y);
+		}
+	}
+
+	for(it=0; it<1000; it++)
+	{
+		for(scan=0; scan<8 && Set_Progress(scan,8); scan++)					// Stage 2, Section 2
+		{
+			R = R0[scan];
+			C = C0[scan];
+			something_done = false;
+
+			do 
+			{
+				if( !pDEM->is_NoData(C, R) && ((wz = pW->asDouble(C, R)) > (z = pDEM->asDouble(C, R))) )
+				{
+					for(i=0; i<8; i++)
+					{
+						ix	= Get_xTo(i, C);		
+						iy	= Get_yTo(i, R);	
+
+						if(	pDEM->is_InGrid(ix, iy) )
+						{
+							if( z >= (wzn = (pW->asDouble(ix, iy) + epsilon[i])) )	// operation 1
+							{
+								pW->Set_Value(C, R, z);
+								something_done = true;
+								Dry_upward_cell(C, R);
+								break;
+							}
+							if( wz > wzn )											// operation 2
+							{
+								pW->Set_Value(C, R, wzn);
+								something_done = true;
+							}
+						}
+					}
+				}
+			}while( Next_Cell(scan) );
+
+			if( something_done == false )
+				break;
+		}
+
+	if( something_done == false )
+		break;
+	}
+	
+	pResult->Assign(pW);
+
+
+	//-----------------------------------------------------
+	delete pW;
+	delete pBorder;
+
+	return( true );
+}
+
+void CFillSinks::Dry_upward_cell(int x, int y)
+{
+	int const	MAX_DEPTH = 32000;													// recursion stack, maybe not needed??
+	int			depth = 0;
+	int			ix, iy, i;
+	double		zn;
+
+	depth += 1;
+	
+	if( depth <= MAX_DEPTH )
+	{
+		for(i=0; i<8; i++)
+		{
+			ix	= Get_xTo(i, x);		
+			iy	= Get_yTo(i, y);	
+			
+			if(	is_InGrid(ix, iy) && pW->asDouble(ix, iy) == 50000 )
+			{
+				if( (zn = pDEM->asDouble(ix , iy)) >= (pW->asDouble(x, y) + epsilon[i]) )
+				{
+					pW->Set_Value(ix, iy, zn);
+					Dry_upward_cell(ix, iy);
+				}
+			}
+		}
+	}
+	depth -= 1;
+}
+
+
+
+void CFillSinks::Init_Altitude()
+{
+	bool	border;
+	int		x, y, i, ix, iy;
+
+	for(x=0; x<Get_NX(); x++)
+	{
+		for(y=0; y<Get_NY(); y++)
+		{
+			border = false;
+
+			if( !pDEM->is_NoData(x, y) )
+			{
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_xTo(i, x);		
+					iy	= Get_yTo(i, y);	
+
+					if(	!pDEM->is_InGrid(ix, iy) )			
+					{
+						border = true;
+						break;
+					}
+				}
+				if( border == true )
+				{
+					pBorder->Set_Value(x, y, 1);
+					pW->Set_Value(x, y, pDEM->asDouble(x, y));
+				}
+				else
+					pW->Set_Value(x, y, 50000.0);
+			}
+		}
+	}	
+}
+
+
+
+bool CFillSinks::Next_Cell(int i)
+{
+
+	R	= R + dR[i];
+	C	= C + dC[i];
+
+	if( R < 0 || C < 0 || R >= Get_NY() || C >= Get_NX() )
+	{
+		R	= R + fR[i];
+		C	= C + fC[i];
+
+		if( R < 0 || C < 0 || R >= Get_NY() || C >= Get_NX() )
+			return (false);
+	}
+
+	return (true);
+}

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      FillSinks.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail: volker.wichmann at geographie.uni-muenchen.de //
+//                                                       //
+//    contact:    Volker Wichmann                        //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__FillSinks_H
+#define HEADER_INCLUDED__FillSinks_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_preprocessor_EXPORT CFillSinks : public CSG_Module_Grid
+{
+public:
+	CFillSinks(void);
+	virtual ~CFillSinks(void);
+
+
+protected:
+
+	virtual bool		On_Execute		(void);
+
+
+private:
+	
+	int					R, C, R0[8], C0[8], dR[8], dC[8], fR[8], fC[8];
+
+	double				epsilon[8];
+
+	CSG_Grid				*pDEM, *pResult, *pW, *pBorder;
+
+
+	bool				Next_Cell		(int i);
+	void				Init_Altitude	(void);
+	void				Dry_upward_cell	(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__FillSinks_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,288 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    FillSinks_WL.cpp                   //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de					     //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "FillSinks_WL.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+CFillSinks_WL::CFillSinks_WL(void)
+{
+
+	Set_Name		(_TL("Fill Sinks (Wang & Liu)"));
+	Set_Author		(_TL("Copyrights (c) 2007 by Volker Wichmann"));
+	Set_Description	(_TW(
+		"This module uses an algorithm proposed by Wang & Liu to identify and fill surface depressions in "
+		"digital elevation models.\n"
+		"The method was enhanced to allow the creation of hydrologic sound elevation models, i.e. not only to "
+		"fill the depression(s) but also to preserve a downward slope along the flow path. If desired, this is accomplished "
+		"by preserving a minimum slope gradient (and thus elevation difference) between cells.\n"
+		"This is the fully featured version of the module creating a depression less DEM, a flow path grid and "
+		"a grid with watershed basins. If you encounter problems processing large data sets "
+		"(e.g. LIDAR data) with this module try the basic version (Fill Sinks XXL).\n\n\n"
+		"References:\n"
+		"Wang, L. & H. Liu (2006): An efficient method for identifying and filling surface depressions in "
+		"digital elevation models for hydrologic analysis and modelling. International Journal of Geographical "
+		"Information Science, Vol. 20, No. 2: 193-213.\n"
+	));
+
+
+	Parameters.Add_Grid(	
+		NULL, "ELEV", _TL("DEM"), 
+		_TL("Digital elevation model"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(	
+		NULL, "FILLED", _TL("Filled DEM"), 
+		_TL("Depression-free digital elevation model"),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "FDIR", _TL("Flow Directions"),
+		_TL("Computed flow directions, 0=N, 1=NE, 2=E, ... 7=NW"),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "WSHED", _TL("Watershed Basins"),
+		_TL("Delineated watershed basins"),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "MINSLOPE", _TL("Minimum Slope"),
+		_TL("Minimum slope gradient to preserve from cell to cell; with a value of zero sinks are filled up to the spill elevation (which results in flat areas). Unit [Degree]"),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true
+	);
+
+}
+
+//---------------------------------------------------------
+CFillSinks_WL::~CFillSinks_WL(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+
+bool CFillSinks_WL::On_Execute(void)		
+{
+	CSG_Grid	*pElev, *pSeed, *pFdir, *pWshed;
+	PriorityQ	theQueue;
+	CFillSinks_WL_Node		tempNode;
+
+	int			x, y, ix, iy, i;
+	int			inverse[8] = { 4, 5, 6, 7, 0, 1, 2, 3 };
+	double		z, iz, progress;
+	double		minslope, mindiff[8];
+	bool		preserve;
+	long		id;
+
+	pElev		= Parameters("ELEV")->asGrid();
+	pFilled		= Parameters("FILLED")->asGrid();
+	pFdir		= Parameters("FDIR")->asGrid();
+	pWshed		= Parameters("WSHED")->asGrid();
+	minslope	= Parameters("MINSLOPE")->asDouble();		
+
+
+	if( minslope > 0.0 )
+	{
+		minslope = tan(minslope * M_DEG_TO_RAD);
+		for(i=0; i<8; i++)
+			mindiff[i] = minslope * Get_Length(i);
+		preserve = true;
+	}
+	else
+		preserve = false;
+
+
+	pSeed	= (CSG_Grid *) new CSG_Grid(SG_DATATYPE_Bit, pElev->Get_NX(), pElev->Get_NY(), pElev->Get_Cellsize(), pElev->Get_XMin(), pElev->Get_YMin());
+	
+	pFilled->Assign_NoData();
+	pWshed->Assign_NoData();
+	pFdir->Assign_NoData();
+	pSeed->Assign(0.0);
+
+
+	
+	// fill priority queue with boundary, i.e. seed cells
+	id = 0;
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pElev->is_NoData(x, y) )
+			{
+				for(i=0; i<8; i++)
+				{
+					ix = Get_xTo(i, x);
+					iy = Get_yTo(i, y);
+					if( !is_InGrid(ix, iy) || pElev->is_NoData(ix, iy) )
+					{
+						z = pElev->asDouble(x, y);
+						pFilled->Set_Value(x, y, z);
+						pSeed->Set_Value(x, y, 1.0);
+						pWshed->Set_Value(x, y, id);
+						id += 1;
+
+						tempNode.x		= x;
+						tempNode.y		= y;
+						tempNode.spill	= z;
+						theQueue.push( tempNode );
+						break;
+					}
+				}
+			}
+		}
+	}
+
+	// work through least cost path
+	progress = 0.0;
+
+	while( !theQueue.empty() )
+	{
+		PriorityQ::value_type tempNode = theQueue.top();
+
+		x = tempNode.x;
+		y = tempNode.y;
+		theQueue.pop();
+
+		id	= (long) pWshed->asDouble(x, y);
+		z	= pFilled->asDouble(x, y);
+
+		for(i=0; i<8; i++)
+		{
+			ix = Get_xTo(i, x);
+			iy = Get_yTo(i, y);
+			if( is_InGrid(ix, iy) && !pElev->is_NoData(ix, iy) )
+			{
+				if( pFilled->is_NoData(ix, iy) )
+				{
+					iz = pElev->asDouble(ix, iy);
+
+					if( preserve )
+					{
+						if( iz < (z + mindiff[i]) )
+							iz = z + mindiff[i];
+					}
+					else if( iz <= z )
+					{
+						iz = z;
+						pFdir->Set_Value(ix, iy, inverse[i]);
+					}
+
+					tempNode.x		= ix;
+					tempNode.y		= iy;
+					tempNode.spill	= iz;
+					theQueue.push( tempNode );
+
+					pFilled->Set_Value(ix, iy, iz);
+					pWshed->Set_Value(ix, iy, id);
+				}
+				else if( pSeed->asInt(ix, iy) == 1 )
+					pWshed->Set_Value(ix, iy, id);
+			}
+		}
+
+		if( pFdir->is_NoData(x, y) )
+			pFdir->Set_Value(x, y, Get_Dir(x, y, z));
+
+
+		progress += 1.0;
+		if( ((int)progress) % 10000 == 0 )
+			Set_Progress(progress, pElev->Get_NCells());
+			//DataObject_Update(pFilled, pElev->Get_ZMin(), pElev->Get_ZMax(), true);
+		
+	}
+
+
+	delete (pSeed);
+	return (true);
+}
+
+
+int CFillSinks_WL::Get_Dir(int x, int y, double z)
+{
+	int		ix, iy, i, steepestn;
+	double	iz, max, gradient;
+
+	max = 0.0;
+	steepestn = -1;
+
+	for(i=0; i<8; i++)
+	{
+		ix = Get_xTo(i, x);
+		iy = Get_yTo(i, y);
+
+		if(	is_InGrid(ix, iy) && !pFilled->is_NoData(ix, iy) && (iz = pFilled->asDouble(ix, iy)) < z)
+		{
+			gradient = (z - iz) / Get_Length(i);
+			if( max < gradient )
+			{
+				max = gradient;
+				steepestn = i;
+			}
+		}
+	}
+
+	return (steepestn);
+}
\ No newline at end of file

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,149 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    FillSinks_WL.h                     //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de					     //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__FillSinks_WL_H
+#define HEADER_INCLUDED__FillSinks_WL_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+#include <iostream>
+#include <queue>
+#include <vector>
+using namespace std;
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CFillSinks_WL_Node
+{
+public:
+	CFillSinks_WL_Node() : spill( 0 ) {}
+		~CFillSinks_WL_Node(){}
+
+	struct Greater : public binary_function< CFillSinks_WL_Node, CFillSinks_WL_Node, bool >
+	{
+		bool operator()(const CFillSinks_WL_Node n1, const CFillSinks_WL_Node n2) const
+		{
+			return n1.spill > n2.spill;
+		}
+	};
+
+	int		x;
+	int		y;
+	double	spill;
+};
+
+
+
+//---------------------------------------------------------
+class ta_preprocessor_EXPORT CFillSinks_WL : public CSG_Module_Grid
+{
+public:
+	CFillSinks_WL(void);
+	virtual ~CFillSinks_WL(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	typedef				vector< CFillSinks_WL_Node > nodeVector;
+	typedef				priority_queue< CFillSinks_WL_Node, nodeVector, CFillSinks_WL_Node::Greater > PriorityQ;
+
+	CSG_Grid			*pFilled;
+
+	int					Get_Dir(int x, int y, double z);
+
+};
+
+//---------------------------------------------------------
+class ta_preprocessor_EXPORT CFillSinks_WL_XXL : public CSG_Module_Grid
+{
+public:
+	CFillSinks_WL_XXL(void);
+	virtual ~CFillSinks_WL_XXL(void);
+
+
+protected:
+
+	virtual bool		On_Execute(void);
+
+
+private:
+
+	typedef		vector< CFillSinks_WL_Node > nodeVector;
+	typedef		priority_queue< CFillSinks_WL_Node, nodeVector, CFillSinks_WL_Node::Greater > PriorityQ;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__FillSinks_WL_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL_XXL.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL_XXL.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/FillSinks_WL_XXL.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,221 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    FillSinks_WL.cpp                   //
+//                                                       //
+//                 Copyright (C) 2007 by                 //
+//                    Volker Wichmann                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     reklovw at web.de					     //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "FillSinks_WL.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Construction/Destruction				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+CFillSinks_WL_XXL::CFillSinks_WL_XXL(void)
+{
+
+	Set_Name		(_TL("Fill Sinks XXL (Wang & Liu)"));
+	Set_Author		(_TL("Copyrights (c) 2007 by Volker Wichmann"));
+	Set_Description	(_TW(
+		"This module uses an algorithm proposed by Wang & Liu to identify and fill surface depressions in "
+		"digital elevation models.\n"
+		"The method was enhanced to allow the creation of hydrologic sound elevation models, i.e. not only to "
+		"fill the depression(s) but also to preserve a downward slope along the flow path. If desired, this is accomplished "
+		"by preserving a minimum slope gradient (and thus elevation difference) between cells.\n"
+		"This version of the module is designed to work on large data sets (e.g. LIDAR data), with smaller "
+		"datasets you might like to check out the fully featured standard version of the module.\n\n\n"
+		"References:\n"
+		"Wang, L. & H. Liu (2006): An efficient method for identifying and filling surface depressions in "
+		"digital elevation models for hydrologic analysis and modelling. International Journal of Geographical "
+		"Information Science, Vol. 20, No. 2: 193-213.\n"
+	));
+
+
+	Parameters.Add_Grid(	
+		NULL, "ELEV", _TL("DEM"), 
+		_TL("Digital elevation model"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(	
+		NULL, "FILLED", _TL("Filled DEM"), 
+		_TL("Depression-free digital elevation model"),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL, "MINSLOPE", _TL("Minimum Slope"),
+		_TL("Minimum slope gradient to preserve from cell to cell; with a value of zero sinks are filled up to the spill elevation (which results in flat areas). Unit [Degree]"),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true
+	);
+
+}
+
+//---------------------------------------------------------
+CFillSinks_WL_XXL::~CFillSinks_WL_XXL(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+
+bool CFillSinks_WL_XXL::On_Execute(void)		
+{
+	CSG_Grid	*pElev, *pFilled;
+	PriorityQ	theQueue;
+	CFillSinks_WL_Node		tempNode;
+
+	int			x, y, ix, iy, i;
+	double		z, iz, progress;
+	double		minslope, mindiff[8];
+	bool		preserve;
+
+
+	pElev		= Parameters("ELEV")->asGrid();
+	pFilled		= Parameters("FILLED")->asGrid();
+	minslope	= Parameters("MINSLOPE")->asDouble();		
+
+
+	if( minslope > 0.0 )
+	{
+		minslope = tan(minslope * M_DEG_TO_RAD);
+		for(i=0; i<8; i++)
+			mindiff[i] = minslope * Get_Length(i);
+		preserve = true;
+	}
+	else
+		preserve = false;
+
+	
+	pFilled->Assign_NoData();
+	
+
+	// fill priority queue with boundary cells, i.e. seed cells
+	for(y=0; y<Get_NY(); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !pElev->is_NoData(x, y) )
+			{
+				for(i=0; i<8; i++)
+				{
+					ix = Get_xTo(i, x);
+					iy = Get_yTo(i, y);
+					if( !is_InGrid(ix, iy) || pElev->is_NoData(ix, iy) )
+					{
+						z = pElev->asDouble(x, y);
+
+						tempNode.x		= x;
+						tempNode.y		= y;
+						tempNode.spill	= z;
+						theQueue.push( tempNode );
+
+						pFilled->Set_Value(x, y, z);
+						break;
+					}
+				}
+			}
+		}
+	}
+
+
+	// process queue
+	progress = 0.0;
+
+	while( !theQueue.empty() )
+	{
+		PriorityQ::value_type tempNode = theQueue.top();
+
+		x = tempNode.x;
+		y = tempNode.y;
+		theQueue.pop();
+
+		z = pFilled->asDouble(x, y);
+
+		for(i=0; i<8; i++)
+		{
+			ix = Get_xTo(i, x);
+			iy = Get_yTo(i, y);
+			if( is_InGrid(ix, iy) && !pElev->is_NoData(ix, iy) && pFilled->is_NoData(ix, iy) )
+			{
+				iz = pElev->asDouble(ix, iy);
+
+				if( preserve )
+				{
+					if( iz < (z + mindiff[i]) )
+						iz = z + mindiff[i];
+				}
+				else if( iz < z )
+					iz = z;
+
+				tempNode.x		= ix;
+				tempNode.y		= iy;
+				tempNode.spill	= iz;
+				theQueue.push( tempNode );
+
+				pFilled->Set_Value(ix, iy, iz);
+			}
+		}
+
+		progress += 1.0;
+		if( ((int)progress) % 10000 == 0 )
+			Set_Progress(progress, pElev->Get_NCells());
+			//DataObject_Update(pFilled, pElev->Get_ZMin(), pElev->Get_ZMax(), true);
+		
+	}
+
+	return (true);
+}
+

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,141 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Terrain Analysis - Preprocessing" ));
+
+	case MLB_INFO_Author:
+		return( _TL("Olaf Conrad (c) 2001, Volker Wichmann (c) 2003") );
+
+	case MLB_INFO_Description:
+		return( _TL("Tools for the preprocessing of digital terrain models." ));
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Terrain Analysis|Preprocessing" ));
+	}
+}
+
+
+//---------------------------------------------------------
+#include "Pit_Router.h"
+#include "Pit_Eliminator.h"
+#include "FillSinks.h"
+#include "FillSinks_WL.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	CSG_Module	*pModule;
+
+	switch( i )
+	{
+	case 0:
+		pModule	= new CPit_Router;
+		break;
+
+	case 1:
+		pModule	= new CPit_Eliminator;
+		break;
+
+	case 2:
+		pModule	= new CFillSinks;
+		break;
+
+	case 3:
+		pModule	= new CFillSinks_WL;
+		break;
+
+	case 4:
+		pModule	= new CFillSinks_WL_XXL;
+		break;
+
+	default:
+		pModule	= NULL;
+		break;
+	}
+
+	return( pModule );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,82 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                   Terrain_Analysis                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    ta_preprocessor                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ta_preprocessor_H
+#define HEADER_INCLUDED__ta_preprocessor_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#ifdef ta_preprocessor_EXPORTS
+	#define	ta_preprocessor_EXPORT	_SAGA_DLL_EXPORT
+#else
+	#define	ta_preprocessor_EXPORT	_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ta_preprocessor_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,419 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Pit_Eliminator.cpp                   //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Pit_Eliminator.h"
+#include "Pit_Router.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPit_Eliminator::CPit_Eliminator(void)
+{
+	Set_Name		(_TL("Sink Removal"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2001"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Parameters.Add_Grid(
+		NULL, "DEM"			, _TL("DEM"),
+		_TL("Digital Elevation Model that has to be processed"),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL, "SINKROUTE"	, _TL("Sink Route"),
+		_TL(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Grid(
+		NULL, "DEM_PREPROC", _TL("Preprocessed DEM"),
+		_TL("Preprocessed DEM. If this is not set changes will be stored in the original DEM grid."),
+		PARAMETER_OUTPUT_OPTIONAL
+	);
+
+	Parameters.Add_Choice(
+		NULL, "METHOD"		, _TL("Method"),
+		_TL(""),
+		CSG_String::Format(SG_T("%s|%s|"),
+			_TL("Deepen Drainage Routes"),
+			_TL("Fill Sinks")
+		), 1
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THRESHOLD"	, _TL("Threshold"),
+		_TL(""),
+		PARAMETER_TYPE_Bool
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THRSHEIGHT"	, _TL("Threshold Height"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100
+	);
+}
+
+//---------------------------------------------------------
+CPit_Eliminator::~CPit_Eliminator(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPit_Eliminator::On_Execute(void)
+{
+	bool		bResult, bKillRoute;
+	int			Method, nPits;
+	CPit_Router	Router;
+
+	//-----------------------------------------------------
+	bResult	= true;
+
+	pRoute	= Parameters("SINKROUTE")	->asGrid();
+	Method	= Parameters("METHOD")		->asInt();
+	pDTM	= Parameters("DEM_PREPROC")	->asGrid();
+
+	if( pDTM == NULL )
+	{
+		pDTM	= Parameters("DEM")->asGrid();
+	}
+	else if( pDTM != Parameters("DEM")->asGrid() )
+	{
+		pDTM->Assign(Parameters("DEM")->asGrid());
+	}
+
+	//-----------------------------------------------------
+	bKillRoute	= pRoute == NULL;
+
+	if( bKillRoute )
+	{
+		pRoute	= SG_Create_Grid(pDTM);
+		nPits	= Router.Get_Routes(pDTM, pRoute, Parameters("THRESHOLD")->asBool() ? Parameters("THRSHEIGHT")->asDouble() : -1.0);
+	}
+	else
+	{
+		nPits	= 1;
+	}
+
+	//-----------------------------------------------------
+	if( nPits > 0 )
+	{
+		Process_Set_Text(_TL("Initializing direction matrix..."));
+
+		Create_goRoute();
+
+		//-------------------------------------------------
+		switch( Method )
+		{
+		case 0:
+			Process_Set_Text(_TL("I'm diggin'..."));
+			bResult	= Dig_Channels();
+			break;
+
+		case 1:
+			Process_Set_Text(_TL("I'm fillin'..."));
+			bResult	= Fill_Sinks();
+			break;
+
+		default:
+			bResult	= false;
+			break;
+		}
+
+		delete( goRoute );
+	}
+
+	//-----------------------------------------------------
+	if( bKillRoute )
+	{
+		delete(pRoute);
+	}
+
+	Lock_Destroy();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPit_Eliminator::Create_goRoute(void)
+{
+	int		x, y;
+
+	goRoute	= SG_Create_Grid(pRoute);
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( !is_InGrid(x,y) )
+			{
+				goRoute->Set_NoData(x, y);
+			}
+			else if( pRoute->asChar(x, y) > 0 )
+			{
+				goRoute->Set_Value(x, y, pRoute->asChar(x, y) % 8 );
+			}
+			else
+			{
+				goRoute->Set_Value(x, y, pDTM->Get_Gradient_NeighborDir(x, y));
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPit_Eliminator::Dig_Channels(void)
+{
+	bool	bPit;
+	int		x, y, i, ix, iy;
+	double	z;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			z		= pDTM->asDouble(x, y);
+
+			for(i=0, bPit=true; i<8 && bPit; i++)
+			{
+				ix		= Get_xTo(i, x);
+				iy		= Get_yTo(i, y);
+
+				if( !is_InGrid(ix, iy) || z > pDTM->asDouble(ix, iy) )
+				{
+					bPit	= false;
+				}
+			}
+
+			if( bPit )
+			{
+				Dig_Channel(x, y);
+			}
+		}
+	}
+
+	return( is_Progress() );
+}
+
+
+//---------------------------------------------------------
+void CPit_Eliminator::Dig_Channel(int x, int y)
+{
+	bool	bContinue;
+	int		goDir;
+	double	z;
+
+	z			= pDTM->asDouble(x, y);
+	bContinue	= true;
+
+	do
+	{
+		z		-= M_ALMOST_ZERO;
+		goDir	= goRoute->asChar(x, y);
+
+		if( goDir < 0 )
+		{
+			bContinue	= false;
+		}
+		else
+		{
+			x	= Get_xTo(goDir, x);
+			y	= Get_yTo(goDir, y);
+
+			if( !is_InGrid(x, y) || z > pDTM->asDouble(x, y) )
+			{
+				bContinue	= false;
+			}
+			else
+			{
+				pDTM->Set_Value(x, y, z);
+			}
+		}
+	}
+	while( bContinue );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPit_Eliminator::Fill_Sinks(void)
+{
+	int		x, y;
+
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			Fill_Check(x, y);
+		}
+	}
+
+	return( is_Progress() );
+}
+
+//---------------------------------------------------------
+void CPit_Eliminator::Fill_Check(int x, int y)
+{
+	bool	bOutlet;
+	int		i, ix, iy, j;
+	double	z;
+
+	z	= pDTM		->asDouble	(x, y);
+	i	= goRoute	->asChar	(x, y);
+
+	ix	= Get_xTo(i, x);
+	iy	= Get_yTo(i, y);
+
+	if( !is_InGrid(ix, iy) || z > pDTM->asDouble(ix, iy) )
+	{
+		for(i=0, j=4, bOutlet=false; i<8 && !bOutlet; i++, j=(j+1)%8)
+		{
+			ix	= Get_xTo(i, x);
+			iy	= Get_yTo(i, y);
+
+			if( is_InGrid(ix, iy) && goRoute->asChar(ix, iy) == j && z > pDTM->asDouble(ix, iy) )
+			{
+				bOutlet	= true;
+			}
+		}
+
+		if( bOutlet )
+		{
+			Lock_Create();
+			Lock_Set(x, y);
+
+			for(i=0, j=4; i<8; i++, j=(j+1)%8)
+			{
+				ix	= Get_xTo(i, x);
+				iy	= Get_yTo(i, y);
+
+				Fill_Sink(ix, iy, j, z);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CPit_Eliminator::Fill_Sink(int x, int y, int j, double z)
+{
+	int		i, ix, iy;
+
+	if( is_InGrid(x, y) && !is_Locked(x, y) && goRoute->asChar(x, y) == j )
+	{
+		Lock_Set(x, y);
+
+		z	+= M_ALMOST_ZERO * Get_UnitLength(j);
+
+		if( pDTM->asDouble(x, y) < z )
+		{
+			pDTM->Set_Value(x, y, z);
+
+			for(i=0, j=4; i<8; i++, j=(j+1)%8)
+			{
+				ix	= Get_xTo(i, x);
+				iy	= Get_yTo(i, y);
+
+				Fill_Sink(ix, iy, j, z);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Eliminator.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Pit_Eliminator.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Pit_Eliminator_H
+#define HEADER_INCLUDED__Pit_Eliminator_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_preprocessor_EXPORT CPit_Eliminator : public CSG_Module_Grid
+{
+public:
+	CPit_Eliminator(void);
+	virtual ~CPit_Eliminator(void);
+
+
+protected:
+
+	virtual bool			On_Execute		(void);
+
+
+private:
+
+	CSG_Grid					*pDTM, *pRoute, *goRoute;
+
+
+	void					Create_goRoute	(void);
+
+	bool					Dig_Channels	(void);
+	void					Dig_Channel		(int x, int y);
+
+	bool					Fill_Sinks		(void);
+	void					Fill_Check		(int x, int y);
+	void					Fill_Sink		(int x, int y, int j, double z);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Pit_Eliminator_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1132 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Pit_Router.cpp                     //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "Pit_Router.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define	IS_Flat(a,b)		(a==b)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CPit_Router::CPit_Router(void)
+{
+	Set_Name		(_TL("Sink Drainage Route Detection"));
+
+	Set_Author		(SG_T("O. Conrad (c) 2001"));
+
+	Set_Description	(_TW(
+		""
+	));
+
+	Parameters.Add_Grid(
+		NULL	, "ELEVATION"	, _TL("Elevation"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid(
+		NULL	, "SINKROUTE"	, _TL("Sink Route"),
+		_TL(""),
+		PARAMETER_OUTPUT
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THRESHOLD"	, _TL("Threshold"),
+		_TL(""),
+		PARAMETER_TYPE_Bool
+	);
+
+	Parameters.Add_Value(
+		NULL	, "THRSHEIGHT"	, _TL("Threshold Height"),
+		_TL(""),
+		PARAMETER_TYPE_Double	, 100
+	);
+}
+
+//---------------------------------------------------------
+CPit_Router::~CPit_Router(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPit_Router::On_Execute(void)
+{
+	return( Get_Routes(
+		Parameters("ELEVATION")->asGrid(),
+		Parameters("SINKROUTE")->asGrid(),
+		Parameters("THRESHOLD")->asBool() ? Parameters("THRSHEIGHT")->asDouble() : -1.0
+	) >= 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CPit_Router::Get_Routes(CSG_Grid *pDEM, CSG_Grid *pRoute, double Threshold)
+{
+	int			iPit, nPits, n;
+	TPit_Outlet	*pOutlet, *pNext;
+
+	//-----------------------------------------------------
+	m_pDEM		= pDEM;
+	m_pRoute	= pRoute;
+	m_Threshold	= Threshold;
+
+	//-----------------------------------------------------
+	m_pPits		= NULL;
+	m_Pit		= NULL;
+
+	m_pFlats	= NULL;
+	m_Flat		= NULL;
+
+	m_Outlets	= NULL;
+
+	//-----------------------------------------------------
+	Get_System()->Assign(m_pDEM->Get_System());
+
+	//-----------------------------------------------------
+	if( Initialize() )
+	{
+		//-------------------------------------------------
+		// 1. Pits/Flats finden...
+
+		SG_UI_Process_Set_Text(_TL("Find Pits"));
+
+		nPits	= Find_Pits();
+
+		if( nPits > 0 )
+		{
+			//---------------------------------------------
+			// 2. Pit/Flat-Zugehoerigkeiten u. pot. m_Outlets finden...
+
+			SG_UI_Process_Set_Text(_TL("Find Outlets"));
+
+			Find_Outlets(nPits);
+
+
+			//---------------------------------------------
+			// 3. Routing vornehmen...
+
+			SG_UI_Process_Set_Text(_TL("Routing"));
+
+			iPit	= 0;
+
+			do
+			{
+				pOutlet	= m_Outlets;
+
+				while( pOutlet && SG_UI_Process_Get_Okay(false) )
+				{
+					pNext	= pOutlet->Next;
+					n		= Find_Route(pOutlet);
+
+					if( n > 0 )
+					{
+						pOutlet	= m_Outlets;
+						iPit	+= n;
+						SG_UI_Process_Set_Progress(iPit, nPits);
+					}
+					else
+					{
+						pOutlet	= pNext;
+					}
+				}
+
+				if( iPit < nPits )	// Thresholding may have prevented total removal of pits...
+				{
+					for(n=0; n<nPits; n++)
+					{
+						if( !m_Pit[n].bDrained )
+						{
+							m_Pit[n].bDrained	= true;
+							iPit++;
+							break;
+						}
+					}
+				}
+			}
+			while( iPit < nPits && SG_UI_Process_Set_Progress(iPit, nPits) );
+		}
+
+
+		//-------------------------------------------------
+		// 4. Threshold
+
+		if( m_Threshold > 0.0 )
+		{
+			nPits	-= Process_Threshold();
+		}
+	}
+
+	//-----------------------------------------------------
+	Process_Set_Text(_TL("Finalize"));
+
+	Finalize();
+
+	if( Process_Get_Okay(false) )
+	{
+		if( nPits > 0 )
+		{
+			Message_Add(CSG_String::Format(_TL("%d sinks have been processed."), nPits));
+
+			return( nPits );
+		}
+		else
+		{
+			Message_Add(_TL("No sinks have been detected."));
+		}
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CPit_Router::Initialize(void)
+{
+	if(	m_pDEM && m_pDEM->is_Valid()
+	&&	m_pRoute && m_pRoute->is_Valid()
+	&&	m_pDEM->Get_System() == m_pRoute->Get_System()	)
+//	&&	m_pDEM->is_Compatible(m_pRoute->Get_System())	)
+	{
+		m_pRoute->Assign();
+
+		m_pPits		= SG_Create_Grid(m_pDEM, SG_DATATYPE_Int);
+		m_pPits->Assign();
+
+		m_Pit		= NULL;
+
+		m_pFlats	= NULL;
+		m_Flat		= NULL;
+
+		m_Outlets	= NULL;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CPit_Router::Finalize(void)
+{
+	TPit_Outlet	*pOutlet;
+
+	if( m_pPits )
+	{
+		delete( m_pPits );
+		m_pPits		= NULL;
+	}
+
+	if( m_Pit )
+	{
+		SG_Free(m_Pit);
+		m_Pit		= NULL;
+	}
+
+	if( m_pFlats )
+	{
+		delete( m_pFlats );
+		m_pFlats	= NULL;
+	}
+
+	if( m_Flat )
+	{
+		SG_Free(m_Flat);
+		m_Flat		= NULL;
+	}
+
+	while( m_Outlets )
+	{
+		pOutlet		= m_Outlets->Next;
+		SG_Free(m_Outlets);
+		m_Outlets	= pOutlet;
+	}
+
+	m_Outlets	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CPit_Router::Find_Pits(void)
+{
+	bool	bLower, bFlat;
+	int		x, y, i, ix, iy, nFlats, nPits;
+	long	n;
+	double	z;
+	TPit	*pPit;
+
+	//-----------------------------------------------------
+	nFlats		= 0;
+	nPits		= 0;
+
+	for(n=0; n<Get_NCells() && SG_UI_Process_Set_Progress(n, Get_NCells()); n++)
+	{
+		m_pDEM->Get_Sorted(n,x,y,false,false);	// von tief nach hoch...
+
+		if(	x > 0 && x < Get_NX() - 1 && y > 0 && y < Get_NY() - 1	// Randzellen und Missing Values sind
+		&&	!m_pDEM->is_NoData(x, y)									// per Definition drainiert (:= 0)...
+		&&	m_pPits->asInt(x, y) == 0	)	// ...oder schon als m_Flat markiert sein...
+		{
+			z		= m_pDEM->asDouble(x,y);
+			bLower	= false;
+			bFlat	= false;
+
+			for(i=0; i<8 && !bLower; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+
+				if( !m_pDEM->is_InGrid(ix, iy) || z > m_pDEM->asDouble(ix, iy) )
+				{
+					bLower	= true;
+				}
+				else if( IS_Flat(z, m_pDEM->asDouble(ix,iy)) )
+				{
+					bFlat	= true;
+				}
+			}
+
+			//-----------------------------------------
+			if( !bLower )	// Pit or Flat...
+			{
+				nPits++;
+
+				m_pPits->Set_Value(x,y, nPits);
+
+				m_Pit				= (TPit *)SG_Realloc(m_Pit, nPits * sizeof(TPit));
+				pPit			= m_Pit + nPits - 1;
+				pPit->bDrained	= false;
+				pPit->z			= z;
+
+				if( bFlat )
+				{
+					nFlats++;
+
+					m_Flat			= (TGEO_iRect *)SG_Realloc(m_Flat, nFlats * sizeof(TGEO_iRect));
+
+					Mark_Flat(x, y, m_Flat + nFlats - 1, nFlats, nPits);
+				}
+			}
+		}
+	}
+
+	return( nPits );
+}
+
+//---------------------------------------------------------
+int CPit_Router::Find_Outlets(int nPits)
+{
+	bool	bOutlet, bExArea, bGoExArea;
+
+	int		x, y, i, ix, iy, iMin,
+			iID, j, jID, Pit_ID[8];
+
+	long	n;
+
+	double	z, dz, dzMin;
+
+	TPit_Outlet	*pOutlet;
+
+	//-----------------------------------------------------
+	if( nPits > 0 && SG_UI_Process_Get_Okay(false) )
+	{
+		pOutlet		= NULL;
+
+		m_nJunctions	= (int  *)SG_Calloc(nPits, sizeof(int  ));
+		m_Junction	= (int **)SG_Calloc(nPits, sizeof(int *));
+
+		//-------------------------------------------------
+		for(n=0; n<Get_NCells() && SG_UI_Process_Set_Progress(n, Get_NCells()); n++)
+		{
+			if(	m_pDEM->Get_Sorted(n, x, y, false) && m_pPits->asInt(x,y) == 0	)
+			{
+				z			= m_pDEM->asDouble(x,y);
+				iMin		= -1;
+
+				bOutlet		= false;
+				bGoExArea	= false;
+
+				//-----------------------------------------
+				for(i=0; i<8; i++)
+				{
+					ix		= Get_xTo(i,x);
+					iy		= Get_yTo(i,y);
+
+					bExArea	= !m_pDEM->is_InGrid(ix, iy);
+
+					if( bExArea || z > m_pDEM->asDouble(ix,iy) )
+					{
+						Pit_ID[i]	= iID	= bExArea ? 0 : m_pPits->asInt(ix,iy);
+
+						if( iID >= 0 )
+						{
+							for(j=0; j<i && !bOutlet; j++)
+							{
+								jID		= Pit_ID[j];
+
+								if(	jID >= 0 && !Get_Junction(iID, jID) )
+								{
+									bOutlet		= true;
+								}
+							}
+						}
+
+						//---------------------------------
+						if( !bGoExArea )
+						{
+							if( bExArea )
+							{
+								bGoExArea	= true;
+								iMin		= i;
+							}
+							else
+							{
+								dz			= (z - m_pDEM->asDouble(ix,iy)) / Get_Length(i);
+
+								if( iMin < 0 || dzMin < dz )
+								{
+									iMin	= i;
+									dzMin	= dz;
+								}
+							}
+						}
+					}
+					else
+					{
+						Pit_ID[i]	= -1;
+					}
+				}
+
+				//-----------------------------------------
+				if( bOutlet )
+				{
+					if( pOutlet )
+					{
+						pOutlet->Next		= (TPit_Outlet *)SG_Malloc(sizeof(TPit_Outlet));
+						pOutlet->Next->Prev	= pOutlet;
+						pOutlet				= pOutlet->Next;
+					}
+					else
+					{
+						m_Outlets	= pOutlet	= (TPit_Outlet *)SG_Malloc(sizeof(TPit_Outlet));
+						m_Outlets->Prev		= NULL;
+					}
+
+					pOutlet->Next	= NULL;
+					pOutlet->x		= x;
+					pOutlet->y		= y;
+					memcpy(pOutlet->Pit_ID, Pit_ID, 8 * sizeof(int));
+
+					//-------------------------------------
+					for(i=1; i<8; i++)
+					{
+						iID	= Pit_ID[i];
+
+						if( iID >= 0 )
+						{
+							for(j=0; j<i; j++)
+							{
+								jID	= Pit_ID[j];
+
+								if( jID >= 0 && !Get_Junction(iID, jID) )
+								{
+									Add_Junction(iID, jID);
+								}
+							}
+						}
+					}
+				}
+
+				//-----------------------------------------
+				if( iMin >= 0 )
+				{
+					m_pPits->Set_Value(x,y, Pit_ID[iMin] );
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<nPits; i++)
+		{
+			if( m_Junction[i] )
+			{
+				SG_Free(m_Junction[i]);
+			}
+		}
+
+		SG_Free(m_Junction);
+
+		SG_Free(m_nJunctions);
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CPit_Router::Find_Route(TPit_Outlet *pOutlet)
+{
+	bool	bDrained, bNotDrained;
+
+	int		x, y, i, ix, iy, iMin,
+			Pit_ID, nPitsDrained;
+
+	double	z, dz, dzMin;
+
+
+	//-----------------------------------------------------
+	// 1. Ist Outlets Verbindung zw. Drained und Not Drained ???...
+
+	bDrained		= false;
+	bNotDrained		= false;
+
+	for(i=0; i<8; i++)
+	{
+		Pit_ID	= pOutlet->Pit_ID[i];
+
+		if( Pit_ID == 0 )
+		{
+			bDrained	= true;
+		}
+		else if( Pit_ID > 0 )
+		{
+			if( m_Pit[Pit_ID - 1].bDrained )
+			{
+				bDrained	= true;
+			}
+			else
+			{
+				bNotDrained	= true;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	nPitsDrained	= 0;
+
+	if( bDrained )
+	{
+		if( bNotDrained )
+		{
+			x		= pOutlet->x;
+			y		= pOutlet->y;
+			z		= m_pDEM->asDouble(x,y);
+
+
+			//---------------------------------------------
+			// 2. Threshold ??!!...
+
+		/*	if( m_Threshold > 0.0 )
+			{
+				for(i=0; i<8; i++)
+				{
+					Pit_ID	= pOutlet->Pit_ID[i];
+
+					if( Pit_ID > 0 && !m_Pit[Pit_ID - 1].bDrained && m_Threshold < z - m_Pit[Pit_ID - 1].z )
+					{
+						pOutlet->Pit_ID[i]	= -1;
+					}
+				}
+			}/**/
+
+
+			//---------------------------------------------
+			// 3.a) nach außen entwaessern...
+
+			if( !m_pRoute->asChar(x,y) )
+			{
+				iMin	= -1;
+
+				for(i=0; i<8; i++)
+				{
+					ix	= Get_xTo(i,x);
+					iy	= Get_yTo(i,y);
+
+					if( !m_pDEM->is_InGrid(ix, iy) || m_pRoute->asChar(ix, iy) > 0 )
+					{
+						iMin	= i;
+						break;
+					}
+					else
+					{
+						Pit_ID	= pOutlet->Pit_ID[i];
+
+						if(	Pit_ID == 0 || (Pit_ID > 0 && m_Pit[Pit_ID - 1].bDrained) )
+						{
+							dz		= (z - m_pDEM->asDouble(ix,iy)) / Get_Length(i);
+
+							if( iMin < 0 || dzMin < dz )
+							{
+								iMin	= i;
+								dzMin	= dz;
+							}
+						}
+					}
+				}
+
+				if( iMin >= 0 )
+				{
+					m_pRoute->Set_Value(x,y, iMin > 0 ? iMin : 8 );
+				}
+				else
+				{
+					SG_UI_Msg_Add_Error(_TL("Routing Error"));
+				}
+			}
+
+
+			//---------------------------------------------
+			// 3.b) Pit(s)/Flat(s) drainieren...
+
+			for(i=0; i<8; i++)
+			{
+				Pit_ID	= pOutlet->Pit_ID[i];
+
+				if( Pit_ID > 0 && !m_Pit[Pit_ID - 1].bDrained )
+				{
+					m_Pit[Pit_ID - 1].bDrained	= true;
+
+					Drain_Pit(x,y,Pit_ID);
+
+					nPitsDrained++;
+				}
+			}
+		}
+
+
+		//-------------------------------------------------
+		// 4. pOutlet entfernen...
+
+		if( pOutlet->Prev )
+		{
+			pOutlet->Prev->Next	= pOutlet->Next;
+		}
+		else
+		{
+			m_Outlets			= pOutlet->Next;
+		}
+
+		if( pOutlet->Next )
+		{
+			pOutlet->Next->Prev	= pOutlet->Prev;
+		}
+
+		SG_Free(pOutlet);
+	}
+
+	return( nPitsDrained );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPit_Router::Add_Junction(int iID, int jID)
+{
+	int		i;
+
+	if( iID != jID )
+	{
+		if( iID > jID )
+		{
+			i	= iID;
+			iID	= jID;
+			jID	= i;
+		}
+
+		m_nJunctions[iID]++;
+
+		i	= m_nJunctions[iID];
+
+		m_Junction[iID]			= (int *)SG_Realloc(m_Junction[iID], i * sizeof(int));
+		m_Junction[iID][i-1]	= jID;
+	}
+}
+
+//---------------------------------------------------------
+bool CPit_Router::Get_Junction(int iID, int jID)
+{
+	int		i;
+
+	if(	iID == jID )
+	{
+		return( true );
+	}
+	else
+	{
+		if( iID > jID )
+		{
+			i	= iID;
+			iID	= jID;
+			jID	= i;
+		}
+
+		for(i=0; i<m_nJunctions[iID]; i++)
+		{
+			if( m_Junction[iID][i] == jID )
+			{
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPit_Router::Drain_Pit(int x, int y, int Pit_ID)
+{
+	int		i, ix, iy, iMin;
+
+	double	z, dz, dzMin;
+
+	do
+	{
+		iMin	= -1;
+
+		if( m_pFlats && m_pFlats->asInt(x,y) > 0 )
+		{
+			Drain_Flat(x,y);
+		}
+		else
+		{
+			z		= m_pDEM->asDouble(x,y);
+			dzMin	= 0;
+
+			for(i=0; i<8; i++)
+			{
+				ix	= Get_xTo(i,x);
+				iy	= Get_yTo(i,y);
+
+				if( m_pDEM->is_InGrid(ix,iy) && m_pPits->asInt(ix,iy) == Pit_ID && !m_pRoute->asChar(ix,iy) )
+				{
+					dz		= (z - m_pDEM->asDouble(ix,iy)) / Get_Length(i);
+
+					if( dzMin < dz )
+					{
+						iMin	= i;
+						dzMin	= dz;
+					}
+				}
+			}
+
+			if( iMin >= 0 )
+			{
+				x	+= Get_xTo(iMin);
+				y	+= Get_yTo(iMin);
+
+				i	= (iMin + 4) % 8;
+
+				m_pRoute->Set_Value(x,y, i > 0 ? i : 8 );
+			}
+		}
+	}
+	while( iMin >= 0 );
+}
+
+//---------------------------------------------------------
+void CPit_Router::Drain_Flat(int x, int y)
+{
+	bool		bContinue;
+
+	int			i, ix, iy, j,
+				n, nPlus,
+				Flat_ID;
+
+	TGEO_iRect	*pFlat;
+
+	//-----------------------------------------------------
+	Flat_ID	= m_pFlats->asInt(x,y);
+
+	if( Flat_ID > 0 )
+	{
+		pFlat	= m_Flat + Flat_ID - 1;
+
+		nPlus	= -1;
+
+		m_pFlats->Set_Value(x,y, nPlus );
+
+		//-------------------------------------------------
+		do
+		{
+			bContinue	= false;
+			n			= nPlus--;
+
+			for(y=pFlat->yMin; y<=pFlat->yMax; y++)
+			{
+				for(x=pFlat->xMin; x<=pFlat->xMax; x++)
+				{
+					if( m_pFlats->asInt(x,y) == n )
+					{
+						for(i=0; i<8; i++)
+						{
+							ix	= Get_xTo(i,x);
+							iy	= Get_yTo(i,y);
+
+							if(	m_pDEM->is_InGrid(ix, iy) && Flat_ID == m_pFlats->asInt(ix, iy) )
+							{
+								bContinue	= true;
+
+								j			= (i + 4) % 8;
+
+								m_pRoute->Set_Value(ix,iy, j ? j : 8 );
+								m_pFlats->Set_Value(ix,iy, nPlus );
+							}
+						}
+					}
+				}
+			}
+		}
+		while( bContinue );
+
+		//-------------------------------------------------
+		for(y=pFlat->yMin; y<=pFlat->yMax; y++)
+		{
+			for(x=pFlat->xMin; x<=pFlat->xMax; x++)
+			{
+				if( m_pFlats->asInt(x,y) < 0 )
+				{
+					m_pFlats->Set_Value(x,y, 0 );
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CPit_Router::Mark_Flat(int x, int y, TGEO_iRect *pFlat, int Flat_ID, int Pit_ID)
+{
+	bool	goStackDown;
+
+	int		i, ix, iy,
+			iStart, iStack, nStack,
+			*xMem, *yMem, *iMem;
+
+	double	z;
+
+	//-----------------------------------------------------
+	if( !m_pFlats )
+	{
+		m_pFlats		= SG_Create_Grid(m_pDEM, SG_DATATYPE_Int);
+		//m_pFlats->Set_Cache(false);
+	}
+
+	z			= m_pDEM->asDouble(x,y);
+
+	xMem		= NULL;
+	yMem		= NULL;
+	iMem		= NULL;
+
+	iStart		= 0;
+	iStack		= 0;
+	nStack		= 0;
+
+	pFlat->xMin	= pFlat->xMax	= x;
+	pFlat->yMin	= pFlat->yMax	= y;
+
+	m_pPits->Set_Value(	x, y, Pit_ID );
+	m_pFlats->Set_Value(	x, y, Flat_ID );
+
+
+	//-----------------------------------------------------
+	do
+	{
+		goStackDown	= true;
+
+		for(i=iStart; i<8 && goStackDown; i++)
+		{
+			ix	= Get_xTo(i,x);
+			iy	= Get_yTo(i,y);
+
+			if(	m_pDEM->is_InGrid(ix, iy) && !m_pPits->asInt(ix, iy) && IS_Flat(z, m_pDEM->asDouble(ix, iy)) )
+			{
+				goStackDown		= false;
+				m_pPits->Set_Value(	ix, iy, Pit_ID );
+				m_pFlats->Set_Value(	ix, iy, Flat_ID );
+			}
+		}
+
+		//-------------------------------------------------
+		if( goStackDown )
+		{
+			iStack--;
+
+			if( iStack >= 0 )
+			{
+				x		= xMem[iStack];
+				y		= yMem[iStack];
+				iStart	= iMem[iStack];
+			}
+		}
+		else
+		{
+			if( nStack <= iStack )
+			{
+				nStack	= iStack + 32;
+				xMem	= (int  *)SG_Realloc(xMem, nStack * sizeof(int ));
+				yMem	= (int  *)SG_Realloc(yMem, nStack * sizeof(int ));
+				iMem	= (int  *)SG_Realloc(iMem, nStack * sizeof(int ));
+			}
+
+			xMem[iStack]	= x;
+			yMem[iStack]	= y;
+			iMem[iStack]	= i + 1;
+
+			x				= ix;
+			y				= iy;
+			iStart			= 0;
+
+			if( x < pFlat->xMin )
+				pFlat->xMin	= x;
+			else if( x > pFlat->xMax )
+				pFlat->xMax	= x;
+
+			if( y < pFlat->yMin )
+				pFlat->yMin	= y;
+			else if( y > pFlat->yMax )
+				pFlat->yMax	= y;
+
+			iStack++;
+		}
+	}
+	while( iStack >= 0 );
+
+	//-----------------------------------------------------
+	if( nStack > 0 )
+	{
+		SG_Free(xMem);
+		SG_Free(yMem);
+		SG_Free(iMem);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CPit_Router::Process_Threshold(void)
+{
+	int		x, y, i, n;
+
+	m_Route.Create(*Get_System(), SG_DATATYPE_Char);
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( m_pDEM->is_NoData(x, y) )
+			{
+				m_Route.Set_Value(x, y, -1);
+			}
+			else if( (i = m_pRoute->asInt(x, y)) > 0 )
+			{
+				m_Route.Set_Value(x, y, i % 8);
+			}
+			else
+			{
+				m_Route.Set_Value(x, y, m_pDEM->Get_Gradient_NeighborDir(x, y));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	Lock_Create();
+
+	for(i=0, n=0; i<Get_NCells() && Set_Progress_NCells(i); i++)
+	{
+		if( m_pDEM->Get_Sorted(i, x, y, false) && m_pPits->asInt(x, y) )
+		{
+			m_zThr	= m_pDEM->asDouble(x, y) + m_Threshold;
+			m_zMax	= m_pDEM->asDouble(x, y);
+
+			Check_Threshold(x, y);
+
+			if( m_zMax > m_zThr )
+				n++;
+		}
+	}
+
+	Lock_Destroy();
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && Set_Progress(y); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			i	= m_Route.asInt(x, y);
+
+			if( i < 0 || i == m_pDEM->Get_Gradient_NeighborDir(x, y) )
+			{
+				m_pRoute->Set_Value(x, y, 0);
+			}
+			else
+			{
+				m_pRoute->Set_Value(x, y, i == 0 ? 8 : i);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	Message_Add(CSG_String::Format(_TL("%d pits above threshold level."), n));
+
+	m_Route.Destroy();
+
+	return( n );
+}
+
+//---------------------------------------------------------
+void CPit_Router::Check_Threshold(int x, int y)
+{
+	if( Lock_Get(x, y) )
+		return;
+
+	Lock_Set(x, y);
+
+	if( m_pDEM->asDouble(x, y) > m_zMax )
+	{
+		m_zMax	= m_pDEM->asDouble(x, y);
+	}
+
+	int		i	= m_Route.asInt(x, y);
+	int		ix	= Get_xTo(i, x);
+	int		iy	= Get_yTo(i, y);
+
+	if( m_pDEM->is_InGrid(ix, iy) )
+	{
+		if( m_pDEM->asDouble(x, y) < m_pDEM->asDouble(ix, iy) || m_zMax < m_zThr )
+		{
+			Check_Threshold(ix, iy);
+		}
+	}
+
+	if( m_zMax > m_zThr )
+	{
+		m_Route.Set_Value(x, y, (i + 4) % 8);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_preprocessor/Pit_Router.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,163 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    ta_preprocessor                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Pit_Router.h                      //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Pit_Router_H
+#define HEADER_INCLUDED__Pit_Router_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class ta_preprocessor_EXPORT CPit_Router : public CSG_Module_Grid
+{
+public:
+	CPit_Router(void);
+	virtual ~CPit_Router(void);
+
+	int							Get_Routes		(CSG_Grid *pDEM, CSG_Grid *pRoutes, double Threshold = -1.0);
+
+
+protected:
+
+	virtual bool				On_Execute		(void);
+
+
+private:
+
+	typedef struct
+	{
+		int						xMin, yMin, xMax, yMax;
+	}
+	TGEO_iRect;
+
+	typedef struct
+	{
+		bool					bDrained;
+
+		double					z;
+	}
+	TPit;
+
+	typedef struct TPit_Outlet
+	{
+		int						x, y, Pit_ID[8];
+
+		struct TPit_Outlet		*Prev, *Next;
+	}
+	TPit_Outlet;
+
+
+	int							**m_Junction, *m_nJunctions;
+
+	double						m_Threshold, m_zThr, m_zMax;
+
+	CSG_Grid					*m_pDEM, *m_pRoute, *m_pFlats, *m_pPits, m_Route;
+
+	TGEO_iRect					*m_Flat;
+
+	TPit						*m_Pit;
+
+	TPit_Outlet					*m_Outlets;
+
+
+	bool						Initialize		(void);
+	void						Finalize		(void);
+
+	int							Find_Pits		(void);
+	int							Find_Outlets	(int nPits);
+	int							Find_Route		(TPit_Outlet *pOutlet);
+
+	void						Add_Junction	(int iID, int jID);
+	bool						Get_Junction	(int iID, int jID);
+
+	void						Drain_Pit		(int x, int y, int Pit_ID);
+	void						Drain_Flat		(int x, int y );
+
+	void						Mark_Flat		(int x, int y, TGEO_iRect *pFlat, int Flat_ID, int Pit_ID);
+
+
+	int							Process_Threshold	(void);
+	void						Check_Threshold		(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Pit_Router_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,362 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Grid_Cross_Profiles.cpp                //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/doc_pdf.h>
+
+#include "Grid_Cross_Profiles.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define OFFSET	3
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Cross_Profiles::CGrid_Cross_Profiles(void)
+{
+	Set_Name(_TL("Cross Profiles"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create cross profiles from a grid based DEM for given lines.\n"
+	));
+
+	Parameters.Add_Grid(
+		NULL, "DEM"			, _TL("DEM"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_INPUT		, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "PROFILES"	, _TL("Cross Profiles"),
+		_TL(""),
+		PARAMETER_OUTPUT	, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Value(
+		NULL, "DIST_LINE"	, _TL("Profile Distance"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "DIST_PROFILE", _TL("Profile Length"),
+		_TL(""),
+		PARAMETER_TYPE_Double, 10.0, 0.0, true
+	);
+
+	Parameters.Add_Value(
+		NULL, "NUM_PROFILE"	, _TL("Profile Samples"),
+		_TL(""),
+		PARAMETER_TYPE_Int	, 10.0, 3.0, true
+	);
+
+	Parameters.Add_FilePath(
+		NULL, "DOCUMENT"	, _TL("Report"),
+		_TL(""),
+		_TL("Portable Document Format (*.pdf)|*.pdf|All Files|*.*"), NULL, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Cross_Profiles::~CGrid_Cross_Profiles(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Cross_Profiles::On_Execute(void)
+{
+	int			iLine, iPart, iPoint, nSamples;
+	double		Distance, Length, dLine, dist, dx, dy;
+	TSG_Point	iPt, jPt, dPt, aPt, bPt;
+	CSG_Shapes		*pLines, *pProfiles;
+	CSG_Shape		*pLine, *pProfile;
+
+	//-----------------------------------------------------
+	m_pDEM		= Parameters("DEM")			->asGrid();
+	pProfiles	= Parameters("PROFILES")	->asShapes();
+	pLines		= Parameters("LINES")		->asShapes();
+	Distance	= Parameters("DIST_LINE")	->asDouble();
+	Length		= Parameters("DIST_PROFILE")->asDouble();
+	nSamples	= Parameters("NUM_PROFILE")	->asInt();
+
+	//-----------------------------------------------------
+	pProfiles->Create(SHAPE_TYPE_Line, _TL("Profiles"));
+	pProfiles->Add_Field("ID"	, SG_DATATYPE_Int);
+	pProfiles->Add_Field("LINE"	, SG_DATATYPE_Int);
+	pProfiles->Add_Field("PART"	, SG_DATATYPE_Int);
+
+	for(iPoint=0; iPoint<nSamples; iPoint++)
+	{
+		pProfiles->Add_Field(CSG_String::Format(SG_T("X%03d"), iPoint), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	for(iLine=0; iLine<pLines->Get_Count() && Set_Progress(iLine, pLines->Get_Count()); iLine++)
+	{
+		pLine	= pLines->Get_Shape(iLine);
+
+		for(iPart=0; iPart<pLine->Get_Part_Count(); iPart++)
+		{
+			if( pLine->Get_Point_Count(iPart) > 1 )
+			{
+				dist	= 0.0;
+				iPt		= pLine->Get_Point(0, iPart);
+
+				for(iPoint=1; iPoint<pLine->Get_Point_Count(iPart); iPoint++)
+				{
+					jPt		= iPt;
+					iPt		= pLine->Get_Point(iPoint, iPart);
+					dx		= iPt.x - jPt.x;
+					dy		= iPt.y - jPt.y;
+					dLine	= sqrt(dx*dx + dy*dy);
+					dx		/= dLine;
+					dy		/= dLine;
+
+					while( dist < dLine )
+					{
+						dPt.x	= jPt.x + dist * dx;
+						dPt.y	= jPt.y + dist * dy;
+
+						if( m_pDEM->is_InGrid_byPos(dPt) )
+						{
+							aPt.x	= dPt.x + dy * Length;
+							aPt.y	= dPt.y - dx * Length;
+							bPt.x	= dPt.x - dy * Length;
+							bPt.y	= dPt.y + dx * Length;
+
+							pProfile	= pProfiles->Add_Shape();
+							pProfile->Add_Point(aPt);
+							pProfile->Add_Point(bPt);
+							pProfile->Set_Value(0, pProfiles->Get_Count());
+							pProfile->Set_Value(1, iLine);
+							pProfile->Set_Value(2, iPart);
+
+							Get_Profile(pProfile, aPt, bPt, nSamples);
+						}
+
+						dist	+= Distance;
+					}
+
+					dist	-= dLine;
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pProfiles->Get_Count() > 0 )
+	{
+		if( Parameters("DOCUMENT")->asString() )
+		{
+			Make_Report(Parameters("DOCUMENT")->asString(), m_pDEM, pLines, pProfiles, Distance);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Cross_Profiles::Get_Profile(CSG_Shape *pProfile, TSG_Point A, TSG_Point B, int nSamples)
+{
+	if( 1 )
+	{
+		double	d, dx, dy, z;
+
+		dx	= B.x - A.x;
+		dy	= B.y - A.y;
+	//	d	= sqrt(dx*dx + dy*dy) / (nSamples - 1);
+		d	= (nSamples - 1);
+		dx	/= d;
+		dy	/= d;
+
+		for(int i=0; i<nSamples; i++)
+		{
+			if( m_pDEM->Get_Value(A, z) )
+			{
+				pProfile->Set_Value	(OFFSET + i, z);
+			}
+			else
+			{
+				pProfile->Set_NoData	(OFFSET + i);
+			}
+
+			A.x	+= dx;
+			A.y	+= dy;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define NBOXES	4
+
+//---------------------------------------------------------
+void CGrid_Cross_Profiles::Make_Report(const SG_Char *FileName, CSG_Grid *pDEM, CSG_Shapes *pLines, CSG_Shapes *pProfiles, double Distance)
+{
+	if( FileName )
+	{
+		int				iProfile, iPoint, nSamples, iBox;
+		CSG_Rect		r;
+		CSG_Shape			*pProfile, *pLine;
+		CSG_Shapes			Profile;
+		CSG_Doc_PDF	pdf;
+
+		pdf.Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_PORTRAIT, _TL("Cross Profiles"));
+		pdf.Layout_Add_Box(5,  5, 95, 20);
+		pdf.Layout_Add_Box(5, 25, 95, 45);
+		pdf.Layout_Add_Box(5, 50, 95, 70);
+		pdf.Layout_Add_Box(5, 75, 95, 90);
+
+		nSamples	= pProfiles->Get_Field_Count() - OFFSET;
+		Distance	= Distance / (nSamples - 1);
+		iBox		= 0;
+
+		for(iProfile=0; iProfile<pProfiles->Get_Count() && Set_Progress(iProfile, pProfiles->Get_Count()); iProfile++)
+		{
+			pProfile	= pProfiles->Get_Shape(iProfile);
+
+			Profile.Create(SHAPE_TYPE_Line);
+			pLine		= Profile.Add_Shape();
+
+			for(iPoint=0; iPoint<nSamples; iPoint++)
+			{
+				if( !pProfile->is_NoData(OFFSET + iPoint) )
+				{
+					pLine->Add_Point(
+						(iPoint - nSamples / 2) * Distance,
+						pProfile->asDouble(OFFSET + iPoint)
+					);
+				}
+			}
+
+			if( pLine->Get_Point_Count(0) > 1 )
+			{
+				if( iBox >= NBOXES )
+				{
+					pdf.Add_Page();
+					iBox	= 0;
+				}
+
+//				pdf.Draw_Graticule	(pdf.Layout_Get_Box(iBox),  Profile.Get_Extent(), 20);
+//				pdf.Draw_Shapes		(pdf.Layout_Get_Box(iBox), &Profile);
+				r	= pLine->Get_Extent();	r.Inflate(10);
+				pdf.Draw_Graticule	(pdf.Layout_Get_Box(iBox), r, 15);
+				pdf.Draw_Shape		(pdf.Layout_Get_Box(iBox), pLine, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_GREEN, SG_COLOR_BLACK, 1, &r);
+
+				iBox++;
+			}
+		}
+
+		pdf.Save(Parameters("DOCUMENT")->asString());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Cross_Profiles.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,106 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Cross_Profiles.h                 //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Cross_Profiles_H
+#define HEADER_INCLUDED__Grid_Cross_Profiles_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Cross_Profiles : public CSG_Module_Grid
+{
+public:
+	CGrid_Cross_Profiles(void);
+	virtual ~CGrid_Cross_Profiles(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+
+
+private:
+
+	CSG_Grid						*m_pDEM;
+
+
+	bool						Get_Profile			(CSG_Shape *pProfile, TSG_Point A, TSG_Point B, int nSamples);
+
+	void						Make_Report			(const SG_Char *FileName, CSG_Grid *pDEM, CSG_Shapes *pLines, CSG_Shapes *pProfiles, double Distance);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Cross_Profiles_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,289 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Flow_Profile.cpp                 //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Flow_Profile.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define VALUE_OFFSET	6
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Flow_Profile::CGrid_Flow_Profile(void)
+{
+	Set_Name(_TL("Flow Path Profile"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create interactively flow path profiles from a grid based DEM\n"
+		"Use a left mouse button click to create a flow profile starting from the clicked point.")
+	);
+
+	Parameters.Add_Grid(
+		NULL, "DEM"		, _TL("DEM"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "VALUES"	, _TL("Values"),
+		_TL("Additional values that shall be saved to the output table."),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "POINTS"	, _TL("Profile Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "LINE"	, _TL("Profile Line"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Flow_Profile::~CGrid_Flow_Profile(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Flow_Profile::On_Execute(void)
+{
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	m_pValues	= Parameters("VALUES")	->asGridList();
+	m_pPoints	= Parameters("POINTS")	->asShapes();
+	m_pLine		= Parameters("LINE")	->asShapes();
+
+	DataObject_Update(m_pDEM, true);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Flow_Profile::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	switch( Mode )
+	{
+	default:
+		break;
+
+	case MODULE_INTERACTIVE_LDOWN:
+		Set_Profile(Get_System()->Fit_to_Grid_System(ptWorld));
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Flow_Profile::Set_Profile(TSG_Point ptWorld)
+{
+	int			x, y, i;
+
+	//-----------------------------------------------------
+	if( Get_System()->Get_World_to_Grid(x, y, ptWorld) && m_pDEM->is_InGrid(x, y) )
+	{
+		m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name()));
+
+		m_pPoints->Add_Field("ID"				, SG_DATATYPE_Int);
+		m_pPoints->Add_Field(_TL("Distance")			, SG_DATATYPE_Double);
+		m_pPoints->Add_Field(_TL("Distance Overland"), SG_DATATYPE_Double);
+		m_pPoints->Add_Field("X"				, SG_DATATYPE_Double);
+		m_pPoints->Add_Field("Y"				, SG_DATATYPE_Double);
+		m_pPoints->Add_Field("Z"				, SG_DATATYPE_Double);
+
+		for(i=0; i<m_pValues->Get_Count(); i++)
+		{
+			m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+		}
+
+		//-----------------------------------------------------
+		m_pLine->Create(SHAPE_TYPE_Line, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name()));
+		m_pLine->Add_Field("ID"	, SG_DATATYPE_Int);
+		m_pLine->Add_Shape()->Set_Value(0, 1);
+
+		//-----------------------------------------------------
+		Set_Profile(x, y);
+
+		//-----------------------------------------------------
+		DataObject_Update(m_pLine	, false);
+		DataObject_Update(m_pPoints	, false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Flow_Profile::Set_Profile(int x, int y)
+{
+	int		Direction;
+
+	if( Add_Point(x, y) && (Direction = m_pDEM->Get_Gradient_NeighborDir(x, y)) >= 0 )
+	{
+		Set_Profile(
+			Get_System()->Get_xTo(Direction, x),
+			Get_System()->Get_yTo(Direction, y)
+		);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Flow_Profile::Add_Point(int x, int y)
+{
+	int			i;
+	double		z, Distance, Distance_2;
+	TSG_Point	Point;
+	CSG_Shape		*pPoint, *pLast;
+
+	if( m_pDEM->is_InGrid(x, y) )
+	{
+		z		= m_pDEM->asDouble(x, y);
+		Point	= Get_System()->Get_Grid_to_World(x, y);
+
+		if( m_pPoints->Get_Count() == 0 )
+		{
+			Distance	= 0.0;
+			Distance_2	= 0.0;
+		}
+		else
+		{
+			pLast		= m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1);
+			Distance	= SG_Get_Distance(Point, pLast->Get_Point(0));
+
+			Distance_2	= pLast->asDouble(5) - z;
+			Distance_2	= sqrt(Distance*Distance + Distance_2*Distance_2);
+
+			Distance	+= pLast->asDouble(1);
+			Distance_2	+= pLast->asDouble(2);
+		}
+
+		pPoint	= m_pPoints->Add_Shape();
+		pPoint->Add_Point(Point);
+
+		pPoint->Set_Value(0, m_pPoints->Get_Count());
+		pPoint->Set_Value(1, Distance);
+		pPoint->Set_Value(2, Distance_2);
+		pPoint->Set_Value(3, Point.x);
+		pPoint->Set_Value(4, Point.y);
+		pPoint->Set_Value(5, z);
+
+		for(i=0; i<m_pValues->Get_Count(); i++)
+		{
+			pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y, true));
+		}
+
+		m_pLine->Get_Shape(0)->Add_Point(Point);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Flow_Profile.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Flow_Profile.h                  //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Flow_Profile_H
+#define HEADER_INCLUDED__Grid_Flow_Profile_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Flow_Profile : public CSG_Module_Grid_Interactive
+{
+public:
+	CGrid_Flow_Profile(void);
+	virtual ~CGrid_Flow_Profile(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+	virtual bool				On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	CSG_Shapes						*m_pPoints, *m_pLine;
+
+	CSG_Grid						*m_pDEM;
+
+	CSG_Parameter_Grid_List		*m_pValues;
+
+
+	bool						Set_Profile			(TSG_Point ptWorld);
+	bool						Set_Profile			(int x, int y);
+
+	bool						Add_Point			(int x, int y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Flow_Profile_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,355 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Grid_Profile.cpp                    //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Profile.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define VALUE_OFFSET	6
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Profile::CGrid_Profile(void)
+{
+	Set_Name		(_TL("Profile"));
+
+	Set_Author		(SG_T("(c) 2004 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create interactively profiles from a grid based DEM\n"
+		"Use left mouse button clicks into a map window to add profile points."
+		"A right mouse button click will finish the profile."
+	));
+
+	Set_Drag_Mode	(MODULE_INTERACTIVE_DRAG_LINE);
+
+	Parameters.Add_Grid(
+		NULL, "DEM"			, _TL("DEM"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "VALUES"		, _TL("Values"),
+		_TL("Additional values that shall be saved to the output table."),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "POINTS"		, _TL("Profile Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "LINE"		, _TL("Profile Line"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Profile::~CGrid_Profile(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Profile::On_Execute(void)
+{
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	m_pValues	= Parameters("VALUES")	->asGridList();
+	m_pPoints	= Parameters("POINTS")	->asShapes();
+	m_pLine		= Parameters("LINE")	->asShapes();
+
+	m_bAdd		= false;
+
+	DataObject_Update(m_pDEM , SG_UI_DATAOBJECT_SHOW_NEW_MAP);
+	DataObject_Update(m_pLine, SG_UI_DATAOBJECT_SHOW_LAST_MAP);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGrid_Profile::On_Execute_Finish(void)
+{
+	if( m_bAdd )
+	{
+		Set_Profile();
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Profile::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	switch( Mode )
+	{
+	default:
+		break;
+
+	case MODULE_INTERACTIVE_LDOWN:
+		if( !m_bAdd )
+		{
+			m_bAdd	= true;
+			m_pLine->Create(SHAPE_TYPE_Line, CSG_String::Format(SG_T("Profile [%s]"), m_pDEM->Get_Name()));
+			m_pLine->Add_Field("ID"	, SG_DATATYPE_Int);
+			m_pLine->Add_Shape()->Set_Value(0, 1);
+		}
+
+		m_pLine->Get_Shape(0)->Add_Point(Get_System()->Fit_to_Grid_System(ptWorld));
+
+		DataObject_Update(m_pLine);
+		break;
+
+	case MODULE_INTERACTIVE_RDOWN:
+		Set_Profile();
+		m_bAdd	= false;
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Profile::Set_Profile(void)
+{
+	int			i;
+	TSG_Point	A, B;
+	CSG_Shape	*pLine;
+
+	//-----------------------------------------------------
+	m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name()));
+
+	m_pPoints->Add_Field("ID"						, SG_DATATYPE_Int);
+	m_pPoints->Add_Field(_TL("Distance")			, SG_DATATYPE_Double);
+	m_pPoints->Add_Field(_TL("Distance Overland")	, SG_DATATYPE_Double);
+	m_pPoints->Add_Field("X"						, SG_DATATYPE_Double);
+	m_pPoints->Add_Field("Y"						, SG_DATATYPE_Double);
+	m_pPoints->Add_Field("Z"						, SG_DATATYPE_Double);
+
+	for(i=0; i<m_pValues->Get_Count(); i++)
+	{
+		m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	if( (pLine = m_pLine->Get_Shape(0)) != NULL && pLine->Get_Point_Count(0) > 1 )
+	{
+		B	= pLine->Get_Point(0);
+
+		for(i=1; i<pLine->Get_Point_Count(0); i++)
+		{
+			A	= B;
+			B	= pLine->Get_Point(i);
+
+			Set_Profile(A, B);
+		}
+	}
+
+	//-----------------------------------------------------
+	DataObject_Update(m_pLine);
+	DataObject_Update(m_pPoints);
+
+	return( m_pPoints->Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CGrid_Profile::Set_Profile(TSG_Point A, TSG_Point B)
+{
+	double		dx, dy, d, n;
+	TSG_Point	p;
+
+	//-----------------------------------------------------
+	dx	= fabs(B.x - A.x);
+	dy	= fabs(B.y - A.y);
+
+	if( dx > 0.0 || dy > 0.0 )
+	{
+		if( dx > dy )
+		{
+			dx	/= Get_Cellsize();
+			n	 = dx;
+			dy	/= dx;
+			dx	 = Get_Cellsize();
+		}
+		else
+		{
+			dy	/= Get_Cellsize();
+			n	 = dy;
+			dx	/= dy;
+			dy	 = Get_Cellsize();
+		}
+
+		if( B.x < A.x )
+		{
+			dx	= -dx;
+		}
+
+		if( B.y < A.y )
+		{
+			dy	= -dy;
+		}
+
+		//-------------------------------------------------
+		for(d=0.0, p.x=A.x, p.y=A.y; d<=n; d++, p.x+=dx, p.y+=dy)
+		{
+			Add_Point(p);
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGrid_Profile::Add_Point(CSG_Point Point)
+{
+	int			x, y, i;
+	double		z, Distance, Distance_2;
+	CSG_Shape	*pPoint, *pLast;
+
+	if( Get_System()->Get_World_to_Grid(x, y, Point) && m_pDEM->is_InGrid(x, y) )
+	{
+		z	= m_pDEM->asDouble(x, y);
+
+		if( m_pPoints->Get_Count() == 0 )
+		{
+			Distance	= 0.0;
+			Distance_2	= 0.0;
+		}
+		else
+		{
+			pLast		= m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1);
+			Distance	= SG_Get_Distance(Point, pLast->Get_Point(0));
+
+			if( Distance == 0.0 )
+			{
+				return( false );
+			}
+
+			Distance_2	= pLast->asDouble(5) - z;
+			Distance_2	= sqrt(Distance*Distance + Distance_2*Distance_2);
+
+			Distance	+= pLast->asDouble(1);
+			Distance_2	+= pLast->asDouble(2);
+		}
+
+		pPoint	= m_pPoints->Add_Shape();
+		pPoint->Add_Point(Point);
+
+		pPoint->Set_Value(0, m_pPoints->Get_Count());
+		pPoint->Set_Value(1, Distance);
+		pPoint->Set_Value(2, Distance_2);
+		pPoint->Set_Value(3, Point.Get_X());
+		pPoint->Set_Value(4, Point.Get_Y());
+		pPoint->Set_Value(5, z);
+
+		for(i=0; i<m_pValues->Get_Count(); i++)
+		{
+			pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y, true));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Grid_Profile.h                     //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Profile_H
+#define HEADER_INCLUDED__Grid_Profile_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Profile : public CSG_Module_Grid_Interactive
+{
+public:
+	CGrid_Profile(void);
+	virtual ~CGrid_Profile(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+	virtual bool				On_Execute_Finish	(void);
+	virtual bool				On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	bool						m_bAdd;
+
+	CSG_Shapes					*m_pPoints, *m_pLine;
+
+	CSG_Grid					*m_pDEM;
+
+	CSG_Parameter_Grid_List		*m_pValues;
+
+
+	bool						Set_Profile			(void);
+	bool						Set_Profile			(TSG_Point A, TSG_Point B);
+
+	bool						Add_Point			(CSG_Point Point);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Profile_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,365 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              Grid_Profile_From_Lines.cpp              //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Profile_From_Lines.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Profile_From_Lines::CGrid_Profile_From_Lines(void)
+{
+	Set_Name		(_TL("Profiles from Lines"));
+
+	Set_Author		(SG_T("(c) 2006 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create profiles from a grid based DEM for each line of a lines layer. "
+	));
+
+	Parameters.Add_Grid(
+		NULL, "DEM"			, _TL("DEM"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "VALUES"		, _TL("Values"),
+		_TL("Additional values that shall be saved to the output table."),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "LINES"		, _TL("Lines"),
+		_TL(""),
+		PARAMETER_INPUT, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "PROFILE"		, _TL("Profiles"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes_List(
+		NULL, "PROFILES"	, _TL("Profiles"),
+		_TL(""),
+		PARAMETER_OUTPUT_OPTIONAL, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Value(
+		NULL, "SPLIT"		, _TL("Each Line as new Profile"),
+		_TL(""),
+		PARAMETER_TYPE_Bool, false
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Profile_From_Lines::~CGrid_Profile_From_Lines(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Profile_From_Lines::On_Execute(void)
+{
+	int			iLine;
+	CSG_String	Name;
+
+	//-----------------------------------------------------
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	m_pValues	= Parameters("VALUES")	->asGridList();
+	m_pLines	= Parameters("LINES")	->asShapes();
+
+	//-----------------------------------------------------
+	if( Parameters("SPLIT")->asBool() == false )
+	{
+		if( (m_pProfile = Parameters("PROFILE")->asShapes()) == NULL )
+		{
+			Parameters("PROFILE")->Set_Value(m_pProfile = SG_Create_Shapes(SHAPE_TYPE_Point));
+		}
+
+		Name.Printf(SG_T("%s [%s]"), _TL("Profile"), m_pDEM->Get_Name());
+		Init_Profile(m_pProfile, Name);
+
+		for(iLine=0; iLine<m_pLines->Get_Count() && Set_Progress(iLine, m_pLines->Get_Count()); iLine++)
+		{
+			Set_Profile(iLine, m_pLines->Get_Shape(iLine));
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		Parameters("PROFILES")->asShapesList()->Del_Items();
+
+		for(iLine=0; iLine<m_pLines->Get_Count() && Set_Progress(iLine, m_pLines->Get_Count()); iLine++)
+		{
+			Name.Printf(SG_T("%s [%d, %s]"), _TL("Profile"), iLine, m_pDEM->Get_Name());
+			Init_Profile(m_pProfile = SG_Create_Shapes(), Name);
+
+			Set_Profile(iLine, m_pLines->Get_Shape(iLine));
+
+			Parameters("PROFILES")->asShapesList()->Add_Item(m_pProfile);
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	F_LINE_ID	= 0,
+	F_ID,
+	F_DIST,
+	F_DIST_SURF,
+	F_X,
+	F_Y,
+	F_Z,
+	F_VALUES
+};
+
+//---------------------------------------------------------
+bool CGrid_Profile_From_Lines::Init_Profile(CSG_Shapes *pPoints, const SG_Char *Name)
+{
+	if( pPoints )
+	{
+		pPoints->Create(SHAPE_TYPE_Point, Name);
+
+		pPoints->Add_Field("LINE_ID"	, SG_DATATYPE_Int);
+		pPoints->Add_Field("ID"			, SG_DATATYPE_Int);
+		pPoints->Add_Field("DIST"		, SG_DATATYPE_Double);
+		pPoints->Add_Field("DIST_SURF"	, SG_DATATYPE_Double);
+		pPoints->Add_Field("X"			, SG_DATATYPE_Double);
+		pPoints->Add_Field("Y"			, SG_DATATYPE_Double);
+		pPoints->Add_Field("Z"			, SG_DATATYPE_Double);
+
+		for(int i=0; i<m_pValues->Get_Count(); i++)
+		{
+			pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Profile_From_Lines::Set_Profile(int Line_ID, CSG_Shape *pLine)
+{
+	if( pLine && pLine->Get_Point_Count(0) > 1 )
+	{
+		for(int iPart=0; iPart<pLine->Get_Part_Count(); iPart++)
+		{
+			TSG_Point	A, B;
+
+			B	= pLine->Get_Point(0, iPart);
+
+			for(int iPoint=1; iPoint<pLine->Get_Point_Count(iPart); iPoint++)
+			{
+				A	= B;
+				B	= pLine->Get_Point(iPoint, iPart);
+
+				Set_Profile(Line_ID, iPoint == 1, A, B);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Profile_From_Lines::Set_Profile(int Line_ID, bool bStart, const TSG_Point &A, const TSG_Point &B)
+{
+	double		dx, dy, d, n;
+	TSG_Point	p;
+
+	//-----------------------------------------------------
+	dx	= fabs(B.x - A.x);
+	dy	= fabs(B.y - A.y);
+
+	if( dx > 0.0 || dy > 0.0 )
+	{
+		if( dx > dy )
+		{
+			dx	/= Get_Cellsize();
+			n	 = dx;
+			dy	/= dx;
+			dx	 = Get_Cellsize();
+		}
+		else
+		{
+			dy	/= Get_Cellsize();
+			n	 = dy;
+			dx	/= dy;
+			dy	 = Get_Cellsize();
+		}
+
+		if( B.x < A.x )
+		{
+			dx	= -dx;
+		}
+
+		if( B.y < A.y )
+		{
+			dy	= -dy;
+		}
+
+		//-------------------------------------------------
+		for(d=0.0, p.x=A.x, p.y=A.y; d<=n; d++, p.x+=dx, p.y+=dy)
+		{
+			Add_Point(Line_ID, bStart, p);
+
+			bStart	= false;
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGrid_Profile_From_Lines::Add_Point(int Line_ID, bool bStart, const TSG_Point &Point)
+{
+	int			x, y, i;
+	double		z, Distance, Distance_2;
+	CSG_Shape	*pPoint, *pLast;
+
+	if( Get_System()->Get_World_to_Grid(x, y, Point) && m_pDEM->is_InGrid(x, y) )
+	{
+		z	= m_pDEM->asDouble(x, y);
+
+		if( bStart || m_pProfile->Get_Count() == 0 )
+		{
+			Distance	= 0.0;
+			Distance_2	= 0.0;
+		}
+		else
+		{
+			pLast		= m_pProfile->Get_Shape(m_pProfile->Get_Count() - 1);
+			Distance	= SG_Get_Distance(Point, pLast->Get_Point(0));
+
+			if( Distance == 0.0 )
+			{
+				return( false );
+			}
+
+			Distance_2	= pLast->asDouble(F_Z) - z;
+			Distance_2	= sqrt(Distance*Distance + Distance_2*Distance_2);
+
+			Distance	+= pLast->asDouble(F_DIST);
+			Distance_2	+= pLast->asDouble(F_DIST_SURF);
+		}
+
+		pPoint	= m_pProfile->Add_Shape();
+		pPoint->Add_Point(Point);
+
+		pPoint->Set_Value(F_LINE_ID	, Line_ID);
+		pPoint->Set_Value(F_ID		, m_pProfile->Get_Count());
+		pPoint->Set_Value(F_DIST		, Distance);
+		pPoint->Set_Value(F_DIST_SURF	, Distance_2);
+		pPoint->Set_Value(F_X			, Point.x);
+		pPoint->Set_Value(F_Y			, Point.y);
+		pPoint->Set_Value(F_Z			, z);
+
+		for(i=0; i<m_pValues->Get_Count(); i++)
+		{
+			pPoint->Set_Value(F_VALUES + i, m_pValues->asGrid(i)->asDouble(x, y, true));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Profile_From_Lines.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Grid_Profile_From_Lines.h               //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Profile_From_Lines_H
+#define HEADER_INCLUDED__Grid_Profile_From_Lines_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Profile_From_Lines : public CSG_Module_Grid
+{
+public:
+	CGrid_Profile_From_Lines(void);
+	virtual ~CGrid_Profile_From_Lines(void);
+
+
+protected:
+
+	virtual bool				On_Execute(void);
+
+
+private:
+
+	CSG_Shapes					*m_pProfile, *m_pLines;
+
+	CSG_Grid					*m_pDEM;
+
+	CSG_Parameter_Grid_List		*m_pValues;
+
+
+	bool						Init_Profile	(CSG_Shapes *pPoints, const SG_Char *Name);
+
+	bool						Set_Profile		(int Line_ID, CSG_Shape *pLine);
+	bool						Set_Profile		(int Line_ID, bool bStart, const TSG_Point &A, const TSG_Point &B);
+	bool						Add_Point		(int Line_ID, bool bStart, const TSG_Point &Point);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Profile_From_Lines_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,468 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Grid_Swath_Profile.cpp                //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "Grid_Swath_Profile.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define VALUE_OFFSET	10
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CGrid_Swath_Profile::CGrid_Swath_Profile(void)
+{
+	Set_Name(_TL("Swath Profile"));
+
+	Set_Author		(SG_T("(c) 2005 by O.Conrad"));
+
+	Set_Description	(_TW(
+		"Create interactively swath profiles from a grid based DEM\n"
+		"Use left mouse button clicks into a map window to add profile points."
+		"A right mouse button click will finish the profile.\n"
+		"Generated outputs for the swath profile are arithmetic mean, "
+		"minimum, maximum values and the standard deviation.\n")
+	);
+
+	Parameters.Add_Grid(
+		NULL, "DEM"			, _TL("DEM"),
+		_TL(""),
+		PARAMETER_INPUT
+	);
+
+	Parameters.Add_Grid_List(
+		NULL, "VALUES"		, _TL("Values"),
+		_TL("Additional values that shall be saved to the output table."),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "POINTS"		, _TL("Profile Points"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Point
+	);
+
+	Parameters.Add_Shapes(
+		NULL, "LINE"		, _TL("Swath Profile"),
+		_TL(""),
+		PARAMETER_OUTPUT, SHAPE_TYPE_Line
+	);
+
+	Parameters.Add_Value(
+		NULL, "WIDTH"		, _TL("Swath Width"),
+		_TL("Swath width measured in map units."),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+}
+
+//---------------------------------------------------------
+CGrid_Swath_Profile::~CGrid_Swath_Profile(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::On_Execute(void)
+{
+	m_pDEM		= Parameters("DEM")		->asGrid();
+	m_pValues	= Parameters("VALUES")	->asGridList();
+	m_pPoints	= Parameters("POINTS")	->asShapes();
+	m_pLine		= Parameters("LINE")	->asShapes();
+	m_Width		= Parameters("WIDTH")	->asDouble() / 2.0;
+
+	m_bAdd		= false;
+
+	DataObject_Update(m_pDEM , SG_UI_DATAOBJECT_SHOW_NEW_MAP);
+	DataObject_Update(m_pLine, SG_UI_DATAOBJECT_SHOW_LAST_MAP);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::On_Execute_Finish(void)
+{
+	if( m_bAdd )
+	{
+		Set_Profile();
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	switch( Mode )
+	{
+	default:
+		break;
+
+	case MODULE_INTERACTIVE_LDOWN:
+		if( !m_bAdd )
+		{
+			m_bAdd	= true;
+			m_pLine->Create(SHAPE_TYPE_Line, CSG_String::Format(SG_T("Profile [%s]"), m_pDEM->Get_Name()));
+			m_pLine->Add_Field("ID"	, SG_DATATYPE_Int);
+			m_pLine->Add_Shape()->Set_Value(0, 1);
+		}
+
+		m_pLine->Get_Shape(0)->Add_Point(Get_System()->Fit_to_Grid_System(ptWorld));
+
+		DataObject_Update(m_pLine);
+		break;
+
+	case MODULE_INTERACTIVE_RDOWN:
+		Set_Profile();
+		m_bAdd	= false;
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::Set_Profile(void)
+{
+	int			i;
+	double		d;
+	CSG_Point	A, B, P, Left, Right;
+	CSG_Shape	*pLine, *pLeft, *pRight;
+
+	//-----------------------------------------------------
+	m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name()));
+
+	m_pPoints->Add_Field("ID"			, SG_DATATYPE_Int);
+	m_pPoints->Add_Field("D"			, SG_DATATYPE_Double);
+	m_pPoints->Add_Field("X"			, SG_DATATYPE_Double);
+	m_pPoints->Add_Field("Y"			, SG_DATATYPE_Double);
+	m_pPoints->Add_Field("Z"			, SG_DATATYPE_Double);
+	m_pPoints->Add_Field(_TL("Z [mean]")		, SG_DATATYPE_Double);
+	m_pPoints->Add_Field(_TL("Z [min]")		, SG_DATATYPE_Double);
+	m_pPoints->Add_Field(_TL("Z [max]")		, SG_DATATYPE_Double);
+	m_pPoints->Add_Field(_TL("Z [min_sd]")	, SG_DATATYPE_Double);
+	m_pPoints->Add_Field(_TL("Z [max_sd]")	, SG_DATATYPE_Double);
+
+	for(i=0; i<m_pValues->Get_Count(); i++)
+	{
+		m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
+		m_pPoints->Add_Field(CSG_String::Format(_TL("%s [mean]")	, m_pValues->asGrid(i)->Get_Name()), SG_DATATYPE_Double);
+		m_pPoints->Add_Field(CSG_String::Format(_TL("%s [min]"	)	, m_pValues->asGrid(i)->Get_Name()), SG_DATATYPE_Double);
+		m_pPoints->Add_Field(CSG_String::Format(_TL("%s [max]"	)	, m_pValues->asGrid(i)->Get_Name()), SG_DATATYPE_Double);
+		m_pPoints->Add_Field(CSG_String::Format(_TL("%s [min_sd]")	, m_pValues->asGrid(i)->Get_Name()), SG_DATATYPE_Double);
+		m_pPoints->Add_Field(CSG_String::Format(_TL("%s [max_sd]")	, m_pValues->asGrid(i)->Get_Name()), SG_DATATYPE_Double);
+	}
+
+	//-----------------------------------------------------
+	if( (pLine = m_pLine->Get_Shape(0)) != NULL && pLine->Get_Point_Count(0) > 1 )
+	{
+		if( (pLeft	= m_pLine->Get_Shape(1)) == NULL )
+			pLeft	= m_pLine->Add_Shape();
+		else
+			pLeft	->Del_Parts();
+
+		if( (pRight	= m_pLine->Get_Shape(2)) == NULL )
+			pRight	= m_pLine->Add_Shape();
+		else
+			pRight	->Del_Parts();
+
+		B	= pLine->Get_Point(0);
+
+		for(i=1; i<pLine->Get_Point_Count(0); i++)
+		{
+			A		= B;
+			B		= pLine->Get_Point(i);
+
+			P		= B - A;
+			d		= m_Width / sqrt(P.Get_X()*P.Get_X() + P.Get_Y()*P.Get_Y());
+			P		.Assign(-d * P.Get_Y(), d * P.Get_X());
+			Left	= A - P;
+			Right	= A + P;
+
+			Set_Profile(A, B, Left, Right);
+
+			pLeft	->Add_Point(Left , i - 1);
+			Left	= B - P;
+			pLeft	->Add_Point(Left , i - 1);
+
+			pRight	->Add_Point(Right, i - 1);
+			Right	= B + P;
+			pRight	->Add_Point(Right, i - 1);
+		}
+	}
+
+	//-----------------------------------------------------
+	DataObject_Update(m_pLine);
+	DataObject_Update(m_pPoints);
+
+	return( m_pPoints->Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::Set_Profile(CSG_Point A, CSG_Point B, CSG_Point Left, CSG_Point Right)
+{
+	double		dx, dy, d, n;
+	CSG_Point	p, dStep, Step;
+
+	//-----------------------------------------------------
+	dx	= fabs(B.Get_X() - A.Get_X());
+	dy	= fabs(B.Get_Y() - A.Get_Y());
+
+	if( dx > 0.0 || dy > 0.0 )
+	{
+		if( dx > dy )
+		{
+			dx	/= Get_Cellsize();
+			n	 = dx;
+			dy	/= dx;
+			dx	 = Get_Cellsize();
+		}
+		else
+		{
+			dy	/= Get_Cellsize();
+			n	 = dy;
+			dx	/= dy;
+			dy	 = Get_Cellsize();
+		}
+
+		dx		= A.Get_X() < B.Get_X() ? dx : -dx;
+		dy		= A.Get_Y() < B.Get_Y() ? dy : -dy;
+
+		dStep	.Assign( dx, dy);
+		Step	.Assign(-dy, dx);
+
+		if( fabs(Step.Get_X()) > fabs(Step.Get_Y()) )
+		{
+			if( Left.Get_X() > Right.Get_X() )
+			{
+				p	= Left;	Left	= Right;	Right	= p;
+			}
+
+			if( Step.Get_X() < 0.0 )
+			{
+				Step.Assign(-Step.Get_X(), -Step.Get_Y());
+			}
+		}
+		else
+		{
+			if( Left.Get_Y() > Right.Get_Y() )
+			{
+				p	= Left;	Left	= Right;	Right	= p;
+			}
+
+			if( Step.Get_Y() < 0.0 )
+			{
+				Step.Assign(-Step.Get_X(), -Step.Get_Y());
+			}
+		}
+
+		//-------------------------------------------------
+		for(d=0.0; d<=n; d++, A+=dStep, Left+=dStep, Right+=dStep)
+		{
+			Add_Point(A, Left, Right, Step);
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::Add_Point(CSG_Point Point, CSG_Point Left, CSG_Point Right, CSG_Point Step)
+{
+	int		i, j;
+	double	Distance;
+	CSG_Shape	*pPoint, *pLast;
+
+	if( m_pDEM->is_InGrid_byPos(Point) )
+	{
+		if( m_pPoints->Get_Count() == 0 )
+		{
+			Distance	= 0.0;
+		}
+		else
+		{
+			pLast		= m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1);
+			Distance	= SG_Get_Distance(Point, pLast->Get_Point(0));
+
+			if( Distance == 0.0 )
+			{
+				return( false );
+			}
+
+			Distance	+= pLast->asDouble(1);
+		}
+
+		pPoint	= m_pPoints->Add_Shape();
+		pPoint->Add_Point(Point);
+
+		pPoint->Set_Value(0, m_pPoints->Get_Count());
+		pPoint->Set_Value(1, Distance);
+		pPoint->Set_Value(2, Point.Get_X());
+		pPoint->Set_Value(3, Point.Get_Y());
+
+		pPoint->Set_Value(4, m_pDEM->Get_Value(Point, GRID_INTERPOLATION_BSpline, true));
+		Add_Swath(pPoint, 4, m_pDEM, Left, Right, Step);
+
+		for(i=0, j=VALUE_OFFSET; i<m_pValues->Get_Count(); i++, j+=6)
+		{
+			pPoint->Set_Value(j, m_pValues->asGrid(i)->Get_Value(Point, GRID_INTERPOLATION_BSpline, true));
+			Add_Swath(pPoint, j, m_pValues->asGrid(i), Left, Right, Step);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CGrid_Swath_Profile::Add_Swath(CSG_Table_Record *pRecord, int iEntry, CSG_Grid *pGrid, CSG_Point Left, CSG_Point Right, CSG_Point Step)
+{
+	int		n;
+	double	z, Sum, Sum2, Min, Max, iRun, dRun, nRun;
+
+	if( Step.Get_X() > Step.Get_Y() )
+	{
+		iRun	= Left	.Get_X();
+		dRun	= Step	.Get_X();
+		nRun	= Right	.Get_X();
+	}
+	else
+	{
+		iRun	= Left	.Get_Y();
+		dRun	= Step	.Get_Y();
+		nRun	= Right	.Get_Y();
+	}
+
+	for(n=0, Sum=0.0, Sum2=0.0; iRun<=nRun; iRun+=dRun, Left+=Step)
+	{
+		if( pGrid->Get_Value(Left, z, GRID_INTERPOLATION_BSpline, true) )
+		{
+			if( n == 0 )
+				Min	= Max	= z;
+			else if( z < Min )
+				Min	= z;
+			else if( z > Max )
+				Max	= z;
+
+			Sum		+= z;
+			Sum2	+= z * z;
+
+			n++;
+		}
+	}
+
+	if( n > 0 )
+	{
+		Sum		/= (double)n;							// arithmetic mean
+		Sum2	= sqrt(Sum2 / (double)n - Sum * Sum);	// standard deviation
+
+		pRecord->Set_Value(iEntry + 1, Sum);
+		pRecord->Set_Value(iEntry + 2, Min);
+		pRecord->Set_Value(iEntry + 3, Max);
+		pRecord->Set_Value(iEntry + 4, Sum - Sum2);
+		pRecord->Set_Value(iEntry + 5, Sum + Sum2);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Grid_Swath_Profile.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  Grid_Swath_Profile.h                 //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Grid_Swath_Profile_H
+#define HEADER_INCLUDED__Grid_Swath_Profile_H
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CGrid_Swath_Profile : public CSG_Module_Grid_Interactive
+{
+public:
+	CGrid_Swath_Profile(void);
+	virtual ~CGrid_Swath_Profile(void);
+
+
+protected:
+
+	virtual bool				On_Execute			(void);
+	virtual bool				On_Execute_Finish	(void);
+	virtual bool				On_Execute_Position	(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+
+
+private:
+
+	bool						m_bAdd;
+
+	double						m_Width;
+
+	CSG_Shapes					*m_pPoints, *m_pLine;
+
+	CSG_Grid					*m_pDEM;
+
+	CSG_Parameter_Grid_List		*m_pValues;
+
+
+	bool						Set_Profile	(void);
+	bool						Set_Profile	(CSG_Point A, CSG_Point B, CSG_Point Left, CSG_Point Right);
+
+	bool						Add_Point	(CSG_Point Point, CSG_Point Left, CSG_Point Right, CSG_Point Step);
+	bool						Add_Swath	(CSG_Table_Record *pRecord, int iEntry, CSG_Grid *pGrid, CSG_Point Left, CSG_Point Right, CSG_Point Step);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Grid_Swath_Profile_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   MLB_Interface.cpp                   //
+//                                                       //
+//                 Copyright (C) 2004 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			The Module Link Library Interface			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "MLB_Interface.h"
+
+
+//---------------------------------------------------------
+const SG_Char * Get_Info(int i)
+{
+	switch( i )
+	{
+	case MLB_INFO_Name:	default:
+		return( _TL("Terrain Analysis - Profiles") );
+
+	case MLB_INFO_Author:
+		return( _TL("O. Conrad and V. Olaya, (c) 2004-06") );
+
+	case MLB_INFO_Description:
+		return( _TL("Simple, flow path and swath profiles.") );
+
+	case MLB_INFO_Version:
+		return( SG_T("1.0") );
+
+	case MLB_INFO_Menu_Path:
+		return( _TL("Terrain Analysis|Profiles" ));
+	}
+}
+
+
+//---------------------------------------------------------
+#include "Grid_Profile.h"
+#include "Grid_Flow_Profile.h"
+#include "Grid_Swath_Profile.h"
+#include "Grid_CrossSections.h"
+#include "Grid_Cross_Profiles.h"
+#include "Grid_Profile_From_Lines.h"
+#include "Grid_ProfileFromPoints.h"
+
+
+//---------------------------------------------------------
+CSG_Module *		Create_Module(int i)
+{
+	switch( i )
+	{
+	case 0:	return( new CGrid_Profile );
+	case 1:	return( new CGrid_Flow_Profile );
+	case 2:	return( new CGrid_Swath_Profile );
+	case 3:	return( new CGrid_CrossSections );
+	case 4:	return( new CGrid_Cross_Profiles );
+	case 5:	return( new CGrid_Profile_From_Lines );
+	case 6:	return( new CProfileFromPoints );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//{{AFX_SAGA
+
+	MLB_INTERFACE
+
+//}}AFX_SAGA

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/MLB_Interface.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,69 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                     ta_profiles                       //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    MLB_Interface.h                    //
+//                                                       //
+//                 Copyright (C) 2003 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Include the SAGA-API here				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__ta_profiles_H
+#define HEADER_INCLUDED__ta_profiles_H
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__ta_profiles_H

Added: packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Polygon_Clipper.h
===================================================================
--- packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Polygon_Clipper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/modules_terrain_analysis/terrain_analysis/ta_profiles/Polygon_Clipper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,95 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    Module Library:                    //
+//                    shapes_polygons                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   Polygon_Clipper.h                   //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//                                                       //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__Polygon_Clipper_H
+#define HEADER_INCLUDED__Polygon_Clipper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		GPC_Intersection	(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_Difference		(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_ExclusiveOr		(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+bool		GPC_Union			(CSG_Shape *pShape_A, CSG_Shape *pShape_B, CSG_Shape *pShape_AB = NULL);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__Polygon_Clipper_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_callback.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_callback.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_callback.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,519 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   api_callback.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "api_core.h"
+#include "grid.h"
+#include "parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_PFNC_UI_Callback	gSG_UI_Callback	= NULL;
+
+//---------------------------------------------------------
+bool					SG_Set_UI_Callback(TSG_PFNC_UI_Callback Function)
+{
+	gSG_UI_Callback	= Function;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+TSG_PFNC_UI_Callback	SG_Get_UI_Callback(void)
+{
+	return( gSG_UI_Callback );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int			gSG_UI_Progress_Lock	= 0;
+
+//---------------------------------------------------------
+int			SG_UI_Progress_Lock(bool bOn)
+{
+	if( bOn )
+	{
+		gSG_UI_Progress_Lock++;
+	}
+	else if( gSG_UI_Progress_Lock > 0 )
+	{
+		gSG_UI_Progress_Lock--;
+	}
+
+	return( gSG_UI_Progress_Lock );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_Process_Get_Okay(bool bBlink)
+{
+	if( gSG_UI_Callback )
+	{
+		return( gSG_UI_Callback(CALLBACK_PROCESS_GET_OKAY, gSG_UI_Progress_Lock && bBlink ? 1 : 0, 0) != 0 );
+	}
+	else
+	{
+		if( gSG_UI_Progress_Lock && bBlink )
+		{
+			static int	iBuisy		= 0;
+			const SG_Char	Buisy[4]	= {	'|', '/', '-', '\\'	};
+
+			SG_PRINTF(SG_T("\r%c   "), Buisy[iBuisy++]);
+			iBuisy	%= 4;
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_Process_Set_Okay(bool bOkay)
+{
+	if( gSG_UI_Callback )
+	{
+		return( gSG_UI_Callback(CALLBACK_PROCESS_SET_OKAY, bOkay ? 1 : 0, 0) != 0 );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_Process_Set_Progress(double Position, double Range)
+{
+	if( gSG_UI_Progress_Lock > 0 )
+	{
+		if( gSG_UI_Callback )
+		{
+			return( gSG_UI_Callback(CALLBACK_PROCESS_GET_OKAY, 0, 0) != 0 );
+		}
+	}
+	else
+	{
+		if( gSG_UI_Callback )
+		{
+			return( gSG_UI_Callback(CALLBACK_PROCESS_SET_PROGRESS, (long)&Position, (long)&Range) != 0 );
+		}
+		else
+		{
+			SG_PRINTF(SG_T("\r%3d%%"), Range != 0.0 ? 1 + (int)(100.0 * Position / Range) : 100);
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_Process_Set_Ready(void)
+{
+	if( gSG_UI_Callback )
+	{
+		SG_UI_Process_Set_Text(LNG("ready"));
+
+		return( gSG_UI_Callback(CALLBACK_PROCESS_SET_READY, 0, 0) != 0 );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void		SG_UI_Process_Set_Text(const SG_Char *Text)
+{
+	if( gSG_UI_Progress_Lock == 0 )
+	{
+		if( gSG_UI_Callback )
+		{
+			gSG_UI_Callback(CALLBACK_PROCESS_SET_TEXT, (long)Text, 0);
+		}
+		else
+		{
+			SG_PRINTF(SG_T("\n%s"), Text);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		SG_UI_Dlg_Message(const SG_Char *Message, const SG_Char *Caption)
+{
+	if( gSG_UI_Callback )
+	{
+		gSG_UI_Callback(CALLBACK_DLG_MESSAGE, (long)Message, (long)Caption);
+	}
+	else
+	{
+		SG_PRINTF(SG_T("\n%s: %s"), Caption, Message);
+	}
+}
+
+//---------------------------------------------------------
+bool		SG_UI_Dlg_Continue(const SG_Char *Message, const SG_Char *Caption)
+{
+	if( gSG_UI_Callback )
+	{
+		return( gSG_UI_Callback(CALLBACK_DLG_CONTINUE, (long)Message, (long)Caption) != 0 );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+int			SG_UI_Dlg_Error(const SG_Char *Message, const SG_Char *Caption)
+{
+	if( gSG_UI_Callback )
+	{
+		return( gSG_UI_Callback(CALLBACK_DLG_ERROR, (long)Message, (long)Caption) );
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		SG_UI_Dlg_Parameters(CSG_Parameters *pParameters, const SG_Char *Caption)
+{
+	if( gSG_UI_Callback && pParameters )
+	{
+		return( gSG_UI_Callback(CALLBACK_DLG_PARAMETERS, (long)pParameters, (long)Caption) != 0 );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int			gSG_UI_Msg_Lock	= 0;
+
+//---------------------------------------------------------
+int			SG_UI_Msg_Lock(bool bOn)
+{
+	if( bOn )
+	{
+		gSG_UI_Msg_Lock++;
+	}
+	else if( gSG_UI_Msg_Lock > 0 )
+	{
+		gSG_UI_Msg_Lock--;
+	}
+
+	return( gSG_UI_Msg_Lock );
+}
+
+//---------------------------------------------------------
+void		SG_UI_Msg_Add(const SG_Char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
+{
+	if( gSG_UI_Msg_Lock )
+		return;
+
+	if( gSG_UI_Callback )
+	{
+		int		Parameters[2];
+
+		Parameters[0]	= bNewLine ? 1 : 0;
+		Parameters[1]	= Style;
+
+		gSG_UI_Callback(CALLBACK_MESSAGE_ADD, (long)Message, (long)Parameters);
+	}
+	else
+	{
+		SG_PRINTF(SG_T("%s"), Message);
+
+		if( bNewLine )
+		{
+			SG_PRINTF(SG_T("\n\n"));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void		SG_UI_Msg_Add_Error(const SG_Char *Message)
+{
+	if( gSG_UI_Msg_Lock )
+		return;
+
+	if( gSG_UI_Callback )
+	{
+		gSG_UI_Callback(CALLBACK_MESSAGE_ADD_ERROR, (long)Message, 0);
+	}
+	else
+	{
+		SG_PRINTF(SG_T("\n%s: %s"), LNG("Error"), Message);
+	}
+}
+
+//---------------------------------------------------------
+void		SG_UI_Msg_Add_Execution(const SG_Char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
+{
+	if( gSG_UI_Msg_Lock )
+		return;
+
+	if( gSG_UI_Callback )
+	{
+		int		Parameters[2];
+
+		Parameters[0]	= bNewLine ? 1 : 0;
+		Parameters[1]	= Style;
+
+		gSG_UI_Callback(CALLBACK_MESSAGE_ADD_EXECUTION, (long)Message, (long)Parameters);
+	}
+	else
+	{
+		SG_PRINTF(SG_T("%s"), Message);
+
+		if( bNewLine )
+		{
+			SG_PRINTF(SG_T("\n\n"));
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Data_Object *	SG_UI_DataObject_Find(const SG_Char *File_Name, int Object_Type)
+{
+	if( gSG_UI_Callback && File_Name )
+	{
+		return( (class CSG_Data_Object *)gSG_UI_Callback(CALLBACK_DATAOBJECT_FIND_BY_FILE, (long)File_Name, Object_Type) );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Check(CSG_Data_Object *pDataObject, int Object_Type)
+{
+	if( gSG_UI_Callback && pDataObject )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_CHECK, (long)pDataObject, Object_Type) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Add(CSG_Data_Object *pDataObject, int Show)
+{
+	if( gSG_UI_Callback && pDataObject )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_ADD, (long)pDataObject, Show ? 1 : 0) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Update(CSG_Data_Object *pDataObject, int Show, CSG_Parameters *pParameters)
+{
+	CSG_Parameters	Parameters;
+
+	if( gSG_UI_Callback && pDataObject )
+	{
+		if( gSG_UI_Callback(CALLBACK_DATAOBJECT_UPDATE, (long)pDataObject, (long)pParameters) != 0 )
+		{
+			if( Show != SG_UI_DATAOBJECT_UPDATE_ONLY )
+			{
+				SG_UI_DataObject_Show(pDataObject, Show);
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Show(CSG_Data_Object *pDataObject, int Show)
+{
+	if( gSG_UI_Callback && pDataObject )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_SHOW, (long)pDataObject, Show) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_asImage(CSG_Data_Object *pDataObject, CSG_Grid *pGrid)
+{
+	if( gSG_UI_Callback && pDataObject )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_ASIMAGE, (long)pDataObject, (long)pGrid) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Colors_Get(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
+{
+	if( gSG_UI_Callback && pDataObject && pColors )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_COLORS_GET, (long)pDataObject, (long)pColors) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Colors_Set(CSG_Data_Object *pDataObject, CSG_Colors *pColors)
+{
+	if( gSG_UI_Callback && pDataObject && pColors )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_COLORS_SET, (long)pDataObject, (long)pColors) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Params_Get	(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
+{
+	if( gSG_UI_Callback && pDataObject && pParameters )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_PARAMS_GET, (long)pDataObject, (long)pParameters) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Params_Set	(CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
+{
+	if( gSG_UI_Callback && pDataObject && pParameters )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_PARAMS_SET, (long)pDataObject, (long)pParameters) != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		SG_UI_DataObject_Get_All(class CSG_Parameters *pParameters)
+{
+	if( gSG_UI_Callback && pParameters )
+	{
+		return( gSG_UI_Callback(CALLBACK_DATAOBJECT_GET_ALL, (long)pParameters, 0) != 0 );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void *		SG_UI_Get_Window_Main(void)
+{
+	if( gSG_UI_Callback )
+	{
+		return( (void *)gSG_UI_Callback(CALLBACK_GUI_GET_WINDOW, 0, 0) );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_colors.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_colors.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_colors.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,916 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   api_colors.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					class CSG_Colors					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <stdlib.h>
+#include <string.h>
+
+#include "api_core.h"
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define COLORS_SERIAL_VERSION_BINARY	SG_T("SAGA_COLORPALETTE_VERSION_0.100_BINARY")
+#define COLORS_SERIAL_VERSION__ASCII	SG_T("SAGA_COLORPALETTE_VERSION_0.100__ASCII")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Colors::CSG_Colors(void)
+{
+	m_Colors	= NULL;
+	m_nColors	= 0;
+
+	Set_Count(100);
+}
+
+//---------------------------------------------------------
+CSG_Colors::CSG_Colors(const CSG_Colors &Colors)
+{
+	m_Colors	= NULL;
+	m_nColors	= 0;
+
+	Assign(Colors);
+}
+
+//---------------------------------------------------------
+CSG_Colors::CSG_Colors(int nColors, int Palette, bool bRevert)
+{
+	m_Colors	= NULL;
+	m_nColors	= 0;
+
+	if( nColors <= 1 )
+	{
+		nColors	= 100;
+	}
+
+	Set_Count(nColors);
+
+	Set_Palette(Palette, bRevert, nColors);
+}
+
+//---------------------------------------------------------
+CSG_Colors::~CSG_Colors(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Colors::Destroy(void)
+{
+	if( m_nColors > 0 )
+	{
+		SG_Free(m_Colors);
+
+		m_Colors	= NULL;
+		m_nColors	= 0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Count(int nColors)
+{
+	int		i, j, ja, jb;
+	long	*Colors;
+	double	d, dj, dRed, dGreen, dBlue;
+
+	if( nColors > 0 && nColors != m_nColors )
+	{
+		if( m_nColors == 0 )
+		{
+			Set_Default(nColors);
+		}
+		else
+		{
+			Colors	= (long *)SG_Malloc(nColors * sizeof(long));
+
+			//---------------------------------------------
+			if( nColors < m_nColors )
+			{
+				d	= (double)m_nColors / (double)nColors;
+
+				for(i=0; i<nColors; i++)
+				{
+					j	= (int)(i * d);
+
+					Colors[i]	= SG_GET_RGB(Get_Red(j), Get_Green(j), Get_Blue(j));
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				jb	= 0;
+				d	= (double)nColors / (double)(m_nColors - 1);
+
+				for(i=0; i<m_nColors-1; i++)
+				{
+					ja	= jb;
+					jb	= (int)((i + 1.0) * d);
+					dj	= jb - ja;
+
+					if( dj > 0 )
+					{
+						dRed	= (double)(Get_Red  (i) - Get_Red  (i + 1)) / dj;
+						dGreen	= (double)(Get_Green(i) - Get_Green(i + 1)) / dj;
+						dBlue	= (double)(Get_Blue (i) - Get_Blue (i + 1)) / dj;
+
+						for(j=ja; j<jb; j++)
+						{
+							Colors[j]	= SG_GET_RGB(
+								Get_Red  (i) - (j - ja) * dRed,
+								Get_Green(i) - (j - ja) * dGreen,
+								Get_Blue (i) - (j - ja) * dBlue
+							);
+						}
+					}
+					else
+					{
+						Colors[ja]	= m_Colors[i];
+					}
+				}
+			}
+
+			//---------------------------------------------
+			SG_Free(m_Colors);
+
+			m_nColors	= nColors;
+			m_Colors	= Colors;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Color(int Index, long Color)
+{
+	if( Index >= 0 && Index < m_nColors )
+	{
+		m_Colors[Index]	= Color;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Color(int Index, int Red, int Green, int Blue)
+{
+	return( Set_Color(Index, SG_GET_RGB(Red, Green, Blue)) );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Red(int Index, int Value)
+{
+	return( Set_Color(Index, Value			, Get_Green(Index)	, Get_Blue(Index)) );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Green(int Index, int Value)
+{
+	return( Set_Color(Index, Get_Red(Index)	, Value				, Get_Blue(Index)) );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Blue(int Index, int Value)
+{
+	return( Set_Color(Index, Get_Red(Index)	, Get_Green(Index)	, Value) );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Brightness(int Index, int Value)
+{
+	double	r, g, b, ds;
+
+	//-----------------------------------------------------
+	if( Value < 0 )
+	{
+		Value	= 0;
+	}
+	else if( Value > 255 )
+	{
+		Value	= 255;
+	}
+
+	//-----------------------------------------------------
+	r	= Get_Red  (Index);
+	g	= Get_Green(Index);
+	b	= Get_Blue (Index);
+	ds	= (r + g + b) / 3.0;
+
+	if( ds > 0.0 )
+	{
+		ds	= Value / ds;
+		r	*= ds;
+		g	*= ds;
+		b	*= ds;
+
+		_Set_Brightness(r, g, b);
+	}
+	else
+	{
+		r	= g	= b	= Value / 3.0;
+	}
+
+	return( Set_Color(Index, (int)r, (int)g, (int)b) );
+}
+
+//---------------------------------------------------------
+void CSG_Colors::_Set_Brightness(double &a, double &b, double &c, int Pass)
+{
+	if( a > 255 )
+	{
+		int		addSum;
+
+		addSum	= (int)((a - 255) / 2.0);
+		a		= 255;
+
+		b		+= addSum;
+		c		+= addSum;
+
+		if( b > 255 )
+		{
+			addSum	= (int)(b - 255);
+			b		= 255;
+
+			c		+= addSum;
+
+			if( c > 255 )
+			{
+				c	= 255;
+			}
+		}
+		else if( c > 255 )
+		{
+			addSum	= (int)(c - 255);
+			c		= 255;
+
+			b		+= addSum;
+
+			if( b > 255 )
+			{
+				b	= 255;
+			}
+		}
+	}
+	else if( Pass < 2 )
+	{
+		_Set_Brightness(b, c, a, Pass + 1);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Default(int nColors)
+{
+	int		i;
+	double	d, dStep;
+
+	if( nColors > 0 )
+	{
+		m_nColors	= nColors;
+		m_Colors	= (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
+
+		dStep		= 2 * M_PI / (double)Get_Count();
+
+		for(i=0, d=0; i<Get_Count(); i++, d+=dStep)
+		{
+			Set_Color(i,
+				(int)(d < M_PI / 2 ? 0 : 128 - 127 * sin(M_PI - d)),
+				(int)(128 - 127 * cos(d)),
+				(int)(d > M_PI * 3 / 2 ? 0 : 128 + 127 * sin(d))
+			);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Palette(int Index, bool bRevert, int nColors)
+{
+	switch( Index )
+	{
+	default:
+		return( false );
+
+	case SG_COLORS_DEFAULT:
+		Set_Default(nColors);
+		break;
+
+	case SG_COLORS_DEFAULT_BRIGHT:
+		Set_Default(nColors);
+		Set_Ramp_Brighness(127, 127);
+		break;
+
+	case SG_COLORS_BLACK_WHITE:
+		Set_Ramp(SG_GET_RGB(  0,   0,   0), SG_GET_RGB(255, 255, 255));
+		break;
+
+	case SG_COLORS_BLACK_RED:
+		Set_Ramp(SG_GET_RGB(  0,   0,   0), SG_GET_RGB(255,   0,   0));
+		break;
+
+	case SG_COLORS_BLACK_GREEN:
+		Set_Ramp(SG_GET_RGB(  0,   0,   0), SG_GET_RGB(  0, 255,   0));
+		break;
+
+	case SG_COLORS_BLACK_BLUE:
+		Set_Ramp(SG_GET_RGB(  0,   0,   0), SG_GET_RGB(  0,   0, 255));
+		break;
+
+	case SG_COLORS_WHITE_RED:
+		Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB(255,   0,   0));
+		break;
+
+	case SG_COLORS_WHITE_GREEN:
+		Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB(  0, 127,   0));
+		break;
+
+	case SG_COLORS_WHITE_BLUE:
+		Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB(  0,   0, 191));
+		break;
+
+	case SG_COLORS_YELLOW_RED:
+		Set_Ramp(SG_GET_RGB(255, 255,   0), SG_GET_RGB(191,   0,   0));
+		break;
+
+	case SG_COLORS_YELLOW_GREEN:
+		Set_Ramp(SG_GET_RGB(255, 255,   0), SG_GET_RGB(  0,  63,   0));
+		break;
+
+	case SG_COLORS_YELLOW_BLUE:
+		Set_Ramp(SG_GET_RGB(255, 255,   0), SG_GET_RGB(  0,   0,  255));
+		break;
+
+	case SG_COLORS_RED_GREEN:
+//		Set_Ramp(SG_GET_RGB(255,   0,   0), SG_GET_RGB(  0, 255,   0));
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(  0, 255,   0));
+		Set_Color(1, SG_GET_RGB(191, 191,   0));
+		Set_Color(2, SG_GET_RGB(255, 127,   0));
+		Set_Color(3, SG_GET_RGB(223,  63,   0));
+		Set_Color(4, SG_GET_RGB( 63,   0,   0));
+		break;
+
+	case SG_COLORS_RED_BLUE:
+		Set_Ramp(SG_GET_RGB(255,   0,   0), SG_GET_RGB(  0,   0, 255));
+		break;
+
+	case SG_COLORS_GREEN_BLUE:
+		Set_Ramp(SG_GET_RGB(  0, 255,   0), SG_GET_RGB(  0,   0, 255));
+		break;
+
+	case SG_COLORS_RED_GREY_BLUE:
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(127,   0,   0));
+		Set_Color(1, SG_GET_RGB(255, 127,   0));
+		Set_Color(2, SG_GET_RGB(200, 200, 200));
+		Set_Color(3, SG_GET_RGB(  0, 127, 255));
+		Set_Color(4, SG_GET_RGB(  0,   0, 127));
+		break;
+
+	case SG_COLORS_RED_GREY_GREEN:
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(127,   0,   0));
+		Set_Color(1, SG_GET_RGB(255, 127,   0));
+		Set_Color(2, SG_GET_RGB(200, 200, 200));
+		Set_Color(3, SG_GET_RGB(  0, 255, 127));
+		Set_Color(4, SG_GET_RGB(  0, 127,   0));
+		break;
+
+	case SG_COLORS_GREEN_GREY_BLUE:
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(  0, 127,   0));
+		Set_Color(1, SG_GET_RGB(127, 255,   0));
+		Set_Color(2, SG_GET_RGB(200, 200, 200));
+		Set_Color(3, SG_GET_RGB(  0, 127, 255));
+		Set_Color(4, SG_GET_RGB(  0,   0, 127));
+		break;
+
+	case SG_COLORS_RED_GREEN_BLUE:
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(127,   0, 127));
+		Set_Color(1, SG_GET_RGB(255,   0,   0));
+		Set_Color(2, SG_GET_RGB(  0, 255,   0));
+		Set_Color(3, SG_GET_RGB(  0,   0, 255));
+		Set_Color(4, SG_GET_RGB(127,   0, 127));
+		break;
+
+	case SG_COLORS_RED_BLUE_GREEN:
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(127, 127,   0));
+		Set_Color(1, SG_GET_RGB(255,   0,   0));
+		Set_Color(2, SG_GET_RGB(  0,   0, 255));
+		Set_Color(3, SG_GET_RGB(  0, 255,   0));
+		Set_Color(4, SG_GET_RGB(127, 127,   0));
+		break;
+
+	case SG_COLORS_GREEN_RED_BLUE:
+		Set_Count(5);
+		Set_Color(0, SG_GET_RGB(  0, 127, 127));
+		Set_Color(1, SG_GET_RGB(  0, 255,   0));
+		Set_Color(2, SG_GET_RGB(255,   0,   0));
+		Set_Color(3, SG_GET_RGB(  0,   0, 255));
+		Set_Color(4, SG_GET_RGB(  0, 127, 127));
+		break;
+
+	case SG_COLORS_RAINBOW:
+		Set_Count(8);
+		Set_Color(0, SG_GET_RGB(127,   0, 127));
+		Set_Color(1, SG_GET_RGB(  0,   0, 255));
+		Set_Color(2, SG_GET_RGB(  0, 255, 255));
+		Set_Color(3, SG_GET_RGB(  0, 191,   0));
+		Set_Color(4, SG_GET_RGB(255, 255,   0));
+		Set_Color(5, SG_GET_RGB(255, 127,   0));
+		Set_Color(6, SG_GET_RGB(255,   0,   0));
+		Set_Color(7, SG_GET_RGB(127,   0,   0));
+		break;
+
+	case SG_COLORS_NEON:
+		Set_Count(7);
+		Set_Color(0, SG_GET_RGB(  0,   0,   0));
+		Set_Color(1, SG_GET_RGB(255,   0,   0));
+		Set_Color(2, SG_GET_RGB(  0,   0,   0));
+		Set_Color(3, SG_GET_RGB(255, 255,   0));
+		Set_Color(4, SG_GET_RGB(  0,   0,   0));
+		Set_Color(5, SG_GET_RGB(  0, 255,   0));
+		Set_Color(6, SG_GET_RGB(  0,   0,   0));
+		break;
+	}
+
+	//-----------------------------------------------------
+	Set_Count(nColors);
+
+	if( bRevert )
+	{
+		Revert();
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Ramp(long Color_A, long Color_B)
+{
+	return( Set_Ramp(Color_A, Color_B, 0, Get_Count() - 1) );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Ramp(long Color_A, long Color_B, int iColor_A, int iColor_B)
+{
+	int		i, n, ar, ag, ab;
+	double	dr, dg, db;
+
+	//-----------------------------------------------------
+	if( iColor_A > iColor_B )
+	{
+		i			= iColor_A;
+		iColor_A	= iColor_B;
+		iColor_B	= i;
+	}
+
+	if( iColor_A < 0 )
+	{
+		iColor_A	= 0;
+	}
+
+	if( iColor_B >= Get_Count() )
+	{
+		iColor_B	= Get_Count() - 1;
+	}
+
+	//-----------------------------------------------------
+	if( (n = iColor_B - iColor_A) > 0 )
+	{
+		ar		= SG_GET_R(Color_A);
+		dr		= (double)(SG_GET_R(Color_B) - ar) / (double)n;
+
+		ag		= SG_GET_G(Color_A);
+		dg		= (double)(SG_GET_G(Color_B) - ag) / (double)n;
+
+		ab		= SG_GET_B(Color_A);
+		db		= (double)(SG_GET_B(Color_B) - ab) / (double)n;
+
+		for(i=0; i<=n; i++)
+		{
+			Set_Color(iColor_A + i,
+				(int)(ar + i * dr),
+				(int)(ag + i * dg),
+				(int)(ab + i * db)
+			);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Ramp_Brighness(int Brightness_A, int Brightness_B)
+{
+	return( Set_Ramp_Brighness(Brightness_A, Brightness_B, 0, Get_Count() - 1) );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Set_Ramp_Brighness(int Brightness_A, int Brightness_B, int iColor_A, int iColor_B)
+{
+	int		i, n;
+	double	dBrightness;
+
+	//-----------------------------------------------------
+	if( iColor_A > iColor_B )
+	{
+		i			= iColor_A;
+		iColor_A	= iColor_B;
+		iColor_B	= i;
+	}
+
+	if( iColor_A < 0 )
+	{
+		iColor_A	= 0;
+	}
+
+	if( iColor_B >= Get_Count() )
+	{
+		iColor_B	= Get_Count() - 1;
+	}
+
+	//-----------------------------------------------------
+	if( (n = iColor_B - iColor_A) > 0 )
+	{
+		dBrightness	= (double)(Brightness_B - Brightness_A) / (double)n;
+
+		for(i=0; i<=n; i++)
+		{
+			Set_Brightness(iColor_A + i, (int)(Brightness_A + i * dBrightness));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Colors::Random(void)
+{
+	int		i;
+
+	for(i=0; i<Get_Count(); i++)
+	{
+		Set_Color(i,
+			(int)(255.0 * (double)rand() / (double)RAND_MAX),
+			(int)(255.0 * (double)rand() / (double)RAND_MAX),
+			(int)(255.0 * (double)rand() / (double)RAND_MAX)
+		);
+	}
+
+	return( Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Invert(void)
+{
+	int		i;
+
+	for(i=0; i<Get_Count(); i++)
+	{
+		Set_Color(i, 255 - Get_Red(i), 255 - Get_Green(i), 255 - Get_Blue(i));
+	}
+
+	return( Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Revert(void)
+{
+	int		i, j;
+	long	c;
+
+	for(i=0, j=Get_Count()-1; i<j; i++, j--)
+	{
+		c		=    Get_Color(j);
+		Set_Color(j, Get_Color(i));
+		Set_Color(i, c);
+	}
+
+	return( Get_Count() > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Colors & CSG_Colors::operator = (const CSG_Colors &Colors)
+{
+	Assign(Colors);
+
+	return( *this );
+}
+
+bool CSG_Colors::Assign(const CSG_Colors &Colors)
+{
+	if( Colors.m_nColors > 0 )
+	{
+		m_nColors	= Colors.m_nColors;
+		m_Colors	= (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
+
+		memcpy(m_Colors, Colors.m_Colors, m_nColors * sizeof(long));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_Colors::Assign(CSG_Colors *pColors)
+{
+	return( pColors ? Assign(*pColors) : false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Colors::Load(const CSG_String &File_Name)
+{
+	CSG_String	Version;
+	CSG_File	Stream;
+
+	if( Stream.Open(File_Name, SG_FILE_R, true) )
+	{
+		Stream.Read(Version, sizeof(COLORS_SERIAL_VERSION_BINARY));
+
+		if( !Version.Cmp(COLORS_SERIAL_VERSION_BINARY) )
+		{
+			return( Serialize(Stream, false, true) );
+		}
+		else if( !Version.Cmp(COLORS_SERIAL_VERSION__ASCII) )
+		{
+			return( Serialize(Stream, false, false) );
+		}
+		else	// SAGA 1.x compatibility...
+		{
+			short		nColors;
+
+			Stream.Seek_Start();
+			Stream.Read(&nColors, sizeof(short));
+
+			if( Stream.Length() == (int)(sizeof(short) + 3 * nColors) )
+			{
+				BYTE	*R, *G, *B;
+
+				R	= (BYTE *)SG_Malloc(nColors * sizeof(BYTE));
+				G	= (BYTE *)SG_Malloc(nColors * sizeof(BYTE));
+				B	= (BYTE *)SG_Malloc(nColors * sizeof(BYTE));
+
+				Stream.Read(R, nColors * sizeof(BYTE));
+				Stream.Read(G, nColors * sizeof(BYTE));
+				Stream.Read(B, nColors * sizeof(BYTE));
+
+				Set_Count(nColors);
+
+				for(int i=0; i<nColors; i++)
+				{
+					Set_Color(i, R[i], G[i], B[i]);
+				}
+
+				SG_Free(R);
+				SG_Free(G);
+				SG_Free(B);
+
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Colors::Save(const CSG_String &File_Name, bool bBinary)
+{
+	CSG_File	Stream;
+
+	if( Stream.Open(File_Name, SG_FILE_W, true) )
+	{
+		if( bBinary )
+		{
+			Stream.Write((void *)COLORS_SERIAL_VERSION_BINARY, sizeof(COLORS_SERIAL_VERSION_BINARY));
+		}
+		else
+		{
+			Stream.Printf(SG_T("%s\n"), COLORS_SERIAL_VERSION__ASCII);
+		}
+
+		Serialize(Stream, true, bBinary);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Colors::Serialize(CSG_File &Stream, bool bSave, bool bBinary)
+{
+	int		i, r, g, b;
+
+	if( Stream.is_Open() )
+	{
+		if( bBinary )
+		{
+			if( bSave )
+			{
+				if( m_nColors > 0 )
+				{
+					Stream.Write(&m_nColors, sizeof(m_nColors));
+					Stream.Write(m_Colors, sizeof(long), m_nColors);
+				}
+			}
+			else
+			{
+				Stream.Read(&i, sizeof(m_nColors));
+
+				if( i > 0 )
+				{
+					Set_Count(i);
+
+					Stream.Read(m_Colors, sizeof(long), m_nColors);
+				}
+			}
+
+			return( true );
+		}
+		else
+		{
+			if( bSave )
+			{
+				if( m_nColors > 0 )
+				{
+					Stream.Printf(SG_T("%d\n"), m_nColors);
+
+					for(i=0; i<m_nColors; i++)
+					{
+						Stream.Printf(SG_T("%03d %03d %03d\n"), (int)Get_Red(i), (int)Get_Green(i), (int)Get_Blue(i));
+					}
+				}
+			}
+			else
+			{
+				SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%d"), &i);
+
+				if( i > 0 )
+				{
+					Set_Count(i);
+
+					for(i=0; i<m_nColors; i++)
+					{
+						SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%d %d %d"), &r, &g, &b);
+
+						m_Colors[i]	= SG_GET_RGB(r, g, b);
+					}
+				}
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,102 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     api_core.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char *	SG_Data_Type_Get_Name	(TSG_Data_Type Type)
+{
+	switch( Type )
+	{
+	default:					return( LNG("undefined") );
+	case SG_DATATYPE_Bit:		return( LNG("bit") );
+	case SG_DATATYPE_Byte:		return( LNG("unsigned 1 byte integer") );
+	case SG_DATATYPE_Char:		return( LNG("signed 1 byte integer") );
+	case SG_DATATYPE_Word:		return( LNG("unsigned 2 byte integer") );
+	case SG_DATATYPE_Short:		return( LNG("signed 2 byte integer") );
+	case SG_DATATYPE_DWord:		return( LNG("unsigned 4 byte integer") );
+	case SG_DATATYPE_Int:		return( LNG("signed 4 byte integer") );
+	case SG_DATATYPE_ULong:		return( LNG("unsigned 8 byte integer") );
+	case SG_DATATYPE_Long:		return( LNG("signed 8 byte integer") );
+	case SG_DATATYPE_Float:		return( LNG("4 byte floating point number") );
+	case SG_DATATYPE_Double:	return( LNG("8 byte floating point number") );
+	case SG_DATATYPE_String:	return( LNG("string") );
+	case SG_DATATYPE_Date:		return( LNG("date") );
+	case SG_DATATYPE_Color:		return( LNG("color") );
+	}
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_core.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,848 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      api_core.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__api_core_H
+#define HEADER_INCLUDED__SAGA_API__api_core_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _SAGA_MSW
+	#define	_SAGA_DLL_EXPORT		__declspec( dllexport )
+	#define	_SAGA_DLL_IMPORT		__declspec( dllimport )
+#else
+	#define	_SAGA_DLL_EXPORT
+	#define	_SAGA_DLL_IMPORT
+#endif
+
+//---------------------------------------------------------
+#ifdef _SAGA_API_EXPORTS
+	#define	SAGA_API_DLL_EXPORT		_SAGA_DLL_EXPORT
+#else
+	#define	SAGA_API_DLL_EXPORT		_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef SWIG
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+#endif	// #ifdef SWIG
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// this is defined by configure, but will not be on a normal
+// application build
+//
+#ifndef SIZEOF_LONG
+	#if defined(__alpha) || defined(__sparcv9) || defined(__LP64__) || (defined(__HOS_AIX__) && defined(_LP64))
+		#define SIZEOF_LONG        8
+	#else
+		#define SIZEOF_LONG        4
+	#endif
+#endif
+
+//---------------------------------------------------------
+#ifdef _TYPEDEF_BOOL
+	typedef unsigned int	bool;
+	#define true			((bool)1)
+	#define false			((bool)0)
+#endif	// _TYPEDEF_BOOL
+
+//---------------------------------------------------------
+#ifdef _TYPEDEF_BYTE
+	typedef unsigned char	BYTE;
+#endif	// _TYPEDEF_BYTE
+
+//---------------------------------------------------------
+#ifdef _TYPEDEF_WORD
+	typedef unsigned short	WORD;
+	#if (SIZEOF_LONG == 4)
+		typedef unsigned long	DWORD;
+	#else
+		typedef unsigned int	DWORD;
+	#endif
+#endif	// _TYPEDEF_WORD
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Memory							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SG_GET_LONG(b0, b1, b2, b3)	((long) (((BYTE)(b0) | ((WORD)(b1) << 8)) | (((DWORD)(BYTE)(b2)) << 16) | (((DWORD)(BYTE)(b3)) << 24)))
+
+#define SG_GET_BYTE_0(vLong)		((BYTE) ((vLong)      ))
+#define SG_GET_BYTE_1(vLong)		((BYTE) ((vLong) >>  8))
+#define SG_GET_BYTE_2(vLong)		((BYTE) ((vLong) >> 16))
+#define SG_GET_BYTE_3(vLong)		((BYTE) ((vLong) >> 24))
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT void *			SG_Malloc			(size_t size);
+SAGA_API_DLL_EXPORT void *			SG_Calloc			(size_t num, size_t size);
+SAGA_API_DLL_EXPORT void *			SG_Realloc			(void *memblock, size_t size);
+SAGA_API_DLL_EXPORT void			SG_Free				(void *memblock);
+
+SAGA_API_DLL_EXPORT void			SG_Swap_Bytes		(void *Buffer, int nBytes);
+
+SAGA_API_DLL_EXPORT int				SG_Mem_Get_Int		(const char *Buffer			, bool bSwapBytes);
+SAGA_API_DLL_EXPORT void			SG_Mem_Set_Int		(char *Buffer, int Value	, bool bSwapBytes);
+SAGA_API_DLL_EXPORT double			SG_Mem_Get_Double	(const char *Buffer			, bool bSwapBytes);
+SAGA_API_DLL_EXPORT void			SG_Mem_Set_Double	(char *Buffer, double Value	, bool bSwapBytes);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						String							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _SAGA_UNICODE
+	#define SG_Char				char
+	#define SG_T(s)				s
+	#define SG_PRINTF			printf
+	#define SG_SSCANF			sscanf
+	#define SG_STR_CMP			strcmp
+	#define SG_STR_CPY			strcpy
+	#define SG_STR_LEN			strlen
+	#define SG_STR_TOD			strtod
+	#define SG_STR_SGTOMB(s)	s
+	#define SG_STR_MBTOSG(s)	s
+#else
+	#define SG_Char				wchar_t
+	#define SG_T(s)				L ## s
+	#define SG_PRINTF			SG_Printf
+	#define SG_SSCANF			swscanf
+	#define SG_STR_CMP			wcscmp
+	#define SG_STR_CPY			wcscpy
+	#define SG_STR_LEN			wcslen
+	#define SG_STR_TOD			wcstod
+	#define SG_STR_SGTOMB(s)	CSG_String(s).b_str()
+	#define SG_STR_MBTOSG(s)	CSG_String(s).c_str()
+#endif
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_String
+{
+public:
+	CSG_String(void);
+	CSG_String(const CSG_String &String);
+	CSG_String(const SG_Char *String);
+#ifdef _SAGA_UNICODE
+	CSG_String(const char *String);
+#endif
+	CSG_String(SG_Char Character);
+
+	virtual ~CSG_String(void);
+
+	const SG_Char *					c_str				(void)	const;
+	operator const SG_Char *							(void)	const	{	return( c_str() );	}
+
+#ifndef _SAGA_UNICODE
+	const char *					b_str				(void)			{	return( c_str() );	}
+#else
+	const char *					b_str				(void);
+#endif
+
+	size_t							Length				(void)	const;
+
+	void							Clear				(void);
+	static CSG_String				Format				(const SG_Char *Format, ...);
+	int								Printf				(const SG_Char *Format, ...);
+	int								Scanf				(const SG_Char *Format, ...);
+
+	CSG_String &					Append				(const SG_Char *String);
+	CSG_String &					Append				(SG_Char Character);
+
+	CSG_String &					operator =			(const CSG_String &String);
+	CSG_String &					operator =			(const SG_Char *String);
+	CSG_String &					operator =			(SG_Char Character);
+
+	CSG_String						operator +			(const CSG_String &String)		const;
+	CSG_String						operator +			(const SG_Char *String)			const;
+	CSG_String						operator +			(SG_Char Character)				const;
+
+	void							operator +=			(const CSG_String &String);
+	void							operator +=			(const SG_Char *String);
+	void							operator +=			(SG_Char Character);
+
+	SG_Char &						operator []			(int i);
+
+	int								Cmp					(const SG_Char *String)			const;
+	int								CmpNoCase			(const SG_Char *String)			const;
+
+	CSG_String &					Make_Lower			(void);
+	CSG_String &					Make_Upper			(void);
+
+	size_t							Replace				(const SG_Char *sOld, const SG_Char *sNew, bool replaceAll = true);
+
+	CSG_String &					Remove				(size_t pos);
+	CSG_String &					Remove				(size_t pos, size_t len);
+
+	int								Trim				(bool fromRight = false);
+
+	int								Find				(SG_Char Character, bool fromEnd = false);
+	int								Find				(const SG_Char *String);
+	bool							Contains			(const SG_Char *String);
+
+	CSG_String						AfterFirst			(SG_Char Character)				const;
+	CSG_String						AfterLast			(SG_Char Character)				const;
+	CSG_String						BeforeFirst			(SG_Char Character)				const;
+	CSG_String						BeforeLast			(SG_Char Character)				const;
+
+	CSG_String						Right				(size_t count)					const;
+	CSG_String						Mid					(size_t first, size_t count = 0)const;
+	CSG_String						Left				(size_t count) const;
+
+	int								asInt				(void)							const;
+	bool							asInt				(int &Value)					const;
+	double							asDouble			(void)							const;
+	bool							asDouble			(double &Value)					const;
+
+
+protected:
+
+	class wxString					*m_pString;
+
+#ifdef _SAGA_UNICODE
+	char							*m_bString;
+#endif
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT CSG_String		operator +			(const SG_Char *A, const CSG_String &B);
+SAGA_API_DLL_EXPORT CSG_String		operator +			(SG_Char        A, const CSG_String &B);
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Strings
+{
+public:
+	CSG_Strings(void);
+	CSG_Strings(const CSG_Strings &Strings);
+	CSG_Strings(int nStrings, const SG_Char **Strings);
+
+	virtual ~CSG_Strings(void);
+
+	void							Clear				(void);
+
+	CSG_Strings &					operator  =			(const CSG_Strings &Strings);
+	bool							Assign				(const CSG_Strings &Strings);
+
+	bool							Add					(const CSG_String &String);
+	CSG_Strings &					operator +=			(const CSG_String &String);
+
+	bool							Set_Count			(int nStrings);
+	int								Get_Count			(void)		const	{	return( m_nStrings );	}
+
+	CSG_String &					operator []			(int Index) const	{	return( *m_Strings[Index]   );	}
+	CSG_String &					Get_String			(int Index) const	{	return( *m_Strings[Index]   );	}
+
+
+protected:
+
+	int								m_nStrings;
+
+	CSG_String						**m_Strings;
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT int				SG_Printf						(const SG_Char *Format, ...);
+SAGA_API_DLL_EXPORT int				SG_Sscanf						(const SG_Char *Buffer, const SG_Char *Format, ...);
+
+SAGA_API_DLL_EXPORT CSG_String		SG_Get_CurrentTimeStr			(bool bWithDate = true);
+
+SAGA_API_DLL_EXPORT CSG_String		SG_UTF8_To_String				(const SG_Char *String);
+SAGA_API_DLL_EXPORT CSG_String		SG_String_To_UTF8				(const SG_Char *String);
+
+SAGA_API_DLL_EXPORT double			SG_Degree_To_Double				(const SG_Char *String);
+SAGA_API_DLL_EXPORT CSG_String		SG_Double_To_Degree				(double Value);
+
+SAGA_API_DLL_EXPORT double			SG_Date_To_Double				(const SG_Char *String);
+SAGA_API_DLL_EXPORT CSG_String		SG_Double_To_Date				(double Value);
+
+SAGA_API_DLL_EXPORT int				SG_Get_Significant_Decimals		(double Value, int maxDecimals = 6);
+
+SAGA_API_DLL_EXPORT void			SG_Flip_Decimal_Separators		(CSG_String &String);
+
+SAGA_API_DLL_EXPORT CSG_String		SG_Get_String					(double Value, int Precision = 2, bool bScientific = false);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Data Types						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Data_Type
+{
+	SG_DATATYPE_Bit			= 0,
+	SG_DATATYPE_Byte,
+	SG_DATATYPE_Char,
+	SG_DATATYPE_Word,
+	SG_DATATYPE_Short,
+	SG_DATATYPE_DWord,
+	SG_DATATYPE_Int,
+	SG_DATATYPE_ULong,
+	SG_DATATYPE_Long,
+	SG_DATATYPE_Float,
+	SG_DATATYPE_Double,
+	SG_DATATYPE_String,
+	SG_DATATYPE_Date,
+	SG_DATATYPE_Color,
+	SG_DATATYPE_Undefined
+}
+TSG_Data_Type;
+
+//---------------------------------------------------------
+const SG_Char	gSG_Data_Type_Identifier[][32]	=
+{
+	SG_T("BIT"),
+	SG_T("BYTE_UNSIGNED"),
+	SG_T("BYTE"),
+	SG_T("SHORTINT_UNSIGNED"),
+	SG_T("SHORTINT"),
+	SG_T("INTEGER_UNSIGNED"),
+	SG_T("INTEGER"),
+	SG_T("LONGINT_UNSIGNED"),
+	SG_T("LONGINT"),
+	SG_T("FLOAT"),
+	SG_T("DOUBLE"),
+	SG_T("STRING"),
+	SG_T("DATE"),
+	SG_T("COLOR"),
+	SG_T("UNDEFINED")
+};
+
+//---------------------------------------------------------
+inline size_t	SG_Data_Type_Get_Size	(TSG_Data_Type Type)
+{
+	switch( Type )
+	{
+	default:					return( 0 );
+	case SG_DATATYPE_Bit:		return( 0 );
+	case SG_DATATYPE_Byte:		return( sizeof(unsigned char) );
+	case SG_DATATYPE_Char:		return( sizeof(char) );
+	case SG_DATATYPE_Word:		return( sizeof(unsigned short int) );
+	case SG_DATATYPE_Short:		return( sizeof(short int) );
+	case SG_DATATYPE_DWord:		return( sizeof(unsigned int) );
+	case SG_DATATYPE_Int:		return( sizeof(int) );
+	case SG_DATATYPE_ULong:		return( sizeof(unsigned long) );
+	case SG_DATATYPE_Long:		return( sizeof(long) );
+	case SG_DATATYPE_Float:		return( sizeof(float) );
+	case SG_DATATYPE_Double:	return( sizeof(double) );
+	case SG_DATATYPE_String:	return( 0 );
+	case SG_DATATYPE_Date:		return( 0 );
+	case SG_DATATYPE_Color:		return( sizeof(unsigned int) );
+	}
+}
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT const SG_Char *	SG_Data_Type_Get_Name	(TSG_Data_Type Type);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						File							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _SAGA_UNICODE
+	#define SG_FILE_OPEN		fopen
+	#define SG_FILE_PRINTF		fprintf
+	#define SG_FILE_SCANF		fscanf
+	#define SG_FILE_GETC		fgetc
+#else
+	#ifndef _SAGA_LINUX
+		#define SG_FILE_OPEN	_wfopen
+	#else
+		#define SG_FILE_OPEN	fopen
+	#endif
+	#define SG_FILE_PRINTF		fwprintf
+	#define SG_FILE_SCANF		fwscanf
+	#define SG_FILE_GETC		fgetwc
+#endif
+
+//---------------------------------------------------------
+enum
+{
+	SG_FILE_R,
+	SG_FILE_W,
+	SG_FILE_RW,
+	SG_FILE_WA,
+	SG_FILE_RWA
+};
+
+//---------------------------------------------------------
+enum
+{
+	SG_FILE_START,
+	SG_FILE_CURRENT,
+	SG_FILE_END
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_File
+{
+public:
+
+	CSG_File(void);
+	CSG_File(const CSG_String &File_Name, int Mode = SG_FILE_R, bool bBinary = true);
+
+	virtual ~CSG_File(void);
+
+	bool							Attach				(FILE *Stream);
+	bool							Detach				(void);
+	FILE *							Get_Stream			(void)	const	{	return( m_pStream );	}
+
+	bool							Open				(const CSG_String &FileName, int Mode = SG_FILE_R, bool bBinary = true);
+	bool							Close				(void);
+
+	bool							is_Open				(void)	const	{	return( m_pStream != NULL );	}
+	bool							is_EOF				(void)	const;
+
+	int								Length				(void)	const;
+
+	bool							Seek				(int Offset, int Origin = SG_FILE_START)	const;
+	bool							Seek_Start			(void)	const;
+	bool							Seek_End			(void)	const;
+
+	int								Tell				(void)	const;
+
+	bool							Flush				(void)	const;
+
+	int								Printf				(const SG_Char *Format, ...);
+	int								Scanf				(const SG_Char *Format, ...)	const;
+
+	size_t							Read				(void       *Buffer, size_t Size, size_t Count = 1)	const;
+	size_t							Write				(void       *Buffer, size_t Size, size_t Count = 1)	const;
+	size_t							Read				(CSG_String &Buffer, size_t Size)	const;
+	size_t							Write				(CSG_String &Buffer)				const;
+
+	bool							Read_Line			(CSG_String &sLine);
+
+	int								Read_Int			(				bool bByteOrderBig);
+	bool							Write_Int			(int    Value,	bool bByteOrderBig);
+	double							Read_Double			(				bool bByteOrderBig);
+	bool							Write_Double		(double Value,	bool bByteOrderBig);
+
+
+protected:
+
+	FILE							*m_pStream;
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT bool			SG_Dir_Exists			(const SG_Char *Directory);
+SAGA_API_DLL_EXPORT bool			SG_Dir_Create			(const SG_Char *Directory);
+SAGA_API_DLL_EXPORT CSG_String		SG_Dir_Get_Current		(void);
+
+SAGA_API_DLL_EXPORT bool			SG_File_Exists			(const SG_Char *FileName);
+SAGA_API_DLL_EXPORT bool			SG_File_Delete			(const SG_Char *FileName);
+SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_TmpName		(const SG_Char *Prefix, const SG_Char *Directory);
+SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Name		(const SG_Char *full_Path, bool bExtension);
+SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Path		(const SG_Char *full_Path);
+SAGA_API_DLL_EXPORT CSG_String		SG_File_Make_Path		(const SG_Char *Directory, const SG_Char *Name, const SG_Char *Extension = NULL);
+SAGA_API_DLL_EXPORT bool			SG_File_Cmp_Extension	(const SG_Char *File_Name, const SG_Char *Extension);
+SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Extension	(const SG_Char *File_Name);
+
+SAGA_API_DLL_EXPORT bool			SG_Read_Line			(FILE *Stream, CSG_String &Line);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Colors							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SG_GET_RGB(r, g, b)			((DWORD) (((BYTE)(r) | ((WORD)(g) << 8)) | (((DWORD)(BYTE)(b)) << 16)))
+#define SG_GET_RGBA(r, g, b, a)		((DWORD) (((BYTE)(r) | ((WORD)(g) << 8)) | (((DWORD)(BYTE)(b)) << 16) | (((DWORD)(BYTE)(a)) << 24)))
+
+#define SG_GET_R(rgb)				((BYTE) ((rgb)      ))
+#define SG_GET_G(rgb)				((BYTE) ((rgb) >>  8))
+#define SG_GET_B(rgb)				((BYTE) ((rgb) >> 16))
+#define SG_GET_A(rgb)				((BYTE) ((rgb) >> 24))
+
+//---------------------------------------------------------
+#define SG_COLOR_BLACK				SG_GET_RGB(  0,   0,   0)
+#define SG_COLOR_GREY				SG_GET_RGB(128, 128, 128)
+#define SG_COLOR_GREY_LIGHT			SG_GET_RGB(192, 192, 192)
+#define SG_COLOR_WHITE				SG_GET_RGB(255, 255, 255)
+#define SG_COLOR_RED				SG_GET_RGB(255,   0,   0)
+#define SG_COLOR_RED_DARK			SG_GET_RGB(128,   0,   0)
+#define SG_COLOR_YELLOW				SG_GET_RGB(255, 255,   0)
+#define SG_COLOR_YELLOW_DARK		SG_GET_RGB(128, 128,   0)
+#define SG_COLOR_GREEN				SG_GET_RGB(  0, 255,   0)
+#define SG_COLOR_GREEN_DARK			SG_GET_RGB(  0, 128,   0)
+#define SG_COLOR_GREEN_LIGHT		SG_GET_RGB(  0, 255,   0)
+#define SG_COLOR_BLUE				SG_GET_RGB(  0,   0, 255)
+#define SG_COLOR_BLUE_DARK			SG_GET_RGB(  0,   0, 128)
+#define SG_COLOR_BLUE_LIGHT			SG_GET_RGB(  0, 255, 255)
+#define SG_COLOR_BLUE_GREEN			SG_GET_RGB(  0, 128, 128)
+#define SG_COLOR_PURPLE				SG_GET_RGB(128,   0, 128)
+#define SG_COLOR_PINK				SG_GET_RGB(255,   0, 255)
+#define SG_COLOR_NONE				-1
+#define SG_COLOR_RANDOM				-2
+
+//---------------------------------------------------------
+enum ESG_Colors
+{
+	SG_COLORS_DEFAULT			= 0,
+	SG_COLORS_DEFAULT_BRIGHT,
+	SG_COLORS_BLACK_WHITE,
+	SG_COLORS_BLACK_RED,
+	SG_COLORS_BLACK_GREEN,
+	SG_COLORS_BLACK_BLUE,
+	SG_COLORS_WHITE_RED,
+	SG_COLORS_WHITE_GREEN,
+	SG_COLORS_WHITE_BLUE,
+	SG_COLORS_YELLOW_RED,
+	SG_COLORS_YELLOW_GREEN,
+	SG_COLORS_YELLOW_BLUE,
+	SG_COLORS_RED_GREEN,
+	SG_COLORS_RED_BLUE,
+	SG_COLORS_GREEN_BLUE,
+	SG_COLORS_RED_GREY_BLUE,
+	SG_COLORS_RED_GREY_GREEN,
+	SG_COLORS_GREEN_GREY_BLUE,
+	SG_COLORS_RED_GREEN_BLUE,
+	SG_COLORS_RED_BLUE_GREEN,
+	SG_COLORS_GREEN_RED_BLUE,
+	SG_COLORS_RAINBOW,
+	SG_COLORS_NEON,
+	SG_COLORS_COUNT
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Colors
+{
+public:
+	CSG_Colors(void);
+	CSG_Colors(const CSG_Colors &Colors);
+	CSG_Colors(int nColors, int Palette = SG_COLORS_DEFAULT, bool bRevert = false);
+	virtual ~CSG_Colors(void);
+
+	void							Destroy				(void);
+
+	bool							Set_Count			(int nColors);
+	int								Get_Count			(void) const		{	return( m_nColors );	}
+
+	CSG_Colors &					operator  =			(const CSG_Colors &Colors);
+	long &							operator []			(int Index)			{	return( m_Colors[Index] );	}
+
+	bool							Set_Color			(int Index, long Color);
+	bool							Set_Color			(int Index, int Red, int Green, int Blue);
+	bool							Set_Red				(int Index, int Value);
+	bool							Set_Green			(int Index, int Value);
+	bool							Set_Blue			(int Index, int Value);
+	bool							Set_Brightness		(int Index, int Value);
+
+	long							Get_Color			(int Index) const	{	return( Index >= 0 && Index < m_nColors ? m_Colors[Index] : 0 );	}
+	long							Get_Red				(int Index) const	{	return( SG_GET_R(Get_Color(Index)) );	}
+	long							Get_Green			(int Index) const	{	return( SG_GET_G(Get_Color(Index)) );	}
+	long							Get_Blue			(int Index) const	{	return( SG_GET_B(Get_Color(Index)) );	}
+	long							Get_Brightness		(int Index) const	{	return( (Get_Red(Index) + Get_Green(Index) + Get_Blue(Index)) / 3 );	}
+
+	bool							Set_Default			(int nColors = 100);
+	bool							Set_Palette			(int Index, bool bRevert = false, int nColors = 100);
+	bool							Set_Ramp			(long Color_A, long Color_B);
+	bool							Set_Ramp			(long Color_A, long Color_B, int iColor_A, int iColor_B);
+	bool							Set_Ramp_Brighness	(int Brightness_A, int Brightness_B);
+	bool							Set_Ramp_Brighness	(int Brightness_A, int Brightness_B, int iColor_A, int iColor_B);
+
+	bool							Random				(void);
+	bool							Invert				(void);
+	bool							Revert				(void);
+
+	bool							Assign				(const CSG_Colors &Colors);
+	bool							Assign				(CSG_Colors *pSource);
+
+	bool							Load				(const CSG_String &File_Name);
+	bool							Save				(const CSG_String &File_Name, bool bBinary);
+
+	bool							Serialize			(CSG_File &Stream, bool bSave, bool bBinary);
+
+
+private:
+
+	int								m_nColors;
+
+	long							*m_Colors;
+
+
+	void							_Set_Brightness		(double &a, double &b, double &c, int Pass = 0);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Translator						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Translator
+{
+public:
+	CSG_Translator(void);
+	CSG_Translator(const CSG_String &File_Name, bool bSetExtension = true);
+
+	virtual ~CSG_Translator(void);
+
+	bool							Create					(const CSG_String &File_Name, bool bSetExtension = true);
+	void							Destroy					(void);
+
+	int								Get_Count				(void)	{	return( m_nTranslations );	}
+
+	const SG_Char *					Get_Text				(int Index);
+	const SG_Char *					Get_Translation			(int Index);
+
+	const SG_Char *					Get_Translation			(const SG_Char *Text);
+
+
+private:
+
+	class CSG_Translation
+	{
+	public:
+		CSG_Translation(const SG_Char *Text, const SG_Char *Translation)
+		{
+			m_Text					= Text;
+			m_Translation			= Translation;
+		}
+
+		CSG_String					m_Text, m_Translation;
+	};
+
+
+private:
+
+	int								m_nTranslations;
+
+	CSG_Translation					**m_Translations;
+
+
+	int								_Get_Index				(const SG_Char *Text);
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT CSG_Translator &	SG_Get_Translator	(void);
+
+SAGA_API_DLL_EXPORT const SG_Char *		SG_Translate		(const SG_Char *Text);
+
+#ifndef _SAGA_UNICODE
+	#define LNG(s)	SG_Translate(s)
+#else
+	#define LNG(s)	SG_Translate(SG_T(s))
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						UI Callback						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_UI_MSG_STYLE
+{
+	SG_UI_MSG_STYLE_NORMAL	= 0,
+	SG_UI_MSG_STYLE_BOLD,
+	SG_UI_MSG_STYLE_ITALIC,
+	SG_UI_MSG_STYLE_SUCCESS,
+	SG_UI_MSG_STYLE_FAILURE,
+	SG_UI_MSG_STYLE_BIG,
+	SG_UI_MSG_STYLE_SMALL,
+	SG_UI_MSG_STYLE_01,
+	SG_UI_MSG_STYLE_02,
+	SG_UI_MSG_STYLE_03
+}
+TSG_UI_MSG_STYLE;
+
+//---------------------------------------------------------
+typedef enum ESG_UI_DataObject_Update
+{
+	SG_UI_DATAOBJECT_UPDATE_ONLY	= 0,
+	SG_UI_DATAOBJECT_SHOW,
+	SG_UI_DATAOBJECT_SHOW_NEW_MAP,
+	SG_UI_DATAOBJECT_SHOW_LAST_MAP
+}
+TSG_UI_DataObject_Update;
+
+//---------------------------------------------------------
+typedef enum ESG_UI_Callback_ID
+{
+	CALLBACK_PROCESS_GET_OKAY,
+	CALLBACK_PROCESS_SET_OKAY,
+	CALLBACK_PROCESS_SET_PROGRESS,
+	CALLBACK_PROCESS_SET_READY,
+	CALLBACK_PROCESS_SET_TEXT,
+
+	CALLBACK_DLG_MESSAGE,
+	CALLBACK_DLG_CONTINUE,
+	CALLBACK_DLG_ERROR,
+
+	CALLBACK_DLG_PARAMETERS,
+
+	CALLBACK_MESSAGE_ADD,
+	CALLBACK_MESSAGE_ADD_ERROR,
+	CALLBACK_MESSAGE_ADD_EXECUTION,
+
+	CALLBACK_DATAOBJECT_FIND_BY_FILE,
+	CALLBACK_DATAOBJECT_CHECK,
+	CALLBACK_DATAOBJECT_ADD,
+	CALLBACK_DATAOBJECT_UPDATE,
+	CALLBACK_DATAOBJECT_SHOW,
+	CALLBACK_DATAOBJECT_ASIMAGE,
+
+	CALLBACK_DATAOBJECT_COLORS_GET,
+	CALLBACK_DATAOBJECT_COLORS_SET,
+	CALLBACK_DATAOBJECT_PARAMS_GET,
+	CALLBACK_DATAOBJECT_PARAMS_SET,
+
+	CALLBACK_DATAOBJECT_GET_ALL,
+
+	CALLBACK_GUI_GET_WINDOW
+}
+TSG_UI_Callback_ID;
+
+//---------------------------------------------------------
+typedef int (* TSG_PFNC_UI_Callback) (TSG_UI_Callback_ID ID, long pParam_1, long pParam_2);
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT bool					SG_Set_UI_Callback			(TSG_PFNC_UI_Callback Function);
+SAGA_API_DLL_EXPORT TSG_PFNC_UI_Callback	SG_Get_UI_Callback			(void);
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT int						SG_UI_Progress_Lock			(bool bOn);
+SAGA_API_DLL_EXPORT bool					SG_UI_Process_Get_Okay		(bool bBlink = false);
+SAGA_API_DLL_EXPORT bool					SG_UI_Process_Set_Okay		(bool bOkay = true);
+SAGA_API_DLL_EXPORT bool					SG_UI_Process_Set_Progress	(double Position, double Range);
+SAGA_API_DLL_EXPORT bool					SG_UI_Process_Set_Ready		(void);
+SAGA_API_DLL_EXPORT void					SG_UI_Process_Set_Text		(const SG_Char *Text);
+
+SAGA_API_DLL_EXPORT void					SG_UI_Dlg_Message			(const SG_Char *Message, const SG_Char *Caption);
+SAGA_API_DLL_EXPORT bool					SG_UI_Dlg_Continue			(const SG_Char *Message, const SG_Char *Caption);
+SAGA_API_DLL_EXPORT int						SG_UI_Dlg_Error				(const SG_Char *Message, const SG_Char *Caption);
+SAGA_API_DLL_EXPORT bool					SG_UI_Dlg_Parameters		(class CSG_Parameters *pParameters, const SG_Char *Caption);
+
+SAGA_API_DLL_EXPORT int						SG_UI_Msg_Lock				(bool bOn);
+SAGA_API_DLL_EXPORT void					SG_UI_Msg_Add				(const SG_Char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
+SAGA_API_DLL_EXPORT void					SG_UI_Msg_Add_Error			(const SG_Char *Message);
+SAGA_API_DLL_EXPORT void					SG_UI_Msg_Add_Execution		(const SG_Char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
+
+SAGA_API_DLL_EXPORT class CSG_Data_Object *	SG_UI_DataObject_Find		(const SG_Char *File_Name          , int Object_Type);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Check		(class CSG_Data_Object *pDataObject, int Object_Type);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Add		(class CSG_Data_Object *pDataObject, int Show);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Update		(class CSG_Data_Object *pDataObject, int Show, class CSG_Parameters *pParameters);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Show		(class CSG_Data_Object *pDataObject, int Show);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_asImage	(class CSG_Data_Object *pDataObject, class CSG_Grid *pGrid);
+
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Colors_Get	(class CSG_Data_Object *pDataObject, class CSG_Colors *pColors);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Colors_Set	(class CSG_Data_Object *pDataObject, class CSG_Colors *pColors);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Params_Get	(class CSG_Data_Object *pDataObject, class CSG_Parameters *pParameters);
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Params_Set	(class CSG_Data_Object *pDataObject, class CSG_Parameters *pParameters);
+
+SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Get_All	(class CSG_Parameters *pParameters);
+
+SAGA_API_DLL_EXPORT void *					SG_UI_Get_Window_Main		(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__api_core_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_file.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_file.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_file.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,504 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    api_file.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/utils.h>
+#include <wx/filename.h>
+
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_File::CSG_File(void)
+{
+	m_pStream	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_File::CSG_File(const CSG_String &FileName, int Mode, bool bBinary)
+{
+	m_pStream	= NULL;
+
+	Open(FileName, Mode, bBinary);
+}
+
+//---------------------------------------------------------
+CSG_File::~CSG_File(void)
+{
+	Close();
+}
+
+//---------------------------------------------------------
+bool CSG_File::Attach(FILE *Stream)
+{
+	Close();
+
+	m_pStream	= Stream;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Detach(void)
+{
+	m_pStream	= NULL;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Open(const CSG_String &File_Name, int Mode, bool bBinary)
+{
+	Close();
+
+	const SG_Char *sMode;
+
+	switch( Mode )
+	{
+	case SG_FILE_R:		sMode	= bBinary ? SG_T("rb" ) : SG_T("r" );	break;
+	case SG_FILE_W:		sMode	= bBinary ? SG_T("wb" ) : SG_T("w" );	break;
+	case SG_FILE_RW:	sMode	= bBinary ? SG_T("wb+") : SG_T("w+");	break;
+	case SG_FILE_WA:	sMode	= bBinary ? SG_T("ab" ) : SG_T("a" );	break;
+	case SG_FILE_RWA:	sMode	= bBinary ? SG_T("rb+") : SG_T("r+");	break;
+	}
+
+#if defined(_SAGA_LINUX) && defined(_SAGA_UNICODE)
+	return( File_Name.Length() > 0 && (m_pStream = SG_FILE_OPEN( SG_STR_SGTOMB( File_Name ), SG_STR_SGTOMB( sMode ) )) != NULL );
+#else
+	return( File_Name.Length() > 0 && (m_pStream = SG_FILE_OPEN(File_Name, sMode)) != NULL );
+#endif
+}
+
+//---------------------------------------------------------
+bool CSG_File::Close(void)
+{
+	if( m_pStream )
+	{
+		fclose(m_pStream);
+
+		m_pStream	= NULL;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+int CSG_File::Length(void)	const
+{
+	if( m_pStream )
+	{
+		long	pos, len;
+
+		pos	= ftell(m_pStream);
+		fseek(m_pStream, 0, SEEK_END);
+		len	= ftell(m_pStream);
+		fseek(m_pStream, pos, SEEK_SET);
+
+		return( len );
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+bool CSG_File::is_EOF(void)	const
+{
+	return( m_pStream == NULL || feof(m_pStream) != 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Seek(int Offset, int Origin) const
+{
+	switch( Origin )
+	{
+	default:
+	case SG_FILE_START:		Origin	= SEEK_SET;	break;
+	case SG_FILE_CURRENT:	Origin	= SEEK_CUR;	break;
+	case SG_FILE_END:		Origin	= SEEK_END;	break;
+	}
+
+	return( m_pStream ? !fseek(m_pStream, Offset, Origin) : false );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Seek_Start(void) const
+{
+	return( m_pStream && fseek(m_pStream, 0, SEEK_SET) == 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Seek_End(void) const
+{
+	return( m_pStream && fseek(m_pStream, 0, SEEK_END) == 0 );
+}
+
+//---------------------------------------------------------
+int CSG_File::Tell(void) const
+{
+	return( m_pStream ? ftell(m_pStream) : -1 );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Flush(void) const
+{
+	return( m_pStream ? !fflush(m_pStream) : false );
+}
+
+//---------------------------------------------------------
+int CSG_File::Printf(const SG_Char *Format, ...)
+{
+	int		result	= 0;
+
+	if( m_pStream )
+	{
+		va_list	argptr;
+
+		va_start(argptr, Format);
+
+		result	= wxVfprintf(m_pStream, Format, argptr);
+
+		va_end(argptr);
+	}
+
+	return( result );
+}
+
+//---------------------------------------------------------
+int CSG_File::Scanf(const SG_Char *Format, ...) const
+{
+	int		result	= 0;
+
+	if( m_pStream )
+	{
+		va_list argptr;
+
+		va_start(argptr, Format);
+
+		result	= 0;	// wxVfscanf(m_pStream, Format, argptr);
+
+		va_end(argptr);
+	}
+
+	return( result );
+}
+
+//---------------------------------------------------------
+size_t CSG_File::Read(void *Buffer, size_t Size, size_t Count) const
+{
+	return( m_pStream ? fread(Buffer, Size, Count, m_pStream) : 0 );
+}
+
+size_t CSG_File::Read(CSG_String &Buffer, size_t Size) const
+{
+	if( m_pStream )
+	{
+		char	*b	= (char *)SG_Calloc(Size + 1, sizeof(char));
+		int		i	= fread(b, sizeof(char), Size, m_pStream);
+		Buffer		= b;
+		SG_Free(b);
+
+		return( i );
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+size_t CSG_File::Write(void *Buffer, size_t Size, size_t Count) const
+{
+	return( m_pStream && Size > 0 && Count > 0 ? fwrite(Buffer, Size, Count, m_pStream) : 0 );
+}
+
+size_t CSG_File::Write(CSG_String &Buffer) const
+{
+	return( Write((void *)Buffer.b_str(), sizeof(char), strlen(Buffer.b_str())) );
+}
+
+//---------------------------------------------------------
+bool CSG_File::Read_Line(CSG_String &sLine)
+{
+	char	c;
+
+	if( m_pStream && !feof(m_pStream) )
+	{
+		sLine.Clear();
+
+		while( !feof(m_pStream) && (c = fgetc(m_pStream)) != 0x0A && c != 0x0D && c != EOF )
+		{
+			sLine.Append(SG_STR_MBTOSG(c));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+int CSG_File::Read_Int(bool bByteOrderBig)
+{
+	int		Value	= 0;
+
+	if( Read(&Value, sizeof(Value)) == sizeof(Value) )
+	{
+		if( bByteOrderBig )
+		{
+			SG_Swap_Bytes(&Value, sizeof(Value));
+		}
+	}
+
+	return( Value );
+}
+
+bool CSG_File::Write_Int(int Value, bool bByteOrderBig)
+{
+	if( bByteOrderBig )
+	{
+		SG_Swap_Bytes(&Value, sizeof(Value));
+	}
+
+	return( Write(&Value, sizeof(Value)) == sizeof(Value) );
+}
+
+//---------------------------------------------------------
+double CSG_File::Read_Double(bool bByteOrderBig)
+{
+	double	Value	= 0;
+
+	if( Read(&Value, sizeof(Value)) == sizeof(Value) )
+	{
+		if( bByteOrderBig )
+		{
+			SG_Swap_Bytes(&Value, sizeof(Value));
+		}
+	}
+
+	return( Value );
+}
+
+bool CSG_File::Write_Double(double Value, bool bByteOrderBig)
+{
+	if( bByteOrderBig )
+	{
+		SG_Swap_Bytes(&Value, sizeof(Value));
+	}
+
+	return( Write(&Value, sizeof(Value)) == sizeof(Value) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool			SG_Dir_Exists(const SG_Char *Directory)
+{
+	return( Directory && *Directory && wxFileName::DirExists(Directory) );
+}
+
+//---------------------------------------------------------
+bool			SG_Dir_Create(const SG_Char *Directory)
+{
+	if( SG_Dir_Exists(Directory) )
+	{
+		return( true );
+	}
+
+	return( wxFileName::Mkdir(Directory) );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_Dir_Get_Current(void)
+{
+	return( wxGetCwd().c_str() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool			SG_File_Exists(const SG_Char *FileName)
+{
+	return( FileName && *FileName && wxFileExists(FileName) );
+}
+
+//---------------------------------------------------------
+bool			SG_File_Delete(const SG_Char *FileName)
+{
+	return( FileName && *FileName && wxRemoveFile(FileName) );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_File_Get_TmpName(const SG_Char *Prefix, const SG_Char *Directory)
+{
+	if( !SG_Dir_Exists(Directory) )
+	{
+		return( wxFileName::CreateTempFileName(Prefix).c_str() );
+	}
+
+	return( wxFileName::CreateTempFileName(SG_File_Make_Path(Directory, Prefix).c_str()).c_str() );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_File_Get_Name(const SG_Char *full_Path, bool bExtension)
+{
+	wxFileName	fn(full_Path);
+	CSG_String	s;
+
+	s.Printf(bExtension ? fn.GetFullName().c_str() : fn.GetName().c_str());
+
+	return( s );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_File_Get_Path(const SG_Char *full_Path)
+{
+	wxFileName	fn(full_Path);
+
+	return( fn.GetPath(wxPATH_GET_VOLUME|wxPATH_GET_SEPARATOR).c_str() );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_File_Make_Path(const SG_Char *Directory, const SG_Char *Name, const SG_Char *Extension)
+{
+	wxFileName	fn;
+
+	fn.AssignDir(SG_Dir_Exists(Directory) ? Directory : SG_File_Get_Path(Name).c_str());
+
+	if( Extension && *Extension )
+	{
+		fn.SetName		(SG_File_Get_Name(Name, false).c_str());
+		fn.SetExt		(Extension);
+	}
+	else
+	{
+		fn.SetFullName	(SG_File_Get_Name(Name,  true).c_str());
+	}
+
+	return( fn.GetFullPath().c_str() );
+}
+
+//---------------------------------------------------------
+bool			SG_File_Cmp_Extension(const SG_Char *File_Name, const SG_Char *Extension)
+{
+	wxFileName	fn(File_Name);
+
+	return( fn.GetExt().CmpNoCase(Extension) == 0 );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_File_Get_Extension(const SG_Char *File_Name)
+{
+	wxFileName	fn(File_Name);
+
+	return( fn.GetExt().c_str() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool			SG_Read_Line(FILE *Stream, CSG_String &Line)
+{
+	char	c;
+
+	if( Stream && !feof(Stream) )
+	{
+		Line.Clear();
+
+		while( !feof(Stream) && (c = fgetc(Stream)) != 0x0A && c != 0x0D )
+		{
+			Line.Append(c);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_memory.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_memory.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_memory.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,241 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    api_memory.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "malloc.h"
+
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+#ifndef _WINDOWS_
+
+//---------------------------------------------------------
+void *		SG_Malloc(size_t size)
+{
+	return( malloc(size) );
+}
+
+//---------------------------------------------------------
+void *		SG_Calloc(size_t num, size_t size)
+{
+	return( calloc(num, size) );
+}
+
+//---------------------------------------------------------
+void *		SG_Realloc(void *memblock, size_t new_size)
+{
+	return( realloc(memblock, new_size) );
+}
+
+//---------------------------------------------------------
+void		SG_Free(void *memblock)
+{
+	if( memblock )
+	{
+		free(memblock);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// Due to a bad 'feature' in the realloc routine of MS's
+// MSVCRT (C-Runtime-Library), we recommend to use our own
+// memory allocation routines...
+
+#else	// ifndef _WINDOWS_
+
+void *		SG_Malloc(size_t size)
+{
+	return( HeapAlloc(GetProcessHeap(), 0, size) );
+}
+
+void *		SG_Calloc(size_t num, size_t size)
+{
+	return( HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num * size) );
+}
+
+void *		SG_Realloc(void *memblock, size_t new_size)
+{
+	if( new_size > 0 )
+	{
+		if( memblock )
+		{
+			return( HeapReAlloc(GetProcessHeap(), 0, memblock, new_size) );
+		}
+		else
+		{
+			return( HeapAlloc(GetProcessHeap(), 0, new_size) );
+		}
+	}
+	else
+	{
+		SG_Free(memblock);
+
+		return( NULL );
+	}
+}
+
+void		SG_Free(void *memblock)
+{
+	if( memblock )
+	{
+		HeapFree(GetProcessHeap(), 0, memblock);
+	}
+}
+
+#endif	// ifndef _WINDOWS_
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void			SG_Swap_Bytes(void *Buffer, int nBytes)
+{
+	char	Byte, *pA, *pB;
+
+	pA	= (char *)Buffer;
+	pB	= pA + nBytes - 1;
+
+	while( pA < pB )
+	{
+		Byte	= *pA;
+		*(pA++)	= *pB;
+		*(pB--)	= Byte;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int				SG_Mem_Get_Int(const char *Buffer, bool bSwapBytes)
+{
+	int		Value	= *(int *)Buffer;
+
+	if( bSwapBytes )
+	{
+		SG_Swap_Bytes(&Value, sizeof(Value));
+	}
+
+	return( Value );
+}
+
+void			SG_Mem_Set_Int(char *Buffer, int Value, bool bSwapBytes)
+{
+	if( bSwapBytes )
+	{
+		SG_Swap_Bytes(&Value, sizeof(Value));
+	}
+
+	*((int *)Buffer)	= Value;
+}
+
+//---------------------------------------------------------
+double			SG_Mem_Get_Double(const char *Buffer, bool bSwapBytes)
+{
+	double	Value	= *(double *)Buffer;
+
+	if( bSwapBytes )
+	{
+		SG_Swap_Bytes(&Value, sizeof(Value));
+	}
+
+	return( Value );
+}
+
+void			SG_Mem_Set_Double(char *Buffer, double Value, bool bSwapBytes)
+{
+	if( bSwapBytes )
+	{
+		SG_Swap_Bytes(&Value, sizeof(Value));
+	}
+
+	*(double *)Buffer	= Value;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_string.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_string.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_string.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,946 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    api_string.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <math.h>
+
+#include <wx/string.h>
+#include <wx/datetime.h>
+
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define WXCONV			wxConvUTF8
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String::CSG_String(void)
+{
+	m_pString	= new wxString;
+#ifdef _SAGA_UNICODE
+	m_bString	= NULL;
+#endif
+}
+
+CSG_String::CSG_String(const CSG_String &String)
+{
+	m_pString	= new wxString(*String.m_pString);
+#ifdef _SAGA_UNICODE
+	m_bString	= NULL;
+#endif
+}
+
+CSG_String::CSG_String(const SG_Char *String)
+{
+	m_pString	= new wxString(String);
+#ifdef _SAGA_UNICODE
+	m_bString	= NULL;
+#endif
+}
+
+#ifdef _SAGA_UNICODE
+CSG_String::CSG_String(const char *String)
+{
+	m_pString	= new wxString(WXCONV.cMB2WC(String));
+	m_bString	= NULL;
+}
+#endif
+
+CSG_String::CSG_String(SG_Char Character)
+{
+	m_pString	= new wxString(Character);
+#ifdef _SAGA_UNICODE
+	m_bString	= NULL;
+#endif
+}
+
+//---------------------------------------------------------
+CSG_String::~CSG_String(void)
+{
+	delete(m_pString);
+
+#ifdef _SAGA_UNICODE
+	if( m_bString )
+	{
+		SG_Free(m_bString);
+	}
+#endif
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_String::c_str(void) const
+{
+	return( m_pString->c_str() );
+}
+
+//---------------------------------------------------------
+#ifdef _SAGA_UNICODE
+const char * CSG_String::b_str(void)
+{
+	m_bString	= (char *)SG_Realloc(m_bString, (1 + strlen(m_pString->mb_str(WXCONV))) * sizeof(char));
+
+	strcpy(m_bString, m_pString->mb_str(WXCONV));
+
+	return( m_bString );
+}
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+size_t CSG_String::Length(void)	const
+{
+	return( m_pString->Length() );
+}
+
+//---------------------------------------------------------
+void CSG_String::Clear(void)
+{
+	m_pString->Clear();
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::Format(const SG_Char *Format, ...)
+{
+	va_list		argptr;
+	CSG_String	s;
+
+	va_start(argptr, Format);
+
+	s.m_pString->PrintfV(Format, argptr);
+
+	va_end(argptr);
+
+	return( s );
+}
+
+//---------------------------------------------------------
+int CSG_String::Printf(const SG_Char *Format, ...)
+{
+	va_list	argptr;
+
+	va_start(argptr, Format);
+
+	m_pString->PrintfV(Format, argptr);
+
+	va_end(argptr);
+
+	return( Length() );
+}
+
+//---------------------------------------------------------
+int CSG_String::Scanf(const SG_Char *Format, ...)
+{
+	va_list	argptr;
+
+	va_start(argptr, Format);
+
+	int	ret	= SG_Sscanf(m_pString->c_str(), Format, argptr);
+
+	va_end(argptr);
+
+	return( ret );
+}
+
+//---------------------------------------------------------
+CSG_String & CSG_String::Append(const SG_Char *String)
+{
+	m_pString->Append(String);
+
+	return( *this );
+}
+
+CSG_String & CSG_String::Append(SG_Char Character)
+{
+	m_pString->Append(Character);
+
+	return( *this );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String & CSG_String::operator = (const CSG_String &String)
+{
+	*m_pString	= *String.m_pString;
+
+	return( *this );
+}
+
+CSG_String & CSG_String::operator = (const SG_Char *String)
+{
+	*m_pString	= String;
+
+	return( *this );
+}
+
+CSG_String & CSG_String::operator = (SG_Char Character)
+{
+	*m_pString	= Character;
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::operator + (const CSG_String &String) const
+{
+	CSG_String	s(*this);
+
+	s	+= String;
+
+	return( s );
+}
+
+CSG_String CSG_String::operator + (const SG_Char *String) const
+{
+	CSG_String	s(*this);
+
+	s	+= String;
+
+	return( s );
+}
+
+CSG_String CSG_String::operator + (SG_Char Character) const
+{
+	CSG_String	s(*this);
+
+	s	+= Character;
+
+	return( s );
+}
+
+CSG_String		operator + (const SG_Char *A, const CSG_String &B)
+{
+	CSG_String	s(A);
+
+	s	+= B;
+
+	return( s );
+}
+
+CSG_String		operator + (SG_Char A, const CSG_String &B)
+{
+	CSG_String	s(A);
+
+	s	+= B;
+
+	return( s );
+}
+
+//---------------------------------------------------------
+void CSG_String::operator += (const CSG_String &String)
+{
+	*m_pString	+= *String.m_pString;
+}
+
+void CSG_String::operator += (const SG_Char *String)
+{
+	*m_pString	+= String;
+}
+
+void CSG_String::operator += (SG_Char Character)
+{
+	*m_pString	+= Character;
+}
+
+//---------------------------------------------------------
+SG_Char & CSG_String::operator [] (int i)
+{
+	return( m_pString->GetWritableChar(i) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_String::Cmp(const SG_Char *String)	const
+{
+	return( m_pString->Cmp(String) );
+}
+
+//---------------------------------------------------------
+int CSG_String::CmpNoCase(const SG_Char *String) const
+{
+	return( m_pString->CmpNoCase(String) );
+}
+
+//---------------------------------------------------------
+CSG_String & CSG_String::Make_Lower(void)
+{
+	m_pString->MakeLower();
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_String & CSG_String::Make_Upper(void)
+{
+	m_pString->MakeUpper();
+
+	return( *this );
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+size_t CSG_String::Replace(const SG_Char *sOld, const SG_Char *sNew, bool replaceAll)
+{
+	return( m_pString->Replace(sOld, sNew, replaceAll) );
+}
+
+//---------------------------------------------------------
+CSG_String & CSG_String::Remove(size_t pos)
+{
+	m_pString->Remove(pos);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_String & CSG_String::Remove(size_t pos, size_t len)
+{
+	m_pString->Remove(pos, len);
+
+	return( *this );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_String::Trim(bool fromRight)
+{
+	int		n	= m_pString->Length();
+
+	m_pString->Trim(fromRight);
+
+	return( n - m_pString->Length() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_String::Find(SG_Char Character, bool fromEnd)
+{
+	return( m_pString->Find(Character, fromEnd) );
+}
+
+//---------------------------------------------------------
+int CSG_String::Find(const SG_Char *String)
+{
+	return( m_pString->Find(String) );
+}
+
+//---------------------------------------------------------
+bool CSG_String::Contains(const SG_Char *String)
+{
+	return( m_pString->Contains(String) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_String::AfterFirst(SG_Char Character) const
+{
+	return( CSG_String(m_pString->AfterFirst(Character).c_str()) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::AfterLast(SG_Char Character) const
+{
+	return( CSG_String(m_pString->AfterLast(Character).c_str()) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::BeforeFirst(SG_Char Character) const
+{
+	return( CSG_String(m_pString->BeforeFirst(Character).c_str()) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::BeforeLast(SG_Char Character) const
+{
+	return( CSG_String(m_pString->BeforeLast(Character).c_str()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_String::Right(size_t count) const
+{
+	return( CSG_String(m_pString->Right(count).c_str()) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::Mid(size_t first, size_t count) const
+{
+	return( CSG_String(m_pString->Mid(first, count <= 0 ? wxSTRING_MAXLEN : count).c_str()) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_String::Left(size_t count) const
+{
+	return( CSG_String(m_pString->Left(count).c_str()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_String::asInt(void) const
+{
+	int		Value	= 0;
+
+	asInt(Value);
+
+	return( Value );
+
+//	return( asInt(Value) ? Value : 0 );
+}
+
+bool CSG_String::asInt(int &Value) const
+{
+	long	lValue	= 0;
+
+	if( m_pString->ToLong(&lValue) || lValue != 0 )
+	{
+		Value	= (int)lValue;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CSG_String::asDouble(void) const
+{
+	double	Value	= 0.0;
+
+	asDouble(Value);
+
+	return( Value );
+}
+
+bool CSG_String::asDouble(double &Value) const
+{
+	double	dValue	= 0.0;
+
+	if( m_pString->ToDouble(&dValue) || dValue != 0.0 )
+	{
+		Value	= dValue;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Strings::CSG_Strings(void)
+{
+	m_nStrings	= 0;
+	m_Strings	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Strings::CSG_Strings(const CSG_Strings &Strings)
+{
+	m_nStrings	= 0;
+	m_Strings	= NULL;
+
+	Assign(Strings);
+}
+
+//---------------------------------------------------------
+CSG_Strings::CSG_Strings(int nStrings, const SG_Char **Strings)
+{
+	m_nStrings	= 0;
+	m_Strings	= NULL;
+
+	for(int i=0; i<nStrings; i++)
+	{
+		Add(Strings[i]);
+	}
+}
+
+//---------------------------------------------------------
+CSG_Strings::~CSG_Strings(void)
+{
+	Clear();
+}
+
+//---------------------------------------------------------
+void CSG_Strings::Clear(void)
+{
+	if( m_Strings )
+	{
+		for(int i=0; i<m_nStrings; i++)
+		{
+			delete(m_Strings[i]);
+		}
+
+		SG_Free(m_Strings);
+
+		m_nStrings	= 0;
+		m_Strings	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Strings::Assign(const CSG_Strings &Strings)
+{
+	Clear();
+
+	for(int i=0; i<Strings.m_nStrings; i++)
+	{
+		Add(Strings[i]);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Strings & CSG_Strings::operator  = (const CSG_Strings &Strings)
+{
+	Assign(Strings);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+bool CSG_Strings::Add(const CSG_String &String)
+{
+	m_Strings	= (CSG_String **)SG_Realloc(m_Strings, (m_nStrings + 1) * sizeof(CSG_String *));
+	m_Strings[m_nStrings++]	= new CSG_String(String);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Strings & CSG_Strings::operator  += (const CSG_String &String)
+{
+	Add(String);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+bool CSG_Strings::Set_Count(int nStrings)
+{
+	Clear();
+
+	for(int i=0; i<nStrings; i++)
+	{
+		Add(SG_T(""));
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int				SG_Printf(const SG_Char *Format, ...)
+{
+	va_list	argptr;
+
+	va_start(argptr, Format);
+
+	int		ret	= wxVprintf(Format, argptr);
+
+	va_end(argptr);
+
+	return( ret );
+}
+
+//---------------------------------------------------------
+int				SG_Sscanf(const SG_Char *Buffer, const SG_Char *Format, ...)
+{
+	va_list	argptr;
+
+	va_start(argptr, Format);
+
+	int		ret	= 0;	// wxVsscanf(Buffer, Format, argptr);
+
+	va_end(argptr);
+
+	return( ret );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String		SG_Get_CurrentTimeStr(bool bWithDate)
+{
+	CSG_String	s;
+	wxDateTime	t;
+
+	t.SetToCurrent();
+
+	if( bWithDate )
+	{
+		s.Append(t.FormatISODate());
+		s.Append(SG_T("/"));
+	}
+
+	s.Append(t.FormatISOTime());
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String		SG_UTF8_To_String(const SG_Char *String)
+{
+#ifdef _SAGA_UNICODE
+	return( !String && !String[0] ? SG_T("") : String );
+#else
+	return( !String && !String[0] ? SG_T("") : wxString::FromUTF8(String).c_str() );
+#endif
+}
+
+//---------------------------------------------------------
+CSG_String		SG_String_To_UTF8(const SG_Char *String)
+{
+#ifdef _SAGA_UNICODE
+	return( !String && !String[0] ? SG_T("") : wxString(String, wxConvUTF8).c_str() );
+#else
+	return( !String && !String[0] ? SG_T("") : wxString(wxString(String).ToUTF8()).c_str() );
+#endif
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String		SG_Double_To_Degree(double Value)
+{
+	SG_Char		c;
+	int			d, h;
+	double		s;
+	CSG_String	String;
+
+	if( Value < 0.0 )
+	{
+		Value	= -Value;
+		c		= SG_T('-');
+	}
+	else
+	{
+		c		= SG_T('+');
+	}
+
+	Value	= fmod(Value, 360.0);
+	d		= (int)Value;
+	Value	= 60.0 * (Value - d);
+	h		= (int)Value;
+	Value	= 60.0 * (Value - h);
+	s		= Value;
+
+	String.Printf(SG_T("%c%03d\xb0%02d'%02f''"), c, d, h, s);
+
+	return( String );
+}
+
+//---------------------------------------------------------
+double			SG_Degree_To_Double(const SG_Char *String)
+{
+	double		d, h, s, sig;
+	CSG_String	sVal(String);
+
+	sig	= 1.0;
+	d	= h	= s	= 0.0;
+
+	if( sVal.BeforeFirst('\xb0').asDouble(d) )
+	{
+		if( d < 0.0 )
+		{
+			sig	= -1.0;
+			d	= -d;
+		}
+
+		sVal.AfterFirst('\xb0' ).asDouble(h);
+		sVal.AfterFirst('\'').asDouble(s);
+	}
+	else
+	{
+		sVal.asDouble(d);
+	}
+
+	return( sig * (d + h / 60.0 + s / (60.0 * 60.0)) );
+}
+
+//---------------------------------------------------------
+CSG_String		SG_Double_To_Date(double Value)
+{
+	int		y, m, d;
+
+	y	= (int)(Value / 10000);	Value	-= y * 10000;
+	m	= (int)(Value / 100);	Value	-= m * 100;
+	d	= (int)(Value / 1);
+
+	return( CSG_String::Format(SG_T("%02d.%02d.%04d"), d, m, y) );
+}
+
+//---------------------------------------------------------
+double			SG_Date_To_Double(const SG_Char *String)
+{
+	int			d, m, y;
+
+	if( String )
+	{
+		CSG_String	s(String), sValue;
+
+		sValue	= s.AfterLast	('.');
+		y		= sValue.asInt();
+		sValue	= s.BeforeLast	('.');	s		= sValue;
+
+		sValue	= s.AfterLast	('.');
+		m		= sValue.asInt();
+		sValue	= s.BeforeLast	('.');	s		= sValue;
+		d		= sValue.asInt();
+
+		if( d < 1 )	d	= 1;	else if( d > 31 )	d	= 31;
+		if( m < 1 )	m	= 1;	else if( m > 12 )	m	= 12;
+
+		return( 10000 * y + 100 * m + 1 * d );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int				SG_Get_Significant_Decimals(double Value, int maxDecimals)
+{
+	int		Decimals;
+	double	Reminder;
+
+	Value	= fabs(Value);
+
+	for(Decimals=0; Decimals<maxDecimals; Decimals++)
+	{
+		Reminder	= Value - (int)(Value);
+
+		if( Reminder == 0.0 )
+		{
+			return( Decimals );
+		}
+
+		Value	= 10.0 * Value;
+	}
+
+	return( maxDecimals );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void			SG_Flip_Decimal_Separators(CSG_String &String)
+{
+	for(int i=0; i<(int)String.Length(); i++)
+	{
+		switch( String[i] )
+		{
+		case '.':	String[i]	= ',';	break;
+		case ',':	String[i]	= '.';	break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String		SG_Get_String(double Value, int Precision, bool bScientific)
+{
+	CSG_String	s;
+
+	if( Precision >= 0 )
+	{
+		s.Printf(SG_T("%.*f"), Precision, Value);
+	}
+	else if( Precision == -1 )
+	{
+		s.Printf(SG_T("%f"), Value);
+	}
+	else // if( Precision == -2 )
+	{
+		s.Printf(SG_T("%.*f"), SG_Get_Significant_Decimals(Value, 10), Value);
+	}
+
+	s.Replace(SG_T(","), SG_T("."));
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/api_translator.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/api_translator.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/api_translator.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,308 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  api_translator.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "api_core.h"
+
+#include "table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Translator		gSG_Translator;
+
+//---------------------------------------------------------
+CSG_Translator &	SG_Get_Translator(void)
+{
+	return( gSG_Translator );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char *	SG_Translate(const SG_Char *Text)
+{
+	return( gSG_Translator.Get_Translation(Text) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Translator::CSG_Translator(void)
+{
+	m_nTranslations	= 0;
+	m_Translations	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Translator::CSG_Translator(const CSG_String &File_Name, bool bSetExtension)
+{
+	m_nTranslations	= 0;
+	m_Translations	= NULL;
+
+	Create(File_Name, bSetExtension);
+}
+
+//---------------------------------------------------------
+CSG_Translator::~CSG_Translator(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+void CSG_Translator::Destroy(void)
+{
+	if( m_Translations )
+	{
+		for(int i=0; i<m_nTranslations; i++)
+		{
+			delete(m_Translations[i]);
+		}
+
+		SG_Free(m_Translations);
+
+		m_nTranslations	= 0;
+		m_Translations	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Translator::Create(const CSG_String &File_Name, bool bSetExtension)
+{
+	Destroy();
+
+	CSG_Table	Translations;
+	CSG_String	fName(bSetExtension ? SG_File_Make_Path(NULL, File_Name, SG_T("lng")) : File_Name);
+
+	SG_UI_Msg_Lock(true);
+
+	if( SG_File_Exists(fName) && Translations.Create(fName) && Translations.Get_Field_Count() == 2 && Translations.Get_Record_Count() > 0 )
+	{
+		m_Translations	= (CSG_Translation **)SG_Malloc(Translations.Get_Record_Count() * sizeof(CSG_Translation *));
+
+		Translations.Set_Index(0, TABLE_INDEX_Ascending);
+
+		for(int i=0; i<Translations.Get_Record_Count(); i++)
+		{
+			CSG_Table_Record	*pRecord	= Translations.Get_Record_byIndex(i);
+
+			if( *pRecord->asString(0) && *pRecord->asString(1) )
+			{
+				m_Translations[m_nTranslations++]	= new CSG_Translation(pRecord->asString(0), pRecord->asString(1));
+			}
+		}
+
+		if( m_nTranslations < Translations.Get_Record_Count() )
+		{
+			m_Translations	= (CSG_Translation **)SG_Realloc(m_Translations, m_nTranslations * sizeof(CSG_Translation *));
+		}
+	}
+
+	SG_UI_Msg_Lock(false);
+
+	return( m_nTranslations > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Translator::_Get_Index(const SG_Char *Text)
+{
+	int		a, b, i, c;
+
+	if( m_nTranslations == 1 )
+	{
+		c	= m_Translations[0]->m_Text.Cmp(Text);
+
+		return( c >= 0 ? 0 : 1 );
+	}
+
+	if( m_nTranslations > 1 )
+	{
+		for(a=0, b=m_nTranslations-1; b - a > 1; )
+		{
+			i	= a + (b - a) / 2;
+			c	= m_Translations[i]->m_Text.Cmp(Text);
+
+			if( c > 0 )
+			{
+				b	= i;
+			}
+			else if( c < 0 )
+			{
+				a	= i;
+			}
+			else
+			{
+				return( i );
+			}
+		}
+
+		if( m_Translations[a]->m_Text.Cmp(Text) < 0 )
+		{
+			if( m_Translations[b]->m_Text.Cmp(Text) < 0 )
+			{
+				return( m_nTranslations );
+			}
+
+			return( b );
+		}
+
+		if( m_Translations[b]->m_Text.Cmp(Text) > 0 )
+		{
+			return( a );
+		}
+	}
+
+	return( m_nTranslations );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Translator::Get_Text(int Index)
+{
+	return( Index >= 0 && Index < m_nTranslations ? m_Translations[Index]->m_Text : SG_T("") );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Translator::Get_Translation(int Index)
+{
+	return( Index >= 0 && Index < m_nTranslations ? m_Translations[Index]->m_Translation : SG_T("") );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Translator::Get_Translation(const SG_Char *Text)
+{
+	if( Text )
+	{
+		if( m_nTranslations > 0 )
+		{
+			int			i;
+			CSG_String	s(Text);
+
+			if( *Text == '{' )
+			{
+				s	= s.AfterFirst('{').BeforeFirst('}');
+			}
+
+			if(	(i = _Get_Index(s)) < m_nTranslations && !m_Translations[i]->m_Text.Cmp(s) )
+			{
+				return( m_Translations[i]->m_Translation );
+			}
+		}
+
+		if( *Text == '{' )
+		{
+			do	{	Text++;	}	while( *Text != '}' && *Text != '\0' );
+			do	{	Text++;	}	while( *Text == ' ' && *Text != '\0' );
+		}
+
+		if( *Text == '[' )
+		{
+			do	{	Text++;	}	while( *Text != ']' && *Text != '\0' );
+			do	{	Text++;	}	while( *Text == ' ' && *Text != '\0' );
+		}
+	}
+
+	return( Text );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,298 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    dataobject.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					class CData_Object					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dataobject.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char *	SG_Get_DataObject_Identifier(TSG_Data_Object_Type Type)
+{
+	switch( Type )
+	{
+	default:
+	case DATAOBJECT_TYPE_Undefined:		return( SG_T("UNDEFINED") );
+	case DATAOBJECT_TYPE_Grid:			return( SG_T("GRID") );
+	case DATAOBJECT_TYPE_Table:			return( SG_T("TABLE") );
+	case DATAOBJECT_TYPE_Shapes:		return( SG_T("SHAPES") );
+	case DATAOBJECT_TYPE_TIN:			return( SG_T("TIN") );
+	case DATAOBJECT_TYPE_PointCloud:	return( SG_T("POINTS") );
+	}
+}
+
+//---------------------------------------------------------
+const SG_Char *	SG_Get_DataObject_Name(TSG_Data_Object_Type Type)
+{
+	switch( Type )
+	{
+	default:
+	case DATAOBJECT_TYPE_Undefined:		return( LNG("[DAT] Undefined") );
+	case DATAOBJECT_TYPE_Grid:			return( LNG("[DAT] Grid") );
+	case DATAOBJECT_TYPE_Table:			return( LNG("[DAT] Table") );
+	case DATAOBJECT_TYPE_Shapes:		return( LNG("[DAT] Shapes") );
+	case DATAOBJECT_TYPE_TIN:			return( LNG("[DAT] TIN") );
+	case DATAOBJECT_TYPE_PointCloud:	return( LNG("[DAT] Point Cloud") );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Data_Object::CSG_Data_Object(void)
+{
+	CSG_MetaData	*pSource;
+
+	m_MetaData.Set_Name(SG_T("SAGA_METADATA"));
+
+	m_pHistory		= m_MetaData.	Add_Child(SG_META_HST);
+
+	pSource			= m_MetaData.	Add_Child(SG_META_SRC);
+	m_pFile			= pSource->		Add_Child(SG_META_SRC_FILE);
+	m_pMetaData_DB	= pSource->		Add_Child(SG_META_SRC_DB);
+	m_pProjection	= pSource->		Add_Child(SG_META_SRC_PROJ);
+
+	//-----------------------------------------------------
+	m_File_Type		= 0;
+	m_bModified		= true;
+
+	Set_Name		(NULL);
+	Set_File_Name	(NULL);
+
+	m_bUpdate		= false;
+}
+
+//---------------------------------------------------------
+CSG_Data_Object::~CSG_Data_Object(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool CSG_Data_Object::Destroy(void)
+{
+	m_pHistory		->Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Data_Object::Set_Name(const SG_Char *Name)
+{
+	m_Name.Printf(Name ? CSG_String(Name).c_str() : LNG("[DAT] new") );
+}
+
+const SG_Char * CSG_Data_Object::Get_Name(void) const
+{
+	return( m_Name.c_str() );
+}
+
+//---------------------------------------------------------
+void CSG_Data_Object::Set_File_Name(const SG_Char *File_Name)
+{
+	if( File_Name )
+	{
+		m_File_Name.Printf(File_Name);
+
+		m_Name	= SG_File_Get_Name(File_Name, false);
+
+		m_bModified	= false;
+	}
+	else
+	{
+		m_File_Name.Clear();
+
+		Set_Name(NULL);
+	}
+
+	m_pFile->Set_Content(m_File_Name);
+}
+
+const SG_Char * CSG_Data_Object::Get_File_Name(bool bNullAsString)	const
+{
+	return(	m_File_Name.Length() > 0
+		?	m_File_Name.c_str()
+		:	(bNullAsString ? (SG_Char *)LNG("[DAT] [not set]") : (SG_Char *)NULL)
+	);
+}
+
+//---------------------------------------------------------
+void CSG_Data_Object::Set_File_Type(int File_Type)
+{
+	m_File_Type	= File_Type;
+}
+
+int CSG_Data_Object::Get_File_Type(void) const
+{
+	return( m_File_Type );
+}
+
+//---------------------------------------------------------
+bool CSG_Data_Object::Load_MetaData(const SG_Char *File_Name)
+{
+	CSG_MetaData	m, *p;
+
+	switch( Get_ObjectType() )
+	{
+	default:							return( false );;
+	case DATAOBJECT_TYPE_Grid:			m.Load(File_Name, SG_META_EXT_GRID);		break;
+	case DATAOBJECT_TYPE_Table:			m.Load(File_Name, SG_META_EXT_TABLE);		break;
+	case DATAOBJECT_TYPE_Shapes:		m.Load(File_Name, SG_META_EXT_SHAPES);		break;
+	case DATAOBJECT_TYPE_TIN:			m.Load(File_Name, SG_META_EXT_TIN);			break;
+	case DATAOBJECT_TYPE_PointCloud:	m.Load(File_Name, SG_META_EXT_POINTCLOUD);	break;
+	}
+
+	if( (p = m.Get_Child(SG_META_SRC)) != NULL )
+	{
+		m_pMetaData_DB->Destroy();
+
+		if( p->Get_Child(SG_META_SRC_DB) )
+		{
+			m_pMetaData_DB->Assign(*p->Get_Child(SG_META_SRC_DB));
+		}
+
+		m_pProjection->Destroy();
+
+		if( p->Get_Child(SG_META_SRC_PROJ) )
+		{
+			m_pProjection->Assign(*p->Get_Child(SG_META_SRC_PROJ));
+		}
+	}
+
+	m_pHistory->Destroy();
+
+	if( (p = m.Get_Child(SG_META_HST)) != NULL )
+	{
+		m_pHistory->Assign(*m.Get_Child(SG_META_HST));
+	}
+	else
+	{
+		m_pHistory->Add_Child(SG_META_SRC_FILE, File_Name);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Data_Object::Save_MetaData(const SG_Char *File_Name)
+{
+	switch( Get_ObjectType() )
+	{
+	default:							return( m_MetaData.Save(File_Name) );
+	case DATAOBJECT_TYPE_Grid:			return( m_MetaData.Save(File_Name, SG_META_EXT_GRID) );
+	case DATAOBJECT_TYPE_Table:			return( m_MetaData.Save(File_Name, SG_META_EXT_TABLE) );
+	case DATAOBJECT_TYPE_Shapes:		return( m_MetaData.Save(File_Name, SG_META_EXT_SHAPES) );
+	case DATAOBJECT_TYPE_TIN:			return( m_MetaData.Save(File_Name, SG_META_EXT_TIN) );
+	case DATAOBJECT_TYPE_PointCloud:	return( m_MetaData.Save(File_Name, SG_META_EXT_POINTCLOUD) );
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Data_Object::Update(void)
+{
+	if( m_bUpdate )
+	{
+		m_bUpdate	= false;
+
+		return( On_Update() );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Data_Object::Assign(CSG_Data_Object *pObject)
+{
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/dataobject.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,237 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     dataobject.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__dataobject_H
+#define HEADER_INCLUDED__SAGA_API__dataobject_H
+
+//---------------------------------------------------------
+/** \file dataobject.h
+  * Base class for data objects and related declarations.
+  * @see CSG_Data_Object
+  * @see CSG_History
+*/
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+#include "metadata.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Meta-Data						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SG_META_EXT_GRID		SG_T("mgrd")
+#define SG_META_EXT_TABLE		SG_T("mtab")
+#define SG_META_EXT_SHAPES		SG_T("mshp")
+#define SG_META_EXT_TIN			SG_T("mtin")
+#define SG_META_EXT_POINTCLOUD	SG_T("mpts")
+
+//---------------------------------------------------------
+#define SG_META_SRC				SG_T("SOURCE")
+#define SG_META_SRC_FILE		SG_T("FILE")
+#define SG_META_SRC_DB			SG_T("DATABASE")
+#define SG_META_SRC_PROJ		SG_T("PROJECTION")
+
+#define SG_META_HST				SG_T("HISTORY")
+#define SG_META_HST_FILE		SG_T("FILE")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Data Objects					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * Definition of available data types. This is returned by
+  * the CSG_Data_Object::Get_ObjectType() function to allow
+  * type checking at run time.
+  * @see CSG_Data_Object
+  * @see CSG_Table
+  * @see CSG_PointCloud
+  * @see CSG_Shapes
+  * @see CSG_TIN
+  * @see CSG_Grid
+*/
+//---------------------------------------------------------
+typedef enum ESG_Data_Object_Type
+{
+	DATAOBJECT_TYPE_Grid,
+	DATAOBJECT_TYPE_Table,
+	DATAOBJECT_TYPE_Shapes,
+	DATAOBJECT_TYPE_TIN,
+	DATAOBJECT_TYPE_PointCloud,
+	DATAOBJECT_TYPE_Undefined
+}
+TSG_Data_Object_Type;
+
+//---------------------------------------------------------
+#define DATAOBJECT_NOTSET		((void *)NULL)
+#define DATAOBJECT_CREATE		((void *)1)
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT const SG_Char *	SG_Get_DataObject_Identifier	(TSG_Data_Object_Type Type);
+SAGA_API_DLL_EXPORT const SG_Char *	SG_Get_DataObject_Name			(TSG_Data_Object_Type Type);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Data_Object is the base class for all types of data
+  * sets, which are provided by the SAGA API.
+  * @see CSG_Table
+  * @see CSG_Shapes
+  * @see CSG_TIN
+  * @see CSG_PointCloud
+  * @see CSG_Grid
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Data_Object
+{
+public:
+	CSG_Data_Object(void);
+	virtual ~CSG_Data_Object(void);
+
+	virtual bool					Destroy			(void);
+
+	/// Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking.
+	virtual TSG_Data_Object_Type	Get_ObjectType	(void)	const									= 0;
+
+	virtual bool					is_Valid		(void)	const									= 0;
+
+	virtual bool					Save			(const CSG_String &File_Name, int Format = 0)	= 0;
+
+	const SG_Char *					Get_File_Name	(bool bNullAsString = false)	const;
+	int								Get_File_Type	(void)	const;
+
+	virtual bool					Assign			(CSG_Data_Object *pObject);
+
+	void							Set_Name		(const SG_Char *Name);
+	const SG_Char *					Get_Name		(void)	const;
+
+	virtual void					Set_Modified	(bool bOn = true)	{	m_bModified	= bOn;			}
+	bool							is_Modified		(void)	const		{	return( m_bModified );		}
+	bool							Update			(void);
+
+	CSG_MetaData &					Get_MetaData	(void)	const		{	return( *m_pMetaData );		}
+	CSG_MetaData &					Get_MetaData_DB	(void)				{	return( *m_pMetaData_DB );	}
+	CSG_MetaData &					Get_History		(void)				{	return( *m_pHistory );		}
+
+	CSG_Projection &				Get_Projection	(void)				{	return( m_Projection );		}
+
+	class CSG_Table *				asTable			(void)	{	return( Get_ObjectType() == DATAOBJECT_TYPE_Table      ? (class CSG_Table      *)this : NULL );	}
+	class CSG_Shapes *				asShapes		(void)	{	return( Get_ObjectType() == DATAOBJECT_TYPE_Shapes     ? (class CSG_Shapes     *)this : NULL );	}
+	class CSG_TIN *					asTIN			(void)	{	return( Get_ObjectType() == DATAOBJECT_TYPE_TIN        ? (class CSG_TIN        *)this : NULL );	}
+	class CSG_PointCloud *			asPointCloud	(void)	{	return( Get_ObjectType() == DATAOBJECT_TYPE_PointCloud ? (class CSG_PointCloud *)this : NULL );	}
+	class CSG_Grid *				asGrid			(void)	{	return( Get_ObjectType() == DATAOBJECT_TYPE_Grid       ? (class CSG_Grid       *)this : NULL );	}
+
+
+protected:
+
+	void							Set_File_Name	(const SG_Char *File_Name);
+	void							Set_File_Type	(int File_Type);
+
+	bool							Load_MetaData	(const SG_Char *File_Name);
+	bool							Save_MetaData	(const SG_Char *File_Name);
+
+	void							Set_Update_Flag	(bool bOn = true)	{	m_bUpdate	= bOn;		}
+	bool							Get_Update_Flag	(void)				{	return( m_bUpdate );	}
+	virtual bool					On_Update		(void)				{	return( true );			}
+
+
+private:
+
+	bool							m_bModified, m_bUpdate;
+
+	int								m_File_Type;
+
+	CSG_String						m_File_Name, m_Name;
+
+	CSG_MetaData					m_MetaData, *m_pMetaData, *m_pHistory, *m_pFile, *m_pProjection, *m_pMetaData_DB;
+
+	CSG_Projection					m_Projection;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__dataobject_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,722 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     doc_html.cpp                      //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Victor Olaya                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Victor Olaya                           //
+//                                                       //
+//    e-mail:     volaya at saga-gis.org                    //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "doc_html.h"
+
+//---------------------------------------------------------
+#define GRAPH_WIDTH		700
+#define GRAPH_HEIGHT	350
+#define MAP_WIDTH		700.
+#define MAP_HEIGHT		700.
+#define OFFSET_X		50
+#define OFFSET_Y		50
+
+//---------------------------------------------------------
+#define HTML_CODE_OPENING_1	SG_T("<html>\n<head><title>")
+
+#define HTML_CODE_OPENING_2	SG_T("</title>\n")\
+	SG_T("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n")\
+	SG_T("</head>\n")\
+	SG_T("<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n")
+
+#define HTML_CODE_CLOSING	SG_T("</body>\n</html>")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Doc_HTML::CSG_Doc_HTML(){}
+
+CSG_Doc_HTML::~CSG_Doc_HTML(){}
+
+void CSG_Doc_HTML::Open(const SG_Char *Title)
+{
+
+	m_sHTMLCode.Clear();
+
+	m_sHTMLCode.Append(HTML_CODE_OPENING_1);
+	m_sHTMLCode.Append(Title);
+	m_sHTMLCode.Append(HTML_CODE_OPENING_2);
+
+}
+
+bool CSG_Doc_HTML::Save(const SG_Char *Filename)
+{
+
+	m_sHTMLCode.Append(HTML_CODE_CLOSING);
+
+	CSG_File	Stream(Filename, SG_FILE_W, false);
+
+	if( Stream.is_Open() )
+	{
+		Stream.Printf(SG_T("%s"), m_sHTMLCode.c_str());
+		return true;
+	}
+
+	return false;
+
+}
+
+void CSG_Doc_HTML::AddParagraph(const SG_Char *Text)
+{
+
+	m_sHTMLCode.Append(SG_T("<p align=\"left\">"));
+	m_sHTMLCode.Append(Text);
+	m_sHTMLCode.Append(SG_T("</p>\n"));
+
+}
+
+void CSG_Doc_HTML::AddLineBreak()
+{
+
+	m_sHTMLCode.Append(SG_T("</br>"));	
+
+}
+void CSG_Doc_HTML::AddHeader(const SG_Char *Text,
+							int iOrder)
+{
+
+	m_sHTMLCode.Append(SG_T("<h"));
+	m_sHTMLCode.Append(SG_Get_String(iOrder,0));
+	m_sHTMLCode.Append(SG_T(" align=\"left\">"));
+	m_sHTMLCode.Append(Text);
+	m_sHTMLCode.Append(SG_T("</h"));
+	m_sHTMLCode.Append(SG_Get_String(iOrder,0));
+	m_sHTMLCode.Append(SG_T(">\n"));
+
+}
+
+void CSG_Doc_HTML::AddHyperlink(const SG_Char *Text,
+								const SG_Char *URL)
+{
+
+	m_sHTMLCode.Append(SG_T("<a href=\""));
+	m_sHTMLCode.Append(URL);
+	m_sHTMLCode.Append(SG_T("\">\n"));
+	m_sHTMLCode.Append(Text);
+	m_sHTMLCode.Append(SG_T("\n</a>"));
+
+}
+
+CSG_String CSG_Doc_HTML::GetHyperlinkCode(const SG_Char *Text,
+									const SG_Char *URL)
+{
+	CSG_String s;
+
+	s.Append(SG_T("<a href=\""));
+	s.Append(URL);
+	s.Append(SG_T("\">\n"));
+	s.Append(Text);
+	s.Append(SG_T("\n</a>"));
+
+	return s;
+
+}
+void CSG_Doc_HTML::AddImage(const SG_Char *Filename)
+{
+
+	m_sHTMLCode.Append(SG_T("<img src=\""));
+	m_sHTMLCode.Append(Filename);
+	m_sHTMLCode.Append(SG_T("\">\n"));
+
+}
+
+void CSG_Doc_HTML::AddThumbnail(const SG_Char *Filename,
+								int iWidth,
+								bool bIsPercent)
+{
+
+	m_sHTMLCode.Append(SG_T("<a href=\""));
+	m_sHTMLCode.Append(Filename);
+	m_sHTMLCode.Append(SG_T("\">\n"));
+    m_sHTMLCode.Append(SG_T("<img src=\""));
+    m_sHTMLCode.Append(Filename);
+    m_sHTMLCode.Append(SG_T("\" width="));
+    m_sHTMLCode.Append(SG_Get_String(iWidth,0));
+    if (bIsPercent)
+    {
+		m_sHTMLCode.Append(SG_T("%"));
+	}
+    m_sHTMLCode.Append(SG_T("></a><br><br>\n"));
+
+}
+
+void CSG_Doc_HTML::AddThumbnails(const SG_Char **Filename,
+								int iImages,
+								int iThumbnailsPerRow)
+{
+
+	int i,j;
+	int iImage	= 0;
+	int iRows	= (int)ceil((double)iImages / (double)iThumbnailsPerRow);
+	int iWidth	= (int)(100.0 / (double)iThumbnailsPerRow);
+
+    m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));
+	for (i=0; i<iRows; i++)
+	{
+		m_sHTMLCode.Append(SG_T("<tr>\n"));
+
+		for (j=0; j<iThumbnailsPerRow; j++){
+			m_sHTMLCode.Append(SG_T("<td width=\""));
+			m_sHTMLCode.Append(SG_Get_String(iWidth));
+			m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
+			AddThumbnail(Filename[iImage], 100, true);
+			iImage++;
+			if (iImage >= iImages){
+				break;
+			}
+			m_sHTMLCode.Append(SG_T("</td>"));
+		}
+		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
+	}
+
+	m_sHTMLCode.Append(SG_T("\n</table>\n"));
+
+}
+
+void CSG_Doc_HTML::StartUnorderedList()
+{
+
+	m_sHTMLCode.Append(SG_T("<ul>\n"));
+
+}
+
+void CSG_Doc_HTML::StartOrderedList()
+{
+
+	m_sHTMLCode.Append(SG_T("<ol>\n"));
+
+}
+
+void CSG_Doc_HTML::CloseUnorderedList()
+{
+
+	m_sHTMLCode.Append(SG_T("</ul>\n"));
+
+}
+
+void CSG_Doc_HTML::CloseOrderedList()
+{
+
+	m_sHTMLCode.Append(SG_T("</ol>\n"));
+
+}
+
+void CSG_Doc_HTML::AddListElement(const SG_Char *Text)
+{
+
+	m_sHTMLCode.Append(SG_T("<li>"));
+	m_sHTMLCode.Append(Text);
+	m_sHTMLCode.Append(SG_T("</li>\n"));
+
+}
+
+void CSG_Doc_HTML::AddOrderedList(const SG_Char **Text, int iElements)
+{
+
+	StartOrderedList();
+	for (int i = 0; i < iElements; i++)
+	{
+		AddListElement(Text[i]);
+	}
+	CloseOrderedList();
+
+}
+
+void CSG_Doc_HTML::AddUnorderedList(const SG_Char **Text, int iElements)
+{
+
+	StartUnorderedList();
+	for (int i = 0; i < iElements; i++)
+	{
+		AddListElement(Text[i]);
+	}
+	CloseUnorderedList();
+
+}
+
+void CSG_Doc_HTML::AddCurve(const SG_Char *Filename,
+								CSG_Points &Data,
+								const SG_Char *Description,
+								int iGraphType,
+								bool bIncludeTableData)
+{
+
+	int i;
+    int iMag;
+	int iNumLines;
+    double fMinLine = 0;
+	double fWidth;
+	double fMax, fMin;
+	double fRange, fRangeX;
+	double fStep;
+    double fX, fY, fY2;
+	double fMaxX, fMinX;
+	CSG_String sValue;
+	CSG_String sTableFilename;
+	CSG_Points Points;
+	CSG_Doc_SVG SVG;
+
+	m_sHTMLCode.Append(SG_T("<object type=\"image/svg+xml\" width=\""));
+	m_sHTMLCode.Append(SG_Get_String(GRAPH_WIDTH + OFFSET_X, 0));
+	m_sHTMLCode.Append(SG_T("\" height=\""));
+	m_sHTMLCode.Append(SG_Get_String(GRAPH_HEIGHT + OFFSET_Y, 0));
+	m_sHTMLCode.Append(SG_T("\" data=\"file://"));
+	m_sHTMLCode.Append(Filename);
+	m_sHTMLCode.Append(SG_T("\"></object><br>\n"));
+
+	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
+	m_sHTMLCode.Append(Description);
+	m_sHTMLCode.Append(SG_T("</i></p>\n"));
+
+	fMin = fMax = Data[0].y;
+
+	for (i = 0; i < Data.Get_Count(); i++)
+	{
+		if (Data[i].y > fMax)
+		{
+			fMax = Data[i].y;
+		}
+		if (Data[i].y < fMin)
+		{
+			fMin = Data[i].y;
+		}
+		if (iGraphType == HTML_GRAPH_TYPE_BARS){
+			fMin = M_GET_MIN(0, fMin);
+		}
+    }
+
+	fRange = fMax - fMin;
+
+	fMaxX = Data[Data.Get_Count() - 1].x;
+    fMinX = Data[0].x;
+
+	fRangeX = fMaxX - fMinX;
+
+	SVG.Open(GRAPH_WIDTH + OFFSET_X, GRAPH_HEIGHT + OFFSET_Y);
+
+	if (fMin != fMax){
+		iMag	= (int) (log(fMax - fMin) / log(10.0));
+		fStep	= (int) pow(10.0, (double) iMag);
+		if (fStep == 0)
+		{
+			fStep = 1.;
+		}
+		if (fMin < 0)
+		{
+			iMag = (int) (log(fabs(fMin)) / log(10.0));
+			fMinLine = -(int) pow(10.0, (double) iMag);
+		}
+		else
+		{
+			fMinLine=(int)(((int)(fMin/fStep)) *fStep);
+		}
+
+		iNumLines = (int) ((fMax - fMin) / fStep);
+
+		while (iNumLines < 8)
+		{
+			fStep = fStep / 2.0;
+			iNumLines = (int) ((fMax - fMin) / fStep);
+		}
+		iNumLines = (int) ((fMax - fMinLine) / fStep);
+	}
+	else{
+		if (fMin > 0)
+		{
+			fStep = fMin = 0;
+			iNumLines = 1;
+			fMinLine = fMax;
+		}
+		else if (fMin < 0)
+		{
+			fStep = 0;
+			fMin = fMin - 1;
+			fMinLine = fMax;
+		}
+		else
+		{
+			return;
+		}
+	}
+
+	for (i = 0; i < iNumLines; i++)
+	{
+        fY = (fMinLine + fStep * i - fMin) / (fRange) * GRAPH_HEIGHT;
+		fY = GRAPH_HEIGHT - fY;
+        if (fY >= 0 && fY <= GRAPH_HEIGHT)
+		{
+			SVG.Draw_Line(OFFSET_X - 10, fY, GRAPH_WIDTH + OFFSET_X, fY);
+			SVG.Draw_Text(OFFSET_X - 10, fY, SG_Get_String(fMinLine + fStep * i, 1), 0, SG_T("Verdana"), 8, SVG_ALIGNMENT_Right);
+        }
+    }
+
+	if (iGraphType == HTML_GRAPH_TYPE_BARS)
+	{
+		fWidth = GRAPH_WIDTH / (double) (Data.Get_Count()) ;
+	    for (i = 0; i < Data.Get_Count(); i++)
+		{
+	        fX = OFFSET_X + i * fWidth;
+			fY = GRAPH_HEIGHT;
+			fY2 = (Data.Get_Y(i) - fMin) / fRange * GRAPH_HEIGHT;
+			fY2 = GRAPH_HEIGHT - fY2;
+			SVG.Draw_Rectangle(fX, fY, fX + fWidth, fY2, 0x660000, 0x000000);
+	    }
+	}
+	else
+	{
+		for (i = 0; i < Data.Get_Count(); i++)
+		{
+			fX = OFFSET_X + (Data.Get_X(i) - fMinX) / fRangeX * GRAPH_WIDTH;
+			fY = (Data.Get_Y(i) - fMin) / fRange * GRAPH_HEIGHT;
+			fY = GRAPH_HEIGHT - fY;
+			Points.Add(fX, fY);
+	    }
+		SVG.Draw_Line(Points, 4, 0x660000);
+	}
+
+	if (fMaxX != fMinX)
+	{
+		iMag = (int) (log(fMaxX - fMinX) / log(10.0));
+		fStep = (double) pow(10.0, (double) iMag);
+
+		iNumLines = (int) ((fMaxX -fMinX) / fStep);
+
+		while (iNumLines < 5)
+		{
+			fStep = fStep / 2.0;
+			iNumLines = (int) ((fMaxX-fMinX) / fStep);
+		}
+		fMinLine = (int)(((int)(fMinX/fStep)) * fStep);
+		while (fMinLine <fMinX)
+		{
+			fMinLine+=fStep;
+		}
+
+		for (i = 0; i < iNumLines + 1; i++)
+		{
+			if (iGraphType == HTML_GRAPH_TYPE_BARS)
+			{
+				fX = OFFSET_X + (fMinLine + fStep * i - fMinX) / fRangeX * (GRAPH_WIDTH - fWidth);
+			}
+			else
+			{
+				fX = OFFSET_X + (fMinLine + fStep * i - fMinX) / fRangeX * GRAPH_WIDTH;
+			}
+			if (fX >= OFFSET_X && fX <= GRAPH_WIDTH + OFFSET_X){
+				if (fabs(fStep * i +fMinLine) > 100000)
+				{
+					sValue = SG_Get_String(fStep * i +fMinLine);
+				}
+				else
+				{
+					sValue = SG_Get_String(fStep * i + fMinLine, 2, true);
+				}
+				SVG.Draw_Text(fX, GRAPH_HEIGHT + 10, sValue, 0, SG_T("Verdana"), 8, SVG_ALIGNMENT_Center);
+				SVG.Draw_Line(fX, GRAPH_HEIGHT, fX, GRAPH_HEIGHT - 5);
+			}
+		}
+    }
+
+	SVG.Draw_Line(OFFSET_X, 0, OFFSET_X, GRAPH_HEIGHT, 4);
+	SVG.Draw_Line(OFFSET_X, GRAPH_HEIGHT, OFFSET_X + GRAPH_WIDTH, GRAPH_HEIGHT, 4);
+
+	SVG.Save(Filename);
+
+	if (bIncludeTableData)
+	{
+		CSG_Doc_HTML HTMLDoc;
+		HTMLDoc.Open(LNG("Data Table"));
+
+		sTableFilename = Filename;
+		sTableFilename.Append(SG_T(".htm"));
+
+		m_sHTMLCode.Append(SG_T("<a href=\"file://"));
+		m_sHTMLCode.Append(sTableFilename);
+		m_sHTMLCode.Append(SG_T("\">"));
+		m_sHTMLCode.Append(LNG("Data Table"));
+		m_sHTMLCode.Append(SG_T("</a><br><br>\n"));
+
+		HTMLDoc._AddBicolumTable(&Data);
+		HTMLDoc.Save(sTableFilename);
+
+	}
+
+
+}//method
+
+void CSG_Doc_HTML::_AddBicolumTable(CSG_Points *pData)
+{
+
+	int i;
+
+    m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));
+	m_sHTMLCode.Append(
+		SG_T("<tr bgcolor=\"#CCCCCC\">\n")
+		SG_T("<td width=\"50%\" align=\"center\">X</td><td width=\"50%\" align=\"center\">Y</td>\n")
+		SG_T("</tr>\n")
+	);
+
+	for (i=0; i<pData->Get_Count(); i++)
+	{
+		m_sHTMLCode.Append(SG_T("<tr>\n"));
+		m_sHTMLCode.Append(SG_T("<td width=\"50%\" align=\"center\">"));
+		m_sHTMLCode.Append(SG_Get_String(pData->Get_X(i),2));
+		m_sHTMLCode.Append(SG_T("</td>"));
+		m_sHTMLCode.Append(SG_T("<td width=\"50%\" align=\"center\">"));
+		m_sHTMLCode.Append(SG_Get_String(pData->Get_Y(i),2));
+		m_sHTMLCode.Append(SG_T("</td>"));
+		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
+	}
+
+	m_sHTMLCode.Append(SG_T("\n</table>\n"));
+	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
+	m_sHTMLCode.Append(LNG("Data Table"));
+	m_sHTMLCode.Append(SG_T("</i></p>\n"));
+
+}
+
+void CSG_Doc_HTML::AddTable(const SG_Char ***Table,
+								int iRows,
+								int iCols,
+								const SG_Char *Description)
+{
+
+	int i,j;
+	int iWidth = (int) (100/iCols);
+
+    m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));
+	for (i=0; i<iRows; i++)
+	{
+		if (i==0)
+		{
+			m_sHTMLCode.Append(SG_T("<tr bgcolor=\"#CCCCCC\">\n"));
+		}
+		else
+		{
+			m_sHTMLCode.Append(SG_T("<tr>\n"));
+		}
+		for (j=0; j<iCols; j++){
+			m_sHTMLCode.Append(SG_T("<td width=\""));
+			m_sHTMLCode.Append(SG_Get_String(iWidth,0));
+			m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
+			try
+			{
+				m_sHTMLCode.Append(Table[i][j]);
+			}
+			catch(...){}
+			m_sHTMLCode.Append(SG_T("</td>"));
+		}
+		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
+	}
+
+	m_sHTMLCode.Append(SG_T("\n</table>\n"));
+	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
+	m_sHTMLCode.Append(Description);
+	m_sHTMLCode.Append(SG_T("</i></p>\n"));
+
+}
+
+void CSG_Doc_HTML::AddTable(CSG_Table *pTable)
+{
+
+	int i,j;
+	int iWidth = (int) (100/pTable->Get_Field_Count());
+
+    m_sHTMLCode.Append(SG_T("<table width=\"99%\" style=\"background-color:transparent;\" border=0 cellspacing=0 cellpadding=2 >\n"));
+
+	m_sHTMLCode.Append(SG_T("<tr bgcolor=\"#CCCCCC\">\n"));
+	for (i=0; i<pTable->Get_Field_Count(); i++){
+		m_sHTMLCode.Append(SG_T("<td width=\""));
+		m_sHTMLCode.Append(SG_Get_String(iWidth,0));
+		m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
+		m_sHTMLCode.Append(pTable->Get_Field_Name(i));
+		m_sHTMLCode.Append(SG_T("</td>"));
+	}
+	m_sHTMLCode.Append(SG_T("\n</tr>\n"));
+
+	for (i=0; i<pTable->Get_Record_Count(); i++)
+	{
+		m_sHTMLCode.Append(SG_T("<tr>\n"));
+		for (j=0; j<pTable->Get_Field_Count(); j++){
+			m_sHTMLCode.Append(SG_T("<td width=\""));
+			m_sHTMLCode.Append(SG_Get_String(iWidth,0));
+			m_sHTMLCode.Append(SG_T("%\" align=\"center\">"));
+			try
+			{
+				m_sHTMLCode.Append(pTable->Get_Record(i)->asString(j));
+			}
+			catch(...){}
+			m_sHTMLCode.Append(SG_T("</td>"));
+		}
+		m_sHTMLCode.Append(SG_T("\n</tr>\n"));
+	}
+
+	m_sHTMLCode.Append(SG_T("\n</table>\n"));
+	m_sHTMLCode.Append(SG_T("<p align=\"center\"><i>"));
+	m_sHTMLCode.Append(pTable->Get_Name());
+	m_sHTMLCode.Append(SG_T("</i></p>\n"));
+
+}
+
+bool CSG_Doc_HTML::_Draw_Shape(CSG_Doc_SVG &SVG, CSG_Shape *pShape, CSG_Rect GlobalRect, int Fill_Color, int Line_Color, int Line_Width, int Point_Width)
+{
+	if( pShape && pShape->is_Valid() )
+	{
+		int			iPart, iPoint;
+		double		x,y;
+		TSG_Point	Point;
+		CSG_Points	Points;
+		double		dWidth, dHeight;
+		double		dOffsetX, dOffsetY;
+
+		if (GlobalRect.Get_XRange() / GlobalRect.Get_YRange() > MAP_WIDTH / MAP_HEIGHT)
+		{
+			dWidth	= MAP_WIDTH * .95;
+			dHeight	= MAP_HEIGHT / GlobalRect.Get_XRange() * GlobalRect.Get_YRange();
+		}
+		else{
+			dHeight	= MAP_HEIGHT * .95;
+			dWidth	= MAP_WIDTH / GlobalRect.Get_YRange() * GlobalRect.Get_XRange();
+		}
+
+		dOffsetX = (MAP_WIDTH  - dWidth)  / 2.;
+		dOffsetY = (MAP_HEIGHT - dHeight) / 2.;
+
+		SVG.Draw_Rectangle(0,0,MAP_WIDTH,MAP_HEIGHT,SG_COLOR_NONE,SG_COLOR_BLACK,1);
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			Points.Clear();
+
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				Point = pShape->Get_Point(iPoint, iPart);
+				x = dOffsetX + (Point.x - GlobalRect.Get_XMin()) / GlobalRect.Get_XRange() * dWidth;
+				y = (Point.y - GlobalRect.Get_YMin()) / GlobalRect.Get_YRange() * dHeight;
+				y = MAP_HEIGHT - y - dOffsetY;
+				Points.Add(x, y);
+			}
+
+			switch( pShape->Get_Type() )
+			{
+			case SHAPE_TYPE_Point:
+			case SHAPE_TYPE_Points:
+				for(iPoint=0; iPoint<Points.Get_Count(); iPoint++)
+				{
+					SVG.Draw_Circle(Points[iPoint].x, Points[iPoint].y, Point_Width, Fill_Color, Line_Color, Line_Width);
+				}
+				break;
+
+			case SHAPE_TYPE_Line:
+				SVG.Draw_Line(Points, Line_Width, Line_Color);
+				break;
+
+			case SHAPE_TYPE_Polygon:
+				if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
+				{
+					SVG.Draw_Polygon(Points, SG_COLOR_WHITE, Line_Color, Line_Width);
+				}
+				else
+				{
+					SVG.Draw_Polygon(Points, Fill_Color, Line_Color, Line_Width);
+				}
+				break;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_Doc_HTML::Draw_Shapes(CSG_Shapes *pShapes, const SG_Char *Filename, int Fill_Color, int Line_Color, int Line_Width)
+{
+
+	CSG_Doc_SVG	SVG;
+	CSG_Rect	r;
+
+	if( pShapes && pShapes->is_Valid())
+	{
+		r = pShapes->Get_Extent();
+		SVG.Open((int)MAP_WIDTH, (int)MAP_HEIGHT);
+
+		for(int iShape=0; iShape<pShapes->Get_Count(); iShape++)
+		{
+			_Draw_Shape(SVG, pShapes->Get_Shape(iShape), r, Fill_Color, Line_Color, 1, 3);
+		}
+
+		SVG.Save(Filename);
+
+		m_sHTMLCode.Append(SG_T("<center>\n<object type=\"image/svg+xml\" width=\""));
+		m_sHTMLCode.Append(SG_Get_String(MAP_WIDTH, 0));
+		m_sHTMLCode.Append(SG_T("\" height=\""));
+		m_sHTMLCode.Append(SG_Get_String(MAP_HEIGHT, 0));
+		m_sHTMLCode.Append(SG_T("\" data=\"file://"));
+		m_sHTMLCode.Append(Filename);
+		m_sHTMLCode.Append(SG_T("\"></object></center><br>\n"));
+
+		return( true );
+
+	}
+
+	return( false );
+}

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_html.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,171 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      doc_html.h                       //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Victor Olaya                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__doc_html_H
+#define HEADER_INCLUDED__SAGA_API__doc_html_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+#include "doc_svg.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define HTML_GRAPH_TYPE_BARS					1
+#define HTML_GRAPH_TYPE_LINES					2
+
+#define HTML_COLOR_RANDOM						-2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Doc_HTML
+{
+public:
+	CSG_Doc_HTML(void);
+	virtual ~CSG_Doc_HTML(void);
+
+	void						Open						(const SG_Char *Title);
+	bool						Save						(const SG_Char *FileName);
+
+	void						AddCurve					(const SG_Char *Filename,
+															CSG_Points &Points,
+															const SG_Char *Description,
+															int iGraphType,
+															bool bIncludeTableData);
+	void						AddTable					(const SG_Char ***Table,
+															int iRows,
+															int iCols,
+															const SG_Char *Description);
+	void						AddTable					(CSG_Table *pTable);
+	void						AddParagraph				(const SG_Char *Text);
+	void						AddLineBreak				();
+	void						AddHeader					(const SG_Char *Text, int iOrder);
+	void						AddHyperlink				(const SG_Char *Text, const SG_Char *URL);
+	CSG_String					GetHyperlinkCode			(const SG_Char *Text, const SG_Char *URL);
+
+	void						AddImage					(const SG_Char *Filename);
+	void						AddThumbnail				(const SG_Char *Filename,
+															int iWidth,
+															bool bIsPercent);
+	void						AddThumbnails				(const SG_Char **Text,
+															int iImages,
+															int iThumbnailsPerRow);
+	void						StartUnorderedList			(void);
+	void						StartOrderedList			(void);
+	void						CloseUnorderedList			(void);
+	void						CloseOrderedList			(void);
+	void						AddListElement				(const SG_Char *Text);
+	void						AddOrderedList				(const SG_Char **Text,
+															int iElement);
+	void						AddUnorderedList			(const SG_Char **Text,
+															int iElement);
+
+	bool						Draw_Shapes					(CSG_Shapes *pShapes,
+															const SG_Char *Filename,
+															int Fill_Color, 
+															int Line_Color, 
+															int Line_Width);
+
+private:
+
+	CSG_String					m_sHTMLCode;
+
+	bool						_Draw_Shape					(CSG_Doc_SVG &SVG,
+															CSG_Shape *pShape,
+															CSG_Rect GlobalRect,
+															int Fill_Color, 
+															int Line_Color, 
+															int Line_Width, 
+															int Point_Width);
+
+	void						_AddBicolumTable			(CSG_Points *pData);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__doc_html_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1731 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     doc_pdf.cpp                       //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//              Victor Olaya, Olaf Conrad                //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _SAGA_DONOTUSE_HARU
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <hpdf.h>
+
+#include "doc_pdf.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define PDF_PAGE_WIDTH_A4		595.276
+#define PDF_PAGE_HEIGHT_A4		841.89
+
+#define PDF_PAGE_HEIGHT_A4_M	0.297
+
+#define PDF_PAGE_WIDTH_A3		 PDF_PAGE_HEIGHT_A4
+#define PDF_PAGE_HEIGHT_A3		(PDF_PAGE_HEIGHT_A4 * sqrt(2.0))
+
+#define PDF_METER_TO_POINT		(PDF_PAGE_HEIGHT_A4 / PDF_PAGE_HEIGHT_A4_M)
+#define PDF_POINT_TO_METER		(PDF_PAGE_HEIGHT_A4_M / PDF_PAGE_HEIGHT_A4)
+
+//---------------------------------------------------------
+#define PDF_GET_R(c)			(float)(SG_GET_R(c) / 255.0)
+#define PDF_GET_G(c)			(float)(SG_GET_G(c) / 255.0)
+#define PDF_GET_B(c)			(float)(SG_GET_B(c) / 255.0)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Doc_PDF::CSG_Doc_PDF(void)
+{
+	m_pPDF	= NULL;
+
+	Layout_Set_Box_Space(5, false);
+
+	Open();
+}
+
+//---------------------------------------------------------
+CSG_Doc_PDF::CSG_Doc_PDF(TSG_PDF_Page_Size Size, int Orientation, const SG_Char *Title)
+{
+	m_pPDF	= NULL;
+
+	Layout_Set_Box_Space(5, false);
+
+	Open(Size, Orientation, Title);
+}
+
+//---------------------------------------------------------
+CSG_Doc_PDF::~CSG_Doc_PDF(void)
+{
+	Close();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Doc_PDF::Get_Version(void)
+{
+	static CSG_String	s	= CSG_String::Format(SG_T("Haru Free PDF Library, Version %s"), HPDF_VERSION_TEXT);
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Open(const SG_Char *Title)
+{
+	return( Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_PORTRAIT, Title) );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Open(TSG_PDF_Page_Size Size, int Orientation, const SG_Char *Title)
+{
+	if( Close() )
+	{
+		m_pPDF	= HPDF_New(NULL, NULL);
+
+		m_pOutline_Last_Level_0 = NULL;
+		m_pOutline_Last_Level_1 = NULL;
+		m_pOutline_Last_Level_2 = NULL;
+
+		Set_Size_Page(Size, Orientation);
+
+		if( Title && *Title )
+		{
+			Add_Page_Title(Title);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Close(void)
+{
+	if( m_pPDF )
+	{
+		try
+		{
+			HPDF_Free(m_pPDF);
+		}
+		catch(...)
+		{
+			return( false );
+		}
+	}
+
+	m_pPDF		= NULL;
+	m_pPage		= NULL;
+	m_nPages	= 0;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Save(const SG_Char *FileName)
+{
+	if( m_pPDF && m_nPages > 0 && SG_Dir_Create(SG_File_Get_Path(FileName)) )
+	{
+		try
+		{
+			return( HPDF_SaveToFile(m_pPDF, SG_STR_SGTOMB(FileName)) == HPDF_OK );
+		}
+		catch(...)
+		{}
+	}
+
+	SG_UI_Msg_Add_Error(LNG("[ERR] Could not save PDF file."));
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Doc_PDF::Get_Page_To_Meter(void)
+{
+	return( PDF_POINT_TO_METER );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+struct _HPDF_Dict_Rec * CSG_Doc_PDF::_Get_Font(TSG_PDF_Font_Type Font)
+{
+	switch( Font )
+	{
+	default:
+	case PDF_FONT_Helvetica:				return( HPDF_GetFont(m_pPDF, "Helvetica"			, NULL) );
+	case PDF_FONT_Helvetica_Bold:			return( HPDF_GetFont(m_pPDF, "Helvetica-Bold"		, NULL) );
+	case PDF_FONT_Helvetica_Oblique:		return( HPDF_GetFont(m_pPDF, "Helvetica-Oblique"	, NULL) );
+	case PDF_FONT_Helvetica_BoldOblique:	return( HPDF_GetFont(m_pPDF, "Helvetica-BoldOblique", NULL) );
+	case PDF_FONT_Times_Roman:				return( HPDF_GetFont(m_pPDF, "Times-Roman"			, NULL) );
+	case PDF_FONT_Times_Bold:				return( HPDF_GetFont(m_pPDF, "Times-Bold"			, NULL) );
+	case PDF_FONT_Times_Italic:				return( HPDF_GetFont(m_pPDF, "Times-Italic"			, NULL) );
+	case PDF_FONT_Times_BoldItalic:			return( HPDF_GetFont(m_pPDF, "Times-BoldItalic"		, NULL) );
+	case PDF_FONT_Courier:					return( HPDF_GetFont(m_pPDF, "Courier"				, NULL) );
+	case PDF_FONT_Courier_Bold:				return( HPDF_GetFont(m_pPDF, "Courier-Bold"			, NULL) );
+	case PDF_FONT_Courier_Oblique:			return( HPDF_GetFont(m_pPDF, "Courier-Oblique"		, NULL) );
+	case PDF_FONT_Courier_BoldOblique:		return( HPDF_GetFont(m_pPDF, "Courier-BoldOblique"	, NULL) );
+	case PDF_FONT_Symbol:					return( HPDF_GetFont(m_pPDF, "Symbol"				, NULL) );
+	case PDF_FONT_ZapfDingbats:				return( HPDF_GetFont(m_pPDF, "ZapfDingbats"			, NULL) );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Layout_Add_Box(double xMin_Percent, double yMin_Percent, double xMax_Percent, double yMax_Percent, const SG_Char *ID)
+{
+	if( m_Boxes_Percent.Add(xMin_Percent, yMin_Percent, xMax_Percent, yMax_Percent) )
+	{
+		m_Boxes.Add();
+		m_Boxes_ID.Add(ID);
+
+		_Layout_Set_Box(m_Boxes.Get_Count() - 1);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Layout_Add_Box(const CSG_Rect &Box_Percent, const SG_Char *ID)
+{
+	return( Layout_Add_Box(Box_Percent.Get_XMin(), Box_Percent.Get_YMin(), Box_Percent.Get_XMax(), Box_Percent.Get_YMax(), ID) );
+}
+
+//---------------------------------------------------------
+const CSG_Rect & CSG_Doc_PDF::Layout_Get_Box(const SG_Char *ID)
+{
+	for(int i=0; i<m_Boxes_ID.Get_Count(); i++)
+	{
+		if( !m_Boxes_ID[i].Cmp(ID) )
+		{
+			return( Layout_Get_Box(i) );
+		}
+	}
+
+	return( Layout_Get_Box(-1) );
+}
+
+//---------------------------------------------------------
+void CSG_Doc_PDF::Layout_Set_Box_Space(double Space, bool bPercent)
+{
+	m_Boxes_Space_bPercent	= bPercent;
+	m_Boxes_Space			= Space;
+}
+
+//---------------------------------------------------------
+void CSG_Doc_PDF::_Layout_Set_Boxes(void)
+{
+	for(int i=0; i<m_Boxes.Get_Count(); i++)
+	{
+		_Layout_Set_Box(i);
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Doc_PDF::_Layout_Set_Box(int iBox)
+{
+	if( iBox >= 0 && iBox < m_Boxes.Get_Count() && iBox < m_Boxes_Percent.Get_Count() )
+	{
+		m_Boxes[iBox].Assign(
+			m_Size_Margins.Get_XMin() + 0.01 * m_Boxes_Percent[iBox].Get_XMin() * m_Size_Margins.Get_XRange(),
+			m_Size_Margins.Get_YMax() - 0.01 * m_Boxes_Percent[iBox].Get_YMax() * m_Size_Margins.Get_YRange(),
+			m_Size_Margins.Get_XMin() + 0.01 * m_Boxes_Percent[iBox].Get_XMax() * m_Size_Margins.Get_XRange(),
+			m_Size_Margins.Get_YMax() - 0.01 * m_Boxes_Percent[iBox].Get_YMin() * m_Size_Margins.Get_YRange()
+		);
+
+		m_Boxes[iBox].Deflate(m_Boxes_Space, m_Boxes_Space_bPercent);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Fit_Rectangle(double &x, double &y, double &dx, double &dy, double XToY_Ratio, bool bShrink)
+{
+	if( XToY_Ratio != 0.0 && dx != 0.0 && dy != 0.0 )
+	{
+		if( XToY_Ratio > dx / dy )
+		{
+			if( bShrink )
+			{
+				XToY_Ratio	 = dx / XToY_Ratio;
+				y			+= (dy - XToY_Ratio) / 2.0;
+				dy			 = XToY_Ratio;
+			}
+			else
+			{
+				XToY_Ratio	 = dy * XToY_Ratio;
+				x			-= (dx - XToY_Ratio) / 2.0;
+				dx			 = XToY_Ratio;
+			}
+		}
+		else
+		{
+			if( bShrink )
+			{
+				XToY_Ratio	 = dy * XToY_Ratio;
+				x			+= (dx - XToY_Ratio) / 2.0;
+				dx			 = XToY_Ratio;
+			}
+			else
+			{
+				XToY_Ratio	 = dx / XToY_Ratio;
+				y			-= (dy - XToY_Ratio) / 2.0;
+				dy			 = XToY_Ratio;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Fit_Rectangle(CSG_Rect &r, double XToY_Ratio, bool bShrink)
+{
+	double	x, y, dx, dy;
+
+	x	= r.Get_XMin();
+	y	= r.Get_YMin();
+	dx	= r.Get_XRange();
+	dy	= r.Get_YRange();
+
+	if( _Fit_Rectangle(x, y, dx, dy, XToY_Ratio, bShrink) )
+	{
+		r.Assign(x, y, x + dx, y + dy);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Add_Outline_Item(const SG_Char *Title, struct _HPDF_Dict_Rec *pPage, TSG_PDF_Title_Level Level)
+{
+	if( m_pPDF && pPage )
+	{
+		HPDF_Outline	pOutlineItem	= NULL;
+
+		switch( Level )
+		{
+		case PDF_TITLE:
+			pOutlineItem	= m_pOutline_Last_Level_0	= HPDF_CreateOutline(m_pPDF, NULL, SG_STR_SGTOMB(Title), NULL);
+			break;
+
+		case PDF_TITLE_01:
+			if( m_pOutline_Last_Level_0 )
+			{
+				pOutlineItem	= m_pOutline_Last_Level_1	= HPDF_CreateOutline(m_pPDF, m_pOutline_Last_Level_0, SG_STR_SGTOMB(Title), NULL);
+			}
+			break;
+
+		case PDF_TITLE_02:
+			if( m_pOutline_Last_Level_1 )
+			{
+				pOutlineItem	= m_pOutline_Last_Level_2	= HPDF_CreateOutline(m_pPDF, m_pOutline_Last_Level_1, SG_STR_SGTOMB(Title), NULL);
+			}
+			break;
+
+		case PDF_TITLE_NONE:
+			if( m_pOutline_Last_Level_2 )
+			{
+				pOutlineItem	= HPDF_CreateOutline(m_pPDF, m_pOutline_Last_Level_2, SG_STR_SGTOMB(Title), NULL);
+			}
+			break;
+
+		}
+
+		if( pOutlineItem )
+		{
+			if( pPage )
+			{
+				struct _HPDF_Array_Rec	*pDestination	= HPDF_Page_CreateDestination(pPage);
+
+				HPDF_Destination_SetFit		(pDestination);
+				HPDF_Outline_SetDestination	(pOutlineItem, pDestination);
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Add_Outline_Item(const SG_Char *Title)
+{
+	return( _Add_Outline_Item(Title, m_pPage, _Get_Lowest_Outline_Level()) );
+}
+
+//---------------------------------------------------------
+TSG_PDF_Title_Level CSG_Doc_PDF::_Get_Lowest_Outline_Level(void)
+{
+	if( m_pOutline_Last_Level_2 )
+	{
+		return( PDF_TITLE_NONE );
+	}
+	else if( m_pOutline_Last_Level_1 )
+	{
+		return( PDF_TITLE_02 );
+	}
+	else if( m_pOutline_Last_Level_0 )
+	{
+		return( PDF_TITLE_01 );
+	}
+
+	return( PDF_TITLE );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Add_Page(void)
+{
+	return( Add_Page(m_Size_Paper.Get_XRange(), m_Size_Paper.Get_YRange()) );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Add_Page(TSG_PDF_Page_Size Size, int Orientation)
+{
+	if( Add_Page() )
+	{
+		return( Set_Size_Page(Size, Orientation) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Add_Page(double Width, double Height)
+{
+	if( m_pPDF )
+	{
+		m_nPages++;
+
+		m_pPage		= HPDF_AddPage(m_pPDF);
+
+		Set_Size_Page(Width, Height);
+
+		HPDF_Page_SetRGBStroke	(m_pPage, 0.0, 0.0, 0.0);
+		HPDF_Page_SetRGBFill	(m_pPage, 1.0, 1.0, 1.0);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Set_Size_Page(TSG_PDF_Page_Size Size, int Orientation)
+{
+	double	Width, Height;
+
+	switch( Size )
+	{
+	case PDF_PAGE_SIZE_A4:	default:
+		Width	= PDF_PAGE_WIDTH_A4;
+		Height	= PDF_PAGE_HEIGHT_A4;
+		break;
+
+	case PDF_PAGE_SIZE_A3:
+		Width	= PDF_PAGE_WIDTH_A3;
+		Height	= PDF_PAGE_HEIGHT_A3;
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( Orientation == PDF_PAGE_ORIENTATION_LANDSCAPE )
+	{
+		double	a;
+
+		a		= Width;
+		Width	= Height;
+		Height	= a;
+	}
+
+	return( Set_Size_Page(Width, Height) );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Set_Size_Page(double Width, double Height)
+{
+	if( Width > 0.0 && Height > 0.0 )
+	{
+		m_Size_Paper.Assign(0.0, 0.0, Width, Height);
+
+		m_Size_Margins	= m_Size_Paper;
+		m_Size_Margins.Deflate(10.0, false);
+
+		_Layout_Set_Boxes();
+
+		if( m_pPage )
+		{
+			HPDF_Page_SetWidth	(m_pPage, (float)m_Size_Paper.Get_XRange());
+			HPDF_Page_SetHeight	(m_pPage, (float)m_Size_Paper.Get_YRange());
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Add_Page_Title(const SG_Char *Title, TSG_PDF_Title_Level Level, TSG_PDF_Page_Size Size, int Orientation)
+{
+	bool	bLine, bDestination, bPage;
+	int		FontSize;
+
+	//-----------------------------------------------------
+	if( Add_Page() )
+	{
+		if( m_nPages % 2 - 1 )
+		{
+			Add_Page();
+		}
+
+		if( Size != PDF_PAGE_SIZE_PREVIOUS || Orientation != PDF_PAGE_ORIENTATION_PREVIOUS )
+		{
+			Set_Size_Page(Size, Orientation);
+		}
+
+		//-------------------------------------------------
+		switch( Level )
+		{
+		case PDF_TITLE:
+			FontSize		= 26;
+			bLine			= true;
+			bDestination	= true;
+			bPage			= true;
+			break;
+
+		case PDF_TITLE_01:
+			FontSize		= 22;
+			bLine			= true;
+			bDestination	= false;
+			bPage			= true;
+			break;
+
+		case PDF_TITLE_02:
+			FontSize		= 20;
+			bLine			= false;
+			bDestination	= false;
+			bPage			= false;
+			break;
+		}
+
+		_Add_Outline_Item(Title, m_pPage, Level);
+
+		//-------------------------------------------------
+		Draw_Text(Get_Margins().Get_XCenter(), Get_Margins().Get_YCenter(), Title, FontSize, PDF_STYLE_TEXT_ALIGN_H_CENTER, 0.0, SG_GET_RGB(0, 0, 0));
+
+		//-------------------------------------------------
+		if( bLine )
+		{
+			double	y	= Get_Margins().Get_YCenter() - 25.0;
+
+			Draw_Line(Get_Margins().Get_XMin(), y, Get_Margins().Get_XMax(), y, 5, SG_GET_RGB(0, 0, 0), PDF_STYLE_LINE_END_ROUND);
+		}
+
+		if( bPage )
+		{
+			Add_Page();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Set_Style_FillStroke(int Style, int Fill_Color, int Line_Color, int Line_Width)
+{
+	if( Is_Ready_To_Draw() )
+	{
+		if( Style & PDF_STYLE_POLYGON_STROKE )
+		{
+			if( Style & PDF_STYLE_LINE_END_ROUND )
+			{
+				HPDF_Page_SetLineCap(m_pPage, HPDF_ROUND_END);
+			}
+			else if( Style & PDF_STYLE_LINE_END_SQUARE )
+			{
+				HPDF_Page_SetLineCap(m_pPage, HPDF_PROJECTING_SCUARE_END);
+			}
+			else // if( Style & PDF_STYLE_LINE_END_BUTT )
+			{
+				HPDF_Page_SetLineCap(m_pPage, HPDF_BUTT_END);
+			}
+
+			if( Style & PDF_STYLE_LINE_JOIN_ROUND )
+			{
+				HPDF_Page_SetLineJoin(m_pPage, HPDF_ROUND_JOIN);
+			}
+			else if( Style & PDF_STYLE_LINE_JOIN_BEVEL )
+			{
+				HPDF_Page_SetLineJoin(m_pPage, HPDF_BEVEL_JOIN);
+			}
+			else // if( Style & PDF_STYLE_LINE_JOIN_MITER )
+			{
+				HPDF_Page_SetLineJoin(m_pPage, HPDF_MITER_JOIN);
+			}
+
+			HPDF_Page_SetRGBStroke	(m_pPage, PDF_GET_R(Line_Color), PDF_GET_G(Line_Color), PDF_GET_B(Line_Color));
+
+			HPDF_Page_SetLineWidth	(m_pPage, (float)Line_Width);
+		}
+
+		//-------------------------------------------------
+		if( Style & PDF_STYLE_POLYGON_FILL )
+		{
+			HPDF_Page_SetRGBFill(m_pPage, PDF_GET_R(Fill_Color), PDF_GET_G(Fill_Color), PDF_GET_B(Fill_Color));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Point(double x, double y, double Width, int Style, int Fill_Color, int Line_Color, int Line_Width)
+{
+	if( Is_Ready_To_Draw() )
+	{
+		Width	/= 2.0;
+
+		//-------------------------------------------------
+	//	if( Style & PDF_STYLE_POINT_CIRCLE )
+		{
+		}
+	//	else // if( Style & PDF_STYLE_POINT_SQUARE )
+		{
+			return( Draw_Rectangle(x - Width, y - Width, x + Width, y + Width, Style, Fill_Color, Line_Color, Line_Width) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Line(double xa, double ya, double xb, double yb, int Width, int Color, int Style)
+{
+	CSG_Points	Points;
+
+	Points.Add(xa, ya);
+	Points.Add(xb, yb);
+
+	return( Draw_Line(Points, Width, Color, Style) );
+}
+
+bool CSG_Doc_PDF::Draw_Line(CSG_Points &Points, int Width, int Color, int Style)
+{
+	if( Points.Get_Count() > 1 && _Set_Style_FillStroke(Style|PDF_STYLE_POLYGON_STROKE, 0, Color, Width) )
+	{
+		HPDF_Page_MoveTo(m_pPage, (float)Points[0].x, (float)Points[0].y);
+
+		for(int i=1; i<Points.Get_Count(); i++)
+		{
+			HPDF_Page_LineTo(m_pPage, (float)Points[i].x, (float)Points[i].y);
+		}
+
+		//-------------------------------------------------
+		HPDF_Page_Stroke(m_pPage);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Rectangle(double xa, double ya, double xb, double yb, int Style, int Fill_Color, int Line_Color, int Line_Width)
+{
+	CSG_Points	Points;
+
+	Points.Add(xa, ya);
+	Points.Add(xb, ya);
+	Points.Add(xb, yb);
+	Points.Add(xa, yb);
+
+	return( Draw_Polygon(Points, Style, Fill_Color, Line_Color, Line_Width) );
+}
+
+bool CSG_Doc_PDF::Draw_Rectangle(const CSG_Rect &r, int Style, int Fill_Color, int Line_Color, int Line_Width)
+{
+	return( Draw_Rectangle(r.Get_XMin(), r.Get_YMin(), r.Get_XMax(), r.Get_YMax(), Style, Fill_Color, Line_Color, Line_Width) );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Polygon(CSG_Points &Points, int Style, int Fill_Color, int Line_Color, int Line_Width)
+{
+	if( Points.Get_Count() > 2 && _Set_Style_FillStroke(Style, Fill_Color, Line_Color, Line_Width) )
+	{
+		HPDF_Page_MoveTo(m_pPage, (float)Points[0].x, (float)Points[0].y);
+
+		for(int i=1; i<Points.Get_Count(); i++)
+		{
+			HPDF_Page_LineTo(m_pPage, (float)Points[i].x, (float)Points[i].y);
+		}
+
+		HPDF_Page_ClosePath(m_pPage);
+
+		//-------------------------------------------------
+		if( Style & PDF_STYLE_POLYGON_FILL && Style & PDF_STYLE_POLYGON_STROKE )
+		{
+			HPDF_Page_EofillStroke(m_pPage);
+		}
+		else if( Style & PDF_STYLE_POLYGON_FILL )
+		{
+			HPDF_Page_Eofill(m_pPage);
+		}
+		else // if( Style & PDF_STYLE_POLYGON_STROKE )
+		{
+			HPDF_Page_Stroke(m_pPage);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Text(double x, double y, CSG_Strings &Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)
+{
+	if( Is_Ready_To_Draw() && Text.Get_Count() > 0 )
+	{
+		for(int i=0; i<Text.Get_Count(); i++, y-=Size)
+		{
+			_Draw_Text(x, y, Text[i], Size, Style, Angle, Color, Font);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Text(double x, double y, const SG_Char *Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)
+{
+	int				n;
+	CSG_String		String(Text);
+	CSG_Strings	Strings;
+
+	while( (n = String.Find('\n')) >= 0 )
+	{
+		Strings.Add(String.Left(n));
+		String.Remove(0, n + 1);
+	}
+
+	if( Strings.Get_Count() > 0 )
+	{
+		if( String.Length() > 0 )
+		{
+			Strings.Add(String);
+		}
+
+		return( Draw_Text(x, y, Strings, Size, Style, Angle, Color, Font) );
+	}
+
+	return( _Draw_Text(x, y, Text, Size, Style, Angle, Color, Font) );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Draw_Text(double x, double y, const SG_Char *Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)
+{
+	float	Width, Height;
+
+	if( m_pPage && Text && *Text != '\0' )
+	{
+		double	ax, ay, bx, by;
+
+		HPDF_Page_SetFontAndSize(m_pPage, _Get_Font(Font), (float)Size);
+
+		HPDF_Page_SetTextRenderingMode(m_pPage, HPDF_FILL_THEN_STROKE);
+		HPDF_Page_SetLineWidth	(m_pPage, 0);
+		HPDF_Page_SetRGBStroke	(m_pPage, PDF_GET_R(Color), PDF_GET_G(Color), PDF_GET_B(Color));
+		HPDF_Page_SetRGBFill	(m_pPage, PDF_GET_R(Color), PDF_GET_G(Color), PDF_GET_B(Color));
+
+		Width	= HPDF_Page_TextWidth(m_pPage, SG_STR_SGTOMB(Text)) * (float)cos(Angle);
+		Height	= HPDF_Page_TextWidth(m_pPage, SG_STR_SGTOMB(Text)) * (float)sin(Angle) + Size;
+
+		//-------------------------------------------------
+		if( Style & PDF_STYLE_TEXT_ALIGN_H_CENTER )
+		{
+			ax	= x - HPDF_Page_TextWidth(m_pPage, SG_STR_SGTOMB(Text)) / 2.0;
+		}
+		else if( Style & PDF_STYLE_TEXT_ALIGN_H_RIGHT )
+		{
+			ax	= x - HPDF_Page_TextWidth(m_pPage, SG_STR_SGTOMB(Text));
+		}
+		else
+		{
+			ax	= x;
+		}
+
+		bx	= ax + HPDF_Page_TextWidth(m_pPage, SG_STR_SGTOMB(Text));
+
+		if( Style & PDF_STYLE_TEXT_ALIGN_V_CENTER )
+		{
+			ay	= y - Size / 2.0;
+		}
+		else if( Style & PDF_STYLE_TEXT_ALIGN_V_TOP )
+		{
+			ay	= y - Size;
+		}
+		else
+		{
+			ay	= y;
+		}
+
+		by	= ay;
+
+		//-------------------------------------------------
+		HPDF_Page_BeginText(m_pPage);
+
+		if( Angle != 0.0 )
+		{
+			double	dSin, dCos, dx, dy;
+
+			dSin	= sin(-Angle);
+			dCos	= cos(-Angle),
+
+			dx	= ax - x,
+			dy	= ay - y;
+			ax	= x + dCos * dx + dSin * dy;
+			ay	= y - dSin * dx + dCos * dy;
+
+			dx	= bx - x,
+			dy	= by - y;
+			bx	= x + dCos * dx + dSin * dy;
+			by	= y - dSin * dx + dCos * dy;
+
+			dSin	= sin(Angle);
+			dCos	= cos(Angle),
+
+			HPDF_Page_SetTextMatrix(m_pPage, (float)dCos, (float)dSin, -(float)dSin, (float)dCos, (float)ax, (float)ay);
+		}
+		else
+		{
+			HPDF_Page_MoveTextPos(m_pPage, (float)ax, (float)ay);
+		}
+
+		HPDF_Page_ShowText(m_pPage, SG_STR_SGTOMB(Text));
+		HPDF_Page_EndText(m_pPage);
+
+		//-------------------------------------------------
+		if( Style & PDF_STYLE_TEXT_UNDERLINE )
+		{
+			double	dx, dy;
+
+			dy	=  0.2 * Size * (ax - bx) / SG_Get_Distance(ax, ay, bx, by);
+			dx	= -0.2 * Size * (ay - by) / SG_Get_Distance(ax, ay, bx, by);
+
+			Draw_Line(ax + dx, ay + dy, bx + dx, by + dy, (int)(0.1 * Size), Color);
+		}
+
+		if( Style & PDF_STYLE_TEXT_STROKE )
+		{
+			double	dx, dy;
+
+			dy	= -0.4 * Size * (ax - bx) / SG_Get_Distance(ax, ay, bx, by);
+			dx	=  0.4 * Size * (ay - by) / SG_Get_Distance(ax, ay, bx, by);
+
+			Draw_Line(ax + dx, ay + dy, bx + dx, by + dy, (int)(0.1 * Size), Color);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Image(double x, double y, double dx, double dy, const SG_Char *FileName)
+{
+	bool		bKeepRatio	= true;
+	double		nx, ny;
+	HPDF_Image	pImage		= NULL;
+
+	//-----------------------------------------------------
+	if( m_pPage && SG_File_Exists(FileName) && dx > 0.0 && dy > 0.0 )
+	{
+		if( SG_File_Cmp_Extension(FileName, SG_T("png")) )
+		{
+	try	{	pImage	= HPDF_LoadPngImageFromFile (m_pPDF, SG_STR_SGTOMB(FileName));	}	catch(...)	{}
+		}
+		else if( SG_File_Cmp_Extension(FileName, SG_T("jpg")) )
+		{
+	try	{	pImage	= HPDF_LoadJpegImageFromFile(m_pPDF, SG_STR_SGTOMB(FileName));	}	catch(...)	{}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pImage && (nx = HPDF_Image_GetWidth(pImage)) > 0 && (ny = HPDF_Image_GetHeight(pImage)) > 0 )
+	{
+		if( bKeepRatio )
+		{
+			_Fit_Rectangle(x, y, dx, dy, nx / ny, true);
+		}
+
+		HPDF_Page_DrawImage(m_pPage, pImage, (float)x, (float)y, (float)dx, (float)dy);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Image(const CSG_Rect &r, const SG_Char *FileName)
+{
+	return( Draw_Image(r.Get_XMin(), r.Get_YMin(), r.Get_XRange(), r.Get_YRange(), FileName) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Graticule(const CSG_Rect &r, const CSG_Rect &rWorld, int Size)
+{
+	if( Is_Ready_To_Draw() )
+	{
+		CSG_Rect	rRuler, rFrame(r);
+
+		rFrame.Inflate(Size, false);
+
+		Draw_Rectangle(rFrame, PDF_STYLE_POLYGON_STROKE);
+		Draw_Rectangle(r     , PDF_STYLE_POLYGON_STROKE);
+
+		rRuler.Assign(r.Get_XMin(), r.Get_YMax(), r.Get_XMax(), rFrame.Get_YMax());
+		_Draw_Ruler(rRuler, rWorld.Get_XMin(), rWorld.Get_XMax()  , true , true , false);
+
+		rRuler.Assign(r.Get_XMin(), r.Get_YMin(), r.Get_XMax(), rFrame.Get_YMin());
+		_Draw_Ruler(rRuler, 0.0              , rWorld.Get_XRange(), true , true , true);
+
+		rRuler.Assign(r.Get_XMin(), r.Get_YMin(), rFrame.Get_XMin(), r.Get_YMax());
+		_Draw_Ruler(rRuler, rWorld.Get_YMin(), rWorld.Get_YMax()  , false, false, false);
+
+		rRuler.Assign(r.Get_XMax(), r.Get_YMin(), rFrame.Get_XMax(), r.Get_YMax());
+		_Draw_Ruler(rRuler, 0.0              , rWorld.Get_YRange(), false, false, true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+#define RULER_TEXT_SPACE	4
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Draw_Ruler(const CSG_Rect &r, double zMin, double zMax, bool bHorizontal, bool bAscendent, bool bTickAtTop)
+{
+	int			Decimals, FontSize;
+	double		xOff, yOff, Width, Height, Height_Tick, z, dz, zToDC, zDC, zPos, tPos;
+	CSG_String	s;
+
+	//-----------------------------------------------------
+	Width	= bHorizontal ? r.Get_XRange() : r.Get_YRange();
+	Height	= bHorizontal ? r.Get_YRange() : r.Get_XRange();
+
+	if( Is_Ready_To_Draw() && zMin < zMax && Width > 0 && Height > 0 )
+	{
+		xOff		= r.Get_XMin();
+		yOff		= r.Get_YMax();
+
+		FontSize	= (int)(0.45 * (double)Height);
+		HPDF_Page_SetFontAndSize(m_pPage, _Get_Font(PDF_FONT_DEFAULT), (float)FontSize);
+
+		Height_Tick	= (int)(0.3 * (double)Height);
+
+		//-------------------------------------------------
+		zToDC		= (double)Width / (zMax - zMin);
+
+		dz			= pow(10.0, floor(log10(zMax - zMin)) - 1.0);
+		Decimals	= dz >= 1.0 ? 0 : (int)fabs(log10(dz));
+
+		s.Printf(SG_T("%.*f"), Decimals, zMax);
+		zDC			= HPDF_Page_TextWidth(m_pPage, SG_STR_SGTOMB(s));
+		while( zToDC * dz < zDC + RULER_TEXT_SPACE )
+		{
+			dz	*= 2;
+		}
+
+		//-------------------------------------------------
+		z			= dz * floor(zMin / dz);
+		if( z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			s.Printf(SG_T("%.*f"), Decimals, z);
+
+			zDC	= bAscendent ? zToDC * (z - zMin) : Width - zToDC * (z - zMin);
+
+			if( bHorizontal )
+			{
+				zPos	= xOff + zDC;
+
+				if( bTickAtTop )
+				{
+					tPos	= yOff;
+					Draw_Line(zPos, tPos - Height_Tick, zPos, yOff);
+					Draw_Text(zPos, tPos - Height_Tick, s, FontSize, PDF_STYLE_TEXT_ALIGN_H_CENTER|PDF_STYLE_TEXT_ALIGN_V_TOP, 0.0);
+				}
+				else
+				{
+					tPos	= yOff - Height;
+					Draw_Line(zPos, tPos + Height_Tick, zPos, tPos);
+					Draw_Text(zPos, tPos + Height_Tick, s, FontSize, PDF_STYLE_TEXT_ALIGN_H_CENTER|PDF_STYLE_TEXT_ALIGN_V_BOTTOM, 0.0);
+				}
+			}
+			else
+			{
+				zPos	= yOff - zDC;
+
+				if( bTickAtTop )
+				{
+					tPos	= xOff;
+					Draw_Line(tPos + Height_Tick, zPos, tPos, zPos);
+					Draw_Text(tPos + Height_Tick, zPos, s, FontSize, PDF_STYLE_TEXT_ALIGN_H_CENTER|PDF_STYLE_TEXT_ALIGN_V_TOP, M_DEG_TO_RAD * 90.0);
+				}
+				else
+				{
+					tPos	= xOff + Height;
+					Draw_Line(tPos - Height_Tick, zPos, tPos, zPos);
+					Draw_Text(tPos - Height_Tick, zPos, s, FontSize, PDF_STYLE_TEXT_ALIGN_H_CENTER|PDF_STYLE_TEXT_ALIGN_V_BOTTOM, M_DEG_TO_RAD * 90.0);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Draw_Table(CSG_Rect r, CSG_Table *pTable, int iRecord, int nRecords, double CellHeight, double HeaderHeightRel)
+{
+	int				iField, dyFont, dyFont_Hdr;
+	double			xPos, yPos, dxPos, dyPos, dyPos_Hdr, xSpace, ySpace, ySpace_Hdr;
+	bool			bAddHeader;
+	CSG_Table_Record	*pRecord;
+
+	if( pTable && pTable->is_Valid() && iRecord < pTable->Get_Record_Count() )
+	{
+	//	Draw_Text(r.Get_XMin(), r.Get_YMax(), pTable->Get_Name(), 16);	// the table's name should not be drawn here...
+
+		dxPos		= r.Get_XRange() / pTable->Get_Field_Count();
+
+		if( HeaderHeightRel < 1.0 )
+			HeaderHeightRel	= 1.0;
+
+		dyPos		= CellHeight > 0.0 ? CellHeight : r.Get_YRange() / (nRecords + HeaderHeightRel);
+		dyPos_Hdr	= dyPos * HeaderHeightRel;
+
+		dyFont		= (int)(0.75 * dyPos);
+		dyFont_Hdr	= (int)(0.75 * dyPos_Hdr);
+
+		ySpace		= 0.1 * dyPos;
+		ySpace_Hdr	= 0.1 * dyPos_Hdr;
+		xSpace		= ySpace;
+
+		nRecords	+= iRecord;
+
+		if( nRecords > pTable->Get_Record_Count() )
+		{
+			nRecords	= pTable->Get_Record_Count();
+		}
+
+		//-------------------------------------------------
+		for(yPos=r.Get_YMax(), bAddHeader=true; iRecord<nRecords; iRecord++, yPos-=dyPos)
+		{
+			if( yPos < r.Get_YMin() - dyPos )
+			{
+				Add_Page();
+
+				yPos		= r.Get_YMax();
+				bAddHeader	= true;
+			}
+
+			if( bAddHeader )
+			{
+				for(iField=0, xPos=r.Get_XMin(); iField<pTable->Get_Field_Count(); iField++, xPos+=dxPos)
+				{
+					Draw_Rectangle(xPos, yPos, xPos + dxPos, yPos - dyPos_Hdr, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_GREY_LIGHT, SG_COLOR_BLACK, 0);
+					Draw_Text(xPos + xSpace, yPos - ySpace_Hdr, pTable->Get_Field_Name(iField), dyFont_Hdr, PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP);
+				}
+
+				yPos		-= dyPos_Hdr;
+				bAddHeader	= false;
+			}
+
+			//---------------------------------------------
+			pRecord	= pTable->Get_Record(iRecord);
+
+			for(iField=0, xPos=r.Get_XMin(); iField<pTable->Get_Field_Count(); iField++, xPos+=dxPos)
+			{
+				Draw_Rectangle(xPos, yPos, xPos + dxPos, yPos - dyPos, PDF_STYLE_POLYGON_STROKE, SG_COLOR_WHITE, SG_COLOR_BLACK, 0);
+				Draw_Text(xPos + xSpace, yPos - ySpace, pRecord->asString(iField), dyFont, PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Table(const CSG_Rect &r, CSG_Table *pTable, double CellHeight, double HeaderHeightRel)
+{
+	if( pTable && pTable->is_Valid() )
+	{
+		return( _Draw_Table(r, pTable, 0, pTable->Get_Record_Count(), CellHeight, HeaderHeightRel) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Table(const CSG_Rect &r, CSG_Table *pTable, int nColumns, double CellHeight, double HeaderHeightRel)
+{
+	if( pTable && pTable->is_Valid() && nColumns > 1 )
+	{
+		int			nRecords;
+		double		dx, dxSpace;
+		CSG_Rect	rColumn(r), rTable(r);
+
+		dxSpace		= 4;
+		rTable.Inflate(dxSpace, 0.0, false);
+		dx			= rTable.Get_XRange() / (double)nColumns;
+		nRecords	= pTable->Get_Record_Count() / nColumns;
+
+		for(int i=0, iRecord=0; i<nColumns; i++, iRecord+=nRecords)
+		{
+			rColumn.m_rect.xMin	= rTable.Get_XMin() + (i + 0) * dx + dxSpace;
+			rColumn.m_rect.xMax	= rTable.Get_XMin() + (i + 1) * dx - dxSpace;
+
+			_Draw_Table(rColumn, pTable, iRecord, nRecords, CellHeight, HeaderHeightRel);
+		}
+
+		return( true );
+	}
+
+	return( Draw_Table(r, pTable, CellHeight, HeaderHeightRel) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::_Draw_Shape(CSG_Rect r, CSG_Shape *pShape, double xMin, double yMin, double World2PDF, int Style, int Fill_Color, int Line_Color, int Line_Width, int Point_Width)
+{
+	if( pShape && pShape->is_Valid() )
+	{
+		int			iPart, iPoint;
+		TSG_Point	Point;
+		CSG_Points	Points;
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			Points.Clear();
+
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				Point	= pShape->Get_Point(iPoint, iPart);
+				Point.x	= r.Get_XMin() + World2PDF * (Point.x - xMin);
+				Point.y	= r.Get_YMin() + World2PDF * (Point.y - yMin);
+				Points.Add(Point.x, Point.y);
+			}
+
+			switch( pShape->Get_Type() )
+			{
+			case SHAPE_TYPE_Point:
+			case SHAPE_TYPE_Points:
+				for(iPoint=0; iPoint<Points.Get_Count(); iPoint++)
+				{
+					Draw_Point(Points[iPoint].x, Points[iPoint].y, Point_Width, Style, Fill_Color, Line_Color, Line_Width);
+				}
+				break;
+
+			case SHAPE_TYPE_Line:
+				Draw_Line(Points, Line_Width, Line_Color, Style);
+				break;
+
+			case SHAPE_TYPE_Polygon:
+				if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
+				{
+					Draw_Polygon(Points, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_WHITE, Line_Color, Line_Width);
+				}
+				else
+				{
+					Draw_Polygon(Points, Style, Fill_Color, Line_Color, Line_Width);
+				}
+				break;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Shape(const CSG_Rect &r, CSG_Shape *pShape, int Style, int Fill_Color, int Line_Color, int Line_Width, CSG_Rect *prWorld)
+{
+	double		World2PDF;
+	CSG_Rect	rWorld, rFit;
+
+	if( pShape && pShape->is_Valid() && r.Get_XRange() > 0.0 && r.Get_YRange() > 0.0 )
+	{
+		rWorld	= prWorld ? *prWorld : pShape->Get_Extent();
+
+		if( rWorld.Get_XRange() > 0.0 && rWorld.Get_YRange() > 0.0 )
+		{
+			_Fit_Rectangle(rFit = r, rWorld.Get_XRange() / rWorld.Get_YRange(), true);
+
+			World2PDF	= rFit.Get_XRange() / rWorld.Get_XRange();
+
+			_Draw_Shape(rFit, pShape, rWorld.Get_XMin(), rWorld.Get_YMin(), World2PDF, Style, Fill_Color, Line_Color, Line_Width, Line_Width);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Shapes(const CSG_Rect &r, CSG_Shapes *pShapes, int Style, int Fill_Color, int Line_Color, int Line_Width, CSG_Rect *prWorld)
+{
+	double		World2PDF;
+	CSG_Rect	rWorld, rFit;
+
+	if( pShapes && pShapes->is_Valid() && r.Get_XRange() > 0.0 && r.Get_YRange() > 0.0 )
+	{
+		rWorld	= prWorld ? *prWorld : pShapes->Get_Extent();
+
+		if( rWorld.Get_XRange() > 0.0 && rWorld.Get_YRange() > 0.0 )
+		{
+			_Fit_Rectangle(rFit = r, rWorld.Get_XRange() / rWorld.Get_YRange(), true);
+
+			World2PDF	= rFit.Get_XRange() / rWorld.Get_XRange();
+
+			for(int iShape=0; iShape<pShapes->Get_Count(); iShape++)
+			{
+				_Draw_Shape(rFit, pShapes->Get_Shape(iShape), rWorld.Get_XMin(), rWorld.Get_YMin(), World2PDF, Style, Fill_Color, Line_Color, Line_Width, Line_Width);
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Doc_PDF::Draw_Grid(const CSG_Rect &r, CSG_Grid *pGrid, const CSG_Colors &Colors, double zMin, double zMax, int Style, CSG_Rect *prWorld)
+{
+	double		x, y, z, d, xFit, yFit, dFit;
+	CSG_Rect	rWorld, rFit;
+
+	if( Is_Ready_To_Draw() && pGrid && pGrid->is_Valid() && pGrid->Get_ZRange() > 0.0 )
+	{
+		rWorld	= prWorld ? *prWorld : pGrid->Get_Extent();
+
+		if( rWorld.Get_XRange() > 0.0 && rWorld.Get_YRange() > 0.0 )
+		{
+			_Fit_Rectangle(rFit = r, rWorld.Get_XRange() / rWorld.Get_YRange(), true);
+
+			dFit	= 1.0;
+			d		= dFit * (rWorld.Get_XRange() / rFit.Get_XRange());
+
+			if( zMin >= zMax )
+			{
+				zMin	= pGrid->Get_ZMin();
+				zMax	= pGrid->Get_ZMax();
+			}
+
+			zMax	= Colors.Get_Count() / (zMax - zMin);
+
+			for(y=rWorld.Get_YMin(), yFit=rFit.Get_YMin(); yFit<rFit.Get_YMax() && y<pGrid->Get_Extent().Get_YMax(); y++, yFit+=dFit, y+=d)
+			{
+				for(x=rWorld.Get_XMin(), xFit=rFit.Get_XMin(); xFit<rFit.Get_XMax() && x<pGrid->Get_Extent().Get_XMax(); x++, xFit+=dFit, x+=d)
+				{
+					if( pGrid->Get_Value(x, y, z) )
+					{
+						Draw_Point(xFit, yFit, dFit, PDF_STYLE_POINT_SQUARE|PDF_STYLE_POLYGON_FILL, Colors.Get_Color((int)(zMax * (z - zMin))));
+					}
+				}
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Doc_PDF::Draw_Curve(CSG_Points &Data, const CSG_Rect &r, int iGraphType)
+{
+/*
+	int i;
+    int iMag;
+	int iNumLines;
+	int iNumData;
+    float fMinLine = 0;
+	float fWidth;
+	float fMax, fMin;
+	float fStep;
+    float fX, fY;
+	float fMaxX, fMinX;
+	float fOffsetX;
+	CSG_String sValue;
+	CSG_Points Points;
+
+	fMin = fMax = Data[0].y;
+
+	for (i = 0; i < Data.Get_Count(); i++)
+	{
+		if (Data[i].y > fMax)
+		{
+			fMax = Data[i].y;
+		}
+		if (Data[i].y < fMin)
+		{
+			fMin = Data[i].y;
+		}
+		if (iGraphType == PDF_GRAPH_TYPE_BARS){
+			fMin = M_GET_MIN(0, fMin);
+		}
+    }
+
+	if (fMin != fMax){
+		iMag = (int) (log(fMax - fMin) / log(10.0));
+		fStep = (float) ((int) pow(10.0, (double) iMag));
+		if (fStep == 0)
+		{
+			fStep = 1.;
+		}
+		if (fMin < 0) 
+		{
+			iMag = (int) (log(fabs(fMin)) / log(10.0));
+			fMinLine = -(int) pow(10.0, (double) iMag);
+		}
+		else 
+		{
+			fMinLine=(int)(((int)(fMin/fStep)) *fStep);
+		}
+
+		iNumLines = (int) ((fMax - fMin) / fStep);
+
+		while (iNumLines < 8) 
+		{
+			fStep = fStep / 2.0;
+			iNumLines = (int) ((fMax - fMin) / fStep);
+		}
+		iNumLines = (int) ((fMax - fMinLine) / fStep);
+	}
+	else{
+		if (fMin > 0)
+		{
+			fStep = fMin = 0;
+			iNumLines = 1;
+			fMinLine = fMax;
+		}
+		else if (fMin < 0)
+		{
+			fStep = 0;
+			fMin = fMin - 1;
+			fMinLine = fMax;
+		}
+		else
+		{
+			return;
+		}		
+	}
+
+	for (i = 0; i < iNumLines; i++) 
+	{
+        fY = r.Get_YMax() - ((fMinLine + fStep * i - fMin) / (fMax - fMin)) * r.Get_YRange();
+        if (fY <= r.Get_YMax() && fY >= r.Get_YMin()) 
+		{
+			fY = HPDF_Page_Height() - fY;
+        }
+    }
+
+	if (iGraphType == PDF_GRAPH_TYPE_BARS)
+	{
+		fWidth = (float) r.Get_XRange() / (float) (Data.Get_Count());
+	    for (i = 0; i < Data.Get_Count(); i++)
+		{
+	        fX = r.Get_XMin() + i * fWidth;
+			fY = r.Get_YMax();
+			fY = HPDF_Page_Height() - fY;
+			Draw_Rectangle(fX, fY, fX + fWidth,
+					fY - r.Get_YRange() * ((Data[i].y - fMin) / (fMax - fMin)),
+					PDF_STYLE_POLYGON_FILLSTROKE, 0x660000);
+	    }
+	}
+	else
+	{
+		fWidth = (float) r.Get_XRange() / (float) (Data.Get_Count() - 1);
+		fY = r.Get_YMin() + r.Get_YRange()
+				- r.Get_YRange() * ((Data[0].y - fMin) / (fMax - fMin));
+		fY = HPDF_Page_Height() - fY;
+		Points.Add(r.Get_XMin(), fY);
+		for (i = 1; i < Data.Get_Count(); i++)
+		{
+			fY = r.Get_YMin() + r.Get_YRange()
+					- r.Get_YRange() * ((Data[i].y - fMin) / (fMax - fMin));
+			fY = HPDF_Page_Height() - fY;
+			Points.Add(r.Get_XMin() + i * fWidth, fY);
+	    }
+		Draw_Line(Points, 3, 0x660000);
+	}
+
+    fMaxX = Data[Data.Get_Count() - 1].x;
+    fMinX = Data[0].x;
+
+	if (fMaxX != fMinX)
+	{
+		iMag = (int) (log(fMaxX - fMinX) / log(10.0));
+		fStep = (float) pow(10.0, (double) iMag);
+
+		iNumData = (int) ((fMaxX-fMinX) / fStep);
+
+		while (iNumData < 3)
+		{
+			fStep = fStep / 2.0;
+			iNumData = (int) ((fMaxX-fMinX) / fStep);
+		}
+		fMinLine = (int)(((int)(fMinX/fStep)) * fStep);
+		while (fMinLine<fMinX)
+		{
+			fMinLine+=fStep;
+		}
+		fOffsetX = fMinX-fMinLine;
+
+		fY = HPDF_Page_Height() - r.Get_YMin() - r.Get_YRange();
+		for (i = 0; i < iNumData; i++)
+		{
+			fX = r.Get_XMin() + ((fStep * (float) i-fOffsetX) / (fMaxX-fMinX)) * r.Get_XRange();
+			if (fX >= r.Get_XMin() && fX < r.Get_XMin() + r.Get_XRange()){
+				if (fabs(fStep * (float)i +fMinLine) > 100000)
+				{
+					sValue = SG_Get_String(fStep * (float)i +fMinLine);
+				}
+				else
+				{
+					sValue = SG_Get_String(fStep * (float)i + fMinLine, 2, true);
+				}
+				Draw_Text(fX, fY, sValue, 9, PDF_STYLE_TEXT_ALIGN_H_RIGHT);
+				Draw_Line(fX, fY, fX, fY - 10, 1);
+			}
+		}
+    }
+
+	Draw_Line(r.Get_XMin(), HPDF_Page_Height() - r.Get_YMin(),
+			r.Get_XMin(), HPDF_Page_Height() - r.Get_YMax(), 4);
+	Draw_Line(r.Get_XMin(), HPDF_Page_Height() - r.Get_YMax(),
+			r.Get_XMax(), HPDF_Page_Height() - r.Get_YMax(), 4);
+*/
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#else // #ifndef _SAGA_DONOTUSE_HARU
+
+#include "doc_pdf.h"
+
+//---------------------------------------------------------
+const SG_Char * CSG_Doc_PDF::Get_Version(void)											{	return( NULL );	}
+CSG_Doc_PDF::CSG_Doc_PDF(void)															{	m_pPDF	= NULL;	}
+CSG_Doc_PDF::CSG_Doc_PDF(TSG_PDF_Page_Size Size, int Orientation, const SG_Char *Title)	{	m_pPDF	= NULL;	}
+CSG_Doc_PDF::~CSG_Doc_PDF(void)															{}
+void CSG_Doc_PDF::Layout_Set_Box_Space(double Space, bool bPercent)						{}
+void CSG_Doc_PDF::_Layout_Set_Boxes(void)												{}
+void CSG_Doc_PDF::_Layout_Set_Box(int iBox)												{}
+double CSG_Doc_PDF::Get_Page_To_Meter(void)												{	return( 1.0 );	}
+struct _HPDF_Dict_Rec * CSG_Doc_PDF::_Get_Font(TSG_PDF_Font_Type Font)					{	return( NULL );	}
+const CSG_Rect & CSG_Doc_PDF::Layout_Get_Box(const SG_Char *ID)							{	return( m_Size_Margins );	}
+TSG_PDF_Title_Level CSG_Doc_PDF::_Get_Lowest_Outline_Level(void)						{	return( PDF_TITLE_NONE );	}
+bool CSG_Doc_PDF::Open(const SG_Char *Title)											{	return( false );	}
+bool CSG_Doc_PDF::Open(TSG_PDF_Page_Size Size, int Orientation, const SG_Char *Title)	{	return( false );	}
+bool CSG_Doc_PDF::Close(void)															{	return( false );	}
+bool CSG_Doc_PDF::Save(const SG_Char *FileName)											{	return( false );	}
+bool CSG_Doc_PDF::Layout_Add_Box(double xMin_Percent, double yMin_Percent, double xMax_Percent, double yMax_Percent, const SG_Char *ID)	{	return( false );	}
+bool CSG_Doc_PDF::Layout_Add_Box(const CSG_Rect &Box_Percent, const SG_Char *ID)														{	return( false );	}
+bool CSG_Doc_PDF::_Fit_Rectangle(double &x, double &y, double &dx, double &dy, double XToY_Ratio, bool bShrink)							{	return( false );	}
+bool CSG_Doc_PDF::_Fit_Rectangle(CSG_Rect &r, double XToY_Ratio, bool bShrink)															{	return( false );	}
+bool CSG_Doc_PDF::_Add_Outline_Item(const SG_Char *Title, struct _HPDF_Dict_Rec *pPage, TSG_PDF_Title_Level Level)						{	return( false );	}
+bool CSG_Doc_PDF::Add_Outline_Item(const SG_Char *Title)																				{	return( false );	}
+bool CSG_Doc_PDF::Add_Page(void)																																						{	return( false );	}
+bool CSG_Doc_PDF::Add_Page(TSG_PDF_Page_Size Size, int Orientation)																														{	return( false );	}
+bool CSG_Doc_PDF::Add_Page(double Width, double Height)																																{	return( false );	}
+bool CSG_Doc_PDF::Set_Size_Page(TSG_PDF_Page_Size Size, int Orientation)																													{	return( false );	}
+bool CSG_Doc_PDF::Set_Size_Page(double Width, double Height)																															{	return( false );	}
+bool CSG_Doc_PDF::Add_Page_Title(const SG_Char *Title, TSG_PDF_Title_Level Level, TSG_PDF_Page_Size Size, int Orientation)																		{	return( false );	}
+bool CSG_Doc_PDF::_Set_Style_FillStroke(int Style, int Fill_Color, int Line_Color, int Line_Width)																					{	return( false );	}
+bool CSG_Doc_PDF::Draw_Point(double x, double y, double Width, int Style, int Fill_Color, int Line_Color, int Line_Width)																{	return( false );	}
+bool CSG_Doc_PDF::Draw_Line(double xa, double ya, double xb, double yb, int Width, int Color, int Style)																				{	return( false );	}
+bool CSG_Doc_PDF::Draw_Line(CSG_Points &Points, int Width, int Color, int Style)																									{	return( false );	}
+bool CSG_Doc_PDF::Draw_Rectangle(double xa, double ya, double xb, double yb, int Style, int Fill_Color, int Line_Color, int Line_Width)												{	return( false );	}
+bool CSG_Doc_PDF::Draw_Rectangle(const CSG_Rect &r, int Style, int Fill_Color, int Line_Color, int Line_Width)																		{	return( false );	}
+bool CSG_Doc_PDF::Draw_Polygon(CSG_Points &Points, int Style, int Fill_Color, int Line_Color, int Line_Width)																		{	return( false );	}
+bool CSG_Doc_PDF::Draw_Text(double x, double y, CSG_Strings &Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)												{	return( false );	}
+bool CSG_Doc_PDF::Draw_Text(double x, double y, const SG_Char *Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)													{	return( false );	}
+bool CSG_Doc_PDF::_Draw_Text(double x, double y, const SG_Char *Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font)													{	return( false );	}
+bool CSG_Doc_PDF::Draw_Image(double x, double y, double dx, double dy, const SG_Char *FileName)																							{	return( false );	}
+bool CSG_Doc_PDF::Draw_Image(const CSG_Rect &r, const SG_Char *FileName)																												{	return( false );	}
+bool CSG_Doc_PDF::Draw_Graticule(const CSG_Rect &r, const CSG_Rect &rWorld, int Size)																								{	return( false );	}
+bool CSG_Doc_PDF::_Draw_Ruler(const CSG_Rect &r, double zMin, double zMax, bool bHorizontal, bool bAscendent, bool bTickAtTop)														{	return( false );	}
+bool CSG_Doc_PDF::_Draw_Table(CSG_Rect r, CSG_Table *pTable, int iRecord, int nRecords, double CellHeight, double HeaderHeightRel)														{	return( false );	}
+bool CSG_Doc_PDF::Draw_Table(const CSG_Rect &r, CSG_Table *pTable, double CellHeight, double HeaderHeightRel)																			{	return( false );	}
+bool CSG_Doc_PDF::Draw_Table(const CSG_Rect &r, CSG_Table *pTable, int nColumns, double CellHeight, double HeaderHeightRel)																{	return( false );	}
+bool CSG_Doc_PDF::_Draw_Shape(CSG_Rect r, CSG_Shape *pShape, double xMin, double yMin, double World2PDF, int Style, int Fill_Color, int Line_Color, int Line_Width, int Point_Width)	{	return( false );	}
+bool CSG_Doc_PDF::Draw_Shape(const CSG_Rect &r, CSG_Shape *pShape, int Style, int Fill_Color, int Line_Color, int Line_Width, CSG_Rect *prWorld)										{	return( false );	}
+bool CSG_Doc_PDF::Draw_Shapes(const CSG_Rect &r, CSG_Shapes *pShapes, int Style, int Fill_Color, int Line_Color, int Line_Width, CSG_Rect *prWorld)									{	return( false );	}
+bool CSG_Doc_PDF::Draw_Grid(const CSG_Rect &r, CSG_Grid *pGrid, const CSG_Colors &Colors, double zMin, double zMax, int Style, CSG_Rect *prWorld)											{	return( false );	}
+void CSG_Doc_PDF::Draw_Curve(CSG_Points &Data, const CSG_Rect &r, int iGraphType)	{}
+
+#endif	// #else // #ifndef _SAGA_DONOTUSE_HARU
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _SAGA_UNICODE
+
+bool CSG_Doc_PDF::Layout_Add_Box(double xMin_Percent, double yMin_Percent, double xMax_Percent, double yMax_Percent, const char *ID)
+{	return( Layout_Add_Box(xMin_Percent, yMin_Percent, xMax_Percent, yMax_Percent, SG_STR_MBTOSG(ID)) );	}
+
+bool CSG_Doc_PDF::Layout_Add_Box(const CSG_Rect &Box_Percent, const char *ID)
+{	return( Layout_Add_Box(Box_Percent, SG_STR_MBTOSG(ID)) );	}
+
+const CSG_Rect & CSG_Doc_PDF::Layout_Get_Box(const char *ID)
+{	return( Layout_Get_Box(SG_STR_MBTOSG(ID)) );	}
+
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_pdf.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,299 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      doc_pdf.h                        //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//              Victor Olaya, Olaf Conrad                //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__doc_pdf_H
+#define HEADER_INCLUDED__SAGA_API__doc_pdf_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define PDF_TABLE_CELL_HEIGHT_DEFAULT		20.0
+#define PDF_TABLE_HEADER_HEIGHT				40.0
+
+//---------------------------------------------------------
+#define PDF_PAGE_ORIENTATION_PREVIOUS		-1
+#define PDF_PAGE_ORIENTATION_PORTRAIT		0
+#define PDF_PAGE_ORIENTATION_LANDSCAPE		1
+
+//---------------------------------------------------------
+#define PDF_STYLE_POINT_CIRCLE				0x00000001
+#define PDF_STYLE_POINT_SQUARE				0x00000002
+
+#define PDF_STYLE_LINE_END_BUTT				0x00000004
+#define PDF_STYLE_LINE_END_ROUND			0x00000008
+#define PDF_STYLE_LINE_END_SQUARE			0x00000010
+#define PDF_STYLE_LINE_JOIN_MITER			0x00000020
+#define PDF_STYLE_LINE_JOIN_ROUND			0x00000040
+#define PDF_STYLE_LINE_JOIN_BEVEL			0x00000080
+
+#define PDF_STYLE_POLYGON_STROKE			0x00000100
+#define PDF_STYLE_POLYGON_FILL				0x00000200
+#define PDF_STYLE_POLYGON_FILLSTROKE		(PDF_STYLE_POLYGON_STROKE|PDF_STYLE_POLYGON_FILL)
+
+//---------------------------------------------------------
+#define PDF_STYLE_TEXT_ALIGN_H_LEFT			0x00000001
+#define PDF_STYLE_TEXT_ALIGN_H_CENTER		0x00000002
+#define PDF_STYLE_TEXT_ALIGN_H_RIGHT		0x00000004
+
+#define PDF_STYLE_TEXT_ALIGN_V_TOP			0x00000008
+#define PDF_STYLE_TEXT_ALIGN_V_CENTER		0x00000010
+#define PDF_STYLE_TEXT_ALIGN_V_BOTTOM		0x00000020
+
+#define PDF_STYLE_TEXT_UNDERLINE			0x00000040
+#define PDF_STYLE_TEXT_STROKE				0x00000080
+
+//----------------------------------------------------------
+#define PDF_GRAPH_TYPE_BARS					1
+#define PDF_GRAPH_TYPE_LINES				2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_PDF_Font_Type
+{
+	PDF_FONT_DEFAULT	= 0,
+	PDF_FONT_Helvetica	= 0,
+	PDF_FONT_Helvetica_Bold,
+	PDF_FONT_Helvetica_Oblique,
+	PDF_FONT_Helvetica_BoldOblique,
+	PDF_FONT_Times_Roman,
+	PDF_FONT_Times_Bold,
+	PDF_FONT_Times_Italic,
+	PDF_FONT_Times_BoldItalic,
+	PDF_FONT_Courier,
+	PDF_FONT_Courier_Bold,
+	PDF_FONT_Courier_Oblique,
+	PDF_FONT_Courier_BoldOblique,
+	PDF_FONT_Symbol,
+	PDF_FONT_ZapfDingbats
+}
+TSG_PDF_Font_Type;
+
+//---------------------------------------------------------
+typedef enum ESG_PDF_Page_Size
+{
+	PDF_PAGE_SIZE_A4		= 1,
+	PDF_PAGE_SIZE_A3,
+	PDF_PAGE_SIZE_PREVIOUS
+}
+TSG_PDF_Page_Size;
+
+//---------------------------------------------------------
+typedef enum ESG_PDF_Title_Level
+{
+	PDF_TITLE	= 0,
+	PDF_TITLE_01,
+	PDF_TITLE_02,
+	PDF_TITLE_NONE
+}
+TSG_PDF_Title_Level;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Doc_PDF
+{
+public:
+	CSG_Doc_PDF(void);
+	CSG_Doc_PDF(TSG_PDF_Page_Size Size, int Orientation = PDF_PAGE_ORIENTATION_PORTRAIT, const SG_Char *Title = NULL);
+	virtual ~CSG_Doc_PDF(void);
+
+	static const SG_Char *		Get_Version					(void);
+
+	bool						Open						(TSG_PDF_Page_Size Size = PDF_PAGE_SIZE_A4, int Orientation = PDF_PAGE_ORIENTATION_PORTRAIT, const SG_Char *Title = NULL);
+	bool						Open						(const SG_Char *Title);
+	bool						Close						(void);
+
+	bool						Save						(const SG_Char *FileName);
+
+	bool						Is_Open						(void)	{	return( m_pPDF != NULL );	}
+	bool						Is_Ready_To_Draw			(void)	{	return( m_pPDF != NULL );	}
+
+	static double				Get_Page_To_Meter			(void);
+
+	bool						Add_Page					(void);
+	bool						Add_Page					(TSG_PDF_Page_Size Size, int Orientation = PDF_PAGE_ORIENTATION_PORTRAIT);
+	bool						Add_Page					(double Width, double Height);
+
+	bool						Add_Page_Title				(const SG_Char *Title, TSG_PDF_Title_Level Level = PDF_TITLE, TSG_PDF_Page_Size Size = PDF_PAGE_SIZE_PREVIOUS, int Orientation = PDF_PAGE_ORIENTATION_PREVIOUS);
+	bool						Add_Outline_Item			(const SG_Char *Title);
+
+	bool						Set_Size_Page				(TSG_PDF_Page_Size Size, int Orientation = PDF_PAGE_ORIENTATION_PORTRAIT);
+	bool						Set_Size_Page				(double Width, double Height);
+	const CSG_Rect &			Get_Size_Page				(void)	{	return( m_Size_Paper );		}
+	const CSG_Rect &			Get_Margins					(void)	{	return( m_Size_Margins );	}
+
+	void						Layout_Set_Box_Space		(double Space, bool bPercent);
+	bool						Layout_Add_Box				(double xMin_Percent, double yMin_Percent, double xMax_Percent, double yMax_Percent, const SG_Char *ID = NULL);
+	bool						Layout_Add_Box				(const CSG_Rect &Box_Percent, const SG_Char *ID = NULL);
+	const CSG_Rect &			Layout_Get_Box				(int iBox)	{	return( iBox >= 0 && iBox < m_Boxes.Get_Count() ? m_Boxes[iBox] : m_Size_Margins );	}
+	const CSG_Rect &			Layout_Get_Box				(const SG_Char *ID);
+#ifdef _SAGA_UNICODE
+	bool						Layout_Add_Box				(double xMin_Percent, double yMin_Percent, double xMax_Percent, double yMax_Percent, const char *ID);
+	bool						Layout_Add_Box				(const CSG_Rect &Box_Percent, const char *ID);
+	const CSG_Rect &			Layout_Get_Box				(const char *ID);
+#endif
+
+	bool						Draw_Point					(double x, double y, double Width, int Style = PDF_STYLE_POINT_SQUARE|PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_WHITE, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0);
+	bool						Draw_Line					(double xa, double ya, double xb, double yb	, int Width = 0, int Color = SG_COLOR_BLACK, int Style = 0);
+	bool						Draw_Line					(CSG_Points &Points							, int Width = 0, int Color = SG_COLOR_BLACK, int Style = 0);
+	bool						Draw_Rectangle				(double xa, double ya, double xb, double yb	, int Style = PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_WHITE, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0);
+	bool						Draw_Rectangle				(const CSG_Rect &r							, int Style = PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_WHITE, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0);
+	bool						Draw_Polygon				(CSG_Points &Points							, int Style = PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_GREEN, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0);
+	bool						Draw_Text					(double x, double y, const SG_Char   *Text, int Size, int Style = PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP, double Angle = 0.0, int Color = SG_COLOR_BLACK, TSG_PDF_Font_Type Font = PDF_FONT_DEFAULT);
+	bool						Draw_Text					(double x, double y, CSG_Strings  &Text, int Size, int Style = PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP, double Angle = 0.0, int Color = SG_COLOR_BLACK, TSG_PDF_Font_Type Font = PDF_FONT_DEFAULT);
+	bool						Draw_Image					(double x, double y, double dx, double dy	, const SG_Char *FileName);
+	bool						Draw_Image					(const CSG_Rect &r							, const SG_Char *FileName);
+
+	bool						Draw_Graticule				(const CSG_Rect &r, const CSG_Rect &rWorld, int Size = 10);
+	void						Draw_Curve					(CSG_Points &Data, const CSG_Rect &r, int iGraphType);
+
+	bool						Draw_Table					(const CSG_Rect &r, CSG_Table *pTable					, double CellHeight = 0.0, double HeaderHeightRel = 1.5);
+	bool						Draw_Table					(const CSG_Rect &r, CSG_Table *pTable, int nColumns	, double CellHeight = 0.0, double HeaderHeightRel = 1.5);
+
+	bool						Draw_Shape					(const CSG_Rect &r, CSG_Shape  *pShape , int Style = PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_GREEN, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0, CSG_Rect *prWorld = NULL);
+	bool						Draw_Shapes					(const CSG_Rect &r, CSG_Shapes *pShapes, int Style = PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_GREEN, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0, CSG_Rect *prWorld = NULL);
+
+	bool						Draw_Grid					(const CSG_Rect &r, CSG_Grid *pGrid, const CSG_Colors &Colors, double zMin = 0.0, double zMax = 0.0, int Style = 0, CSG_Rect *prWorld = NULL);
+
+
+protected:
+
+	bool						_Fit_Rectangle				(double &x, double &y, double &dx, double &dy, double XToY_Ratio, bool bShrink);
+	bool						_Fit_Rectangle				(CSG_Rect &r, double XToY_Ratio, bool bShrink);
+
+	bool						_Add_Outline_Item			(const SG_Char *Title, struct _HPDF_Dict_Rec *pPage, TSG_PDF_Title_Level Level = PDF_TITLE);
+
+	bool						_Draw_Ruler					(const CSG_Rect &r, double zMin, double zMax, bool bHorizontal, bool bAscendent, bool bTickAtTop);
+	bool						_Draw_Text					(double x, double y, const SG_Char *Text, int Size, int Style, double Angle, int Color, TSG_PDF_Font_Type Font);
+	bool						_Draw_Table					(CSG_Rect r, CSG_Table *pTable, int iRecord, int nRecords, double CellHeight, double HeaderHeightRel);
+	bool						_Draw_Shape					(CSG_Rect r, CSG_Shape *pShape, double xMin, double yMin, double World2PDF, int Style = PDF_STYLE_POLYGON_FILLSTROKE, int Fill_Color = SG_COLOR_GREEN, int Line_Color = SG_COLOR_BLACK, int Line_Width = 0, int Point_Width = 5);
+
+	TSG_PDF_Title_Level			_Get_Lowest_Outline_Level	(void);
+
+
+private:
+
+	bool						m_Boxes_Space_bPercent;
+
+	int							m_nPages;
+
+	double						m_Boxes_Space;
+
+	CSG_Rect					m_Size_Paper, m_Size_Margins;
+
+	CSG_Rects					m_Boxes_Percent, m_Boxes;
+
+	CSG_Strings					m_Boxes_ID;
+
+	struct _HPDF_Doc_Rec		*m_pPDF;
+
+	struct _HPDF_Dict_Rec		*m_pPage;
+
+	struct _HPDF_Dict_Rec		*m_pOutline_Last_Level_0, *m_pOutline_Last_Level_1, *m_pOutline_Last_Level_2;
+
+
+	struct _HPDF_Dict_Rec *		_Get_Font					(TSG_PDF_Font_Type Font);
+
+	void						_Layout_Set_Boxes			(void);
+	void						_Layout_Set_Box				(int iBox);
+
+	bool						_Set_Style_FillStroke		(int Style, int Fill_Color, int Line_Color, int Line_Width);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__doc_pdf_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,398 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     doc_svg.cpp                       //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                      Victor Olaya                     //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "doc_svg.h"
+#include <time.h>
+
+//---------------------------------------------------------
+#define SVG_CODE_OPENING_1	SG_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n")\
+							SG_T("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" ")\
+							SG_T("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n")\
+							SG_T("<svg version=\"1.1\" width=\"")
+
+#define SVG_CODE_OPENING_2	SG_T("\"\n xmlns=\"http://www.w3.org/2000/svg\">\n")
+
+#define SVG_CODE_CLOSING	SG_T("</svg>")
+
+//---------------------------------------------------------
+const SG_Char *g_Unit	= SG_T("");
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Doc_SVG::CSG_Doc_SVG(){}
+
+CSG_Doc_SVG::~CSG_Doc_SVG(){}
+
+void CSG_Doc_SVG::Open(int iWidth, int iHeight)
+{
+
+	m_sSVGCode.Append(SVG_CODE_OPENING_1);
+	m_sSVGCode.Append(SG_Get_String(iWidth,0));
+	m_sSVGCode.Append(SG_T("\" height=\""));
+	m_sSVGCode.Append(SG_Get_String(iHeight,0));
+	m_sSVGCode.Append(SVG_CODE_OPENING_2);
+
+	m_iWidth = iWidth;
+	m_iHeight = iHeight;
+
+}
+
+bool CSG_Doc_SVG::Save(const SG_Char *Filename)
+{
+
+	m_sSVGCode.Append(SVG_CODE_CLOSING);
+
+	CSG_File	Stream(Filename, SG_FILE_W, false);
+
+	if( Stream.is_Open() )
+	{
+		Stream.Printf(SG_T("%s"), m_sSVGCode.c_str());
+		return true;
+	}
+	
+	return false;
+
+}
+
+void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, 
+							   const SG_Char *Value)
+{
+
+		m_sSVGCode.Append(Attribute);
+		m_sSVGCode.Append(SG_T("=\""));
+		m_sSVGCode.Append(Value);
+		m_sSVGCode.Append(SG_T("\" "));		
+
+}
+
+void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, 
+							   int iValue)
+{
+
+	_AddAttribute(Attribute, SG_Get_String(iValue, 0));
+}
+
+void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, 
+							   double dValue)
+{
+
+	_AddAttribute(Attribute, SG_Get_String(dValue, 2));
+
+}
+
+void CSG_Doc_SVG::Draw_Circle(double x, 
+							 double y, 
+							 double Radius, 
+							 int Fill_Color, 
+							 int Line_Color, 
+							 double Line_Width)
+{
+	
+	CSG_String sWidth;
+
+	m_sSVGCode.Append(SG_T("<circle "));
+	_AddAttribute(SG_T("cx"), x);
+	_AddAttribute(SG_T("cy"), y);
+	_AddAttribute(SG_T("r"), Radius);
+	sWidth.Append(SG_Get_String(Line_Width,2));
+	sWidth.Append(g_Unit);
+	_AddAttribute(SG_T("stroke-width"), sWidth);
+	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
+	_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
+	m_sSVGCode.Append(SG_T("/>\n"));
+
+}
+
+void CSG_Doc_SVG::Draw_LinkedCircle(double x, 
+								 double y, 
+								 double Radius, 
+								 const SG_Char *Link,
+								 int Fill_Color, 
+								 int Line_Color, 
+								 double Line_Width)
+{
+	
+	CSG_String sWidth;
+	CSG_String sLink;
+
+	m_sSVGCode.Append(SG_T("<circle "));
+	_AddAttribute(SG_T("cx"), x);
+	_AddAttribute(SG_T("cy"), y);
+	_AddAttribute(SG_T("r"), Radius);
+	sWidth.Append(SG_Get_String(Line_Width,2));
+	sWidth.Append(g_Unit);
+	_AddAttribute(SG_T("stroke-width"), sWidth);
+	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
+	_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
+	sLink = SG_T("window.open('");
+	sLink.Append(Link);
+	sLink.Append(SG_T("')"));
+	_AddAttribute(SG_T("onclick"), sLink);
+	m_sSVGCode.Append(SG_T("/>\n"));
+
+}
+
+void CSG_Doc_SVG::Draw_Line(double xa, 
+						   double ya, 
+						   double xb, 
+						   double yb, 
+						   double Width, 
+						   int Color)
+{
+
+	CSG_String sWidth;
+
+	m_sSVGCode.Append(SG_T("<line "));
+	_AddAttribute(SG_T("x1"), xa);
+	_AddAttribute(SG_T("x2"), xb);
+	_AddAttribute(SG_T("y1"), ya);
+	_AddAttribute(SG_T("y2"), yb);
+	sWidth.Append(SG_Get_String(Width,2));
+	sWidth.Append(g_Unit);
+	_AddAttribute(SG_T("stroke-width"), sWidth);	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Color));
+	m_sSVGCode.Append(SG_T("/>\n"));
+
+}
+
+void CSG_Doc_SVG::Draw_Line(CSG_Points &Points, 
+						   double Width, 
+						   int Color)
+{
+	int i;
+	CSG_String sPoints;
+	CSG_String sWidth;
+	
+	for (i = 0; i < Points.Get_Count(); i++)
+	{
+		sPoints.Append(SG_Get_String(Points.Get_X(i),2));
+		sPoints.Append(SG_T(","));
+		sPoints.Append(SG_Get_String(Points.Get_Y(i),2));
+		sPoints.Append(SG_T(" "));
+	}
+	m_sSVGCode.Append(SG_T("<polyline "));
+	_AddAttribute(SG_T("points"), sPoints);	
+	sWidth.Append(SG_Get_String(Width,2));
+	sWidth.Append(g_Unit);
+	_AddAttribute(SG_T("stroke-width"), sWidth);
+	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Color));
+	_AddAttribute(SG_T("fill"), SG_T("none"));
+	m_sSVGCode.Append(SG_T("/>\n"));
+
+}
+
+void CSG_Doc_SVG::Draw_Rectangle(double xa, 
+								double ya, 
+								double xb, 
+								double yb, 
+								int Fill_Color, 
+								int Line_Color, 
+								double Line_Width)
+{
+	CSG_Points	Points;
+
+	Points.Add(xa, ya);
+	Points.Add(xb, ya);
+	Points.Add(xb, yb);
+	Points.Add(xa, yb);
+
+	Draw_Polygon(Points, Fill_Color, Line_Color, Line_Width);
+}
+
+void CSG_Doc_SVG::Draw_Rectangle(const CSG_Rect &r, 
+								int Fill_Color, 
+								int Line_Color, 
+								double Line_Width)
+{
+	Draw_Rectangle(r.Get_XMin(), r.Get_YMin(), r.Get_XMax(), r.Get_YMax(), Fill_Color, Line_Color, Line_Width) ;
+}
+
+void CSG_Doc_SVG::Draw_Polygon(CSG_Points &Points, 
+							  int Fill_Color, 
+							  int Line_Color, 
+							  double Line_Width)
+{
+	if( Points.Get_Count() > 2 )
+	{
+		int i;
+		CSG_String sPoints;
+		CSG_String sWidth;
+		
+		for (i = 0; i < Points.Get_Count(); i++)
+		{
+			sPoints.Append(SG_Get_String(Points.Get_X(i),2));
+			sPoints.Append(SG_T(","));
+			sPoints.Append(SG_Get_String(Points.Get_Y(i),2));
+			sPoints.Append(SG_T(" "));
+		}
+		m_sSVGCode.Append(SG_T("<polygon "));
+		_AddAttribute(SG_T("points"), sPoints);
+		sWidth.Append(SG_Get_String(Line_Width,2));
+		sWidth.Append(g_Unit);
+		_AddAttribute(SG_T("stroke-width"), sWidth);				
+		_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
+		_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
+		m_sSVGCode.Append(SG_T("/>\n"));
+	}
+}
+
+void CSG_Doc_SVG::Draw_LinkedPolygon(CSG_Points &Points, 
+							  const SG_Char* Link,
+							  int Fill_Color, 
+							  int Line_Color, 
+							  double Line_Width)
+{
+	if( Points.Get_Count() > 2 )
+	{
+		int i;
+		CSG_String sPoints;
+		CSG_String sWidth;
+		CSG_String sLink;
+		
+		for (i = 0; i < Points.Get_Count(); i++)
+		{
+			sPoints.Append(SG_Get_String(Points.Get_X(i),2));
+			sPoints.Append(SG_T(","));
+			sPoints.Append(SG_Get_String(Points.Get_Y(i),2));
+			sPoints.Append(SG_T(" "));
+		}
+		m_sSVGCode.Append(SG_T("<polygon "));
+		_AddAttribute(SG_T("points"), sPoints);
+		sWidth.Append(SG_Get_String(Line_Width,2));
+		sWidth.Append(g_Unit);
+		_AddAttribute(SG_T("stroke-width"), sWidth);				
+		_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
+		_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
+		sLink = SG_T("window.open('");
+		sLink.Append(Link);
+		sLink.Append(SG_T("')"));
+		_AddAttribute(SG_T("onclick"), sLink);
+		m_sSVGCode.Append(SG_T("/>\n"));
+	}
+}
+
+void CSG_Doc_SVG::Draw_Text(double x, 
+						 double y, 
+						 const SG_Char *Text, 
+						 int Color, 
+						 const SG_Char* Font, 
+						 double dSize,
+						 TSG_SVG_Alignment iAlignment)
+{
+
+	CSG_String sAlignments[] = {SG_T(""), SG_T("middle"), SG_T("end")};
+	CSG_String sSize;
+	
+	sSize.Append(SG_Get_String(dSize,2));
+	sSize.Append(g_Unit);
+	
+	m_sSVGCode.Append(SG_T("<text "));
+	_AddAttribute(SG_T("x"), x);	
+	_AddAttribute(SG_T("y"), y);
+	_AddAttribute(SG_T("font-family"), Font);
+	_AddAttribute(SG_T("fill"), _Get_SVGColor(Color));
+	_AddAttribute(SG_T("font-size"), sSize);
+	_AddAttribute(SG_T("text-anchor"), sAlignments[iAlignment]);
+	m_sSVGCode.Append(SG_T(">\n"));
+	m_sSVGCode.Append(Text);
+	m_sSVGCode.Append(SG_T("</text>"));
+
+}
+
+CSG_String CSG_Doc_SVG::_Get_SVGColor(int iColor)
+{
+
+	CSG_String s;
+
+	if (iColor == SG_COLOR_NONE)
+	{
+		return SG_T("none");
+	}
+	else if (iColor == SG_COLOR_RANDOM)
+	{
+		s.Append(SG_T("rgb("));
+		s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0));
+		s.Append(SG_T(","));
+		s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0));
+		s.Append(SG_T(","));
+		s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0));
+		s.Append(SG_T(")"));
+
+		return s;
+	}
+	else
+	{
+		s.Append(SG_T("rgb("));
+		s.Append(SG_Get_String(SG_GET_R(iColor),0));
+		s.Append(SG_T(","));
+		s.Append(SG_Get_String(SG_GET_G(iColor),0));
+		s.Append(SG_T(","));
+		s.Append(SG_Get_String(SG_GET_B(iColor),0));
+		s.Append(SG_T(")"));
+
+		return s;
+	}
+
+}

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/doc_svg.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,142 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      doc_svg.h                        //
+//                                                       //
+//                 Copyright (C) 2005 by                 //
+//                     Victor Olaya                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__doc_svg_H
+#define HEADER_INCLUDED__SAGA_API__doc_svg_H
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "geo_tools.h"
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_SVG_Alignment
+{
+	SVG_ALIGNMENT_Left	= 0,
+	SVG_ALIGNMENT_Center,
+	SVG_ALIGNMENT_Right
+}
+TSG_SVG_Alignment;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Doc_SVG
+{
+public:
+	CSG_Doc_SVG(void);
+	virtual ~CSG_Doc_SVG(void);
+
+	void						Open						(int iWidth, int iHeight);
+	bool						Save						(const SG_Char *FileName);
+
+	void						Draw_Line					(double xa, double ya, double xb, double yb	, double Width = 1., int Color = SG_COLOR_BLACK);
+	void						Draw_Line					(CSG_Points &Points							, double Width = 1., int Color = SG_COLOR_BLACK);
+	void						Draw_Rectangle				(double xa, double ya, double xb, double yb	, int Fill_Color = SG_COLOR_WHITE, int Line_Color = SG_COLOR_BLACK, double Line_Width = 1.);
+	void						Draw_Rectangle				(const CSG_Rect &r							, int Fill_Color = SG_COLOR_WHITE, int Line_Color = SG_COLOR_BLACK, double Line_Width = 1.);
+	void						Draw_Polygon				(CSG_Points &Points							, int Fill_Color = SG_COLOR_GREEN, int Line_Color = SG_COLOR_BLACK, double Line_Width = 1.);
+	void						Draw_LinkedPolygon			(CSG_Points &Points, const SG_Char *Link	, int Fill_Color = SG_COLOR_GREEN, int Line_Color = SG_COLOR_BLACK, double Line_Width = 1.);
+	void						Draw_Circle					(double x, double y, double Radius			, int Fill_Color = SG_COLOR_RED  , int Line_Color = SG_COLOR_BLACK, double Line_Width = 1.);
+	void						Draw_LinkedCircle			(double x, double y, double Radius, const SG_Char *Link, int Fill_Color = SG_COLOR_RED  , int Line_Color = SG_COLOR_BLACK, double Line_Width = 1.);
+
+	void						Draw_Text					(double x, double y,  const SG_Char *Text, int iColor, const SG_Char* Font, double dSize, TSG_SVG_Alignment Alignment = SVG_ALIGNMENT_Center);
+
+protected:
+
+	CSG_String					m_sSVGCode;
+	void						_AddAttribute				(const SG_Char *Attribute, const SG_Char *Value);
+	void						_AddAttribute				(const SG_Char *Attribute, int Value);
+	void						_AddAttribute				(const SG_Char *Attribute, double Value);
+	CSG_String					_Get_SVGColor				(int iColor);
+
+private:
+	
+	int							m_iWidth, m_iHeight;
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif //#ifndef HEADER_INCLUDED__SAGA_API__doc_svg_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_classes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_classes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_classes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,860 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   geo_classes.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "geo_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						CSG_Point						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Point::CSG_Point(void)
+{
+	Assign(0.0, 0.0);
+}
+
+CSG_Point::CSG_Point(const CSG_Point &Point)
+{
+	Assign(Point);
+}
+
+CSG_Point::CSG_Point(const TSG_Point &Point)
+{
+	Assign(Point.x, Point.y);
+}
+
+CSG_Point::CSG_Point(double x, double y)
+{
+	Assign(x, y);
+}
+
+//---------------------------------------------------------
+CSG_Point::~CSG_Point(void)
+{
+}
+
+//---------------------------------------------------------
+bool CSG_Point::operator == (const CSG_Point &Point) const
+{
+	return( is_Equal(Point) );
+}
+
+bool CSG_Point::operator != (const CSG_Point &Point) const
+{
+	return( !is_Equal(Point) );
+}
+
+CSG_Point & CSG_Point::operator = (const CSG_Point &Point)
+{
+	Assign(Point);
+
+	return( *this );
+}
+
+void CSG_Point::operator += (const CSG_Point &Point)
+{
+	m_point.x	+= Point.Get_X();
+	m_point.y	+= Point.Get_Y();
+}
+
+void CSG_Point::operator -= (const CSG_Point &Point)
+{
+	m_point.x	-= Point.Get_X();
+	m_point.y	-= Point.Get_Y();
+}
+
+CSG_Point CSG_Point::operator + (const CSG_Point &Point) const
+{
+	return( CSG_Point(
+		m_point.x + Point.Get_X(),
+		m_point.y + Point.Get_Y())
+	);
+}
+
+CSG_Point CSG_Point::operator - (const CSG_Point &Point) const
+{
+	return( CSG_Point(
+		m_point.x - Point.Get_X(),
+		m_point.y - Point.Get_Y())
+	);
+}
+
+//---------------------------------------------------------
+void CSG_Point::Assign(double x, double y)
+{
+	m_point.x	= x;
+	m_point.y	= y;
+}
+
+void CSG_Point::Assign(const CSG_Point &Point)
+{
+	m_point		= Point.m_point;
+}
+
+//---------------------------------------------------------
+bool CSG_Point::is_Equal(double x, double y) const
+{
+	return(	m_point.x == x && m_point.y == y );
+}
+
+bool CSG_Point::is_Equal(const CSG_Point &Point) const
+{
+	return(	is_Equal(Point.Get_X(), Point.Get_Y()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Points::CSG_Points(void)
+{
+	m_nPoints	= 0;
+	m_Points	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Points::~CSG_Points(void)
+{
+	Clear();
+}
+
+//---------------------------------------------------------
+void CSG_Points::Clear(void)
+{
+	if( m_Points )
+	{
+		SG_Free(m_Points);
+	}
+
+	m_nPoints	= 0;
+	m_Points	= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Points::Assign(const CSG_Points &Points)
+{
+	Set_Count(Points.m_nPoints);
+
+	if( m_nPoints > 0 )
+	{
+		memcpy(m_Points, Points.m_Points, m_nPoints * sizeof(TSG_Point));
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Points & CSG_Points::operator  = (const CSG_Points &Points)
+{
+	Assign(Points);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+bool CSG_Points::Set_Count(int nPoints)
+{
+	m_nPoints	= nPoints;
+	m_Points	= (TSG_Point *)SG_Realloc(m_Points, m_nPoints * sizeof(TSG_Point));
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Points::Add(double x, double y)
+{
+	m_Points	= (TSG_Point *)SG_Realloc(m_Points, (m_nPoints + 1) * sizeof(TSG_Point));
+	m_Points[m_nPoints].x	= x;
+	m_Points[m_nPoints].y	= y;
+	m_nPoints++;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Points::Add(const TSG_Point &Point)
+{
+	return( Add(Point.x, Point.y) );
+}
+
+//---------------------------------------------------------
+bool CSG_Points::Del(int Index)
+{
+	if( Index >= 0 && Index < m_nPoints )
+	{
+		m_nPoints--;
+
+		if( m_nPoints > 0 )
+		{
+			for(TSG_Point *A=m_Points+Index, *B=m_Points+Index+1; Index<m_nPoints; Index++, A++, B++)
+			{
+				*A	= *B;
+			}
+
+			m_Points	= (TSG_Point *)SG_Realloc(m_Points, m_nPoints * sizeof(TSG_Point));
+		}
+		else
+		{
+			SG_Free(m_Points);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Points_Int::CSG_Points_Int(void)
+{
+	m_nPoints	= 0;
+	m_Points	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Points_Int::~CSG_Points_Int(void)
+{
+	Clear();
+}
+
+//---------------------------------------------------------
+void CSG_Points_Int::Clear(void)
+{
+	if( m_Points )
+	{
+		SG_Free(m_Points);
+	}
+
+	m_nPoints	= 0;
+	m_Points	= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Points_Int::Assign(const CSG_Points_Int &Points)
+{
+	Set_Count(Points.m_nPoints);
+
+	if( m_nPoints > 0 )
+	{
+		memcpy(m_Points, Points.m_Points, m_nPoints * sizeof(TSG_Point_Int));
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Points_Int & CSG_Points_Int::operator  = (const CSG_Points_Int &Points)
+{
+	Assign(Points);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_Int::Set_Count(int nPoints)
+{
+	m_nPoints	= nPoints;
+	m_Points	= (TSG_Point_Int *)SG_Realloc(m_Points, m_nPoints * sizeof(TSG_Point_Int));
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_Int::Add(int x, int y)
+{
+	m_Points	= (TSG_Point_Int *)SG_Realloc(m_Points, (m_nPoints + 1) * sizeof(TSG_Point_Int));
+	m_Points[m_nPoints].x	= x;
+	m_Points[m_nPoints].y	= y;
+	m_nPoints++;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_Int::Add(const TSG_Point_Int &Point)
+{
+	return( Add(Point.x, Point.y) );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_Int::Del(int Index)
+{
+	if( Index >= 0 && Index < m_nPoints )
+	{
+		m_nPoints--;
+
+		if( m_nPoints > 0 )
+		{
+			for(TSG_Point_Int *A=m_Points+Index, *B=m_Points+Index+1; Index<m_nPoints; Index++, A++, B++)
+			{
+				*A	= *B;
+			}
+
+			m_Points	= (TSG_Point_Int *)SG_Realloc(m_Points, m_nPoints * sizeof(TSG_Point_Int));
+		}
+		else
+		{
+			SG_Free(m_Points);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Points_3D::CSG_Points_3D(void)
+{
+	m_nPoints	= 0;
+	m_Points	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Points_3D::~CSG_Points_3D(void)
+{
+	Clear();
+}
+
+//---------------------------------------------------------
+void CSG_Points_3D::Clear(void)
+{
+	if( m_Points )
+	{
+		SG_Free(m_Points);
+	}
+
+	m_nPoints	= 0;
+	m_Points	= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Points_3D::Assign(const CSG_Points_3D &Points)
+{
+	Set_Count(Points.m_nPoints);
+
+	if( m_nPoints > 0 )
+	{
+		memcpy(m_Points, Points.m_Points, m_nPoints * sizeof(TSG_Point_3D));
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Points_3D & CSG_Points_3D::operator  = (const CSG_Points_3D &Points)
+{
+	Assign(Points);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_3D::Set_Count(int nPoints)
+{
+	m_nPoints	= nPoints;
+	m_Points	= (TSG_Point_3D *)SG_Realloc(m_Points, m_nPoints * sizeof(TSG_Point_3D));
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_3D::Add(double x, double y, double z)
+{
+	m_Points	= (TSG_Point_3D *)SG_Realloc(m_Points, (m_nPoints + 1) * sizeof(TSG_Point_3D));
+	m_Points[m_nPoints].x	= x;
+	m_Points[m_nPoints].y	= y;
+	m_Points[m_nPoints].z	= z;
+	m_nPoints++;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_3D::Add(const TSG_Point_3D &Point)
+{
+	return( Add(Point.x, Point.y, Point.z) );
+}
+
+//---------------------------------------------------------
+bool CSG_Points_3D::Del(int Index)
+{
+	if( Index >= 0 && Index < m_nPoints )
+	{
+		m_nPoints--;
+
+		if( m_nPoints > 0 )
+		{
+			for(TSG_Point_3D *A=m_Points+Index, *B=m_Points+Index+1; Index<m_nPoints; Index++, A++, B++)
+			{
+				*A	= *B;
+			}
+
+			m_Points	= (TSG_Point_3D *)SG_Realloc(m_Points, m_nPoints * sizeof(TSG_Point_3D));
+		}
+		else
+		{
+			SG_Free(m_Points);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						CSG_Rect						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Rect::CSG_Rect(void)
+{
+	Assign(0.0, 0.0, 0.0, 0.0);
+}
+
+CSG_Rect::CSG_Rect(const CSG_Rect &Rect)
+{
+	Assign(Rect.m_rect);
+}
+
+CSG_Rect::CSG_Rect(const TSG_Rect &Rect)
+{
+	Assign(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax);
+}
+
+CSG_Rect::CSG_Rect(const CSG_Point &A, const CSG_Point &B)
+{
+	Assign(A.Get_X(), A.Get_Y(), B.Get_X(), B.Get_Y());
+}
+
+CSG_Rect::CSG_Rect(double xMin, double yMin, double xMax, double yMax)
+{
+	Assign(xMin, yMin, xMax, yMax);
+}
+
+//---------------------------------------------------------
+CSG_Rect::~CSG_Rect(void)
+{}
+
+//---------------------------------------------------------
+bool CSG_Rect::operator == (const CSG_Rect &Rect) const
+{
+	return( is_Equal(Rect) );
+}
+
+bool CSG_Rect::operator != (const CSG_Rect &Rect) const
+{
+	return( !is_Equal(Rect) );
+}
+
+CSG_Rect & CSG_Rect::operator = (const CSG_Rect &Rect)
+{
+	Assign(Rect);
+
+	return( *this );
+}
+
+void CSG_Rect::operator += (const CSG_Point &Point)
+{
+	Move( Point.Get_X(),  Point.Get_Y());
+}
+
+void CSG_Rect::operator -= (const CSG_Point &Point)
+{
+	Move(-Point.Get_Y(), -Point.Get_Y());
+}
+
+//---------------------------------------------------------
+void CSG_Rect::Assign(double xMin, double yMin, double xMax, double yMax)
+{
+	double	d;
+
+	m_rect.xMin	= xMin;
+	m_rect.yMin	= yMin;
+	m_rect.xMax	= xMax;
+	m_rect.yMax	= yMax;
+
+	if( m_rect.xMin > m_rect.xMax )
+	{
+		d			= m_rect.xMin;
+		m_rect.xMin	= m_rect.xMax;
+		m_rect.xMax	= d;
+	}
+
+	if( m_rect.yMin > m_rect.yMax )
+	{
+		d			= m_rect.yMin;
+		m_rect.yMin	= m_rect.yMax;
+		m_rect.yMax	= d;
+	}
+}
+
+void CSG_Rect::Assign(const CSG_Point &A, const CSG_Point &B)
+{
+	Assign(A.Get_X(), A.Get_Y(), B.Get_X(), B.Get_Y());
+}
+
+void CSG_Rect::Assign(const CSG_Rect &Rect)
+{
+	Assign(Rect.Get_XMin(), Rect.Get_YMin(), Rect.Get_XMax(), Rect.Get_YMax());
+}
+
+//---------------------------------------------------------
+void CSG_Rect::Set_BottomLeft(double x, double y)
+{
+	Assign(x, y, m_rect.xMax, m_rect.yMax);
+}
+
+void CSG_Rect::Set_BottomLeft(const CSG_Point &Point)
+{
+	Set_BottomLeft(Point.Get_X(), Point.Get_Y() );
+}
+
+void CSG_Rect::Set_TopRight(double x, double y)
+{
+	Assign(m_rect.xMin, m_rect.yMin, x, y);
+}
+
+void CSG_Rect::Set_TopRight(const CSG_Point &Point)
+{
+	Set_TopRight(Point.Get_X(), Point.Get_Y() );
+}
+
+//---------------------------------------------------------
+bool CSG_Rect::is_Equal(double xMin, double yMin, double xMax, double yMax) const
+{
+	return(	m_rect.xMin == xMin && m_rect.yMin == yMin
+		&&	m_rect.xMax == xMax && m_rect.yMax == yMax	);
+}
+
+bool CSG_Rect::is_Equal(const CSG_Rect &Rect) const
+{
+	return(	is_Equal(Rect.Get_XMin(), Rect.Get_YMin(), Rect.Get_XMax(), Rect.Get_YMax()) );
+}
+
+//---------------------------------------------------------
+void CSG_Rect::Move(double dx, double dy)
+{
+	m_rect.xMin	+= dx;
+	m_rect.yMin	+= dy;
+	m_rect.xMax	+= dx;
+	m_rect.yMax	+= dy;
+}
+
+void CSG_Rect::Move(const CSG_Point &Point)
+{
+	Move(Point.Get_X(), Point.Get_Y());
+}
+
+//---------------------------------------------------------
+void CSG_Rect::Inflate(double dx, double dy, bool bPercent)
+{
+	if( bPercent )
+	{
+		dx	= (Get_XRange() * 0.01 * dx) / 2.0;
+		dy	= (Get_YRange() * 0.01 * dy) / 2.0;
+	}
+
+	Assign(
+		m_rect.xMin - dx, m_rect.yMin - dy,
+		m_rect.xMax + dx, m_rect.yMax + dy
+	);
+}
+
+void CSG_Rect::Inflate(double d, bool bPercent)
+{
+	Inflate(d, d, bPercent);
+}
+
+void CSG_Rect::Deflate(double dx, double dy, bool bPercent)
+{
+	Inflate(-dx, -dy, bPercent);
+}
+
+void CSG_Rect::Deflate(double d, bool bPercent)
+{
+	Deflate(d, d, bPercent);
+}
+
+//---------------------------------------------------------
+void CSG_Rect::Union(const CSG_Rect &Rect)
+{
+	if( m_rect.xMin > Rect.Get_XMin() )
+	{
+		m_rect.xMin	= Rect.Get_XMin();
+	}
+
+	if( m_rect.yMin > Rect.Get_YMin() )
+	{
+		m_rect.yMin	= Rect.Get_YMin();
+	}
+
+	if( m_rect.xMax < Rect.Get_XMax() )
+	{
+		m_rect.xMax	= Rect.Get_XMax();
+	}
+
+	if( m_rect.yMax < Rect.Get_YMax() )
+	{
+		m_rect.yMax	= Rect.Get_YMax();
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Rect::Intersect(const CSG_Rect &Rect)
+{
+	switch( Intersects(Rect) )
+	{
+	case INTERSECTION_None: default:
+		return( false );
+
+	case INTERSECTION_Identical:
+	case INTERSECTION_Contained:
+		break;
+
+	case INTERSECTION_Contains:
+		m_rect	= Rect.m_rect;
+		break;
+
+	case INTERSECTION_Overlaps:
+		if( m_rect.xMin < Rect.Get_XMin() )
+		{
+			m_rect.xMin	= Rect.Get_XMin();
+		}
+
+		if( m_rect.yMin < Rect.Get_YMin() )
+		{
+			m_rect.yMin	= Rect.Get_YMin();
+		}
+
+		if( m_rect.xMax > Rect.Get_XMax() )
+		{
+			m_rect.xMax	= Rect.Get_XMax();
+		}
+
+		if( m_rect.yMax > Rect.Get_YMax() )
+		{
+			m_rect.yMax	= Rect.Get_YMax();
+		}
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+TSG_Intersection CSG_Rect::Intersects(const CSG_Rect &Rect) const
+{
+	if(	m_rect.xMax < Rect.Get_XMin() || Rect.Get_XMax() < m_rect.xMin
+	||	m_rect.yMax < Rect.Get_YMin() || Rect.Get_YMax() < m_rect.yMin )
+	{
+		return( INTERSECTION_None );
+	}
+
+	if(	is_Equal(Rect) )
+	{
+		return( INTERSECTION_Identical );
+	}
+
+	if(	Contains(Rect.Get_XMin(), Rect.Get_YMin())
+	&&	Contains(Rect.Get_XMax(), Rect.Get_YMax()) )
+	{
+		return( INTERSECTION_Contains );
+	}
+
+	if(	Rect.Contains(Get_XMin(), Get_YMin())
+	&&	Rect.Contains(Get_XMax(), Get_YMax()) )
+	{
+		return( INTERSECTION_Contained );
+	}
+
+	return( INTERSECTION_Overlaps );
+}
+
+//---------------------------------------------------------
+bool CSG_Rect::Contains(double x, double y) const
+{
+	return(	m_rect.xMin <= x && x <= m_rect.xMax
+		&&	m_rect.yMin <= y && y <= m_rect.yMax
+	);
+}
+
+bool CSG_Rect::Contains(const CSG_Point &Point) const
+{
+	return( Contains(Point.Get_X(), Point.Get_Y()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Rects::CSG_Rects(void)
+{
+	m_nRects	= 0;
+	m_Rects		= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Rects::~CSG_Rects(void)
+{
+	Clear();
+}
+
+//---------------------------------------------------------
+void CSG_Rects::Clear(void)
+{
+	if( m_Rects )
+	{
+		for(int i=0; i<m_nRects; i++)
+		{
+			delete(m_Rects[i]);
+		}
+
+		SG_Free(m_Rects);
+	}
+
+	m_nRects	= 0;
+	m_Rects		= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Rects::Assign(const CSG_Rects &Rects)
+{
+	Clear();
+
+	for(int i=0; i<Rects.m_nRects; i++)
+	{
+		Add(*Rects.m_Rects[i]);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Rects & CSG_Rects::operator  = (const CSG_Rects &Rects)
+{
+	Assign(Rects);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+bool CSG_Rects::Add(void)
+{
+	return( Add(CSG_Rect()) );
+}
+
+//---------------------------------------------------------
+bool CSG_Rects::Add(double xMin, double yMin, double xMax, double yMax)
+{
+	return( Add(CSG_Rect(xMin, yMin, xMax, yMax)) );
+}
+
+//---------------------------------------------------------
+bool CSG_Rects::Add(const CSG_Rect &Rect)
+{
+	m_Rects				= (CSG_Rect **)SG_Realloc(m_Rects, (m_nRects + 1) * sizeof(CSG_Rect *));
+	m_Rects[m_nRects]	= new CSG_Rect(Rect);
+	m_nRects++;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_functions.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_functions.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_functions.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,402 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  geo_functions.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Tools - Functions					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "geo_tools.h"
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double		SG_Get_Length(double dx, double dy)
+{
+	return( sqrt(dx*dx + dy*dy) );
+}
+
+//---------------------------------------------------------
+double		SG_Get_Distance(double ax, double ay, double bx, double by)
+{
+	ax	-= bx;
+	ay	-= by;
+
+	return( sqrt(ax*ax + ay*ay) );
+}
+
+//---------------------------------------------------------
+double		SG_Get_Distance(const TSG_Point &A, const TSG_Point &B)
+{
+	double	dx,	dy;
+
+	dx	= B.x - A.x;
+	dy	= B.y - A.y;
+
+	return( sqrt(dx*dx + dy*dy) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double		SG_Get_Angle_Of_Direction(double dx, double dy)
+{
+	if( dx == 0.0 )
+	{
+		return( dy > 0.0 ? 0.0 : M_PI_180 );
+	}
+
+	dx	= M_PI_090 - atan2(dy, dx);
+
+	return( dx < 0.0 ? M_PI_360 + dx : dx );
+}
+
+//---------------------------------------------------------
+double		SG_Get_Angle_Of_Direction(double ax, double ay, double bx, double by)
+{
+	return( SG_Get_Angle_Of_Direction(bx - ax, by - ay) );
+}
+
+//---------------------------------------------------------
+double		SG_Get_Angle_Of_Direction(const TSG_Point &A)
+{
+	return( SG_Get_Angle_Of_Direction(A.x, A.y) );
+}
+
+//---------------------------------------------------------
+double		SG_Get_Angle_Of_Direction(const TSG_Point &A, const TSG_Point &B)
+{
+	return( SG_Get_Angle_Of_Direction(B.x - A.x, B.y - A.y) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool	SG_Get_Crossing(TSG_Point &Crossing, const TSG_Point &a1, const TSG_Point &a2, const TSG_Point &b1, const TSG_Point &b2, bool bExactMatch)
+{
+	double	lambda, div, a_dx, a_dy, b_dx, b_dy;
+
+	a_dx	= a2.x - a1.x;
+	a_dy	= a2.y - a1.y;
+
+	b_dx	= b2.x - b1.x;
+	b_dy	= b2.y - b1.y;
+
+	if( (div = a_dx * b_dy - b_dx * a_dy) != 0.0 )
+	{
+		lambda		= ((b1.x - a1.x) * b_dy - b_dx * (b1.y - a1.y)) / div;
+
+		Crossing.x	= a1.x + lambda * a_dx;
+		Crossing.y	= a1.y + lambda * a_dy;
+
+		if( !bExactMatch )
+		{
+			return( true );
+		}
+		else if( 0.0 <= lambda && lambda <= 1.0 )
+		{
+			lambda	= ((b1.x - a1.x) * a_dy - a_dx * (b1.y - a1.y)) / div;
+
+			if( 0.0 <= lambda && lambda <= 1.0 )
+			{
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool	SG_Get_Crossing_InRegion(TSG_Point &Crossing, const TSG_Point &_a, const TSG_Point &_b, const TSG_Rect &Region)
+{
+	bool		bResult;
+	TSG_Point	a, b, pExt_XY, pExt_X, pExt_Y;
+	CSG_Rect	r(Region);
+
+	a	= _a;
+	b	= _b;
+
+	//-----------------------------------------------------
+	if( !r.Contains(a) && r.Contains(b) )
+	{
+		pExt_X	= a;
+		a		= b;
+		b		= pExt_X;
+		bResult	= true;
+	}
+	else if( r.Contains(a) && !r.Contains(b) )
+	{
+		bResult	= true;
+	}
+	else
+	{
+		bResult	= false;
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		if( a.x > b.x )
+		{
+			pExt_XY.x	= Region.xMin;
+			pExt_X.x	= Region.xMin;
+			pExt_Y.x	= Region.xMax;
+		}
+		else
+		{
+			pExt_XY.x	= Region.xMax;
+			pExt_X.x	= Region.xMax;
+			pExt_Y.x	= Region.xMin;
+		}
+		if( a.y > b.y )
+		{
+			pExt_XY.y	= Region.yMin;
+			pExt_Y.y	= Region.yMin;
+			pExt_X.y	= Region.yMax;
+		}
+		else
+		{
+			pExt_XY.y	= Region.yMax;
+			pExt_Y.y	= Region.yMax;
+			pExt_X.y	= Region.yMin;
+		}
+
+		//-------------------------------------------------
+		if( !SG_Get_Crossing(Crossing, a, b, pExt_X, pExt_XY) )
+		{
+			if( !SG_Get_Crossing(Crossing, a, b, pExt_Y, pExt_XY) )
+			{
+				bResult	= false;
+			}
+		}
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double		SG_Get_Nearest_Point_On_Line(const TSG_Point &Point, const TSG_Point &Ln_A, const TSG_Point &Ln_B, TSG_Point &Ln_Point, bool bExactMatch)
+{
+	double		dx, dy, Distance, d;
+	TSG_Point	Point_B;
+
+	Point_B.x	= Point.x - (Ln_B.y - Ln_A.y);
+	Point_B.y	= Point.y + (Ln_B.x - Ln_A.x);
+
+	if( SG_Get_Crossing(Ln_Point, Ln_A, Ln_B, Point, Point_B, false) )
+	{
+		if( !bExactMatch || (bExactMatch && SG_IS_BETWEEN(Ln_A.x, Ln_Point.x, Ln_B.x) && SG_IS_BETWEEN(Ln_A.y, Ln_Point.y, Ln_B.y)) )
+		{
+			dx			= Point.x - Ln_Point.x;
+			dy			= Point.y - Ln_Point.y;
+			Distance	= sqrt(dx*dx + dy*dy);
+		}
+		else
+		{
+			dx			= Point.x - Ln_A.x;
+			dy			= Point.y - Ln_A.y;
+			d			= sqrt(dx*dx + dy*dy);
+
+			dx			= Point.x - Ln_B.x;
+			dy			= Point.y - Ln_B.y;
+			Distance	= sqrt(dx*dx + dy*dy);
+
+			if( d < Distance )
+			{
+				Distance	= d;
+				Ln_Point	= Ln_A;
+			}
+			else
+			{
+				Ln_Point	= Ln_B;
+			}
+		}
+
+		return( Distance );
+	}
+
+	return( -1.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define A	Triangle[0]
+#define B	Triangle[1]
+#define C	Triangle[2]
+
+//---------------------------------------------------------
+bool		SG_Get_Triangle_CircumCircle(TSG_Point Triangle[3], TSG_Point &Point, double &Radius)
+{
+	TSG_Point	AB, AC, AB_M, AC_M, AB_N, AC_N;
+
+	AB.x	= B.x - A.x;
+	AB.y	= B.y - A.y;
+	AB_M.x	= A.x + AB.x / 2.0;
+	AB_M.y	= A.y + AB.y / 2.0;
+	AB_N.x	= AB_M.x - AB.y;
+	AB_N.y	= AB_M.y + AB.x;
+
+	AC.x	= C.x - A.x;
+	AC.y	= C.y - A.y;
+	AC_M.x	= A.x + AC.x / 2.0;
+	AC_M.y	= A.y + AC.y / 2.0;
+	AC_N.x	= AC_M.x - AC.y;
+	AC_N.y	= AC_M.y + AC.x;
+
+	if( SG_Get_Crossing(Point, AB_M, AB_N, AC_M, AC_N, false) )
+	{
+		AB.x	= A.x - Point.x;
+		AB.y	= A.y - Point.y;
+
+		Radius	= sqrt(AB.x*AB.x + AB.y*AB.y);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+#undef A
+#undef B
+#undef C
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double		SG_Get_Polygon_Area(TSG_Point *Points, int nPoints)
+{
+	double	Area	= 0.0;
+
+	if( nPoints >= 3 )
+	{
+		int			i;
+		TSG_Point	*jP, *iP;
+
+		for(i=0, iP=Points, jP=Points+nPoints-1; i<nPoints; i++, jP=iP++)
+		{
+			Area	+= (jP->x * iP->y) - (iP->x * jP->y);
+		}
+
+		Area	/= 2.0;
+	}
+
+	return( Area );
+}
+
+//---------------------------------------------------------
+double		SG_Get_Polygon_Area(const CSG_Points &Points)
+{
+	double	Area	= 0.0;
+
+	if( Points.Get_Count() >= 3 )
+	{
+		for(int i=0, j=Points.Get_Count()-1; i<Points.Get_Count(); j=i++)
+		{
+			Area	+= (Points.Get_X(j) * Points.Get_Y(i))
+					 - (Points.Get_X(i) * Points.Get_Y(j));
+		}
+
+		Area	/= 2.0;
+	}
+
+	return( Area );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_tools.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_tools.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/geo_tools.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,564 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      geo_tools.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__geo_tools_H
+#define HEADER_INCLUDED__SAGA_API__geo_tools_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define	SG_IS_BETWEEN(a, x, b)	(((a) <= (x) && (x) <= (b)) || ((b) <= (x) && (x) <= (a)))
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Intersection
+{
+	INTERSECTION_None			 = 0,
+	INTERSECTION_Identical,
+	INTERSECTION_Overlaps,
+	INTERSECTION_Contained,
+	INTERSECTION_Contains
+}
+TSG_Intersection;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef struct SSG_Point
+{
+	double						x, y;
+}
+TSG_Point;
+
+//---------------------------------------------------------
+typedef struct SSG_Point_Int
+{
+	int							x, y;
+}
+TSG_Point_Int;
+
+//---------------------------------------------------------
+typedef struct SSG_Point_3D
+{
+	double						x, y, z;
+}
+TSG_Point_3D;
+
+//---------------------------------------------------------
+typedef struct SSG_Rect
+{
+	double						xMin, yMin, xMax, yMax;
+}
+TSG_Rect;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Point
+{
+public:
+	CSG_Point(void);
+	CSG_Point(const CSG_Point &Point);
+	CSG_Point(const TSG_Point &Point);
+	CSG_Point(double x, double y);
+
+	~CSG_Point(void);
+
+	operator TSG_Point &						(void)			{	return( m_point );		}
+
+	double						Get_X			(void)	const	{	return( m_point.x );	}
+	double						Get_Y			(void)	const	{	return( m_point.y );	}
+
+	bool						operator ==		(const CSG_Point &Point)	const;
+	bool						operator !=		(const CSG_Point &Point)	const;
+
+	CSG_Point &					operator  =		(const CSG_Point &Point);
+	void						operator +=		(const CSG_Point &Point);
+	void						operator -=		(const CSG_Point &Point);
+
+	CSG_Point					operator +		(const CSG_Point &Point)	const;
+	CSG_Point					operator -		(const CSG_Point &Point)	const;
+
+	void						Assign			(double x, double y);
+	void						Assign			(const CSG_Point &Point);
+
+	bool						is_Equal		(double x, double y)		const;
+	bool						is_Equal		(const CSG_Point &Point)	const;
+
+
+	//-----------------------------------------------------
+	TSG_Point					m_point;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Points
+{
+public:
+	CSG_Points(void);
+	virtual ~CSG_Points(void);
+
+	void						Clear			(void);
+
+	CSG_Points &				operator  =		(const CSG_Points &Points);
+	bool						Assign			(const CSG_Points &Points);
+
+	bool						Add				(double x, double y);
+	bool						Add				(const TSG_Point &Point);
+	bool						Del				(int Index);
+
+	bool						Set_Count		(int nPoints);
+	int							Get_Count		(void)		const	{	return( m_nPoints );	}
+
+	TSG_Point &					operator []		(int Index)			{	return( m_Points[Index]   );	}
+	TSG_Point &					Get_Point		(int Index)			{	return( m_Points[Index]   );	}
+	double						Get_X			(int Index) const	{	return( m_Points[Index].x );	}
+	double						Get_Y			(int Index) const	{	return( m_Points[Index].y );	}
+
+
+private:
+
+	int							m_nPoints;
+
+	TSG_Point					*m_Points;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Points_Int
+{
+public:
+	CSG_Points_Int(void);
+	virtual ~CSG_Points_Int(void);
+
+	void						Clear			(void);
+
+	CSG_Points_Int &			operator  =		(const CSG_Points_Int &Points);
+	bool						Assign			(const CSG_Points_Int &Points);
+
+	bool						Add				(int x, int y);
+	bool						Add				(const TSG_Point_Int &Point);
+	bool						Del				(int Index);
+
+	bool						Set_Count		(int nPoints);
+	int							Get_Count		(void)		const	{	return( m_nPoints );	}
+
+	TSG_Point_Int &				operator []		(int Index)			{	return( m_Points[Index]   );	}
+	TSG_Point_Int &				Get_Point		(int Index)			{	return( m_Points[Index]   );	}
+	int							Get_X			(int Index) const	{	return( m_Points[Index].x );	}
+	int							Get_Y			(int Index) const	{	return( m_Points[Index].y );	}
+
+
+private:
+
+	int							m_nPoints;
+
+	TSG_Point_Int				*m_Points;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Points_3D
+{
+public:
+	CSG_Points_3D(void);
+	virtual ~CSG_Points_3D(void);
+
+	void						Clear			(void);
+
+	CSG_Points_3D &				operator  =		(const CSG_Points_3D &Points);
+	bool						Assign			(const CSG_Points_3D &Points);
+
+	bool						Add				(double x, double y, double z);
+	bool						Add				(const TSG_Point_3D &Point);
+	bool						Del				(int Index);
+
+	bool						Set_Count		(int nPoints);
+	int							Get_Count		(void)		const	{	return( m_nPoints );	}
+
+	TSG_Point_3D &				operator []		(int Index)			{	return( m_Points[Index]   );	}
+	TSG_Point_3D &				Get_Point		(int Index)			{	return( m_Points[Index]   );	}
+	double						Get_X			(int Index)	const	{	return( m_Points[Index].x );	}
+	double						Get_Y			(int Index)	const	{	return( m_Points[Index].y );	}
+	double						Get_Z			(int Index)	const	{	return( m_Points[Index].z );	}
+
+
+private:
+
+	int							m_nPoints;
+
+	TSG_Point_3D				*m_Points;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Rect
+{
+public:
+	CSG_Rect(void);
+	CSG_Rect(const CSG_Rect &Rect);
+	CSG_Rect(const TSG_Rect &Rect);
+	CSG_Rect(const CSG_Point &A, const CSG_Point &B);
+	CSG_Rect(double xMin, double yMin, double xMax, double yMax);
+
+	~CSG_Rect(void);
+
+	operator const TSG_Rect &					(void) const	{	return( m_rect );	}
+
+	bool						operator ==		(const CSG_Rect &Rect) const;
+	bool						operator !=		(const CSG_Rect &Rect) const;
+
+	CSG_Rect &					operator  =		(const CSG_Rect &Rect);
+	void						operator +=		(const CSG_Point &Point);
+	void						operator -=		(const CSG_Point &Point);
+
+	void						Assign			(double xMin, double yMin, double xMax, double yMax);
+	void						Assign			(const CSG_Point &A, const CSG_Point &B);
+	void						Assign			(const CSG_Rect &Rect);
+
+	void						Set_BottomLeft	(double x, double y);
+	void						Set_BottomLeft	(const CSG_Point &Point);
+	void						Set_TopRight	(double x, double y);
+	void						Set_TopRight	(const CSG_Point &Point);
+
+	bool						is_Equal		(double xMin, double yMin, double xMax, double yMax) const;
+	bool						is_Equal		(const CSG_Rect &Rect) const;
+
+	double						Get_XMin		(void) const	{	return( m_rect.xMin );	}
+	double						Get_XMax		(void) const	{	return( m_rect.xMax );	}
+	double						Get_YMin		(void) const	{	return( m_rect.yMin );	}
+	double						Get_YMax		(void) const	{	return( m_rect.yMax );	}
+
+	double						Get_XRange		(void) const	{	return( m_rect.xMax - m_rect.xMin );	}
+	double						Get_YRange		(void) const	{	return( m_rect.yMax - m_rect.yMin );	}
+
+	CSG_Point					Get_TopLeft		(void)			{	return( CSG_Point(m_rect.xMin, m_rect.yMax) );	}
+	CSG_Point					Get_BottomRight	(void)			{	return( CSG_Point(m_rect.xMax, m_rect.yMin) );	}
+
+	CSG_Point					Get_Center		(void) const	{	return( CSG_Point(Get_XCenter(), Get_YCenter()) );	}
+	double						Get_XCenter		(void) const	{	return( (m_rect.xMin + m_rect.xMax) / 2.0 );	}
+	double						Get_YCenter		(void) const	{	return( (m_rect.yMin + m_rect.yMax) / 2.0 );	}
+
+	void						Move			(double dx, double dy);
+	void						Move			(const CSG_Point &Point);
+
+	void						Inflate			(double d, bool bPercent = true);
+	void						Deflate			(double d, bool bPercent = true);
+	void						Inflate			(double dx, double dy, bool bPercent = true);
+	void						Deflate			(double dx, double dy, bool bPercent = true);
+
+	void						Union			(const CSG_Rect &Rect);
+	bool						Intersect		(const CSG_Rect &Rect);
+
+	TSG_Intersection			Intersects		(const CSG_Rect &Rect)		const;
+
+	bool						Contains		(double x, double y)		const;
+	bool						Contains		(const CSG_Point &Point)	const;
+
+
+	//-----------------------------------------------------
+	TSG_Rect					m_rect;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Rects
+{
+public:
+	CSG_Rects(void);
+	virtual ~CSG_Rects(void);
+
+	void						Clear			(void);
+
+	CSG_Rects &					operator  =		(const CSG_Rects &Points);
+	bool						Assign			(const CSG_Rects &Points);
+
+	bool						Add				(void);
+	bool						Add				(double xMin, double yMin, double xMax, double yMax);
+	bool						Add				(const CSG_Rect &Rect);
+
+	int							Get_Count		(void)	const	{	return( m_nRects );	}
+
+	CSG_Rect &					operator []		(int Index)		{	return( *m_Rects[Index] );	}
+	CSG_Rect &					Get_Rect		(int Index)		{	return( *m_Rects[Index] );	}
+
+
+private:
+
+	int							m_nRects;
+
+	CSG_Rect					**m_Rects;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Projection_Type
+{
+	SG_PROJ_TYPE_CS_Undefined	= 0,
+	SG_PROJ_TYPE_CS_Projected,
+	SG_PROJ_TYPE_CS_Geographic,
+	SG_PROJ_TYPE_CS_Geocentric
+}
+TSG_Projection_Type;
+
+//---------------------------------------------------------
+const SG_Char	gSG_Projection_Type_Identifier[][32]	=
+{
+	SG_T("Undefined"),
+	SG_T("PROJCS"),
+	SG_T("GEOGCS"),
+	SG_T("GEOCCS")
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT CSG_String	SG_Get_Projection_Type_Name	(TSG_Projection_Type Type);
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Projection
+{
+public:
+	CSG_Projection(void);
+	virtual ~CSG_Projection(void);
+
+									CSG_Projection			(const CSG_Projection &Projection);
+	bool							Create					(const CSG_Projection &Projection);
+
+									CSG_Projection			(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4);
+	bool							Create					(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4);
+
+	bool							Assign					(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4);
+	bool							Assign					(const CSG_Projection &Projection);
+	CSG_Projection &				operator =				(const CSG_Projection &Projection)			{	Assign(Projection);	return( *this );	}
+
+	bool							is_Equal				(const CSG_Projection &Projection)	const;
+	bool							operator ==				(const CSG_Projection &Projection)	const	{	return( is_Equal(Projection) );	}
+
+	int								Get_SRID				(void)	const	{	return( m_SRID );			}
+	TSG_Projection_Type				Get_Type				(void)	const	{	return( m_Type );			}
+	const CSG_String &				Get_Name				(void)	const	{	return( m_Name );			}
+	const CSG_String &				Get_OpenGIS				(void)	const	{	return( m_OpenGIS );		}
+	const CSG_String &				Get_Proj4				(void)	const	{	return( m_Proj4 );			}
+	const CSG_String &				Get_Authority			(void)	const	{	return( m_Authority );		}
+	CSG_String						Get_Type_Name			(void)	const	{	return( gSG_Projection_Type_Identifier[m_Type] );	}
+	CSG_String						Get_Type_Identifier		(void)	const	{	return( SG_Get_Projection_Type_Name(m_Type) );	}
+
+	CSG_String						asString				(void)	const;
+
+	bool							from_ESRI				(const CSG_String &ESRI_PRJ);
+	bool							to_ESRI					(CSG_String &ESRI_PRJ)	const;
+
+
+private:
+
+	int								m_SRID;
+
+	TSG_Projection_Type				m_Type;
+
+	CSG_String						m_Name, m_Authority, m_OpenGIS, m_Proj4;
+
+
+	void							_Reset					(void);
+
+	bool							_Get_OpenGIS_from_Proj4	(const SG_Char *Text);
+	bool							_Get_Proj4_from_OpenGIS	(const SG_Char *Text);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Projections
+{
+public:
+	CSG_Projections(void);
+	virtual ~CSG_Projections(void);
+
+									CSG_Projections			(const CSG_String &File_Name);
+	bool							Create					(const CSG_String &File_Name);
+
+									CSG_Projections			(class CSG_Table *pProjections);
+	bool							Create					(class CSG_Table *pProjections);
+
+	void							Destroy					(void);
+
+	bool							Load					(const CSG_String &File_Name);
+	bool							Save					(const CSG_String &File_Name);
+
+	bool							Add						(const CSG_Projection &Projection);
+	bool							Add						(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4);
+
+	int								Get_Count				(void)	const	{	return( m_nProjections );	}
+	const CSG_Projection &			Get_Projection			(int i)	const	{	return( i >= 0 && i < m_nProjections ? *(m_pProjections[i]) : m_Undefined );	}
+	const CSG_Projection &			operator []				(int i) const	{	return( i >= 0 && i < m_nProjections ? *(m_pProjections[i]) : m_Undefined );	}
+
+	CSG_String						Get_Names				(void)	const;
+	int								Get_SRID_byNamesIndex	(int i)	const;
+
+
+private:
+
+	int								m_nProjections, m_nBuffer;
+
+	CSG_Projection					**m_pProjections, m_Undefined;
+
+	static CSG_Projections			*s_pProjections;
+
+	class CSG_Index					*m_pIdx_Names, *m_pIdx_SRIDs;
+
+
+	void							_On_Construction		(void);
+	CSG_Projection *				_Add					(void);
+
+	static int						_Cmp_Names				(const int iElement_1, const int iElement_2);
+	static int						_Cmp_SRIDs				(const int iElement_1, const int iElement_2);
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT CSG_Projections &	SG_Get_Projections	(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Functions						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT double		SG_Get_Length					(double dx, double dy);
+SAGA_API_DLL_EXPORT double		SG_Get_Distance					(double ax, double ay, double bx, double by);
+SAGA_API_DLL_EXPORT double		SG_Get_Distance					(const TSG_Point &A, const TSG_Point &B);
+
+SAGA_API_DLL_EXPORT double		SG_Get_Angle_Of_Direction		(double dx, double dy);
+SAGA_API_DLL_EXPORT double		SG_Get_Angle_Of_Direction		(double ax, double ay, double bx, double by);
+SAGA_API_DLL_EXPORT double		SG_Get_Angle_Of_Direction		(const TSG_Point &A);
+SAGA_API_DLL_EXPORT double		SG_Get_Angle_Of_Direction		(const TSG_Point &A, const TSG_Point &B);
+
+SAGA_API_DLL_EXPORT bool		SG_Get_Crossing					(TSG_Point &Crossing, const TSG_Point &a1, const TSG_Point &a2, const TSG_Point &b1, const TSG_Point &b2, bool bExactMatch = true);
+SAGA_API_DLL_EXPORT bool		SG_Get_Crossing_InRegion		(TSG_Point &Crossing, const TSG_Point &a , const TSG_Point & b, const TSG_Rect &Region);
+
+SAGA_API_DLL_EXPORT double		SG_Get_Nearest_Point_On_Line	(const TSG_Point &Point, const TSG_Point &Ln_A, const TSG_Point &Ln_B, TSG_Point &Ln_Point, bool bExactMatch = true);
+
+SAGA_API_DLL_EXPORT bool		SG_Get_Triangle_CircumCircle	(TSG_Point Triangle[3], TSG_Point &Point, double &Radius);
+
+SAGA_API_DLL_EXPORT double		SG_Get_Polygon_Area				(TSG_Point *Points, int nPoints);
+SAGA_API_DLL_EXPORT double		SG_Get_Polygon_Area				(const CSG_Points &Points);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__geo_tools_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1408 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       grid.cpp                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BYTE	CSG_Grid::m_Bitmask[8]	= { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid * SG_Create_Grid(void)
+{
+	return( new CSG_Grid );
+}
+
+//---------------------------------------------------------
+CSG_Grid * SG_Create_Grid(const CSG_Grid &Grid)
+{
+	return( new CSG_Grid(Grid) );
+}
+
+//---------------------------------------------------------
+CSG_Grid * SG_Create_Grid(const CSG_String &File_Name, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( new CSG_Grid(File_Name, Type, Memory_Type) );
+}
+
+//---------------------------------------------------------
+CSG_Grid * SG_Create_Grid(CSG_Grid *pGrid, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( new CSG_Grid(pGrid, Type, Memory_Type) );
+}
+
+//---------------------------------------------------------
+CSG_Grid * SG_Create_Grid(const CSG_Grid_System &System, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( new CSG_Grid(System, Type, Memory_Type) );
+}
+
+//---------------------------------------------------------
+CSG_Grid * SG_Create_Grid(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( new CSG_Grid(Type, NX, NY, Cellsize, xMin, yMin, Memory_Type) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * Default constructor.
+*/
+//---------------------------------------------------------
+CSG_Grid::CSG_Grid(void)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+/**
+  * Copy constructor.
+*/
+//---------------------------------------------------------
+CSG_Grid::CSG_Grid(const CSG_Grid &Grid)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(Grid);
+}
+
+//---------------------------------------------------------
+/**
+  * Create a grid from file.
+*/
+//---------------------------------------------------------
+CSG_Grid::CSG_Grid(const CSG_String &File_Name, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(File_Name, Type, Memory_Type);
+}
+
+//---------------------------------------------------------
+/**
+  * Create a grid similar to 'pGrid'.
+*/
+//---------------------------------------------------------
+CSG_Grid::CSG_Grid(CSG_Grid *pGrid, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(pGrid, Type, Memory_Type);
+}
+
+//---------------------------------------------------------
+/**
+  * Create a grid using 'System'.
+*/
+//---------------------------------------------------------
+CSG_Grid::CSG_Grid(const CSG_Grid_System &System, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(System, Type, Memory_Type);
+}
+
+//---------------------------------------------------------
+/**
+  * Create a grid with specified parameters.
+  * This constructor initializes the grid's data space with 'NX' x 'NY' cells of the size indicated by 'Type'.
+  * If 'DX/DY' are equal or less zero then both will be set to 1.0. 'xMin/yMin' specify the coordinates of the
+  * lower left corner of the grid.
+*/
+//---------------------------------------------------------
+CSG_Grid::CSG_Grid(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin, TSG_Grid_Memory_Type Memory_Type)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(Type, NX, NY, Cellsize, xMin, yMin, Memory_Type);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::_On_Construction(void)
+{
+	m_bCreated			= false;
+
+	m_Type				= SG_DATATYPE_Undefined;
+	m_Memory_Type		= GRID_MEMORY_Normal;
+	m_Memory_bLock		= false;
+
+	m_Values			= NULL;
+
+	LineBuffer			= NULL;
+	LineBuffer_Count	= 5;
+
+	m_zFactor			= 1.0;
+	m_NoData_Value		= -99999.0;
+	m_NoData_hiValue	= -999.0;
+
+	m_bIndexed			= false;
+	m_Index				= NULL;
+
+	Set_Update_Flag();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::Create(const CSG_Grid &Grid)
+{
+	if( Create((CSG_Grid *)&Grid, ((CSG_Grid *)&Grid)->Get_Type()) )
+	{
+		return( Assign((CSG_Data_Object *)&Grid) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Create(CSG_Grid *pGrid, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( Create(Type, pGrid->Get_NX(), pGrid->Get_NY(), pGrid->Get_Cellsize(), pGrid->Get_XMin(), pGrid->Get_YMin(), Memory_Type) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Create(const CSG_Grid_System &System, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( Create(Type, System.Get_NX(), System.Get_NY(), System.Get_Cellsize(), System.Get_XMin(), System.Get_YMin(), Memory_Type) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Create(const CSG_String &File_Name, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	return( _Load(File_Name, Type, Memory_Type) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Create(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin, TSG_Grid_Memory_Type Memory_Type)
+{
+	Destroy();
+
+	_Set_Properties(Type, NX, NY, Cellsize, xMin, yMin);
+
+	if( _Memory_Create(Memory_Type) )
+	{
+		m_bCreated	= true;
+	}
+
+	return( m_bCreated );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Destruction							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * The destructor.
+*/
+CSG_Grid::~CSG_Grid(void)
+{
+	Destroy();
+}
+
+/**
+  * Destroys the data space of CSG_Grid.
+*/
+bool CSG_Grid::Destroy(void)
+{
+	_Memory_Destroy();
+
+	m_bCreated		= false;
+
+	m_Type			= SG_DATATYPE_Undefined;
+	m_Memory_Type	= GRID_MEMORY_Normal;
+
+	m_zFactor		= 1.0;
+
+	m_Description	.Clear();
+	m_Unit			.Clear();
+
+	m_System		.Assign(0.0, 0.0, 0.0, 0, 0);
+
+	return( CSG_Data_Object::Destroy() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Header							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::_Set_Properties(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin)
+{
+	m_Type	= Type;
+
+	switch( m_Type )
+	{
+	case SG_DATATYPE_Bit:		m_NoData_Value	= m_NoData_hiValue	=  0.0;				break;
+	case SG_DATATYPE_Byte:		m_NoData_Value	= m_NoData_hiValue	=  255.0;			break;
+	case SG_DATATYPE_Char:		m_NoData_Value	= m_NoData_hiValue	= -127.0;			break;
+	case SG_DATATYPE_Word:		m_NoData_Value	= m_NoData_hiValue	=  65535.0;			break;
+	case SG_DATATYPE_Short:		m_NoData_Value	= m_NoData_hiValue	= -32767.0;			break;
+	case SG_DATATYPE_DWord:		m_NoData_Value	= m_NoData_hiValue	=  4294967295.0;	break;
+	case SG_DATATYPE_Int:		m_NoData_Value	= m_NoData_hiValue	= -2147483647.0;	break;
+	case SG_DATATYPE_ULong:		m_NoData_Value	= m_NoData_hiValue	=  4294967295.0;	break;
+	case SG_DATATYPE_Long:		m_NoData_Value	= m_NoData_hiValue	= -2147483647.0;	break;
+	case SG_DATATYPE_Double:	m_NoData_Value	= m_NoData_hiValue	= -99999.0;			break;
+	case SG_DATATYPE_Color:		m_NoData_Value	= m_NoData_hiValue	=  4294967295.0;	break;
+
+	default:					m_Type	= SG_DATATYPE_Float;
+	case SG_DATATYPE_Float:		m_NoData_Value	= m_NoData_hiValue	= -99999.0;			break;
+	}
+
+	m_System.Assign(Cellsize > 0.0 ? Cellsize : 1.0, xMin, yMin, NX, NY);
+
+	m_zStats.Invalidate();
+
+}
+
+//---------------------------------------------------------
+void CSG_Grid::Set_Description(const SG_Char *String)
+{
+	m_Description.Printf(String ? String : SG_T(""));
+}
+
+const SG_Char * CSG_Grid::Get_Description(void) const
+{
+	return( m_Description.c_str() );
+}
+
+//---------------------------------------------------------
+void CSG_Grid::Set_Unit(const SG_Char *String)
+{
+	m_Unit.Printf(String ? String : SG_T(""));
+}
+
+const SG_Char * CSG_Grid::Get_Unit(void) const
+{
+	return( m_Unit.c_str() );
+}
+
+//---------------------------------------------------------
+void CSG_Grid::Set_ZFactor(double Value)
+{
+	m_zFactor		= Value;
+}
+
+//---------------------------------------------------------
+double CSG_Grid::Get_ZFactor(void) const
+{
+	return( m_zFactor );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					No Data Values						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::Set_NoData_Value(double Value)
+{
+	Set_NoData_Value_Range(Value, Value);
+}
+
+void CSG_Grid::Set_NoData_Value_Range(double loValue, double hiValue)
+{
+	double	d;
+
+	if( loValue > hiValue )
+	{
+		d			= loValue;
+		loValue		= hiValue;
+		hiValue		= d;
+	}
+
+	if( !Get_Update_Flag() && (loValue != m_NoData_Value || hiValue != m_NoData_hiValue) )
+	{
+		Set_Update_Flag();
+	}
+
+	m_NoData_Value		= loValue;
+	m_NoData_hiValue	= hiValue;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Checks							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::is_Valid(void) const
+{
+	if(	m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined )
+	{
+		switch( m_Memory_Type )
+		{
+		default:
+			return( m_Values != NULL );
+
+		case GRID_MEMORY_Cache:
+			return( Cache_Stream.is_Open() );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+TSG_Intersection CSG_Grid::is_Intersecting(const CSG_Rect &Extent) const
+{
+	return( Get_Extent().Intersects(Extent.m_rect) );
+}
+
+TSG_Intersection CSG_Grid::is_Intersecting(const TSG_Rect &Extent) const
+{
+	return( Get_Extent().Intersects(Extent) );
+}
+
+TSG_Intersection CSG_Grid::is_Intersecting(double xMin, double yMin, double xMax, double yMax) const
+{
+	return( is_Intersecting(CSG_Rect(xMin, yMin, xMax, yMax)) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::is_Compatible(CSG_Grid *pGrid) const
+{
+	return( pGrid && is_Compatible(pGrid->Get_System()) );
+}
+
+bool CSG_Grid::is_Compatible(const CSG_Grid_System &System) const
+{
+	return( m_System == System );
+}
+
+bool CSG_Grid::is_Compatible(int NX, int NY, double Cellsize, double xMin, double yMin) const
+{
+	return(	is_Compatible(CSG_Grid_System(Cellsize, xMin, yMin, NX, NY)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//		Value access by Position (-> Interpolation)		 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Grid::Get_Value(TSG_Point Position, int Interpolation, bool bZFactor, bool bByteWise, bool bOnlyValidCells) const
+{
+	double	Value;
+
+	return( Get_Value(Position.x, Position.y, Value, Interpolation, bZFactor, bByteWise, bOnlyValidCells) ? Value : m_NoData_Value );
+}
+
+double CSG_Grid::Get_Value(double xPosition, double yPosition, int Interpolation, bool bZFactor, bool bByteWise, bool bOnlyValidCells) const
+{
+	double	Value;
+
+	return( Get_Value(xPosition, yPosition, Value, Interpolation, bZFactor, bByteWise, bOnlyValidCells) ? Value : m_NoData_Value );
+}
+
+bool CSG_Grid::Get_Value(TSG_Point Position, double &Value, int Interpolation, bool bZFactor, bool bByteWise, bool bOnlyValidCells) const
+{
+	return( Get_Value(Position.x, Position.y, Value, Interpolation, bZFactor, bByteWise, bOnlyValidCells) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Get_Value(double xPosition, double yPosition, double &Value, int Interpolation, bool bZFactor, bool bByteWise, bool bOnlyValidCells) const
+{
+	if(	m_System.Get_Extent_Cells().Contains(xPosition, yPosition) )
+	{
+		int		x	= (int)(xPosition	= (xPosition - Get_XMin()) / Get_Cellsize());
+		int		y	= (int)(yPosition	= (yPosition - Get_YMin()) / Get_Cellsize());
+
+		double	dx	= xPosition - x;
+		double	dy	= yPosition - y;
+
+		if( !bOnlyValidCells || is_InGrid(x + (int)(0.5 + dx), y + (int)(0.5 + dy)) )
+		{
+			switch( Interpolation )
+			{
+			case GRID_INTERPOLATION_NearestNeighbour:
+				Value	= _Get_ValAtPos_NearestNeighbour(x, y, dx, dy);
+				break;
+
+			case GRID_INTERPOLATION_Bilinear:
+				Value	= _Get_ValAtPos_BiLinear		(x, y, dx, dy, bByteWise);
+				break;
+
+			case GRID_INTERPOLATION_InverseDistance:
+				Value	= _Get_ValAtPos_InverseDistance	(x, y, dx, dy, bByteWise);
+				break;
+
+			case GRID_INTERPOLATION_BicubicSpline:
+				Value	= _Get_ValAtPos_BiCubicSpline	(x, y, dx, dy, bByteWise);
+				break;
+
+			default:
+			case GRID_INTERPOLATION_BSpline:
+				Value	= _Get_ValAtPos_BSpline			(x, y, dx, dy, bByteWise);
+				break;
+			}
+
+			if( Value != m_NoData_Value )
+			{
+				if( bZFactor )
+				{
+					Value	*= m_zFactor;
+				}
+
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline double CSG_Grid::_Get_ValAtPos_NearestNeighbour(int x, int y, double dx, double dy) const
+{
+	x	+= (int)(0.5 + dx);
+	y	+= (int)(0.5 + dy);
+
+	if( is_InGrid(x, y) )
+	{
+		return( asDouble(x, y) );
+	}
+
+	return( m_NoData_Value );
+}
+
+//---------------------------------------------------------
+#define BILINEAR_ADD(ix, iy, d)			if( is_InGrid(ix, iy) ) { n += d;\
+											z += d * asDouble(ix, iy); }
+
+#define BILINEAR_ADD_BYTE(ix, iy, d)	if( is_InGrid(ix, iy) ) { n += d; v = asInt(ix, iy);\
+											z[0] += d * SG_GET_BYTE_0(v);\
+											z[1] += d * SG_GET_BYTE_1(v);\
+											z[2] += d * SG_GET_BYTE_2(v);\
+											z[3] += d * SG_GET_BYTE_3(v); }
+
+inline double CSG_Grid::_Get_ValAtPos_BiLinear(int x, int y, double dx, double dy, bool bByteWise) const
+{
+	if( !bByteWise )
+	{
+		double	z = 0.0, n = 0.0;
+
+		BILINEAR_ADD(x    , y    , (1.0 - dx) * (1.0 - dy));
+		BILINEAR_ADD(x + 1, y    , (      dx) * (1.0 - dy));
+		BILINEAR_ADD(x    , y + 1, (1.0 - dx) * (      dy));
+		BILINEAR_ADD(x + 1, y + 1, (      dx) * (      dy));
+
+		if( n > 0.0 )
+		{
+			return( z / n );
+		}
+	}
+	else
+	{
+		long	v;
+		double	z[4], n = 0.0;
+
+		z[0] = z[1] = z[2] = z[3] = 0.0;
+
+		BILINEAR_ADD_BYTE(x    , y    , (1.0 - dx) * (1.0 - dy));
+		BILINEAR_ADD_BYTE(x + 1, y    , (      dx) * (1.0 - dy));
+		BILINEAR_ADD_BYTE(x    , y + 1, (1.0 - dx) * (      dy));
+		BILINEAR_ADD_BYTE(x + 1, y + 1, (      dx) * (      dy));
+
+		if( n > 0.0 )
+		{
+			z[0]	/= n;
+			z[1]	/= n;
+			z[2]	/= n;
+			z[3]	/= n;
+
+			return( SG_GET_LONG(z[0], z[1], z[2], z[3]) );
+		}
+	}
+
+	return( m_NoData_Value );
+}
+
+//---------------------------------------------------------
+#define INVERSEDIST_ADD(ix, iy, dsx, dsy)		if( is_InGrid(ix, iy) ) { d = 1.0 / sqrt((dsx)*(dsx) + (dsy)*(dsy)); n += d;\
+													z += d * asDouble(ix, iy); }
+
+#define INVERSEDIST_ADD_BYTE(ix, iy, dsx, dsy)	if( is_InGrid(ix, iy) ) { d = 1.0 / sqrt((dsx)*(dsx) + (dsy)*(dsy)); n += d; v = asInt(ix, iy);\
+													z[0] += d * SG_GET_BYTE_0(v);\
+													z[1] += d * SG_GET_BYTE_1(v);\
+													z[2] += d * SG_GET_BYTE_2(v);\
+													z[3] += d * SG_GET_BYTE_3(v); }
+
+inline double CSG_Grid::_Get_ValAtPos_InverseDistance(int x, int y, double dx, double dy, bool bByteWise) const
+{
+	if( dx > 0.0 || dy > 0.0 )
+	{
+		if( !bByteWise )
+		{
+			double	z = 0.0, n = 0.0, d;
+
+			INVERSEDIST_ADD(x    , y    ,       dx,       dy);
+			INVERSEDIST_ADD(x + 1, y    , 1.0 - dx,       dy);
+			INVERSEDIST_ADD(x    , y + 1,       dx, 1.0 - dy);
+			INVERSEDIST_ADD(x + 1, y + 1, 1.0 - dx, 1.0 - dy);
+
+			if( n > 0.0 )
+			{
+				return( z / n );
+			}
+		}
+		else
+		{
+			long	v;
+			double	z[4], n = 0.0, d;
+
+			z[0] = z[1] = z[2] = z[3] = 0.0;
+
+			INVERSEDIST_ADD_BYTE(x    , y    ,       dx,       dy);
+			INVERSEDIST_ADD_BYTE(x + 1, y    , 1.0 - dx,       dy);
+			INVERSEDIST_ADD_BYTE(x    , y + 1,       dx, 1.0 - dy);
+			INVERSEDIST_ADD_BYTE(x + 1, y + 1, 1.0 - dx, 1.0 - dy);
+
+			if( n > 0.0 )
+			{
+				z[0]	/= n;
+				z[1]	/= n;
+				z[2]	/= n;
+				z[3]	/= n;
+
+				return( SG_GET_LONG(z[0], z[1], z[2], z[3]) );
+			}
+		}
+	}
+	else
+	{
+		return( asDouble(x, y) );
+	}
+
+	return( m_NoData_Value );
+}
+
+//---------------------------------------------------------
+inline double CSG_Grid::_Get_ValAtPos_BiCubicSpline(double dx, double dy, double z_xy[4][4]) const
+{
+	double	a0, a2, a3, b1, b2, b3, c[4];
+
+	for(int i=0; i<4; i++)
+	{
+		a0		= z_xy[0][i] - z_xy[1][i];
+		a2		= z_xy[2][i] - z_xy[1][i];
+		a3		= z_xy[3][i] - z_xy[1][i];
+
+		b1		= -a0 / 3.0 + a2       - a3 / 6.0;
+		b2		=  a0 / 2.0 + a2 / 2.0;
+		b3		= -a0 / 6.0 - a2 / 2.0 + a3 / 6.0;
+
+		c[i]	= z_xy[1][i] + b1 * dx + b2 * dx*dx + b3 * dx*dx*dx;
+	}
+
+	a0		= c[0] - c[1];
+	a2		= c[2] - c[1];
+	a3		= c[3] - c[1];
+
+	b1		= -a0 / 3.0 + a2       - a3 / 6.0;
+	b2		=  a0 / 2.0 + a2 / 2.0;
+	b3		= -a0 / 6.0 - a2 / 2.0 + a3 / 6.0;
+
+	return( c[1] + b1 * dy + b2 * dy*dy + b3 * dy*dy*dy );
+}
+
+inline double CSG_Grid::_Get_ValAtPos_BiCubicSpline(int x, int y, double dx, double dy, bool bByteWise) const
+{
+	if( !bByteWise )
+	{
+		double	z_xy[4][4];
+
+		if( _Get_ValAtPos_Fill4x4Submatrix(x, y, z_xy) )
+		{
+			return( _Get_ValAtPos_BiCubicSpline(dx, dy, z_xy) );
+		}
+	}
+	else
+	{
+		double	z_xy[4][4][4];
+
+		if( _Get_ValAtPos_Fill4x4Submatrix(x, y, z_xy) )
+		{
+			return( SG_GET_LONG(
+				_Get_ValAtPos_BiCubicSpline(dx, dy, z_xy[0]),
+				_Get_ValAtPos_BiCubicSpline(dx, dy, z_xy[1]),
+				_Get_ValAtPos_BiCubicSpline(dx, dy, z_xy[2]),
+				_Get_ValAtPos_BiCubicSpline(dx, dy, z_xy[3])
+			));
+		}
+	}
+
+	return( m_NoData_Value );
+}
+
+//---------------------------------------------------------
+inline double CSG_Grid::_Get_ValAtPos_BSpline(double dx, double dy, double z_xy[4][4]) const
+{
+	int		i, ix, iy;
+	double	z, px, py, Rx[4], Ry[4];
+
+	for(i=0, px=-1.0-dx, py=-1.0-dy; i<4; i++, px++, py++)
+	{
+		Rx[i]	= 0.0;
+		Ry[i]	= 0.0;
+
+		if( (z = px + 2.0) > 0.0 )
+			Rx[i]	+=        z*z*z;
+		if( (z = px + 1.0) > 0.0 )
+			Rx[i]	+= -4.0 * z*z*z;
+		if( (z = px + 0.0) > 0.0 )
+			Rx[i]	+=  6.0 * z*z*z;
+		if( (z = px - 1.0) > 0.0 )
+			Rx[i]	+= -4.0 * z*z*z;
+		if( (z = py + 2.0) > 0.0 )
+			Ry[i]	+=        z*z*z;
+		if( (z = py + 1.0) > 0.0 )
+			Ry[i]	+= -4.0 * z*z*z;
+		if( (z = py + 0.0) > 0.0 )
+			Ry[i]	+=  6.0 * z*z*z;
+		if( (z = py - 1.0) > 0.0 )
+			Ry[i]	+= -4.0 * z*z*z;
+
+		Rx[i]	/= 6.0;
+		Ry[i]	/= 6.0;
+	}
+
+	for(iy=0, z=0.0; iy<4; iy++)
+	{
+		for(ix=0; ix<4; ix++)
+		{
+			z	+= z_xy[ix][iy] * Rx[ix] * Ry[iy];
+		}
+	}
+
+	return( z );
+}
+
+inline double CSG_Grid::_Get_ValAtPos_BSpline(int x, int y, double dx, double dy, bool bByteWise) const
+{
+	if( !bByteWise )
+	{
+		double	z_xy[4][4];
+
+		if( _Get_ValAtPos_Fill4x4Submatrix(x, y, z_xy) )
+		{
+			return( _Get_ValAtPos_BSpline(dx, dy, z_xy) );
+		}
+	}
+	else
+	{
+		double	z_xy[4][4][4];
+
+		if( _Get_ValAtPos_Fill4x4Submatrix(x, y, z_xy) )
+		{
+			return( SG_GET_LONG(
+				_Get_ValAtPos_BSpline(dx, dy, z_xy[0]),
+				_Get_ValAtPos_BSpline(dx, dy, z_xy[1]),
+				_Get_ValAtPos_BSpline(dx, dy, z_xy[2]),
+				_Get_ValAtPos_BSpline(dx, dy, z_xy[3])
+			));
+		}
+	}
+
+	return( m_NoData_Value );
+}
+
+//---------------------------------------------------------
+inline bool CSG_Grid::_Get_ValAtPos_Fill4x4Submatrix(int x, int y, double z_xy[4][4]) const
+{
+	int		ix, iy, jx, jy, nNoData;
+
+	for(iy=0, jy=y-1, nNoData=0; iy<4; iy++, jy++)
+	{
+		for(ix=0, jx=x-1; ix<4; ix++, jx++)
+		{
+			if( is_InGrid(jx, jy) )
+			{
+				z_xy[ix][iy]	= asDouble(jx, jy);
+			}
+			else
+			{
+				z_xy[ix][iy]	= m_NoData_Value;
+
+				nNoData++;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( nNoData >= 16 )
+	{
+		return( false );
+	}
+
+	if( nNoData > 0 )
+	{
+		double	t_xy[4][4];
+
+		for(iy=0; iy<4; iy++)
+		{
+			for(ix=0; ix<4; ix++)
+			{
+				t_xy[ix][iy]	= z_xy[ix][iy];
+			}
+		}
+
+		do
+		{
+			for(iy=0; iy<4; iy++)
+			{
+				for(ix=0; ix<4; ix++)
+				{
+					if( z_xy[ix][iy] == m_NoData_Value )
+					{
+						int		n	= 0;
+
+						for(jy=iy-1; jy<=iy+1; jy++)
+						{
+							if( jy >= 0 && jy < 4 )
+							{
+								for(jx=ix-1; jx<=ix+1; jx++)
+								{
+									if( jx >= 0 && jx < 4 && !(jx == ix && jy == iy) && z_xy[jx][jy] != m_NoData_Value )
+									{
+										if( n == 0 )
+										{
+											t_xy[ix][iy]	 = z_xy[jx][jy];
+										}
+										else
+										{
+											t_xy[ix][iy]	+= z_xy[jx][jy];
+										}
+
+										n++;
+									}
+								}
+							}
+						}
+
+						if( n > 0 )
+						{
+							if( n > 1 )
+							{
+								t_xy[ix][iy]	/= n;
+							}
+
+							nNoData--;
+						}
+					}
+				}
+			}
+
+			for(iy=0; iy<4; iy++)
+			{
+				for(ix=0; ix<4; ix++)
+				{
+					if( t_xy[ix][iy] != z_xy[ix][iy] )
+					{
+						z_xy[ix][iy]	= t_xy[ix][iy];
+					}
+				}
+			}
+		}
+		while( nNoData > 0 );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CSG_Grid::_Get_ValAtPos_Fill4x4Submatrix(int x, int y, double z_xy[4][4][4]) const
+{
+	int		ix, iy, jx, jy, nNoData;
+
+	for(iy=0, jy=y-1, nNoData=0; iy<4; iy++, jy++)
+	{
+		for(ix=0, jx=x-1; ix<4; ix++, jx++)
+		{
+			if( is_InGrid(jx, jy) )
+			{
+				int		v	= asInt(jx, jy);
+
+				z_xy[0][ix][iy]	= SG_GET_BYTE_0(v);
+				z_xy[1][ix][iy]	= SG_GET_BYTE_1(v);
+				z_xy[2][ix][iy]	= SG_GET_BYTE_2(v);
+				z_xy[3][ix][iy]	= SG_GET_BYTE_3(v);
+			}
+			else
+			{
+				z_xy[0][ix][iy]	= m_NoData_Value;
+
+				nNoData++;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( nNoData >= 16 )
+	{
+		return( false );
+	}
+
+	if( nNoData > 0 )
+	{
+		double	t_xy[4][4][4];
+
+		for(iy=0; iy<4; iy++)
+		{
+			for(ix=0; ix<4; ix++)
+			{
+				t_xy[0][ix][iy]	= z_xy[0][ix][iy];
+				t_xy[1][ix][iy]	= z_xy[1][ix][iy];
+				t_xy[2][ix][iy]	= z_xy[2][ix][iy];
+				t_xy[3][ix][iy]	= z_xy[3][ix][iy];
+			}
+		}
+
+		do
+		{
+			for(iy=0; iy<4; iy++)
+			{
+				for(ix=0; ix<4; ix++)
+				{
+					if( z_xy[0][ix][iy] == m_NoData_Value )
+					{
+						int		n	= 0;
+
+						for(jy=iy-1; jy<=iy+1; jy++)
+						{
+							if( jy >= 0 && jy < 4 )
+							{
+								for(jx=ix-1; jx<=ix+1; jx++)
+								{
+									if( jx >= 0 && jx < 4 && !(jx == ix && jy == iy) && z_xy[0][jx][jy] != m_NoData_Value )
+									{
+										if( n == 0 )
+										{
+											t_xy[0][ix][iy]	 = z_xy[0][jx][jy];
+											t_xy[1][ix][iy]	 = z_xy[1][jx][jy];
+											t_xy[2][ix][iy]	 = z_xy[2][jx][jy];
+											t_xy[3][ix][iy]	 = z_xy[3][jx][jy];
+										}
+										else
+										{
+											t_xy[0][ix][iy]	+= z_xy[0][jx][jy];
+											t_xy[1][ix][iy]	+= z_xy[1][jx][jy];
+											t_xy[2][ix][iy]	+= z_xy[2][jx][jy];
+											t_xy[3][ix][iy]	+= z_xy[3][jx][jy];
+										}
+
+										n++;
+									}
+								}
+							}
+						}
+
+						if( n > 0 )
+						{
+							if( n > 1 )
+							{
+								t_xy[0][ix][iy]	/= n;
+								t_xy[1][ix][iy]	/= n;
+								t_xy[2][ix][iy]	/= n;
+								t_xy[3][ix][iy]	/= n;
+							}
+
+							nNoData--;
+						}
+					}
+				}
+			}
+
+			for(iy=0; iy<4; iy++)
+			{
+				for(ix=0; ix<4; ix++)
+				{
+					if( t_xy[0][ix][iy] != z_xy[0][ix][iy] )
+					{
+						z_xy[0][ix][iy]	= t_xy[0][ix][iy];
+						z_xy[1][ix][iy]	= t_xy[1][ix][iy];
+						z_xy[2][ix][iy]	= t_xy[2][ix][iy];
+						z_xy[3][ix][iy]	= t_xy[3][ix][iy];
+					}
+				}
+			}
+		}
+		while( nNoData > 0 );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Statistics						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Grid::Get_ZMin(bool bZFactor)
+{
+	Update();	return( (bZFactor ? m_zFactor : 1.0) * m_zStats.Get_Minimum() );
+}
+
+double CSG_Grid::Get_ZMax(bool bZFactor)
+{
+	Update();	return( (bZFactor ? m_zFactor : 1.0) * m_zStats.Get_Maximum() );
+}
+
+double CSG_Grid::Get_ZRange(bool bZFactor)
+{
+	Update();	return( (bZFactor ? m_zFactor : 1.0) * m_zStats.Get_Range() );
+}
+
+double CSG_Grid::Get_ArithMean(bool bZFactor)
+{
+	Update();	return( (bZFactor ? m_zFactor : 1.0) * m_zStats.Get_Mean() );
+}
+
+double CSG_Grid::Get_StdDev(bool bZFactor)
+{
+	Update();	return( (bZFactor ? m_zFactor : 1.0) * m_zStats.Get_StdDev() );
+}
+
+double CSG_Grid::Get_Variance(void)
+{
+	Update();	return( m_zStats.Get_Variance() );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::On_Update(void)
+{
+	if( is_Valid() )
+	{
+		m_zStats.Invalidate();
+
+		for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+		{
+			for(int x=0; x<Get_NX(); x++)
+			{
+				double	z	= asDouble(x, y);
+
+				if( !is_NoData_Value(z) )
+				{
+					m_zStats.Add_Value(z);
+				}
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Index							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::Set_Value_And_Sort(long n, double Value)
+{
+	if( !m_bIndexed )
+	{
+		Set_Value(n, Value);
+
+		Set_Index(true);
+
+		return;
+	}
+
+	//-----------------------------------------------------
+	if( Value == asDouble(n) )
+		return;
+
+	long	i, j;
+
+	for(i=0, j=-1; i<Get_NCells() && j<0; i++)	// find index, could be faster...
+	{
+		if( n == m_Index[i] )
+		{
+			j	= i;
+		}
+	}
+
+	if( j > 0 )
+	{
+		if( Value < asDouble(n) )
+		{
+			for(i=j-1; i>=0; i--, j--)
+			{
+				if( Value < asDouble(m_Index[i]) )
+				{
+					m_Index[j]	= m_Index[i];
+				}
+				else
+				{
+					m_Index[j]	= n;
+					break;
+				}
+			}
+		}
+		else
+		{
+			for(i=j+1; i<Get_NCells(); i++, j++)
+			{
+				if( Value > asDouble(m_Index[i]) )
+				{
+					m_Index[j]	= m_Index[i];
+				}
+				else
+				{
+					m_Index[j]	= n;
+					break;
+				}
+			}
+		}
+
+		Set_Value(n, Value);
+
+		m_bIndexed	= true;
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::Set_Value_And_Sort(int x, int y, double Value)
+{
+	Set_Value_And_Sort(x + y * Get_NX(), Value);
+}
+
+//---------------------------------------------------------
+double CSG_Grid::Get_Percentile(double Percent, bool bZFactor)
+{
+	int		x, y;
+
+	if( Percent < 0.0 )
+	{
+		Percent	= 0.0;
+	}
+	else if( Percent > 100.0 )
+	{
+		Percent	= 100.0;
+	}
+
+	if( Get_Sorted((int)(Percent * Get_NCells() / 100.0), x, y, true) )
+	{
+		return( asDouble(x, y, bZFactor) );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Set_Index(bool bOn)
+{
+	if( bOn && !m_bIndexed )
+	{
+		m_bIndexed	= true;
+
+		if( _Set_Index() == false )
+		{
+			Set_Index(false);
+
+			return( false );
+		}
+	}
+	else if( !bOn )
+	{
+		m_bIndexed	= false;
+
+		if( m_Index )
+		{
+			SG_Free(m_Index);
+			m_Index		= NULL;
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+#define SORT_SWAP(a,b)	{itemp=(a);(a)=(b);(b)=itemp;}
+
+bool CSG_Grid::_Set_Index(void)
+{
+	const int	M	= 7;
+
+	int		i, j, k, l, ir, n, nCells, *istack, jstack, nstack, indxt, itemp;
+	double	a;
+
+	//-----------------------------------------------------
+	SG_UI_Process_Set_Text(CSG_String::Format(SG_T("%s: %s"), LNG("Create index"), Get_Name()));
+
+	if( m_Index == NULL )
+	{
+		m_Index		= (long *)SG_Calloc(Get_NCells(), sizeof(long));
+
+		if( m_Index == NULL )
+		{
+			SG_UI_Process_Set_Ready();
+
+			return( false );
+		}
+
+		for(i=0, l=0; i<Get_NCells(); i++)
+		{
+			if(  is_NoData(i) )
+			{
+				m_Index[l++]	= i;
+			}
+		}
+
+		for(i=0, j=l; i<Get_NCells(); i++)
+		{
+			if( !is_NoData(i) )
+			{
+				m_Index[j++]	= i;
+			}
+		}
+	}
+	else
+	{
+		l	= 0;
+	}
+
+	//-----------------------------------------------------
+	if( (nCells = Get_NCells() - l) <= 1 )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	n		= 0;
+	ir		= Get_NCells() - 1;
+
+	nstack	= 64;
+	istack	= (int *)SG_Malloc(nstack * sizeof(int));
+	jstack	= 0;
+
+	for(;;)
+	{
+		if( ir - l < M )
+		{
+			if( !SG_UI_Process_Set_Progress(n += M - 1, nCells) )
+			{
+				SG_Free(istack);
+
+				return( false );
+			}
+
+			for(j=l+1; j<=ir; j++)
+			{
+				indxt	= m_Index[j];
+				a		= asDouble(indxt);
+
+				for(i=j-1; i>=0; i--)
+				{
+					if( asDouble(m_Index[i]) <= a )
+					{
+						break;
+					}
+
+					m_Index[i + 1]	= m_Index[i];
+				}
+
+				m_Index[i + 1]	= indxt;
+			}
+
+			if( jstack == 0 )
+			{
+				break;
+			}
+
+			ir		= istack[jstack--];
+			l		= istack[jstack--];
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			k		= (l + ir) >> 1;
+
+			SORT_SWAP(m_Index[k], m_Index[l + 1]);
+
+			if( asDouble( m_Index[l + 1]) > asDouble(m_Index[ir]) )
+				SORT_SWAP(m_Index[l + 1],            m_Index[ir]);
+
+			if( asDouble( m_Index[l    ]) > asDouble(m_Index[ir]) )
+				SORT_SWAP(m_Index[l    ],            m_Index[ir]);
+
+			if( asDouble( m_Index[l + 1]) > asDouble(m_Index[l ]) )
+				SORT_SWAP(m_Index[l + 1],            m_Index[l ]);
+
+			i		= l + 1;
+			j		= ir;
+			indxt	= m_Index[l];
+			a		= asDouble(indxt);
+
+			for(;;)
+			{
+				do	i++;	while(asDouble(m_Index[i]) < a);
+				do	j--;	while(asDouble(m_Index[j]) > a);
+
+				if( j < i )
+				{
+					break;
+				}
+
+				SORT_SWAP(m_Index[i], m_Index[j]);
+			}
+
+			m_Index[l]	= m_Index[j];
+			m_Index[j]	= indxt;
+			jstack		+= 2;
+
+			if( jstack >= nstack )
+			{
+				nstack	+= 64;
+				istack	= (int *)SG_Realloc(istack, nstack * sizeof(int));
+			}
+
+			if( ir - i + 1 >= j - l )
+			{
+				istack[jstack]		= ir;
+				istack[jstack - 1]	= i;
+				ir					= j - 1;
+			}
+			else
+			{
+				istack[jstack]		= j - 1;
+				istack[jstack - 1]	= l;
+				l					= i;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(istack);
+
+	SG_UI_Process_Set_Ready();
+
+	return( true );
+}
+#undef SORT_SWAP
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,912 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        grid.h                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__grid_H
+#define HEADER_INCLUDED__SAGA_API__grid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dataobject.h"
+
+#include "grid_pyramid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Memory Handling						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_Memory_Type
+{
+	GRID_MEMORY_Normal					= 0,
+	GRID_MEMORY_Cache,
+	GRID_MEMORY_Compression
+}
+TSG_Grid_Memory_Type;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Grid File						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_File_Format
+{
+	GRID_FILE_FORMAT_Undefined			= 0,
+	GRID_FILE_FORMAT_Binary,
+	GRID_FILE_FORMAT_ASCII
+}
+TSG_Grid_File_Format;
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_File_Key
+{
+	GRID_FILE_KEY_NAME					= 0,
+	GRID_FILE_KEY_DESCRIPTION,
+	GRID_FILE_KEY_UNITNAME,
+	GRID_FILE_KEY_DATAFILE_NAME,
+	GRID_FILE_KEY_DATAFILE_OFFSET,
+	GRID_FILE_KEY_DATAFORMAT,
+	GRID_FILE_KEY_BYTEORDER_BIG,
+	GRID_FILE_KEY_POSITION_XMIN,
+	GRID_FILE_KEY_POSITION_YMIN,
+	GRID_FILE_KEY_CELLCOUNT_X,
+	GRID_FILE_KEY_CELLCOUNT_Y,
+	GRID_FILE_KEY_CELLSIZE,
+	GRID_FILE_KEY_Z_FACTOR,
+	GRID_FILE_KEY_NODATA_VALUE,
+	GRID_FILE_KEY_TOPTOBOTTOM,
+	GRID_FILE_KEY_Count
+}
+TSG_Grid_File_Key;
+
+//---------------------------------------------------------
+const SG_Char	gSG_Grid_File_Key_Names[GRID_FILE_KEY_Count][32]	=
+{
+	SG_T("NAME"),
+	SG_T("DESCRIPTION"),
+	SG_T("UNIT"),
+	SG_T("DATAFILE_NAME"),
+	SG_T("DATAFILE_OFFSET"),
+	SG_T("DATAFORMAT"),
+	SG_T("BYTEORDER_BIG"),
+	SG_T("POSITION_XMIN"),
+	SG_T("POSITION_YMIN"),
+	SG_T("CELLCOUNT_X"),
+	SG_T("CELLCOUNT_Y"),
+	SG_T("CELLSIZE"),
+	SG_T("Z_FACTOR"),
+	SG_T("NODATA_VALUE"),
+	SG_T("TOPTOBOTTOM")
+};
+
+//---------------------------------------------------------
+#define GRID_FILE_KEY_TRUE		SG_T("TRUE")
+#define GRID_FILE_KEY_FALSE		SG_T("FALSE")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_Interpolation
+{
+	GRID_INTERPOLATION_NearestNeighbour	= 0,
+	GRID_INTERPOLATION_Bilinear,
+	GRID_INTERPOLATION_InverseDistance,
+	GRID_INTERPOLATION_BicubicSpline,
+	GRID_INTERPOLATION_BSpline,
+
+	GRID_INTERPOLATION_Mean_Nodes,
+	GRID_INTERPOLATION_Mean_Cells,
+	GRID_INTERPOLATION_Minimum,
+	GRID_INTERPOLATION_Maximum,
+
+	GRID_INTERPOLATION_Undefined
+}
+TSG_Grid_Interpolation;
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_Operation
+{
+	GRID_OPERATION_Addition				= 0,
+	GRID_OPERATION_Subtraction,
+	GRID_OPERATION_Multiplication,
+	GRID_OPERATION_Division
+}
+TSG_Grid_Operation;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					CSG_Grid_System						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Grid_System is used by the CSG_Grid class to provide
+  * information about the number of rows and columns, the
+  * cell size and the georeference, which define the grid.
+  * It offers various functions, which help when working
+  * with grids.
+  * @see CSG_Grid
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Grid_System
+{
+public:
+	CSG_Grid_System(void);
+	CSG_Grid_System(const CSG_Grid_System &System);
+	CSG_Grid_System(double Cellsize, const CSG_Rect &Extent);
+	CSG_Grid_System(double Cellsize, double xMin, double yMin, double xMax, double yMax);
+	CSG_Grid_System(double Cellsize, double xMin, double yMin, int NX, int NY);
+
+	~CSG_Grid_System(void);
+
+
+	//-----------------------------------------------------
+	bool						is_Valid			(void)	const;
+
+	const SG_Char *				Get_Name			(bool bShort = true);
+
+	double						Get_Cellsize		(void)	const	{	return( m_Cellsize );				}
+	double						Get_Cellarea		(void)	const	{	return( m_Cellarea );				}
+	const CSG_Rect &			Get_Extent			(void)	const	{	return( m_Extent );					}
+	const CSG_Rect &			Get_Extent_Cells	(void)	const	{	return( m_Extent_Cells );			}
+
+	int							Get_NX				(void)	const	{	return( m_NX );						}
+	int							Get_NY				(void)	const	{	return( m_NY );						}
+	long						Get_NCells			(void)	const	{	return( m_NCells );					}
+
+	double						Get_XMin			(void)	const	{	return( m_Extent.m_rect.xMin );		}
+	double						Get_XMax			(void)	const	{	return( m_Extent.m_rect.xMax );		}
+	double						Get_XRange			(void)	const	{	return( m_Extent.Get_XRange() );	}
+
+	double						Get_YMin			(void)	const	{	return( m_Extent.m_rect.yMin );		}
+	double						Get_YMax			(void)	const	{	return( m_Extent.m_rect.yMax );		}
+	double						Get_YRange			(void)	const	{	return( m_Extent.Get_YRange() );	}
+
+
+	//-----------------------------------------------------
+	bool						operator ==			(const CSG_Grid_System &System) const;
+	void						operator =			(const CSG_Grid_System &System);
+
+	bool						Assign				(const CSG_Grid_System &System);
+	bool						Assign				(double Cellsize, const CSG_Rect &Extent);
+	bool						Assign				(double Cellsize, double xMin, double yMin, double xMax, double yMax);
+	bool						Assign				(double Cellsize, double xMin, double yMin, int NX, int NY);
+
+	bool						is_Equal			(const CSG_Grid_System &System) const;
+	bool						is_Equal			(double Cellsize, const TSG_Rect &Extent) const;
+
+
+	//-----------------------------------------------------
+	/// Aligns the world coordinate x to the rows of the grid system and returns it.
+	double						Fit_xto_Grid_System	(double x)	const	{	return( Get_XMin() + m_Cellsize * (int)(0.5 + (x - Get_XMin()) / m_Cellsize) );	}
+
+	/// Aligns the world coordinate y to the columns of the grid system and returns it.
+	double						Fit_yto_Grid_System	(double y)	const	{	return( Get_YMin() + m_Cellsize * (int)(0.5 + (y - Get_YMin()) / m_Cellsize) );	}
+
+	/// Aligns the world coordinate ptWorld to the rows and columns of the grid system and returns it.
+	TSG_Point					Fit_to_Grid_System	(TSG_Point ptWorld)	const
+	{
+		ptWorld.x	= Fit_xto_Grid_System(ptWorld.x);
+		ptWorld.y	= Fit_yto_Grid_System(ptWorld.y);
+
+		return( ptWorld );
+	}
+
+
+	//-----------------------------------------------------
+	double						Get_xGrid_to_World	(int xGrid)	const	{	return( Get_XMin() + xGrid * m_Cellsize );	}
+	double						Get_yGrid_to_World	(int yGrid)	const	{	return( Get_YMin() + yGrid * m_Cellsize );	}
+
+	TSG_Point					Get_Grid_to_World	(int xGrid, int yGrid)	const
+	{
+		TSG_Point	pt;
+
+		pt.x	= Get_xGrid_to_World(xGrid);
+		pt.y	= Get_yGrid_to_World(yGrid);
+
+		return( pt );
+	}
+
+
+	//-----------------------------------------------------
+	int							Get_xWorld_to_Grid	(double xWorld)	const	{	return( (int)(0.5 + (xWorld - Get_XMin()) / m_Cellsize) );	}
+	int							Get_yWorld_to_Grid	(double yWorld)	const	{	return( (int)(0.5 + (yWorld - Get_YMin()) / m_Cellsize) );	}
+
+	bool						Get_World_to_Grid	(int &xGrid, int &yGrid, double xWorld, double yWorld)	const
+	{
+		return( is_InGrid(xGrid = Get_xWorld_to_Grid(xWorld), yGrid = Get_yWorld_to_Grid(yWorld)) );
+	}
+
+	bool						Get_World_to_Grid	(int &xGrid, int &yGrid, TSG_Point ptWorld)	const
+	{
+		return( is_InGrid(xGrid = Get_xWorld_to_Grid(ptWorld.x), yGrid = Get_yWorld_to_Grid(ptWorld.y)) );
+	}
+
+
+	//-----------------------------------------------------
+	bool						Get_Neighbor_Pos	(int Direction, int x, int y, int &xPos, int &yPos)	const
+	{
+		return( is_InGrid(xPos = Get_xTo(Direction, x), yPos = Get_yTo(Direction, y)) );
+	}
+
+	int							Get_xTo				(int Direction, int x = 0)	const
+	{
+		static int	ix[8]	= { 0, 1, 1, 1, 0,-1,-1,-1 };
+
+		Direction	%= 8;
+
+		if( Direction < 0 )
+		{
+			Direction	+= 8;
+		}
+
+		return( x + ix[Direction] );
+	}
+
+	int							Get_yTo				(int Direction, int y = 0)	const
+	{
+		static int	iy[8]	= { 1, 1, 0,-1,-1,-1, 0, 1 };
+
+		Direction	%= 8;
+
+		if( Direction < 0 )
+		{
+			Direction	+= 8;
+		}
+
+		return( y + iy[Direction] );
+	}
+
+	int							Get_xFrom			(int Direction, int x = 0)	const	{	return( Get_xTo(Direction + 4, x) );	}
+	int							Get_yFrom			(int Direction, int y = 0)	const	{	return( Get_yTo(Direction + 4, y) );	}
+	int							Get_xToSave			(int Direction, int x)		const	{	return( (x = Get_xTo  (Direction, x)) < 0 ? 0 : (x >= m_NX ? m_NX - 1 : x) );	}
+	int							Get_yToSave			(int Direction, int y)		const	{	return( (y = Get_yTo  (Direction, y)) < 0 ? 0 : (y >= m_NY ? m_NY - 1 : y) );	}
+	int							Get_xFromSave		(int Direction, int x)		const	{	return( (x = Get_xFrom(Direction, x)) < 0 ? 0 : (x >= m_NX ? m_NX - 1 : x) );	}
+	int							Get_yFromSave		(int Direction, int y)		const	{	return( (y = Get_yFrom(Direction, y)) < 0 ? 0 : (y >= m_NY ? m_NY - 1 : y) );	}
+
+	bool						is_InGrid			(int x, int y)				const	{	return(	x >= 0    && x < m_NX        && y >= 0    && y < m_NY );		}
+	bool						is_InGrid			(int x, int y, int Rand)	const	{	return(	x >= Rand && x < m_NX - Rand && y >= Rand && y < m_NY - Rand );	}
+
+	double						Get_Length			(int Direction)				const	{	return( Direction % 2 ? m_Diagonal : m_Cellsize );	}
+	double						Get_UnitLength		(int Direction)				const	{	return( Direction % 2 ? sqrt(2.0)  : 1.0 );			}
+
+
+private:	///////////////////////////////////////////////
+
+	int							m_NX, m_NY, m_NCells;
+
+	double						m_Cellsize, m_Cellarea, m_Diagonal;
+
+	CSG_Rect					m_Extent, m_Extent_Cells;
+
+	CSG_String					m_Name;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						CSG_Grid						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Grid is the data object created for raster handling.
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Grid : public CSG_Data_Object
+{
+//---------------------------------------------------------
+public:		///////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	CSG_Grid(void);
+
+								CSG_Grid	(const CSG_Grid &Grid);
+	bool						Create		(const CSG_Grid &Grid);
+
+								CSG_Grid	(const CSG_String &File_Name, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+	bool						Create		(const CSG_String &File_Name, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+								CSG_Grid	(CSG_Grid *pGrid, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+	bool						Create		(CSG_Grid *pGrid, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+								CSG_Grid	(const CSG_Grid_System &System, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+	bool						Create		(const CSG_Grid_System &System, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+								CSG_Grid	(TSG_Data_Type Type, int NX, int NY, double Cellsize = 0.0, double xMin = 0.0, double yMin = 0.0, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+	bool						Create		(TSG_Data_Type Type, int NX, int NY, double Cellsize = 0.0, double xMin = 0.0, double yMin = 0.0, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+
+	//-----------------------------------------------------
+	virtual ~CSG_Grid(void);
+
+	virtual bool				Destroy	(void);
+
+
+	//-----------------------------------------------------
+	/** Data object type information.
+	*/
+	virtual TSG_Data_Object_Type	Get_ObjectType	(void)	const	{	return( DATAOBJECT_TYPE_Grid );		}
+
+
+	//-----------------------------------------------------
+	// Data-Info...
+
+	TSG_Data_Type				Get_Type		(void)	const	{	return( m_Type );					}
+
+	int							Get_nValueBytes	(void)	const	{	return( SG_Data_Type_Get_Size(m_Type) );	}
+
+	void						Set_Description	(const SG_Char *String);
+	const SG_Char *				Get_Description	(void)	const;
+
+	void						Set_Unit		(const SG_Char *String);
+	const SG_Char *				Get_Unit		(void)	const;
+
+	const CSG_Grid_System &		Get_System		(void)	const	{	return( m_System );					}
+
+	int							Get_NX			(void)	const	{	return( m_System.Get_NX() );		}
+	int							Get_NY			(void)	const	{	return( m_System.Get_NY() );		}
+	long						Get_NCells		(void)	const	{	return( m_System.Get_NCells() );	}
+
+	double						Get_Cellsize	(void)	const	{	return( m_System.Get_Cellsize() );	}
+	double						Get_Cellarea	(void)	const	{	return( m_System.Get_Cellarea() );	}
+
+	const CSG_Rect &			Get_Extent		(void)	const	{	return( m_System.Get_Extent() );	}
+
+	double						Get_XMin		(void)	const	{	return( m_System.Get_XMin() );		}
+	double						Get_XMax		(void)	const	{	return( m_System.Get_XMax() );		}
+	double						Get_XRange		(void)	const	{	return( m_System.Get_XRange() );	}
+
+	double						Get_YMin		(void)	const	{	return( m_System.Get_YMin() );		}
+	double						Get_YMax		(void)	const	{	return( m_System.Get_YMax() );		}
+	double						Get_YRange		(void)	const	{	return( m_System.Get_YRange() );	}
+
+	double						Get_ZMin		(bool bZFactor = false);
+	double						Get_ZMax		(bool bZFactor = false);
+	double						Get_ZRange		(bool bZFactor = false);
+
+	void						Set_ZFactor		(double Value);
+	double						Get_ZFactor		(void)	const;
+
+	double						Get_ArithMean	(bool bZFactor = false);
+	double						Get_StdDev		(bool bZFactor = false);
+	double						Get_Variance	(void);
+
+	void						Set_NoData_Value		(double Value);
+	void						Set_NoData_Value_Range	(double loValue, double hiValue);
+	double						Get_NoData_Value		(void)	const	{	return( m_NoData_Value );			}
+	double						Get_NoData_hiValue		(void)	const	{	return( m_NoData_hiValue );			}
+
+	virtual bool				Save	(const CSG_String &File_Name, int Format = GRID_FILE_FORMAT_Binary);
+	virtual bool				Save	(const CSG_String &File_Name, int Format, int xA, int yA, int xN, int yN);
+
+
+	//-----------------------------------------------------
+	// Checks...
+
+	virtual bool				is_Valid		(void)	const;
+
+	TSG_Intersection			is_Intersecting	(const CSG_Rect &Extent) const;
+	TSG_Intersection			is_Intersecting	(const TSG_Rect &Extent) const;
+	TSG_Intersection			is_Intersecting	(double xMin, double yMin, double xMax, double yMax) const;
+
+	bool						is_Compatible	(CSG_Grid *pGrid) const;
+	bool						is_Compatible	(const CSG_Grid_System &System) const;
+	bool						is_Compatible	(int NX, int NY, double Cellsize, double xMin, double yMin) const;
+
+	bool						is_InGrid(int x, int y, bool bCheckNoData = true)	const	{	return( m_System.is_InGrid(x, y) && (!bCheckNoData || (bCheckNoData && !is_NoData(x, y))) );	}
+	bool						is_InGrid_byPos	(double xPos, double yPos)			const	{	return( xPos >= Get_XMin() && xPos <= Get_XMax() && yPos >= Get_YMin() && yPos <= Get_YMax() );	}
+	bool						is_InGrid_byPos	(TSG_Point Position)				const	{	return( is_InGrid_byPos(Position.x, Position.y) );	}
+
+
+	//-----------------------------------------------------
+	// Memory...
+
+	int							Get_Buffer_Size				(void)					{	return( LineBuffer_Count * _LineBuffer_Get_nBytes() );	}
+	bool						Set_Buffer_Size				(int Size);
+
+	bool						Set_Cache					(bool bOn);
+	bool						is_Cached					(void);
+
+	bool						Set_Compression				(bool bOn);
+	bool						is_Compressed				(void);
+	double						Get_Compression_Ratio		(void);
+
+
+	//-----------------------------------------------------
+	// Operations...
+
+	void						Assign_NoData				(void);
+
+	virtual bool				Assign						(double Value = 0.0);
+	virtual bool				Assign						(CSG_Data_Object *pObject);
+	virtual bool				Assign						(CSG_Grid *pGrid, TSG_Grid_Interpolation Interpolation);
+
+	void						Flip						(void);
+	void						Mirror						(void);
+	void						Invert						(void);
+
+	void						Normalise					(void);
+	void						DeNormalise					(double ArithMean, double Variance);
+
+	int							Get_Gradient_NeighborDir	(int x, int y, bool bMustBeLower = true)			const;
+	bool						Get_Gradient				(int x, int y, double &Decline, double &Azimuth)	const;
+
+
+	//-----------------------------------------------------
+	// Set update flag when modified...
+
+	virtual void				Set_Modified	(bool bFlag = true)
+	{
+		CSG_Data_Object::Set_Modified(bFlag);
+
+		if( bFlag )
+		{
+			Set_Update_Flag();
+
+			m_bIndexed	= false;
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// Index...
+
+	bool						Set_Index		(bool bOn = false);
+
+	long						Get_Sorted		(long Position, bool bDown = true, bool bCheckNoData = true)
+	{
+		if( Position >= 0 && Position < Get_NCells() && (m_bIndexed || Set_Index(true)) )
+		{
+			Position	= m_Index[bDown ? Get_NCells() - Position - 1 : Position];
+
+			if( !bCheckNoData || !is_NoData(Position) )
+			{
+				return( Position );
+			}
+		}
+
+		return( -1 );
+	}
+
+	bool						Get_Sorted		(long Position, long &n, bool bDown = true, bool bCheckNoData = true)
+	{
+		return( (n = Get_Sorted(Position, bDown, bCheckNoData)) >= 0 );
+	}
+
+	bool						Get_Sorted		(long Position, int &x, int &y, bool bDown = true, bool bCheckNoData = true)
+	{
+		if( (Position = Get_Sorted(Position, bDown, bCheckNoData)) >= 0 )
+		{
+			x	= (int)(Position % Get_NX());
+			y	= (int)(Position / Get_NX());
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	double						Get_Percentile	(double Percent, bool bZFactor = false);
+
+
+	//-----------------------------------------------------
+	// No Data Value...
+
+	virtual bool				is_NoData_Value	(double Value)	const
+	{
+		return( m_NoData_Value < m_NoData_hiValue ? m_NoData_Value <= Value && Value <= m_NoData_hiValue : Value == m_NoData_Value );
+	}
+
+	virtual bool				is_NoData		(int x, int y)	const	{	return( is_NoData_Value(asDouble(x, y)) );	}
+	virtual bool				is_NoData		(long n)		const	{	return( is_NoData_Value(asDouble(   n)) );	}
+
+	virtual void				Set_NoData		(int x, int y)	{	Set_Value(x, y, m_NoData_Value );	}
+	virtual void				Set_NoData		(long n)		{	Set_Value(   n, m_NoData_Value );	}
+
+
+	//-----------------------------------------------------
+	// Operators...
+
+	virtual CSG_Grid &			operator  =		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			operator  =		(double Value);
+
+	virtual CSG_Grid			operator +		(const CSG_Grid &Grid)	const;
+	virtual CSG_Grid			operator +		(double Value)			const;
+	virtual CSG_Grid &			operator +=		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			operator +=		(double Value);
+	virtual CSG_Grid &			Add				(const CSG_Grid &Grid);
+	virtual CSG_Grid &			Add				(double Value);
+
+	virtual CSG_Grid			operator -		(const CSG_Grid &Grid)	const;
+	virtual CSG_Grid			operator -		(double Value)			const;
+	virtual CSG_Grid &			operator -=		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			operator -=		(double Value);
+	virtual CSG_Grid &			Subtract		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			Subtract		(double Value);
+
+	virtual CSG_Grid			operator *		(const CSG_Grid &Grid)	const;
+	virtual CSG_Grid			operator *		(double Value)			const;
+	virtual CSG_Grid &			operator *=		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			operator *=		(double Value);
+	virtual CSG_Grid &			Multiply		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			Multiply		(double Value);
+
+	virtual CSG_Grid			operator /		(const CSG_Grid &Grid)	const;
+	virtual CSG_Grid			operator /		(double Value)			const;
+	virtual CSG_Grid &			operator /=		(const CSG_Grid &Grid);
+	virtual CSG_Grid &			operator /=		(double Value);
+	virtual CSG_Grid &			Divide			(const CSG_Grid &Grid);
+	virtual CSG_Grid &			Divide			(double Value);
+
+	virtual double				operator ()		(int x, int y) const	{	return( asDouble(x, y) );	}
+
+
+	//-----------------------------------------------------
+	// Get Value...
+
+	double						Get_Value(double xPos, double yPos,                int Interpolation = GRID_INTERPOLATION_BSpline, bool bZFactor = false, bool bByteWise = false, bool bOnlyValidCells = false) const;
+	double						Get_Value(TSG_Point Position      ,                int Interpolation = GRID_INTERPOLATION_BSpline, bool bZFactor = false, bool bByteWise = false, bool bOnlyValidCells = false) const;
+	bool						Get_Value(double xPos, double yPos, double &Value, int Interpolation = GRID_INTERPOLATION_BSpline, bool bZFactor = false, bool bByteWise = false, bool bOnlyValidCells = false) const;
+	bool						Get_Value(TSG_Point Position      , double &Value, int Interpolation = GRID_INTERPOLATION_BSpline, bool bZFactor = false, bool bByteWise = false, bool bOnlyValidCells = false) const;
+
+	virtual BYTE				asByte	(int x, int y, bool bZFactor = false) const	{	return( (BYTE )asDouble(x, y, bZFactor) );	}
+	virtual BYTE				asByte	(      long n, bool bZFactor = false) const	{	return( (BYTE )asDouble(   n, bZFactor) );	}
+	virtual char				asChar	(int x, int y, bool bZFactor = false) const	{	return( (char )asDouble(x, y, bZFactor) );	}
+	virtual char				asChar	(      long n, bool bZFactor = false) const	{	return( (char )asDouble(   n, bZFactor) );	}
+	virtual short				asShort	(int x, int y, bool bZFactor = false) const	{	return( (short)asDouble(x, y, bZFactor) );	}
+	virtual short				asShort	(      long n, bool bZFactor = false) const	{	return( (short)asDouble(   n, bZFactor) );	}
+	virtual int					asInt	(int x, int y, bool bZFactor = false) const	{	return( (int  )asDouble(x, y, bZFactor) );	}
+	virtual int					asInt	(      long n, bool bZFactor = false) const	{	return( (int  )asDouble(   n, bZFactor) );	}
+	virtual float				asFloat	(int x, int y, bool bZFactor = false) const	{	return( (float)asDouble(x, y, bZFactor) );	}
+	virtual float				asFloat	(      long n, bool bZFactor = false) const	{	return( (float)asDouble(   n, bZFactor) );	}
+
+	//-----------------------------------------------------
+	virtual double				asDouble(      long n, bool bZFactor = false) const
+	{
+		return( asDouble(n % Get_NX(), n / Get_NX(), bZFactor) );
+	}
+
+	virtual double				asDouble(int x, int y, bool bZFactor = false) const
+	{
+		double	Result;
+
+		if( m_Memory_Type == GRID_MEMORY_Normal )
+		{
+			switch( m_Type )
+			{
+				default:				Result	= 0.0;							break;
+				case SG_DATATYPE_Byte:	Result	= ((BYTE   **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Char:	Result	= ((char   **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Word:	Result	= ((WORD   **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Short:	Result	= ((short  **)m_Values)[y][x];	break;
+				case SG_DATATYPE_DWord:	Result	= ((DWORD  **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Int:		Result	= ((int    **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Float:	Result	= ((float  **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Double:	Result	= ((double **)m_Values)[y][x];	break;
+				case SG_DATATYPE_Bit:		Result	=(((BYTE   **)m_Values)[y][x / 8] & m_Bitmask[x % 8]) == 0 ? 0.0 : 1.0;	break;
+			}
+		}
+		else
+		{
+			Result	= _LineBuffer_Get_Value(x, y);
+		}
+
+		if( bZFactor )
+		{
+			Result	*= m_zFactor;
+		}
+
+		return( Result );
+	}
+
+
+	//-----------------------------------------------------
+	// Set Value...
+
+	virtual void				Add_Value(int x, int y, double Value)	{	Set_Value(x, y, asDouble(x, y) + Value );	}
+	virtual void				Add_Value(      long n, double Value)	{	Set_Value(   n, asDouble(   n) + Value );	}
+
+	virtual void				Mul_Value(int x, int y, double Value)	{	Set_Value(x, y, asDouble(x, y) * Value );	}
+	virtual void				Mul_Value(      long n, double Value)	{	Set_Value(   n, asDouble(   n) * Value );	}
+
+	//-----------------------------------------------------
+	virtual void				Set_Value(      long n, double Value)
+	{
+		Set_Value(n % Get_NX(), n / Get_NX(), Value);
+	}
+
+	virtual void				Set_Value(int x, int y, double Value)
+	{
+		if( m_Memory_Type == GRID_MEMORY_Normal )
+		{
+			switch( m_Type )
+			{
+			    default:																break;
+				case SG_DATATYPE_Byte:	((BYTE   **)m_Values)[y][x]	= (BYTE  )Value;	break;
+				case SG_DATATYPE_Char:	((char   **)m_Values)[y][x]	= (char  )Value;	break;
+				case SG_DATATYPE_Word:	((WORD   **)m_Values)[y][x]	= (WORD  )Value;	break;
+				case SG_DATATYPE_Short:	((short  **)m_Values)[y][x]	= (short )Value;	break;
+				case SG_DATATYPE_DWord:	((DWORD  **)m_Values)[y][x]	= (DWORD )Value;	break;
+				case SG_DATATYPE_Int:		((int    **)m_Values)[y][x]	= (int   )Value;	break;
+				case SG_DATATYPE_Float:	((float  **)m_Values)[y][x]	= (float )Value;	break;
+				case SG_DATATYPE_Double:	((double **)m_Values)[y][x]	= (double)Value;	break;
+				case SG_DATATYPE_Bit:		((BYTE   **)m_Values)[y][x / 8]	= Value != 0.0
+						? ((BYTE  **)m_Values)[y][x / 8] |   m_Bitmask[x % 8]
+						: ((BYTE  **)m_Values)[y][x / 8] & (~m_Bitmask[x % 8]);
+					break;
+			}
+		}
+		else
+		{
+			_LineBuffer_Set_Value(x, y, Value);
+		}
+
+		Set_Modified();
+	}
+
+	virtual void				Set_Value_And_Sort(      long n, double Value);
+	virtual void				Set_Value_And_Sort(int x, int y, double Value);
+
+
+//---------------------------------------------------------
+protected:	///////////////////////////////////////////////
+
+	virtual bool				On_Update				(void);
+
+
+//---------------------------------------------------------
+private:	///////////////////////////////////////////////
+
+	void						**m_Values;
+
+	bool						m_bCreated, m_bIndexed, m_Memory_bLock,
+								Cache_bTemp, Cache_bSwap, Cache_bFlip;
+
+	int							LineBuffer_Count;
+
+	long						*m_Index, Cache_Offset;
+
+	double						m_zFactor, m_NoData_Value, m_NoData_hiValue;
+
+	CSG_Simple_Statistics		m_zStats;
+
+	CSG_File					Cache_Stream;
+
+	TSG_Data_Type				m_Type;
+
+	TSG_Grid_Memory_Type		m_Memory_Type;
+
+	CSG_Grid_System				m_System;
+
+	CSG_String					m_Description, m_Unit, Cache_Path;
+
+
+	//-----------------------------------------------------
+	static	BYTE				m_Bitmask[8];
+
+	//-----------------------------------------------------
+	typedef struct
+	{
+		bool	bModified;
+		int		y;
+		char	*Data;
+	}
+	TSG_Grid_Line;
+
+	TSG_Grid_Line				*LineBuffer;
+
+
+	//-----------------------------------------------------
+	void						_On_Construction		(void);
+
+	void						_Set_Properties			(TSG_Data_Type m_Type, int NX, int NY, double Cellsize, double xMin, double yMin);
+
+	bool						_Set_Index				(void);
+
+
+	//-----------------------------------------------------
+	// Memory handling...
+
+	int							_Get_nLineBytes			(void)	{	return( m_Type == SG_DATATYPE_Bit ? Get_NX() / 8 + 1 : Get_NX() * Get_nValueBytes() );	}
+
+	bool						_Memory_Create			(TSG_Grid_Memory_Type aMemory_Type);
+	void						_Memory_Destroy			(void);
+
+	void						_LineBuffer_Create		(void);
+	void						_LineBuffer_Destroy		(void);
+	int							_LineBuffer_Get_nBytes	(void) const	{	return( SG_Data_Type_Get_Size(m_Type) * Get_NX() );	}
+	void						_LineBuffer_Flush		(void);
+	TSG_Grid_Line *				_LineBuffer_Get_Line	(int y)							const;
+	void						_LineBuffer_Set_Value	(int x, int y, double Value);
+	double						_LineBuffer_Get_Value	(int x, int y)					const;
+
+	bool						_Array_Create			(void);
+	void						_Array_Destroy			(void);
+
+	bool						_Cache_Create			(const SG_Char *FilePath, TSG_Data_Type File_Type, long Offset, bool bSwap, bool bFlip);
+	bool						_Cache_Create			(void);
+	bool						_Cache_Destroy			(bool bMemory_Restore);
+	void						_Cache_LineBuffer_Save	(TSG_Grid_Line *pLine)			const;
+	void						_Cache_LineBuffer_Load	(TSG_Grid_Line *pLine, int y)	const;
+
+	bool						_Compr_Create			(void);
+	bool						_Compr_Destroy			(bool bMemory_Restore);
+	void						_Compr_LineBuffer_Save	(TSG_Grid_Line *pLine)			const;
+	void						_Compr_LineBuffer_Load	(TSG_Grid_Line *pLine, int y)	const;
+
+
+	//-----------------------------------------------------
+	// File access...
+
+	void						_Swap_Bytes				(char *Bytes, int nBytes)			const;
+
+	bool						_Load					(const CSG_String &File_Name, TSG_Data_Type m_Type, TSG_Grid_Memory_Type aMemory_Type);
+
+	bool						_Load_Binary			(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes);
+	bool						_Save_Binary			(CSG_File &Stream, int xA, int yA, int xN, int yN, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes);
+	bool						_Load_ASCII				(CSG_File &Stream, TSG_Grid_Memory_Type aMemory_Type, bool bFlip = false);
+	bool						_Save_ASCII				(CSG_File &Stream, int xA, int yA, int xN, int yN, bool bFlip = false);
+	bool						_Load_Native			(const CSG_String &File_Name, TSG_Grid_Memory_Type aMemory_Type);
+	bool						_Save_Native			(const CSG_String &File_Name, int xA, int yA, int xN, int yN, bool bBinary = true);
+
+	int							_Load_Native_Get_Key	(CSG_File &Stream, CSG_String &Line);
+
+	bool						_Load_Surfer			(const CSG_String &File_Name, TSG_Grid_Memory_Type aMemory_Type);
+
+	//-----------------------------------------------------
+	CSG_Grid &					_Operation_Arithmetic	(const CSG_Grid &Grid, TSG_Grid_Operation Operation);
+	CSG_Grid &					_Operation_Arithmetic	(double Value        , TSG_Grid_Operation Operation);
+
+
+	//-----------------------------------------------------
+	// Interpolation subroutines...
+
+	double						_Get_ValAtPos_NearestNeighbour	(int x, int y, double dx, double dy)				 const;
+	double						_Get_ValAtPos_BiLinear			(int x, int y, double dx, double dy, bool bByteWise) const;
+	double						_Get_ValAtPos_InverseDistance	(int x, int y, double dx, double dy, bool bByteWise) const;
+	double						_Get_ValAtPos_BiCubicSpline		(int x, int y, double dx, double dy, bool bByteWise) const;
+	double						_Get_ValAtPos_BiCubicSpline		(double dx, double dy, double z_xy[4][4])			 const;
+	double						_Get_ValAtPos_BSpline			(int x, int y, double dx, double dy, bool bByteWise) const;
+	double						_Get_ValAtPos_BSpline			(double dx, double dy, double z_xy[4][4])			 const;
+	bool						_Get_ValAtPos_Fill4x4Submatrix	(int x, int y, double z_xy[4][4])					 const;
+	bool						_Get_ValAtPos_Fill4x4Submatrix	(int x, int y, double z_xy[4][4][4])				 const;
+
+	bool						_Assign_Interpolated	(CSG_Grid *pSource, TSG_Grid_Interpolation Interpolation);
+	bool						_Assign_MeanValue		(CSG_Grid *pSource, bool bAreaProportional);
+	bool						_Assign_ExtremeValue	(CSG_Grid *pSource, bool bMaximum);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Functions						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/** Safe grid construction */
+SAGA_API_DLL_EXPORT CSG_Grid *		SG_Create_Grid		(void);
+
+/** Safe grid construction */
+SAGA_API_DLL_EXPORT CSG_Grid *		SG_Create_Grid		(const CSG_Grid &Grid);
+
+/** Safe grid construction */
+SAGA_API_DLL_EXPORT CSG_Grid *		SG_Create_Grid		(const CSG_String &File_Name, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+/** Safe grid construction */
+SAGA_API_DLL_EXPORT CSG_Grid *		SG_Create_Grid		(CSG_Grid *pGrid, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+/** Safe grid construction */
+SAGA_API_DLL_EXPORT CSG_Grid *		SG_Create_Grid		(const CSG_Grid_System &System, TSG_Data_Type Type = SG_DATATYPE_Undefined, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+/** Safe grid construction */
+SAGA_API_DLL_EXPORT CSG_Grid *		SG_Create_Grid		(TSG_Data_Type Type, int NX, int NY, double Cellsize = 0.0, double xMin = 0.0, double yMin = 0.0, TSG_Grid_Memory_Type Memory_Type = GRID_MEMORY_Normal);
+
+//---------------------------------------------------------
+/** Get default directory for grid caching */
+SAGA_API_DLL_EXPORT const SG_Char *	SG_Grid_Cache_Get_Directory		(void);
+
+/** Set default directory for grid caching */
+SAGA_API_DLL_EXPORT void			SG_Grid_Cache_Set_Directory		(const SG_Char *Directory);
+
+SAGA_API_DLL_EXPORT void			SG_Grid_Cache_Set_Automatic		(bool bOn);
+SAGA_API_DLL_EXPORT bool			SG_Grid_Cache_Get_Automatic		(void);
+
+SAGA_API_DLL_EXPORT void			SG_Grid_Cache_Set_Confirm		(int Confirm);
+SAGA_API_DLL_EXPORT int				SG_Grid_Cache_Get_Confirm		(void);
+
+SAGA_API_DLL_EXPORT void			SG_Grid_Cache_Set_Threshold		(int nBytes);
+SAGA_API_DLL_EXPORT void			SG_Grid_Cache_Set_Threshold_MB	(double nMegabytes);
+SAGA_API_DLL_EXPORT int				SG_Grid_Cache_Get_Threshold		(void);
+SAGA_API_DLL_EXPORT double			SG_Grid_Cache_Get_Threshold_MB	(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__grid_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_io.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_io.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_io.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,919 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     grid_io.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Grid: File Operations					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Load(const CSG_String &File_Name, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
+{
+	bool	bResult;
+
+	//-----------------------------------------------------
+	Destroy();
+
+	m_Type	= Type;
+
+	//-----------------------------------------------------
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Load grid"), File_Name.c_str()), true);
+
+	if( SG_File_Cmp_Extension(File_Name, SG_T("grd")) )
+	{
+		bResult	= _Load_Surfer(File_Name, Memory_Type);
+	}
+	else
+	{
+		bResult	= _Load_Native(File_Name, Memory_Type);
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		Set_Update_Flag();
+
+		Set_File_Name(File_Name);
+
+		Load_MetaData(File_Name);
+
+		m_bCreated	= true;
+
+		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+	}
+	else
+	{
+		Destroy();
+
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Grid file could not be opened."));
+	}
+
+	//-----------------------------------------------------
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Save(const CSG_String &File_Name, int Format)
+{
+	return( Save(File_Name, Format, 0, 0, Get_NX(), Get_NY()) );
+}
+
+bool CSG_Grid::Save(const CSG_String &File_Name, int Format, int xA, int yA, int xN, int yN)
+{
+	bool		bResult;
+	CSG_String	sFile_Name	= SG_File_Make_Path(NULL, File_Name, SG_T("sgrd"));
+
+	//-----------------------------------------------------
+	if( xA	< 0 || xA >= Get_NX() - 1 )
+	{
+		xA	= 0;
+	}
+
+	if( yA	< 0 || yA >= Get_NY() - 1 )
+	{
+		yA	= 0;
+	}
+
+	if( xN	> Get_NX() - xA )
+	{
+		xN	= Get_NX() - xA;
+	}
+
+	if( yN	> Get_NY() - yA )
+	{
+		yN	= Get_NY() - yA;
+	}
+
+	//-----------------------------------------------------
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save grid"), File_Name.c_str()), true);
+
+	switch( Format )
+	{
+	default:
+	case GRID_FILE_FORMAT_Binary:	// 1 - Binary
+		bResult	= _Save_Native(sFile_Name, xA, yA, xN, yN, true);
+		break;
+
+	case GRID_FILE_FORMAT_ASCII:	// 2 - ASCII
+		bResult	= _Save_Native(sFile_Name, xA, yA, xN, yN, false);
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		Set_Modified(false);
+
+		Set_File_Name(sFile_Name);
+
+		Save_MetaData(File_Name);
+
+		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+	}
+	else
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Grid file could not be saved."));
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Binary							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::_Swap_Bytes(char *Bytes, int nBytes) const
+{
+	char	Byte, *p;
+
+	p	= Bytes + nBytes - 1;
+
+	while( Bytes < p )
+	{
+		Byte		= *Bytes;
+		*(Bytes++)	= *p;
+		*(p--)		= Byte;
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Load_Binary(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes)
+{
+	char	*Line, *pValue;
+	int		x, y, i, iy, dy, nxBytes, nValueBytes;
+
+	if( Stream.is_Open() && is_Valid() )
+	{
+		Set_File_Type(GRID_FILE_FORMAT_Binary);
+
+		if( bFlip )
+		{
+			y	= Get_NY() - 1;
+			dy	= -1;
+		}
+		else
+		{
+			y	= 0;
+			dy	= 1;
+		}
+
+		//-------------------------------------------------
+		if( File_Type == SG_DATATYPE_Bit )
+		{
+			nxBytes		= Get_NX() / 8 + 1;
+
+			if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal )
+			{
+				for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy)
+				{
+					Stream.Read(m_Values[y], sizeof(char), nxBytes);
+				}
+			}
+			else
+			{
+				Line	= (char *)SG_Malloc(nxBytes);
+
+				for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy)
+				{
+					Stream.Read(Line, sizeof(char), nxBytes);
+
+					for(x=0, pValue=Line; x<Get_NX(); pValue++)
+					{
+						for(i=0; i<8 && x<Get_NX(); i++, x++)
+						{
+							Set_Value(x, y, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0);
+						}
+					}
+				}
+
+				SG_Free(Line);
+			}
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			nValueBytes	= SG_Data_Type_Get_Size(File_Type);
+			nxBytes		= Get_NX() * nValueBytes;
+
+			if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal && !bSwapBytes )
+			{
+				for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy)
+				{
+					Stream.Read(m_Values[y], sizeof(char), nxBytes);
+				}
+			}
+			else
+			{
+				Line	= (char *)SG_Malloc(nxBytes);
+
+				for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy)
+				{
+					Stream.Read(Line, sizeof(char), nxBytes);
+
+					for(x=0, pValue=Line; x<Get_NX(); x++, pValue+=nValueBytes)
+					{
+						if( bSwapBytes )
+						{
+							_Swap_Bytes(pValue, nValueBytes);
+						}
+
+						switch( File_Type )
+						{
+						default:													break;
+						case SG_DATATYPE_Byte:	Set_Value(x, y, *(BYTE   *)pValue);	break;
+						case SG_DATATYPE_Char:	Set_Value(x, y, *(char   *)pValue);	break;
+						case SG_DATATYPE_Word:	Set_Value(x, y, *(WORD   *)pValue);	break;
+						case SG_DATATYPE_Short:	Set_Value(x, y, *(short  *)pValue);	break;
+						case SG_DATATYPE_DWord:	Set_Value(x, y, *(DWORD  *)pValue);	break;
+						case SG_DATATYPE_Int:		Set_Value(x, y, *(int    *)pValue);	break;
+						case SG_DATATYPE_Float:	Set_Value(x, y, *(float  *)pValue);	break;
+						case SG_DATATYPE_Double:	Set_Value(x, y, *(double *)pValue);	break;
+						}
+					}
+				}
+
+				SG_Free(Line);
+			}
+		}
+
+		//-------------------------------------------------
+		SG_UI_Process_Set_Ready();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Save_Binary(CSG_File &Stream, int xA, int yA, int xN, int yN, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes)
+{
+	char	*Line, *pValue;
+	int		x, y, i, ix, iy, dy, axBytes, nxBytes, nValueBytes;
+
+	//-----------------------------------------------------
+	if( Stream.is_Open() && m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined )
+	{
+		Set_File_Type(GRID_FILE_FORMAT_Binary);
+
+		if( bFlip )
+		{
+			y	= yA + yN - 1;
+			dy	= -1;
+		}
+		else
+		{
+			y	= yA;
+			dy	= 1;
+		}
+
+		//-------------------------------------------------
+		if( File_Type == SG_DATATYPE_Bit )
+		{
+			nxBytes		= xN / 8 + 1;
+
+			if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal && xA % 8 == 0 )
+			{
+				axBytes		= xA / 8;
+
+				for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy)
+				{
+					Stream.Write((char *)m_Values[y] + axBytes, sizeof(char), nxBytes);
+				}
+			}
+			else
+			{
+				Line	= (char *)SG_Malloc(nxBytes);
+
+				for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy)
+				{
+					for(ix=0, x=xA, pValue=Line; ix<xN; pValue++)
+					{
+						for(i=0; i<8 && ix<xN; i++, ix++, x++)
+						{
+							*pValue	= asChar(x, y) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]);
+						}
+					}
+
+					Stream.Write(Line, sizeof(char), nxBytes);
+				}
+
+				SG_Free(Line);
+			}
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			nValueBytes	= SG_Data_Type_Get_Size(File_Type);
+			nxBytes		= xN * nValueBytes;
+
+			if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal && !bSwapBytes )
+			{
+				axBytes	= xA * nValueBytes;
+
+				for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy)
+				{
+					Stream.Write((char *)m_Values[y] + axBytes, sizeof(char), nxBytes);
+				}
+			}
+			else
+			{
+				Line	= (char *)SG_Malloc(nxBytes);
+
+				for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy)
+				{
+					for(ix=0, x=xA, pValue=Line; ix<xN; ix++, x++, pValue+=nValueBytes)
+					{
+						switch( File_Type )
+						{
+						default:														break;
+						case SG_DATATYPE_Byte:	*(BYTE   *)pValue	= asChar	(x, y);	break;
+						case SG_DATATYPE_Char:	*(char   *)pValue	= asChar	(x, y);	break;
+						case SG_DATATYPE_Word:	*(WORD   *)pValue	= asShort	(x, y);	break;
+						case SG_DATATYPE_Short:	*(short  *)pValue	= asShort	(x, y);	break;
+						case SG_DATATYPE_DWord:	*(DWORD  *)pValue	= asInt		(x, y);	break;
+						case SG_DATATYPE_Int:		*(int    *)pValue	= asInt		(x, y);	break;
+						case SG_DATATYPE_Float:	*(float  *)pValue	= asFloat	(x, y);	break;
+						case SG_DATATYPE_Double:	*(double *)pValue	= asDouble	(x, y);	break;
+						}
+
+						if( bSwapBytes )
+						{
+							_Swap_Bytes(pValue, nValueBytes);
+						}
+					}
+
+					Stream.Write(Line, sizeof(char), nxBytes);
+				}
+
+				SG_Free(Line);
+			}
+		}
+
+		//-------------------------------------------------
+		SG_UI_Process_Set_Ready();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//							ASCII						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Load_ASCII(CSG_File &Stream, TSG_Grid_Memory_Type Memory_Type, bool bFlip)
+{
+	int		x, y, iy, dy;
+	double	Value;
+
+	if( Stream.is_Open() && m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined && _Memory_Create(Memory_Type) )
+	{
+		Set_File_Type(GRID_FILE_FORMAT_ASCII);
+
+		if( bFlip )
+		{
+			y	= Get_NY() - 1;
+			dy	= -1;
+		}
+		else
+		{
+			y	= 0;
+			dy	= 1;
+		}
+
+		//-------------------------------------------------
+		for(iy=0; iy<Get_NY() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf"), &Value);
+
+				Set_Value(x, y, Value);
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Save_ASCII(CSG_File &Stream, int xA, int yA, int xN, int yN, bool bFlip)
+{
+	int		x, y, ix, iy, dy;
+
+	if( Stream.is_Open() && is_Valid() )
+	{
+		Set_File_Type(GRID_FILE_FORMAT_ASCII);
+
+		if( bFlip )
+		{
+			y	= yA + yN - 1;
+			dy	= -1;
+		}
+		else
+		{
+			y	= yA;
+			dy	= 1;
+		}
+
+		//-------------------------------------------------
+		for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy)
+		{
+			for(ix=0, x=xA; ix<xN; ix++, x++)
+			{
+				Stream.Printf(SG_T("%lf "), asDouble(x, y));
+			}
+
+			Stream.Printf(SG_T("\n"));
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Native							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "parameters.h"
+
+int SG_Grid_Cache_Check(CSG_Grid_System &m_System, int nValueBytes)
+{
+	if(	SG_Grid_Cache_Get_Automatic() && m_System.Get_NCells() * nValueBytes > SG_Grid_Cache_Get_Threshold() )
+	{
+		switch( SG_Grid_Cache_Get_Confirm() )
+		{
+		default:
+			break;
+
+		case 1:
+			{
+				CSG_String	s;
+
+				s.Printf(SG_T("%s\n%s\n%s: %.2fMB"),
+					LNG("Shall I activate file caching for new grid."),
+					m_System.Get_Name(),
+					LNG("Total memory size"),
+					(m_System.Get_NCells() * nValueBytes) / (double)N_MEGABYTE_BYTES
+				);
+
+				if( SG_UI_Dlg_Continue(s, LNG("Activate Grid File Cache?")) )
+				{
+				//	Memory_Type	= GRID_MEMORY_Cache;
+
+					return( SG_Grid_Cache_Get_Threshold() );
+				}
+			}
+			break;
+
+		case 2:
+			{
+				CSG_Parameters	p(NULL, LNG("Activate Grid File Cache?"), SG_T(""));
+
+				p.Add_Value(
+					NULL	, SG_T("BUFFERSIZE")	, LNG("Buffer Size [MB]"),
+					SG_T(""),
+					PARAMETER_TYPE_Double, SG_Grid_Cache_Get_Threshold_MB(), 0.0, true
+				);
+
+				if( SG_UI_Dlg_Parameters(&p, LNG("Activate Grid File Cache?")) )
+				{
+				//	Memory_Type	= GRID_MEMORY_Cache;
+
+				//	Set_Buffer_Size((int)(p(SG_T("BUFFERSIZE"))->asDouble() * N_MEGABYTE_BYTES));
+
+					return( (int)(p(SG_T("BUFFERSIZE"))->asDouble() * N_MEGABYTE_BYTES) );
+				}
+			}
+			break;
+		}
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Load_Native(const CSG_String &File_Name, TSG_Grid_Memory_Type Memory_Type)
+{
+	bool			bResult, hdr_bFlip, hdr_bSwapBytes;
+	int				iType, hdr_Offset, NX, NY;
+	double			Cellsize, xMin, yMin;
+	CSG_File		Stream;
+	TSG_Data_Type	hdr_Type;
+	CSG_Grid_System	System;
+	CSG_String		File_Data, Value;
+
+	//-----------------------------------------------------
+	bResult	= false;
+
+	if( Stream.Open(File_Name, SG_FILE_R, false) )
+	{
+		//-------------------------------------------------
+		// Load Header...
+
+		hdr_Type		= SG_DATATYPE_Undefined;
+		hdr_Offset		= 0;
+		hdr_bFlip		= false;
+		hdr_bSwapBytes	= false;
+
+		NX	= NY		= 0;
+		Cellsize		= 0.0;
+		xMin			= 0.0;
+		yMin			= 0.0;
+
+		//-------------------------------------------------
+		do
+		{
+			switch( _Load_Native_Get_Key(Stream, Value) )
+			{
+			case GRID_FILE_KEY_NAME:			Set_Name		(Value);			break;
+			case GRID_FILE_KEY_DESCRIPTION:		Set_Description	(Value);			break;
+			case GRID_FILE_KEY_UNITNAME:		Set_Unit		(Value);			break;
+
+			case GRID_FILE_KEY_CELLCOUNT_X:		NX				= Value.asInt();	break;
+			case GRID_FILE_KEY_CELLCOUNT_Y:		NY				= Value.asInt();	break;
+			case GRID_FILE_KEY_POSITION_XMIN:	xMin			= Value.asDouble();	break;
+			case GRID_FILE_KEY_POSITION_YMIN:	yMin			= Value.asDouble();	break;
+			case GRID_FILE_KEY_CELLSIZE:		Cellsize		= Value.asDouble();	break;
+			case GRID_FILE_KEY_Z_FACTOR:		m_zFactor		= Value.asDouble();	break;
+			case GRID_FILE_KEY_NODATA_VALUE:	m_NoData_Value	= m_NoData_hiValue	= Value.asDouble();	break;
+
+			case GRID_FILE_KEY_DATAFILE_OFFSET:	hdr_Offset		= Value.asInt();	break;
+			case GRID_FILE_KEY_BYTEORDER_BIG:	hdr_bSwapBytes	= Value.Find(GRID_FILE_KEY_TRUE) >= 0;	break;
+			case GRID_FILE_KEY_TOPTOBOTTOM:		hdr_bFlip		= Value.Find(GRID_FILE_KEY_TRUE) >= 0;	break;
+
+			case GRID_FILE_KEY_DATAFILE_NAME:
+				if( SG_File_Get_Path(Value).Length() > 0 )
+				{
+					File_Data	= Value;
+				}
+				else
+				{
+					File_Data	= SG_File_Make_Path(SG_File_Get_Path(File_Name), Value);
+				}
+				break;
+
+			case GRID_FILE_KEY_DATAFORMAT:
+				for(iType=0; iType<SG_DATATYPE_Undefined && hdr_Type == SG_DATATYPE_Undefined; iType++)
+				{
+					if( Value.Find(gSG_Data_Type_Identifier[iType]) >= 0 )
+					{
+						hdr_Type	= (TSG_Data_Type)iType;
+					}
+				}
+				break;
+			}
+		}
+		while( !Stream.is_EOF() );
+
+
+		//-------------------------------------------------
+		// Load Data...
+
+		if( hdr_Type < SG_DATATYPE_Undefined && m_System.Assign(Cellsize, xMin, yMin, NX, NY) )
+		{
+			//---------------------------------------------
+			// ASCII...
+
+			if( hdr_Type >= SG_DATATYPE_Undefined )
+			{
+				if( m_Type >= SG_DATATYPE_Undefined )
+				{
+					m_Type	= SG_DATATYPE_Float;
+				}
+
+				if(	Stream.Open(File_Data											, SG_FILE_R, false)
+				||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat"))	, SG_FILE_R, false)
+				||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat"))	, SG_FILE_R, false) )
+				{
+					Stream.Seek(hdr_Offset);
+					bResult	= _Load_ASCII(Stream, Memory_Type);
+				}
+			}
+
+			//---------------------------------------------
+			// Binary...
+
+			else
+			{
+				if( m_Type >= SG_DATATYPE_Undefined )
+				{
+					m_Type	= hdr_Type;
+				}
+
+				if( (NX = SG_Grid_Cache_Check(m_System, Get_nValueBytes())) > 0 )
+				{
+					Set_Buffer_Size(NX);
+
+					if( _Cache_Create(File_Data											, hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip)
+					||	_Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T( "dat"))	, hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip)
+					||	_Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T("sdat"))	, hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) )
+					{
+						return( true );
+					}
+
+					Memory_Type	= GRID_MEMORY_Cache;
+				}
+
+				if( _Memory_Create(Memory_Type) )
+				{
+					if(	Stream.Open(File_Data											, SG_FILE_R, true)
+					||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat"))	, SG_FILE_R, true)
+					||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat"))	, SG_FILE_R, true) )
+					{
+						Stream.Seek(hdr_Offset);
+						bResult	= _Load_Binary(Stream, hdr_Type, hdr_bFlip, hdr_bSwapBytes);
+					}
+				}
+			}
+		}
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Save_Native(const CSG_String &File_Name, int xA, int yA, int xN, int yN, bool bBinary)
+{
+	bool		bResult		= false;
+	CSG_File	Stream;
+
+	if(	Stream.Open(File_Name, SG_FILE_W, false) )
+	{
+		//-------------------------------------------------
+		// Header...
+
+		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_NAME			], Get_Name() );
+		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_DESCRIPTION	], Get_Description() );
+		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_UNITNAME		], Get_Unit() );
+		Stream.Printf(SG_T("%s\t= %d\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_DATAFILE_OFFSET], 0 );
+		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_DATAFORMAT		], bBinary ? gSG_Data_Type_Identifier[Get_Type()] : SG_T("ASCII") );
+		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_BYTEORDER_BIG	], GRID_FILE_KEY_FALSE );
+		Stream.Printf(SG_T("%s\t= %.10f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_POSITION_XMIN	], Get_XMin() + Get_Cellsize() * xA );
+		Stream.Printf(SG_T("%s\t= %.10f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_POSITION_YMIN	], Get_YMin() + Get_Cellsize() * yA );
+		Stream.Printf(SG_T("%s\t= %d\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_CELLCOUNT_X	], xN );
+		Stream.Printf(SG_T("%s\t= %d\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_CELLCOUNT_Y	], yN );
+		Stream.Printf(SG_T("%s\t= %.10f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_CELLSIZE		], Get_Cellsize() );
+		Stream.Printf(SG_T("%s\t= %f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_Z_FACTOR		], m_zFactor );
+		Stream.Printf(SG_T("%s\t= %f\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_NODATA_VALUE	], m_NoData_Value );
+		Stream.Printf(SG_T("%s\t= %s\n")	, gSG_Grid_File_Key_Names[ GRID_FILE_KEY_TOPTOBOTTOM	], GRID_FILE_KEY_FALSE );
+
+
+		//-------------------------------------------------
+		// Data...
+
+		if( Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")), SG_FILE_W, true) )
+		{
+			if( bBinary )
+			{
+				bResult		= _Save_Binary	(Stream, xA, yA, xN, yN, Get_Type(), false, false);
+			}
+			else
+			{
+				bResult		= _Save_ASCII	(Stream, xA, yA, xN, yN);
+			}
+		}
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Grid::_Load_Native_Get_Key(CSG_File &Stream, CSG_String &Value)
+{
+	int			i;
+	CSG_String	sLine;
+
+	if( Stream.Read_Line(sLine) && (i = sLine.Find('=')) > 0 )
+	{
+		Value.Printf(sLine.AfterFirst('='));
+		Value.Trim();
+
+		sLine.Remove(i);
+
+		for(i=0; i<GRID_FILE_KEY_Count; i++)
+		{
+			CSG_String	s(gSG_Grid_File_Key_Names[i]);
+
+			if( s.Find(sLine.Left(s.Length())) >= 0 )
+			{
+				return( i );
+			}
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Load_Surfer(const CSG_String &File_Name, TSG_Grid_Memory_Type Memory_Type)
+{
+	bool		bResult		= false;
+	char		Identifier[4];
+	short		sValue;
+	int			x, y, NX, NY;
+	float		*fLine;
+	double		dValue, xMin, yMin, Cellsize;
+	CSG_File	Stream;
+
+	if( Stream.Open(File_Name, SG_FILE_R, true) )
+	{
+		Stream.Read(Identifier, sizeof(char), 4);
+
+		//-------------------------------------------------
+		// Binary...
+
+		if( !strncmp(Identifier, "DSBB", 4) )
+		{
+			Stream.Read(&sValue	, sizeof(short));
+			NX			= sValue;
+			Stream.Read(&sValue	, sizeof(short));
+			NY			= sValue;
+
+			Stream.Read(&xMin	, sizeof(double));
+			Stream.Read(&dValue	, sizeof(double));	// XMax
+			Cellsize	= (dValue - xMin) / (NX - 1.0);
+
+			Stream.Read(&yMin	, sizeof(double));
+			Stream.Read(&dValue	, sizeof(double));	// YMax...
+			//DY		= (dValue - yMin) / (NY - 1.0);		// we could check, if cellsizes (x/y) equal...
+
+			Stream.Read(&dValue	, sizeof(double));	// ZMin...
+			Stream.Read(&dValue	, sizeof(double));	// ZMax...
+
+			//---------------------------------------------
+			if( !Stream.is_EOF() && Create(SG_DATATYPE_Float, NX, NY, Cellsize, xMin, yMin, Memory_Type) )
+			{
+				bResult	= true;
+
+				fLine	= (float *)SG_Malloc(Get_NX() * sizeof(float));
+
+				for(y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+				{
+					Stream.Read(fLine, sizeof(float), Get_NX());
+
+					for(x=0; x<Get_NX(); x++)
+					{
+						Set_Value(x, y, fLine[x]);
+					}
+				}
+
+				SG_Free(fLine);
+			}
+		}
+
+
+		//-------------------------------------------------
+		// ASCII...
+
+		else if( !strncmp(Identifier, "DSAA", 4) )
+		{
+			SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%d %d")	, &NX	, &NY);
+
+			SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf %lf"), &xMin	, &dValue);
+			Cellsize	= (dValue - xMin) / (NX - 1.0);
+
+			SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf %lf"), &yMin	, &dValue);
+			//DY		= (dValue - yMin) / (NY - 1.0);
+
+			SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf %lf"), &dValue, &dValue);
+
+			//---------------------------------------------
+			if( !Stream.is_EOF() && Create(SG_DATATYPE_Float, NX, NY, Cellsize, xMin, yMin, Memory_Type) )
+			{
+				bResult	= true;
+
+				for(y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+				{
+					for(x=0; x<Get_NX(); x++)
+					{
+						SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf"), &dValue);
+
+						Set_Value(x, y, dValue);
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		SG_UI_Process_Set_Ready();
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_memory.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_memory.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_memory.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1093 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   grid_memory.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "grid.h"
+#include "parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Caching Options						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+static CSG_String	gSG_Grid_Cache_Directory;
+
+const SG_Char *		SG_Grid_Cache_Get_Directory(void)
+{
+	return( gSG_Grid_Cache_Directory );
+}
+
+void				SG_Grid_Cache_Set_Directory(const SG_Char *Directory)
+{
+	if( SG_Dir_Exists(Directory) )
+	{
+		gSG_Grid_Cache_Directory.Printf(Directory);
+	}
+}
+
+//---------------------------------------------------------
+static bool			gSG_Grid_Cache_bAutomatic	= false;
+
+void				SG_Grid_Cache_Set_Automatic(bool bOn)
+{
+	gSG_Grid_Cache_bAutomatic	= bOn;
+}
+
+bool				SG_Grid_Cache_Get_Automatic(void)
+{
+	return( gSG_Grid_Cache_bAutomatic );
+}
+
+//---------------------------------------------------------
+static int			gSG_Grid_Cache_Confirm		= 1;
+
+void				SG_Grid_Cache_Set_Confirm(int Confirm)
+{
+	gSG_Grid_Cache_Confirm		= Confirm;
+}
+
+int					SG_Grid_Cache_Get_Confirm(void)
+{
+	return( gSG_Grid_Cache_Confirm );
+}
+
+//---------------------------------------------------------
+static int			gSG_Grid_Cache_Threshold	= 40 * N_MEGABYTE_BYTES;
+
+void				SG_Grid_Cache_Set_Threshold(int nBytes)
+{
+	if( nBytes >= 0 )
+	{
+		gSG_Grid_Cache_Threshold	= nBytes;
+	}
+}
+
+void				SG_Grid_Cache_Set_Threshold_MB(double nMegabytes)
+{
+	SG_Grid_Cache_Set_Threshold((int)(nMegabytes * N_MEGABYTE_BYTES));
+}
+
+int					SG_Grid_Cache_Get_Threshold(void)
+{
+	return( gSG_Grid_Cache_Threshold );
+}
+
+double				SG_Grid_Cache_Get_Threshold_MB(void)
+{
+	return( (double)gSG_Grid_Cache_Threshold / (double)N_MEGABYTE_BYTES );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Memory							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Memory_Create(TSG_Grid_Memory_Type Memory_Type)
+{
+	if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined )
+	{
+		_Memory_Destroy();
+
+		Set_Buffer_Size(gSG_Grid_Cache_Threshold);
+
+		if(	Memory_Type != GRID_MEMORY_Cache && gSG_Grid_Cache_bAutomatic && Get_NCells() * Get_nValueBytes() > gSG_Grid_Cache_Threshold )
+		{
+			switch( gSG_Grid_Cache_Confirm )
+			{
+			default:
+				Memory_Type	= GRID_MEMORY_Cache;
+				break;
+
+			case 1:
+				{
+					CSG_String	s;
+
+					s.Printf(SG_T("%s\n%s\n%s: %.2fMB"),
+						LNG("Shall I activate file caching for new grid."),
+						m_System.Get_Name(),
+						LNG("Total memory size"),
+						(Get_NCells() * Get_nValueBytes()) / (double)N_MEGABYTE_BYTES
+					);
+
+					if( SG_UI_Dlg_Continue(s, LNG("Activate Grid File Cache?")) )
+					{
+						Memory_Type	= GRID_MEMORY_Cache;
+					}
+				}
+				break;
+
+			case 2:
+				{
+					CSG_Parameters	p(NULL, LNG("Activate Grid File Cache?"), SG_T(""));
+
+					p.Add_Value(
+						NULL	, SG_T("BUFFERSIZE")	, LNG("Buffer Size [MB]"),
+						SG_T(""),
+						PARAMETER_TYPE_Double, SG_Grid_Cache_Get_Threshold_MB(), 0.0, true
+					);
+
+					if( SG_UI_Dlg_Parameters(&p, LNG("Activate Grid File Cache?")) )
+					{
+						Memory_Type	= GRID_MEMORY_Cache;
+
+						Set_Buffer_Size((int)(p(SG_T("BUFFERSIZE"))->asDouble() * N_MEGABYTE_BYTES));
+					}
+				}
+				break;
+			}
+		}
+
+		//-------------------------------------------------
+		switch( Memory_Type )
+		{
+		case GRID_MEMORY_Normal:
+			return( _Array_Create() );
+
+		case GRID_MEMORY_Cache:
+			return( _Cache_Create() );
+
+		case GRID_MEMORY_Compression:
+			return( _Compr_Create() );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_Memory_Destroy(void)
+{
+	Set_Index(false);
+
+	switch( m_Memory_Type )
+	{
+	case GRID_MEMORY_Normal:		_Array_Destroy();		break;
+	case GRID_MEMORY_Cache:			_Cache_Destroy(false);	break;
+	case GRID_MEMORY_Compression:	_Compr_Destroy(false);	break;
+	}
+
+	_LineBuffer_Destroy();
+
+	m_Memory_Type	= GRID_MEMORY_Normal;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						LineBuffer						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::_LineBuffer_Create(void)
+{
+	_LineBuffer_Destroy();
+
+	LineBuffer			= (TSG_Grid_Line *)SG_Malloc(LineBuffer_Count * sizeof(TSG_Grid_Line));
+
+	for(int i=0; i<LineBuffer_Count; i++)
+	{
+		LineBuffer[i].Data		= (char *)SG_Malloc(_LineBuffer_Get_nBytes());
+		LineBuffer[i].y			= -1;
+		LineBuffer[i].bModified	= false;
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_LineBuffer_Destroy(void)
+{
+	if( LineBuffer )
+	{
+		for(int i=0; i<LineBuffer_Count; i++)
+		{
+			if( LineBuffer[i].Data )
+			{
+				SG_Free(LineBuffer[i].Data);
+			}
+		}
+
+		SG_Free(LineBuffer);
+
+		LineBuffer	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Set_Buffer_Size(int Size)
+{
+	int		i;
+
+	if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined )
+	{
+		Size	/= _LineBuffer_Get_nBytes();
+
+		if( Size < 1 )
+		{
+			Size	= 1;
+		}
+		else if( Size >= Get_NY() )
+		{
+			Size	= Get_NY() - 1;
+		}
+
+		if( Size != LineBuffer_Count )
+		{
+			if( LineBuffer )
+			{
+				if( Size > LineBuffer_Count )
+				{
+					LineBuffer			= (TSG_Grid_Line *)SG_Realloc(LineBuffer, Size * sizeof(TSG_Grid_Line));
+
+					for(i=LineBuffer_Count; i<Size; i++)
+					{
+						LineBuffer[i].Data		= (char *)SG_Malloc(_LineBuffer_Get_nBytes());
+						LineBuffer[i].y			= -1;
+						LineBuffer[i].bModified	= false;
+					}
+				}
+				else
+				{
+					for(i=Size; i<LineBuffer_Count; i++)
+					{
+						if( LineBuffer[i].Data )
+						{
+							SG_Free(LineBuffer[i].Data);
+						}
+					}
+
+					LineBuffer			= (TSG_Grid_Line *)SG_Realloc(LineBuffer, Size * sizeof(TSG_Grid_Line));
+				}
+			}
+
+			LineBuffer_Count	= Size;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_LineBuffer_Flush(void)
+{
+	if( LineBuffer )
+	{
+		for(int i=0; i<LineBuffer_Count; i++)
+		{
+			switch( m_Memory_Type )
+			{
+		    default:
+		        break;
+
+			case GRID_MEMORY_Cache:
+				_Cache_LineBuffer_Save(LineBuffer + i);
+				break;
+
+			case GRID_MEMORY_Compression:
+				_Compr_LineBuffer_Save(LineBuffer + i);
+				break;
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+CSG_Grid::TSG_Grid_Line * CSG_Grid::_LineBuffer_Get_Line(int y) const
+{
+	int				i, iLine;
+	TSG_Grid_Line	tmp_Line;
+
+	if( LineBuffer && y >= 0 && y < Get_NY() )
+	{
+		//-------------------------------------------------
+		if( y != LineBuffer[0].y )
+		{
+			for(i=1, iLine=0; i<LineBuffer_Count && !iLine; i++)
+			{
+				if( y == LineBuffer[i].y )
+				{
+					iLine	= i;
+				}
+			}
+
+			//---------------------------------------------
+			if( !iLine )
+			{
+				iLine	= LineBuffer_Count - 1;
+
+				switch( m_Memory_Type )
+				{
+				default:
+					break;
+
+				case GRID_MEMORY_Cache:
+					_Cache_LineBuffer_Save(LineBuffer + iLine);
+					_Cache_LineBuffer_Load(LineBuffer + iLine, y);
+					break;
+
+				case GRID_MEMORY_Compression:
+					_Compr_LineBuffer_Save(LineBuffer + iLine);
+					_Compr_LineBuffer_Load(LineBuffer + iLine, y);
+					break;
+				}
+			}
+
+			//---------------------------------------------
+			tmp_Line		= LineBuffer[iLine];
+
+			for(i=iLine; i>0; i--)
+			{
+				LineBuffer[i]	= LineBuffer[i - 1];
+			}	// memmove(LineBuffer + 1, LineBuffer, (iLine - 1) * sizeof(TSG_Grid_Line));
+
+			LineBuffer[0]	= tmp_Line;
+		}
+
+		//-------------------------------------------------
+		return( LineBuffer );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_LineBuffer_Set_Value(int x, int y, double Value)
+{
+	TSG_Grid_Line	*pLine;
+
+	if( (pLine = _LineBuffer_Get_Line(y)) != NULL )
+	{
+		switch( m_Type )
+		{
+		default:
+			break;
+
+		case SG_DATATYPE_Byte:
+			((BYTE   *)pLine->Data)[x]	= (BYTE  )Value;
+			break;
+
+		case SG_DATATYPE_Char:
+			((char   *)pLine->Data)[x]	= (char  )Value;
+			break;
+
+		case SG_DATATYPE_Word:
+			((WORD   *)pLine->Data)[x]	= (WORD  )Value;
+			break;
+
+		case SG_DATATYPE_Short:
+			((short  *)pLine->Data)[x]	= (short )Value;
+			break;
+
+		case SG_DATATYPE_DWord:
+			((DWORD  *)pLine->Data)[x]	= (DWORD )Value;
+			break;
+
+		case SG_DATATYPE_Int:
+			((int    *)pLine->Data)[x]	= (int   )Value;
+			break;
+
+		case SG_DATATYPE_Float:
+			((float  *)pLine->Data)[x]	= (float )Value;
+			break;
+
+		case SG_DATATYPE_Double:
+			((double *)pLine->Data)[x]	= (double)Value;
+			break;
+		}
+
+		pLine->bModified	= true;
+	}
+}
+
+//---------------------------------------------------------
+double CSG_Grid::_LineBuffer_Get_Value(int x, int y) const
+{
+	TSG_Grid_Line	*pLine;
+
+	if( (pLine = _LineBuffer_Get_Line(y)) != NULL )
+	{
+		switch( m_Type )
+		{
+		default:
+			break;
+
+		case SG_DATATYPE_Byte:
+			return( ((BYTE   *)pLine->Data)[x] );
+
+		case SG_DATATYPE_Char:
+			return( ((char   *)pLine->Data)[x] );
+
+		case SG_DATATYPE_Word:
+			return( ((WORD   *)pLine->Data)[x] );
+
+		case SG_DATATYPE_Short:
+			return( ((short  *)pLine->Data)[x] );
+
+		case SG_DATATYPE_DWord:
+			return( ((DWORD  *)pLine->Data)[x] );
+
+		case SG_DATATYPE_Int:
+			return( ((int    *)pLine->Data)[x] );
+
+		case SG_DATATYPE_Float:
+			return( ((float  *)pLine->Data)[x] );
+
+		case SG_DATATYPE_Double:
+			return( ((double *)pLine->Data)[x] );
+		}
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Array							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Array_Create(void)
+{
+	if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined )
+	{
+		_Array_Destroy();
+
+		m_Values	= (void **)SG_Malloc(Get_NY() * sizeof(void *));
+
+		for(int y=0; y<Get_NY(); y++)
+		{
+			m_Values[y]	= (void *)SG_Calloc(1, _Get_nLineBytes());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_Array_Destroy(void)
+{
+	if( m_Values )
+	{
+		for(int y=0; y<Get_NY(); y++)
+		{
+			if( m_Values[y] )
+			{
+				SG_Free(m_Values[y]);
+			}
+		}
+
+		SG_Free(m_Values);
+
+		m_Values	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Cache							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::Set_Cache(bool bOn)
+{
+	return( bOn ? _Cache_Create() : _Cache_Destroy(true) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::is_Cached(void)
+{
+	return( m_Memory_Type == GRID_MEMORY_Cache );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Cache: Create / Destroy					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Cache_Create(const SG_Char *FilePath, TSG_Data_Type File_Type, long Offset, bool bSwap, bool bFlip)
+{
+	if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined && m_Memory_Type == GRID_MEMORY_Normal )
+	{
+		Cache_Path.Printf(FilePath);
+
+		if( m_Type == File_Type
+		&&	(	Cache_Stream.Open(Cache_Path, SG_FILE_RWA, true)
+			||	Cache_Stream.Open(Cache_Path, SG_FILE_R  , true)) )
+		{
+			m_Memory_bLock	= true;
+
+			Cache_bTemp		= false;
+
+			Cache_Offset	= Offset;
+			Cache_bSwap		= bSwap;
+			Cache_bFlip		= bFlip;
+
+			_LineBuffer_Create();
+
+			m_Memory_bLock	= false;
+			m_Memory_Type	= GRID_MEMORY_Cache;
+
+			_Array_Destroy();
+		}
+	}
+
+	return( is_Cached() );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Cache_Create(void)
+{
+	TSG_Grid_Line	Line;
+
+	if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined && m_Memory_Type == GRID_MEMORY_Normal )
+	{
+		Cache_Path	= SG_File_Get_TmpName(SG_T("sg_grd"), SG_Grid_Cache_Get_Directory());
+
+		if( Cache_Stream.Open(Cache_Path, SG_FILE_RW, true) )
+		{
+			m_Memory_bLock	= true;
+
+			Cache_bTemp		= true;
+
+			Cache_Offset	= 0;
+			Cache_bSwap		= false;
+			Cache_bFlip		= false;
+
+			_LineBuffer_Create();
+
+			if( m_Values )
+			{
+				Line.Data	= (char *)SG_Malloc(_LineBuffer_Get_nBytes());
+
+				for(Line.y=0; Line.y<Get_NY() && SG_UI_Process_Set_Progress(Line.y, Get_NY()); Line.y++)
+				{
+					Line.bModified	= true;
+					memcpy(Line.Data, m_Values[Line.y], _LineBuffer_Get_nBytes());
+					_Cache_LineBuffer_Save(&Line);
+					SG_Free(m_Values[Line.y]);
+				}
+
+				SG_Free(Line.Data);
+
+				SG_Free(m_Values);
+				m_Values	= NULL;
+
+				SG_UI_Process_Set_Ready();
+			}
+
+			m_Memory_bLock	= false;
+			m_Memory_Type	= GRID_MEMORY_Cache;
+		}
+	}
+
+	return( is_Cached() );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Cache_Destroy(bool bMemory_Restore)
+{
+	int				y;
+	TSG_Grid_Line	*pLine;
+
+	if( is_Valid() && m_Memory_Type == GRID_MEMORY_Cache )
+	{
+		m_Memory_bLock	= true;
+
+		if( !Cache_bTemp )
+		{
+			_LineBuffer_Flush();
+		}
+
+		if( bMemory_Restore && _Array_Create() )
+		{
+			for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+			{
+				if( (pLine = _LineBuffer_Get_Line(y)) != NULL )
+				{
+					memcpy(m_Values[y], pLine->Data, _LineBuffer_Get_nBytes());
+				}
+			}
+
+			SG_UI_Process_Set_Ready();
+		}
+
+		_LineBuffer_Destroy();
+
+		m_Memory_bLock	= false;
+		m_Memory_Type	= GRID_MEMORY_Normal;
+
+		//-------------------------------------------------
+		Cache_Stream.Close();
+
+		if( Cache_bTemp )
+		{
+			SG_File_Delete(Cache_Path);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Cache: Save / Load					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::_Cache_LineBuffer_Save(TSG_Grid_Line *pLine) const
+{
+	int		x, y, Line_Pos, Line_Size;
+	char	*pValue;
+
+	if( pLine && pLine->bModified )
+	{
+		pLine->bModified	= false;
+
+		if( pLine->y >= 0 && pLine->y < Get_NY() )
+		{
+			y			= Cache_bFlip ? Get_NY() - 1 - pLine->y : pLine->y;
+
+			Line_Size	= _LineBuffer_Get_nBytes();
+			Line_Pos	= Cache_Offset + y * Line_Size;
+
+			//-------------------------------------------------
+			if( Cache_bSwap && m_Type != SG_DATATYPE_Bit )
+			{
+				for(x=0, pValue=pLine->Data; x<Get_NX(); x++, pValue+=Get_nValueBytes())
+				{
+					_Swap_Bytes(pValue, Get_nValueBytes());
+				}
+			}
+
+			Cache_Stream.Seek(Line_Pos);
+			Cache_Stream.Write(pLine->Data, sizeof(char), Line_Size);
+			Cache_Stream.Flush();
+
+			if( Cache_bSwap && m_Type != SG_DATATYPE_Bit )
+			{
+				for(x=0, pValue=pLine->Data; x<Get_NX(); x++, pValue+=Get_nValueBytes())
+				{
+					_Swap_Bytes(pValue, Get_nValueBytes());
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_Cache_LineBuffer_Load(TSG_Grid_Line *pLine, int y) const
+{
+	int		x, Line_Pos, Line_Size;
+	char	*pValue;
+
+	if( pLine )
+	{
+		pLine->bModified	= false;
+		pLine->y			= y;
+
+		if( pLine->y >= 0 && pLine->y < Get_NY() )
+		{
+			y			= Cache_bFlip ? Get_NY() - 1 - pLine->y : pLine->y;
+
+			Line_Size	= _LineBuffer_Get_nBytes();
+			Line_Pos	= Cache_Offset + y * Line_Size;
+
+			//-------------------------------------------------
+			Cache_Stream.Seek(Line_Pos);
+			Cache_Stream.Read(pLine->Data, sizeof(char), Line_Size);
+
+			if( Cache_bSwap && m_Type != SG_DATATYPE_Bit )
+			{
+				for(x=0, pValue=pLine->Data; x<Get_NX(); x++, pValue+=Get_nValueBytes())
+				{
+					_Swap_Bytes(pValue, Get_nValueBytes());
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					RTL - Compression					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::Set_Compression(bool bOn)
+{
+	return( bOn ? _Compr_Create() : _Compr_Destroy(true) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::is_Compressed(void)
+{
+	return( m_Memory_Type == GRID_MEMORY_Compression );
+}
+
+//---------------------------------------------------------
+double CSG_Grid::Get_Compression_Ratio(void)
+{
+	int		y;
+	long	nCompression, nNoCompression;
+
+	if( is_Compressed() )
+	{
+		for(y=0, nCompression=0; y<Get_NY(); y++)
+		{
+			nCompression	+= *((int *)m_Values[y]);
+		}
+
+		if( (nNoCompression = Get_NCells() * Get_nValueBytes()) > 0 )
+		{
+			return( (double)nCompression / (double)nNoCompression );
+		}
+	}
+
+	return( 1.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			RTL - Compression: Create / Destroy			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::_Compr_Create(void)
+{
+	TSG_Grid_Line	Line;
+
+	if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined && m_Memory_Type == GRID_MEMORY_Normal )
+	{
+		m_Memory_bLock	= true;
+
+		Line.Data		= (char *)SG_Calloc(1, _Get_nLineBytes());
+
+		if( m_Values )	// compress loaded data...
+		{
+			for(Line.y=0; Line.y<Get_NY() && SG_UI_Process_Set_Progress(Line.y, Get_NY()); Line.y++)
+			{
+				memcpy(Line.Data, m_Values[Line.y], _LineBuffer_Get_nBytes());
+				Line.bModified	= true;
+				_Compr_LineBuffer_Save(&Line);
+			}
+		}
+		else			// create empty grid...
+		{
+			m_Values	= (void **)SG_Malloc(Get_NY() * sizeof(void *));
+
+			for(Line.y=0; Line.y<Get_NY() && SG_UI_Process_Set_Progress(Line.y, Get_NY()); Line.y++)
+			{
+				m_Values[Line.y]	= (void *)SG_Calloc(1, _LineBuffer_Get_nBytes());
+				Line.bModified	= true;
+				_Compr_LineBuffer_Save(&Line);
+			}
+		}
+
+		SG_Free(Line.Data);
+
+		_LineBuffer_Create();
+
+		m_Memory_bLock	= false;
+		m_Memory_Type	= GRID_MEMORY_Compression;
+
+		SG_UI_Process_Set_Ready();
+	}
+
+	return( is_Compressed() );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Compr_Destroy(bool bMemory_Restore)
+{
+	TSG_Grid_Line	Line;
+
+	if( is_Valid() && m_Memory_Type == GRID_MEMORY_Compression )
+	{
+		m_Memory_bLock	= true;
+
+		if( bMemory_Restore )
+		{
+			_LineBuffer_Flush();
+
+			Line.Data		= (char *)SG_Calloc(1, _Get_nLineBytes());
+
+			for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+			{
+				_Compr_LineBuffer_Load(&Line, y);
+				m_Values[y]	= (void *)SG_Realloc(m_Values[y], _Get_nLineBytes());
+				memcpy(m_Values[y], Line.Data, _LineBuffer_Get_nBytes());
+			}
+
+			SG_Free(Line.Data);
+
+			SG_UI_Process_Set_Ready();
+		}
+		else
+		{
+			_Array_Destroy();
+		}
+
+		_LineBuffer_Destroy();
+
+		m_Memory_bLock	= false;
+		m_Memory_Type	= GRID_MEMORY_Normal;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			RTL - Compression: Save / Load				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::_Compr_LineBuffer_Save(TSG_Grid_Line *pLine) const
+{
+	char	*pResult, *pNoCompress, *pCompress, *pNext;
+	int		x, ix, Threshold, nCompress, nNoCompress, nBytesTotal, Line_Pos;
+
+	if( pLine && pLine->bModified )
+	{
+		pLine->bModified	= false;
+
+		if( pLine->y >= 0 && pLine->y < Get_NY() )
+		{
+			Threshold	= 1 + (sizeof(WORD) + sizeof(bool) + Get_nValueBytes()) / Get_nValueBytes();
+
+			nBytesTotal	= Line_Pos	= sizeof(nBytesTotal);
+			pResult		= (char *)SG_Malloc(nBytesTotal);
+			pNoCompress	= pLine->Data;
+			nNoCompress	= 0;
+
+			//---------------------------------------------
+			for(x=0; x<Get_NX(); )
+			{
+				nCompress	= 1;
+				pCompress	= pLine->Data + x * Get_nValueBytes();
+				pNext		= pCompress + Get_nValueBytes();
+
+				for(ix=x+1; ix<Get_NX(); ix++, pNext+=Get_nValueBytes())
+				{
+					if( memcmp(pCompress, pNext, Get_nValueBytes()) )
+					{
+						break;
+					}
+					else
+					{
+						nCompress++;
+					}
+				}
+
+				//-----------------------------------------
+				if( nCompress <= Threshold )
+				{
+					nNoCompress++;
+					x++;
+				}
+				else
+				{
+					nBytesTotal	+= sizeof(WORD) + sizeof(bool) + Get_nValueBytes();
+
+					if( nNoCompress > 0 )
+					{
+						nBytesTotal	+= sizeof(WORD) + sizeof(bool) + nNoCompress * Get_nValueBytes();
+						pResult	= (char *)SG_Realloc(pResult, nBytesTotal);
+
+						*((WORD *)(pResult + Line_Pos))	= nNoCompress;
+						Line_Pos	+= sizeof(WORD);
+						*((bool *)(pResult + Line_Pos))	= false;
+						Line_Pos	+= sizeof(bool);
+
+						memcpy(pResult + Line_Pos, pNoCompress, nNoCompress * Get_nValueBytes());
+						Line_Pos	+= nNoCompress * Get_nValueBytes();
+
+						nNoCompress	= 0;
+					}
+					else
+					{
+						pResult	= (char *)SG_Realloc(pResult, nBytesTotal);
+					}
+
+					*((WORD *)(pResult + Line_Pos))	= nCompress;
+					Line_Pos	+= sizeof(WORD);
+					*((bool *)(pResult + Line_Pos))	= true;
+					Line_Pos	+= sizeof(bool);
+
+					memcpy(pResult + Line_Pos, pCompress, Get_nValueBytes());
+					Line_Pos	+= Get_nValueBytes();
+
+					pNoCompress	= pCompress + nCompress * Get_nValueBytes();
+					x			+= nCompress;
+				}
+			}
+
+			//---------------------------------------------
+			if( nNoCompress > 0 )
+			{
+				nBytesTotal	+= sizeof(WORD) + sizeof(bool) + nNoCompress * Get_nValueBytes();
+				pResult	= (char *)SG_Realloc(pResult, nBytesTotal);
+
+				*((WORD *)(pResult + Line_Pos))	= nNoCompress;
+				Line_Pos	+= sizeof(WORD);
+				*((bool *)(pResult + Line_Pos))	= false;
+				Line_Pos	+= sizeof(bool);
+
+				memcpy(pResult + Line_Pos, pNoCompress, nNoCompress * Get_nValueBytes());
+			}
+
+			//-------------------------------------------------
+			memcpy(pResult, &nBytesTotal, sizeof(nBytesTotal));
+
+			if( m_Values[pLine->y] )
+			{
+				SG_Free(m_Values[pLine->y]);
+			}
+
+			m_Values[pLine->y]	= pResult;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::_Compr_LineBuffer_Load(TSG_Grid_Line *pLine, int y) const
+{
+	bool	bCompressed;
+	char	*pData, *pValue;
+	int		x, iValue;
+	WORD	nValues;
+
+	if( pLine )
+	{
+		pLine->bModified	= false;
+		pLine->y			= y;
+
+		if( pLine->y >= 0 && pLine->y < Get_NY() )
+		{
+			pValue		= (char *)m_Values[y] + sizeof(int);
+			pData		= pLine->Data;
+
+			for(x=0; x<Get_NX(); )
+			{
+				nValues		= *((WORD *)pValue);
+				pValue		+= sizeof(WORD);
+				bCompressed	= *((bool *)pValue);
+				pValue		+= sizeof(bool);
+
+				if( bCompressed )
+				{
+					for(iValue=0; iValue<nValues && x<Get_NX(); iValue++, x++, pData+=Get_nValueBytes())
+					{
+						memcpy(pData, pValue, Get_nValueBytes());
+					}
+
+					pValue	+= Get_nValueBytes();
+				}
+				else
+				{
+					memcpy(pData, pValue, Get_nValueBytes() * nValues);
+					x		+= nValues;
+					pData	+= Get_nValueBytes() * nValues;
+					pValue	+= Get_nValueBytes() * nValues;
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_operation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_operation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_operation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1004 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  grid_operation.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Data Assignments - Value				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::Assign_NoData(void)
+{
+	Assign(Get_NoData_Value());
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Assign(double Value)
+{
+	if( is_Valid() )
+	{
+		if( Value == 0.0 && m_Memory_Type == GRID_MEMORY_Normal )
+		{
+			for(int n=0, m=_Get_nLineBytes(); n<Get_NY(); n++)
+			{
+				memset(m_Values[n], 0, m);
+			}
+		}
+		else
+		{
+			for(int n=0; n<Get_NCells(); n++)
+			{
+				Set_Value(n, Value);
+			}
+		}
+
+		//-------------------------------------------------
+		Get_History().Destroy();
+		Get_History().Add_Child(LNG("[HST] Value assigned to grid"), CSG_String::Format(SG_T("%f"), Value));
+
+		//-------------------------------------------------
+		m_zStats.Invalidate();
+		m_zStats.Add_Value(Value);
+
+		Set_Update_Flag(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Data Assignments - Grid					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid::Assign(CSG_Data_Object *pObject)
+{
+	if( pObject && pObject->is_Valid() && pObject->Get_ObjectType() == Get_ObjectType() )
+	{
+		return( Assign((CSG_Grid *)pObject, GRID_INTERPOLATION_Undefined) );
+	}
+
+	return( false );
+}
+
+bool CSG_Grid::Assign(CSG_Grid *pGrid, TSG_Grid_Interpolation Interpolation)
+{
+	bool	bResult	= false;
+
+	//-----------------------------------------------------
+	if(	is_Valid() && pGrid && pGrid->is_Valid() && is_Intersecting(pGrid->Get_Extent()) != INTERSECTION_None )
+	{
+		if(	Get_Cellsize() == pGrid->Get_Cellsize()			// No-Scaling...
+		&&	fmod(Get_XMin() - pGrid->Get_XMin(), Get_Cellsize()) == 0.0
+		&&	fmod(Get_YMin() - pGrid->Get_YMin(), Get_Cellsize()) == 0.0	)
+		{
+			bResult	= _Assign_Interpolated	(pGrid, GRID_INTERPOLATION_NearestNeighbour);
+		}
+		else switch( Interpolation )
+		{
+			case GRID_INTERPOLATION_NearestNeighbour:
+			case GRID_INTERPOLATION_Bilinear:
+			case GRID_INTERPOLATION_InverseDistance:
+			case GRID_INTERPOLATION_BicubicSpline:
+			case GRID_INTERPOLATION_BSpline:
+				bResult	= _Assign_Interpolated	(pGrid, Interpolation);
+				break;
+
+			case GRID_INTERPOLATION_Mean_Nodes:
+			case GRID_INTERPOLATION_Mean_Cells:
+				bResult	= _Assign_MeanValue		(pGrid, Interpolation != GRID_INTERPOLATION_Mean_Nodes);
+				break;
+
+			case GRID_INTERPOLATION_Minimum:
+			case GRID_INTERPOLATION_Maximum:
+				bResult	= _Assign_ExtremeValue	(pGrid, Interpolation == GRID_INTERPOLATION_Maximum);
+				break;
+
+			default:
+				if( Get_Cellsize() < pGrid->Get_Cellsize() )	// Down-Scaling...
+				{
+					bResult	= _Assign_Interpolated	(pGrid, GRID_INTERPOLATION_BSpline);
+				}
+				else											// Up-Scaling...
+				{
+					bResult	= _Assign_MeanValue		(pGrid, Interpolation != GRID_INTERPOLATION_Mean_Nodes);
+				}
+				break;
+		}
+
+		//-------------------------------------------------
+		if( bResult )
+		{
+			m_zFactor			= pGrid->m_zFactor;
+
+			m_NoData_Value		= pGrid->m_NoData_Value;
+			m_NoData_hiValue	= pGrid->m_NoData_hiValue;
+
+//			Set_Name			(pGrid->Get_Name());
+			Set_Description		(pGrid->Get_Description());
+			Set_Unit			(pGrid->Get_Unit());
+		}
+	}
+
+	//-----------------------------------------------------
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Assign_Interpolated(CSG_Grid *pGrid, TSG_Grid_Interpolation Interpolation)
+{
+	int		x, y;
+	double	xPosition, yPosition, z;
+
+	Set_NoData_Value_Range(pGrid->Get_NoData_Value(), pGrid->Get_NoData_hiValue());
+
+	for(y=0, yPosition=Get_YMin(); y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++, yPosition+=Get_Cellsize())
+	{
+		for(x=0, xPosition=Get_XMin(); x<Get_NX(); x++, xPosition+=Get_Cellsize())
+		{
+			if( pGrid->Get_Value(xPosition, yPosition, z, Interpolation) )
+			{
+				Set_Value (x, y, z);
+			}
+			else
+			{
+				Set_NoData(x, y);
+			}
+		}
+	}
+
+	Get_History()	= pGrid->Get_History();
+	Get_History().Add_Child(LNG("[DAT] Resampling"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()));
+
+	SG_UI_Process_Set_Ready();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Assign_ExtremeValue(CSG_Grid *pGrid, bool bMaximum)
+{
+	if( Get_Cellsize() < pGrid->Get_Cellsize() || is_Intersecting(pGrid->Get_Extent()) == INTERSECTION_None )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int			x, y, ix, iy;
+	double		px, py, ax, ay, d, z;
+	CSG_Matrix	S(Get_NY(), Get_NX()), N(Get_NY(), Get_NX());
+
+	d	= pGrid->Get_Cellsize() / Get_Cellsize();
+
+	Set_NoData_Value(pGrid->Get_NoData_Value());
+
+	Assign_NoData();
+
+	//-----------------------------------------------------
+	ax	= 0.5 + (pGrid->Get_XMin() - Get_XMin()) / Get_Cellsize();
+	ay	= 0.5 + (pGrid->Get_YMin() - Get_YMin()) / Get_Cellsize();
+
+	for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
+	{
+		if( (iy = (int)floor(py)) >= 0 && iy < Get_NY() )
+		{
+			for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
+			{
+				if( !pGrid->is_NoData(x, y) && (ix = (int)floor(px)) >= 0 && ix < Get_NX() )
+				{
+					z	= pGrid->asDouble(x, y);
+
+					if( is_NoData(ix, iy)
+					||	(bMaximum == true  && z > asDouble(ix, iy))
+					||	(bMaximum == false && z < asDouble(ix, iy)) )
+					{
+						Set_Value(ix, iy, z);
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	Get_History()	= pGrid->Get_History();
+	Get_History().Add_Child(LNG("[DAT] Resampling"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()));
+
+	SG_UI_Process_Set_Ready();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::_Assign_MeanValue(CSG_Grid *pGrid, bool bAreaProportional)
+{
+	if( Get_Cellsize() < pGrid->Get_Cellsize() || is_Intersecting(pGrid->Get_Extent()) == INTERSECTION_None )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int			x, y, ix, iy, jx, jy;
+	double		px, py, ax, ay, d, w, wx, wy, z;
+	CSG_Matrix	S(Get_NY(), Get_NX()), N(Get_NY(), Get_NX());
+
+	d	= pGrid->Get_Cellsize() / Get_Cellsize();
+
+	Set_NoData_Value(pGrid->Get_NoData_Value());
+
+	Assign_NoData();
+
+	//-----------------------------------------------------
+	if( bAreaProportional == false )
+	{
+		ax	= 0.5 + (pGrid->Get_XMin() - Get_XMin()) / Get_Cellsize();
+		ay	= 0.5 + (pGrid->Get_YMin() - Get_YMin()) / Get_Cellsize();
+
+		for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
+		{
+			if( (iy = (int)floor(py)) >= 0 && iy < Get_NY() )
+			{
+				for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
+				{
+					if( !pGrid->is_NoData(x, y) && (ix = (int)floor(px)) >= 0 && ix < Get_NX() )
+					{
+						S[ix][iy]	+= pGrid->asDouble(x, y);
+						N[ix][iy]	++;
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else // if( bAreaProportional == true )
+	{
+		ax	= ((pGrid->Get_XMin() - 0.5 * pGrid->Get_Cellsize()) - (Get_XMin() - 0.5 * Get_Cellsize())) / Get_Cellsize();
+		ay	= ((pGrid->Get_YMin() - 0.5 * pGrid->Get_Cellsize()) - (Get_YMin() - 0.5 * Get_Cellsize())) / Get_Cellsize();
+
+		for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
+		{
+			if( py > -d || py < Get_NY() )
+			{
+				iy	= (int)floor(py);
+				wy	= (py + d) - iy;
+				wy	= wy < 1.0 ? 1.0 : wy - 1.0; 
+
+				for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
+				{
+					if( !pGrid->is_NoData(x, y) && (px > -d && px < Get_NX()) )
+					{
+						ix	= (int)floor(px);
+						wx	= (px + d) - ix;
+						wx	= wx < 1.0 ? 1.0 : wx - 1.0; 
+
+						z	= pGrid->asDouble(x, y);
+
+						if( iy >= 0 && iy < Get_NY() )		// wy > 0.0 is always true
+						{
+							if( ix >= 0 && ix < Get_NX() )	// wx > 0.0 is always true
+							{
+								w	= wx * wy;
+								S[ix][iy]	+= w * z;
+								N[ix][iy]	+= w;
+							}
+
+							if( wx < 1.0 && (jx = ix + 1) >= 0 && jx < Get_NX() )
+							{
+								w	= (1.0 - wx) * wy;
+								S[jx][iy]	+= w * z;
+								N[jx][iy]	+= w;
+							}
+						}
+
+						if( wy < 1.0 && (jy = iy + 1) >= 0 && jy < Get_NY() )
+						{
+							if( ix >= 0 && ix < Get_NX() )
+							{
+								w	= wx * (1.0 - wy);
+								S[ix][jy]	+= w * z;
+								N[ix][jy]	+= w;
+							}
+
+							if( wx < 1.0 && (jx = ix + 1) >= 0 && jx < Get_NX() )
+							{
+								w	= (1.0 - wx) * (1.0 - wy);
+								S[jx][jy]	+= w * z;
+								N[jx][jy]	+= w;
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+	{
+		for(x=0; x<Get_NX(); x++)
+		{
+			if( N[x][y] )
+			{
+				Set_Value(x, y, S[x][y] / N[x][y]);
+			}
+			else
+			{
+				Set_NoData(x, y);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	Get_History()	= pGrid->Get_History();
+	Get_History().Add_Child(LNG("[DAT] Resampling"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()));
+
+	SG_UI_Process_Set_Ready();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Operatoren							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid & CSG_Grid::operator = (const CSG_Grid &Grid)
+{
+	Assign((CSG_Grid *)&Grid, GRID_INTERPOLATION_Undefined);
+
+	return( *this );
+}
+
+CSG_Grid & CSG_Grid::operator =	(double Value)
+{
+	Assign(Value);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Grid CSG_Grid::operator +		(const CSG_Grid &Grid) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Grid, GRID_OPERATION_Addition) );
+}
+
+CSG_Grid CSG_Grid::operator +		(double Value) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Value, GRID_OPERATION_Addition) );
+}
+
+CSG_Grid & CSG_Grid::operator +=	(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Addition) );
+}
+
+CSG_Grid & CSG_Grid::operator +=	(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Addition) );
+}
+
+CSG_Grid & CSG_Grid::Add			(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Addition) );
+}
+
+CSG_Grid & CSG_Grid::Add			(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Addition) );
+}
+
+//---------------------------------------------------------
+CSG_Grid CSG_Grid::operator -		(const CSG_Grid &Grid) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Grid, GRID_OPERATION_Subtraction) );
+}
+
+CSG_Grid CSG_Grid::operator -		(double Value) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Value, GRID_OPERATION_Subtraction) );
+}
+
+CSG_Grid & CSG_Grid::operator -=	(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Subtraction) );
+}
+
+CSG_Grid & CSG_Grid::operator -=	(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Subtraction) );
+}
+
+CSG_Grid & CSG_Grid::Subtract		(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Subtraction) );
+}
+
+CSG_Grid & CSG_Grid::Subtract		(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Subtraction) );
+}
+
+//---------------------------------------------------------
+CSG_Grid CSG_Grid::operator *		(const CSG_Grid &Grid) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Grid, GRID_OPERATION_Multiplication) );
+}
+
+CSG_Grid CSG_Grid::operator *		(double Value) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Value, GRID_OPERATION_Multiplication) );
+}
+
+CSG_Grid & CSG_Grid::operator *=	(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Multiplication) );
+}
+
+CSG_Grid & CSG_Grid::operator *=	(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Multiplication) );
+}
+
+CSG_Grid & CSG_Grid::Multiply		(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Multiplication) );
+}
+
+CSG_Grid & CSG_Grid::Multiply		(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Multiplication) );
+}
+
+//---------------------------------------------------------
+CSG_Grid CSG_Grid::operator /		(const CSG_Grid &Grid) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Grid, GRID_OPERATION_Division) );
+}
+
+CSG_Grid CSG_Grid::operator /		(double Value) const
+{
+	CSG_Grid	g(*this);
+
+	return( g._Operation_Arithmetic(Value, GRID_OPERATION_Division) );
+}
+
+CSG_Grid & CSG_Grid::operator /=	(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Division) );
+}
+
+CSG_Grid & CSG_Grid::operator /=	(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Division) );
+}
+
+CSG_Grid & CSG_Grid::Divide			(const CSG_Grid &Grid)
+{
+	return( _Operation_Arithmetic(Grid, GRID_OPERATION_Division) );
+}
+
+CSG_Grid & CSG_Grid::Divide			(double Value)
+{
+	return( _Operation_Arithmetic(Value, GRID_OPERATION_Division) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Operatoren							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid & CSG_Grid::_Operation_Arithmetic(const CSG_Grid &Grid, TSG_Grid_Operation Operation)
+{
+	if( is_Intersecting(Grid.Get_Extent()) )
+	{
+		int						x, y;
+		double					xWorld, yWorld, Value;
+		TSG_Grid_Interpolation	Interpolation;
+
+		Interpolation	=	Get_Cellsize() == Grid.Get_Cellsize() && fmod(Get_XMin() - Grid.Get_XMin(), Get_Cellsize()) == 0.0
+						&&	Get_Cellsize() == Grid.Get_Cellsize() && fmod(Get_YMin() - Grid.Get_YMin(), Get_Cellsize()) == 0.0
+						?	GRID_INTERPOLATION_NearestNeighbour
+						:	GRID_INTERPOLATION_BSpline;
+
+		for(y=0, yWorld=Get_YMin(); y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++, yWorld+=Get_Cellsize())
+		{
+			for(x=0, xWorld=Get_XMin(); x<Get_NX(); x++, xWorld+=Get_Cellsize())
+			{
+				if( !Grid.Get_Value(xWorld, yWorld, Value, Interpolation, true) )
+				{
+					Set_NoData(x, y);
+				}
+				else switch( Operation )
+				{
+				case GRID_OPERATION_Addition:
+					Add_Value(x, y,  Value);
+					break;
+
+				case GRID_OPERATION_Subtraction:
+					Add_Value(x, y, -Value);
+					break;
+
+				case GRID_OPERATION_Multiplication:
+					Mul_Value(x, y,  Value);
+					break;
+
+				case GRID_OPERATION_Division:
+					if( Value != 0.0 )
+					{
+						Mul_Value(x, y, 1.0 / Value);
+					}
+					else
+					{
+						Set_NoData(x, y);
+					}
+					break;
+				}
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		//-------------------------------------------------
+		switch( Operation )
+		{
+		case GRID_OPERATION_Addition:
+			Get_History().Add_Child(LNG("[HST] Grid addition")		, Grid.Get_Name());
+			break;
+
+		case GRID_OPERATION_Subtraction:
+			Get_History().Add_Child(LNG("[HST] Grid subtraction")	, Grid.Get_Name());
+			break;
+
+		case GRID_OPERATION_Multiplication:
+			Get_History().Add_Child(LNG("[HST] Grid multiplication"), Grid.Get_Name());
+			break;
+
+		case GRID_OPERATION_Division:
+			Get_History().Add_Child(LNG("[HST] Grid division")		, Grid.Get_Name());
+			break;
+		}
+
+		Get_History()	+= ((CSG_Grid *)&Grid)->Get_History();
+	}
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Grid & CSG_Grid::_Operation_Arithmetic(double Value, TSG_Grid_Operation Operation)
+{
+	//-----------------------------------------------------
+	switch( Operation )
+	{
+	case GRID_OPERATION_Addition:
+		Get_History().Add_Child(LNG("[HST] Value addition")			, CSG_String::Format(SG_T("%f"), Value));
+		break;
+
+	case GRID_OPERATION_Subtraction:
+		Get_History().Add_Child(LNG("[HST] Value subtraction")		, CSG_String::Format(SG_T("%f"), Value));
+		Value	= -Value;
+		break;
+
+	case GRID_OPERATION_Multiplication:
+		Get_History().Add_Child(LNG("[HST] Value multiplication")	, CSG_String::Format(SG_T("%f"), Value));
+		break;
+
+	case GRID_OPERATION_Division:
+		if( Value == 0.0 )
+			return( *this );
+
+		Get_History().Add_Child(LNG("[HST] Value division")			, CSG_String::Format(SG_T("%f"), Value));
+		Value	= 1.0 / Value;
+		break;
+	}
+
+	//-----------------------------------------------------
+	for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+	{
+		for(int x=0; x<Get_NX(); x++)
+		{
+			if( !is_NoData(x, y) )
+			{
+				switch( Operation )
+				{
+				case GRID_OPERATION_Addition:
+				case GRID_OPERATION_Subtraction:
+					Add_Value(x, y, Value);
+					break;
+
+				case GRID_OPERATION_Multiplication:
+				case GRID_OPERATION_Division:
+					Mul_Value(x, y, Value);
+					break;
+				}
+			}
+		}
+	}
+
+	SG_UI_Process_Set_Ready();
+
+	return( *this );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Grid-Operations - A					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Grid::Invert(void)
+{
+	int		x, y;
+	double	zMin, zMax;
+
+	if( is_Valid() && Get_ZRange() > 0.0 )
+	{
+		zMin	= Get_ZMin();
+		zMax	= Get_ZMax();
+
+		for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !is_NoData(x, y) )
+				{
+					Set_Value(x, y, zMax - (asDouble(x, y) - zMin));
+				}
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		Get_History().Add_Child(LNG("[HST] Grid operation"), LNG("[HST] Inversion"));
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::Flip(void)
+{
+	int		x, yA, yB;
+	double	*Line, d;
+
+	if( is_Valid() )
+	{
+		Line	= (double *)SG_Malloc(Get_NX() * sizeof(double));
+
+		for(yA=0, yB=Get_NY()-1; yA<yB && SG_UI_Process_Set_Progress(2 * yA, Get_NY()); yA++, yB--)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				Line[x]	= asDouble(x, yA);
+			}
+
+			for(x=0; x<Get_NX(); x++)
+			{
+				d		= Line[x];
+				Line[x]	= asDouble(x, yB);
+				Set_Value(x, yB, d);
+			}
+
+			for(x=0; x<Get_NX(); x++)
+			{
+				Set_Value(x, yA, Line[x]);
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		SG_Free(Line);
+
+		Get_History().Add_Child(LNG("[HST] Grid operation"), LNG("[HST] Vertically mirrored"));
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::Mirror(void)
+{
+	int		xA, xB, y;
+	double	d;
+
+	if( is_Valid() )
+	{
+		for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+		{
+			for(xA=0, xB=Get_NX()-1; xA<xB; xA++, xB--)
+			{
+				d			=    asDouble(xA, y);
+				Set_Value(xA, y, asDouble(xB, y));
+				Set_Value(xB, y, d);
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		Get_History().Add_Child(LNG("[HST] Grid operation"), LNG("[HST] Horizontally mirrored"));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Grid-Operations - B					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define NORMALISED_NODATA	9.0
+
+//---------------------------------------------------------
+void CSG_Grid::Normalise(void)
+{
+	if( is_Valid() )
+	{
+		Update();
+
+		if( m_zStats.Get_StdDev() > 0.0 )
+		{
+			int		x, y;
+
+			if(	(Get_NoData_hiValue() > -NORMALISED_NODATA && Get_NoData_hiValue() < NORMALISED_NODATA)
+			||	(Get_NoData_Value  () > -NORMALISED_NODATA && Get_NoData_Value  () < NORMALISED_NODATA) )
+			{
+				for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+				{
+					for(x=0; x<Get_NX(); x++)
+					{
+						if( is_NoData(x, y) )
+						{
+							Set_Value(x, y, -NORMALISED_NODATA);
+						}
+					}
+				}
+
+				Set_NoData_Value(-NORMALISED_NODATA);
+			}
+
+			for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+			{
+				for(x=0; x<Get_NX(); x++)
+				{
+					if( !is_NoData(x, y) )
+					{
+						Set_Value(x, y, (asDouble(x, y) - m_zStats.Get_Mean()) / m_zStats.Get_StdDev() );
+					}
+				}
+			}
+
+			SG_UI_Process_Set_Ready();
+
+			Get_History().Add_Child(LNG("[HST] Grid normalisation"), CSG_String::Format(SG_T("%f / %f"), m_zStats.Get_Mean(), m_zStats.Get_StdDev()));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Grid::DeNormalise(double ArithMean, double Variance)
+{
+	int		x, y;
+
+	if( is_Valid() )
+	{
+		Variance	= sqrt(Variance);
+
+		for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
+		{
+			for(x=0; x<Get_NX(); x++)
+			{
+				if( !is_NoData(x, y) )
+				{
+					Set_Value(x, y, Variance * asDouble(x, y) + ArithMean);
+				}
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		Get_History().Add_Child(LNG("[HST] Grid denormalisation"), CSG_String::Format(SG_T("%f / %f"), ArithMean, Variance));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Grid::Get_Gradient_NeighborDir(int x, int y, bool bMustBeLower)	const
+{
+	int		i, ix, iy, Direction;
+	double	z, dz, dzMax;
+
+	Direction	= -1;
+
+	if( is_InGrid(x, y) )
+	{
+		z		= asDouble(x, y);
+		dzMax	= 0.0;
+
+		for(i=0; i<8; i++)
+		{
+			ix	= m_System.Get_xTo(i, x);
+			iy	= m_System.Get_yTo(i, y);
+
+			if( !is_InGrid(ix, iy) )
+			{
+				if( 1 )	// flag 'bStopOnNoData'
+				{
+					return( -1 );
+				}
+			}
+			else
+			{
+				dz	= (z - asDouble(ix, iy)) / m_System.Get_Length(i);
+
+				if( (bMustBeLower && dz > 0.0) || !bMustBeLower )
+				{
+					if( Direction < 0 || (dz > dzMax) )
+					{
+						Direction	= i;
+						dzMax		= dz;
+					}
+				}
+			}
+		}
+	}
+
+	return( Direction );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid::Get_Gradient(int x, int y, double &Decline, double &Azimuth) const
+{
+	int		i, ix, iy, iDir;
+	double	z, zm[4], G, H;
+
+	if( is_InGrid(x, y) )
+	{
+		z		= asDouble(x, y);
+
+		for(i=0, iDir=0; i<4; i++, iDir+=2)
+		{
+			ix		= m_System.Get_xTo(iDir, x);
+			iy		= m_System.Get_yTo(iDir, y);
+
+			if( is_InGrid(ix, iy) )
+			{
+				zm[i]	= asDouble(ix, iy) - z;
+			}
+			else
+			{
+				ix		= m_System.Get_xFrom(iDir, x);
+				iy		= m_System.Get_yFrom(iDir, y);
+
+				if( is_InGrid(ix, iy) )
+				{
+					zm[i]	= z - asDouble(ix, iy);
+				}
+				else
+				{
+					zm[i]	= 0.0;
+				}
+			}
+		}
+
+		G		= (zm[0] - zm[2]) / (2.0 * Get_Cellsize());
+        H		= (zm[1] - zm[3]) / (2.0 * Get_Cellsize());
+
+		Decline	= atan(sqrt(G*G + H*H));
+
+		if( G != 0.0 )
+			Azimuth	= M_PI_180 + atan2(H, G);
+		else
+			Azimuth	= H > 0.0 ? M_PI_270 : (H < 0.0 ? M_PI_090 : -1.0);
+
+		return( true );
+	}
+
+	Decline	= 0.0;
+	Azimuth	= -1.0;
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,261 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   grid_pyramids.cpp                   //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid_pyramid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid_Pyramid::CSG_Grid_Pyramid(void)
+{
+	m_nLevels	= 0;
+	m_pLevels	= NULL;
+	m_pGrid		= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Grid_Pyramid::CSG_Grid_Pyramid(CSG_Grid *pGrid, double Grow, TSG_Grid_Pyramid_Generalisation Generalisation, TSG_Grid_Pyramid_Grow_Type Grow_Type)
+{
+	m_nLevels	= 0;
+	m_pLevels	= NULL;
+	m_pGrid		= NULL;
+
+	Create(pGrid, Grow, Generalisation, Grow_Type);
+}
+
+//---------------------------------------------------------
+CSG_Grid_Pyramid::CSG_Grid_Pyramid(CSG_Grid *pGrid, double Grow, double Start, int nMaxLevels, TSG_Grid_Pyramid_Generalisation Generalisation, TSG_Grid_Pyramid_Grow_Type Grow_Type)
+{
+	m_nLevels	= 0;
+	m_pLevels	= NULL;
+	m_pGrid		= NULL;
+
+	Create(pGrid, Grow, Start, nMaxLevels, Generalisation, Grow_Type);
+}
+
+//---------------------------------------------------------
+CSG_Grid_Pyramid::~CSG_Grid_Pyramid(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_Pyramid::Create(CSG_Grid *pGrid, double Grow, TSG_Grid_Pyramid_Generalisation Generalisation, TSG_Grid_Pyramid_Grow_Type Grow_Type)
+{
+	if( pGrid && pGrid->is_Valid() && Grow > 1.0 && (pGrid->Get_NX() > Grow || pGrid->Get_NY() > Grow) )
+	{
+		Destroy();
+
+		m_Grow_Type			= Grow_Type;
+		m_nMaxLevels		= 0;
+		m_pGrid				= pGrid;
+		m_Grow				= Grow;
+		m_Generalisation	= Generalisation;
+
+		_Get_Next_Level(pGrid);
+
+		return( true );
+	}
+
+	return( false );	
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_Pyramid::Create(CSG_Grid *pGrid, double Grow, double Start, int nMaxLevels, TSG_Grid_Pyramid_Generalisation Generalisation, TSG_Grid_Pyramid_Grow_Type Grow_Type)
+{
+	if( pGrid && pGrid->is_Valid() && Grow > 0.0 && (pGrid->Get_NX() > Grow || pGrid->Get_NY() > Grow) )
+	{
+		Destroy();
+
+		m_Grow_Type			= Grow_Type;
+		m_nMaxLevels		= nMaxLevels;
+		m_pGrid				= pGrid;
+		m_Grow				= Grow;
+		m_Generalisation	= Generalisation;
+
+		if( Start > 0.0 )
+		{
+			_Get_Next_Level(pGrid, Start);
+		}
+		else
+		{
+			_Get_Next_Level(pGrid);
+		}
+
+		return( true );
+	}
+
+	return( false );	
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_Pyramid::Destroy(void)
+{
+	if( m_pLevels )
+	{
+		for(int i=0; i<m_nLevels; i++)
+		{
+			delete(m_pLevels[i]);
+		}
+
+		SG_Free(m_pLevels);
+
+		m_nLevels	= 0;
+		m_pLevels	= NULL;
+		m_pGrid		= NULL;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_Pyramid::_Get_Next_Level(CSG_Grid *pGrid)
+{
+	if( (m_nMaxLevels <= 0 || m_nLevels < m_nMaxLevels) )
+	{
+		int		nx, ny;
+		double	Cellsize;
+
+		switch( m_Grow_Type )
+		{
+		case GRID_PYRAMID_Arithmetic:	Cellsize	= pGrid->Get_Cellsize() + m_Grow;	break;
+		case GRID_PYRAMID_Geometric:	Cellsize	= pGrid->Get_Cellsize() * m_Grow;	break;
+		}
+
+		nx	= (int)(1.5 + m_pGrid->Get_XRange() / Cellsize);	if( nx < 1 )	nx	= 1;
+		ny	= (int)(1.5 + m_pGrid->Get_YRange() / Cellsize);	if( ny < 1 )	ny	= 1;
+
+		if( nx > 1 || ny > 1 )
+		{
+			CSG_Grid	*pNext	= SG_Create_Grid(SG_DATATYPE_Float, nx, ny, Cellsize, pGrid->Get_XMin(), pGrid->Get_YMin());
+
+			pNext->Set_NoData_Value(pGrid->Get_NoData_Value());
+			pNext->Assign(pGrid);
+
+			m_pLevels	= (CSG_Grid **)SG_Realloc(m_pLevels, (m_nLevels + 1) * sizeof(CSG_Grid *));
+			m_pLevels[m_nLevels++]	= pNext;
+
+			_Get_Next_Level(pNext);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_Pyramid::_Get_Next_Level(CSG_Grid *pGrid, double Cellsize)
+{
+	if( (m_nMaxLevels <= 0 || m_nLevels < m_nMaxLevels) )
+	{
+		int		nx, ny;
+
+		nx	= (int)(1.5 + m_pGrid->Get_XRange() / Cellsize);	if( nx < 1 )	nx	= 1;
+		ny	= (int)(1.5 + m_pGrid->Get_YRange() / Cellsize);	if( ny < 1 )	ny	= 1;
+
+		if( nx > 1 || ny > 1 )
+		{
+			CSG_Grid	*pNext	= SG_Create_Grid(SG_DATATYPE_Float, nx, ny, Cellsize, pGrid->Get_XMin(), pGrid->Get_YMin());
+
+			pNext->Set_NoData_Value(pGrid->Get_NoData_Value());
+			pNext->Assign(pGrid);
+
+			m_pLevels	= (CSG_Grid **)SG_Realloc(m_pLevels, (m_nLevels + 1) * sizeof(CSG_Grid *));
+			m_pLevels[m_nLevels++]	= pNext;
+
+			_Get_Next_Level(pNext);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_pyramid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,155 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    grid_pyramids.h                    //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__grid_pyramid_H
+#define HEADER_INCLUDED__SAGA_API__grid_pyramid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_Pyramid_Generalisation
+{
+	GRID_PYRAMID_Mean	= 0,
+	GRID_PYRAMID_Max,
+	GRID_PYRAMID_Min,
+	GRID_PYRAMID_MaxCount
+}
+TSG_Grid_Pyramid_Generalisation;
+
+//---------------------------------------------------------
+typedef enum ESG_Grid_Pyramid_Grow_Type
+{
+	GRID_PYRAMID_Arithmetic	= 0,
+	GRID_PYRAMID_Geometric
+}
+TSG_Grid_Pyramid_Grow_Type;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Grid_Pyramid
+{
+public:
+	CSG_Grid_Pyramid(void);
+
+										CSG_Grid_Pyramid	(class CSG_Grid *pGrid, double Grow = 2.0, TSG_Grid_Pyramid_Generalisation Generalisation = GRID_PYRAMID_Mean, TSG_Grid_Pyramid_Grow_Type Grow_Type = GRID_PYRAMID_Geometric);
+	bool								Create				(class CSG_Grid *pGrid, double Grow = 2.0, TSG_Grid_Pyramid_Generalisation Generalisation = GRID_PYRAMID_Mean, TSG_Grid_Pyramid_Grow_Type Grow_Type = GRID_PYRAMID_Geometric);
+
+										CSG_Grid_Pyramid	(class CSG_Grid *pGrid, double Grow, double Start, int nMaxLevels, TSG_Grid_Pyramid_Generalisation Generalisation = GRID_PYRAMID_Mean, TSG_Grid_Pyramid_Grow_Type Grow_Type = GRID_PYRAMID_Geometric);
+	bool								Create				(class CSG_Grid *pGrid, double Grow, double Start, int nMaxLevels, TSG_Grid_Pyramid_Generalisation Generalisation = GRID_PYRAMID_Mean, TSG_Grid_Pyramid_Grow_Type Grow_Type = GRID_PYRAMID_Geometric);
+
+	virtual ~CSG_Grid_Pyramid(void);
+
+	bool								Destroy				(void);
+
+
+	int									Get_Count			(void)			{	return( m_nLevels );	}
+	class CSG_Grid *					Get_Grid			(int iLevel)	{	return( iLevel >= 0 && iLevel < m_nLevels ? m_pLevels[iLevel] : m_pGrid );	}
+
+
+private:
+
+	int									m_nLevels, m_nMaxLevels;
+
+	double								m_Grow;
+
+	TSG_Grid_Pyramid_Generalisation		m_Generalisation;
+
+	TSG_Grid_Pyramid_Grow_Type			m_Grow_Type;
+
+	class CSG_Grid						**m_pLevels, *m_pGrid;
+
+
+	bool								_Get_Next_Level		(class CSG_Grid *pGrid);
+	bool								_Get_Next_Level		(class CSG_Grid *pGrid, double Cellsize);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__grid_pyramid_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_system.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_system.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/grid_system.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,279 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   grid_system.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                Universit??? G???tingen                  //
+//                Goldschmidtstr. 5                      //
+//                37077 G???tingen                        //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid_System::CSG_Grid_System(void)
+{
+	m_Cellsize		= -1.0;
+
+	m_NX	= m_NY	= 0;
+}
+
+//---------------------------------------------------------
+CSG_Grid_System::CSG_Grid_System(const CSG_Grid_System &System)
+{
+	m_Cellsize	= -1.0;
+
+	Assign(System);
+}
+
+//---------------------------------------------------------
+CSG_Grid_System::CSG_Grid_System(double Cellsize, const CSG_Rect &Extent)
+{
+	m_Cellsize	= -1.0;
+
+	Assign(Cellsize, Extent);
+}
+
+//---------------------------------------------------------
+CSG_Grid_System::CSG_Grid_System(double Cellsize, double xMin, double yMin, double xMax, double yMax)
+{
+	m_Cellsize	= -1.0;
+
+	Assign(Cellsize, xMin, yMin, xMax, yMax);
+}
+
+//---------------------------------------------------------
+CSG_Grid_System::CSG_Grid_System(double Cellsize, double xMin, double yMin, int NX, int NY)
+{
+	m_Cellsize	= -1.0;
+
+	Assign(Cellsize, xMin, yMin, NX, NY);
+}
+
+//---------------------------------------------------------
+CSG_Grid_System::~CSG_Grid_System(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_System::is_Valid(void) const
+{
+	return( m_Cellsize > 0.0 );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Grid_System::Get_Name(bool bShort)
+{
+	if( is_Valid() )
+	{
+		if( bShort )
+		{
+			m_Name.Printf(SG_T("%.*f; %dx %dy; %.*fx %.*fy"),
+				SG_Get_Significant_Decimals(Get_Cellsize()),
+				Get_Cellsize(),
+				Get_NX(),
+				Get_NY(),
+				SG_Get_Significant_Decimals(Get_XMin()), Get_XMin(),
+				SG_Get_Significant_Decimals(Get_YMin()), Get_YMin()
+			);
+		}
+		else
+		{
+			m_Name.Printf(SG_T("%s: %f, %s: %dx/%dy, %s: %fx/%fy"),
+				LNG("[DAT] Cell size"),
+				Get_Cellsize(),
+				LNG("[DAT] Number of cells"),
+				Get_NX(),
+				Get_NY(),
+				LNG("[DAT] Lower left corner"),
+				Get_XMin(),
+				Get_YMin()
+			);
+		}
+
+		return( m_Name );
+	}
+
+	return( LNG("[DAT] [not set]") );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_System::operator == (const CSG_Grid_System &System) const
+{
+	return( is_Equal(System) );
+}
+
+//---------------------------------------------------------
+void CSG_Grid_System::operator = (const CSG_Grid_System &System)
+{
+	Assign(System);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_System::Assign(const CSG_Grid_System &System)
+{
+	return( Assign(System.m_Cellsize, System.m_Extent) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_System::Assign(double Cellsize, const CSG_Rect &Extent)
+{
+	return( Assign(Cellsize, Extent.m_rect.xMin, Extent.m_rect.yMin, Extent.m_rect.xMax, Extent.m_rect.yMax) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_System::Assign(double Cellsize, double xMin, double yMin, double xMax, double yMax)
+{
+	if( Cellsize > 0.0 && xMin < xMax && yMin < yMax )
+	{
+		return( Assign(Cellsize, xMin, yMin, 1 + (int)(0.5 + (xMax - xMin) / Cellsize), 1 + (int)(0.5 + (yMax - yMin) / Cellsize)) );
+	}
+
+	m_Cellsize	= -1.0;
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_System::Assign(double Cellsize, double xMin, double yMin, int NX, int NY)
+{
+	if( Cellsize > 0.0 && NX > 0 && NY > 0 )
+	{
+		m_NX		= NX;
+		m_NY		= NY;
+		m_NCells	= NY * NX;
+
+		m_Cellsize	= Cellsize;
+		m_Cellarea	= Cellsize * Cellsize;
+
+		m_Extent		.Assign(
+			xMin,
+			yMin,
+			xMin + (NX - 1.0) * Cellsize,
+			yMin + (NY - 1.0) * Cellsize
+		);
+
+		m_Extent_Cells	.Assign(
+			xMin - 0.5 * Cellsize,
+			yMin - 0.5 * Cellsize,
+			xMin + (NX - 0.5) * Cellsize,
+			yMin + (NY - 0.5) * Cellsize
+		);
+
+		m_Diagonal	= Cellsize * sqrt(2.0);
+
+		return( true );
+	}
+
+	m_Cellsize	= -1.0;
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_System::is_Equal(const CSG_Grid_System &System) const
+{
+	return( is_Equal(System.m_Cellsize, System.m_Extent.m_rect) );
+}
+
+//---------------------------------------------------------
+bool CSG_Grid_System::is_Equal(double Cellsize, const TSG_Rect &Extent) const
+{
+	return( m_Cellsize == Cellsize && m_Extent == Extent );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_formula.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_formula.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_formula.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1398 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    mat_formula.cpp                    //
+//                                                       //
+//         Copyright (C) 2002 by Andre Ringeler          //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     aringel at saga-gis.org                   //
+//                                                       //
+//    contact:    Andre Ringeler                         //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// Based on                                              //
+// FORMULC.C 2.22           as of 2/19/98                //
+// Copyright (c) 1993 - 98 by Harald Helfgott            //
+//                                                       //
+// Modified for Grid Data by Andre Ringeler 2001         //
+// Modified for Function-Fitting by Andre Ringeler 2002  //
+// Converted to C++ by Andre Ringeler 2002               //
+//                                                       //
+// Modified to fit SAGA needs by Olaf Conrad 2002        //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include "mat_tools.h"
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MAX_PARMS			3
+#define MAX_CTABLE			255
+
+#define STD_FNC_NUM			19
+
+//---------------------------------------------------------
+#define GET_VALUE_BUFSIZE	500
+
+//---------------------------------------------------------
+#define EPSILON				1e-9
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+static double f_atan2(double x, double val)
+{
+	return( atan2(x, val) );
+}
+
+//---------------------------------------------------------
+static double f_gt(double x, double val)
+{
+	return( x > val ? 1.0 : 0.0 );
+}
+
+//---------------------------------------------------------
+static double f_lt(double x, double val)
+{
+	return( x < val ? 1.0 : 0.0 );
+}
+
+//---------------------------------------------------------
+static double f_eq(double x, double val)
+{
+	return( fabs(x - val) < EPSILON ? 1.0 : 0.0 );
+}
+
+//---------------------------------------------------------
+static double f_pi(void)
+{
+	return( M_PI );
+}
+
+//---------------------------------------------------------
+static double f_int(double x)
+{
+	return( (int)(x) );
+}
+
+//---------------------------------------------------------
+static double f_fmod(double x, double val)
+{
+	return( fmod(x, val) );
+}
+
+//---------------------------------------------------------
+static double f_ifelse(double condition, double x, double y)
+{
+	return( fabs(condition - 1.0) < EPSILON ? x : y );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+static CSG_Formula::TSG_Formula_Item gSG_Functions[MAX_CTABLE]	=
+{
+	{SG_T("exp")	,						exp		, 1, 0},	//  1
+	{SG_T("ln")		,						log		, 1, 0},	//  2
+	{SG_T("sin")	,						sin		, 1, 0},	//  3
+	{SG_T("cos")	,						cos		, 1, 0},	//  4
+	{SG_T("tan")	,						tan		, 1, 0},	//  5
+	{SG_T("asin")	,						asin	, 1, 0},	//  6
+	{SG_T("acos")	,						acos	, 1, 0},	//  7
+	{SG_T("atan")	,						atan	, 1, 0},	//  8
+	{SG_T("atan2")	, (TSG_PFNC_Formula_1)	f_atan2	, 2, 0},	//  9
+	{SG_T("abs")	,						fabs	, 1, 0},	// 10
+	{SG_T("sqrt")	,						sqrt	, 1, 0},	// 11
+	{SG_T("gt")		, (TSG_PFNC_Formula_1)	f_gt	, 2, 0},	// 12
+	{SG_T("lt")		, (TSG_PFNC_Formula_1)	f_lt	, 2, 0},	// 13
+	{SG_T("eq")		, (TSG_PFNC_Formula_1)	f_eq	, 2, 0},	// 14
+	{SG_T("pi")		, (TSG_PFNC_Formula_1)	f_pi	, 0, 0},	// 15
+	{SG_T("int")	, (TSG_PFNC_Formula_1)	f_int	, 1, 0},	// 16
+	{SG_T("mod")	, (TSG_PFNC_Formula_1)	f_fmod	, 2, 0},	// 17
+	{SG_T("ifelse")	, (TSG_PFNC_Formula_1)	f_ifelse, 3, 0},	// 18
+	{SG_T("log")	,						log10	, 1, 0},	// 19
+	{NULL			,						NULL	, 0, 0}
+};
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Formula::CSG_Formula(void)
+{
+	i_ctable	= NULL;
+	i_error		= NULL;
+
+	m_bError	= false;
+
+	m_Formula.code		= NULL;
+	m_Formula.ctable	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Formula::~CSG_Formula(void)
+{
+	if( m_Formula.code )
+	{
+		SG_Free(m_Formula.code);
+		m_Formula.code		= NULL;
+	}
+
+	if( m_Formula.ctable )
+	{
+		SG_Free(m_Formula.ctable);
+		m_Formula.ctable	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_Formula::Get_Help_Operators(void)
+{
+	return( SG_Translate(
+		SG_T("+ Addition\n")
+		SG_T("- Subtraction\n")
+		SG_T("* Multiplication\n")
+		SG_T("/ Division\n")
+		SG_T("^ power\n")
+		SG_T("abs(x)          - absolute value\n")
+		SG_T("sqrt(x)         - square root\n")
+		SG_T("ln(x)           - natural logarithm\n")
+		SG_T("log(x)          - base 10 logarithm\n")
+		SG_T("exp(x)          - exponential\n")
+		SG_T("sin(x)          - sine\n")
+		SG_T("cos(x)          - cosine\n")
+		SG_T("tan(x)          - tangent\n")
+		SG_T("asin(x)         - arcsine\n")
+		SG_T("acos(x)         - arccosine\n")
+		SG_T("atan(x)         - arctangent\n")
+		SG_T("atan2(x, y)     - arctangent of x/y\n")
+		SG_T("gt(x, y)        - if x>y the result is 1.0, else 0.0\n")
+		SG_T("lt(x, y)        - if x<y the result is 1.0, else 0.0\n")
+		SG_T("eq(x, y)        - if x=y the result is 1.0, else 0.0\n")
+		SG_T("mod(x, y)       - returns the floating point remainder of x/y\n")
+		SG_T("ifelse(c, x, y) - if c=1 the result is x, else y\n")
+		SG_T("int(x)          - integer part of floating point value x\n")
+		SG_T("pi()            - returns the value of Pi\n")
+	));
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Formula::Get_Help_Usage(void)
+{
+	return( SG_Translate(
+		SG_T("Use single characters to define the parameters of your function f(x)\n")
+		SG_T("Example: 'a + b * x'\n")
+	));
+}
+
+//---------------------------------------------------------
+bool CSG_Formula::Get_Error(int *pPosition, CSG_String *pMessage)
+{
+	if( m_Formula.code )
+	{
+		if( pPosition )
+		{
+			*pPosition	= m_Error_Position;
+		}
+
+		if( pMessage )
+		{
+			*pMessage	= m_sError;
+		}
+	}
+
+	return( m_bError );
+}
+
+//---------------------------------------------------------
+void CSG_Formula::_Set_Error(const SG_Char *Error)
+{
+	if( Error == NULL || *Error == SG_T('\0') )
+	{
+		m_bError	= false;
+		m_sError	.Clear();
+	}
+	else
+	{
+		m_bError	= true;
+		m_sError	= Error;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Formula::Set_Variable(SG_Char Var, double Value)
+{
+	m_Parameters[Var - 'a']	= Value;
+}
+
+//---------------------------------------------------------
+bool CSG_Formula::Set_Formula(const SG_Char *Formula)
+{
+	if( Formula )
+	{
+		m_sFormula	= Formula;
+
+		if( m_Formula.code )
+		{
+			SG_Free(m_Formula.code);
+			m_Formula.code		= NULL;
+		}
+
+		if( m_Formula.ctable )
+		{
+			SG_Free(m_Formula.ctable);
+			m_Formula.ctable	= NULL;
+		}
+
+		m_Formula	= _Translate(Formula, SG_T("abcdefghijklmnopqrstxyz"), &m_Length, &m_Error_Position);
+
+		return( m_Formula.code != NULL );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Formula::Get_Value(void)
+{
+	_Set_Error();
+
+	return( _Get_Value(m_Formula) );
+}
+
+//---------------------------------------------------------
+double CSG_Formula::Get_Value(double x)
+{
+	m_Parameters['x'-'a']	= x;
+
+	_Set_Error();
+
+	return( _Get_Value(m_Formula) );
+}
+
+//---------------------------------------------------------
+double CSG_Formula::Get_Value(double *Values, int nValues)
+{
+	for(int i=0; i<nValues; i++)
+	{
+		m_Parameters[i]	= Values[i];
+	}
+
+	_Set_Error();
+
+	return( _Get_Value(m_Formula) );
+}
+
+//---------------------------------------------------------
+double CSG_Formula::Get_Value(SG_Char *Args, ...)
+{
+	va_list	ap;
+
+	va_start(ap, Args);
+
+	while( *Args )
+	{
+		m_Parameters[(*Args++) - 'a']	= va_arg(ap, double);
+	}
+
+	va_end(ap);
+
+	_Set_Error();
+
+	return( _Get_Value(m_Formula) );
+}
+
+//---------------------------------------------------------
+double CSG_Formula::_Get_Value(TMAT_Formula func)
+{
+	double	x, y, z, buffer[GET_VALUE_BUFSIZE];
+
+	register double		*bufp		= buffer;	// points to the first free space in the buffer
+	register SG_Char	*function	= func.code;
+	register double		*ctable		= func.ctable;
+	register double		result;
+
+	if( !function )
+	{
+		_Set_Error(LNG("empty coded function"));
+
+		return( 0 );
+	}
+
+	for(; ; )
+	{
+		switch( *function++ )
+		{
+		case SG_T('\0'):
+			goto finish;	// there is a reason for this "goto": this function must be as fast as possible
+
+		case 'D': 
+			*bufp++	= ctable[*function++];
+			break;
+
+		case 'V': 
+			*bufp++	= m_Parameters[(*function++) - 'a'];
+			break;
+
+		case 'M':
+			result	= -(*--bufp);
+			*bufp++	= result;
+			break;
+
+		case '+':
+			y		= *(--bufp);
+			result	= y + *(--bufp);
+			*bufp++	= result;
+			break;
+
+		case '-':
+			y		= *--bufp;
+			result	= *(--bufp) - y;
+			*bufp++	= result;
+			break;
+
+		case '*':
+			y		= *(--bufp);
+			result	= *(--bufp) * y;
+			*bufp++ = result;
+			break;
+
+		case '/':
+			y		= *--bufp;
+			result	= *(--bufp) / y;
+			*bufp++	= result;
+			break;
+
+		case '^':
+			y		= *--bufp;
+			result	= pow(*(--bufp), y);
+			*bufp++	= result;
+			break;
+
+		case '=':
+			y		= *--bufp;
+			result	= y == *(--bufp) ? 1.0 : 0.0;
+			*bufp++	= result;
+			break;
+
+		case '>':
+			y		= *--bufp;
+			result	= y < *(--bufp) ? 1.0 : 0.0;
+			*bufp++	= result;
+			break;
+
+		case '<':
+			y		= *--bufp;
+			result	= y > *(--bufp) ? 1.0 : 0.0;
+			*bufp++	= result;
+			break;
+
+		case '&':
+			y		= *--bufp;
+			result	= y != 0.0 && *(--bufp) != 0.0 ? 1.0 : 0.0;
+			*bufp++	= result;
+			break;
+
+		case '|':
+			y		= *--bufp;
+			result	= y != 0.0 || *(--bufp) != 0.0 ? 1.0 : 0.0;
+			*bufp++	= result;
+			break;
+
+		case 'F':
+			switch (gSG_Functions[*function].n_pars)
+			{
+			case 0:
+				*bufp++	= ((TSG_PFNC_Formula_0)gSG_Functions[*function++].f)();
+				break;
+
+			case 1:
+				x		= *--bufp;
+				*bufp++	= gSG_Functions[*function++].f(x);
+				break;
+
+			case 2:
+				y		= *--bufp;
+				x		= *--bufp;
+				*bufp++	=((TSG_PFNC_Formula_2)gSG_Functions[*function++].f)(x, y);
+				break;
+
+			case 3:
+				z		= *--bufp;
+				y		= *--bufp;
+				x		= *--bufp;
+				*bufp++	=((TSG_PFNC_Formula_3)gSG_Functions[*function++].f)(x, y, z);
+				break;
+
+			default:
+				_Set_Error(LNG("I2: too many parameters"));
+				return( 0 );
+			}
+			break;
+
+		default:
+			_Set_Error(LNG("I1: unrecognizable operator"));
+			return( 0 );
+		}
+	}
+
+finish:
+
+	if( (bufp - buffer) != 1 )
+	{
+		_Set_Error(LNG("I3: corrupted buffer"));
+	}
+
+	return( buffer[0] );
+} 
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Formula::Get_Used_Variables(void)
+{
+	static CSG_String	ret;
+
+	ret.Clear();
+
+	for(int i=0; i<'z'-'a'; i++)
+	{
+		if( m_Vars_Used[i] == true )
+		{
+			ret.Append((SG_Char)(i + 'a'));
+		}
+	}
+
+	return( ret );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// If the function exists, it is deleted and a non-negative
+// value is returned. Otherwise, -1 is returned.
+// Original library functions may not be deleted.
+//
+int CSG_Formula::Del_Function(SG_Char *name)
+{
+	int		place	 = _Get_Function(name);
+
+	if( place == -1 )
+	{
+		return( -1 );	// there is an error message already
+	}
+
+	if( place < STD_FNC_NUM )
+	{
+		_Set_Error(LNG("original functions may not be deleted"));
+
+		return( -1 );
+	}
+
+	free(gSG_Functions[place].name);
+
+	TSG_Formula_Item	*pFunction;
+
+	for(pFunction=&gSG_Functions[place]; pFunction->f!=NULL; pFunction++)
+	{
+		pFunction->name		= (pFunction + 1)->name;
+		pFunction->f		= (pFunction + 1)->f;
+		pFunction->n_pars	= (pFunction + 1)->n_pars;
+	}
+
+	_Set_Error();
+
+	return( pFunction - gSG_Functions );
+}
+
+//---------------------------------------------------------
+// int varying;  Does the result of the function vary
+// even when the parameters stay the same?
+// varying = 1 for e.g. random - number generators.
+// Result: 0 is rendered if there is an error
+// 1 is rendered otherwise
+//
+int CSG_Formula::Add_Function(SG_Char *name, TSG_PFNC_Formula_1 f, int n_pars, int varying)
+{
+	TSG_Formula_Item *where;
+	
+	if( n_pars < 0 || n_pars > 3 )
+	{
+		_Set_Error(LNG("invalid number of parameters"));
+
+		return( 0 );
+	}
+
+	for(where=gSG_Functions; where->f != NULL && SG_STR_CMP(name, where->name); where++)
+	{
+		;
+	}
+
+	if( where->f != NULL )
+	{
+		where->f		= f;
+		where->varying	= varying;
+		where->n_pars	= n_pars;   /*old function is superseded */
+
+		_Set_Error();
+
+		return( 1 );
+	}
+	else if( (where - gSG_Functions) >= MAX_CTABLE - 1 )
+	{
+		_Set_Error(LNG("function table full"));
+
+		return 0;
+	}
+	else 
+	{
+		where->name	=(SG_Char *)calloc(SG_STR_LEN(name) + 1, sizeof(SG_Char));
+
+		if( where->name == NULL )
+		{
+			_Set_Error(LNG("no memory"));
+
+			return( 0 );
+		}
+
+		SG_STR_CPY(where->name, name);
+		where->f		= f;
+		where->varying	= varying;
+		where->n_pars	= n_pars;
+
+		_Set_Error();
+
+		return( 1 );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Formula::_Get_Function(int i, SG_Char *name, int *n_pars, int *varying)
+{
+	if( !gSG_Functions[i].f )
+	{
+		_Set_Error(LNG("index out of bounds"));
+
+		return( 0 );
+	}
+
+	SG_STR_CPY(name, gSG_Functions[i].name);
+
+	*n_pars		= gSG_Functions[i].n_pars;
+	*varying	= gSG_Functions[i].varying;
+
+	_Set_Error();
+
+	return( 1 );
+}
+
+//---------------------------------------------------------
+// If the function exists, _Get_Function() returns the index
+// of its name in the table. Otherwise, it returns -1.
+//
+int CSG_Formula::_Get_Function(SG_Char *name)
+{
+	TSG_Formula_Item	*pFunction;
+
+	for(pFunction=gSG_Functions; pFunction->f && SG_STR_CMP(name, pFunction->name); pFunction++)
+	{}
+
+	if( pFunction->f == NULL )
+	{
+		_Set_Error(LNG("function not found"));
+
+		return( -1 );
+	}
+
+	_Set_Error();
+
+	return( pFunction - gSG_Functions );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline int CSG_Formula::_is_Operand(SG_Char c)
+{
+	return(	(c == SG_T('+'))
+		||	(c == SG_T('-'))
+		||	(c == SG_T('*'))
+		||	(c == SG_T('/'))
+		||	(c == SG_T('^'))
+		||	(c == SG_T('='))
+		||	(c == SG_T('<'))
+		||	(c == SG_T('>'))
+		||	(c == SG_T('&'))
+		||	(c == SG_T('|'))
+	);
+}
+
+//---------------------------------------------------------
+inline int CSG_Formula::_is_Operand_Code(SG_Char c)
+{
+	return(	(c == SG_T('+'))
+		||	(c == SG_T('-'))
+		||	(c == SG_T('*'))
+		||	(c == SG_T('/'))
+		||	(c == SG_T('^'))
+		||	(c == SG_T('='))
+		||	(c == SG_T('<'))
+		||	(c == SG_T('>'))
+		||	(c == SG_T('&'))
+		||	(c == SG_T('|'))
+		||	(c == SG_T('M'))
+	);
+}
+
+//---------------------------------------------------------
+inline int CSG_Formula::_is_Number(SG_Char c)
+{
+	return( isdigit(c) || c == '.' || c == 'E' );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////
+// Interpreting functions                                //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Formula::TMAT_Formula CSG_Formula::_Translate(const SG_Char *sourc, const SG_Char *args, int *leng, int *error)
+{
+	SG_Char *result;
+	SG_Char *source;
+	const SG_Char *scan, *scarg;
+	SG_Char *code;
+	SG_Char *nfunc; 
+	size_t size_estim; 
+
+	double *ctable;
+	TMAT_Formula returned; 
+
+	//-----------------------------------------------------
+	*leng			= 0;
+	*error			= 0; 
+	returned.code	= NULL;
+	returned.ctable	= NULL;
+
+	i_error = NULL;
+
+	//-----------------------------------------------------
+	source	= (SG_Char *)SG_Malloc((SG_STR_LEN(sourc) + 1) * sizeof(SG_Char));
+
+	if( source == NULL )
+	{
+		_Set_Error(LNG("no memory"));
+
+		return( returned );
+	}
+
+	SG_STR_CPY(source, sourc);
+
+	for(scan=source; *scan!=SG_T('\0'); scan++)
+	{
+		if( islower(*scan) && !isalpha(*(scan + 1)) && (scan == source || !isalpha(*(scan - 1))) )
+		{
+			for(scarg=args; *scarg!=SG_T('\0') && *scarg != *scan; scarg++)
+			{}
+
+			if( *scarg == SG_T('\0') )
+			{
+				_Set_Error(LNG("undeclared parameter"));
+
+				i_error	= scan;
+				*error	= i_error - source;
+				
+				SG_Free(source);
+
+				return (returned);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	size_estim = max_size(source); 
+
+	if( !(code =(SG_Char *) SG_Malloc(size_estim)) )
+	{
+		_Set_Error(LNG("no memory"));
+
+		*error	= -1;
+
+		SG_Free(source);
+
+		return (returned);
+	}
+	
+	
+	//-----------------------------------------------------
+	i_pctable = 0;
+
+	if( !(i_ctable = (double *)SG_Malloc(MAX_CTABLE * sizeof(double))) )
+	{
+		_Set_Error(LNG("no memory"));
+
+		*error = -1;
+
+		SG_Free(source);
+		SG_Free(code);
+
+		return (returned);
+	}
+
+	ctable = i_ctable;
+
+	//-----------------------------------------------------
+	_Set_Error();
+
+	result = i_trans(code, (SG_Char *)source, (SG_Char *)source + SG_STR_LEN(source));
+
+	if( !result || m_bError )
+	{
+		*error	= i_error ? i_error - source : -1;
+
+		SG_Free(source);
+		SG_Free(code);
+		SG_Free(i_ctable);
+
+		return (returned);
+	}
+	else 
+	{
+		*result	= SG_T('\0');
+		*error	= -1;
+		*leng	= result - code;
+
+		if( ((*leng) + 1) * sizeof(SG_Char) > size_estim )
+		{
+			_Set_Error(LNG("I4: size estimate too small"));
+
+			SG_Free(source);
+
+			return( returned );
+		}
+		else if( ((*leng) + 1) * sizeof(SG_Char) < size_estim )
+		{
+			nfunc	= (SG_Char *) SG_Malloc(((*leng) + 1) * sizeof(SG_Char));
+
+			if (nfunc) 
+			{
+				memcpy(nfunc, code, ((*leng) + 1) * sizeof(SG_Char));
+				SG_Free(code);
+				code = nfunc;
+			}
+		}
+
+		if( i_pctable < MAX_CTABLE )
+		{
+			ctable	= (double *)SG_Malloc(i_pctable * sizeof(double));
+
+			if( ctable )
+			{
+				memcpy(ctable, i_ctable, i_pctable * sizeof(double));
+
+				SG_Free(i_ctable);
+			}
+			else 
+			{
+				ctable	= i_ctable;
+			}
+		}
+		else 
+		{
+			ctable	= i_ctable;
+		}
+
+		returned.code	= code;
+		returned.ctable	= ctable;
+
+		_Set_Error();
+
+		SG_Free(source);
+
+		return (returned);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+SG_Char *CSG_Formula::i_trans(SG_Char *function, SG_Char *begin, SG_Char *end)
+{
+	int pars;     
+	SG_Char *scan;
+	SG_Char *tempu, *temp3;
+	SG_Char *temps	= NULL;
+	SG_Char tempch;
+	double tempd;
+	SG_Char *endf;     
+	
+	int n_function;
+	int space;
+	int i;
+	
+	SG_Char *paramstr[MAX_PARMS];
+	SG_Char *par_buf;
+	
+	if (begin >= end)
+	{
+		_Set_Error(LNG("missing operand"));
+		i_error = begin;
+		return NULL;
+	}
+	
+	for (pars = 0, scan = begin; scan < end && pars >= 0; scan++)
+	{
+		if (*scan == SG_T('(')) pars++;
+		else if (*scan == SG_T(')'))
+			pars--;
+	}
+	if (pars < 0 || pars > 0)
+	{
+		_Set_Error(LNG("unmatched parentheses"));
+		i_error = scan - 1;
+		return NULL;
+	}
+	
+	for (pars = 0, scan = end - 1; scan >= begin; scan--)
+	{
+		if (*scan == SG_T('(')) pars++;
+		else if (*scan == SG_T(')'))
+			pars--;
+		else if (!pars &&(*scan == SG_T('+') ||((*scan == SG_T('-')) && scan != begin))
+			&&(scan == begin || *(scan - 1) != SG_T('E')))
+			break;
+	}
+	
+	if (scan >= begin)
+	{                                 
+		if ((tempu = i_trans(function, begin, scan)) &&      
+			(temp3 = i_trans(tempu, scan + 1, end)))
+		{
+			*temp3++ = *scan; 
+			temp3 = comp_time(function, temp3, 2); 
+			if( m_bError )
+				return NULL;   
+			else 
+				return temp3;  
+		}
+		else 
+			return NULL;  
+	}
+	
+	for (pars = 0, scan = end - 1; scan >= begin; scan--)
+	{
+		if (*scan == SG_T('(')) pars++;
+		else if (*scan == SG_T(')'))
+			pars--;
+		else if (!pars &&(*scan == SG_T('*') || *scan == SG_T('/')))
+			break;
+	}
+	if (scan >= begin)
+	{                                 
+		if ((tempu = i_trans(function, begin, scan)) &&      
+			(temp3 = i_trans(tempu, scan + 1, end)))
+		{
+			*temp3++ = *scan; 
+			temp3 = comp_time(function, temp3, 2); 
+			if (m_bError)
+				return NULL;   
+			else 
+				return temp3;  
+		}
+		else 
+			return NULL;  
+	}
+	
+	/* unary minus */
+	if (*begin == SG_T('-'))
+	{
+		tempu = i_trans(function, begin + 1, end);
+		if (tempu)
+		{
+			*tempu++ = SG_T('M');
+			tempu = comp_time(function, tempu, 1); 
+			if (m_bError)
+				return NULL; 
+			else 
+				return tempu;
+		}
+		else 
+			return NULL;
+	}
+	
+	for (pars = 0, scan = end - 1; scan >= begin; scan--)
+	{
+		if (*scan == SG_T('(')) pars++;
+		else if (*scan == SG_T(')'))
+			pars--;
+		else if (!pars &&(*scan == SG_T('^')))
+			break;
+		else if (!pars &&(*scan == SG_T('=')))
+			break;
+		else if (!pars &&(*scan == SG_T('>')))
+			break;
+		else if (!pars &&(*scan == SG_T('<')))
+			break;
+		else if (!pars &&(*scan == SG_T('&')))
+			break;
+		else if (!pars &&(*scan == SG_T('|')))
+			break;
+	}
+
+	if (scan >= begin)
+	{                                 
+		if ((tempu = i_trans(function, begin, scan)) &&      
+			(temp3 = i_trans(tempu, scan + 1, end)))
+		{
+			*temp3++ = *scan; 
+			temp3 = comp_time(function, temp3, 2); 
+			if (m_bError)
+				return NULL;   
+			else 
+				return temp3;  
+		}
+		else 
+			return NULL;  
+	}
+	
+	/* erase white space */
+	while (isspace(*begin))
+		begin++;
+	while (isspace(*(end - 1)))
+		end--;
+	
+	if (*begin == SG_T('(') && *(end - 1) == SG_T(')'))
+		return i_trans(function, begin + 1, end - 1);
+	
+	if (end == begin + 1 && islower(*begin))
+	{
+		*function++ = SG_T('V');
+		*function++ = *begin;
+		return function;
+	}
+	
+	tempch = *end;
+	*end = SG_T('\0');
+	tempd = SG_STR_TOD(begin, (SG_Char**) &tempu);
+	*end = tempch;
+	if ((SG_Char*) tempu == end)
+	{
+		*function++ = SG_T('D');
+		if (i_pctable < MAX_CTABLE)
+		{
+			i_ctable[i_pctable] = tempd;
+			*function++ =(SG_Char) i_pctable++;
+		}
+		else
+		{
+			_Set_Error(LNG("too many constants"));
+			i_error = begin;
+			return NULL;
+		}
+		return function;
+	}
+	
+				/*function*/
+	if (!isalpha(*begin) && *begin != SG_T('_'))
+	{
+		_Set_Error(LNG("syntax error"));
+		i_error = begin;
+		return NULL;
+	}
+	for (endf = begin + 1; endf < end &&(isalnum(*endf) || *endf == SG_T('_'));
+	endf++)
+		;
+	tempch = *endf;
+	*endf = SG_T('\0');
+	if ((n_function = _Get_Function(begin)) == -1)
+	{
+		*endf = tempch;
+		i_error = begin;
+		return NULL;
+	}
+	*endf = tempch;
+	if (*endf != SG_T('(') || *(end - 1) != SG_T(')'))
+	{
+		_Set_Error(LNG("improper function syntax"));
+		i_error = endf;
+		return NULL;
+	}
+	if (gSG_Functions[n_function].n_pars == 0)
+	{
+		/*function without parameters(e.g. pi()) */
+		space = 1;
+		for (scan = endf + 1; scan <(end - 1); scan++)
+			if (!isspace(*scan))
+				space = 0;
+			if (space)
+			{
+				*function++ = SG_T('F');
+				*function++ = n_function;
+				function = comp_time(function - 2, function, 0);
+				if (m_bError)
+					return NULL; /* internal error in comp_time */
+				else 
+					return function;
+			}
+			else 
+			{
+				i_error = endf + 1;
+				_Set_Error(LNG("too many parameters"));
+				return NULL;
+			}
+	}
+	else 
+	{	/*function with parameters*/
+		tempch = *(end - 1);
+		*(end - 1) = SG_T('\0');
+		par_buf =(SG_Char *) SG_Malloc(SG_STR_LEN(endf + 1) + 1);
+
+		if (!par_buf)
+		{    
+			_Set_Error(LNG("no memory")); 
+			i_error = NULL;  
+			return NULL;   
+		}
+		
+		SG_STR_CPY(par_buf, endf + 1);
+		*(end - 1) = tempch;
+		
+		for (i = 0; i < gSG_Functions[n_function].n_pars; i++)
+		{
+			if ((temps = my_strtok((i == 0) ? par_buf : NULL)) == NULL)
+				break; 
+			paramstr[i] = temps;
+		}
+
+		if (temps == NULL)
+		{
+			SG_Free(par_buf);
+			i_error = end - 2;
+			_Set_Error(LNG("too few parameters"));
+			return NULL;
+		}
+
+		if ((temps = my_strtok(NULL)) != NULL)
+		{
+			SG_Free(par_buf);
+			i_error =(temps - par_buf) +(endf + 1); 
+			_Set_Error(LNG("too many parameters"));
+			return NULL;
+		}
+		
+		tempu = function;
+		for (i = 0; i < gSG_Functions[n_function].n_pars; i++)
+			if( !(tempu = i_trans(tempu, paramstr[i], paramstr[i] + SG_STR_LEN(paramstr[i]))) )
+			{
+				i_error =(i_error - par_buf) +(endf + 1); 
+				SG_Free(par_buf);
+				
+				return NULL; 
+			}
+
+		/* OK */
+		SG_Free(par_buf);
+		*tempu++ = SG_T('F');
+		*tempu++ = n_function;
+		tempu = comp_time(function, tempu, gSG_Functions[n_function].n_pars);
+		if (m_bError)
+			return NULL; /* internal error in comp_time */
+		else 
+			return tempu;
+	}
+}
+
+//---------------------------------------------------------
+SG_Char *CSG_Formula::comp_time(SG_Char *function, SG_Char *fend, int npars)
+{
+	SG_Char *scan;
+	SG_Char temp;
+	double tempd;
+	int i;
+	TMAT_Formula trans;
+	
+	scan = function;
+	for (i = 0; i < npars; i++)
+	{
+		if (*scan++ != SG_T('D'))
+			return fend;
+		scan++;
+	}
+	
+	if (!((scan == fend -(sizeof((SG_Char) SG_T('F')) + sizeof(SG_Char))
+		&& *(fend - 2) == SG_T('F') && gSG_Functions[*(fend - 1)].varying == 0) ||
+		(scan == fend - sizeof(SG_Char)
+		&& _is_Operand_Code(*(fend - 1))))
+		)
+		return fend;
+	
+	temp = *fend;
+	*fend = SG_T('\0');
+	
+	trans.code = function;
+	trans.ctable = i_ctable;
+	tempd = _Get_Value(trans);
+	*fend = temp;
+	*function++ = SG_T('D');
+	i_pctable -= npars;
+	*function++ =(SG_Char) i_pctable;
+	i_ctable[i_pctable++] = tempd;
+	
+	return function;
+}
+
+//---------------------------------------------------------
+int CSG_Formula::max_size(const SG_Char *source)
+{
+	int numbers		= 0;
+	int functions	= 0;
+	int operators	= 0;
+	int variables	= 0;
+
+	const size_t var_size	= 2*sizeof(SG_Char);
+	const size_t num_size	= sizeof(SG_Char) + sizeof(double);
+	const size_t op_size	= sizeof(SG_Char);
+	const size_t end_size	= sizeof(SG_T('\0'));
+
+	const SG_Char *scan;
+
+    for(int i=0; i<SG_T('z')-SG_T('a'); i++)
+	{
+		m_Vars_Used[i]	= false;
+	}
+
+	for(scan=source; *scan; scan++)
+	{
+		if( isalpha(*scan) && (*scan != SG_T('E')) )
+		{
+			if( isalpha(*(scan + 1)) )
+			{
+				// it is a function name, it will be counted later on
+			}
+			else if( *(scan + 1) == SG_T('(') )
+			{
+				functions++;
+			}
+			else
+			{
+				variables++;
+				m_Vars_Used[(int)(*scan - SG_T('a'))] = true;
+			}
+		}
+	}
+
+	if( _is_Operand(*source) )
+	{
+		operators++;
+	}
+
+	if( *source != SG_T('\0') )
+	{
+		for(scan=source+1; *scan; scan++)
+		{
+			if( _is_Operand(*scan) && *(scan - 1) != SG_T('E') )
+			{
+				operators++;
+			}
+		}
+	}
+
+	scan	= source;
+	while( *scan )
+	{
+		if( _is_Number(*scan) || ((*scan == SG_T('+') || *scan == SG_T('-')) && scan > source && *(scan - 1) == SG_T('E')) )
+		{
+			numbers++;
+			scan++;
+
+			while( _is_Number(*scan) ||((*scan == SG_T('+') || *scan == SG_T('-')) && scan > source && *(scan - 1) == SG_T('E')) )
+				scan++;
+		}
+		else 
+		{
+			scan++;
+		}
+	}
+
+	return( numbers*num_size + operators*op_size + functions*num_size + variables*var_size + end_size );
+}
+
+//---------------------------------------------------------
+SG_Char *CSG_Formula::my_strtok(SG_Char *s)
+{
+	int pars;
+	static SG_Char *token = NULL;
+	SG_Char *next_token;
+	
+	if (s != NULL)
+		token = s;
+	else if (token != NULL)
+		s = token;
+	else 
+		return NULL;
+	
+	for (pars = 0; *s != SG_T('\0') &&(*s != SG_T(',') || pars != 0); s++)
+	{
+		if (*s == SG_T('(')) ++pars;
+		if (*s == SG_T(')'))
+			--pars;
+	}
+	if (*s == SG_T('\0'))
+	{
+		next_token = NULL;
+		s = token;
+		
+		token = next_token;
+		return s;
+	}
+	else 
+	{
+		*s = SG_T('\0');
+		next_token = s + 1;
+		s = token;
+		
+		token = next_token;
+		return s;
+	}
+} 
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_grid_radius.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_grid_radius.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_grid_radius.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,197 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  mat_grid_radius.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Grid Radius						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+#include "grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Grid_Radius::CSG_Grid_Radius(int maxRadius)
+{
+	m_maxRadius	= 0;
+	m_nPoints	= 0;
+	m_Points	= NULL;
+	m_nPoints_R	= NULL;
+	m_Points_R	= NULL;
+
+	Create(maxRadius);
+}
+
+//---------------------------------------------------------
+CSG_Grid_Radius::~CSG_Grid_Radius(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Grid_Radius::Create(int maxRadius)
+{
+	Destroy();
+
+	//-----------------------------------------------------
+	if( maxRadius > 0 && maxRadius != m_maxRadius )
+	{
+		int		x, y, i, n;
+		double	d;
+
+		m_maxRadius	= maxRadius;
+
+		m_nPoints_R	= (int *)SG_Calloc(m_maxRadius + 1, sizeof(int));
+
+		for(y=-m_maxRadius; y<=m_maxRadius; y++)
+		{
+			for(x=-m_maxRadius; x<=m_maxRadius; x++)
+			{
+				if( (d = M_GET_LENGTH(x, y)) <= m_maxRadius )
+				{
+					m_nPoints++;
+					m_nPoints_R[(int)d]++;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_nPoints > 0 )
+		{
+			m_Points	= (TSG_Grid_Radius  *)SG_Calloc(m_nPoints      , sizeof(TSG_Grid_Radius  ));
+			m_Points_R	= (TSG_Grid_Radius **)SG_Calloc(m_maxRadius + 1, sizeof(TSG_Grid_Radius *));
+
+			for(i=0, n=0; i<=m_maxRadius; i++)
+			{
+				m_Points_R [i]	 = m_Points + n;
+				n				+= m_nPoints_R[i];
+				m_nPoints_R[i]	 = 0;
+			}
+
+			//---------------------------------------------
+			for(y=-m_maxRadius; y<=m_maxRadius; y++)
+			{
+				for(x=-m_maxRadius; x<=m_maxRadius; x++)
+				{
+					if( (d = M_GET_LENGTH(x, y)) <= m_maxRadius )
+					{
+						i	= (int)d;
+						n	= m_nPoints_R[i]++;
+
+						m_Points_R[i][n].x	= x;
+						m_Points_R[i][n].y	= y;
+						m_Points_R[i][n].d	= d;
+					}
+				}
+			}
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Grid_Radius::Destroy(void)
+{
+	if( m_Points )
+	{
+		SG_Free(m_Points);
+	}
+
+	if( m_nPoints_R )
+	{
+		SG_Free(m_nPoints_R);
+	}
+
+	if( m_Points_R )
+	{
+		SG_Free(m_Points_R);
+	}
+
+	m_maxRadius	= 0;
+	m_nPoints	= 0;
+	m_Points	= NULL;
+	m_nPoints_R	= NULL;
+	m_Points_R	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_indexing.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_indexing.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_indexing.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,369 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   mat_indexing.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SG_INDEX_COMPARE_INT		0
+#define SG_INDEX_COMPARE_DOUBLE		1
+#define SG_INDEX_COMPARE_FUNCTION	2
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Index::CSG_Index(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Index::CSG_Index(int nValues, int *Values, bool bAscending)
+{
+	_On_Construction();
+
+	Create(nValues, Values, bAscending);
+}
+
+bool CSG_Index::Create(int nValues, int *Values, bool bAscending)
+{
+	m_iCompare	= SG_INDEX_COMPARE_INT;
+	m_Values	= Values;
+
+	if( _Set_Array(nValues) && _Set_Index(bAscending) )
+	{
+		return( true );
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Index::CSG_Index(int nValues, double *Values, bool bAscending)
+{
+	_On_Construction();
+
+	Create(nValues, Values, bAscending);
+}
+
+bool CSG_Index::Create(int nValues, double *Values, bool bAscending)
+{
+	m_iCompare	= SG_INDEX_COMPARE_DOUBLE;
+	m_Values	= Values;
+
+	if( _Set_Array(nValues) && _Set_Index(bAscending) )
+	{
+		return( true );
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Index::CSG_Index(int nValues, TSG_PFNC_Compare fCompare, bool bAscending)
+{
+	_On_Construction();
+
+	Create(nValues, fCompare, bAscending);
+}
+
+bool CSG_Index::Create(int nValues, TSG_PFNC_Compare fCompare, bool bAscending)
+{
+	m_iCompare	= SG_INDEX_COMPARE_FUNCTION;
+	m_fCompare	= fCompare;
+
+	if( _Set_Array(nValues) && _Set_Index(bAscending) )
+	{
+		return( true );
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Index::~CSG_Index(void)
+{
+	Destroy();
+}
+
+bool CSG_Index::Destroy(void)
+{
+	if( m_Index )
+	{
+		SG_Free(m_Index);
+	}
+
+	_On_Construction();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CSG_Index::_On_Construction(void)
+{
+	m_nValues	= 0;
+	m_Index		= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Index::_Set_Array(int nValues)
+{
+	if( nValues > 0 )
+	{
+		if( nValues != m_nValues )
+		{
+			m_nValues	= nValues;
+			m_Index		= (int *)SG_Realloc(m_Index, m_nValues * sizeof(int));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline int CSG_Index::_Compare(const int iElement_1, const int iElement_2)
+{
+	double	d;
+
+	switch( m_iCompare )
+	{
+	case SG_INDEX_COMPARE_INT:
+		return(  ((int *)m_Values)[iElement_1] - ((int    *)m_Values)[iElement_2] );
+
+	case SG_INDEX_COMPARE_DOUBLE:
+		d	= ((double *)m_Values)[iElement_1] - ((double *)m_Values)[iElement_2];
+
+		return( d < 0.0 ? -1 : (d > 0.0 ? 1 : 0) );
+
+	case SG_INDEX_COMPARE_FUNCTION:
+		return( m_fCompare(iElement_1, iElement_2) );
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SG_INDEX_SWAP(a, b)	{itemp=(a);(a)=(b);(b)=itemp;}
+
+//---------------------------------------------------------
+bool CSG_Index::_Set_Index(bool bAscending)
+{
+	const int	M	= 7;
+
+	int		indxt, itemp, *istack,
+			i, j, k, a,
+			l		= 0,
+			ir		= m_nValues - 1,
+			nstack	= 64,
+			jstack	= 0;
+
+	//-----------------------------------------------------
+	for(j=0; j<m_nValues; j++)
+	{
+		m_Index[j]	= j;
+	}
+
+	istack	= (int *)SG_Malloc(nstack * sizeof(int));
+
+	//-----------------------------------------------------
+	for(;;)
+	{
+		if( ir - l < M )
+		{
+			for(j=l+1; j<=ir; j++)
+			{
+				a		= indxt	= m_Index[j];
+
+				for(i=j-1; i>=0; i--)
+				{
+					if( _Compare(m_Index[i], a) <= 0 )
+					{
+						break;
+					}
+
+					m_Index[i + 1]	= m_Index[i];
+				}
+
+				m_Index[i + 1]	= indxt;
+			}
+
+			if( jstack == 0 )
+			{
+				break;
+			}
+
+			ir		= istack[jstack--];
+			l		= istack[jstack--];
+		}
+		else
+		{
+			k		= (l + ir) >> 1;
+			SG_INDEX_SWAP(m_Index[k], m_Index[l + 1]);
+
+			if( _Compare     (m_Index[l + 1], m_Index[ir]) > 0 )
+				SG_INDEX_SWAP(m_Index[l + 1], m_Index[ir]);
+
+			if( _Compare     (m_Index[l    ], m_Index[ir]) > 0 )
+				SG_INDEX_SWAP(m_Index[l    ], m_Index[ir]);
+
+			if( _Compare     (m_Index[l + 1], m_Index[l ]) > 0 )
+				SG_INDEX_SWAP(m_Index[l + 1], m_Index[l ]);
+
+			i		= l + 1;
+			j		= ir;
+			a		= indxt	= m_Index[l];
+
+			for(;;)
+			{
+				do	i++;	while( _Compare(m_Index[i], a) < 0 );
+				do	j--;	while( _Compare(m_Index[j], a) > 0 );
+
+				if( j < i )
+				{
+					break;
+				}
+
+				SG_INDEX_SWAP(m_Index[i], m_Index[j]);
+			}
+
+			m_Index[l]	= m_Index[j];
+			m_Index[j]	= indxt;
+			jstack		+= 2;
+
+			if( jstack >= nstack )
+			{
+				nstack	+= 64;
+				istack	= (int *)SG_Realloc(istack, nstack * sizeof(int));
+			}
+
+			if( ir - i + 1 >= j - l )
+			{
+				istack[jstack]		= ir;
+				istack[jstack - 1]	= i;
+				ir					= j - 1;
+			}
+			else
+			{
+				istack[jstack]		= j - 1;
+				istack[jstack - 1]	= l;
+				l					= i;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( !bAscending )
+	{
+		for(i=0, j=m_nValues-1; i<j; i++, j--)
+		{
+			k			= m_Index[i];
+			m_Index[i]	= m_Index[j];
+			m_Index[j]	= k;
+		}
+	}
+
+	SG_Free(istack);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_matrix.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_matrix.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_matrix.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1394 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    mat_matrix.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		SG_Matrix_LU_Decomposition	(int n, int *Permutation, double **Matrix, bool bSilent);
+bool		SG_Matrix_LU_Solve			(int n, int *Permutation, double **Matrix, double *Vector, bool bSilent);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Vector::CSG_Vector(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Vector::CSG_Vector(const CSG_Vector &Vector)
+{
+	_On_Construction();
+
+	Create(Vector);
+}
+
+bool CSG_Vector::Create(const CSG_Vector &Vector)
+{
+	return( Assign(Vector) );
+}
+
+//---------------------------------------------------------
+CSG_Vector::CSG_Vector(int n, double *Data)
+{
+	_On_Construction();
+
+	Create(n, Data);
+}
+
+bool CSG_Vector::Create(int n, double *Data)
+{
+	if( n > 0 )
+	{
+		if( n != m_n )
+		{
+			Destroy();
+
+			m_n	= n;
+			m_z	= (double *)SG_Malloc(m_n * sizeof(double));
+		}
+
+		if( Data )
+		{
+			memcpy(m_z, Data, m_n * sizeof(double));
+		}
+		else
+		{
+			memset(m_z,    0, m_n * sizeof(double));
+		}
+
+		return( true );
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Vector::~CSG_Vector(void)
+{
+	Destroy();
+}
+
+bool CSG_Vector::Destroy(void)
+{
+	if( m_z )
+	{
+		SG_Free(m_z);
+		m_z	= NULL;
+		m_n	= 0;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CSG_Vector::_On_Construction(void)
+{
+	m_z	= NULL;
+	m_n	= 0;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_Vector::asString(void)
+{
+	CSG_String	s;
+
+	for(int i=0; i<m_n; i++)
+	{
+		s.Append(CSG_String::Format(SG_T("%f\n"), m_z[i]));
+	}
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Vector::is_Equal(const CSG_Vector &Vector) const
+{
+	if( m_n == Vector.m_n )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			if( m_z[i] != Vector.m_z[i] )
+			{
+				return( false );
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Assign(double Scalar)
+{
+	if( m_n > 0 )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			m_z[i]	= Scalar;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Assign(const CSG_Vector &Vector)
+{
+	if( Create(Vector.m_n) )
+	{
+		memcpy(m_z, Vector.m_z, m_n * sizeof(double));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Add(double Scalar)
+{
+	if( m_n > 0 )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			m_z[i]	+= Scalar;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Add(const class CSG_Vector &Vector)
+{
+	if( m_n == Vector.m_n && m_n > 0 )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			m_z[i]	+= Vector.m_z[i];
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Subtract(const class CSG_Vector &Vector)
+{
+	if( m_n == Vector.m_n && m_n > 0 )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			m_z[i]	-= Vector.m_z[i];
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Multiply(double Scalar)
+{
+	if( m_n > 0 )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			m_z[i]	*= Scalar;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Multiply(const class CSG_Vector &Vector)
+{
+	if( m_n == Vector.m_n && m_n == 3 )
+	{
+		CSG_Vector	v(*this);
+
+		m_z[0]	= v[1] * Vector.m_z[2] - v[2] * Vector.m_z[1];
+		m_z[1]	= v[2] * Vector.m_z[0] - v[0] * Vector.m_z[2];
+		m_z[2]	= v[0] * Vector.m_z[1] - v[1] * Vector.m_z[0];
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CSG_Vector::Multiply_Scalar(const class CSG_Vector &Vector) const
+{
+	double	z	= 0.0;
+
+	if( m_n == Vector.m_n )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			z	+= m_z[i] * Vector.m_z[i];
+		}
+	}
+
+	return( z );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Multiply(const CSG_Matrix &Matrix)
+{
+	return( Assign(Matrix.Multiply(*this)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Vector::operator == (const CSG_Vector &Vector) const
+{
+	return( is_Equal(Vector) );
+}
+
+//---------------------------------------------------------
+CSG_Vector & CSG_Vector::operator = (double Scalar)
+{
+	Assign(Scalar);
+
+	return( *this );
+}
+
+CSG_Vector & CSG_Vector::operator = (const CSG_Vector &Vector)
+{
+	Assign(Vector);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Vector & CSG_Vector::operator += (double Scalar)
+{
+	Add(Scalar);
+
+	return( *this );
+}
+
+CSG_Vector & CSG_Vector::operator += (const class CSG_Vector &Vector)
+{
+	Add(Vector);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Vector & CSG_Vector::operator -= (double Scalar)
+{
+	Add(-Scalar);
+
+	return( *this );
+}
+
+CSG_Vector & CSG_Vector::operator -= (const class CSG_Vector &Vector)
+{
+	Subtract(Vector);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Vector & CSG_Vector::operator *= (double Scalar)
+{
+	Multiply(Scalar);
+
+	return( *this );
+}
+
+CSG_Vector & CSG_Vector::operator *= (const class CSG_Vector &Vector)
+{
+	Multiply(Vector);
+
+	return( *this );
+}
+
+CSG_Vector & CSG_Vector::operator *= (const CSG_Matrix &Matrix)
+{
+	Multiply(Matrix);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Vector CSG_Vector::operator + (double Scalar) const
+{
+	CSG_Vector	v(*this);
+
+	v.Add(Scalar);
+
+	return( v );
+}
+
+CSG_Vector CSG_Vector::operator + (const class CSG_Vector &Vector) const
+{
+	CSG_Vector	v(*this);
+
+	v.Add(Vector);
+
+	return( v );
+}
+
+//---------------------------------------------------------
+CSG_Vector CSG_Vector::operator - (double Scalar) const
+{
+	CSG_Vector	v(*this);
+
+	v.Add(-Scalar);
+
+	return( v );
+}
+
+CSG_Vector CSG_Vector::operator - (const class CSG_Vector &Vector) const
+{
+	CSG_Vector	v(*this);
+
+	v.Subtract(Vector);
+
+	return( v );
+}
+
+//---------------------------------------------------------
+CSG_Vector CSG_Vector::operator * (double Scalar) const
+{
+	CSG_Vector	v(*this);
+
+	v.Multiply(Scalar);
+
+	return( v );
+}
+
+double CSG_Vector::operator * (const class CSG_Vector &Vector) const
+{
+	return( Multiply_Scalar(Vector) );
+}
+
+CSG_Vector operator * (double Scalar, const CSG_Vector &Vector)
+{
+	return( Vector * Scalar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Vector::Set_Zero(void)
+{
+	return( Create(m_n) );
+}
+
+//---------------------------------------------------------
+bool CSG_Vector::Set_Unity(void)
+{
+	double	Length;
+
+	if( (Length = Get_Length()) > 0.0 )
+	{
+		for(int i=0; i<m_n; i++)
+		{
+			m_z[i]	/= Length;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Vector::Get_Length(void) const
+{
+	if( m_n > 0 )
+	{
+		double	z	= 0.0;
+
+		for(int i=0; i<m_n; i++)
+		{
+			z	+= m_z[i] * m_z[i];
+		}
+
+		return( sqrt(z) );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Vector::Get_Angle(const CSG_Vector &Vector) const
+{
+	if( m_n > Vector.m_n )
+	{
+		return( Vector.Get_Angle(*this) );
+	}
+
+	int		i;
+	double	A, B, z;
+
+	if( (A = Get_Length()) > 0.0 && (B = Vector.Get_Length()) > 0.0 )
+	{
+		for(i=0, z=0.0; i<m_n; i++)
+		{
+			z	+= Vector.m_z[i] * m_z[i];
+		}
+
+		for(i=m_n; i<Vector.m_n; i++)
+		{
+			z	+= Vector.m_z[i];
+		}
+
+		return( acos(z / (A * B)) );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+CSG_Vector CSG_Vector::Get_Unity(void) const
+{
+	CSG_Vector	v(*this);
+
+	v.Set_Unity();
+
+	return( v );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Matrix::CSG_Matrix(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Matrix::CSG_Matrix(const CSG_Matrix &Matrix)
+{
+	_On_Construction();
+
+	Create(Matrix);
+}
+
+bool CSG_Matrix::Create(const CSG_Matrix &Matrix)
+{
+	return( Assign(Matrix) );
+}
+
+//---------------------------------------------------------
+CSG_Matrix::CSG_Matrix(int nx, int ny, double *Data)
+{
+	_On_Construction();
+
+	Create(nx, ny, Data);
+}
+
+bool CSG_Matrix::Create(int nx, int ny, double *Data)
+{
+	if( nx > 0 && ny > 0 )
+	{
+		if( nx != m_nx || ny != m_ny )
+		{
+			Destroy();
+
+			m_nx	= nx;
+			m_ny	= ny;
+			m_z		= (double **)SG_Malloc(m_ny        * sizeof(double *));
+			m_z[0]	= (double  *)SG_Malloc(m_ny * m_nx * sizeof(double  ));
+
+			for(ny=1; ny<m_ny; ny++)
+			{
+				m_z[ny]	= m_z[ny - 1] + nx;
+			}
+		}
+
+		if( Data )
+		{
+			memcpy(m_z[0], Data, m_ny * m_nx * sizeof(double));
+		}
+		else
+		{
+			memset(m_z[0],    0, m_ny * m_nx * sizeof(double));
+		}
+
+		return( true );
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Matrix::~CSG_Matrix(void)
+{
+	Destroy();
+}
+
+bool CSG_Matrix::Destroy(void)
+{
+	if( m_z )
+	{
+		SG_Free(m_z[0]);
+		SG_Free(m_z);
+
+		m_z		= NULL;
+		m_nx	= 0;
+		m_ny	= 0;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CSG_Matrix::_On_Construction(void)
+{
+	m_z		= NULL;
+	m_nx	= 0;
+	m_ny	= 0;
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Add_Cols(int nCols)
+{
+	if( nCols > 0 && m_ny > 0 )
+	{
+		CSG_Matrix	Tmp(*this);
+
+		if( Create(Tmp.m_nx + nCols, Tmp.m_ny) )
+		{
+			for(int y=0; y<Tmp.m_ny; y++)
+			{
+				memcpy(m_z[y], Tmp.m_z[y], Tmp.m_nx * sizeof(double));
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Add_Rows(int nRows)
+{
+	if( nRows > 0 && m_nx > 0 )
+	{
+		CSG_Matrix	Tmp(*this);
+
+		if( Create(Tmp.m_nx, Tmp.m_ny + nRows) )
+		{
+			for(int y=0; y<Tmp.m_ny; y++)
+			{
+				memcpy(m_z[y], Tmp.m_z[y], Tmp.m_nx * sizeof(double));
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_Matrix::asString(void)
+{
+	CSG_String	s;
+
+	for(int y=0; y<m_ny; y++)
+	{
+		for(int x=0; x<m_nx; x++)
+		{
+			s.Append(CSG_String::Format(SG_T("%f\t"), m_z[y][x]));
+		}
+
+		s.Append(SG_T("\n"));
+	}
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Matrix::is_Equal(const CSG_Matrix &Matrix) const
+{
+	if( m_nx == Matrix.m_nx && m_ny == Matrix.m_ny )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				if( m_z[y][x] != Matrix.m_z[y][x] )
+				{
+					return( false );
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Assign(double Scalar)
+{
+	if( m_nx > 0 && m_ny > 0 )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	= Scalar;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Assign(const CSG_Matrix &Matrix)
+{
+	if( Create(Matrix.m_nx, Matrix.m_ny) )
+	{
+		memcpy(m_z[0], Matrix.m_z[0], m_nx * m_ny * sizeof(double));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Add(double Scalar)
+{
+	if( m_nx > 0 && m_ny > 0 )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	+= Scalar;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Add(const CSG_Matrix &Matrix)
+{
+	if( m_nx == Matrix.m_nx && m_ny == Matrix.m_ny )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	+= Matrix.m_z[y][x];
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Subtract(const CSG_Matrix &Matrix)
+{
+	if( m_nx == Matrix.m_nx && m_ny == Matrix.m_ny )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	-= Matrix.m_z[y][x];
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Multiply(double Scalar)
+{
+	if( m_nx > 0 && m_ny > 0 )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	*= Scalar;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+CSG_Vector CSG_Matrix::Multiply(const CSG_Vector &Vector) const
+{
+	CSG_Vector	v;
+
+	if( m_nx == Vector.Get_N() && v.Create(m_ny) )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			double	z	= 0.0;
+
+			for(int x=0; x<m_nx; x++)
+			{
+				z	+= m_z[y][x] * Vector(x);
+			}
+
+			v[y]	= z;
+		}
+	}
+
+	return( v );
+}
+
+CSG_Matrix CSG_Matrix::Multiply(const CSG_Matrix &Matrix) const
+{
+	CSG_Matrix	m;
+
+	if( m_nx == Matrix.m_ny && m.Create(Matrix.m_nx, m_ny) )
+	{
+		for(int y=0; y<m.m_ny; y++)
+		{
+			for(int x=0; x<m.m_nx; x++)
+			{
+				double	z	= 0.0;
+
+				for(int n=0; n<m_nx; n++)
+				{
+					z	+= m_z[y][n] * Matrix.m_z[n][x];
+				}
+
+				m.m_z[y][x]	= z;
+			}
+		}
+	}
+
+	return( m );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Matrix::operator == (const CSG_Matrix &Matrix) const
+{
+	return( is_Equal(Matrix) );
+}
+
+//---------------------------------------------------------
+CSG_Matrix & CSG_Matrix::operator = (double Scalar)
+{
+	Assign(Scalar);
+
+	return( *this );
+}
+
+CSG_Matrix & CSG_Matrix::operator = (const CSG_Matrix &Matrix)
+{
+	Assign(Matrix);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Matrix & CSG_Matrix::operator += (double Scalar)
+{
+	Add(Scalar);
+
+	return( *this );
+}
+
+CSG_Matrix & CSG_Matrix::operator += (const CSG_Matrix &Matrix)
+{
+	Add(Matrix);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Matrix & CSG_Matrix::operator -= (double Scalar)
+{
+	Add(-Scalar);
+
+	return( *this );
+}
+
+CSG_Matrix & CSG_Matrix::operator -= (const CSG_Matrix &Matrix)
+{
+	Subtract(Matrix);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Matrix & CSG_Matrix::operator *= (double Scalar)
+{
+	Multiply(Scalar);
+
+	return( *this );
+}
+
+CSG_Matrix & CSG_Matrix::operator *= (const CSG_Matrix &Matrix)
+{
+	Multiply(Matrix);
+
+	return( *this );
+}
+
+//---------------------------------------------------------
+CSG_Matrix CSG_Matrix::operator + (double Scalar) const
+{
+	CSG_Matrix	m(*this);
+
+	m.Add(Scalar);
+
+	return( m );
+}
+
+CSG_Matrix CSG_Matrix::operator + (const CSG_Matrix &Matrix) const
+{
+	CSG_Matrix	m(*this);
+
+	m.Add(Matrix);
+
+	return( m );
+}
+
+//---------------------------------------------------------
+CSG_Matrix CSG_Matrix::operator - (double Scalar) const
+{
+	CSG_Matrix	m(*this);
+
+	m.Add(-Scalar);
+
+	return( m );
+}
+
+CSG_Matrix CSG_Matrix::operator - (const CSG_Matrix &Matrix) const
+{
+	CSG_Matrix	m(*this);
+
+	m.Subtract(Matrix);
+
+	return( m );
+}
+
+//---------------------------------------------------------
+CSG_Matrix CSG_Matrix::operator * (double Scalar) const
+{
+	CSG_Matrix	m(*this);
+
+	m.Multiply(Scalar);
+
+	return( m );
+}
+
+CSG_Vector CSG_Matrix::operator * (const CSG_Vector &Vector) const
+{
+	return( Multiply(Vector) );
+}
+
+CSG_Matrix CSG_Matrix::operator * (const CSG_Matrix &Matrix) const
+{
+	return( Multiply(Matrix) );
+}
+
+CSG_Matrix	operator * (double Scalar, const CSG_Matrix &Matrix)
+{
+	return( Matrix * Scalar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Matrix::Set_Zero(void)
+{
+	return( Create(m_nx, m_ny) );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Set_Identity(void)
+{
+	if( m_nx > 0 && m_ny > 0 )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	= x == y ? 1.0 : 0.0;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Set_Transpose(void)
+{
+	CSG_Matrix	m;
+	
+	if( m.Create(*this) && Create(m_ny, m_nx) )
+	{
+		for(int y=0; y<m_ny; y++)
+		{
+			for(int x=0; x<m_nx; x++)
+			{
+				m_z[y][x]	= m.m_z[y][x];
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Matrix::Set_Inverse(bool bSilent, int nSubSquare)
+{
+	bool	bResult	= false;
+	int		n		= 0;
+
+	//-----------------------------------------------------
+	if( nSubSquare > 0 )
+	{
+		if( nSubSquare <= m_nx && nSubSquare <= m_ny )
+		{
+			n	= nSubSquare;
+		}
+	}
+	else if( is_Square() )
+	{
+		n	= m_nx;
+	}
+
+	//-----------------------------------------------------
+	if( n > 0 )
+	{
+		CSG_Matrix	m(*this);
+		int		*Permutation	= (int *)SG_Malloc(n * sizeof(int));
+
+		if( SG_Matrix_LU_Decomposition(n, Permutation, m.Get_Data(), bSilent) )
+		{
+			CSG_Vector	v(n);
+
+			for(int j=0; j<n && (bSilent || SG_UI_Process_Set_Progress(j, n)); j++)
+			{
+				v.Set_Zero();
+				v[j]	= 1.0;
+
+				SG_Matrix_LU_Solve(n, Permutation, m.Get_Data(), v.Get_Data(), true);
+
+				for(int i=0; i<n; i++)
+				{
+					m_z[i][j]	= v[i];
+				}
+			}
+
+			bResult	= true;
+		}
+
+		SG_Free(Permutation);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Matrix::Get_Determinant(void) const
+{
+	double	d	= 0.0;
+
+	for(int y=0; y<m_ny; y++)
+	{
+		for(int x=0; x<m_nx; x++)
+		{
+		}
+	}
+
+	return( d );
+}
+
+//---------------------------------------------------------
+CSG_Matrix CSG_Matrix::Get_Transpose(void) const
+{
+	CSG_Matrix	m(m_ny, m_nx);
+
+	for(int y=0; y<m_ny; y++)
+	{
+		for(int x=0; x<m_nx; x++)
+		{
+			m.m_z[x][y]	= m_z[y][x];
+		}
+	}
+
+	return( m );
+}
+
+//---------------------------------------------------------
+CSG_Matrix CSG_Matrix::Get_Inverse(bool bSilent, int nSubSquare) const
+{
+	CSG_Matrix	m(*this);
+
+	m.Set_Inverse(bSilent, nSubSquare);
+
+	return( m );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		SG_Matrix_Solve(CSG_Matrix &Matrix, CSG_Vector &Vector, bool bSilent)
+{
+	bool	bResult	= false;
+	int		n		= Vector.Get_N();
+
+	if( n > 0 && n == Matrix.Get_NX() && n == Matrix.Get_NY() )
+	{
+		int	*Permutation	= (int *)SG_Malloc(n * sizeof(int));
+
+		if( SG_Matrix_LU_Decomposition(n, Permutation, Matrix.Get_Data(), bSilent) )
+		{
+			SG_Matrix_LU_Solve(n, Permutation, Matrix.Get_Data(), Vector.Get_Data(), bSilent);
+
+			bResult	= true;
+		}
+
+		SG_Free(Permutation);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		SG_Matrix_LU_Decomposition(int n, int *Permutation, double **Matrix, bool bSilent)
+{
+	int			i, j, k, iMax;
+	double		dMax, d, Sum;
+	CSG_Vector	Vector;
+	
+	Vector.Create(n);
+
+	for(i=0, iMax=0; i<n && (bSilent || SG_UI_Process_Set_Progress(i, n)); i++)
+	{
+		dMax	= 0.0;
+
+		for(j=0; j<n; j++)
+		{
+			if( (d = fabs(Matrix[i][j])) > dMax )
+			{
+				dMax	= d;
+			}
+		}
+
+		if( dMax <= 0.0 )	// singular matrix !!!...
+		{
+			return( false );
+		}
+
+		Vector[i]	= 1.0 / dMax;
+	}
+
+	for(j=0; j<n && (bSilent || SG_UI_Process_Set_Progress(j, n)); j++)
+	{
+		for(i=0; i<j; i++)
+		{
+			Sum		= Matrix[i][j];
+
+			for(k=0; k<i; k++)
+			{
+				Sum		-= Matrix[i][k] * Matrix[k][j];
+			}
+
+			Matrix[i][j]	= Sum;
+		}
+
+		for(i=j, dMax=0.0; i<n; i++)
+		{
+			Sum		= Matrix[i][j];
+
+			for(k=0; k<j; k++)
+			{
+				Sum		-= Matrix[i][k] * Matrix[k][j];
+			}
+
+			Matrix[i][j]	= Sum;
+
+			if( (d = Vector[i] * fabs(Sum)) >= dMax )
+			{
+				dMax	= d;
+				iMax	= i;
+			}
+		}
+
+		if( j != iMax )
+		{
+			for(k=0; k<n; k++)
+			{
+				d				= Matrix[iMax][k];
+				Matrix[iMax][k]	= Matrix[j   ][k];
+				Matrix[j   ][k]	= d;
+			}
+
+			Vector[iMax]	= Vector[j];
+		}
+
+		Permutation[j]	= iMax;
+
+		if( Matrix[j][j] == 0.0 )
+		{
+			Matrix[j][j]	= M_TINY;
+		}
+
+		if( j != n )
+		{
+			d	= 1.0 / (Matrix[j][j]);
+
+			for(i=j+1; i<n; i++)
+			{
+				Matrix[i][j]	*= d;
+			}
+		}
+	}
+
+	return( bSilent || SG_UI_Process_Get_Okay(false) );
+}
+
+//---------------------------------------------------------
+bool		SG_Matrix_LU_Solve(int n, int *Permutation, double **Matrix, double *Vector, bool bSilent)
+{
+	int		i, j, k;
+	double	Sum;
+
+	for(i=0, k=-1; i<n && (bSilent || SG_UI_Process_Set_Progress(i, n)); i++)
+	{
+		Sum						= Vector[Permutation[i]];
+		Vector[Permutation[i]]	= Vector[i];
+
+		if( k >= 0 )
+		{
+			for(j=k; j<=i-1; j++)
+			{
+				Sum	-= Matrix[i][j] * Vector[j];
+			}
+		}
+		else if( Sum )
+		{
+			k		= i;
+		}
+
+		Vector[i]	= Sum;
+	}
+
+	for(i=n-1; i>=0 && (bSilent || SG_UI_Process_Set_Progress(n-i, n)); i--)
+	{
+		Sum			= Vector[i];
+
+		for(j=i+1; j<n; j++)
+		{
+			Sum		-= Matrix[i][j] * Vector[j];
+		}
+
+		Vector[i]	= Sum / Matrix[i][i];
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,483 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  mat_regression.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Regression::CSG_Regression(void)
+{
+	m_nBuffer	= 0;
+	m_nValues	= 0;
+	m_x			= NULL;
+	m_y			= NULL;
+
+	m_Type		= REGRESSION_Linear;
+}
+
+//---------------------------------------------------------
+CSG_Regression::~CSG_Regression(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Regression::Destroy(void)
+{
+	if( m_nBuffer > 0 )
+	{
+		SG_Free(m_x);
+		SG_Free(m_y);
+
+		m_nBuffer	= 0;
+	}
+
+	m_nValues	= 0;
+	m_x			= NULL;
+	m_y			= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Regression::Add_Values(double x, double y)
+{
+	if( m_nValues >= m_nBuffer )
+	{
+		m_nBuffer	+= 64;
+		m_x	= (double *)SG_Realloc(m_x, m_nBuffer * sizeof(double));
+		m_y	= (double *)SG_Realloc(m_y, m_nBuffer * sizeof(double));
+	}
+
+	m_x[m_nValues]	= x;
+	m_y[m_nValues]	= y;
+
+	m_nValues++;
+}
+
+//---------------------------------------------------------
+void CSG_Regression::Set_Values(int nValues, double *x, double *y)
+{
+	Destroy();
+
+	for(int i=0; i<nValues; i++)
+	{
+		Add_Values(x[i], y[i]);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Regression::asString(void)
+{
+	static CSG_String	s;
+
+	s.Printf(
+		SG_T("N = %d\n")
+		SG_T("  Min. = %.6f  Max. = %.6f\n  Arithmetic Mean = %.6f\n  Variance = %.6f\n  Standard Deviation = %.6f\n")
+		SG_T("  Min. = %.6f  Max. = %.6f\n  Arithmetic Mean = %.6f\n  Variance = %.6f\n  Standard Deviation = %.6f\n")
+		SG_T("Linear Regression:\n  Y = %.6f * X %+.6f\n  (r=%.4f, r\xc2\xb2=%.4f)"),
+		m_nValues,
+		m_xMin, m_xMax, m_xMean, m_xVar, sqrt(m_xVar),
+		m_yMin, m_yMax, m_yMean, m_yVar, sqrt(m_yVar),
+		m_RCoeff, m_RConst, m_R, m_R*m_R
+	);
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Regression::Get_x(double y)
+{
+	if( m_nValues > 0.0 )
+	{
+		switch( m_Type )
+		{
+		case REGRESSION_Linear:	// Y = a + b * X		-> X = (Y - a) / b
+			if( m_RCoeff != 0.0 )
+				return( (m_RConst * y) / m_RCoeff );
+
+		case REGRESSION_Rez_X:	// Y = a + b / X		-> X = b / (Y - a)
+			if( (y = y - m_RConst) != 0.0 )
+				return( m_RCoeff / y );
+
+		case REGRESSION_Rez_Y:	// Y = a / (b - X)		-> X = b - a / Y
+			if( y != 0.0 )
+				return( m_RCoeff - m_RConst / y );
+
+		case REGRESSION_Pow:	// Y = a * X^b			-> X = (Y / a)^(1 / b)
+			if( m_RConst != 0.0 && m_RCoeff != 0.0 )
+				return( pow(y / m_RConst, 1.0 / m_RCoeff) );
+
+		case REGRESSION_Exp:	// Y = a * e^(b * X)	-> X = ln(Y / a) / b
+			if( m_RConst != 0.0 && (y = y / m_RConst) > 0.0 && m_RCoeff != 0.0 )
+			return( log(y) / m_RCoeff );
+
+		case REGRESSION_Log:	// Y = a + b * ln(X)	-> X = e^((Y - a) / b)
+			if( m_RCoeff != 0.0 )
+				return( exp((y - m_RConst) / m_RCoeff) );
+		}
+	}
+
+	return( sqrt(-1.0) );
+}
+
+//---------------------------------------------------------
+double CSG_Regression::Get_y(double x)
+{
+	if( m_nValues > 0.0 )
+	{
+		switch( m_Type )
+		{
+		case REGRESSION_Linear:	// Y = a + b * X
+			return( m_RConst + m_RCoeff * x );
+
+		case REGRESSION_Rez_X:	// Y = a + b / X
+			if( x != 0.0 )
+				return( m_RConst + m_RCoeff / x );
+
+		case REGRESSION_Rez_Y:	// Y = a / (b - X)
+			if( (x = m_RCoeff - x) != 0.0 )
+				return( m_RConst / x );
+
+		case REGRESSION_Pow:	// Y = a * X^b
+			return( m_RConst * pow(x, m_RCoeff) );
+
+		case REGRESSION_Exp:	// Y = a e^(b * X)
+			return( m_RConst * exp(m_RCoeff * x) );
+
+		case REGRESSION_Log:	// Y = a + b * ln(X)
+			if( x > 0.0 )
+				return( m_RConst + m_RCoeff * log(x) );
+		}
+	}
+
+	return( sqrt(-1.0) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Regression::_Get_MinMeanMax(double &xMin, double &xMean, double &xMax, double &yMin, double &yMean, double &yMax)
+{
+	int		i;
+	double	x, y;
+
+	if( m_nValues > 0 )
+	{
+		xMin = xMean = xMax = m_x[0];
+		yMin = yMean = yMax = m_y[0];
+
+		for(i=1; i<m_nValues; i++)
+		{
+			xMean	+= (x = m_x[i]);
+			yMean	+= (y = m_y[i]);
+
+			M_SET_MINMAX(xMin, xMax, x);
+			M_SET_MINMAX(yMin, yMax, y);
+		}
+
+		xMean	/= m_nValues;
+		yMean	/= m_nValues;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline double CSG_Regression::_Y_Transform(double y)
+{
+	switch( m_Type )
+	{
+	default:
+		return( y );
+
+	case REGRESSION_Rez_Y:
+		if( y == 0.0 )	y	= M_ALMOST_ZERO;
+		return( 1.0 / y );
+
+	case REGRESSION_Pow:
+	case REGRESSION_Exp:
+		if( y <= 0.0 )	y	= M_ALMOST_ZERO;
+		return( log(y) );
+	}
+}
+
+//---------------------------------------------------------
+inline double CSG_Regression::_X_Transform(double x)
+{
+	switch( m_Type )
+	{
+	default:
+		return( x );
+
+	case REGRESSION_Rez_X:
+		if( x == 0.0 )	x	= M_ALMOST_ZERO;
+		return( 1.0 / x );
+
+	case REGRESSION_Pow:
+	case REGRESSION_Log:
+		if( x <= 0.0 )	x	= M_ALMOST_ZERO;
+		return( log(x) );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Regression::_Linear(void)
+{
+	int		i;
+	double	x, y, s_xx, s_xy, s_x, s_y, s_dx2, s_dy2, s_dxdy;
+
+	//-----------------------------------------------------
+	if( m_nValues > 1 )
+	{
+		m_xMean	= m_xMin = m_xMax = _X_Transform(m_x[0]);
+		m_yMean	= m_yMin = m_yMax = _Y_Transform(m_y[0]);
+
+		for(i=1; i<m_nValues; i++)
+		{
+			m_xMean	+= (x = _X_Transform(m_x[i]));
+			m_yMean	+= (y = _Y_Transform(m_y[i]));
+
+			M_SET_MINMAX(m_xMin, m_xMax, x);
+			M_SET_MINMAX(m_yMin, m_yMax, y);
+		}
+
+		m_xMean	/= m_nValues;
+		m_yMean	/= m_nValues;
+
+		//-------------------------------------------------
+		if( m_xMin < m_xMax && m_yMin < m_yMax )
+		{
+			s_x = s_y = s_xx = s_xy = s_dx2 = s_dy2 = s_dxdy = 0.0;
+
+			for(i=0; i<m_nValues; i++)
+			{
+				x		 = _X_Transform(m_x[i]);
+				y		 = _Y_Transform(m_y[i]);
+
+				s_x		+= x;
+				s_y		+= y;
+				s_xx	+= x * x;
+				s_xy	+= x * y;
+
+				x		-= m_xMean;
+				y		-= m_yMean;
+
+				s_dx2	+= x * x;
+				s_dy2	+= y * y;
+				s_dxdy	+= x * y;
+			}
+
+			//---------------------------------------------
+			m_xVar		= s_dx2 / m_nValues;
+			m_yVar		= s_dy2 / m_nValues;
+
+			m_RCoeff	= s_dxdy / s_dx2;
+			m_RConst	= (s_xx * s_y - s_x * s_xy) / (m_nValues * s_xx - s_x * s_x);
+			m_R			= s_dxdy / sqrt(s_dx2 * s_dy2);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Regression::Calculate(TSG_Regression_Type Type)
+{
+	double	d;
+
+	m_Type	= Type;
+
+	if( _Linear() )
+	{
+		switch( m_Type )
+		{
+		case REGRESSION_Linear:	default:
+			break;
+
+		case REGRESSION_Rez_X:
+			m_xVar		= 1.0 / m_xVar;
+			break;
+
+		case REGRESSION_Rez_Y:
+			d			= m_RConst;
+			m_RConst	= 1.0 / m_RCoeff;
+			m_RCoeff	= d   * m_RCoeff;
+			m_yVar		= 1.0 / m_yVar;
+			break;
+
+		case REGRESSION_Pow:
+			m_RConst	= exp(m_RConst);
+			m_xVar		= exp(m_xVar);
+			m_yVar		= exp(m_yVar);
+			break;
+
+		case REGRESSION_Exp:
+			m_RConst	= exp(m_RConst);
+			m_yVar		= exp(m_yVar);
+			break;
+
+		case REGRESSION_Log:
+			m_xVar		= exp(m_xVar);
+			break;
+		}
+
+		if( m_Type != REGRESSION_Linear )
+		{
+			_Get_MinMeanMax(
+				m_xMin, m_xMean, m_xMax,
+				m_yMin, m_yMean, m_yMax
+			);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Regression::Calculate(int nValues, double *x, double *y, TSG_Regression_Type Type)
+{
+	bool	bResult;
+
+	Destroy();
+
+	m_nValues	= nValues;
+	m_x			= x;
+	m_y			= y;
+
+	bResult		= Calculate(Type);
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression_multiple.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression_multiple.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_regression_multiple.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,438 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              mat_regression_multiple.cpp              //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "mat_tools.h"
+#include "table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum ESG_Regression_Fields
+{
+	MRFIELD_NR	= 0,
+	MRFIELD_NAME,
+	MRFIELD_RCOEFF,
+	MRFIELD_DCOEFF,
+	MRFIELD_ORDER
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Regression_Multiple::CSG_Regression_Multiple(void)
+{
+	m_pResult	= new CSG_Table;
+
+	m_pResult->Add_Field("Field"				, SG_DATATYPE_Int);
+	m_pResult->Add_Field("Variable"				, SG_DATATYPE_String);
+	m_pResult->Add_Field("Regression Coeff."	, SG_DATATYPE_Double);
+	m_pResult->Add_Field("Determination Coeff."	, SG_DATATYPE_Double);
+	m_pResult->Add_Field("Order"				, SG_DATATYPE_Int);
+}
+
+//---------------------------------------------------------
+CSG_Regression_Multiple::~CSG_Regression_Multiple(void)
+{
+	delete(m_pResult);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Regression_Multiple::Destroy(void)
+{
+	m_pResult->Del_Records();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Regression_Multiple::Calculate(const CSG_Table &Values)
+{
+	int				i, nVariables, nValues;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	Destroy();
+
+	if(	(nVariables = Values.Get_Field_Count() - 1) > 0
+	&&	(nValues    = Values.Get_Record_Count()) > nVariables )
+	{
+		for(i=0; i<=nVariables; i++)
+		{
+			pRecord	= m_pResult->Add_Record();
+			pRecord->Set_Value(MRFIELD_NR	, i);
+			pRecord->Set_Value(MRFIELD_NAME	, Values.Get_Field_Name(i));
+		}
+
+		//-------------------------------------------------
+		_Get_Regression (Values);
+		_Get_Correlation(Values);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Regression_Multiple::_Get_Regression(const CSG_Table &Values)
+{
+	int			i, j, k, nVariables, nValues;
+	double		sum;
+	CSG_Vector	B, Y;
+	CSG_Matrix	P, X;
+
+	if(	(nVariables = Values.Get_Field_Count() - 1) > 0
+	&&	(nValues    = Values.Get_Record_Count()) > nVariables )
+	{
+		B.Create(nVariables + 1);
+		P.Create(nVariables + 1, nVariables + 1);
+
+		Y.Create(nValues);
+		X.Create(nValues, nVariables + 1);
+
+		//-------------------------------------------------
+		for(k=0; k<nValues; k++)
+		{
+			Y[k]	= Values[k][0];
+			X[0][k] = 1.0;
+		}
+
+		for(i=1; i<=nVariables; i++)
+		{
+			for(k=0; k<nValues; k++)
+			{
+				X[i][k] = Values[k][i];
+			}
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<=nVariables; i++)
+		{
+			for(k=0, sum=0.0; k<nValues; k++)
+			{
+				sum		+= X[i][k] * Y[k];
+			}
+
+			B[i]	= sum;
+
+			for(j=0; j<=nVariables; j++) 
+			{ 
+				for(k=0, sum=0.0; k<nValues; k++)
+				{
+					sum		+= X[i][k] * X[j][k];
+				}
+
+				P[i][j]	= sum;
+			}
+		}
+
+		P.Set_Inverse();
+
+		//-------------------------------------------------
+		for(i=0; i<=nVariables; i++)
+		{
+			for(j=0, sum=0.0; j<=nVariables; j++)
+			{
+				sum		+= P[i][j] * B[j];
+			}
+
+			m_pResult->Get_Record(i)->Set_Value(MRFIELD_RCOEFF, sum);
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Regression_Multiple::_Get_Correlation(const class CSG_Table &Values)
+{
+	int			i, j, nVariables, nValues;
+	double		r2, r2_sum;
+	CSG_Matrix	z;
+
+	//-----------------------------------------------------
+	if(	(nVariables = Values.Get_Field_Count() - 1) > 0
+	&&	(nValues    = Values.Get_Record_Count()) > nVariables )
+	{
+		z.Create(nValues, nVariables + 1);
+
+		for(i=0; i<=nVariables; i++)
+		{
+			for(j=0; j<nValues; j++)
+			{
+				z[i][j]	= Values[j][i];
+			}
+		}
+
+		//-------------------------------------------------
+		m_pResult->Get_Record(0)->Set_Value(MRFIELD_ORDER	, -1);
+		m_pResult->Get_Record(0)->Set_Value(MRFIELD_DCOEFF	, -1);
+
+		for(i=0, r2_sum=0.0; i<nVariables; i++)
+		{
+			_Get_Correlation(nValues, nVariables, z.Get_Data() + 1, z[0], j, r2);
+
+			r2_sum	+= (1.0 - r2_sum) * r2;
+
+			m_pResult->Get_Record(j+1)->Set_Value(MRFIELD_ORDER , i);
+			m_pResult->Get_Record(j+1)->Set_Value(MRFIELD_DCOEFF, r2_sum);
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Regression_Multiple::_Get_Correlation(int nValues, int nVariables, double **X, double *Y, int &iMax, double &rMax)
+{
+	int				i, n;
+	double			*XMax;
+	CSG_Regression	r;
+
+	//-----------------------------------------------------
+	for(i=0, n=0, iMax=-1, rMax=0.0; i<nVariables; i++)
+	{
+		if( X[i] && r.Calculate(nValues, X[i], Y) )
+		{
+			n++;
+
+			if( iMax < 0 || rMax < r.Get_R2() )
+			{
+				iMax	= i;
+				rMax	= r.Get_R2();
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( n > 1 )
+	{
+		XMax	= X[iMax];
+		X[iMax]	= NULL;
+
+		for(i=0; i<nVariables; i++)
+		{
+			if( X[i] )
+			{
+				_Eliminate(nValues, XMax, X[i]);
+			}
+		}
+
+		_Eliminate(nValues, XMax, Y);
+	}
+
+	return( iMax >= 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Regression_Multiple::_Eliminate(int nValues, double *X, double *Y)
+{
+	CSG_Regression	r;
+
+	if( r.Calculate(nValues, X, Y) )
+	{
+		for(int i=0; i<nValues; i++)
+		{
+			Y[i]	-= r.Get_Constant() + r.Get_Coefficient() * X[i];
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Regression_Multiple::Get_Ordered(int iOrder)
+{
+	for(int i=0; i<m_pResult->Get_Record_Count(); i++)
+	{
+		if( iOrder == m_pResult->Get_Record(i)->asInt(MRFIELD_ORDER) )
+		{
+			return( i - 1 );
+		}
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+int CSG_Regression_Multiple::Get_Order(int iVariable)
+{
+	if( ++iVariable > 0 && iVariable < m_pResult->Get_Record_Count() )
+	{
+		return( m_pResult->Get_Record(iVariable)->asInt(MRFIELD_ORDER) );
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+double CSG_Regression_Multiple::Get_R2(int iVariable)
+{
+	if( ++iVariable > 0 && iVariable < m_pResult->Get_Record_Count() )
+	{
+		return( m_pResult->Get_Record(iVariable)->asDouble(MRFIELD_DCOEFF) );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Regression_Multiple::Get_R2_Change(int iVariable)
+{
+	int		iOrder	= Get_Order(iVariable);
+
+	if( iOrder > 0 )
+	{
+		return( Get_R2(iVariable) - Get_R2(Get_Ordered(iOrder - 1)) );
+	}
+
+	if( iOrder == 0 )
+	{
+		return( Get_R2(iVariable) );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Regression_Multiple::Get_RConst(void)
+{
+	if( m_pResult->Get_Record_Count() > 1 )
+	{
+		return( m_pResult->Get_Record(0)->asDouble(MRFIELD_RCOEFF) );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Regression_Multiple::Get_RCoeff(int iVariable)
+{
+	if( ++iVariable > 0 && iVariable < m_pResult->Get_Record_Count() )
+	{
+		return( m_pResult->Get_Record(iVariable)->asDouble(MRFIELD_RCOEFF) );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_spline.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_spline.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_spline.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,300 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    mat_spline.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Spline::CSG_Spline(void)
+{
+	m_Values	= NULL;
+	m_nValues	= 0;
+	m_nBuffer	= 0;
+	m_bCreated	= false;
+}
+
+//---------------------------------------------------------
+CSG_Spline::~CSG_Spline(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Spline::Destroy(void)
+{
+	if( m_Values )
+	{
+		SG_Free(m_Values);
+
+		m_Values	= NULL;
+		m_nValues	= 0;
+		m_nBuffer	= 0;
+		m_bCreated	= false;
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Spline::Create(double *xValues, double *yValues, int nValues, double yA, double yB)
+{
+	Destroy();
+
+	for(int i=0; i<nValues; i++)
+	{
+		Add(xValues[i], yValues[i]);
+	}
+
+	return( _Create(yA, yB) );
+}
+
+//---------------------------------------------------------
+bool CSG_Spline::Create(double yA, double yB)
+{
+	return( _Create(yA, yB) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Spline::Add(double x, double y)
+{
+	m_bCreated	= false;
+
+	//-----------------------------------------------------
+	if( m_nValues >= m_nBuffer )
+	{
+		m_nBuffer	+= 64;
+		m_Values	 = (TSG_Point_3D *)SG_Realloc(m_Values, m_nValues * sizeof(TSG_Point_3D));
+	}
+
+	m_nValues++;
+
+	//-----------------------------------------------------
+	if( m_nValues == 1 )
+	{
+		m_Values[0].x	= x;
+		m_Values[0].y	= y;
+	}
+	else
+	{
+		int		i, iAdd;
+
+		for(iAdd=0; iAdd<m_nValues-1 && m_Values[iAdd].x<x; iAdd++)	{}
+
+		for(i=m_nValues-1; i>iAdd; i--)
+		{
+			m_Values[i]	= m_Values[i - 1];
+		}
+
+		m_Values[iAdd].x	= x;
+		m_Values[iAdd].y	= y;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Spline::_Create(double yA, double yB)
+{
+	int		i, k;
+	double	p, qn, sig, un, *u;
+
+	if( m_nValues > 2 )
+	{
+		m_bCreated	= true;
+		u			= (double *)SG_Malloc(m_nValues * sizeof(double));
+
+		if( yA > 0.99e30 )
+		{
+			m_Values[0].z	= u[0]	= 0.0;
+		}
+		else
+		{
+			m_Values[0].z	= -0.5;
+			u[0]			= (3.0 / (m_Values[1].x - m_Values[0].x))
+							* ((m_Values[1].y - m_Values[0].y) / (m_Values[1].x - m_Values[0].x) - yA);
+		}
+
+		for(i=1; i<m_nValues-1; i++)
+		{
+			sig				= (m_Values[i].x - m_Values[i - 1].x) / (m_Values[i + 1].x - m_Values[i - 1].x);
+			p				= sig * m_Values[i - 1].z + 2.0;
+			m_Values[i].z	= (sig - 1.0) / p;
+			u[i]			= (m_Values[i + 1].y - m_Values[i    ].y) / (m_Values[i + 1].x - m_Values[i    ].x)
+							- (m_Values[i    ].y - m_Values[i - 1].y) / (m_Values[i    ].x - m_Values[i - 1].x);
+			u[i]			= (6.0 * u[i] / (m_Values[i + 1].x - m_Values[i - 1].x) - sig * u[i - 1]) / p;
+		}
+
+		if( yB > 0.99e30 )
+		{
+			qn	= un	= 0.0;
+		}
+		else
+		{
+			qn				= 0.5;
+			un				= (3.0 / (m_Values[m_nValues - 1].x - m_Values[m_nValues - 2].x))
+							* (yB  - (m_Values[m_nValues - 1].y - m_Values[m_nValues - 2].y)
+							       / (m_Values[m_nValues - 1].x - m_Values[m_nValues - 2].x));
+		}
+
+		m_Values[m_nValues - 1].z	= (un - qn * u[m_nValues - 2]) / (qn * m_Values[m_nValues - 2].z + 1.0);
+
+		for(k=m_nValues-2; k>=0; k--)
+		{
+			m_Values[k].z	= m_Values[k].z * m_Values[k + 1].z + u[k];
+		}
+
+		SG_Free(u);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Spline::Get_Value(double x, double &y)
+{
+	if( m_bCreated || Create() )
+	{
+		int		klo, khi, k;
+		double	h, b, a;
+
+		klo	= 0;
+		khi	= m_nValues - 1;
+
+		while( khi - klo > 1 )
+		{
+			k	= (khi+klo) >> 1;
+
+			if( m_Values[k].x > x )
+			{
+				khi	= k;
+			}
+			else
+			{
+				klo	= k;
+			}
+		}
+
+		h	= m_Values[khi].x - m_Values[klo].x;
+
+		if( h != 0.0 )
+		{
+			a	= (m_Values[khi].x - x) / h;
+			b	= (x - m_Values[klo].x) / h;
+
+			y	= a * m_Values[klo].y + b * m_Values[khi].y
+				+ ((a*a*a - a) * m_Values[klo].z + (b*b*b - b) * m_Values[khi].z) * (h*h) / 6.0;
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CSG_Spline::Get_Value(double x)
+{
+	Get_Value(x, x);
+
+	return( x );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     mat_tools.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double			SG_Get_Square(double x)
+{
+	return( x * x );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Simple_Statistics::CSG_Simple_Statistics(void)
+{
+	Invalidate();
+}
+
+//---------------------------------------------------------
+void CSG_Simple_Statistics::Invalidate(void)
+{
+	m_bEvaluated	= false;
+	m_nValues		= 0;
+	m_Sum			= 0.0;
+	m_Sum2			= 0.0;
+
+	m_Minimum		= 0.0;
+	m_Maximum		= 0.0;
+	m_Range			= 0.0;
+	m_Mean			= 0.0;
+	m_Variance		= 0.0;
+	m_StdDev		= 0.0;
+}
+
+//---------------------------------------------------------
+void CSG_Simple_Statistics::_Evaluate(void)
+{
+	if( m_nValues > 0 )
+	{
+		m_Range		= m_Maximum - m_Minimum;
+		m_Mean		= m_Sum  / m_nValues;
+		m_Variance	= m_Sum2 / m_nValues - m_Mean*m_Mean;
+		m_StdDev	= sqrt(m_Variance);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_tools.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,897 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     mat_tools.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__mat_tools_H
+#define HEADER_INCLUDED__SAGA_API__mat_tools_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef SWIG
+
+#include <math.h>
+
+#endif	// #ifdef SWIG
+
+//---------------------------------------------------------
+#include "geo_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef M_PI
+#define M_PI						3.141592653589793
+#endif
+
+#define M_PI_045					(M_PI / 4.0)
+#define M_PI_090					(M_PI / 2.0)
+#define M_PI_135					(M_PI * 3.0 / 4.0)
+#define M_PI_180					(M_PI)
+#define M_PI_225					(M_PI * 5.0 / 4.0)
+#define M_PI_270					(M_PI * 3.0 / 2.0)
+#define M_PI_315					(M_PI * 7.0 / 4.0)
+#define M_PI_360					(M_PI * 2.0)
+
+#define M_RAD_TO_DEG				(180.0 / M_PI)
+#define M_DEG_TO_RAD				(M_PI / 180.0)
+
+//---------------------------------------------------------
+#define M_EULER						2.718281828459045
+
+//---------------------------------------------------------
+#define N_MEGABYTE_BYTES			0x100000
+
+//---------------------------------------------------------
+#define M_ALMOST_ZERO				0.001l
+#define M_TINY						(1.0e-20)
+
+//---------------------------------------------------------
+#define M_SQR(x)					((x) * (x))
+#define M_SQRT(x)					sqrt((double)(x))
+#define M_GET_LENGTH(x, y)			sqrt((double)((x)*(x) + (y)*(y)))
+
+#define M_GET_MIN(a, b)				(((a) < (b)) ? (a) : (b))
+#define M_GET_MAX(a, b)				(((a) > (b)) ? (a) : (b))
+#define M_SET_MINMAX(min, max, x)	if( min > x ) { min = x; } else if( max < x ) { max = x; }
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT double		SG_Get_Square		(double x);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef int (* TSG_PFNC_Compare) (const int iElement_1, const int iElement_2);
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Index
+{
+public:
+	CSG_Index(void);
+	virtual ~CSG_Index(void);
+
+								CSG_Index			(int nValues, int    *Values, bool bAscending = true);
+	bool						Create				(int nValues, int    *Values, bool bAscending = true);
+
+								CSG_Index			(int nValues, double *Values, bool bAscending = true);
+	bool						Create				(int nValues, double *Values, bool bAscending = true);
+
+								CSG_Index			(int nValues, TSG_PFNC_Compare fCompare, bool bAscending = true);
+	bool						Create				(int nValues, TSG_PFNC_Compare fCompare, bool bAscending = true);
+
+	bool						Destroy				(void);
+
+	bool						is_Okay				(void)						const	{	return( m_nValues > 0 );	}
+	int							Get_Count			(void)						const	{	return( m_nValues );		}
+	int							Get_Index			(int i, bool bInv = false)	const	{	return( i >= 0 && i < m_nValues ? m_Index[bInv ? m_nValues-1-i : i] : -1 );	}
+	int							operator []			(int i)						const	{	return( i >= 0 && i < m_nValues ? m_Index[i] : -1 );	}
+
+
+private:
+
+	void						*m_Values;
+
+	int							m_nValues, *m_Index, m_iCompare;
+
+	TSG_PFNC_Compare			m_fCompare;
+
+
+	void						_On_Construction	(void);
+
+	bool						_Set_Array			(int nValues);
+	bool						_Set_Index			(bool bAscending);
+
+	int							_Compare			(const int iElement_1, const int iElement_2);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Vector
+{
+public:
+	CSG_Vector(void);
+	virtual ~CSG_Vector(void);
+
+								CSG_Vector			(const CSG_Vector &Vector);
+	bool						Create				(const CSG_Vector &Vector);
+
+								CSG_Vector			(int n, double *Data = NULL);
+	bool						Create				(int n, double *Data = NULL);
+
+	bool						Destroy				(void);
+
+	int							Get_N				(void)	const	{	return( m_n );		}
+	double *					Get_Data			(void)	const	{	return( m_z );		}
+	double						operator ()			(int x)	const	{	return( m_z[x] );	}
+	double &					operator []			(int x)			{	return( m_z[x] );	}
+
+	CSG_String					asString			(void);
+
+	bool						is_Equal			(const CSG_Vector &Vector)	const;
+
+	bool						Assign				(double Scalar);
+	bool						Assign				(const CSG_Vector &Vector);
+	bool						Add					(double Scalar);
+	bool						Add					(const CSG_Vector &Vector);
+	bool						Subtract			(const CSG_Vector &Vector);
+	bool						Multiply			(double Scalar);
+	bool						Multiply			(const CSG_Vector &Vector);
+	double						Multiply_Scalar		(const CSG_Vector &Vector)	const;
+	bool						Multiply			(const class CSG_Matrix &Matrix);
+
+	bool						operator ==			(const CSG_Vector &Vector)	const;
+	CSG_Vector &				operator =			(double Scalar);
+	CSG_Vector &				operator =			(const CSG_Vector &Vector);
+	CSG_Vector &				operator +=			(double Scalar);
+	CSG_Vector &				operator +=			(const CSG_Vector &Vector);
+	CSG_Vector &				operator -=			(double Scalar);
+	CSG_Vector &				operator -=			(const CSG_Vector &Vector);
+	CSG_Vector &				operator *=			(double Scalar);
+	CSG_Vector &				operator *=			(const CSG_Vector &Vector);
+	CSG_Vector &				operator *=			(const class CSG_Matrix &Matrix);
+	CSG_Vector					operator +			(double Scalar)				const;
+	CSG_Vector					operator +			(const CSG_Vector &Vector)	const;
+	CSG_Vector					operator -			(double Scalar)				const;
+	CSG_Vector					operator -			(const CSG_Vector &Vector)	const;
+	CSG_Vector					operator *			(double Scalar)				const;
+	double						operator *			(const CSG_Vector &Vector)	const;
+
+	bool						Set_Zero			(void);
+	bool						Set_Unity			(void);
+
+	double						Get_Length			(void)						const;
+	double						Get_Angle			(const CSG_Vector &Vector)	const;
+	CSG_Vector					Get_Unity			(void)						const;
+
+
+private:
+
+	int							m_n;
+
+	double						*m_z;
+
+
+	void						_On_Construction	(void);
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT CSG_Vector	operator *			(double Scalar, const CSG_Vector &Vector);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Matrix
+{
+public:
+	CSG_Matrix(void);
+	virtual ~CSG_Matrix(void);
+
+								CSG_Matrix			(const CSG_Matrix &Matrix);
+	bool						Create				(const CSG_Matrix &Matrix);
+
+								CSG_Matrix			(int nx, int ny, double *Data = NULL);
+	bool						Create				(int nx, int ny, double *Data = NULL);
+
+	bool						Destroy				(void);
+
+	bool						Add_Cols			(int nCols);
+	bool						Add_Rows			(int nRows);
+
+	int							Get_NX				(void)			const	{	return( m_nx );			}
+	int							Get_NY				(void)			const	{	return( m_ny );			}
+	double **					Get_Data			(void)			const	{	return( m_z );			}
+	double						operator ()			(int y, int x)	const	{	return( m_z[y][x] );	}
+	double *					operator []			(int y)			const	{	return( m_z[y] );		}
+
+	CSG_String					asString			(void);
+
+	bool						is_Square			(void)	const	{	return( m_nx > 0 && m_nx == m_ny );	}
+	bool						is_Equal			(const CSG_Matrix &Matrix)	const;
+
+	bool						Assign				(double Scalar);
+	bool						Assign				(const CSG_Matrix &Matrix);
+	bool						Add					(double Scalar);
+	bool						Add					(const CSG_Matrix &Matrix);
+	bool						Subtract			(const CSG_Matrix &Matrix);
+	bool						Multiply			(double Scalar);
+	CSG_Vector					Multiply			(const CSG_Vector &Vector)	const;
+	CSG_Matrix					Multiply			(const CSG_Matrix &Matrix)	const;
+
+	bool						operator ==			(const CSG_Matrix &Matrix)	const;
+	CSG_Matrix &				operator =			(double Scalar);
+	CSG_Matrix &				operator =			(const CSG_Matrix &Matrix);
+	CSG_Matrix &				operator +=			(double Scalar);
+	CSG_Matrix &				operator +=			(const CSG_Matrix &Matrix);
+	CSG_Matrix &				operator -=			(double Scalar);
+	CSG_Matrix &				operator -=			(const CSG_Matrix &Matrix);
+	CSG_Matrix &				operator *=			(double Scalar);
+	CSG_Matrix &				operator *=			(const CSG_Matrix &Matrix);
+	CSG_Matrix					operator +			(double Scalar)				const;
+	CSG_Matrix					operator +			(const CSG_Matrix &Matrix)	const;
+	CSG_Matrix					operator -			(double Scalar)				const;
+	CSG_Matrix					operator -			(const CSG_Matrix &Matrix)	const;
+	CSG_Matrix					operator *			(double Scalar)				const;
+	CSG_Vector					operator *			(const CSG_Vector &Vector)	const;
+	CSG_Matrix					operator *			(const CSG_Matrix &Matrix)	const;
+
+	bool						Set_Zero			(void);
+	bool						Set_Identity		(void);
+	bool						Set_Transpose		(void);
+	bool						Set_Inverse			(bool bSilent = true, int nSubSquare = 0);
+
+	double						Get_Determinant		(void)						const;
+	CSG_Matrix					Get_Transpose		(void)						const;
+	CSG_Matrix					Get_Inverse			(bool bSilent = true, int nSubSquare = 0)	const;
+
+
+private:
+
+	int							m_nx, m_ny;
+
+	double						**m_z;
+
+
+	void						_On_Construction	(void);
+
+};
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT CSG_Matrix	operator *			(double Scalar, const CSG_Matrix &Matrix);
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT bool		SG_Matrix_Solve		(CSG_Matrix &Matrix, CSG_Vector &Vector, bool bSilent = true);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Grid_Radius
+{
+public:
+	CSG_Grid_Radius(int maxRadius = 0);
+	~CSG_Grid_Radius(void);
+
+	bool						Create				(int maxRadius);
+	void						Destroy				(void);
+
+	int							Get_Maximum			(void)			{	return( m_maxRadius );	}
+
+	int							Get_nPoints			(void)			{	return( m_nPoints );	}
+	int							Get_nPoints			(int iRadius)	{	return( iRadius >= 0 && iRadius < m_maxRadius ? m_nPoints_R[iRadius] : 0 );	}
+
+	double						Get_Point			(int iPoint, int &x, int &y)
+	{
+		if( iPoint >= 0 && iPoint < m_nPoints )
+		{
+			x	= m_Points[iPoint].x;
+			y	= m_Points[iPoint].y;
+
+			return( m_Points[iPoint].d );				// Distance...
+		}
+
+		return( -1.0 );
+	}
+
+	double						Get_Point			(int iPoint, int xOffset, int yOffset, int &x, int &y)
+	{
+		double	d;
+
+		if( (d = Get_Point(iPoint, x, y)) >= 0.0 )
+		{
+			x	+= xOffset;
+			y	+= yOffset;
+		}
+
+		return( d );
+	}
+
+	double						Get_Point			(int iRadius, int iPoint, int &x, int &y)
+	{
+		if( iRadius >= 0 && iRadius <= m_maxRadius && iPoint >= 0 && iPoint < m_nPoints_R[iRadius] )
+		{
+			x	= m_Points_R[iRadius][iPoint].x;
+			y	= m_Points_R[iRadius][iPoint].y;
+
+			return( m_Points_R[iRadius][iPoint].d );	// Distance...
+		}
+
+		return( -1.0 );
+	}
+
+	double						Get_Point			(int iRadius, int iPoint, int xOffset, int yOffset, int &x, int &y)
+	{
+		double	d;
+
+		if( (d = Get_Point(iRadius, iPoint, x, y)) >= 0.0 )
+		{
+			x	+= xOffset;
+			y	+= yOffset;
+		}
+
+		return( d );
+	}
+
+
+private:
+
+	int							m_maxRadius, m_nPoints, *m_nPoints_R;
+
+	typedef struct
+	{
+		int						x, y;
+
+		double					d;
+	}
+	TSG_Grid_Radius;
+
+	TSG_Grid_Radius				*m_Points, **m_Points_R;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Simple_Statistics
+{
+public:
+	CSG_Simple_Statistics(void);
+
+	void						Invalidate			(void);
+
+	bool						is_Evaluated		(void)		{	return( m_bEvaluated );	}
+
+	int							Get_Count			(void)		{	return( m_nValues );	}
+
+	double						Get_Minimum			(void)		{	_Update();	return( m_Minimum	);	}
+	double						Get_Maximum			(void)		{	_Update();	return( m_Maximum	);	}
+	double						Get_Range			(void)		{	_Update();	return( m_Range		);	}
+	double						Get_Mean			(void)		{	_Update();	return( m_Mean		);	}
+	double						Get_Variance		(void)		{	_Update();	return( m_Variance	);	}
+	double						Get_StdDev			(void)		{	_Update();	return( m_StdDev	);	}
+
+	void						Add_Value			(double Value)
+	{
+		if( m_nValues == 0 )
+		{
+			m_Minimum	= m_Maximum	= Value;
+		}
+		else if( m_Minimum > Value )
+		{
+			m_Minimum	= Value;
+		}
+		else if( m_Maximum < Value )
+		{
+			m_Maximum	= Value;
+		}
+
+		m_nValues		++;
+		m_Sum			+= Value;
+		m_Sum2			+= Value * Value;
+
+		m_bEvaluated	= false;
+	}
+
+
+protected:
+
+	bool						m_bEvaluated;
+
+	int							m_nValues;
+
+	double						m_Sum, m_Sum2, m_Minimum, m_Maximum, m_Range, m_Mean, m_Variance, m_StdDev;
+
+
+	void						_Evaluate			(void);
+
+	void						_Update				(void)
+	{
+		if( !m_bEvaluated )
+		{
+			_Evaluate();
+		}
+	}
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Spline
+{
+public:
+	CSG_Spline(void);
+	virtual ~CSG_Spline(void);
+
+	void						Destroy				(void);
+
+	bool						Create				(double *xValues, double *yValues, int nValues, double yA = 1.0e30, double yB = 1.0e30);
+	bool						Create				(double yA = 1.0e30, double yB = 1.0e30);
+
+	void						Add					(double x, double y);
+
+	double						Get_xMin			(void)	{	return( m_nValues > 0 ? m_Values[0            ].x : 0.0 );	}
+	double						Get_xMax			(void)	{	return( m_nValues > 0 ? m_Values[m_nValues - 1].x : 0.0 );	}
+
+	bool						Get_Value			(double x, double &y);
+	double						Get_Value			(double x);
+
+
+protected:
+
+	bool						m_bCreated;
+
+	int							m_nValues, m_nBuffer;
+
+	TSG_Point_3D				*m_Values;
+
+
+	bool						_Create				(double yA, double yB);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Regression_Type
+{
+	REGRESSION_Linear	= 0,	// Y = a + b * X
+	REGRESSION_Rez_X,			// Y = a + b / X
+	REGRESSION_Rez_Y,			// Y = a / (b - X)
+	REGRESSION_Pow,				// Y = a * X^b
+	REGRESSION_Exp,				// Y = a * e^(b * X)
+	REGRESSION_Log				// Y = a + b * ln(X)
+}
+TSG_Regression_Type;
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Regression
+{
+public:
+	CSG_Regression(void);
+	virtual ~CSG_Regression(void);
+
+	void						Destroy				(void);
+
+	void						Set_Values			(int nValues, double *x, double *y);
+	void						Add_Values			(double x, double y);
+
+	int							Get_Count			(void)			{	return( m_nValues );	}
+
+	double						Get_xValue			(int iValue)	{	return( iValue >= 0 && iValue < m_nValues ? m_x[iValue] : 0.0 );	}
+	double						Get_yValue			(int iValue)	{	return( iValue >= 0 && iValue < m_nValues ? m_y[iValue] : 0.0 );	}
+	bool						Get_Values			(int iValue, double &x, double &y)
+	{
+		if( iValue >= 0 && iValue < m_nValues )
+		{
+			x	= m_x[iValue];
+			y	= m_y[iValue];
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	double						Get_xMin			(void)			{	return( m_xMin );	}
+	double						Get_xMax			(void)			{	return( m_xMax );	}
+	double						Get_xMean			(void)			{	return( m_xMean );	}
+	double						Get_xVariance		(void)			{	return( m_xVar );	}
+	double						Get_x				(double y);	// returns INF on error, this can be checked using the _finite() function (libc, include <float.h>)...
+
+	double						Get_yMin			(void)			{	return( m_yMin );	}
+	double						Get_yMax			(void)			{	return( m_yMax );	}
+	double						Get_yMean			(void)			{	return( m_yMean );	}
+	double						Get_yVariance		(void)			{	return( m_yVar );	}
+	double						Get_y				(double x);	// returns INF on error, this can be checked using the _finite() function (libc, include <float.h>)...
+
+	double						Get_Constant		(void)			{	return( m_RConst );	}
+	double						Get_Coefficient		(void)			{	return( m_RCoeff );	}
+	double						Get_R				(void)			{	return( m_R );		}
+	double						Get_R2				(void)			{	return( m_R*m_R );	}
+
+	const SG_Char *				asString			(void);
+
+	TSG_Regression_Type			Get_Type			(void)			{	return( m_Type );	}
+
+	bool						Calculate			(TSG_Regression_Type Type = REGRESSION_Linear);
+	bool						Calculate			(int nValues, double *x, double *y, TSG_Regression_Type Type = REGRESSION_Linear);
+
+
+protected:
+
+	int							m_nValues, m_nBuffer;
+
+	double						m_RConst, m_RCoeff, m_R,
+								m_xMin, m_xMax, m_xMean, m_xVar, *m_x,
+								m_yMin, m_yMax, m_yMean, m_yVar, *m_y;
+
+	TSG_Regression_Type			m_Type;
+
+
+	bool						_Get_MinMeanMax		(double &xMin, double &xMean, double &xMax, double &yMin, double &yMean, double &yMax);
+
+	double						_Y_Transform		(double x);
+	double						_X_Transform		(double y);
+
+	bool						_Linear				(void);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Regression_Multiple
+{
+public:
+	CSG_Regression_Multiple(void);
+	virtual ~CSG_Regression_Multiple(void);
+
+	void						Destroy				(void);
+
+	bool						Calculate			(const class CSG_Table &Values);
+
+	class CSG_Table *			Get_Result			(void)	{	return( m_pResult );	}
+
+	int							Get_Ordered			(int iOrder);
+	int							Get_Order			(int iVariable);
+	double						Get_R2				(int iVariable);
+	double						Get_R2_Change		(int iVariable);
+	double						Get_RConst			(void);
+	double						Get_RCoeff			(int iVariable);
+
+
+protected:
+
+	class CSG_Table				*m_pResult;
+
+
+	bool						_Get_Regression		(const class CSG_Table &Values);
+
+	bool						_Get_Correlation	(const class CSG_Table &Values);
+	bool						_Get_Correlation	(int nValues, int nVariables, double **X, double *Y, int &iMax, double &rMax);
+
+	bool						_Eliminate			(int nValues, double *X, double *Y);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Formula Parser (A. Ringeler)			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef double (*TSG_PFNC_Formula_0)(void);
+typedef double (*TSG_PFNC_Formula_1)(double);
+typedef double (*TSG_PFNC_Formula_2)(double, double);
+typedef double (*TSG_PFNC_Formula_3)(double, double, double);
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Formula
+{
+public:
+	CSG_Formula(void);
+	virtual ~CSG_Formula(void);
+
+	static CSG_String			Get_Help_Operators	(void);
+	static CSG_String			Get_Help_Usage		(void);
+
+	bool						Get_Error			(int *pPosition = NULL, CSG_String *pMessage = NULL);
+
+	int							Add_Function		(SG_Char *Name, TSG_PFNC_Formula_1 f, int N_of_Pars, int Varying);
+	int							Del_Function		(SG_Char *Name);
+
+	bool						Set_Formula			(const SG_Char *Formula);
+	CSG_String					Get_Formula			(void)		{	return( m_sFormula );	}
+
+	void						Set_Variable		(SG_Char Variable, double Value);
+
+	double						Get_Value			(void);
+	double						Get_Value			(double x);
+	double						Get_Value			(double *Values, int nValues);
+	double						Get_Value			(SG_Char *Arguments, ...);
+
+	const SG_Char *				Get_Used_Variables	(void);
+
+
+	//-----------------------------------------------------
+	typedef struct 
+	{
+		SG_Char					*name;
+		TSG_PFNC_Formula_1		f;			
+		int						n_pars;		
+		int						varying;	// Does the result of the function vary even when the parameters stay the same? varying = 1 for e.g. random - number generators.
+	}
+	TSG_Formula_Item;
+
+
+private:
+
+	//-----------------------------------------------------
+	typedef struct 
+	{
+		SG_Char					*code;
+		double					*ctable;
+	}
+	TMAT_Formula;
+
+
+	//-----------------------------------------------------
+	bool						m_bError, m_Vars_Used[256];
+
+	int							m_Error_Position, m_Length;
+
+	TMAT_Formula				m_Formula;
+
+	CSG_String					m_sFormula, m_sError;
+
+	const SG_Char				*i_error;
+	int							i_pctable;			// number of items in a table of constants - used only by the translating functions
+
+	double						m_Parameters[256],
+								*i_ctable;			// current table of constants - used only by the translating functions
+
+
+	void						_Set_Error			(const SG_Char *Error = NULL);
+
+	double						_Get_Value			(TMAT_Formula Function);
+
+	int							_is_Operand			(SG_Char c);
+	int							_is_Operand_Code	(SG_Char c);
+	int							_is_Number			(SG_Char c);
+
+	int							_Get_Function		(int i, SG_Char *name, int *n_pars, int *varying);
+	int							_Get_Function		(SG_Char *name);
+
+	TMAT_Formula				_Translate			(const SG_Char *source, const SG_Char *args, int *length, int *error);
+
+	int							max_size(const SG_Char *source);
+	SG_Char *					my_strtok(SG_Char *s);
+	SG_Char *					i_trans(SG_Char *function, SG_Char *begin, SG_Char *end);
+	SG_Char *					comp_time(SG_Char *function, SG_Char *fend, int npars);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	SG_TREND_STRING_Formula	= 0,
+	SG_TREND_STRING_Function,
+	SG_TREND_STRING_Formula_Parameters,
+	SG_TREND_STRING_Complete
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Trend
+{
+public:
+	CSG_Trend(void);
+	virtual ~CSG_Trend(void);
+
+	bool						Set_Formula			(const SG_Char *Formula = NULL);
+	CSG_String					Get_Formula			(int Type = SG_TREND_STRING_Complete);
+
+	int							Get_Parameter_Count	(void) const	{	return( m_Params.m_Count );		}
+	double *					Get_Parameters		(void) const	{	return( m_Params.m_A );			}
+
+	void						Clr_Data			(void);
+	void						Set_Data			(double *xData, double *yData, int nData, bool bAdd = false);
+	void						Set_Data			(const CSG_Points &Data, bool bAdd = false);
+	void						Add_Data			(double x, double y);
+	int							Get_Data_Count		(void) const	{	return( m_Data.Get_Count() );	}
+	double						Get_Data_X			(int Index)		{	return( m_Data.Get_X(Index) );	}
+	double						Get_Data_Y			(int Index)		{	return( m_Data.Get_Y(Index) );	}
+	double						Get_Data_XMin		(void)			{	return( m_xMin );	}
+	double						Get_Data_XMax		(void)			{	return( m_xMax );	}
+	double						Get_Data_YMin		(void)			{	return( m_yMin );	}
+	double						Get_Data_YMax		(void)			{	return( m_yMax );	}
+
+	bool						Set_Max_Iterations	(int Iterations);
+	int							Get_Max_Iterations	(void)			{	return( m_Iter_Max);	}
+	bool						Set_Max_Lambda		(double Lambda);
+	double						Get_Max_Lambda		(void)			{	return( m_Lambda_Max);	}
+
+	bool						Get_Trend			(double *xData, double *yData, int nData, const SG_Char *Formula = NULL);
+	bool						Get_Trend			(const CSG_Points &Data, const SG_Char *Formula = NULL);
+	bool						Get_Trend			(void);
+
+	bool						is_Okay				(void)			{	return( m_bOkay );		}
+
+	CSG_String					Get_Error			(void);
+
+	double						Get_ChiSquare		(void);
+	double						Get_R2				(void);
+
+	double						Get_Value			(double x);
+
+
+private:
+
+	//-----------------------------------------------------
+	class SAGA_API_DLL_EXPORT CFncParams
+	{
+	public:
+		CFncParams(void);
+		virtual ~CFncParams(void);
+
+		bool					Create				(const SG_Char *Variables, int nVariables);
+		bool					Destroy				(void);
+
+		int						m_Count;
+
+		SG_Char					*m_Variables;
+
+		double					*m_A, *m_Atry, *m_dA, *m_dA2, *m_Beta, **m_Alpha, **m_Covar;
+
+	};
+
+
+	//-----------------------------------------------------
+	bool						m_bOkay;
+
+	int							m_Iter_Max;
+
+	double						m_ChiSqr, m_ChiSqr_o, m_Lambda, m_Lambda_Max, m_xMin, m_xMax, m_yMin, m_yMax;
+
+	CSG_Points					m_Data;
+
+	CFncParams					m_Params;
+
+	CSG_Formula					m_Formula;
+
+
+	bool						_Fit_Function		(void);
+	bool						_Get_Gaussj			(void);
+	bool						_Get_mrqcof			(double *Parameters, double **Alpha, double *Beta);
+
+	void						_Get_Function		(double x, double *Parameters, double &y, double *dy_da);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__mat_tools_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_trend.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_trend.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/mat_trend.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,839 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     mat_trend.cpp                     //
+//                                                       //
+//                 Copyright (C) 2006 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//  Based on the LMFit.h/cpp, Fit.h/cpp source codes of  //
+//    A. Ringeler (see 'table_calculus' sub project).    //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "mat_tools.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SWAP(a, b)	{	temp = (a); (a) = (b); (b) = temp;	}
+
+//---------------------------------------------------------
+#define EPSILON		0.001
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Trend::CFncParams::CFncParams(void)
+{
+	m_Count		= 0;
+}
+
+//---------------------------------------------------------
+CSG_Trend::CFncParams::~CFncParams(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::CFncParams::Create(const SG_Char *Variables, int nVariables)
+{
+	int		i;
+
+	if( m_Count != nVariables )
+	{
+		Destroy();
+
+		m_Count		= nVariables;
+
+		m_Variables	= (SG_Char *)SG_Calloc(m_Count, sizeof(SG_Char));
+		m_A			= (double  *)SG_Calloc(m_Count, sizeof(double));
+		m_Atry		= (double  *)SG_Calloc(m_Count, sizeof(double));
+		m_Beta		= (double  *)SG_Calloc(m_Count, sizeof(double));
+		m_dA		= (double  *)SG_Calloc(m_Count, sizeof(double));
+		m_dA2		= (double  *)SG_Calloc(m_Count, sizeof(double));
+		m_Alpha		= (double **)SG_Calloc(m_Count, sizeof(double *));
+		m_Covar		= (double **)SG_Calloc(m_Count, sizeof(double *));
+
+		for(i=0; i<m_Count; i++)
+		{
+			m_Alpha[i]		= (double *)SG_Calloc(m_Count, sizeof(double));
+			m_Covar[i]		= (double *)SG_Calloc(m_Count, sizeof(double));
+		}
+	}
+
+	for(i=0; i<m_Count; i++)
+	{
+		m_Variables[i]	= Variables[i];
+		m_A[i]			= 1.0;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::CFncParams::Destroy(void)
+{
+	if( m_Count > 0 )
+	{
+		for(int i=0; i<m_Count; i++)
+		{
+			SG_Free(m_Alpha[i]);
+			SG_Free(m_Covar[i]);
+		}
+
+		SG_Free(m_Variables);
+		SG_Free(m_A);
+		SG_Free(m_Atry);
+		SG_Free(m_Beta);
+		SG_Free(m_dA);
+		SG_Free(m_dA2);
+		SG_Free(m_Alpha);
+		SG_Free(m_Covar);
+
+		m_Count	= 0;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Trend::CSG_Trend(void)
+{
+	m_Lambda_Max	= 10000;
+	m_Iter_Max		= 1000;
+
+//	Set_Formula(SG_T("a + b * x"));
+}
+
+//---------------------------------------------------------
+CSG_Trend::~CSG_Trend(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Trend::Set_Formula(const SG_Char *Formula)
+{
+	m_bOkay	= false;
+
+	if( m_Formula.Set_Formula(Formula) )
+	{
+		CSG_String	vars, uvars(m_Formula.Get_Used_Variables());
+
+		for(unsigned int i=0; i<uvars.Length(); i++)
+		{
+			if( uvars.c_str()[i] >= 'a' && uvars.c_str()[i] <= 'z' && uvars.c_str()[i] != 'x' )
+			{
+				vars.Append(uvars.c_str()[i]);
+			}
+		}
+
+		return( m_Params.Create(vars.c_str(), vars.Length()) );
+	}
+
+	m_Params.Destroy();
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Trend::Clr_Data(void)
+{
+	m_Data.Clear();
+
+	m_bOkay	= false;
+}
+
+//---------------------------------------------------------
+void CSG_Trend::Set_Data(double *xData, double *yData, int nData, bool bAdd)
+{
+	if( !bAdd )
+	{
+		m_Data.Clear();
+	}
+
+	for(int i=0; i<nData; i++)
+	{
+		Add_Data(xData[i], yData[i]);
+	}
+
+	m_bOkay	= false;
+}
+
+//---------------------------------------------------------
+void CSG_Trend::Set_Data(const CSG_Points &Data, bool bAdd)
+{
+	if( !bAdd )
+	{
+		m_Data.Clear();
+	}
+
+	for(int i=0; i<Data.Get_Count(); i++)
+	{
+		Add_Data(Data.Get_X(i), Data.Get_Y(i));
+	}
+
+	m_bOkay	= false;
+}
+
+//---------------------------------------------------------
+void CSG_Trend::Add_Data(double x, double y)
+{
+	if( m_Data.Get_Count() == 0 )
+	{
+		m_xMin	= m_xMax	= x;
+		m_yMin	= m_yMax	= y;
+	}
+	else
+	{
+		if( m_xMin > x )	m_xMin	= x;	else if( m_xMax < x )	m_xMax	= x;
+		if( m_yMin > y )	m_yMin	= y;	else if( m_yMax < y )	m_yMax	= y;
+	}
+
+	m_Data.Add(x, y);
+
+	m_bOkay	= false;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Trend::Set_Max_Iterations(int Iterations)
+{
+	if( Iterations > 0 )
+	{
+		m_Iter_Max		= Iterations;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::Set_Max_Lambda(double Lambda)
+{
+	if( Lambda > 0.0 )
+	{
+		m_Lambda_Max	= Lambda;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Trend::Get_Trend(double *xData, double *yData, int nData, const SG_Char *Formula)
+{
+	Set_Data(xData, yData, false);
+
+	if( Formula )
+	{
+		Set_Formula(Formula);
+	}
+
+	return( Get_Trend() );
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::Get_Trend(const CSG_Points &Data, const SG_Char *Formula)
+{
+	Set_Data(Data, false);
+
+	if( Formula )
+	{
+		Set_Formula(Formula);
+	}
+
+	return( Get_Trend() );
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::Get_Trend(void)
+{
+	if( !m_Formula.Get_Error() )
+	{
+		int		i;
+
+		m_bOkay	= true;
+
+		//-------------------------------------------------
+		if( m_Data.Get_Count() > 1 )
+		{
+			if( m_Params.m_Count > 0 )
+			{
+				m_Lambda	= 0.001;
+
+				_Get_mrqcof(m_Params.m_A, m_Params.m_Alpha, m_Params.m_Beta);
+
+				m_ChiSqr_o	= m_ChiSqr;
+
+				for(i=0; i<m_Params.m_Count; i++)
+				{
+					m_Params.m_Atry[i]	= m_Params.m_A[i];
+				}
+
+				//-----------------------------------------
+				for(i=0; i<m_Iter_Max && m_Lambda<m_Lambda_Max && m_bOkay && SG_UI_Process_Get_Okay(false); i++)
+				{
+					m_bOkay	= _Fit_Function();
+				}
+
+				//-----------------------------------------
+				for(i=0; i<m_Params.m_Count; i++)
+				{
+					m_Formula.Set_Variable(m_Params.m_Variables[i], m_Params.m_A[i]);
+				}
+			}
+
+			//---------------------------------------------
+			double	y_m, y_o, y_t;
+
+			for(i=0, y_m=0.0; i<m_Data.Get_Count(); i++)
+			{
+				y_m	+= m_Data.Get_Y(i);
+			}
+
+			y_m	/= m_Data.Get_Count();
+
+			for(i=0, y_o=0.0, y_t=0.0; i<m_Data.Get_Count(); i++)
+			{
+				y_o	+= SG_Get_Square(y_m - m_Data.Get_Y(i));
+				y_t	+= SG_Get_Square(y_m - m_Formula.Get_Value(m_Data.Get_X(i)));
+			}
+
+			m_ChiSqr_o	= y_o > 0.0 ? y_t / y_o : 1.0;
+		}
+	}
+
+	return( m_bOkay );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_Trend::Get_Error(void)
+{
+	int				Position;
+	CSG_String		s, Message;
+
+	if( m_bOkay )
+	{
+	}
+	else if( m_Formula.Get_Error(&Position, &Message) )
+	{
+		s.Printf(SG_T("%s [%s] %s: %d. \"%s\""), LNG("Error in formula"), m_Formula.Get_Formula().c_str(), LNG("Position"), Position + 1, Message.c_str());
+	}
+	else
+	{
+		s.Printf(SG_T("%s"), LNG("Error in Trend Calculation"));
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Trend::Get_Formula(int Type)
+{
+	int			i;
+	CSG_String	s;
+
+	switch( Type )
+	{
+	case SG_TREND_STRING_Formula:	default:
+		s	+= m_Formula.Get_Formula().c_str();
+		break;
+
+	case SG_TREND_STRING_Function:
+		s	+= m_Formula.Get_Formula().c_str();
+		s	+= SG_T("\n");
+
+		if( m_Params.m_Count > 0 )
+		{
+			s	+= SG_T("\n");
+
+			for(i=0; i<m_Params.m_Count && m_bOkay; i++)
+			{
+				s	+= CSG_String::Format(SG_T("%c = %g\n"), m_Params.m_Variables[i], m_Params.m_A[i]);
+			}
+		}
+		break;
+
+	case SG_TREND_STRING_Formula_Parameters:
+		s	+= m_Formula.Get_Formula().c_str();
+		s	+= SG_T("\n");
+
+		if( m_Params.m_Count > 0 )
+		{
+			s	+= SG_T("\n");
+
+			for(i=0; i<m_Params.m_Count && m_bOkay; i++)
+			{
+				s	+= CSG_String::Format(SG_T("%c = %g\n"), m_Params.m_Variables[i], m_Params.m_A[i]);
+			}
+		}
+		break;
+
+	case SG_TREND_STRING_Complete:
+		s	+= m_Formula.Get_Formula().c_str();
+		s	+= SG_T("\n");
+
+		if( m_Params.m_Count > 0 )
+		{
+			s	+= SG_T("\n");
+
+			for(i=0; i<m_Params.m_Count && m_bOkay; i++)
+			{
+				s	+= CSG_String::Format(SG_T("%c = %g\n"), m_Params.m_Variables[i], m_Params.m_A[i]);
+			}
+		}
+
+		s	+= SG_T("\n");
+		s	+= CSG_String::Format(SG_T("N = %d\n") , Get_Data_Count());
+		s	+= CSG_String::Format(SG_T("R2 = %g\n"), Get_R2() * 100.0);
+		break;
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+double CSG_Trend::Get_ChiSquare(void)
+{
+	if( m_bOkay )
+	{
+//		return( sqrt(m_ChiSqr / m_Data.Get_Count()) );	// RMS of Residuals (stdfit)
+		return( m_ChiSqr );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Trend::Get_R2(void)
+{
+	if( m_bOkay )
+	{
+		return( m_ChiSqr_o );
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Trend::Get_Value(double x)
+{
+	if( m_bOkay )
+	{
+		return( m_Formula.Get_Value(x) );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Trend::_Fit_Function(void)
+{
+	int		i, j;
+
+	//-----------------------------------------------------
+	for(i=0; i<m_Params.m_Count; i++)
+	{
+		for(j=0; j<m_Params.m_Count; j++)
+		{
+			m_Params.m_Covar[i][j]	= m_Params.m_Alpha[i][j];
+		}
+
+		m_Params.m_Covar[i][i]	= m_Params.m_Alpha[i][i] * (1.0 + m_Lambda);
+		m_Params.m_dA2  [i]		= m_Params.m_Beta [i];
+	}
+
+	//-----------------------------------------------------
+	if( _Get_Gaussj() == false )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	for(i=0; i<m_Params.m_Count; i++)
+	{
+		m_Params.m_dA[i]	= m_Params.m_dA2[i];
+	}
+
+	//-----------------------------------------------------
+	if( m_Lambda == 0.0 )
+	{
+		double	temp;
+
+		for(i=m_Params.m_Count-1; i>0; i--)
+		{
+			for(j=0; j<m_Params.m_Count; j++)
+			{
+				SWAP(m_Params.m_Covar[j][i], m_Params.m_Covar[j][i-1]);
+			}
+
+			for(j=0; j<m_Params.m_Count; j++)
+			{
+				SWAP(m_Params.m_Covar[i][j], m_Params.m_Covar[i-1][j]);
+			}
+		}
+	}
+	else
+	{
+		for(i=0; i<m_Params.m_Count; i++)
+		{
+			m_Params.m_Atry[i]	= m_Params.m_A[i] + m_Params.m_dA[i];
+		}
+
+		_Get_mrqcof(m_Params.m_Atry, m_Params.m_Covar, m_Params.m_dA);
+
+		if( m_ChiSqr < m_ChiSqr_o )
+		{
+			m_Lambda	*= 0.1;
+			m_ChiSqr_o	 = m_ChiSqr;
+
+			for(i=0; i<m_Params.m_Count; i++)
+			{
+				for(j=0; j<m_Params.m_Count; j++)
+				{
+					m_Params.m_Alpha[i][j]	= m_Params.m_Covar[i][j];
+				}
+
+				m_Params.m_Beta[i]	= m_Params.m_dA[i];
+			}
+
+			for(i=0; i<m_Params.m_Count; i++)	// Achtung!! in aelteren Versionen war hier ein Fehler
+			{
+				m_Params.m_A[i]		= m_Params.m_Atry[i];
+			}
+		}
+		else 
+		{
+			m_Lambda	*= 10.0;
+			m_ChiSqr	 = m_ChiSqr_o;
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::_Get_Gaussj(void)
+{
+	int		i, j, k, iCol, iRow, *indxc, *indxr, *ipiv;
+	double	big, pivinv, temp;
+
+	//-----------------------------------------------------
+	indxc	= (int *)SG_Calloc(m_Params.m_Count, sizeof(int));
+	indxr	= (int *)SG_Calloc(m_Params.m_Count, sizeof(int));
+	ipiv	= (int *)SG_Calloc(m_Params.m_Count, sizeof(int));
+	
+	for(i=0; i<m_Params.m_Count; i++)
+	{
+		ipiv[i]	= 0;
+	}
+
+	//-----------------------------------------------------
+	for(i=0, iCol=-1, iRow=-1; i<m_Params.m_Count; i++)
+	{
+		for(j=0, big=0.0; j<m_Params.m_Count; j++)
+		{
+			if( ipiv[j] != 1 )
+			{
+				for(k=0; k<m_Params.m_Count; k++)
+				{
+					if( ipiv[k] == 0 )
+					{
+						if( fabs(m_Params.m_Covar[j][k]) >= big )
+						{
+							big		= fabs(m_Params.m_Covar[j][k]);
+							iRow	= j;
+							iCol	= k;
+						}
+					}
+					else if( ipiv[k] > 1 )
+					{
+						SG_Free(indxc);	SG_Free(indxr);	SG_Free(ipiv);	return( false );	// singular matrix...
+					}
+				}
+			}
+		}
+
+		if( iCol < 0 || iRow < 0 )
+		{
+			SG_Free(indxc);	SG_Free(indxr);	SG_Free(ipiv);	return( false );	// singular matrix...
+		}
+
+		//-------------------------------------------------
+		ipiv[iCol]++;
+
+		if( iRow != iCol )
+		{
+			for(j=0; j<m_Params.m_Count; j++)
+			{
+				SWAP(m_Params.m_Covar[iRow][j], m_Params.m_Covar[iCol][j]);
+			}
+
+			SWAP(m_Params.m_dA2[iRow], m_Params.m_dA2[iCol]);
+		}
+
+		indxr[i]	= iRow;
+		indxc[i]	= iCol;
+
+		if( fabs(m_Params.m_Covar[iCol][iCol]) < 1E-300 )
+		{
+			SG_Free(indxc);	SG_Free(indxr);	SG_Free(ipiv);	return( false );	// singular matrix...
+		}
+
+		//-------------------------------------------------
+		pivinv		= 1.0 / m_Params.m_Covar[iCol][iCol];
+		m_Params.m_Covar[iCol][iCol]	= 1.0;
+
+		for(j=0; j<m_Params.m_Count; j++)
+		{
+			m_Params.m_Covar[iCol][j]	*= pivinv;
+		}
+
+		m_Params.m_dA2[iCol]	*= pivinv;
+
+		for(j=0; j<m_Params.m_Count; j++)
+		{
+			if( j != iCol )
+			{
+				temp	= m_Params.m_Covar[j][iCol];
+				m_Params.m_Covar[j][iCol]	= 0.0;
+
+				for(k=0; k<m_Params.m_Count; k++)
+				{
+					m_Params.m_Covar[j][k]	-= m_Params.m_Covar[iCol][k] * temp;
+				}
+
+				m_Params.m_dA2[j]	-= m_Params.m_dA2[iCol] * temp;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(i=m_Params.m_Count-1; i>=0; i--)
+	{
+        if( indxr[i] != indxc[i] )
+		{
+			for(j=0; j<m_Params.m_Count; j++)
+			{
+				SWAP(m_Params.m_Covar[j][indxr[i]], m_Params.m_Covar[j][indxc[i]]);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	SG_Free(indxc);
+	SG_Free(indxr);
+	SG_Free(ipiv);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Trend::_Get_mrqcof(double *Parameters, double **Alpha, double *Beta)
+{
+	int		i, j, k;
+	double	y, dy, *dy_da;
+
+	//-----------------------------------------------------
+	for(i=0; i<m_Params.m_Count; i++)
+	{
+		for(j=0; j<=i; j++)
+		{
+			Alpha[i][j] = 0.0;
+		}
+
+		Beta[i]		= 0.0;
+	}
+
+	//-----------------------------------------------------
+	dy_da	= (double *)SG_Calloc(m_Params.m_Count, sizeof(double));
+
+	for(k=0, m_ChiSqr=0.0; k<m_Data.Get_Count(); k++)
+	{
+		_Get_Function(m_Data[k].x, Parameters, y, dy_da);
+
+		dy	= m_Data[k].y - y;
+
+		for(i=0; i<m_Params.m_Count; i++)
+		{
+			for(j=0; j<=i; j++)
+			{
+				Alpha[i][j]	+= dy_da[i] * dy_da[j];
+			}
+
+			Beta[i]		+= dy * dy_da[i];
+		}
+
+		m_ChiSqr	+= dy * dy;
+	}
+
+	SG_Free(dy_da);
+
+	//-----------------------------------------------------
+	for(i=1; i<m_Params.m_Count; i++)
+	{
+		for(j=0; j<i; j++)
+		{
+			Alpha[j][i]	= Alpha[i][j];
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Trend::_Get_Function(double x, double *Parameters, double &y, double *dy_da)
+{
+	int		i;
+
+	//-----------------------------------------------------
+	for(i=0; i<m_Params.m_Count; i++)
+	{
+		m_Formula.Set_Variable(m_Params.m_Variables[i], Parameters[i]);
+	}
+
+	y	= m_Formula.Get_Value(x);
+
+	//-----------------------------------------------------
+	for(i=0; i<m_Params.m_Count; i++)
+	{
+		m_Formula.Set_Variable(m_Params.m_Variables[i], Parameters[i] + EPSILON);
+
+		dy_da[i]	 = m_Formula.Get_Value(x);
+		dy_da[i]	-= y;
+		dy_da[i]	/= EPSILON;
+
+		m_Formula.Set_Variable(m_Params.m_Variables[i], Parameters[i] - EPSILON);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,583 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     metadata.cpp                      //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/xml/xml.h>
+#include <wx/wfstream.h>
+
+#include "metadata.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_MetaData::CSG_MetaData(void)
+{
+	_On_Construction();
+}
+
+bool CSG_MetaData::Create(void)
+{
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_MetaData::CSG_MetaData(const CSG_MetaData &MetaData)
+{
+	_On_Construction();
+
+	Create(MetaData);
+}
+
+bool CSG_MetaData::Create(const CSG_MetaData &MetaData)
+{
+	return( Assign(MetaData) );
+}
+
+//---------------------------------------------------------
+CSG_MetaData::CSG_MetaData(const CSG_String &File, const SG_Char *Extension)
+{
+	_On_Construction();
+
+	Create(File, Extension);
+}
+
+bool CSG_MetaData::Create(const CSG_String &File, const SG_Char *Extension)
+{
+	return( Load(File, Extension) );
+}
+
+//---------------------------------------------------------
+CSG_MetaData::CSG_MetaData(CSG_MetaData *pParent)
+{
+	_On_Construction();
+
+	m_pParent	= pParent;
+}
+
+//---------------------------------------------------------
+void CSG_MetaData::_On_Construction(void)
+{
+	m_pParent	= NULL;
+	m_pChildren	= NULL;
+	m_nChildren	= 0;
+	m_nBuffer	= 0;
+}
+
+//---------------------------------------------------------
+CSG_MetaData::~CSG_MetaData(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+void CSG_MetaData::Destroy(void)
+{
+	if( m_pChildren )
+	{
+		for(int i=0; i<m_nChildren; i++)
+		{
+			delete(m_pChildren[i]);
+		}
+
+		SG_Free(m_pChildren);
+
+		m_pChildren	= NULL;
+		m_nChildren	= 0;
+		m_nBuffer	= 0;
+	}
+
+//	m_pParent	= NULL;
+
+//	m_Name			.Clear();
+//	m_Content		.Clear();
+
+	m_Prop_Names	.Clear();
+	m_Prop_Values	.Clear();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_GROW_SIZE(n)	(n < 64 ? 1 : (n < 1024 ? 32 : 256))
+
+//---------------------------------------------------------
+CSG_MetaData * CSG_MetaData::Add_Child(void)
+{
+	if( (m_nChildren + 1) >= m_nBuffer )
+	{
+		CSG_MetaData	**pChildren	= (CSG_MetaData **)SG_Realloc(m_pChildren, (m_nBuffer + GET_GROW_SIZE(m_nBuffer)) * sizeof(CSG_MetaData *));
+
+		if( pChildren )
+		{
+			m_pChildren	= pChildren;
+			m_nBuffer	+= GET_GROW_SIZE(m_nBuffer);
+		}
+		else
+		{
+			return( false );
+		}
+	}
+
+	return( m_pChildren[m_nChildren++]	= new CSG_MetaData(this) );
+}
+
+CSG_MetaData * CSG_MetaData::Add_Child(const CSG_String &Name, double Content)
+{
+	return( Add_Child(Name, CSG_String::Format(SG_T("%f"), Content)) );
+}
+
+CSG_MetaData * CSG_MetaData::Add_Child(const CSG_String &Name, int Content)
+{
+	return( Add_Child(Name, CSG_String::Format(SG_T("%d"), Content)) );
+}
+
+//---------------------------------------------------------
+CSG_MetaData * CSG_MetaData::Add_Child(const CSG_String &Name, const SG_Char *Content)
+{
+	CSG_MetaData	*pChild	= Add_Child();
+
+	if( pChild )
+	{
+		pChild->m_Name		= Name;
+		pChild->m_Content	= Content ? Content : SG_T("");
+	}
+
+	return( pChild );
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Del_Child(int Index)
+{
+	if( Index >= 0 && Index < m_nChildren )
+	{
+		delete(m_pChildren[Index]);
+
+		m_nChildren--;
+
+		if( (m_nChildren - 1) < m_nBuffer - GET_GROW_SIZE(m_nBuffer) )
+		{
+			CSG_MetaData	**pChildren	= (CSG_MetaData **)SG_Realloc(m_pChildren, (m_nBuffer - GET_GROW_SIZE(m_nBuffer)) * sizeof(CSG_MetaData *));
+
+			if( pChildren )
+			{
+				m_pChildren	= pChildren;
+				m_nBuffer	-= GET_GROW_SIZE(m_nBuffer);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+int CSG_MetaData::_Get_Child(const CSG_String &Name) const
+{
+	for(int i=0; i<m_nChildren; i++)
+	{
+		if( Name.CmpNoCase(m_pChildren[i]->Get_Name()) == 0 )
+		{
+			return( i );
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_MetaData::Set_Content(const SG_Char *Format, ...)
+{
+	wxString	s;
+	va_list		argptr;
+
+	va_start(argptr, Format);
+
+	if( s.PrintfV(Format, argptr) > 0 )
+	{
+		m_Content	= s.c_str();
+	}
+	else
+	{
+		m_Content.Clear();
+	}
+
+	va_end(argptr);
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Cmp_Content(const CSG_String &String, bool bNoCase) const
+{
+	return( bNoCase ? !m_Content.CmpNoCase(String) : !m_Content.Cmp(String) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_MetaData::Add_Property(const CSG_String &Name, const CSG_String &Value)
+{
+	if( _Get_Property(Name) < 0 )
+	{
+		m_Prop_Names	.Add(Name);
+		m_Prop_Values	.Add(Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_MetaData::Add_Property(const CSG_String &Name, double Value)
+{
+	return( Add_Property(Name, CSG_String::Format(SG_T("%f"), Value)) );
+}
+
+bool CSG_MetaData::Add_Property(const CSG_String &Name, int Value)
+{
+	return( Add_Property(Name, CSG_String::Format(SG_T("%d"), Value)) );
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Set_Property(const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists)
+{
+	int		Index;
+
+	if( (Index = _Get_Property(Name)) >= 0 )
+	{
+		m_Prop_Values[Index]	= Value;
+
+		return( true );
+	}
+	else if( bAddIfNotExists )
+	{
+		m_Prop_Names	.Add(Name);
+		m_Prop_Values	.Add(Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_MetaData::Set_Property(const CSG_String &Name, double Value, bool bAddIfNotExists)
+{
+	return( Set_Property(Name, CSG_String::Format(SG_T("%f"), Value, bAddIfNotExists)) );
+}
+
+bool CSG_MetaData::Set_Property(const CSG_String &Name, int Value, bool bAddIfNotExists)
+{
+	return( Set_Property(Name, CSG_String::Format(SG_T("%d"), Value, bAddIfNotExists)) );
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Get_Property(const CSG_String &Name, CSG_String &Value)	const
+{
+	const SG_Char	*cString	= Get_Property(Name);
+
+	if( cString )
+	{
+		Value	= cString;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_MetaData::Get_Property(const CSG_String &Name, double &Value)	const
+{
+	CSG_String	s;
+
+	return( Get_Property(Name, s) && s.asDouble(Value) );
+}
+
+bool CSG_MetaData::Get_Property(const CSG_String &Name, int &Value)	const
+{
+	CSG_String	s;
+
+	return( Get_Property(Name, s) && s.asInt(Value) );
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Cmp_Property(const CSG_String &Name, const CSG_String &String, bool bNoCase) const
+{
+	CSG_String	s;
+
+	return( Get_Property(Name, s) && (bNoCase ? !s.CmpNoCase(String) : !s.Cmp(String)) );
+}
+
+//---------------------------------------------------------
+int CSG_MetaData::_Get_Property(const CSG_String &Name) const
+{
+	for(int i=0; i<m_Prop_Names.Get_Count(); i++)
+	{
+		if( Name.CmpNoCase(m_Prop_Names[i]) == 0 )
+		{
+			return( i );
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_MetaData::Assign(const CSG_MetaData &MetaData, bool bAppend)
+{
+	int		i;
+
+	if( !bAppend )
+	{
+		Destroy();
+
+		Set_Name	(MetaData.Get_Name   ());
+		Set_Content	(MetaData.Get_Content());
+
+		//-------------------------------------------------
+		for(i=0; i<MetaData.Get_Property_Count(); i++)
+		{
+			Add_Property(MetaData.Get_Property_Name(i), MetaData.Get_Property(i));
+		}
+	}
+
+	//-----------------------------------------------------
+	for(i=0; i<MetaData.Get_Children_Count(); i++)
+	{
+		Add_Child()->Assign(*MetaData.Get_Child(i), false);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_MetaData::Load(const CSG_String &File, const SG_Char *Extension)
+{
+	Destroy();
+
+	wxXmlDocument	XML;
+
+	if( SG_File_Exists(SG_File_Make_Path(NULL, File, Extension)) && XML.Load(SG_File_Make_Path(NULL, File, Extension).c_str()) )
+	{
+		_Load(XML.GetRoot());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Load(CSG_File &File)
+{
+	Destroy();
+
+	wxXmlDocument	XML;
+
+	wxFFileInputStream	Stream(File.Get_Stream());
+
+	if( Stream.IsOk() && XML.Load(Stream) )
+	{
+		_Load(XML.GetRoot());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_MetaData::_Load(wxXmlNode *pNode)
+{
+	Set_Name	(SG_UTF8_To_String(pNode->GetName       ()).c_str());
+	Set_Content	(SG_UTF8_To_String(pNode->GetNodeContent()).c_str());
+
+	//-----------------------------------------------------
+	wxXmlProperty	*pProperty	= pNode->GetProperties();
+
+	while( pProperty )
+	{
+		Add_Property(SG_UTF8_To_String(pProperty->GetName()).c_str(), SG_UTF8_To_String(pProperty->GetValue()).c_str());
+
+		pProperty	= pProperty->GetNext();
+	}
+
+	//-----------------------------------------------------
+	wxXmlNode	*pChild	= pNode->GetChildren();
+
+	while( pChild )
+	{
+		if( pChild->GetType() != wxXML_TEXT_NODE )
+		{
+			Add_Child()->_Load(pChild);
+		}
+
+		pChild	= pChild->GetNext();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_MetaData::Save(const CSG_String &File, const SG_Char *Extension) const
+{
+	wxXmlDocument	XML;
+
+	wxXmlNode	*pRoot	= new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Get_Name().c_str());
+
+	XML.SetRoot(pRoot);
+
+	_Save(pRoot);
+
+	if( XML.Save(SG_File_Make_Path(NULL, File, Extension).c_str()) )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_MetaData::Save(CSG_File &File) const
+{
+	wxXmlDocument	XML;
+
+	wxXmlNode	*pRoot	= new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Get_Name().c_str());
+
+	XML.SetRoot(pRoot);
+
+	_Save(pRoot);
+
+	wxFFileOutputStream	Stream(File.Get_Stream());
+
+	if( Stream.IsOk() && XML.Save(Stream) )
+	{
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_MetaData::_Save(wxXmlNode *pNode) const
+{
+	int		i;
+
+	pNode->SetName	 (Get_Name().Length() ? SG_String_To_UTF8(Get_Name()).c_str() : SG_T("NODE"));
+	pNode->SetContent(SG_String_To_UTF8(Get_Content()).c_str());
+
+	if( Get_Content().Length() > 0 )
+	{
+		wxXmlNode	*pChild	= new wxXmlNode(pNode, wxXML_TEXT_NODE, SG_T("TEXT"));// SG_String_To_UTF8(Get_Name()).c_str());
+
+		pChild->SetContent(SG_String_To_UTF8(Get_Content()).c_str());
+	}
+
+	//-----------------------------------------------------
+	for(i=0; i<Get_Property_Count(); i++)
+	{
+		pNode->AddProperty(SG_String_To_UTF8(Get_Property_Name(i)).c_str(), SG_String_To_UTF8(Get_Property(i)).c_str());
+	}
+
+	//-----------------------------------------------------
+	for(i=Get_Children_Count()-1; i>=0; i--)
+	{
+		if( Get_Child(i)->Get_Content().Length() > 0 || Get_Child(i)->Get_Children_Count() > 0 )
+		{
+			wxXmlNode	*pChild	= new wxXmlNode(pNode, wxXML_ELEMENT_NODE, SG_String_To_UTF8(Get_Child(i)->Get_Name()).c_str());
+
+			Get_Child(i)->_Save(pChild);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/metadata.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,176 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      metadata.h                       //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__metadata_H
+#define HEADER_INCLUDED__SAGA_API__metadata_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_MetaData
+{
+public:
+								CSG_MetaData		(void);
+	bool						Create				(void);
+
+								CSG_MetaData		(const CSG_MetaData &MetaData);
+	bool						Create				(const CSG_MetaData &MetaData);
+
+								CSG_MetaData		(const CSG_String &File, const SG_Char *Extension = NULL);
+	bool						Create				(const CSG_String &File, const SG_Char *Extension = NULL);
+
+								CSG_MetaData		(CSG_File &File);
+	bool						Create				(CSG_File &File);
+
+	virtual						~CSG_MetaData		(void);
+	void						Destroy				(void);
+
+	bool						Load				(const CSG_String &File, const SG_Char *Extension = NULL);
+	bool						Save				(const CSG_String &File, const SG_Char *Extension = NULL)	const;
+
+	bool						Load				(CSG_File &Stream);
+	bool						Save				(CSG_File &Stream)			const;
+
+	bool						Assign				(const CSG_MetaData &MetaData, bool bAppend = false);
+	CSG_MetaData &				operator  =			(const CSG_MetaData &MetaData)		{	Assign(MetaData, false);	return( *this );	}
+	CSG_MetaData &				operator +=			(const CSG_MetaData &MetaData)		{	Assign(MetaData, true );	return( *this );	}
+
+
+	const CSG_String &			Get_Name			(void)						const	{	return( m_Name );		}
+	void						Set_Name			(const CSG_String &Name)			{	m_Name		= Name;		}
+	const CSG_String &			Get_Content			(void)						const	{	return( m_Content );	}
+	void						Set_Content			(const CSG_String &Content)			{	m_Content	= Content;	}
+	void						Set_Content			(const SG_Char *Format, ...);
+	bool						Cmp_Content			(const CSG_String &String, bool bNoCase = false)	const;
+
+	int							Get_Children_Count	(void)						const	{	return( m_nChildren );	}
+	CSG_MetaData *				Get_Child			(int Index)					const	{	return( Index >= 0 && Index < m_nChildren ? m_pChildren[Index] : NULL );	}
+	CSG_MetaData *				Get_Child			(const CSG_String &Name)	const	{	return( Get_Child(_Get_Child(Name)) );	}
+	CSG_MetaData *				Add_Child			(void);
+	CSG_MetaData *				Add_Child			(const CSG_String &Name, const SG_Char *Content = NULL);
+	CSG_MetaData *				Add_Child			(const CSG_String &Name, double         Content);
+	CSG_MetaData *				Add_Child			(const CSG_String &Name, int            Content);
+	bool						Del_Child			(int Index);
+	bool						Del_Child			(const CSG_String &Name)			{	return( Del_Child(_Get_Child(Name)) );	}
+
+	int							Get_Property_Count	(void)						const	{	return( m_Prop_Names.Get_Count() );	}
+	const CSG_String &			Get_Property_Name	(int i)						const	{	return( m_Prop_Names [i] );			}
+	const SG_Char *				Get_Property		(int i)						const	{	return( i >= 0 && i < m_Prop_Values.Get_Count() ? m_Prop_Values[i].c_str() : NULL );	}
+	const SG_Char *				Get_Property		(const CSG_String &Name)	const	{	return( Get_Property(_Get_Property(Name)) );	}
+	bool						Get_Property		(const CSG_String &Name, CSG_String &Value)	const;
+	bool						Get_Property		(const CSG_String &Name, double     &Value)	const;
+	bool						Get_Property		(const CSG_String &Name, int        &Value)	const;
+	bool						Add_Property		(const CSG_String &Name, const CSG_String &Value);
+	bool						Add_Property		(const CSG_String &Name, double            Value);
+	bool						Add_Property		(const CSG_String &Name, int               Value);
+	bool						Set_Property		(const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists = true);
+	bool						Set_Property		(const CSG_String &Name, double            Value, bool bAddIfNotExists = true);
+	bool						Set_Property		(const CSG_String &Name, int               Value, bool bAddIfNotExists = true);
+	bool						Cmp_Property		(const CSG_String &Name, const CSG_String &String, bool bNoCase = false)	const;
+
+
+private:
+
+	CSG_MetaData(CSG_MetaData *pParent);
+
+
+	int							m_nChildren, m_nBuffer;
+
+	CSG_MetaData				**m_pChildren, *m_pParent;
+
+	CSG_String					m_Name, m_Content;
+
+	CSG_Strings					m_Prop_Names, m_Prop_Values;
+
+
+	void						_On_Construction	(void);
+
+	int							_Get_Child			(const CSG_String &Name)	const;
+	int							_Get_Property		(const CSG_String &Name)	const;
+
+	void						_Load				(class wxXmlNode *pNode);
+	void						_Save				(class wxXmlNode *pNode)	const;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__metadata_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,691 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      module.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module::CSG_Module(void)
+{
+	m_bError_Ignore	= false;
+	m_bExecutes		= false;
+
+	m_Garbage		= NULL;
+	m_nGarbage		= 0;
+
+	m_pParameters	= NULL;
+	m_npParameters	= 0;
+
+	Parameters.Create(this, SG_T(""), SG_T(""));
+	Parameters.Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
+
+	Set_Managed			(false);
+	Set_Show_Progress	(true);
+}
+
+//---------------------------------------------------------
+CSG_Module::~CSG_Module(void)
+{
+	if( m_pParameters )
+	{
+		for(int i=0; i<m_npParameters; i++)
+		{
+			delete(m_pParameters[i]);
+		}
+
+		SG_Free(m_pParameters);
+	}
+
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module::Destroy(void)
+{
+	m_bError_Ignore	= false;
+
+	History_Supplement.Destroy();
+
+	Garbage_Clear();
+
+	if( m_bManaged )
+	{
+		SG_UI_Process_Set_Okay();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module::Set_Name(const SG_Char *String)
+{
+	Parameters.Set_Name(String);
+}
+
+const SG_Char * CSG_Module::Get_Name(void)
+{
+	return( Parameters.Get_Name() );
+}
+
+//---------------------------------------------------------
+void CSG_Module::Set_Description(const SG_Char *String)
+{
+	Parameters.Set_Description(String);
+}
+
+const SG_Char * CSG_Module::Get_Description(void)
+{
+	return( Parameters.Get_Description() );
+}
+
+//---------------------------------------------------------
+void CSG_Module::Set_Author(const SG_Char *String)
+{
+	if( String )
+	{
+		m_Author.Printf(String);
+	}
+	else
+	{
+		m_Author.Clear();
+	}
+}
+
+const SG_Char * CSG_Module::Get_Author(void)
+{
+	return( m_Author.c_str() );
+}
+
+//---------------------------------------------------------
+void CSG_Module::Set_Translation(CSG_Translator &Translator)
+{
+	Parameters.Set_Translation(Translator);
+
+	for(int i=0; i<m_npParameters; i++)
+	{
+		m_pParameters[i]->Set_Translation(Translator);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module::Execute(void)
+{
+	bool	bResult	= false;
+
+	if( m_bExecutes == false )
+	{
+		m_bExecutes		= true;
+
+		if( Parameters.DataObjects_Check() )
+		{
+			Destroy();
+
+			Parameters.DataObjects_Create();
+			Parameters.Msg_String(false);
+
+///////////////////////////////////////////////////////////
+#if !defined(_DEBUG) && defined(_SAGA_VC)
+#define _MODULE_EXCEPTION
+__try
+{
+#endif
+///////////////////////////////////////////////////////////
+
+			if( (bResult = On_Execute()) == true )
+			{
+				_Set_Output_History();
+			}
+
+			if( !Process_Get_Okay(false) )
+			{
+				SG_UI_Msg_Add(LNG("[MSG] Execution has been stopped by user!"), true);
+			}
+
+///////////////////////////////////////////////////////////
+#ifdef _MODULE_EXCEPTION
+}	// try
+__except(1)
+{
+	Message_Add(LNG("[ERR] Module caused access violation!"));
+	Message_Dlg(LNG("[ERR] Module caused access violation!"));
+	bResult	= false;
+}	// except(1)
+#endif
+///////////////////////////////////////////////////////////
+
+			Destroy();
+
+			Parameters.DataObjects_Synchronize();
+		}
+
+		m_bExecutes		= false;
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module::Set_Managed(bool bOn)
+{
+	m_bManaged	= Parameters.m_bManaged	= bOn;
+
+	for(int i=0; i<m_npParameters; i++)
+	{
+		m_pParameters[i]->m_bManaged	= bOn;
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Module::Set_Show_Progress(bool bOn)
+{
+	m_bShow_Progress	= bOn;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Parameters						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Module::_On_Parameter_Changed(CSG_Parameter *pParameter)
+{
+	if( pParameter && pParameter->Get_Owner() && pParameter->Get_Owner()->Get_Owner() )
+	{
+		return( ((CSG_Module *)pParameter->Get_Owner()->Get_Owner())->
+			On_Parameter_Changed(pParameter->Get_Owner(), pParameter)
+		);
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Module::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Extra Parameters					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameters * CSG_Module::Add_Parameters(const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameters	*pParameters;
+
+	m_pParameters	= (CSG_Parameters **)SG_Realloc(m_pParameters, (m_npParameters + 1) * sizeof(CSG_Parameters *));
+	pParameters		= m_pParameters[m_npParameters++]	= new CSG_Parameters();
+
+	pParameters->Create(this, Name, Description, Identifier);
+	pParameters->Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
+
+	return( pParameters );
+}
+
+//---------------------------------------------------------
+CSG_Parameters * CSG_Module::Get_Parameters(const SG_Char *Identifier)
+{
+	CSG_String	sIdentifier(Identifier);
+
+	for(int i=0; i<m_npParameters; i++)
+	{
+		if( !sIdentifier.Cmp(m_pParameters[i]->Get_Identifier()) )
+		{
+			return( m_pParameters[i] );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Dlg_Parameters(const SG_Char *Identifier)
+{
+	if( !m_bManaged || Dlg_Parameters(Get_Parameters(Identifier), Get_Name()) )
+	{
+		Get_Parameters(Identifier)->Set_History(History_Supplement);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Dlg_Parameters(CSG_Parameters *pParameters, const SG_Char *Caption)
+{
+	return( SG_UI_Dlg_Parameters(pParameters, Caption) );
+}
+
+//---------------------------------------------------------
+#ifdef _SAGA_UNICODE
+
+CSG_Parameters *	CSG_Module::Add_Parameters(const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_Parameters(CSG_String(Identifier), Name, Description) );	}
+
+CSG_Parameters *	CSG_Module::Get_Parameters(const char *Identifier)
+{	return( Get_Parameters(CSG_String(Identifier)) );	}
+
+bool				CSG_Module::Dlg_Parameters(const char *Identifier)
+{	return( Dlg_Parameters(CSG_String(Identifier)) );	}
+
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Progress						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module::Process_Get_Okay(bool bBlink)
+{
+	return( SG_UI_Process_Get_Okay(bBlink) );
+}
+
+//---------------------------------------------------------
+void CSG_Module::Process_Set_Text(const SG_Char *Text)
+{
+	SG_UI_Process_Set_Text(Text);
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Set_Progress(int Position)
+{
+	return( Set_Progress(Position, 100.0) );
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Set_Progress(double Position, double Range)
+{
+	return( m_bShow_Progress ? SG_UI_Process_Set_Progress(Position, Range) : Process_Get_Okay(false) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Message							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module::Message_Dlg(const SG_Char *Text, const SG_Char *Caption)
+{
+	SG_UI_Dlg_Message(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name());
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Message_Dlg_Confirm(const SG_Char *Text, const SG_Char *Caption)
+{
+	return( SG_UI_Dlg_Continue(Text, Caption && Caption[0] != '\0' ? Caption : Get_Name()) );
+}
+
+//---------------------------------------------------------
+void CSG_Module::Message_Add(const SG_Char *Text, bool bNewLine)
+{
+	SG_UI_Msg_Add_Execution(Text, bNewLine);
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Error_Set(TSG_Module_Error Error_ID)
+{
+	switch( Error_ID )
+	{
+	default:
+		return( Error_Set(LNG("[ERR] Unknown Error")) );
+	    
+	case MODULE_ERROR_Calculation:
+		return( Error_Set(LNG("[ERR] Calculation Error")) );
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Module::Error_Set(const SG_Char *Error_Text)
+{
+	SG_UI_Msg_Add_Error(Error_Text);
+
+	if( SG_UI_Process_Get_Okay(false) && !m_bError_Ignore )
+	{
+		switch( SG_UI_Dlg_Error(Error_Text, LNG("[ERR] Error: Continue anyway ?")) )
+		{
+		case 0: default:
+			SG_UI_Process_Set_Okay(false);
+			break;
+
+		case 1:
+			m_bError_Ignore	= true;
+			break;
+		}
+	}
+
+	return( SG_UI_Process_Get_Okay(false) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				DataObjects / Garbage					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module::_Garbage_Add_Item(CSG_Data_Object *pDataObject)
+{
+	if( pDataObject )
+	{
+		for(int i=0; i<m_nGarbage; i++)
+		{
+			if( pDataObject == m_Garbage[i] )
+			{
+				return( true );
+			}
+		}
+
+		m_Garbage	= (CSG_Data_Object **)SG_Realloc(m_Garbage, (m_nGarbage + 1) * sizeof(CSG_Data_Object *));
+		m_Garbage[m_nGarbage++]	= pDataObject;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Data_Object * CSG_Module::Garbage_Del_Item(int i, bool bFromListOnly)
+{
+	CSG_Data_Object	*pDataObject	= NULL;
+
+	if( i >= 0 && i < m_nGarbage )
+	{
+		if( bFromListOnly || !m_Garbage[i] )
+		{
+			pDataObject	= m_Garbage[i];
+		}
+		else if( m_Garbage[i] )
+		{
+			delete(m_Garbage[i]);
+		}
+
+		for(m_nGarbage--; i<m_nGarbage; i++)
+		{
+			m_Garbage[i]	= m_Garbage[i + 1];
+		}
+
+		m_Garbage	= (CSG_Data_Object **)SG_Realloc(m_Garbage, m_nGarbage * sizeof(CSG_Data_Object *));
+	}
+
+	return( pDataObject );
+}
+
+//---------------------------------------------------------
+void CSG_Module::Garbage_Clear(void)
+{
+	if( m_nGarbage > 0 )
+	{
+		for(int i=0; i<m_nGarbage; i++)
+		{
+			if( m_Garbage[i] )
+			{
+				delete(m_Garbage[i]);
+			}
+		}
+
+		SG_Free(m_Garbage);
+	}
+
+	m_nGarbage	= 0;
+	m_Garbage	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				DataObjects / GUI Interaction			 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module::DataObject_Add(CSG_Data_Object *pDataObject, bool bUpdate)
+{
+	return( m_bManaged && SG_UI_DataObject_Add(pDataObject, bUpdate)
+		? true : _Garbage_Add_Item(pDataObject)
+	);
+}
+
+//---------------------------------------------------------
+bool CSG_Module::DataObject_Update(CSG_Data_Object *pDataObject, int Show)
+{
+	return( SG_UI_DataObject_Update(pDataObject, Show, NULL) );
+}
+
+bool CSG_Module::DataObject_Update(CSG_Data_Object *pDataObject, double Parm_1, double Parm_2, int Show)
+{
+	CSG_Parameters	Parameters;
+
+	if( pDataObject )
+	{
+		switch( pDataObject->Get_ObjectType() )
+		{
+		default:
+			break;
+
+		case DATAOBJECT_TYPE_Grid:
+			Parameters.Add_Range(NULL, SG_T("METRIC_ZRANGE"), SG_T(""), SG_T(""),
+				Parm_1 * ((CSG_Grid *)pDataObject)->Get_ZFactor(),
+				Parm_2 * ((CSG_Grid *)pDataObject)->Get_ZFactor()
+			);
+			break;
+		}
+
+		return( SG_UI_DataObject_Update(pDataObject, Show, &Parameters) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Module::DataObject_Update_All(void)
+{
+	for(int i=0; i<Parameters.Get_Count(); i++)
+	{
+		if( Parameters(i)->is_Output() )
+		{
+			if( Parameters(i)->is_DataObject() )
+			{
+				DataObject_Update(Parameters(i)->asDataObject(), false);
+			}
+			else if( Parameters(i)->is_DataObject_List() )
+			{
+				for(int j=0; j<Parameters(i)->asList()->Get_Count(); j++)
+				{
+					DataObject_Update(Parameters(i)->asList()->asDataObject(j), false);
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Module::DataObject_Get_Colors(CSG_Data_Object *pDataObject, CSG_Colors &Colors)
+{
+	return( SG_UI_DataObject_Colors_Get(pDataObject, &Colors) );
+}
+
+bool CSG_Module::DataObject_Set_Colors(CSG_Data_Object *pDataObject, const CSG_Colors &Colors)
+{
+	CSG_Colors	c(Colors);
+
+	return( SG_UI_DataObject_Colors_Set(pDataObject, &c) );
+}
+
+bool CSG_Module::DataObject_Set_Colors(CSG_Data_Object *pDataObject, int nColors, int Palette, bool bRevert)
+{
+	CSG_Colors	c(nColors, Palette, bRevert);
+
+	return( SG_UI_DataObject_Colors_Set(pDataObject, &c) );
+}
+
+//---------------------------------------------------------
+bool CSG_Module::DataObject_Get_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
+{
+	return( SG_UI_DataObject_Params_Get(pDataObject, &Parameters) );
+}
+
+bool CSG_Module::DataObject_Set_Parameters(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters)
+{
+	return( SG_UI_DataObject_Params_Set(pDataObject, &Parameters) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						History							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module::_Set_Output_History(void)
+{
+	CSG_MetaData	History;
+
+	//-----------------------------------------------------
+	History.Set_Name(SG_META_HST);
+
+	History.Add_Child(SG_T("MODULE")	, Get_Name());
+//	History.Add_Child(SG_T("LIBRARY")	, Get_Library());
+
+	Parameters.Set_History(History);
+
+	History.Assign(History_Supplement, true);
+
+	//-----------------------------------------------------
+	for(int j=-1; j<Get_Parameters_Count(); j++)
+	{
+		CSG_Parameters	*pParameters	= j < 0 ? &Parameters : Get_Parameters(j);
+
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			CSG_Parameter	*p	= pParameters->Get_Parameter(i);
+
+			if( p->is_Output() && p->is_DataObject() && p->asDataObject() )
+			{
+				p->asDataObject()->Get_History().Assign(History);
+			}
+
+			if( p->is_Output() && p->is_DataObject_List() )
+			{
+				for(int j=0; j<p->asList()->Get_Count(); j++)
+				{
+					p->asList()->asDataObject(j)->Get_History().Assign(History);
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,583 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       module.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__module_H
+#define HEADER_INCLUDED__SAGA_API__module_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Module_Type
+{
+	MODULE_TYPE_Base			= 0,
+	MODULE_TYPE_Interactive,
+	MODULE_TYPE_Grid,
+	MODULE_TYPE_Grid_Interactive
+}
+TSG_Module_Type;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Module_Error
+{
+	MODULE_ERROR_Unknown		= 0,
+	MODULE_ERROR_Calculation
+}
+TSG_Module_Error;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						CSG_Module						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Module is the base class for all executable SAGA modules.
+  * @see CSG_Parameters
+  * @see CSG_Module_Interactive
+  * @see CSG_Module_Grid
+  * @see CSG_Module_Grid_Interactive
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module
+{
+	friend class CSG_Module_Interactive_Base;
+
+public:
+
+	CSG_Module(void);
+	virtual ~CSG_Module(void);
+
+	virtual void				Destroy						(void);
+
+	virtual TSG_Module_Type		Get_Type					(void)	{	return( MODULE_TYPE_Base );	}
+
+	const SG_Char *				Get_Name					(void);
+	const SG_Char *				Get_Description				(void);
+	const SG_Char *				Get_Author					(void);
+	const SG_Char *				Get_Icon					(void)	{	return( NULL );	}
+
+	virtual const SG_Char *		Get_MenuPath				(void)	{	return( NULL );	}
+
+	int							Get_Parameters_Count		(void)	{	return( m_npParameters );	}
+	CSG_Parameters *			Get_Parameters				(void)	{	return( &Parameters );	}
+	CSG_Parameters *			Get_Parameters				(int i)	{	return( i >= 0 && i < m_npParameters ? m_pParameters[i] : NULL );	}
+	CSG_Parameters *			Get_Parameters				(const SG_Char *Identifier);
+#ifdef _SAGA_UNICODE
+	CSG_Parameters *			Get_Parameters				(const char    *Identifier);
+#endif
+
+	int							Garbage_Get_Count			(void)	{	return( m_nGarbage );		}
+	CSG_Data_Object *			Garbage_Get_Item			(int i)	{	return( i >= 0 && i < m_nGarbage ? m_Garbage[i] : NULL );	}
+	CSG_Data_Object *			Garbage_Del_Item			(int i, bool bFromListOnly = true);
+	void						Garbage_Clear				(void);
+
+	virtual bool				is_Interactive				(void)	{	return( false );	}
+	bool						is_Progress					(void)	{	return( SG_UI_Process_Get_Okay(false) );	}
+	bool						is_Executing				(void)	{	return( m_bExecutes );	}
+
+	void						Set_Translation				(CSG_Translator &Translator);
+	void						Set_Managed					(bool bOn = true);
+	void						Set_Show_Progress			(bool bOn = true);
+
+	virtual bool				On_Before_Execution			(void)	{	return( true );	}
+
+	bool						Execute						(void);
+
+
+protected:
+
+	CSG_Parameters				Parameters;
+
+	CSG_MetaData				History_Supplement;
+
+
+	//-----------------------------------------------------
+	void						Set_Name					(const SG_Char *String);
+	void						Set_Description				(const SG_Char *String);
+	void						Set_Author					(const SG_Char *String);
+
+	//-----------------------------------------------------
+	virtual bool				On_Execute					(void)	= 0;
+
+	virtual int					On_Parameter_Changed		(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+
+	//-----------------------------------------------------
+	CSG_Parameters *			Add_Parameters				(const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	bool						Dlg_Parameters				(const SG_Char *Identifier);
+	bool						Dlg_Parameters				(CSG_Parameters *pParameters, const SG_Char *Caption);
+#ifdef _SAGA_UNICODE
+	CSG_Parameters *			Add_Parameters				(const char    *Identifier, const SG_Char *Name, const SG_Char *Description);
+	bool						Dlg_Parameters				(const char    *Identifier);
+#endif
+
+
+	//-----------------------------------------------------
+	virtual bool				Process_Get_Okay			(bool bBlink = false);
+	virtual void				Process_Set_Text			(const SG_Char *Text);
+
+	virtual bool				Set_Progress				(int Position);
+	virtual bool				Set_Progress				(double Position, double Range);
+
+	void						Message_Add					(const SG_Char *Text, bool bNewLine = true);
+	void						Message_Dlg					(const SG_Char *Text, const SG_Char *Caption = NULL);
+	bool						Message_Dlg_Confirm			(const SG_Char *Text, const SG_Char *Caption = NULL);
+
+	bool						Error_Set					(TSG_Module_Error Error_ID = MODULE_ERROR_Unknown);
+	bool						Error_Set					(const SG_Char *Error_Text);
+
+
+	//-----------------------------------------------------
+	bool						DataObject_Add				(CSG_Data_Object *pDataObject, bool bUpdate = false);
+	bool						DataObject_Update			(CSG_Data_Object *pDataObject, int Show = SG_UI_DATAOBJECT_UPDATE_ONLY);
+	bool						DataObject_Update			(CSG_Data_Object *pDataObject, double Parm_1, double Parm_2, int Show = SG_UI_DATAOBJECT_UPDATE_ONLY);
+
+	void						DataObject_Update_All		(void);
+
+	bool						DataObject_Get_Colors		(CSG_Data_Object *pDataObject, CSG_Colors &Colors);
+	bool						DataObject_Set_Colors		(CSG_Data_Object *pDataObject, const CSG_Colors &Colors);
+	bool						DataObject_Set_Colors		(CSG_Data_Object *pDataObject, int nColors, int Palette = SG_COLORS_DEFAULT, bool bRevert = false);
+
+	bool						DataObject_Get_Parameters	(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters);
+	bool						DataObject_Set_Parameters	(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters);
+
+
+private:
+
+	bool						m_bExecutes, m_bError_Ignore, m_bManaged, m_bShow_Progress;
+
+	int							m_npParameters, m_nGarbage;
+
+	CSG_Data_Object				**m_Garbage;
+
+	CSG_Parameters				**m_pParameters;
+
+	CSG_String					m_Author;
+
+
+	bool						_Garbage_Add_Item			(CSG_Data_Object *pDataObject);
+
+	void						_Set_Output_History			(void);
+
+	static int					_On_Parameter_Changed		(CSG_Parameter *pParameter);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					CSG_Module_Grid						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Module_Grid.
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module_Grid : public CSG_Module
+{
+public:
+	CSG_Module_Grid(void);
+	virtual ~CSG_Module_Grid(void);
+
+	virtual TSG_Module_Type		Get_Type				(void)			{	return( MODULE_TYPE_Grid );	}
+
+	CSG_Grid_System *			Get_System				(void)			{	return( Parameters.Get_Grid_System() );	}
+
+
+protected:
+
+	virtual bool				Set_Progress			(int iRow);
+	virtual bool				Set_Progress			(double Position, double Range);
+	virtual bool				Set_Progress_NCells		(int iCell);
+
+	//-----------------------------------------------------
+	int							Get_NX					(void)						{	return( Get_System()->Get_NX() );				}
+	int							Get_NY					(void)						{	return( Get_System()->Get_NY() );				}
+	int							Get_NCells				(void)						{	return( Get_System()->Get_NCells() );			}
+	double						Get_Cellsize			(void)						{	return( Get_System()->Get_Cellsize() );			}
+	double						Get_XMin				(void)						{	return( Get_System()->Get_XMin() );				}
+	double						Get_YMin				(void)						{	return( Get_System()->Get_YMin() );				}
+	int							Get_xTo					(int Dir, int x = 0)		{	return( Get_System()->Get_xTo(Dir, x) );		}
+	int							Get_yTo					(int Dir, int y = 0)		{	return( Get_System()->Get_yTo(Dir, y) );		}
+	int							Get_xFrom				(int Dir, int x = 0)		{	return( Get_System()->Get_xFrom(Dir, x) );		}
+	int							Get_yFrom				(int Dir, int y = 0)		{	return( Get_System()->Get_yFrom(Dir, y) );		}
+	double						Get_Length				(int Dir)					{	return( Get_System()->Get_Length(Dir) );		}
+	double						Get_UnitLength			(int Dir)					{	return( Get_System()->Get_UnitLength(Dir) );	}
+	bool						is_InGrid				(int x, int y)				{	return(	Get_System()->is_InGrid(x, y) );		}
+	bool						is_InGrid				(int x, int y, int Rand)	{	return(	Get_System()->is_InGrid(x, y, Rand) );	}
+
+	//-----------------------------------------------------
+	void						Lock_Create				(void);
+	void						Lock_Destroy			(void);
+
+	bool						is_Locked				(int x, int y)	{	return( Lock_Get(x, y) != 0 );	}
+	char						Lock_Get				(int x, int y)	{	return( m_pLock && x >= 0 && x < Get_System()->Get_NX() && y >= 0 && y < Get_System()->Get_NY() ? m_pLock->asChar(x, y) : 0 );	}
+
+	void						Lock_Set				(int x, int y, char Value = 1)
+	{
+		if( m_pLock && x >= 0 && x < Get_System()->Get_NX() && y >= 0 && y < Get_System()->Get_NY() )
+		{
+			m_pLock->Set_Value(x, y, Value);
+		}
+	}
+
+
+private:
+
+	CSG_Grid						*m_pLock;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				CSG_Module_Interactive_Base				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Module_Interactive_Mode
+{
+	MODULE_INTERACTIVE_UNDEFINED		= 0,
+	MODULE_INTERACTIVE_LDOWN,
+	MODULE_INTERACTIVE_LUP,
+	MODULE_INTERACTIVE_LDCLICK,
+	MODULE_INTERACTIVE_MDOWN,
+	MODULE_INTERACTIVE_MUP,
+	MODULE_INTERACTIVE_MDCLICK,
+	MODULE_INTERACTIVE_RDOWN,
+	MODULE_INTERACTIVE_RUP,
+	MODULE_INTERACTIVE_RDCLICK,
+	MODULE_INTERACTIVE_MOVE,
+	MODULE_INTERACTIVE_MOVE_LDOWN,
+	MODULE_INTERACTIVE_MOVE_MDOWN,
+	MODULE_INTERACTIVE_MOVE_RDOWN
+}
+TSG_Module_Interactive_Mode;
+
+//---------------------------------------------------------
+typedef enum ESG_Module_Interactive_DragMode
+{
+	MODULE_INTERACTIVE_DRAG_NONE		= 0,
+	MODULE_INTERACTIVE_DRAG_LINE,
+	MODULE_INTERACTIVE_DRAG_BOX,
+	MODULE_INTERACTIVE_DRAG_CIRCLE
+}
+TSG_Module_Interactive_DragMode;
+
+//---------------------------------------------------------
+#define MODULE_INTERACTIVE_KEY_LEFT		0x01
+#define MODULE_INTERACTIVE_KEY_MIDDLE	0x02
+#define MODULE_INTERACTIVE_KEY_RIGHT	0x04
+#define MODULE_INTERACTIVE_KEY_SHIFT	0x08
+#define MODULE_INTERACTIVE_KEY_ALT		0x10
+#define MODULE_INTERACTIVE_KEY_CTRL		0x20
+
+//---------------------------------------------------------
+/**
+  * CSG_Module_Interactive_Base.
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module_Interactive_Base
+{
+	friend class CSG_Module_Interactive;
+	friend class CSG_Module_Grid_Interactive;
+
+public:
+	CSG_Module_Interactive_Base(void);
+	virtual ~CSG_Module_Interactive_Base(void);
+
+	bool						Execute_Position		(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode, int Keys);
+	bool						Execute_Keyboard		(int Character, int Keys);
+	bool						Execute_Finish			(void);
+
+	int							Get_Drag_Mode			(void)	{	return( m_Drag_Mode );	}
+
+
+protected:
+
+	virtual bool				On_Execute_Position		(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode);
+	virtual bool				On_Execute_Keyboard		(int Character);
+	virtual bool				On_Execute_Finish		(void);
+
+	CSG_Point &					Get_Position			(void)	{	return( m_Point );					}
+	double						Get_xPosition			(void)	{	return( m_Point.m_point.x );		}
+	double						Get_yPosition			(void)	{	return( m_Point.m_point.y );		}
+
+	CSG_Point &					Get_Position_Last		(void)	{	return( m_Point_Last );				}
+	double						Get_xPosition_Last		(void)	{	return( m_Point_Last.m_point.x );	}
+	double						Get_yPosition_Last		(void)	{	return( m_Point_Last.m_point.y );	}
+
+	bool						is_Shift				(void)	{	return( (m_Keys & MODULE_INTERACTIVE_KEY_SHIFT) != 0 );	}
+	bool						is_Alt					(void)	{	return( (m_Keys & MODULE_INTERACTIVE_KEY_ALT)   != 0 );	}
+	bool						is_Ctrl					(void)	{	return( (m_Keys & MODULE_INTERACTIVE_KEY_CTRL)  != 0 );	}
+
+	void						Set_Drag_Mode			(int Drag_Mode);
+
+
+private:
+
+	int							m_Keys, m_Drag_Mode;
+
+	CSG_Point					m_Point, m_Point_Last;
+
+	CSG_Module					*m_pModule;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				CSG_Module_Interactive					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Module_Interactive.
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module_Interactive : public CSG_Module_Interactive_Base, public CSG_Module
+{
+public:
+	CSG_Module_Interactive(void);
+	virtual ~CSG_Module_Interactive(void);
+
+	virtual TSG_Module_Type		Get_Type				(void)	{	return( MODULE_TYPE_Interactive );	}
+
+	virtual bool				is_Interactive			(void)	{	return( true );	}
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				CSG_Module_Grid_Interactive				 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/**
+  * CSG_Module_Grid_Interactive.
+*/
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module_Grid_Interactive : public CSG_Module_Interactive_Base, public CSG_Module_Grid
+{
+public:
+	CSG_Module_Grid_Interactive(void);
+	virtual ~CSG_Module_Grid_Interactive(void);
+
+	virtual TSG_Module_Type		Get_Type				(void)	{	return( MODULE_TYPE_Grid_Interactive );	}
+
+	virtual bool				is_Interactive			(void)	{	return( true );	}
+
+
+protected:
+
+	bool						Get_Grid_Pos			(int &x, int &y);
+
+	int							Get_xGrid				(void);
+	int							Get_yGrid				(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//			Module Library Interface Definitions		 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_MLB_Info
+{
+	MLB_INFO_Name	= 0,
+	MLB_INFO_Description,
+	MLB_INFO_Author,
+	MLB_INFO_Version,
+	MLB_INFO_Menu_Path,
+	MLB_INFO_User,
+	MLB_INFO_Count
+}
+TSG_MLB_Info;
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module_Library_Interface
+{
+public:
+	CSG_Module_Library_Interface(void);
+	virtual ~CSG_Module_Library_Interface(void);
+
+	void						Set_Info				(int ID, const SG_Char *Info);
+	const SG_Char *				Get_Info				(int ID);
+
+	int							Get_Count				(void);
+	bool						Add_Module				(CSG_Module *pModule);
+	CSG_Module *				Get_Module				(int iModule);
+
+	void						Set_File_Name			(const CSG_String &File_Name);
+	const SG_Char *				Get_File_Name			(void);
+
+	const SG_Char *				Get_Translation			(const SG_Char *Text);
+
+
+private:
+
+	const SG_Char				*m_Info[MLB_INFO_Count];
+
+	int							m_nModules;
+
+	CSG_Module					**m_Modules;
+
+	CSG_String					m_File_Name;
+
+	CSG_Translator				m_Translator;
+
+};
+
+//---------------------------------------------------------
+#define SYMBOL_MLB_Initialize			SG_T("MLB_Initialize")
+typedef bool							(* TSG_PFNC_MLB_Initialize)		(const SG_Char *);
+
+//---------------------------------------------------------
+#define SYMBOL_MLB_Get_Interface		SG_T("MLB_Get_Interface")
+typedef CSG_Module_Library_Interface *	(* TSG_PFNC_MLB_Get_Interface)	(void);
+
+//---------------------------------------------------------
+#define MLB_INTERFACE	CSG_Module_Library_Interface		MLB_Interface;\
+\
+extern "C" _SAGA_DLL_EXPORT bool							MLB_Initialize		(const SG_Char *File_Name)\
+{\
+	MLB_Interface.Set_File_Name(File_Name);\
+\
+	int		i	= 0;\
+\
+	while( MLB_Interface.Add_Module(Create_Module(i++)) );\
+\
+	for(i=0; i<MLB_INFO_Count; i++)\
+	{\
+		MLB_Interface.Set_Info(i, Get_Info(i));\
+	}\
+\
+	return( MLB_Interface.Get_Count() > 0 );\
+}\
+\
+extern "C" _SAGA_DLL_EXPORT CSG_Module_Library_Interface *	MLB_Get_Interface   (void)\
+{\
+	return( &MLB_Interface );\
+}\
+\
+extern "C" _SAGA_DLL_EXPORT const SG_Char *					Get_API_Version		(void)\
+{\
+	return( SAGA_API_VERSION );\
+}\
+
+//---------------------------------------------------------
+#ifndef SWIG
+
+extern CSG_Module_Library_Interface	MLB_Interface;
+
+#endif	// #ifdef SWIG
+
+//---------------------------------------------------------
+#ifndef _SAGA_UNICODE
+	#define _TL			MLB_Interface.Get_Translation
+	#define _TW			MLB_Interface.Get_Translation
+#else
+	#define _TL(s)		MLB_Interface.Get_Translation(SG_T(s))
+	#define _TW(s)		CSG_String(MLB_Interface.Get_Translation(CSG_String(s))).c_str()
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__module_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,167 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    module_grid.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module_Grid::CSG_Module_Grid(void)
+	: CSG_Module()
+{
+	m_pLock		= NULL;
+
+	Parameters.Create(this, SG_T(""), SG_T(""), SG_T(""), true);
+}
+
+//---------------------------------------------------------
+CSG_Module_Grid::~CSG_Module_Grid(void)
+{
+	Lock_Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module_Grid::Set_Progress(int iRow)
+{
+	return( CSG_Module::Set_Progress(iRow, Get_System()->Get_NY() - 1) );
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Grid::Set_Progress(double Position, double Range)
+{
+	return( CSG_Module::Set_Progress(Position, Range) );
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Grid::Set_Progress_NCells(int iCell)
+{
+	if( Get_System()->is_Valid() && (Get_System()->Get_NCells() <= 100 || !(iCell % (Get_System()->Get_NCells() / 100))) )
+	{
+		return( CSG_Module::Set_Progress(iCell, Get_System()->Get_NCells()) );
+	}
+
+	return( is_Progress() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module_Grid::Lock_Create(void)
+{
+	if( Get_System()->is_Valid() )
+	{
+		if( m_pLock && Get_System()->is_Equal(m_pLock->Get_System()) )
+		{
+			m_pLock->Assign(0.0);
+		}
+		else
+		{
+			Lock_Destroy();
+
+			m_pLock	= new CSG_Grid(
+				SG_DATATYPE_Char,
+				Get_System()->Get_NX(),
+				Get_System()->Get_NY(),
+				Get_System()->Get_Cellsize(),
+				Get_System()->Get_XMin(),
+				Get_System()->Get_YMin()
+			);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Module_Grid::Lock_Destroy(void)
+{
+	if( m_pLock )
+	{
+		delete(m_pLock);
+
+		m_pLock	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid_interactive.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid_interactive.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_grid_interactive.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,192 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              module_grid_interactive.cpp              //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module_Grid_Interactive::CSG_Module_Grid_Interactive(void)
+{
+	m_pModule	= this;
+}
+
+//---------------------------------------------------------
+CSG_Module_Grid_Interactive::~CSG_Module_Grid_Interactive(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module_Grid_Interactive::Get_Grid_Pos(int &x, int &y)
+{
+	bool	bResult;
+
+	if( Get_System()->is_Valid() )
+	{
+		bResult	= true;
+
+		//-------------------------------------------------
+		x		= (int)(0.5 + (Get_xPosition() - Get_System()->Get_XMin()) / Get_System()->Get_Cellsize());
+
+		if( x < 0 )
+		{
+			bResult	= false;
+			x		= 0;
+		}
+		else if( x >= Get_System()->Get_NX() )
+		{
+			bResult	= false;
+			x		= Get_System()->Get_NX() - 1;
+		}
+
+		//-------------------------------------------------
+		y		= (int)(0.5 + (Get_yPosition() - Get_System()->Get_YMin()) / Get_System()->Get_Cellsize());
+
+		if( y < 0 )
+		{
+			bResult	= false;
+			y		= 0;
+		}
+		else if( y >= Get_System()->Get_NY() )
+		{
+			bResult	= false;
+			y		= Get_System()->Get_NY() - 1;
+		}
+
+		return( bResult );
+	}
+
+	//-----------------------------------------------------
+	x		= 0;
+	y		= 0;
+
+	return( false );
+}
+
+//---------------------------------------------------------
+int CSG_Module_Grid_Interactive::Get_xGrid(void)
+{
+	int		x;
+
+	if( Get_System()->is_Valid() )
+	{
+		x		= (int)(0.5 + (Get_xPosition() - Get_System()->Get_XMin()) / Get_System()->Get_Cellsize());
+
+		if( x < 0 )
+		{
+			x		= 0;
+		}
+		else if( x >= Get_System()->Get_NX() )
+		{
+			x		= Get_System()->Get_NX() - 1;
+		}
+
+		return( x );
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Module_Grid_Interactive::Get_yGrid(void)
+{
+	int		y;
+
+	if( Get_System()->is_Valid() )
+	{
+		y		= (int)(0.5 + (Get_yPosition() - Get_System()->Get_YMin()) / Get_System()->Get_Cellsize());
+
+		if( y < 0 )
+		{
+			y		= 0;
+		}
+		else if( y >= Get_System()->Get_NY() )
+		{
+			y		= Get_System()->Get_NY() - 1;
+		}
+
+		return( y );
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,90 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                module_interactive.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module_Interactive::CSG_Module_Interactive(void)
+{
+	m_pModule	= this;
+}
+
+//---------------------------------------------------------
+CSG_Module_Interactive::~CSG_Module_Interactive(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_interactive_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,202 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              module_interactive_base.cpp              //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module_Interactive_Base::CSG_Module_Interactive_Base(void)
+{
+	m_pModule			= NULL;
+
+	m_Keys				= 0;
+	m_Drag_Mode			= MODULE_INTERACTIVE_DRAG_BOX;
+
+	m_Point.m_point.x	= m_Point_Last.m_point.x	= 0.0;
+	m_Point.m_point.y	= m_Point_Last.m_point.y	= 0.0;
+}
+
+//---------------------------------------------------------
+CSG_Module_Interactive_Base::~CSG_Module_Interactive_Base(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Module_Interactive_Base::Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode, int Keys)
+{
+	bool	bResult	= false;
+
+	if( m_pModule && !m_pModule->m_bExecutes )
+	{
+		SG_UI_Process_Set_Okay();
+
+		m_pModule->m_bExecutes		= true;
+		m_pModule->m_bError_Ignore	= false;
+
+		m_Point_Last				= m_Point;
+		m_Point						= ptWorld;
+
+		m_Keys						= Keys;
+
+		bResult						= On_Execute_Position(m_Point, Mode);
+
+		m_Keys						= 0;
+
+		m_pModule->m_bExecutes		= false;
+	}
+
+	return( bResult );
+}
+
+bool CSG_Module_Interactive_Base::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Interactive_Base::Execute_Keyboard(int Character, int Keys)
+{
+	bool	bResult	= false;
+
+	if( m_pModule && !m_pModule->m_bExecutes )
+	{
+		SG_UI_Process_Set_Okay();
+
+		m_pModule->m_bExecutes		= true;
+		m_pModule->m_bError_Ignore	= false;
+
+		m_Keys						= Keys;
+
+		bResult						= On_Execute_Keyboard(Character);
+
+		m_Keys						= 0;
+
+		m_pModule->m_bExecutes		= false;
+	}
+
+	return( bResult );
+}
+
+bool CSG_Module_Interactive_Base::On_Execute_Keyboard(int Character)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Interactive_Base::Execute_Finish(void)
+{
+	bool	bResult	= false;
+
+	if( m_pModule && !m_pModule->m_bExecutes )
+	{
+		SG_UI_Process_Set_Okay();
+
+		m_pModule->m_bExecutes		= true;
+		m_pModule->m_bError_Ignore	= false;
+
+		bResult						= On_Execute_Finish();
+
+		m_pModule->m_bExecutes		= false;
+	}
+
+	return( bResult );
+}
+
+bool CSG_Module_Interactive_Base::On_Execute_Finish(void)
+{
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module_Interactive_Base::Set_Drag_Mode(int Drag_Mode)
+{
+	m_Drag_Mode	= Drag_Mode;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,452 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  module_library.cpp                   //
+//                                                       //
+//          Copyright (C) 2006 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dynlib.h>
+#include <wx/filename.h>
+#include <wx/utils.h>
+
+#include "module_library.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#if defined(_SAGA_MSW)
+
+	#define ENV_LIB_PATH	SG_T("PATH")
+	#define ENV_LIB_SEPA	SG_T(';')
+
+#elif defined(_SAGA_LINUX)
+
+	#define ENV_LIB_PATH	SG_T("LD_LIBRARY_PATH")
+	#define ENV_LIB_SEPA	SG_T(':')
+
+#else
+
+	#define ENV_LIB_PATH	SG_T("PATH")
+	#define ENV_LIB_SEPA	SG_T(';')
+
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module_Library::CSG_Module_Library(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Module_Library::CSG_Module_Library(const CSG_String &File_Name)
+{
+	_On_Construction();
+
+	Create(File_Name);
+}
+
+//---------------------------------------------------------
+CSG_Module_Library::~CSG_Module_Library(void)
+{
+	Destroy();
+
+	delete(m_pLibrary);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module_Library::_On_Construction(void)
+{
+	m_pLibrary		= new wxDynamicLibrary;
+
+	m_pInterface	= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Library::Create(const CSG_String &File_Name)
+{
+	Destroy();
+
+	TSG_PFNC_MLB_Initialize		MLB_Initialize;
+	TSG_PFNC_MLB_Get_Interface	MLB_Get_Interface;
+
+	wxString	sPath;
+	wxFileName	fName(File_Name.c_str());
+
+	fName.MakeAbsolute();
+	m_File_Name		= fName.GetFullPath();
+
+	//-----------------------------------------------------
+	if( wxGetEnv(ENV_LIB_PATH, &sPath) && sPath.Length() > 0 )
+	{
+		wxSetEnv(ENV_LIB_PATH, CSG_String::Format(SG_T("%s%c%s"), sPath.c_str(), ENV_LIB_SEPA, SG_File_Get_Path(m_File_Name).c_str()));
+	}
+	else
+	{
+		wxSetEnv(ENV_LIB_PATH, SG_File_Get_Path(m_File_Name).c_str());
+	}
+
+	//-----------------------------------------------------
+	if(	m_pLibrary->Load(m_File_Name.c_str())
+	&&	(MLB_Get_Interface	= (TSG_PFNC_MLB_Get_Interface)	m_pLibrary->GetSymbol(SYMBOL_MLB_Get_Interface)) != NULL
+	&&	(MLB_Initialize		= (TSG_PFNC_MLB_Initialize)		m_pLibrary->GetSymbol(SYMBOL_MLB_Initialize)   ) != NULL
+	&&	 MLB_Initialize(m_File_Name) )
+	{
+		m_pInterface	= MLB_Get_Interface();
+	}
+
+	//-----------------------------------------------------
+	if( sPath.Length() > 0 )
+	{
+		wxSetEnv(ENV_LIB_PATH, sPath);
+	}
+	else
+	{
+		wxUnsetEnv(ENV_LIB_PATH);
+	}
+
+	//-----------------------------------------------------
+	if( Get_Count() > 0 )
+	{
+		for(int i=0; i<Get_Count(); i++)
+			Get_Module(i)->Set_Managed(false);
+
+		return( true );
+	}
+
+	Destroy();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Library::Destroy(void)
+{
+	if( m_pLibrary->IsLoaded() )
+	{
+		m_pLibrary->Unload();
+	}
+
+	m_pInterface	= NULL;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Module_Library::Get_Info(int Type)
+{
+	if( m_pInterface != NULL )
+	{
+		return( m_pInterface->Get_Info(Type) );
+	}
+
+	return( SG_T("") );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Name(void)
+{
+	return( Get_Info(MLB_INFO_Name) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Description(void)
+{
+	return( Get_Info(MLB_INFO_Description) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Author(void)
+{
+	return( Get_Info(MLB_INFO_Author) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Version(void)
+{
+	return( Get_Info(MLB_INFO_Version) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Menu(void)
+{
+	return( Get_Info(MLB_INFO_Menu_Path) );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Summary(bool bHTML)
+{
+	CSG_String	s;
+
+	if( bHTML )
+	{
+		s.Printf(
+			SG_T("%s: <b>%s</b><br>%s: <i>%s</i><br>%s: <i>%s</i><br>%s: <i>%s</i><hr>%s"),
+			LNG("[CAP] Module Library")	, Get_Info(MLB_INFO_Name),
+			LNG("[CAP] Author")			, Get_Info(MLB_INFO_Author),
+			LNG("[CAP] Version")		, Get_Info(MLB_INFO_Version),
+			LNG("[CAP] File")			, Get_File_Name().c_str(),
+			Get_Info(MLB_INFO_Description)
+		);
+
+		s.Append(CSG_String::Format(SG_T("<hr><b>%s:<ul>"), LNG("[CAP] Modules")));
+
+		for(int i=0; i<Get_Count(); i++)
+		{
+			s.Append(CSG_String::Format(SG_T("<li>%s</li>"), Get_Module(i)->Get_Name()));
+		}
+
+		s.Append(SG_T("</ul>"));
+
+		s.Replace(SG_T("\n"), SG_T("<br>"));
+	}
+	else
+	{
+		s.Printf(
+			SG_T("%s: %s\n%s: %s\n%s: %s\n%s: %s\n\n%s"),
+			LNG("[CAP] Module Library")	, Get_Info(MLB_INFO_Name),
+			LNG("[CAP] Author")			, Get_Info(MLB_INFO_Author),
+			LNG("[CAP] Version")		, Get_Info(MLB_INFO_Version),
+			LNG("[CAP] File")			, Get_File_Name().c_str(),
+			Get_Info(MLB_INFO_Description)
+		);
+
+		s.Append(CSG_String::Format(SG_T("\n\n%s:\n"), LNG("[CAP] Modules")));
+
+		for(int i=0; i<Get_Count(); i++)
+		{
+			s.Append(CSG_String::Format(SG_T("- %s\n"), Get_Module(i)->Get_Name()));
+		}
+	}
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module * CSG_Module_Library::Get_Module(const SG_Char *Name)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( !SG_STR_CMP(Name, Get_Module(i)->Get_Name()) )
+		{
+			return( Get_Module(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Module_Grid * CSG_Module_Library::Get_Module_Grid(int i)
+{
+	CSG_Module	*pModule	= Get_Module(i);
+
+	return( pModule && pModule->Get_Type() == MODULE_TYPE_Grid
+		? (CSG_Module_Grid *)pModule : NULL
+	);
+}
+
+CSG_Module_Grid * CSG_Module_Library::Get_Module_Grid(const SG_Char *Name)
+{
+	CSG_Module	*pModule	= Get_Module(Name);
+
+	return( pModule && pModule->Get_Type() == MODULE_TYPE_Grid
+		? (CSG_Module_Grid *)pModule : NULL
+	);
+}
+
+//---------------------------------------------------------
+CSG_Module_Interactive * CSG_Module_Library::Get_Module_I(int i)
+{
+	CSG_Module	*pModule	= Get_Module(i);
+
+	return( pModule && pModule->Get_Type() == MODULE_TYPE_Interactive
+		? (CSG_Module_Interactive *)pModule : NULL
+	);
+}
+
+CSG_Module_Interactive * CSG_Module_Library::Get_Module_I(const SG_Char *Name)
+{
+	CSG_Module	*pModule	= Get_Module(Name);
+
+	return( pModule && pModule->Get_Type() == MODULE_TYPE_Interactive
+		? (CSG_Module_Interactive *)pModule : NULL
+	);
+}
+
+//---------------------------------------------------------
+CSG_Module_Grid_Interactive * CSG_Module_Library::Get_Module_Grid_I(int i)
+{
+	CSG_Module	*pModule	= Get_Module(i);
+
+	return( pModule && pModule->Get_Type() == MODULE_TYPE_Grid_Interactive
+		? (CSG_Module_Grid_Interactive *)pModule : NULL
+	);
+}
+
+CSG_Module_Grid_Interactive * CSG_Module_Library::Get_Module_Grid_I(const SG_Char *Name)
+{
+	CSG_Module	*pModule	= Get_Module(Name);
+
+	return( pModule && pModule->Get_Type() == MODULE_TYPE_Grid_Interactive
+		? (CSG_Module_Grid_Interactive *)pModule : NULL
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_Module_Library::Get_Menu(int i)
+{
+	CSG_String	sMenu;
+
+	if( Get_Module(i) != NULL )
+	{
+		bool		bAbsolute	= false;
+		const SG_Char	*sModule	= Get_Module(i)->Get_MenuPath();
+
+		if( sModule && *sModule && *(sModule + 1) == ':' )
+		{
+			bAbsolute	= sModule[0] == SG_T('A') || sModule[0] == SG_T('a');
+			sModule		+= 2;
+		}
+
+		if( bAbsolute )	// menu path is relative to top menu...
+		{
+			if( sModule && *sModule )
+			{
+				sMenu.Printf(SG_T("%s"), sModule);
+			}
+		}
+		else			// menu path is relative to library menu...
+		{
+			const SG_Char	*sLibrary	= Get_Info(MLB_INFO_Menu_Path);
+
+			if( sModule && *sModule )
+			{
+				if( sLibrary && *sLibrary )
+				{
+					sMenu.Printf(SG_T("%s|%s"), sLibrary, sModule);
+				}
+				else
+				{
+					sMenu.Printf(SG_T("%s"), sModule);
+				}
+			}
+			else if( sLibrary && *sLibrary )
+			{
+				sMenu.Printf(SG_T("%s"), sLibrary);
+			}
+		}
+
+		if( sMenu.Length() > 0 )
+		{
+			sMenu.Append(SG_T("|"));
+		}
+
+		sMenu.Append(Get_Info(MLB_INFO_Name));
+	}
+
+	return( sMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,143 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  module_library.h                     //
+//                                                       //
+//          Copyright (C) 2006 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__module_library_H
+#define HEADER_INCLUDED__SAGA_API__module_library_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Module_Library
+{
+public:
+	CSG_Module_Library(void);
+	virtual ~CSG_Module_Library(void);
+
+									CSG_Module_Library	(const CSG_String &File_Name);
+	bool							Create				(const CSG_String &File_Name);
+
+	bool							Destroy				(void);
+
+	bool							is_Valid			(void)		{	return( Get_Count() > 0 );	}
+
+	const CSG_String &				Get_File_Name		(void)		{	return( m_File_Name );	}
+
+	const SG_Char *					Get_Info			(int Type);
+
+	CSG_String						Get_Name			(void);
+	CSG_String						Get_Description		(void);
+	CSG_String						Get_Author			(void);
+	CSG_String						Get_Version			(void);
+	CSG_String						Get_Menu			(void);
+	CSG_String						Get_Summary			(bool bHTML = false);
+
+	int								Get_Count			(void)		{	return( m_pInterface ? m_pInterface->Get_Count() : 0 );	}
+
+	CSG_Module *					Get_Module			(int i)		{	return( i >= 0 && i < Get_Count() ? m_pInterface->Get_Module(i) : NULL );	}
+	CSG_Module *					Get_Module			(const SG_Char *Name);
+	CSG_Module_Grid *				Get_Module_Grid		(int i);
+	CSG_Module_Grid *				Get_Module_Grid		(const SG_Char *Name);
+	CSG_Module_Interactive *		Get_Module_I		(int i);
+	CSG_Module_Interactive *		Get_Module_I		(const SG_Char *Name);
+	CSG_Module_Grid_Interactive *	Get_Module_Grid_I	(int i);
+	CSG_Module_Grid_Interactive *	Get_Module_Grid_I	(const SG_Char *Name);
+
+	CSG_String						Get_Menu			(int i);
+
+
+private:
+
+	CSG_String						m_File_Name;
+
+	CSG_Module_Library_Interface	*m_pInterface;
+
+	class wxDynamicLibrary			*m_pLibrary;
+
+
+	void							_On_Construction	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__module_library_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library_interface.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library_interface.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/module_library_interface.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,194 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//             module_library_interface.cpp              //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module_Library_Interface::CSG_Module_Library_Interface(void)
+{
+	m_nModules	= 0;
+	m_Modules	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Module_Library_Interface::~CSG_Module_Library_Interface(void)
+{
+	if( m_Modules && m_nModules > 0 )
+	{
+		for(int i=0; i<m_nModules; i++)
+		{
+			delete(m_Modules[i]);
+		}
+
+		SG_Free( m_Modules );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module_Library_Interface::Set_Info(int ID, const SG_Char *Info)
+{
+	m_Info[ID]	= Get_Translation(Info);
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Module_Library_Interface::Get_Info(int ID)
+{
+	return( m_Info[ID] );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Module_Library_Interface::Get_Count(void)
+{
+	return( m_nModules );
+}
+
+//---------------------------------------------------------
+bool CSG_Module_Library_Interface::Add_Module(CSG_Module *pModule)
+{
+	if( pModule )
+	{
+		pModule->Set_Managed(true);
+		pModule->Set_Translation(m_Translator);
+
+		m_Modules				= (CSG_Module **)SG_Realloc(m_Modules, (m_nModules + 1) * sizeof(CSG_Module *));
+		m_Modules[m_nModules++]	= pModule;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Module * CSG_Module_Library_Interface::Get_Module(int iModule)
+{
+	if( iModule >= 0 && iModule < m_nModules )
+	{
+		return( m_Modules[iModule] );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Module_Library_Interface::Set_File_Name(const CSG_String &File_Name)
+{
+	m_File_Name	= File_Name;
+
+	m_Translator.Create(m_File_Name);
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Module_Library_Interface::Get_File_Name(void)
+{
+	return( m_File_Name );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Module_Library_Interface::Get_Translation(const SG_Char *Text)
+{
+	return( m_Translator.Get_Translation(Text) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,576 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     parameter.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter::CSG_Parameter(CSG_Parameters *pOwner, CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, int Constraint)
+{
+	m_pOwner		= pOwner;
+	m_pParent		= pParent;
+
+	m_Identifier	= Identifier;
+	m_Name			= Name;
+	m_Description	= Description;
+
+	m_bEnabled		= true;
+
+	//-----------------------------------------------------
+	m_nChildren		= 0;
+	m_Children		= NULL;
+
+	if( m_pParent )
+	{
+		m_pParent->_Add_Child(this);
+	}
+
+	//-----------------------------------------------------
+	switch( Type )
+	{
+	default:								m_pData	= NULL;													break;
+
+	case PARAMETER_TYPE_Node:				m_pData	= new CSG_Parameter_Node				(this, Constraint);	break;
+
+	case PARAMETER_TYPE_Bool:				m_pData	= new CSG_Parameter_Bool				(this, Constraint);	break;
+	case PARAMETER_TYPE_Int:				m_pData	= new CSG_Parameter_Int					(this, Constraint);	break;
+	case PARAMETER_TYPE_Double:				m_pData	= new CSG_Parameter_Double				(this, Constraint);	break;
+	case PARAMETER_TYPE_Degree:				m_pData	= new CSG_Parameter_Degree				(this, Constraint);	break;
+	case PARAMETER_TYPE_Range:				m_pData	= new CSG_Parameter_Range				(this, Constraint);	break;
+	case PARAMETER_TYPE_Choice:				m_pData	= new CSG_Parameter_Choice				(this, Constraint);	break;
+
+	case PARAMETER_TYPE_String:				m_pData	= new CSG_Parameter_String				(this, Constraint);	break;
+	case PARAMETER_TYPE_Text:				m_pData	= new CSG_Parameter_Text				(this, Constraint);	break;
+	case PARAMETER_TYPE_FilePath:			m_pData	= new CSG_Parameter_File_Name			(this, Constraint);	break;
+
+	case PARAMETER_TYPE_Font:				m_pData	= new CSG_Parameter_Font				(this, Constraint);	break;
+	case PARAMETER_TYPE_Color:				m_pData	= new CSG_Parameter_Color				(this, Constraint);	break;
+	case PARAMETER_TYPE_Colors:				m_pData	= new CSG_Parameter_Colors				(this, Constraint);	break;
+	case PARAMETER_TYPE_FixedTable:			m_pData	= new CSG_Parameter_Fixed_Table			(this, Constraint);	break;
+	case PARAMETER_TYPE_Grid_System:		m_pData	= new CSG_Parameter_Grid_System			(this, Constraint);	break;
+	case PARAMETER_TYPE_Table_Field:		m_pData	= new CSG_Parameter_Table_Field			(this, Constraint);	break;
+
+	case PARAMETER_TYPE_DataObject_Output:	m_pData	= new CSG_Parameter_Data_Object_Output	(this, Constraint);	break;
+	case PARAMETER_TYPE_Grid:				m_pData	= new CSG_Parameter_Grid				(this, Constraint);	break;
+	case PARAMETER_TYPE_Table:				m_pData	= new CSG_Parameter_Table				(this, Constraint);	break;
+	case PARAMETER_TYPE_Shapes:				m_pData	= new CSG_Parameter_Shapes				(this, Constraint);	break;
+	case PARAMETER_TYPE_TIN:				m_pData	= new CSG_Parameter_TIN					(this, Constraint);	break;
+	case PARAMETER_TYPE_PointCloud:			m_pData	= new CSG_Parameter_PointCloud			(this, Constraint);	break;
+
+	case PARAMETER_TYPE_Grid_List:			m_pData	= new CSG_Parameter_Grid_List			(this, Constraint);	break;
+	case PARAMETER_TYPE_Table_List:			m_pData	= new CSG_Parameter_Table_List			(this, Constraint);	break;
+	case PARAMETER_TYPE_Shapes_List:		m_pData	= new CSG_Parameter_Shapes_List			(this, Constraint);	break;
+	case PARAMETER_TYPE_TIN_List:			m_pData	= new CSG_Parameter_TIN_List			(this, Constraint);	break;
+	case PARAMETER_TYPE_PointCloud_List:	m_pData	= new CSG_Parameter_PointCloud_List		(this, Constraint);	break;
+
+	case PARAMETER_TYPE_Parameters:			m_pData	= new CSG_Parameter_Parameters			(this, Constraint);	break;
+	}
+
+	//-----------------------------------------------------
+	switch( Type )
+	{
+	default:
+		break;
+
+	case PARAMETER_TYPE_Range:
+		SG_Free(m_Children);
+		m_nChildren		= 0;
+		m_Children		= NULL;
+		break;
+	}
+}
+
+//---------------------------------------------------------
+CSG_Parameter::~CSG_Parameter(void)
+{
+	if( m_Children )
+	{
+		SG_Free(m_Children);
+	}
+
+	if( m_pData )
+	{
+		delete(m_pData);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Parameter::_Add_Child(CSG_Parameter *pChild)
+{
+	m_Children	= (CSG_Parameter **)SG_Realloc(m_Children, (m_nChildren + 1) * sizeof(CSG_Parameter *));
+	m_Children[m_nChildren++]	= pChild;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameter::Set_Enabled(bool bEnabled)
+{
+	if( m_bEnabled != bEnabled )
+	{
+		m_bEnabled	= bEnabled;
+
+		return( !bEnabled );
+	}
+
+	return( bEnabled );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::is_Option(void)
+{
+	if( !is_Information() )
+	{
+		switch( Get_Type() )
+		{
+		default:
+			return( false );
+
+		case PARAMETER_TYPE_Bool:
+		case PARAMETER_TYPE_Int:
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+		case PARAMETER_TYPE_Range:
+		case PARAMETER_TYPE_Choice:
+
+		case PARAMETER_TYPE_String:
+		case PARAMETER_TYPE_Text:
+		case PARAMETER_TYPE_FilePath:
+
+		case PARAMETER_TYPE_Font:
+
+		case PARAMETER_TYPE_Color:
+		case PARAMETER_TYPE_Colors:
+
+		case PARAMETER_TYPE_FixedTable:
+
+		case PARAMETER_TYPE_Grid_System:
+		case PARAMETER_TYPE_Table_Field:
+
+		case PARAMETER_TYPE_Parameters:
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::is_DataObject(void)
+{
+	switch( Get_Type() )
+	{
+	default:
+		return( false );
+
+	case PARAMETER_TYPE_DataObject_Output:
+	case PARAMETER_TYPE_Grid:
+	case PARAMETER_TYPE_Table:
+	case PARAMETER_TYPE_Shapes:
+	case PARAMETER_TYPE_TIN:
+	case PARAMETER_TYPE_PointCloud:
+
+		return( true );
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::is_DataObject_List(void)
+{
+	switch( Get_Type() )
+	{
+	default:
+		return( false );
+
+	case PARAMETER_TYPE_Grid_List:
+	case PARAMETER_TYPE_Table_List:
+	case PARAMETER_TYPE_Shapes_List:
+	case PARAMETER_TYPE_TIN_List:
+	case PARAMETER_TYPE_PointCloud_List:
+
+		return( true );
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::is_Parameters(void)
+{
+	return( Get_Type() == PARAMETER_TYPE_Parameters );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::is_Serializable(void)
+{
+	switch( Get_Type() )
+	{
+	case PARAMETER_TYPE_Undefined:
+	case PARAMETER_TYPE_Node:
+	case PARAMETER_TYPE_DataObject_Output:
+		return( false );
+
+	case PARAMETER_TYPE_String:
+		return( ((CSG_Parameter_String *)Get_Data())->is_Password() == false );
+
+	default:
+		return( !is_Information() );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter::Get_Identifier(void)
+{
+	return( m_Identifier );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter::Get_Name(void)
+{
+	return( m_Name );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter::Get_Description(void)
+{
+	return( m_Description );
+}
+
+
+//---------------------------------------------------------
+CSG_String CSG_Parameter::Get_Description(int Flags)
+{
+	return( Get_Description(Flags, SG_T("\n")) );
+}
+
+//---------------------------------------------------------
+#define SEPARATE	if( bSeparate )	s.Append(Separator);	bSeparate	= true;
+
+//---------------------------------------------------------
+CSG_String CSG_Parameter::Get_Description(int Flags, const SG_Char *Separator)
+{
+	if( !Separator || !Separator[0] )
+	{
+		return( Get_Description(Flags) );
+	}
+
+	bool		bSeparate	= false;
+	int			i;
+	CSG_String	s;
+
+	//-----------------------------------------------------
+	if( (Flags & PARAMETER_DESCRIPTION_NAME) != 0 )
+	{
+		SEPARATE;
+		s.Append(CSG_String::Format(SG_T("%s"), Get_Name()));
+	}
+
+	//-----------------------------------------------------
+	if( (Flags & PARAMETER_DESCRIPTION_TYPE) != 0 )
+	{
+		SEPARATE;
+		s.Append(CSG_String::Format(SG_T("%s"), Get_Type_Name()));
+
+		if( is_DataObject() || is_DataObject_List() )
+		{
+			if( is_Input() )
+			{
+				if( is_Optional() )
+					s.Append(CSG_String::Format(SG_T(" (%s)"), LNG("optional input")));
+				else
+					s.Append(CSG_String::Format(SG_T(" (%s)"), LNG("input")));
+			}
+			else if( is_Output() )
+			{
+				if( is_Optional() )
+					s.Append(CSG_String::Format(SG_T(" (%s)"), LNG("optional output")));
+				else
+					s.Append(CSG_String::Format(SG_T(" (%s)"), LNG("output")));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( (Flags & PARAMETER_DESCRIPTION_OPTIONAL) != 0 && is_Optional() )
+	{
+		SEPARATE;
+		s.Append(CSG_String::Format(SG_T("%s"), LNG("optional")));
+	}
+
+	//-----------------------------------------------------
+	if( (Flags & PARAMETER_DESCRIPTION_PROPERTIES) != 0 )
+	{
+		switch( Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Choice:
+			SEPARATE;
+
+			s.Append(CSG_String::Format(SG_T("%s:"), LNG("Available Choices")));
+
+			for(i=0; i<asChoice()->Get_Count(); i++)
+			{
+				s.Append(CSG_String::Format(SG_T("%s[%d] %s"), Separator, i, asChoice()->Get_Item(i)));
+			}
+			break;
+
+		case PARAMETER_TYPE_Int:
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+//		case PARAMETER_TYPE_Range:
+			if( asValue()->has_Minimum() && asValue()->has_Maximum() )
+			{
+				SEPARATE;
+				s.Append(CSG_String::Format(SG_T("%s: %f - %f"), LNG("Value Range"), asValue()->Get_Minimum(), asValue()->Get_Maximum()));
+			}
+			else if( asValue()->has_Minimum() )
+			{
+				SEPARATE;
+				s.Append(CSG_String::Format(SG_T("%s: %f"), LNG("Minimum"), asValue()->Get_Minimum()));
+			}
+			else if( asValue()->has_Maximum() )
+			{
+				SEPARATE;
+				s.Append(CSG_String::Format(SG_T("%s: %f"), LNG("Maximum"), asValue()->Get_Maximum()));
+			}
+			break;
+
+		case PARAMETER_TYPE_FixedTable:
+			SEPARATE;
+
+			s.Append(CSG_String::Format(SG_T("%d %s:%s"), asTable()->Get_Field_Count(), LNG("Fields"), Separator));
+
+			for(i=0; i<asTable()->Get_Field_Count(); i++)
+			{
+				s.Append(CSG_String::Format(SG_T("- %d. [%s] %s%s"), i + 1, SG_Data_Type_Get_Name(asTable()->Get_Field_Type(i)), asTable()->Get_Field_Name(i), Separator));
+			}
+			break;
+
+		case PARAMETER_TYPE_Parameters:
+			SEPARATE;
+
+			s.Append(CSG_String::Format(SG_T("%d %s:%s"), asParameters()->Get_Count(), LNG("Parameters"), Separator));
+
+			for(i=0; i<asParameters()->Get_Count(); i++)
+			{
+				s.Append(CSG_String::Format(SG_T("- %d. %s%s"), i + 1, asParameters()->Get_Parameter(i)->Get_Description(Flags, Separator).c_str(), Separator));
+			}
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	if( (Flags & PARAMETER_DESCRIPTION_TEXT) != 0 && m_Description.Length() > 0 )
+	{
+		SEPARATE;
+		s.Append(m_Description.c_str());
+	}
+
+	//-----------------------------------------------------
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameter::Set_Value(int Value)
+{
+	if( m_pData->Set_Value(Value) )
+	{
+		has_Changed();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::Set_Value(double Value)
+{
+	if( m_pData->Set_Value(Value) )
+	{
+		has_Changed();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::Set_Value(void *Value)
+{
+	if( m_pData->Set_Value(Value) )
+	{
+		has_Changed();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::Set_Value(const SG_Char *Value)
+{
+	return( Set_Value((void *)Value) );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter::has_Changed(void)
+{
+	if( m_pOwner )
+	{
+		return( m_pOwner->_On_Parameter_Changed(this) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameter::Assign(CSG_Parameter *pSource)
+{
+	return( m_pData->Assign(pSource->m_pData) );
+}
+
+//---------------------------------------------------------
+CSG_MetaData * CSG_Parameter::Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		if( !is_Information() && Get_Type() != PARAMETER_TYPE_Node && Get_Type() != PARAMETER_TYPE_Undefined )
+		{
+			CSG_MetaData	*pEntry	= Entry.Add_Child(
+				is_Option()          ? SG_T("OPTION")    :
+				is_DataObject()      ? SG_T("DATA")      :
+				is_DataObject_List() ? SG_T("DATA_LIST") :
+				                       SG_T("PARAMETER")
+			);
+
+			pEntry->Add_Property(SG_T("type"), Get_Type_Identifier());
+			pEntry->Add_Property(SG_T("id")  , Get_Identifier());
+			pEntry->Add_Property(SG_T("name"), Get_Name());
+
+			m_pData->Serialize(*pEntry, bSave);
+
+			return( pEntry );
+		}
+	}
+	else
+	{
+		if(	Entry.Cmp_Property(SG_T("type"), Get_Type_Identifier())
+		&&	Entry.Cmp_Property(SG_T("id")  , Get_Identifier()) )
+		{
+			return( m_pData->Serialize(Entry, bSave) ? &Entry : NULL );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter_data.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter_data.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/parameter_data.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,2274 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  parameter_data.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SG_MD_PARM_DATAOBJECT_CREATE		SG_T("CREATE")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * SG_Parameter_Type_Get_Identifier(TSG_Parameter_Type Type)
+{
+	switch( Type )
+	{
+	default:								return( SG_T("parameter") );
+
+	case PARAMETER_TYPE_Node:				return( SG_T("node") );
+
+	case PARAMETER_TYPE_Bool:				return( SG_T("boolean") );
+	case PARAMETER_TYPE_Int:				return( SG_T("integer") );
+	case PARAMETER_TYPE_Double:				return( SG_T("double") );
+	case PARAMETER_TYPE_Degree:				return( SG_T("degree") );
+	case PARAMETER_TYPE_Range:				return( SG_T("range") );
+	case PARAMETER_TYPE_Choice:				return( SG_T("choice") );
+
+	case PARAMETER_TYPE_String:				return( SG_T("text") );
+	case PARAMETER_TYPE_Text:				return( SG_T("long_text") );
+	case PARAMETER_TYPE_FilePath:			return( SG_T("file") );
+
+	case PARAMETER_TYPE_Font:				return( SG_T("font") );
+	case PARAMETER_TYPE_Color:				return( SG_T("color") );
+	case PARAMETER_TYPE_Colors:				return( SG_T("colors") );
+	case PARAMETER_TYPE_FixedTable:			return( SG_T("static_table") );
+	case PARAMETER_TYPE_Grid_System:		return( SG_T("grid_system") );
+	case PARAMETER_TYPE_Table_Field:		return( SG_T("table_field") );
+
+	case PARAMETER_TYPE_DataObject_Output:	return( SG_T("data_object") );
+	case PARAMETER_TYPE_Grid:				return( SG_T("grid") );
+	case PARAMETER_TYPE_Table:				return( SG_T("table") );
+	case PARAMETER_TYPE_Shapes:				return( SG_T("shapes") );
+	case PARAMETER_TYPE_TIN:				return( SG_T("tin") );
+	case PARAMETER_TYPE_PointCloud:			return( SG_T("points") );
+
+	case PARAMETER_TYPE_Grid_List:			return( SG_T("grid_list") );
+	case PARAMETER_TYPE_Table_List:			return( SG_T("table_list") );
+	case PARAMETER_TYPE_Shapes_List:		return( SG_T("shapes_list") );
+	case PARAMETER_TYPE_TIN_List:			return( SG_T("tin_list") );
+	case PARAMETER_TYPE_PointCloud_List:	return( SG_T("points_list") );
+
+	case PARAMETER_TYPE_Parameters:			return( SG_T("parameters") );
+	}
+}
+
+//---------------------------------------------------------
+const SG_Char * SG_Parameter_Type_Get_Name(TSG_Parameter_Type Type)
+{
+	switch( Type )
+	{
+	default:								return( LNG("[PRM] Parameter") );
+
+	case PARAMETER_TYPE_Node:				return( LNG("[PRM] Node") );
+
+	case PARAMETER_TYPE_Bool:				return( LNG("[PRM] Boolean") );
+	case PARAMETER_TYPE_Int:				return( LNG("[PRM] Integer") );
+	case PARAMETER_TYPE_Double:				return( LNG("[PRM] Floating point") );
+	case PARAMETER_TYPE_Degree:				return( LNG("[PRM] Degree") );
+	case PARAMETER_TYPE_Range:				return( LNG("[PRM] Value range") );
+	case PARAMETER_TYPE_Choice:				return( LNG("[PRM] Choice") );
+
+	case PARAMETER_TYPE_String:				return( LNG("[PRM] Text") );
+	case PARAMETER_TYPE_Text:				return( LNG("[PRM] Long text") );
+	case PARAMETER_TYPE_FilePath:			return( LNG("[PRM] File path") );
+
+	case PARAMETER_TYPE_Font:				return( LNG("[PRM] Font") );
+	case PARAMETER_TYPE_Color:				return( LNG("[PRM] Color") );
+	case PARAMETER_TYPE_Colors:				return( LNG("[PRM] Colors") );
+	case PARAMETER_TYPE_FixedTable:			return( LNG("[PRM] Static table") );
+	case PARAMETER_TYPE_Grid_System:		return( LNG("[PRM] Grid system") );
+	case PARAMETER_TYPE_Table_Field:		return( LNG("[PRM] Table field") );
+
+	case PARAMETER_TYPE_DataObject_Output:	return( LNG("[PRM] Data Object") );
+	case PARAMETER_TYPE_Grid:				return( LNG("[PRM] Grid") );
+	case PARAMETER_TYPE_Table:				return( LNG("[PRM] Table") );
+	case PARAMETER_TYPE_Shapes:				return( LNG("[PRM] Shapes") );
+	case PARAMETER_TYPE_TIN:				return( LNG("[PRM] TIN") );
+	case PARAMETER_TYPE_PointCloud:			return( LNG("[PRM] Point Cloud") );
+
+	case PARAMETER_TYPE_Grid_List:			return( LNG("[PRM] Grid list") );
+	case PARAMETER_TYPE_Table_List:			return( LNG("[PRM] Table list") );
+	case PARAMETER_TYPE_Shapes_List:		return( LNG("[PRM] Shapes list") );
+	case PARAMETER_TYPE_TIN_List:			return( LNG("[PRM] TIN list") );
+	case PARAMETER_TYPE_PointCloud_List:	return( LNG("[PRM] Point Cloud list") );
+
+	case PARAMETER_TYPE_Parameters:			return( LNG("[PRM] Parameters") );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Base Class						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Data::CSG_Parameter_Data(CSG_Parameter *pOwner, long Constraint)
+{
+	m_pOwner		= pOwner;
+	m_Constraint	= Constraint;
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Data::Get_Type_Identifier(void)
+{
+	return( SG_Parameter_Type_Get_Identifier(Get_Type()) );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Data::Get_Type_Name(void)
+{
+	return( SG_Parameter_Type_Get_Name(Get_Type()) );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data::Set_Value(int Value)
+{
+	return( false );
+}
+
+bool CSG_Parameter_Data::Set_Value(double Value)
+{
+	return( false );
+}
+
+bool CSG_Parameter_Data::Set_Value(void *Value)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+int CSG_Parameter_Data::asInt(void)
+{
+	return( 0 );
+}
+
+double CSG_Parameter_Data::asDouble(void)
+{
+	return( 0.0 );
+}
+
+void * CSG_Parameter_Data::asPointer(void)
+{
+	return( NULL );
+}
+
+const SG_Char * CSG_Parameter_Data::asString(void)
+{
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data::Assign(CSG_Parameter_Data *pSource)
+{
+	if( pSource && Get_Type() == pSource->Get_Type() )
+	{
+		On_Assign(pSource);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+void CSG_Parameter_Data::On_Assign(CSG_Parameter_Data *pSource)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data::Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	return( On_Serialize(Entry, bSave) );
+}
+
+bool CSG_Parameter_Data::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	Entry.Set_Content(SG_T("-"));
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Node							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Node::CSG_Parameter_Node(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Bool							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Bool::CSG_Parameter_Bool(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_Value		= false;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Bool::Set_Value(int Value)
+{
+	bool	bValue = Value != 0 ? true : false;
+
+	if( m_Value != bValue )
+	{
+		m_Value		= bValue;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_Parameter_Bool::Set_Value(double Value)
+{
+	return( Set_Value((int)Value) );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Bool::asString(void)
+{
+	return( m_Value ? LNG("[VAL] yes") : LNG("[VAL] no") );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Bool::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_Value		= ((CSG_Parameter_Bool *)pSource)->m_Value;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Bool::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Set_Content(m_Value ? SG_T("TRUE") : SG_T("FALSE"));
+	}
+	else
+	{
+		m_Value	= Entry.Cmp_Content(SG_T("TRUE"), true);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Value							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Value::CSG_Parameter_Value(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_Minimum	= 0.0;
+	m_bMinimum	= false;
+
+	m_Maximum	= 0.0;
+	m_bMaximum	= false;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Value::Set_Range(double Minimum, double Maximum)
+{
+	if( 1 )
+	{
+		m_Minimum		= Minimum;
+		m_Maximum		= Maximum;
+
+		switch( Get_Type() )
+		{
+		default:
+			return( false );
+
+		case PARAMETER_TYPE_Int:
+			Set_Value(asInt());
+			break;
+
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+			Set_Value(asDouble());
+			break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Value::Set_Minimum(double Minimum, bool bOn)
+{
+	if( bOn == false || (m_bMaximum && Minimum >= m_Maximum) )
+	{
+		m_bMinimum	= false;
+	}
+	else
+	{
+		m_bMinimum	= true;
+
+		Set_Range(Minimum, m_Maximum);
+	}
+}
+
+void CSG_Parameter_Value::Set_Maximum(double Maximum, bool bOn)
+{
+	if( bOn == false || (m_bMaximum && Maximum <= m_Minimum) )
+	{
+		m_bMaximum	= false;
+	}
+	else
+	{
+		m_bMaximum	= true;
+
+		Set_Range(m_Minimum, Maximum);
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Value::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_Minimum	= ((CSG_Parameter_Value *)pSource)->m_Minimum;
+	m_bMinimum	= ((CSG_Parameter_Value *)pSource)->m_bMinimum;
+
+	m_Maximum	= ((CSG_Parameter_Value *)pSource)->m_Maximum;
+	m_bMaximum	= ((CSG_Parameter_Value *)pSource)->m_bMaximum;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Int								 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Int::CSG_Parameter_Int(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Value(pOwner, Constraint)
+{
+	m_Value		= 0;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Int::Set_Value(int Value)
+{
+	if( m_bMinimum && Value < m_Minimum )
+	{
+		return( Set_Value((int)m_Minimum) );
+	}
+
+	if( m_bMaximum && Value > m_Maximum )
+	{
+		return( Set_Value((int)m_Maximum) );
+	}
+
+	if( m_Value != Value )
+	{
+		m_Value	= Value;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_Parameter_Int::Set_Value(double Value)
+{
+	return( Set_Value((int)Value) );
+}
+
+bool CSG_Parameter_Int::Set_Value(void *Value)
+{
+	int		i;
+
+	if( Value && CSG_String((SG_Char *)Value).asInt(i) )
+	{
+		return( Set_Value(i) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Int::asString(void)
+{
+	m_String.Printf(SG_T("%d"), m_Value);
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Int::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_Value::On_Assign(pSource);
+
+	Set_Value(((CSG_Parameter_Value *)pSource)->asInt());
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Int::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Set_Content(CSG_String::Format(SG_T("%d"), m_Value));
+	}
+	else
+	{
+		return( Entry.Get_Content().asInt(m_Value) );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Double							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Double::CSG_Parameter_Double(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Value(pOwner, Constraint)
+{
+	m_Value		= 0.0;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Double::Set_Value(int Value)
+{
+	return( Set_Value((double)Value) );
+}
+
+bool CSG_Parameter_Double::Set_Value(double Value)
+{
+	if( m_bMinimum && Value < m_Minimum )
+	{
+		return( Set_Value(m_Minimum) );
+	}
+
+	if( m_bMaximum && Value > m_Maximum )
+	{
+		return( Set_Value(m_Maximum) );
+	}
+
+	if( m_Value != Value )
+	{
+		m_Value	= Value;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_Parameter_Double::Set_Value(void *Value)
+{
+	double	d;
+
+	if( Value && CSG_String((SG_Char *)Value).asDouble(d) )
+	{
+		return( Set_Value(d) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Double::asString(void)
+{
+	m_String.Printf(SG_T("%f"), m_Value);
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Double::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_Value::On_Assign(pSource);
+
+	Set_Value(((CSG_Parameter_Value *)pSource)->asDouble());
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Double::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Set_Content(CSG_String::Format(SG_T("%f"), m_Value));
+	}
+	else
+	{
+		return( Entry.Get_Content().asDouble(m_Value) );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Degree							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Degree::CSG_Parameter_Degree(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Double(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Degree::Set_Value(void *Value)
+{
+	return( CSG_Parameter_Double::Set_Value(SG_Degree_To_Double((const SG_Char *)Value)) );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Degree::asString(void)
+{
+	m_String	= SG_Double_To_Degree(asDouble());
+
+	return( m_String );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Range							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Range::CSG_Parameter_Range(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	pRange	= new CSG_Parameters;
+
+	if( (m_Constraint & PARAMETER_INFORMATION) != 0 )
+	{
+		pLo		= pRange->Add_Info_Value(m_pOwner, SG_T("MIN"), SG_T("Minimum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
+		pHi		= pRange->Add_Info_Value(m_pOwner, SG_T("MAX"), SG_T("Maximum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
+	}
+	else
+	{
+		pLo		= pRange->Add_Value		(m_pOwner, SG_T("MIN"), SG_T("Minimum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
+		pHi		= pRange->Add_Value		(m_pOwner, SG_T("MAX"), SG_T("Maximum"), m_pOwner->Get_Description(), PARAMETER_TYPE_Double);
+	}
+}
+
+CSG_Parameter_Range::~CSG_Parameter_Range(void)
+{
+	delete(pRange);
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Range::asString(void)
+{
+	m_String.Printf(SG_T("[%f] - [%f]"),
+		Get_LoParm()->asDouble(),
+		Get_HiParm()->asDouble()
+	);
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Range::Set_Range(double loVal, double hiVal)
+{
+	bool	bResult;
+
+	if( loVal > hiVal )
+	{
+		bResult	 = pLo->Set_Value(hiVal);
+		bResult	|= pHi->Set_Value(loVal);
+	}
+	else
+	{
+		bResult	 = pLo->Set_Value(loVal);
+		bResult	|= pHi->Set_Value(hiVal);
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Range::Set_LoVal(double newValue)
+{
+	return( pLo->Set_Value(newValue) );
+}
+
+double CSG_Parameter_Range::Get_LoVal(void)
+{
+	return( pLo->asDouble() );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Range::Set_HiVal(double newValue)
+{
+	return( pHi->Set_Value(newValue) );
+}
+
+double CSG_Parameter_Range::Get_HiVal(void)
+{
+	return( pHi->asDouble() );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Range::On_Assign(CSG_Parameter_Data *pSource)
+{
+	pLo->Assign(((CSG_Parameter_Range *)pSource)->pLo);
+	pHi->Assign(((CSG_Parameter_Range *)pSource)->pHi);
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Range::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Set_Content(CSG_String::Format(SG_T("%f; %f"), Get_LoVal(), Get_HiVal()));
+
+		return( true );
+	}
+	else
+	{
+		double		loVal, hiVal;
+		CSG_String	s(Entry.Get_Content());
+
+		if( s.BeforeFirst(SG_T(';')).asDouble(loVal) && s.AfterFirst(SG_T(';')).asDouble(hiVal) )
+		{
+			return( Set_Range(loVal, hiVal) );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Choice							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Choice::CSG_Parameter_Choice(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Int(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Choice::Set_Value(void *Value)
+{
+	if( Value && *((SG_Char *)Value) )
+	{
+		for(int i=0; i<Items.Get_Count(); i++)
+		{
+			if( Items[i].Cmp((SG_Char *)Value) == 0 )
+			{
+				m_Value	= i;
+
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Choice::asString(void)
+{
+	if( m_Value >= 0 && m_Value < Items.Get_Count() )
+	{
+		return( Items[m_Value].c_str() );
+	}
+
+	return( LNG("[VAL] [no choice available]") );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Choice::Set_Items(const SG_Char *String)
+{
+	Items.Clear();
+
+	const SG_Char	*s	= String;
+
+	while( s && *s != 0 )
+	{
+		CSG_String	Item	= CSG_String(s).BeforeFirst('|');
+
+		Items	+= Item;
+		s		+= Item.Length() + 1;
+	}
+
+	if( Items.Get_Count() <= 0 )
+	{
+		Items	+= LNG("[VAL] [not set]");
+	}
+
+	Set_Minimum(              0, true);
+	Set_Maximum(Get_Count() - 1, true);
+
+	CSG_Parameter_Int::Set_Value(m_Value);
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Choice::Get_Item(int Index)
+{
+	if( Index >= 0 && Index < Items.Get_Count() )
+	{
+		return( Items[Index].c_str() );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Choice::On_Assign(CSG_Parameter_Data *pSource)
+{
+	Items	= ((CSG_Parameter_Choice *)pSource)->Items;
+
+	CSG_Parameter_Int::On_Assign(pSource);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						String							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_String::CSG_Parameter_String(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	bPassword	= false;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_String::is_Valid(void)
+{
+	return( m_String.Length() > 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_String::is_Password(void)
+{
+	return( bPassword );
+}
+
+void CSG_Parameter_String::Set_Password(bool bOn)
+{
+	bPassword	= bOn;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_String::Set_Value(void *Value)
+{
+	if( Value )
+	{
+		if( m_String.Cmp((SG_Char *)Value) )
+		{
+			m_String.Printf((SG_Char *)Value);
+
+			return( true );
+		}
+	}
+	else if( m_String.Length() > 0 )
+	{
+		m_String.Clear();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_String::asString(void)
+{
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_String::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_String.Printf(((CSG_Parameter_String *)pSource)->m_String.c_str());
+
+	bPassword	= ((CSG_Parameter_String *)pSource)->bPassword;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_String::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Set_Content(m_String);
+	}
+	else
+	{
+		m_String	= Entry.Get_Content();
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Text							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Text::CSG_Parameter_Text(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_String(pOwner, Constraint)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						FilePath						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_File_Name::CSG_Parameter_File_Name(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_String(pOwner, Constraint)
+{
+	m_Filter.Printf(SG_T("%s|*.*"), LNG("All Files"));
+
+	m_bSave			= false;
+	m_bMultiple		= false;
+	m_bDirectory	= false;
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_File_Name::Set_Filter(const SG_Char *Filter)
+{
+	if( Filter )
+	{
+		m_Filter	= Filter;
+	}
+	else
+	{
+		m_Filter.Printf(SG_T("%s|*.*"), LNG("All Files"));
+	}
+}
+
+const SG_Char *  CSG_Parameter_File_Name::Get_Filter(void)
+{
+	return( m_Filter.c_str() );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_File_Name::Set_Flag_Save(bool bFlag)
+{
+	m_bSave			= bFlag;
+}
+
+void CSG_Parameter_File_Name::Set_Flag_Multiple(bool bFlag)
+{
+	m_bMultiple		= bFlag;
+}
+
+void CSG_Parameter_File_Name::Set_Flag_Directory(bool bFlag)
+{
+	m_bDirectory	= bFlag;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_File_Name::Get_FilePaths(CSG_Strings &FilePaths)
+{
+	FilePaths.Clear();
+
+	if( m_String.Length() > 0 )
+	{
+		if( !m_bMultiple )
+		{
+			FilePaths.Add(m_String);
+		}
+		else if( m_String[0] != '\"' )
+		{
+			FilePaths.Add(m_String);
+		}
+		else
+		{
+			CSG_String	s(m_String), sTmp;
+
+			while( s.Length() > 2 )
+			{
+				s	= s.AfterFirst('\"');
+				FilePaths.Add(s.BeforeFirst('\"'));
+				s	= s.AfterFirst('\"');
+			}
+		}
+	}
+
+	return( FilePaths.Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_File_Name::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_String::On_Assign(pSource);
+
+	Set_Filter(((CSG_Parameter_File_Name *)pSource)->m_Filter.c_str());
+
+	m_bSave			= ((CSG_Parameter_File_Name *)pSource)->m_bSave;
+	m_bMultiple		= ((CSG_Parameter_File_Name *)pSource)->m_bMultiple;
+	m_bDirectory	= ((CSG_Parameter_File_Name *)pSource)->m_bDirectory;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Font							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/font.h>
+
+//---------------------------------------------------------
+CSG_Parameter_Font::CSG_Parameter_Font(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_pFont		= new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL);
+	m_Color		= SG_GET_RGB(0, 0, 0);
+}
+
+CSG_Parameter_Font::~CSG_Parameter_Font(void)
+{
+	delete(m_pFont);
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Font::Set_Value(int Value)
+{
+	if( m_Color != Value )
+	{
+		m_Color		= Value;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CSG_Parameter_Font::Set_Value(void *Value)
+{
+	if( Value )
+	{
+		*m_pFont	= *((class wxFont *)Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Font::asString(void)
+{
+	m_String.Printf(SG_T("%s, %dpt"), m_pFont->GetFaceName().c_str(), m_pFont->GetPointSize());
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Font::On_Assign(CSG_Parameter_Data *pSource)
+{
+	Set_Value(pSource->asPointer());
+	Set_Value(pSource->asInt());
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Font::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Add_Child(SG_T("COLOR")		, CSG_String::Format(SG_T("R%03d G%03d B%03d"), SG_GET_R(m_Color), SG_GET_G(m_Color), SG_GET_B(m_Color)));
+		Entry.Add_Child(SG_T("POINTSIZE")	, CSG_String::Format(SG_T("%d"), m_pFont->GetPointSize()));
+		Entry.Add_Child(SG_T("FACENAME")	, m_pFont->GetFaceName().c_str());
+		Entry.Add_Child(SG_T("UNDERLINED")	, m_pFont->GetUnderlined() ? SG_T("TRUE") : SG_T("FALSE"));
+
+		switch( m_pFont->GetFamily() )
+		{
+		default:
+		case wxFONTFAMILY_DEFAULT:		Entry.Add_Child(SG_T("FAMILY")	, SG_T("DEFAULT"));		break;
+		case wxFONTFAMILY_DECORATIVE:	Entry.Add_Child(SG_T("FAMILY")	, SG_T("DECORATIVE"));	break;
+		case wxFONTFAMILY_ROMAN:		Entry.Add_Child(SG_T("FAMILY")	, SG_T("ROMAN"));		break;
+		case wxFONTFAMILY_SCRIPT:		Entry.Add_Child(SG_T("FAMILY")	, SG_T("SCRIPT"));		break;
+		case wxFONTFAMILY_SWISS:		Entry.Add_Child(SG_T("FAMILY")	, SG_T("SWISS"));		break;
+		case wxFONTFAMILY_MODERN:		Entry.Add_Child(SG_T("FAMILY")	, SG_T("MODERN"));		break;
+		case wxFONTFAMILY_TELETYPE:		Entry.Add_Child(SG_T("FAMILY")	, SG_T("TELETYPE"));	break;
+		}
+
+		switch( m_pFont->GetStyle() )
+		{
+		default:
+		case wxFONTSTYLE_NORMAL:		Entry.Add_Child(SG_T("STYLE")	, SG_T("NORMAL"));		break;
+		case wxFONTSTYLE_SLANT:			Entry.Add_Child(SG_T("STYLE")	, SG_T("SLANT"));		break;
+		case wxFONTSTYLE_ITALIC:		Entry.Add_Child(SG_T("STYLE")	, SG_T("ITALIC"));		break;
+		}
+
+		switch( m_pFont->GetStyle() )
+		{
+		default:
+		case wxFONTWEIGHT_NORMAL:		Entry.Add_Child(SG_T("WEIGHT")	, SG_T("NORMAL"));		break;
+		case wxFONTWEIGHT_LIGHT:		Entry.Add_Child(SG_T("WEIGHT")	, SG_T("LIGHT"));		break;
+		case wxFONTWEIGHT_BOLD:			Entry.Add_Child(SG_T("WEIGHT")	, SG_T("BOLD"));		break;
+		}
+	}
+	else
+	{
+		int				i;
+		CSG_MetaData	*pEntry;
+
+		if( (pEntry = Entry.Get_Child(SG_T("COLOR"))) != NULL )
+		{
+			m_Color	= SG_GET_RGB(
+				Entry.Get_Content().AfterFirst(SG_T('R')).asInt(),
+				Entry.Get_Content().AfterFirst(SG_T('G')).asInt(),
+				Entry.Get_Content().AfterFirst(SG_T('B')).asInt()
+			);
+		}
+
+		if( (pEntry = Entry.Get_Child(SG_T("POINTSIZE"))) != NULL && pEntry->Get_Content().asInt(i) )
+		{
+			m_pFont->SetPointSize(i);
+		}
+
+		if( (pEntry = Entry.Get_Child(SG_T("FACENAME"))) != NULL )
+		{
+			m_pFont->SetFaceName(pEntry->Get_Content().c_str());
+		}
+
+		if( (pEntry = Entry.Get_Child(SG_T("UNDERLINED"))) != NULL )
+		{
+			m_pFont->SetUnderlined(pEntry->Cmp_Content(SG_T("TRUE")));
+		}
+
+		if( (pEntry = Entry.Get_Child(SG_T("FAMILY"))) != NULL )
+		{
+			m_pFont->SetFamily(
+				pEntry->Cmp_Content(SG_T("TELETYPE"))	? wxFONTFAMILY_TELETYPE		:
+				pEntry->Cmp_Content(SG_T("MODERN"))		? wxFONTFAMILY_MODERN		:
+				pEntry->Cmp_Content(SG_T("SWISS"))		? wxFONTFAMILY_SWISS		:
+				pEntry->Cmp_Content(SG_T("SCRIPT"))		? wxFONTFAMILY_SCRIPT		:
+				pEntry->Cmp_Content(SG_T("ROMAN"))		? wxFONTFAMILY_ROMAN		:
+				pEntry->Cmp_Content(SG_T("DECORATIVE"))	? wxFONTFAMILY_DECORATIVE	: wxFONTFAMILY_DEFAULT
+			);
+		}
+
+		if( (pEntry = Entry.Get_Child(SG_T("STYLE"))) != NULL )
+		{
+			m_pFont->SetStyle(
+				pEntry->Cmp_Content(SG_T("SLANT"))		? wxFONTSTYLE_SLANT			:
+				pEntry->Cmp_Content(SG_T("ITALIC"))		? wxFONTSTYLE_ITALIC		: wxFONTSTYLE_NORMAL
+			);
+		}
+
+		if( (pEntry = Entry.Get_Child(SG_T("WEIGHT"))) != NULL )
+		{
+			m_pFont->SetWeight(
+				pEntry->Cmp_Content(SG_T("BOLD"))		? wxFONTWEIGHT_BOLD			:
+				pEntry->Cmp_Content(SG_T("LIGHT"))		? wxFONTWEIGHT_LIGHT		: wxFONTWEIGHT_NORMAL
+			);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Color							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Color::CSG_Parameter_Color(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Int(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Color::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Set_Content(SG_T("R%03d G%03d B%03d"), SG_GET_R(m_Value), SG_GET_G(m_Value), SG_GET_B(m_Value));
+	}
+	else
+	{
+		m_Value	= SG_GET_RGB(
+			Entry.Get_Content().AfterFirst(SG_T('R')).asInt(),
+			Entry.Get_Content().AfterFirst(SG_T('G')).asInt(),
+			Entry.Get_Content().AfterFirst(SG_T('B')).asInt()
+		);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Colors							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Colors::CSG_Parameter_Colors(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Colors::asString(void)
+{
+	m_String.Printf(SG_T("%d %s"), m_Colors.Get_Count(), LNG("colors"));
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Colors::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_Colors.Assign(&((CSG_Parameter_Colors *)pSource)->m_Colors);
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Colors::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		for(int i=0; i<m_Colors.Get_Count(); i++)
+		{
+			Entry.Add_Child(SG_T("COLOR"), CSG_String::Format(SG_T("R%03d G%03d B%03d"), m_Colors.Get_Red(i), m_Colors.Get_Green(i), m_Colors.Get_Blue(i)));
+		}
+	}
+	else
+	{
+		if( Entry.Get_Children_Count() <= 1 )
+		{
+			return( false );
+		}
+
+		m_Colors.Set_Count(Entry.Get_Children_Count());
+
+		for(int i=0; i<m_Colors.Get_Count(); i++)
+		{
+			CSG_String	s(Entry.Get_Child(i)->Get_Content());
+
+			m_Colors.Set_Red  (i, s.AfterFirst(SG_T('R')).asInt());
+			m_Colors.Set_Green(i, s.AfterFirst(SG_T('G')).asInt());
+			m_Colors.Set_Blue (i, s.AfterFirst(SG_T('B')).asInt());
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						FixedTable						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Fixed_Table::CSG_Parameter_Fixed_Table(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_Table.Set_Name(LNG("Table"));
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Fixed_Table::asString(void)
+{
+	m_String.Printf(SG_T("%s (%s: %d, %s: %d)"), m_Table.Get_Name(), LNG("columns"), m_Table.Get_Field_Count(), LNG("rows"), m_Table.Get_Record_Count());
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Fixed_Table::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_Table.Assign(&((CSG_Parameter_Fixed_Table *)pSource)->m_Table);
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Fixed_Table::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	int				iField, iRecord;
+	CSG_MetaData	*pNode, *pEntry;
+
+	if( bSave )
+	{
+		pNode	= Entry.Add_Child(SG_T("FIELDS"));
+
+		for(iField=0; iField<m_Table.Get_Field_Count(); iField++)
+		{
+			pEntry	= pNode->Add_Child	(SG_T("FIELD")	, m_Table.Get_Field_Name(iField));
+			pEntry	->Set_Property		(SG_T("type")	, gSG_Data_Type_Identifier[m_Table.Get_Field_Type(iField)]);
+		}
+
+		pNode	= Entry.Add_Child(SG_T("RECORDS"));
+
+		for(iRecord=0; iRecord<m_Table.Get_Count(); iRecord++)
+		{
+			pEntry	= pNode->Add_Child(SG_T("RECORD"));
+
+			for(iField=0; iField<m_Table.Get_Field_Count(); iField++)
+			{
+				pEntry->Add_Child(SG_T("FIELD"), m_Table[iRecord].asString(iField));
+			}
+		}
+	}
+	else
+	{
+		CSG_Table	t;
+
+		if( (pNode = Entry.Get_Child(SG_T("FIELDS"))) == NULL )
+		{
+			return( false );
+		}
+
+		for(iField=0; iField<pNode->Get_Children_Count(); iField++)
+		{
+			CSG_String		s;
+			TSG_Data_Type	type	= SG_DATATYPE_String;
+
+			if( pNode->Get_Child(iField)->Get_Property(SG_T("type"), s) )
+			{
+				     if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Bit   ]) )	type	= SG_DATATYPE_Bit;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Byte  ]) )	type	= SG_DATATYPE_Byte;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Char  ]) )	type	= SG_DATATYPE_Char;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Word  ]) )	type	= SG_DATATYPE_Word;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Short ]) )	type	= SG_DATATYPE_Short;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_DWord ]) )	type	= SG_DATATYPE_DWord;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Int   ]) )	type	= SG_DATATYPE_Int;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_ULong ]) )	type	= SG_DATATYPE_ULong;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Long  ]) )	type	= SG_DATATYPE_Long;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Float ]) )	type	= SG_DATATYPE_Float;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Double]) )	type	= SG_DATATYPE_Double;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_String]) )	type	= SG_DATATYPE_String;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Date  ]) )	type	= SG_DATATYPE_Date;
+				else if( !s.Cmp(gSG_Data_Type_Identifier[SG_DATATYPE_Color ]) )	type	= SG_DATATYPE_Color;
+			}
+
+			t.Add_Field(pNode->Get_Child(iField)->Get_Content(), type);
+		}
+
+		if( (pNode = Entry.Get_Child(SG_T("RECORDS"))) == NULL )
+		{
+			return( false );
+		}
+
+		for(iRecord=0; iRecord<pNode->Get_Children_Count(); iRecord++)
+		{
+			pEntry	= pNode->Get_Child(iRecord);
+
+			t.Add_Record();
+
+			for(iField=0; iField<pEntry->Get_Children_Count(); iField++)
+			{
+				t[iRecord].Set_Value(iField, pEntry->Get_Child(iField)->Get_Content());
+			}
+		}
+
+		return( m_Table.Assign_Values(&t) );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Grid_System						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Grid_System::CSG_Parameter_Grid_System(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Grid_System::Set_Value(void *Value)
+{
+	int						i, j;
+	CSG_Grid				*pGrid;
+	CSG_Grid_System			Invalid;
+	CSG_Parameters			*pParameters;
+	CSG_Parameter_Grid_List	*pGrids;
+
+	//-----------------------------------------------------
+	if( Value == NULL )
+	{
+		Value	= &Invalid;
+	}
+
+	//-----------------------------------------------------
+	if( !m_System.is_Equal(*((CSG_Grid_System *)Value)) )
+	{
+		m_System.Assign(*((CSG_Grid_System *)Value));
+
+		//-------------------------------------------------
+		pParameters	= m_pOwner->Get_Owner();
+
+		for(i=0; i<pParameters->Get_Count(); i++)
+		{
+			if(	pParameters->Get_Parameter(i)->Get_Parent() == m_pOwner )
+			{
+				switch( pParameters->Get_Parameter(i)->Get_Type() )
+				{
+				default:
+					break;
+
+				case PARAMETER_TYPE_Grid:
+					pGrid	= pParameters->Get_Parameter(i)->asGrid();
+
+					if(	!SG_UI_DataObject_Check(pGrid, DATAOBJECT_TYPE_Grid) || (pGrid != DATAOBJECT_NOTSET && pGrid != DATAOBJECT_CREATE && !m_System.is_Equal(pGrid->Get_System())) )
+					{
+						pParameters->Get_Parameter(i)->Set_Value(DATAOBJECT_NOTSET);
+					}
+					break;
+
+				case PARAMETER_TYPE_Grid_List:
+					pGrids	= (CSG_Parameter_Grid_List *)pParameters->Get_Parameter(i)->Get_Data();
+
+					for(j=pGrids->Get_Count()-1; j>=0; j--)
+					{
+						if( !SG_UI_DataObject_Check(pGrids->asGrid(j), DATAOBJECT_TYPE_Grid) || m_System.is_Equal(pGrids->asGrid(j)->Get_System()) == false )
+						{
+							pGrids->Del_Item(j);
+						}
+					}
+					break;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Grid_System::asString(void)
+{
+	return( m_System.Get_Name() );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Grid_System::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_System	= ((CSG_Parameter_Grid_System *)pSource)->m_System;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Grid_System::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		Entry.Add_Child(SG_T("CELLSIZE"), m_System.Get_Cellsize());
+		Entry.Add_Child(SG_T("XMIN")    , m_System.Get_Extent().Get_XMin());
+		Entry.Add_Child(SG_T("XMAX")    , m_System.Get_Extent().Get_XMax());
+		Entry.Add_Child(SG_T("YMIN")    , m_System.Get_Extent().Get_YMin());
+		Entry.Add_Child(SG_T("YMAX")    , m_System.Get_Extent().Get_YMax());
+	}
+	else
+	{
+		double		Cellsize;
+		TSG_Rect	Extent;
+
+		Cellsize	= Entry.Get_Child(SG_T("CELLSIZE"))->Get_Content().asDouble();
+		Extent.xMin	= Entry.Get_Child(SG_T("XMIN"))    ->Get_Content().asDouble();
+		Extent.xMax	= Entry.Get_Child(SG_T("XMAX"))    ->Get_Content().asDouble();
+		Extent.yMin	= Entry.Get_Child(SG_T("YMIN"))    ->Get_Content().asDouble();
+		Extent.yMax	= Entry.Get_Child(SG_T("YMAX"))    ->Get_Content().asDouble();
+
+		m_System.Assign(Cellsize, CSG_Rect(Extent));
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Table Field							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Table_Field::CSG_Parameter_Table_Field(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Int(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Table_Field::asString(void)
+{
+	CSG_Table	*pTable;
+
+	if( (pTable = Get_Table()) != NULL )
+	{
+		if( m_Value >= 0 && m_Value < pTable->Get_Field_Count() )
+		{
+			return( pTable->Get_Field_Name(m_Value) );
+		}
+
+		return( LNG("[VAL] [not set]") );
+	}
+
+	return( LNG("[VAL] [no fields]") );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Table_Field::Set_Value(int Value)
+{
+	bool		bChanged;
+	CSG_Table	*pTable;
+
+	bChanged	= false;
+
+	if( (pTable = Get_Table()) != NULL )
+	{
+		if( !m_pOwner->is_Optional() )
+		{
+			if( Value < 0 )
+			{
+				Value	= 0;
+			}
+			else if( Value >= pTable->Get_Field_Count() )
+			{
+				Value	= pTable->Get_Field_Count() - 1;
+			}
+		}
+		else if( Value < 0 || Value >= pTable->Get_Field_Count() )
+		{
+			Value	= -1;
+		}
+	}
+	else
+	{
+		Value	= -1;
+	}
+
+	if( m_Value != Value )
+	{
+		m_Value		= Value;
+		bChanged	= true;
+	}
+
+	return( bChanged );
+}
+
+//---------------------------------------------------------
+CSG_Table * CSG_Parameter_Table_Field::Get_Table(void)
+{
+	CSG_Table		*pTable;
+	CSG_Parameter	*pParent;
+
+	pTable		= NULL;
+
+	if( (pParent = m_pOwner->Get_Parent()) != NULL )
+	{
+		switch( m_pOwner->Get_Parent()->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_TIN:
+			pTable	= pParent->asTable();
+			break;
+
+		case PARAMETER_TYPE_PointCloud:
+			break;
+		}
+	}
+
+	return( pTable && pTable->Get_Field_Count() > 0 ? pTable : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						DataObject						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Data_Object::CSG_Parameter_Data_Object(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_pDataObject	= NULL;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data_Object::is_Valid(void)
+{
+	return(	m_pOwner->is_Optional() || (m_pDataObject && m_pDataObject->is_Valid()) );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data_Object::Set_Value(void *Value)
+{
+	if( m_pDataObject != Value )
+	{
+		m_pDataObject	= (CSG_Data_Object *)Value;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Data_Object::asString(void)
+{
+	if( m_pDataObject == DATAOBJECT_NOTSET )
+	{
+		m_String	= m_pOwner->is_Output() && !m_pOwner->is_Optional()
+					? LNG("[VAL] [create]")
+					: LNG("[VAL] [not set]");
+	}
+	else if( m_pDataObject == DATAOBJECT_CREATE )
+	{
+		m_String	= LNG("[VAL] [create]");
+	}
+	else
+	{
+		m_String	= m_pDataObject->Get_Name();
+	}
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Data_Object::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_pDataObject	= ((CSG_Parameter_Data_Object *)pSource)->m_pDataObject;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data_Object::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		if(	m_pDataObject == DATAOBJECT_CREATE )
+		{
+			Entry.Set_Content(SG_T("CREATE"));
+		}
+		else if( m_pDataObject != DATAOBJECT_NOTSET && m_pDataObject->Get_File_Name() )
+		{
+			Entry.Set_Content(m_pDataObject->Get_File_Name());
+		}
+		else
+		{
+			Entry.Set_Content(SG_T("NOT SET"));
+		}
+	}
+	else
+	{
+		if( !Entry.Cmp_Content(SG_T("CREATE")) )
+		{
+			Set_Value(DATAOBJECT_CREATE);
+		}
+		else
+		{
+			Set_Value(SG_UI_DataObject_Find(Entry.Get_Content(), -1));
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					DataObject_Output					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Data_Object_Output::CSG_Parameter_Data_Object_Output(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data_Object(pOwner, Constraint)
+{
+	m_Type	= DATAOBJECT_TYPE_Undefined;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data_Object_Output::Set_Value(void *Value)
+{
+	CSG_Data_Object	*pDataObject	= (CSG_Data_Object *)Value;
+
+	if( pDataObject == DATAOBJECT_CREATE )
+	{
+		pDataObject	= NULL;
+	}
+
+	if( m_pDataObject != pDataObject && (pDataObject == NULL || pDataObject->Get_ObjectType() == m_Type) )
+	{
+		m_pDataObject	= pDataObject;
+
+		SG_UI_DataObject_Add(m_pDataObject, false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Data_Object_Output::Set_DataObject_Type(TSG_Data_Object_Type Type)
+{
+	if( m_Type == DATAOBJECT_TYPE_Undefined )	// m_Type should not be changed after set once!!!...
+	{
+		switch( Type )
+		{
+		default:
+			break;
+
+		case DATAOBJECT_TYPE_Grid:
+		case DATAOBJECT_TYPE_Table:
+		case DATAOBJECT_TYPE_Shapes:
+		case DATAOBJECT_TYPE_TIN:
+		case DATAOBJECT_TYPE_PointCloud:
+			m_Type	= Type;
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Grid							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Grid::CSG_Parameter_Grid(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data_Object(pOwner, Constraint)
+{
+	m_Type	= SG_DATATYPE_Undefined;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Grid::Set_Value(void *Value)
+{
+	CSG_Grid_System	*pSystem;
+
+	if( Value == DATAOBJECT_CREATE && !m_pOwner->is_Optional() )
+	{
+//		Value	= DATAOBJECT_NOTSET;
+	}
+
+	if( m_pDataObject != Value )
+	{
+		pSystem	= Get_System();
+
+		if(	Value == DATAOBJECT_NOTSET || Value == DATAOBJECT_CREATE
+		||	pSystem == NULL || pSystem->is_Equal(((CSG_Grid *)Value)->Get_System()) )
+		{
+			m_pDataObject	= (CSG_Data_Object *)Value;
+
+			return( true );
+		}
+		else if( !m_pOwner->Get_Owner()->is_Managed() && pSystem != NULL )
+		{
+			pSystem->Assign(((CSG_Grid *)Value)->Get_System());
+			m_pDataObject	= (CSG_Data_Object *)Value;
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Grid_System * CSG_Parameter_Grid::Get_System(void)
+{
+	if( m_pOwner->Get_Parent() && m_pOwner->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System )
+	{
+		return( m_pOwner->Get_Parent()->asGrid_System() );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Grid::Set_Preferred_Type(TSG_Data_Type Type)
+{
+	m_Type	= Type;
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Grid::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_Data_Object::On_Assign(pSource);
+
+	m_Type	= ((CSG_Parameter_Grid *)pSource)->m_Type;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Table							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Table::CSG_Parameter_Table(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data_Object(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Table::Set_Value(void *Value)
+{
+	if( m_pDataObject != Value )
+	{
+		m_pDataObject	= (CSG_Data_Object *)Value;
+
+		CSG_Parameters	*pParameters	= m_pOwner->Get_Owner();
+
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			if(	pParameters->Get_Parameter(i)->Get_Parent() == m_pOwner
+			&&	pParameters->Get_Parameter(i)->Get_Type()   == PARAMETER_TYPE_Table_Field )
+			{
+				pParameters->Get_Parameter(i)->Set_Value(0);
+			}				
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Shapes							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Shapes::CSG_Parameter_Shapes(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data_Object(pOwner, Constraint)
+{
+	m_Type	= SHAPE_TYPE_Undefined;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Shapes::Set_Value(void *Value)
+{
+	if(	Value != DATAOBJECT_NOTSET && Value != DATAOBJECT_CREATE
+	&&	m_Type != SHAPE_TYPE_Undefined && m_Type != ((CSG_Shapes *)Value)->Get_Type() )
+	{
+		return( false );
+	}
+
+	if( m_pDataObject != Value )
+	{
+		m_pDataObject	= (CSG_Data_Object *)Value;
+
+		CSG_Parameters	*pParameters	= m_pOwner->Get_Owner();
+
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			if(	pParameters->Get_Parameter(i)->Get_Parent() == m_pOwner
+			&&	pParameters->Get_Parameter(i)->Get_Type()   == PARAMETER_TYPE_Table_Field )
+			{
+				pParameters->Get_Parameter(i)->Set_Value(0);
+			}				
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Shapes::Set_Shape_Type(TSG_Shape_Type Type)
+{
+	m_Type	= Type;
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Shapes::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_Data_Object::On_Assign(pSource);
+
+	m_Type	= ((CSG_Parameter_Shapes *)pSource)->m_Type;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						TIN								 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_TIN::CSG_Parameter_TIN(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data_Object(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+bool CSG_Parameter_TIN::Set_Value(void *Value)
+{
+	if( m_pDataObject != Value )
+	{
+		m_pDataObject	= (CSG_Data_Object *)Value;
+
+		CSG_Parameters	*pParameters	= m_pOwner->Get_Owner();
+
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			if(	pParameters->Get_Parameter(i)->Get_Parent() == m_pOwner
+			&&	pParameters->Get_Parameter(i)->Get_Type()   == PARAMETER_TYPE_Table_Field )
+			{
+				pParameters->Get_Parameter(i)->Set_Value(0);
+			}				
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						PointCloud						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_PointCloud::CSG_Parameter_PointCloud(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data_Object(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+void CSG_Parameter_PointCloud::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_Data_Object::On_Assign(pSource);
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_PointCloud::Set_Value(void *Value)
+{
+	if( m_pDataObject != Value )
+	{
+		m_pDataObject	= (CSG_Data_Object *)Value;
+
+		CSG_Parameters	*pParameters	= m_pOwner->Get_Owner();
+
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			if(	pParameters->Get_Parameter(i)->Get_Parent() == m_pOwner
+			&&	pParameters->Get_Parameter(i)->Get_Type()   == PARAMETER_TYPE_Table_Field )
+			{
+				pParameters->Get_Parameter(i)->Set_Value(0);
+			}				
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						List							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_List::CSG_Parameter_List(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_Objects	= NULL;
+	m_nObjects	= 0;
+}
+
+CSG_Parameter_List::~CSG_Parameter_List(void)
+{
+	Del_Items();
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_List::asString(void)
+{
+	if( Get_Count() > 0 )
+	{
+		m_String.Printf(SG_T("%d %s ("), Get_Count(), Get_Count() == 1 ? LNG("[VAL] object") : LNG("[VAL] objects"));
+
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( i > 0 )
+			{
+				m_String.Append(SG_T(", "));
+			}
+
+			m_String.Append(asDataObject(i)->Get_Name());
+		}
+
+		m_String.Append(SG_T("))"));
+	}
+	else
+	{
+		m_String.Printf(LNG("[VAL] No objects"));
+	}
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_List::Add_Item(CSG_Data_Object *pObject)
+{
+	if( pObject )
+	{
+		m_Objects	= (CSG_Data_Object **)SG_Realloc(m_Objects, (m_nObjects + 1) * sizeof(CSG_Data_Object *));
+		m_Objects[m_nObjects++]	= pObject;
+	}
+}
+
+//---------------------------------------------------------
+int CSG_Parameter_List::Del_Item(int iObject)
+{
+	int		i;
+
+	if( iObject >= 0 && iObject < m_nObjects )
+	{
+		m_nObjects--;
+
+		for(i=iObject; i<m_nObjects; i++)
+		{
+			m_Objects[i]	= m_Objects[i + 1];
+		}
+
+		m_Objects	= (CSG_Data_Object **)SG_Realloc(m_Objects, m_nObjects * sizeof(CSG_Data_Object *));
+	}
+
+	return( m_nObjects );
+}
+
+int CSG_Parameter_List::Del_Item(CSG_Data_Object *pObject)
+{
+	int		i;
+
+	for(i=0; i<m_nObjects; i++)
+	{
+		if( pObject == m_Objects[i] )
+		{
+			return( Del_Item(i) );
+		}
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_List::Del_Items(void)
+{
+	if( m_nObjects > 0 )
+	{
+		SG_Free(m_Objects);
+		m_Objects	= NULL;
+		m_nObjects	= 0;
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_List::On_Assign(CSG_Parameter_Data *pSource)
+{
+	Del_Items();
+
+	for(int i=0; i<((CSG_Parameter_List *)pSource)->Get_Count(); i++)
+	{
+		Add_Item(((CSG_Parameter_List *)pSource)->asDataObject(i));
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_List::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( bSave )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( asDataObject(i)->Get_File_Name() )
+			{
+				Entry.Add_Child(SG_T("DATA"), asDataObject(i)->Get_File_Name());
+			}
+		}
+	}
+	else
+	{
+		for(int i=0; i<Entry.Get_Children_Count(); i++)
+		{
+			CSG_Data_Object	*pObject	= SG_UI_DataObject_Find(Entry.Get_Child(i)->Get_Content(), -1);
+
+			if( pObject )
+			{
+				Add_Item(pObject);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Grid_List						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+//---------------------------------------------------------
+CSG_Parameter_Grid_List::CSG_Parameter_Grid_List(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_List(pOwner, Constraint)
+{}
+
+//---------------------------------------------------------
+CSG_Grid_System * CSG_Parameter_Grid_List::Get_System(void)
+{
+	if( m_pOwner->Get_Parent() && m_pOwner->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System )
+	{
+		return( m_pOwner->Get_Parent()->asGrid_System() );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Table_List						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+//---------------------------------------------------------
+CSG_Parameter_Table_List::CSG_Parameter_Table_List(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_List(pOwner, Constraint)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Shapes_List						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+//---------------------------------------------------------
+CSG_Parameter_Shapes_List::CSG_Parameter_Shapes_List(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_List(pOwner, Constraint)
+{
+	m_Type	= SHAPE_TYPE_Undefined;
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Shapes_List::Set_Shape_Type(TSG_Shape_Type Type)
+{
+	m_Type	= Type;
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Shapes_List::On_Assign(CSG_Parameter_Data *pSource)
+{
+	CSG_Parameter_List::On_Assign(pSource);
+
+	m_Type	= ((CSG_Parameter_Shapes_List *)pSource)->m_Type;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						TIN_List						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+//---------------------------------------------------------
+CSG_Parameter_TIN_List::CSG_Parameter_TIN_List(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_List(pOwner, Constraint)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					PointCloud_List						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+//---------------------------------------------------------
+CSG_Parameter_PointCloud_List::CSG_Parameter_PointCloud_List(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_List(pOwner, Constraint)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Parameters						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter_Parameters::CSG_Parameter_Parameters(CSG_Parameter *pOwner, long Constraint)
+	: CSG_Parameter_Data(pOwner, Constraint)
+{
+	m_pParameters	= new CSG_Parameters(pOwner->Get_Owner()->Get_Owner(), pOwner->Get_Name(), pOwner->Get_Description(), pOwner->Get_Identifier());
+}
+
+CSG_Parameter_Parameters::~CSG_Parameter_Parameters(void)
+{
+	delete(m_pParameters);
+}
+
+//---------------------------------------------------------
+const SG_Char * CSG_Parameter_Parameters::asString(void)
+{
+	m_String.Printf(SG_T("%d %s"), m_pParameters->Get_Count(), LNG("parameters"));
+
+	return( m_String );
+}
+
+//---------------------------------------------------------
+void CSG_Parameter_Parameters::On_Assign(CSG_Parameter_Data *pSource)
+{
+	m_pParameters->Assign(((CSG_Parameter_Parameters *)pSource)->m_pParameters);
+}
+
+//---------------------------------------------------------
+bool CSG_Parameter_Parameters::On_Serialize(CSG_MetaData &Entry, bool bSave)
+{
+	if( m_pParameters->Serialize(Entry, bSave) )
+	{
+		if( bSave )
+		{
+			Entry.Set_Property(SG_T("id")  , m_pOwner->Get_Identifier());
+			Entry.Set_Property(SG_T("type"), m_pOwner->Get_Type_Name());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1660 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    parameters.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameters::CSG_Parameters(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Parameters::CSG_Parameters(void *pOwner, const SG_Char *Name, const SG_Char *Description, const SG_Char *Identifier, bool bGrid_System)
+{
+	_On_Construction();
+
+	Create(pOwner, Name, Description, Identifier, bGrid_System);
+}
+
+//---------------------------------------------------------
+CSG_Parameters::~CSG_Parameters(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Parameters::_On_Construction(void)
+{
+	m_pOwner		= NULL;
+
+	m_Parameters	= NULL;
+	m_nParameters	= 0;
+
+	m_Callback		= NULL;
+	m_bCallback		= false;
+
+	m_pGrid_System	= NULL;
+
+	m_bManaged		= true;
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Create(void *pOwner, const SG_Char *Name, const SG_Char *Description, const SG_Char *Identifier, bool bGrid_System)
+{
+	Destroy();
+
+	m_pOwner		= pOwner;
+
+	Set_Identifier	(Identifier);
+	Set_Name		(Name);
+	Set_Description	(Description);
+
+	if( bGrid_System )
+	{
+		m_pGrid_System	= Add_Grid_System(
+			NULL, SG_T("PARAMETERS_GRID_SYSTEM"),
+			LNG("[PRM] Grid system"),
+			LNG("[PRM] Grid system")
+		);
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Destroy(void)
+{
+	m_pOwner		= NULL;
+	m_pGrid_System	= NULL;
+
+	if( m_nParameters > 0 )
+	{
+		for(int i=0; i<m_nParameters; i++)
+		{
+			delete(m_Parameters[i]);
+		}
+
+		SG_Free(m_Parameters);
+
+		m_Parameters	= NULL;
+		m_nParameters	= 0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Identifier(const SG_Char *String)
+{
+	if( String )
+	{
+		m_Identifier.Printf(String);
+	}
+	else
+	{
+		m_Identifier.Clear();
+	}
+}
+
+const SG_Char * CSG_Parameters::Get_Identifier(void)
+{
+	return( m_Identifier );
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Name(const SG_Char *String)
+{
+	if( String )
+	{
+		m_Name.Printf(String);
+	}
+	else
+	{
+		m_Name.Clear();
+	}
+}
+
+const SG_Char * CSG_Parameters::Get_Name(void)
+{
+	return( m_Name );
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Description(const SG_Char *String)
+{
+	if( String )
+	{
+		m_Description.Printf(String);
+	}
+	else
+	{
+		m_Description.Clear();
+	}
+}
+
+const SG_Char * CSG_Parameters::Get_Description(void)
+{
+	return( m_Description );
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Translation(CSG_Translator &Translator)
+{
+	m_Name			= Translator.Get_Translation(m_Name);
+	m_Description	= Translator.Get_Translation(m_Description);
+
+	for(int i=0; i<m_nParameters; i++)
+	{
+		m_Parameters[i]->m_Name			= Translator.Get_Translation(m_Parameters[i]->m_Name);
+		m_Parameters[i]->m_Description	= Translator.Get_Translation(m_Parameters[i]->m_Description);
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Enabled(bool bEnabled)
+{
+	for(int i=0; i<m_nParameters; i++)
+	{
+		m_Parameters[i]->Set_Enabled(bEnabled);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Node(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	return( _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Node, PARAMETER_INFORMATION) );
+}
+
+//---------------------------------------------------------
+/**
+  * Following parameter types can be used:
+  * PARAMETER_TYPE_Bool
+  * PARAMETER_TYPE_Int
+  * PARAMETER_TYPE_Double
+  *	PARAMETER_TYPE_Degree
+  * PARAMETER_TYPE_Color
+*/
+CSG_Parameter * CSG_Parameters::Add_Value(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value, double Minimum, bool bMinimum, double Maximum, bool bMaximum)
+{
+	return( _Add_Value(pParent, Identifier, Name, Description, false, Type, Value, Minimum, bMinimum, Maximum, bMaximum) );
+}
+
+CSG_Parameter * CSG_Parameters::Add_Info_Value(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value)
+{
+	return( _Add_Value(pParent, Identifier, Name, Description,  true, Type, Value, 0.0, false, 0.0, false) );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Range(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min, double Range_Max, double Minimum, bool bMinimum, double Maximum, bool bMaximum)
+{
+	return( _Add_Range(pParent, Identifier, Name, Description, false, Range_Min, Range_Max, Minimum, bMinimum, Maximum, bMaximum) );
+}
+
+CSG_Parameter * CSG_Parameters::Add_Info_Range(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min, double Range_Max)
+{
+	return( _Add_Range(pParent, Identifier, Name, Description,  true, Range_Min, Range_Max, 0.0, false, 0.0, false) );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Choice(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Items, int Default)
+{
+	CSG_Parameter			*pParameter;
+	CSG_Parameter_Choice	*m_pData;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Choice, 0);
+
+	m_pData		= (CSG_Parameter_Choice *)pParameter->m_pData;
+	m_pData->Set_Items(Items);
+
+	pParameter->Set_Value(Default);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_String(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText, bool bPassword)
+{
+	return( _Add_String(pParent, Identifier, Name, Description, false, String, bLongText, bPassword) );
+}
+
+CSG_Parameter * CSG_Parameters::Add_Info_String(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText)
+{
+	return( _Add_String(pParent, Identifier, Name, Description,  true, String, bLongText, false) );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_FilePath(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Filter, const SG_Char *Default, bool bSave, bool bDirectory, bool bMultiple)
+{
+	CSG_Parameter			*pParameter;
+	CSG_Parameter_File_Name	*m_pData;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_FilePath, 0);
+
+	m_pData		= (CSG_Parameter_File_Name *)pParameter->m_pData;
+	m_pData->Set_Filter			(Filter);
+	m_pData->Set_Flag_Save		(bSave);
+	m_pData->Set_Flag_Multiple	(bMultiple);
+	m_pData->Set_Flag_Directory	(bDirectory);
+
+	pParameter->Set_Value((void *)Default);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Font(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, wxFont *pInit)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Font, 0);
+
+	if( pInit )
+	{
+		pParameter->Set_Value(pInit);
+	}
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Colors(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Colors *pInit)
+{
+	CSG_Parameter			*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Colors, 0);
+
+	pParameter->asColors()->Assign(pInit);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_FixedTable(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Table *pTemplate)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_FixedTable, 0);
+
+	pParameter->asTable()->Create(pTemplate);
+
+	if( pTemplate )
+	{
+		for(int i=0; i<pTemplate->Get_Record_Count(); i++)
+		{
+			pParameter->asTable()->Add_Record(pTemplate->Get_Record(i));
+		}
+	}
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Grid_System(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Grid_System *pInit)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Grid_System, 0);
+
+	if( pInit )
+	{
+		pParameter->asGrid_System()->Assign(*pInit);
+	}
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Grid(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent, TSG_Data_Type Preferred_Type)
+{
+	CSG_Parameter	*pParameter;
+
+	if( !pParent || pParent->Get_Type() != PARAMETER_TYPE_Grid_System )
+	{
+		if( bSystem_Dependent && m_pGrid_System )
+		{
+			pParent	= m_pGrid_System;
+		}
+		else
+		{
+			pParent	= Add_Grid_System(pParent, CSG_String::Format(SG_T("%s_GRIDSYSTEM"), Identifier), LNG("[PRM] Grid system"), SG_T(""));
+		}
+	}
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Grid, Constraint);
+
+	((CSG_Parameter_Grid *)pParameter->m_pData)->Set_Preferred_Type(Preferred_Type);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Grid_Output(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_DataObject_Output, PARAMETER_OUTPUT_OPTIONAL);
+
+	((CSG_Parameter_Data_Object_Output *)pParameter->Get_Data())->Set_DataObject_Type(DATAOBJECT_TYPE_Grid);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Grid_List(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent)
+{
+	CSG_Parameter	*pParameter;
+
+	if( bSystem_Dependent && (!pParent || pParent->Get_Type() != PARAMETER_TYPE_Grid_System) )
+	{
+		pParent	= m_pGrid_System;
+	}
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Grid_List, Constraint);
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Table_Field(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bAllowNone)
+{
+	if( pParent
+	&&	(	pParent->Get_Type() == PARAMETER_TYPE_Table
+		||	pParent->Get_Type() == PARAMETER_TYPE_Shapes
+		||	pParent->Get_Type() == PARAMETER_TYPE_TIN	) )
+	{
+		return( _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Table_Field, bAllowNone ? PARAMETER_OPTIONAL : 0) );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Table(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Table, Constraint);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Table_Output(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_DataObject_Output, PARAMETER_OUTPUT_OPTIONAL);
+
+	((CSG_Parameter_Data_Object_Output *)pParameter->Get_Data())->Set_DataObject_Type(DATAOBJECT_TYPE_Table);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Table_List(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Table_List, Constraint);
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Shapes(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Shape_Type)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Shapes, Constraint);
+
+	((CSG_Parameter_Shapes *)pParameter->m_pData)->Set_Shape_Type(Shape_Type);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Shapes_Output(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_DataObject_Output, PARAMETER_OUTPUT_OPTIONAL);
+
+	((CSG_Parameter_Data_Object_Output *)pParameter->Get_Data())->Set_DataObject_Type(DATAOBJECT_TYPE_Shapes);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Shapes_List(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Type)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Shapes_List, Constraint);
+
+	((CSG_Parameter_Shapes_List *)pParameter->m_pData)->Set_Shape_Type(Type);
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_TIN(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_TIN, Constraint);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_TIN_Output(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_DataObject_Output, PARAMETER_OUTPUT_OPTIONAL);
+
+	((CSG_Parameter_Data_Object_Output *)pParameter->Get_Data())->Set_DataObject_Type(DATAOBJECT_TYPE_TIN);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_TIN_List(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_TIN_List, Constraint);
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_PointCloud(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_PointCloud, Constraint);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_PointCloud_Output(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_DataObject_Output, PARAMETER_OUTPUT_OPTIONAL);
+
+	((CSG_Parameter_Data_Object_Output *)pParameter->Get_Data())->Set_DataObject_Type(DATAOBJECT_TYPE_PointCloud);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_PointCloud_List(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_PointCloud_List, Constraint);
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Add_Parameters(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Parameters, 0);
+
+	pParameter->asParameters()->m_Callback	= m_Callback;
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::_Add_Value(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bInformation, TSG_Parameter_Type Type, double Value, double Minimum, bool bMinimum, double Maximum, bool bMaximum)
+{
+	CSG_Parameter			*pParameter;
+	CSG_Parameter_Value	*m_pData;
+
+	switch( Type )	// Check if Type is valid...
+	{
+	case PARAMETER_TYPE_Bool:
+	case PARAMETER_TYPE_Int:
+	case PARAMETER_TYPE_Double:
+	case PARAMETER_TYPE_Degree:
+	case PARAMETER_TYPE_Color:
+		break;
+
+	default:
+		Type	= PARAMETER_TYPE_Double;	// if not valid set Type to [double]...
+		break;
+	}
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, Type, bInformation ? PARAMETER_INFORMATION : 0);
+
+	if( !bInformation )
+	{
+		switch( Type )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Int:
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+			m_pData		= (CSG_Parameter_Value *)pParameter->m_pData;
+			m_pData->Set_Minimum(Minimum, bMinimum);
+			m_pData->Set_Maximum(Maximum, bMaximum);
+			break;
+		}
+	}
+
+	pParameter->Set_Value(Value);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::_Add_Range(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bInformation, double Default_Min, double Default_Max, double Minimum, bool bMinimum, double Maximum, bool bMaximum)
+{
+	double				d;
+	CSG_Parameter			*pParameter;
+	CSG_Parameter_Range	*m_pData;
+
+	//-----------------------------------------------------
+	if( Default_Min > Default_Max )
+	{
+		d			= Default_Min;
+		Default_Min	= Default_Max;
+		Default_Max	= d;
+	}
+
+	//-----------------------------------------------------
+	pParameter	= _Add(pParent, Identifier, Name, Description, PARAMETER_TYPE_Range, bInformation ? PARAMETER_INFORMATION : 0);
+
+	m_pData		= pParameter->asRange();
+
+	m_pData->Get_LoParm()->asValue()->Set_Minimum(Minimum, bMinimum);
+	m_pData->Get_LoParm()->asValue()->Set_Maximum(Maximum, bMaximum);
+	m_pData->Get_HiParm()->asValue()->Set_Minimum(Minimum, bMinimum);
+	m_pData->Get_HiParm()->asValue()->Set_Maximum(Maximum, bMaximum);
+
+	m_pData->Set_LoVal(Default_Min);
+	m_pData->Set_HiVal(Default_Max);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::_Add_String(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bInformation, const SG_Char *String, bool bLongText, bool bPassword)
+{
+	CSG_Parameter	*pParameter;
+
+	pParameter	= _Add(pParent, Identifier, Name, Description, bLongText ? PARAMETER_TYPE_Text : PARAMETER_TYPE_String, bInformation ? PARAMETER_INFORMATION : 0);
+
+	pParameter->Set_Value((void *)String);
+
+	((CSG_Parameter_String *)pParameter->Get_Data())->Set_Password(bPassword);
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::_Add(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, int Constraint)
+{
+	CSG_Parameter	*pParameter;
+
+	if( Identifier && *Identifier )
+	{
+		pParameter	= new CSG_Parameter(this, pParent, Identifier, Name, Description, Type, Constraint);
+	}
+	else
+	{
+		pParameter	= new CSG_Parameter(this, pParent, CSG_String::Format(SG_T("%d"), m_nParameters), Name, Description, Type, Constraint);
+	}
+
+	m_Parameters	= (CSG_Parameter **)SG_Realloc(m_Parameters, (m_nParameters + 1) * sizeof(CSG_Parameter *));
+	m_Parameters[m_nParameters++]	= pParameter;
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::_Add(CSG_Parameter *pSource)
+{
+	CSG_Parameter	*pParameter;
+
+	if( pSource )
+	{
+		pParameter	= _Add(
+			pSource->Get_Parent() ? Get_Parameter(pSource->Get_Parent()->Get_Identifier()) : NULL,
+			pSource->Get_Identifier(),
+			pSource->Get_Name(),
+			pSource->Get_Description(),
+			pSource->Get_Type(),
+			pSource->m_pData->Get_Constraint()
+		);
+
+		pParameter->Assign(pSource);
+	}
+	else
+	{
+		pParameter	= NULL;
+	}
+
+	return( pParameter );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Get_Parameter(const SG_Char *Identifier)
+{
+	int		i;
+
+	if( m_Parameters && Identifier )
+	{
+		for(i=0; i<m_nParameters; i++)
+		{
+			if( !m_Parameters[i]->m_Identifier.Cmp(Identifier) )
+			{
+				return( m_Parameters[i] );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CSG_Parameters::Get_Parameter(int iParameter)
+{
+	if( m_Parameters && iParameter >= 0 && iParameter < m_nParameters )
+	{
+		return( m_Parameters[iParameter] );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Callback						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Callback_On_Parameter_Changed(TSG_PFNC_Parameter_Changed Callback)
+{
+	m_Callback	= Callback;
+}
+
+//---------------------------------------------------------
+void CSG_Parameters::Set_Callback(bool bActive)
+{
+	m_bCallback	= bActive;
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::_On_Parameter_Changed(CSG_Parameter *pSender)
+{
+	if( m_Callback && m_bCallback )
+	{
+		m_bCallback	= false;
+		m_Callback(pSender);
+		m_bCallback	= true;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameters::Set_Parameter(const SG_Char *Identifier, CSG_Parameter *pSource)
+{
+	CSG_Parameter	*pTarget;
+
+	if( pSource != NULL && (pTarget = Get_Parameter(Identifier)) != NULL && pSource->Get_Type() == pTarget->Get_Type() )
+	{
+		switch( pTarget->Get_Type() )
+		{
+		default:
+			return( pTarget->Assign(pSource) );
+
+		case PARAMETER_TYPE_DataObject_Output:
+		case PARAMETER_TYPE_Grid:
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_TIN:
+			return( pTarget->Set_Value(pSource->asDataObject()) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::Set_Parameter(const SG_Char *Identifier, int Type, int Value)
+{
+	CSG_Parameter	*pTarget;
+
+	if( (pTarget = Get_Parameter(Identifier)) != NULL && Type == pTarget->Get_Type() )
+	{
+		pTarget->Set_Value(Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::Set_Parameter(const SG_Char *Identifier, int Type, double Value)
+{
+	CSG_Parameter	*pTarget;
+
+	if( (pTarget = Get_Parameter(Identifier)) != NULL && Type == pTarget->Get_Type() )
+	{
+		pTarget->Set_Value(Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::Set_Parameter(const SG_Char *Identifier, int Type, void *Value)
+{
+	CSG_Parameter	*pTarget;
+
+	if( (pTarget = Get_Parameter(Identifier)) != NULL && Type == pTarget->Get_Type() )
+	{
+		pTarget->Set_Value(Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::Set_Parameter(const SG_Char *Identifier, int Type, const SG_Char *Value)
+{
+	CSG_Parameter	*pTarget;
+
+	if( (pTarget = Get_Parameter(Identifier)) != NULL && Type == pTarget->Get_Type() )
+	{
+		pTarget->Set_Value(Value);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Parameters::Assign(CSG_Parameters *pSource)
+{
+	int				i;
+	CSG_Parameter	*pParameter;
+
+	if( pSource && pSource != this )
+	{
+		Destroy();
+
+		m_pOwner	= pSource->Get_Owner();
+
+		Set_Identifier	(pSource->Get_Identifier());
+		Set_Name		(pSource->Get_Name());
+		Set_Description	(pSource->Get_Description());
+
+		m_Callback	= pSource->m_Callback;
+		m_bCallback	= pSource->m_bCallback;
+
+		if( pSource->Get_Count() > 0 )
+		{
+			for(i=0; i<pSource->Get_Count(); i++)
+			{
+				_Add(pSource->Get_Parameter(i));
+			}
+
+			for(i=0; i<pSource->Get_Count(); i++)
+			{
+				if( Get_Parameter(i) && (pParameter = pSource->Get_Parameter(i)->Get_Parent()) != NULL )
+				{
+					Get_Parameter(i)->m_pParent	= Get_Parameter(pParameter->Get_Identifier());
+				}
+			}
+
+			if( pSource->m_pGrid_System )
+			{
+				m_pGrid_System	= Get_Parameter(pSource->m_pGrid_System->Get_Identifier());
+			}
+		}
+
+		return( m_nParameters );
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+int CSG_Parameters::Assign_Values(CSG_Parameters *pSource)
+{
+	if( pSource && pSource != this )
+	{
+		int		i, n;
+
+		for(i=0, n=0; i<pSource->Get_Count(); i++)
+		{
+			CSG_Parameter	*pParameter	= Get_Parameter(pSource->Get_Parameter(i)->Get_Identifier());
+
+			if( pParameter && pParameter->Get_Type() == pSource->Get_Parameter(i)->Get_Type() )
+			{
+				pParameter->Assign(pSource->Get_Parameter(i));
+				n++;
+			}
+		}
+
+		return( n );
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameters::DataObjects_Check(bool bSilent)
+{
+	bool		bInvalid, bResult	= true;
+	CSG_String	s;
+
+	//-----------------------------------------------------
+	for(int i=0; i<Get_Count(); i++)
+	{
+		switch( m_Parameters[i]->Get_Type() )
+		{
+		default:
+			bInvalid	= false;
+			break;
+
+		case PARAMETER_TYPE_Parameters:
+			bInvalid	= m_Parameters[i]->asParameters()->DataObjects_Check(bSilent) == false;
+			break;
+
+		case PARAMETER_TYPE_Grid:
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_TIN:
+			bInvalid	=  m_Parameters[i]->is_Input()				== true
+						&& m_Parameters[i]->is_Optional()			== false
+						&& m_Parameters[i]->asDataObject()			== NULL;
+			break;
+
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+			bInvalid	=  m_Parameters[i]->is_Input()				== true
+						&& m_Parameters[i]->is_Optional()			== false
+						&& m_Parameters[i]->asList()->Get_Count()	== 0;
+			break;
+		}
+
+		if( bInvalid )
+		{
+			bResult	= false;
+			s.Append(CSG_String::Format(SG_T("\n%s: %s"), m_Parameters[i]->Get_Type_Name(), m_Parameters[i]->Get_Name()));
+		}
+	}
+
+	//-----------------------------------------------------
+	if( !bResult && !bSilent )
+	{
+		SG_UI_Dlg_Message(CSG_String::Format(SG_T("%s\n%s"), LNG("[DLG] Invalid parameters!"), s.c_str() ), Get_Name() );
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::DataObjects_Create(void)
+{
+	if( m_bManaged )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			CSG_Data_Object	*pDataObject;
+			CSG_Grid_System	*pGrid_System;
+			CSG_Parameter	*p	= m_Parameters[i];
+
+			if( p->Get_Type() == PARAMETER_TYPE_Parameters )
+			{
+				p->asParameters()->DataObjects_Create();
+			}
+			else if( p->Get_Type() == PARAMETER_TYPE_DataObject_Output )
+			{
+				p->Set_Value(DATAOBJECT_NOTSET);
+			}
+			else if( p->is_DataObject() && p->is_Output()
+			&&	(	(p->asDataObject() == DATAOBJECT_CREATE)
+				||	(p->asDataObject() == NULL && !p->is_Optional())	)	)
+			{
+				pDataObject	= NULL;
+
+				switch( p->Get_Type() )
+				{
+				default:
+					break;
+
+				case PARAMETER_TYPE_Grid:
+					if(	p->Get_Parent() && p->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System
+					&&	(pGrid_System = p->Get_Parent()->asGrid_System()) != NULL && pGrid_System->is_Valid() )
+					{
+						pDataObject	= SG_Create_Grid(*pGrid_System, ((CSG_Parameter_Grid *)p->Get_Data())->Get_Preferred_Type());
+					}
+					break;
+
+				case PARAMETER_TYPE_Table:
+					pDataObject	= SG_Create_Table();
+					break;
+
+				case PARAMETER_TYPE_Shapes:
+					pDataObject	= SG_Create_Shapes(((CSG_Parameter_Shapes *)p->Get_Data())->Get_Shape_Type());
+					break;
+
+				case PARAMETER_TYPE_PointCloud:
+					pDataObject	= SG_Create_PointCloud();
+					break;
+
+				case PARAMETER_TYPE_TIN:
+					pDataObject	= SG_Create_TIN();
+					break;
+				}
+
+				p->Set_Value(pDataObject);
+
+				if( pDataObject )
+				{
+					pDataObject->Set_Name(p->Get_Name());
+					SG_UI_DataObject_Add(pDataObject, false);
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::DataObjects_Synchronize(void)
+{
+	if( m_bManaged )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			CSG_Parameter	*p	= m_Parameters[i];
+
+			if( p->Get_Type() == PARAMETER_TYPE_Parameters )
+			{
+				p->asParameters()->DataObjects_Synchronize();
+			}
+			else
+			{
+				if( p->Get_Type() == PARAMETER_TYPE_Shapes && p->asShapes() && p->asShapes()->Get_Type() == SHAPE_TYPE_Undefined )
+				{
+					delete(p->asShapes());
+					p->Set_Value(DATAOBJECT_NOTSET);
+				}
+
+				if( p->is_Output() )
+				{
+					if( p->is_DataObject() )
+					{
+						if( p->asDataObject() )
+						{
+							SG_UI_DataObject_Add	(p->asDataObject(), false);
+							SG_UI_DataObject_Update	(p->asDataObject(), false, NULL);
+						}
+					}
+					else if( p->is_DataObject_List() )
+					{
+						for(int j=0; j<p->asList()->Get_Count(); j++)
+						{
+							SG_UI_DataObject_Add	(p->asList()->asDataObject(j), false);
+							SG_UI_DataObject_Update	(p->asList()->asDataObject(j), false, NULL);
+						}
+					}
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameters::Get_String(CSG_String &String, bool bOptionsOnly)
+{
+	bool	bResult	= false;
+
+	if( Get_Count() > 0 )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			CSG_Parameter	*p	= m_Parameters[i];
+
+			if( (!bOptionsOnly || p->is_Option()) && !p->is_Information() && !(p->Get_Type() == PARAMETER_TYPE_String && ((CSG_Parameter_String *)p->Get_Data())->is_Password()) )
+			{
+				bResult	= true;
+
+			//	String.Append(CSG_String::Format(SG_T("[%s] %s: %s\n"),
+			//		p->Get_Type_Name(),
+				String.Append(CSG_String::Format(SG_T("%s: %s\n"),
+					p->Get_Name(),
+					p->asString())
+				);
+			}
+		}
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::Msg_String(bool bOptionsOnly)
+{
+	CSG_String	s;
+
+	if( Get_String(s, bOptionsOnly) )
+	{
+		SG_UI_Msg_Add_Execution(SG_T("\n"), false);
+		SG_UI_Msg_Add_Execution(bOptionsOnly ? LNG("[CAP] Options") : LNG("[CAP] Parameters"), false);
+		SG_UI_Msg_Add_Execution(SG_T("\n"), false);
+		SG_UI_Msg_Add_Execution(s, false, SG_UI_MSG_STYLE_01);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameters::Set_History(CSG_MetaData &MetaData, bool bOptions, bool bDataObjects)
+{
+	CSG_MetaData	*pEntry;
+	CSG_Data_Object	*pObject;
+
+	//-----------------------------------------------------
+	if( bOptions )
+	{
+		for(int i=0; i<Get_Count(); i++)	// get options...
+		{
+			CSG_Parameter	*p	= m_Parameters[i];
+
+			if(	p->is_Option() && !p->is_Information()
+			&&	!(p->Get_Type() == PARAMETER_TYPE_String && ((CSG_Parameter_String *)p->Get_Data())->is_Password())
+			&&	!(p->Get_Type() == PARAMETER_TYPE_Grid_System && p->Get_Children_Count() > 0) )
+			{
+				p->Serialize(MetaData, true);
+			}
+
+			if( p->is_Parameters() )
+			{
+				p->asParameters()->Set_History(MetaData, true, false);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( bDataObjects )
+	{
+		for(int i=0; i<Get_Count(); i++)	// get input with history...
+		{
+			CSG_Parameter	*p	= m_Parameters[i];
+
+			if(	p->Get_Type() == PARAMETER_TYPE_Grid_System && p->Get_Children_Count() > 0 )
+			{
+				CSG_MetaData	*pGrids	= NULL;
+
+				for(int j=0; j<p->Get_Children_Count(); j++)
+				{
+					CSG_Parameter	*pj	= p->Get_Child(j);
+
+					if( pj->is_Input() && pj->is_DataObject() && (pObject = pj->asDataObject()) != NULL )
+					{
+						if( pGrids == NULL )
+						{
+							pGrids	= p->Serialize(MetaData, true);
+						}
+
+						pEntry	= pj->Serialize(*pGrids, true);
+						pEntry->Assign(pObject->Get_History(), true);
+					}
+				}
+			}
+			else if( p->is_Input() )
+			{
+				if( p->is_DataObject() && (pObject = p->asDataObject()) != NULL  )
+				{
+					pEntry	= p->Serialize(MetaData, true);
+					pEntry->Assign(pObject->Get_History(), true);
+				}
+
+				if( p->is_DataObject_List() && p->asList()->Get_Count() > 0 )
+				{
+					MetaData.Add_Child(p->Get_Name(), p->asString());
+
+					for(int j=0; j<p->asList()->Get_Count(); j++)
+					{
+						pEntry	= p->Serialize(MetaData, true);
+						pEntry->Assign(p->asList()->asDataObject(j)->Get_History(), true);
+					}
+				}
+			}
+
+			if( p->is_Parameters() )
+			{
+				p->asParameters()->Set_History(MetaData, false, true);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Serialize						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Parameters::Serialize(const CSG_String &File_Name, bool bSave)
+{
+	CSG_MetaData	MetaData;
+
+	if( bSave )
+	{
+		return( Serialize(MetaData, true) && MetaData.Save(File_Name) );
+	}
+	else
+	{
+		return( MetaData.Load(File_Name) && Serialize(MetaData, false) );
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Parameters::Serialize(CSG_MetaData &MetaData, bool bSave)
+{
+	if( bSave )
+	{
+		MetaData.Destroy();
+
+		MetaData.Set_Name    (SG_T("PARAMETERS"));
+		MetaData.Set_Property(SG_T("name"), Get_Name());
+
+		for(int i=0; i<Get_Count(); i++)
+		{
+			m_Parameters[i]->Serialize(MetaData, true);
+		}
+	}
+	else
+	{
+		if( MetaData.Get_Name().Cmp(SG_T("PARAMETERS")) )
+		{
+			return( false );
+		}
+
+		MetaData.Get_Property(SG_T("name"), m_Name);
+
+		for(int i=0; i<MetaData.Get_Children_Count(); i++)
+		{
+			CSG_String		Identifier;
+			CSG_Parameter	*pParameter;
+
+			if(	MetaData.Get_Child(i)->Get_Property(SG_T("id"), Identifier)
+			&&	(pParameter	= Get_Parameter(Identifier)) != NULL )
+			{
+				pParameter->Serialize(*MetaData.Get_Child(i), false);
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+// SAGA 2.0 compatibility...
+bool CSG_Parameters::Serialize_Compatibility(CSG_File &Stream)
+{
+	CSG_Parameter	*pParameter;
+	CSG_String		sLine;
+
+	if( !Stream.is_Open() )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	while( Stream.Read_Line(sLine) && sLine.Cmp(SG_T("[PARAMETER_ENTRIES_BEGIN]")) );
+
+	if( sLine.Cmp(SG_T("[PARAMETER_ENTRIES_BEGIN]")) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	while( Stream.Read_Line(sLine) && sLine.Cmp(SG_T("[PARAMETER_ENTRIES_END]")) )
+	{
+		if( !sLine.Cmp(SG_T("[PARAMETER_ENTRY_BEGIN]"))
+		&&	Stream.Read_Line(sLine) && (pParameter = Get_Parameter(sLine)) != NULL
+		&&	Stream.Read_Line(sLine) &&  pParameter ->Get_Type() == sLine.asInt() )
+		{
+			int			i;
+			double		d, e;
+			TSG_Rect	r;
+			CSG_String	s;
+			CSG_Table	t;
+
+			switch( sLine.asInt() )
+			{
+			case  1: // PARAMETER_TYPE_Bool:
+			case  2: // PARAMETER_TYPE_Int:
+			case  6: // PARAMETER_TYPE_Choice:
+			case 11: // PARAMETER_TYPE_Color:
+			case 15: // PARAMETER_TYPE_Table_Field:
+				SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%d"), &i);
+				pParameter->Set_Value(i);
+				break;
+
+			case  3: // PARAMETER_TYPE_Double:
+			case  4: // PARAMETER_TYPE_Degree:
+				SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf"), &d);
+				pParameter->Set_Value(d);
+				break;
+
+			case  5: // PARAMETER_TYPE_Range:
+				SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf %lf"), &d, &e);
+				pParameter->asRange()->Set_Range(d, e);
+				break;
+
+			case  7: // PARAMETER_TYPE_String:
+			case  9: // PARAMETER_TYPE_FilePath:
+				Stream.Read_Line(sLine);
+				pParameter->Set_Value(sLine);
+				break;
+
+			case  8: // PARAMETER_TYPE_Text:
+				s.Clear();
+				while( Stream.Read_Line(sLine) && sLine.Cmp(SG_T("[TEXT_ENTRY_END]")) )
+				{
+					s	+= sLine + SG_T("\n");
+				}
+				pParameter->Set_Value(s);
+				break;
+
+			case 10: // PARAMETER_TYPE_Font:
+				Stream.Read(&i, sizeof(i));
+				pParameter->Set_Value(i);
+				break;
+
+			case 12: // PARAMETER_TYPE_Colors:
+				pParameter->asColors()->Serialize(Stream, false, false);
+				break;
+
+			case 13: // PARAMETER_TYPE_FixedTable:
+				if( t.Serialize(Stream, false) )
+				{
+					pParameter->asTable()->Assign_Values(&t);
+				}
+				break;
+
+			case 14: // PARAMETER_TYPE_Grid_System:
+				Stream.Read(&d, sizeof(d));
+				Stream.Read(&r, sizeof(r));
+				pParameter->asGrid_System()->Assign(d, r);
+				break;
+
+			case 16: // PARAMETER_TYPE_Grid:
+			case 17: // PARAMETER_TYPE_Table:
+			case 18: // PARAMETER_TYPE_Shapes:
+			case 19: // PARAMETER_TYPE_TIN:
+			case 24: // PARAMETER_TYPE_DataObject_Output:
+				if( Stream.Read_Line(sLine) )
+				{
+					if( !sLine.Cmp(SG_T("[ENTRY_DATAOBJECT_CREATE]")) )
+					{
+						pParameter->Set_Value(DATAOBJECT_CREATE);
+					}
+					else
+					{
+						pParameter->Set_Value(SG_UI_DataObject_Find(sLine, -1));
+					}
+				}
+				break;
+
+			case 20: // PARAMETER_TYPE_Grid_List:
+			case 21: // PARAMETER_TYPE_Table_List:
+			case 22: // PARAMETER_TYPE_Shapes_List:
+			case 23: // PARAMETER_TYPE_TIN_List:
+				while( Stream.Read_Line(sLine) && sLine.Cmp(SG_T("[ENTRY_DATAOBJECTLIST_END]")) )
+				{
+					CSG_Data_Object	*pObject	= SG_UI_DataObject_Find(sLine, -1);
+
+					if( pObject )
+					{
+						pParameter->asList()->Add_Item(pObject);
+					}
+				}
+				break;
+
+			case 25: // PARAMETER_TYPE_Parameters:
+				pParameter->asParameters()->Serialize_Compatibility(Stream);
+				break;
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _SAGA_UNICODE
+
+CSG_Parameter * CSG_Parameters::Get_Parameter(const char *Identifier)
+{	return( Get_Parameter(SG_STR_MBTOSG(Identifier)) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Node				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_Node				(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Value				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value, double Minimum, bool bMinimum, double Maximum, bool bMaximum)
+{	return( Add_Value				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Type, Value, Minimum, bMinimum, Maximum, bMaximum) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Info_Value			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value)
+{	return( Add_Info_Value			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Type, Value) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Range				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min, double Range_Max, double Minimum, bool bMinimum, double Maximum, bool bMaximum)
+{	return( Add_Range				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Range_Min, Range_Max, Minimum, bMinimum, Maximum, bMaximum) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Info_Range			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min, double Range_Max)
+{	return( Add_Info_Range			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Range_Min, Range_Max) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Choice				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Items, int Default)
+{	return( Add_Choice				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Items, Default) );	}
+
+CSG_Parameter * CSG_Parameters::Add_String				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText, bool bPassword)
+{	return( Add_String				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, String, bLongText, bPassword) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Info_String			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText)
+{	return( Add_Info_String			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, String, bLongText) );	}
+
+CSG_Parameter * CSG_Parameters::Add_FilePath			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Filter, const SG_Char *Default, bool bSave, bool bDirectory, bool bMultiple)
+{	return( Add_FilePath			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Filter, Default, bSave, bDirectory, bMultiple) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Font				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, class wxFont *pInit)
+{	return( Add_Font				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, pInit) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Colors				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Colors      *pInit)
+{	return( Add_Colors				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, pInit) );	}
+
+CSG_Parameter * CSG_Parameters::Add_FixedTable			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Table   *pTemplate)
+{	return( Add_FixedTable			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, pTemplate) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Grid_System			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Grid_System *pInit)
+{	return( Add_Grid_System			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, pInit) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Grid				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent, TSG_Data_Type Preferred_Type)
+{	return( Add_Grid				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint, bSystem_Dependent, Preferred_Type) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Grid_Output			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_Grid_Output			(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Grid_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent)
+{	return( Add_Grid_List			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint, bSystem_Dependent) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Table_Field			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bAllowNone)
+{	return( Add_Table_Field			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, bAllowNone) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Table				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{	return( Add_Table				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Table_Output		(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_Table_Output		(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Table_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{	return( Add_Table_List			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Shapes				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Shape_Type)
+{	return( Add_Shapes				(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint, Shape_Type) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Shapes_Output		(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_Shapes_Output		(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Shapes_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Shape_Type)
+{	return( Add_Shapes_List			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint, Shape_Type) );	}
+
+CSG_Parameter * CSG_Parameters::Add_TIN					(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{	return( Add_TIN					(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint) );	}
+
+CSG_Parameter * CSG_Parameters::Add_TIN_Output			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_TIN_Output			(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+CSG_Parameter * CSG_Parameters::Add_TIN_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{	return( Add_TIN_List			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint) );	}
+
+CSG_Parameter * CSG_Parameters::Add_PointCloud			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{	return( Add_PointCloud			(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint) );	}
+
+CSG_Parameter * CSG_Parameters::Add_PointCloud_Output	(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_PointCloud_Output	(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+CSG_Parameter * CSG_Parameters::Add_PointCloud_List		(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint)
+{	return( Add_PointCloud_List		(pParent, SG_STR_MBTOSG(Identifier), Name, Description, Constraint) );	}
+
+CSG_Parameter * CSG_Parameters::Add_Parameters			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description)
+{	return( Add_Parameters			(pParent, SG_STR_MBTOSG(Identifier), Name, Description) );	}
+
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/parameters.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1249 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     parameters.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__parameters_H
+#define HEADER_INCLUDED__SAGA_API__parameters_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "grid.h"
+#include "table.h"
+#include "shapes.h"
+#include "tin.h"
+#include "pointcloud.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define PARAMETER_INPUT						0x01
+#define PARAMETER_OUTPUT					0x02
+#define PARAMETER_OPTIONAL					0x04
+#define PARAMETER_INFORMATION				0x08
+
+#define PARAMETER_INPUT_OPTIONAL			(PARAMETER_INPUT  | PARAMETER_OPTIONAL)
+#define PARAMETER_OUTPUT_OPTIONAL			(PARAMETER_OUTPUT | PARAMETER_OPTIONAL)
+
+//---------------------------------------------------------
+#define PARAMETER_DESCRIPTION_NAME			0x01
+#define PARAMETER_DESCRIPTION_TYPE			0x02
+#define PARAMETER_DESCRIPTION_OPTIONAL		0x04
+#define PARAMETER_DESCRIPTION_PROPERTIES	0x08
+#define PARAMETER_DESCRIPTION_TEXT			0x10
+#define PARAMETER_DESCRIPTION_ALL			(PARAMETER_DESCRIPTION_NAME | PARAMETER_DESCRIPTION_TYPE | PARAMETER_DESCRIPTION_OPTIONAL | PARAMETER_DESCRIPTION_PROPERTIES | PARAMETER_DESCRIPTION_TEXT)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Parameter_Type
+{
+	PARAMETER_TYPE_Node		= 0,
+
+	PARAMETER_TYPE_Bool,
+	PARAMETER_TYPE_Int,
+	PARAMETER_TYPE_Double,
+	PARAMETER_TYPE_Degree,
+
+	PARAMETER_TYPE_Range,
+	PARAMETER_TYPE_Choice,
+
+	PARAMETER_TYPE_String,
+	PARAMETER_TYPE_Text,
+	PARAMETER_TYPE_FilePath,
+
+	PARAMETER_TYPE_Font,
+
+	PARAMETER_TYPE_Color,
+	PARAMETER_TYPE_Colors,
+
+	PARAMETER_TYPE_FixedTable,
+
+	PARAMETER_TYPE_Grid_System,
+	PARAMETER_TYPE_Table_Field,
+
+	PARAMETER_TYPE_PointCloud,
+	PARAMETER_TYPE_Grid,
+	PARAMETER_TYPE_Table,
+	PARAMETER_TYPE_Shapes,
+	PARAMETER_TYPE_TIN,
+
+	PARAMETER_TYPE_Grid_List,
+	PARAMETER_TYPE_Table_List,
+	PARAMETER_TYPE_Shapes_List,
+	PARAMETER_TYPE_TIN_List,
+	PARAMETER_TYPE_PointCloud_List,
+
+	PARAMETER_TYPE_DataObject_Output,
+
+	PARAMETER_TYPE_Parameters,
+
+	PARAMETER_TYPE_Undefined
+}
+TSG_Parameter_Type;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT const SG_Char *		SG_Parameter_Type_Get_Identifier	(TSG_Parameter_Type Type);
+SAGA_API_DLL_EXPORT const SG_Char *		SG_Parameter_Type_Get_Name			(TSG_Parameter_Type Type);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Parameters;
+class CSG_Parameter;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef int		(* TSG_PFNC_Parameter_Changed)	(CSG_Parameter *pSender);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					CSG_Parameter_Data					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Data(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Data(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)			= 0;
+	virtual const SG_Char *		Get_Type_Identifier		(void);
+	virtual const SG_Char *		Get_Type_Name			(void);
+
+	long						Get_Constraint			(void)	{	return( m_Constraint );	}
+
+	virtual bool				is_Valid				(void)	{	return( true );			}
+
+	bool						Assign					(CSG_Parameter_Data *pSource);
+	bool						Serialize				(CSG_MetaData &Entry, bool bSave);
+
+	virtual bool				Set_Value				(int Value);
+	virtual bool				Set_Value				(double Value);
+	virtual bool				Set_Value				(void *Value);
+
+	virtual int					asInt					(void);
+	virtual double				asDouble				(void);
+	virtual void *				asPointer				(void);
+
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	int							m_Constraint;
+
+	CSG_String					m_String;
+
+	CSG_Parameter				*m_pOwner;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Node : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Node(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Node(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Node );	}
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Bool : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Bool(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Bool(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Bool );	}
+
+	virtual bool				Set_Value				(int Value);
+	virtual bool				Set_Value				(double Value);
+
+	virtual int					asInt					(void)	{	return( m_Value );	}
+
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	bool						m_Value;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Value : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Value(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Value(void)	{}
+
+	bool						Set_Range				(double Minimum, double Maximum);
+
+	void						Set_Minimum				(double Minimum, bool bOn = true);
+	double						Get_Minimum				(void)	{	return( m_Minimum );	}
+	bool						has_Minimum				(void)	{	return( m_bMinimum );	}
+
+	void						Set_Maximum				(double Maximum, bool bOn = true);
+	double						Get_Maximum				(void)	{	return( m_Maximum );	}
+	bool						has_Maximum				(void)	{	return( m_bMaximum );	}
+
+
+protected:
+
+	bool						m_bMinimum, m_bMaximum;
+
+	double						m_Minimum, m_Maximum;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Int : public CSG_Parameter_Value
+{
+public:
+	CSG_Parameter_Int(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Int(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Int );		}
+
+	virtual bool				Set_Value				(void *Value);
+	virtual bool				Set_Value				(int Value);
+	virtual bool				Set_Value				(double Value);
+
+	virtual int					asInt					(void)	{	return( m_Value );		}
+	virtual double				asDouble				(void)	{	return( m_Value );		}
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	int							m_Value;
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Double : public CSG_Parameter_Value
+{
+public:
+	CSG_Parameter_Double(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Double(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Double );	}
+
+	virtual bool				Set_Value				(int Value);
+	virtual bool				Set_Value				(double Value);
+	virtual bool				Set_Value				(void *Value);
+
+	virtual int					asInt					(void)	{	return( (int)m_Value );	}
+	virtual double				asDouble				(void)	{	return( m_Value );		}
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	double						m_Value;
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Degree : public CSG_Parameter_Double
+{
+public:
+	CSG_Parameter_Degree(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Degree(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Degree );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+	virtual const SG_Char *		asString				(void);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Range : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Range(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Range(void);
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Range );		}
+
+	virtual const SG_Char *		asString				(void);
+
+	bool						Set_Range				(double loVal, double hiVal);
+
+	bool						Set_LoVal				(double newValue);
+	double						Get_LoVal				(void);
+
+	bool						Set_HiVal				(double newValue);
+	double						Get_HiVal				(void);
+
+	CSG_Parameter *				Get_LoParm				(void)	{	return( pLo );	}
+	CSG_Parameter *				Get_HiParm				(void)	{	return( pHi );	}
+
+
+protected:
+
+	CSG_Parameter				*pLo, *pHi;
+
+	CSG_Parameters				*pRange;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Choice : public CSG_Parameter_Int
+{
+public:
+	CSG_Parameter_Choice(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Choice(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Choice );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+	virtual const SG_Char *		asString				(void);
+
+	void						Set_Items				(const SG_Char *String);
+
+	const SG_Char *				Get_Item				(int Index);
+
+	int							Get_Count				(void)	{	return( Items.Get_Count() );	}
+
+
+protected:
+
+	CSG_Strings					Items;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_String : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_String(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_String(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_String );	}
+
+	virtual const SG_Char *		asString				(void);
+
+	virtual bool				is_Valid				(void);
+
+	virtual bool				Set_Value				(void *Value);
+
+	void						Set_Password			(bool bOn);
+	bool						is_Password				(void);
+
+
+protected:
+
+	bool						bPassword;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Text : public CSG_Parameter_String
+{
+public:
+	CSG_Parameter_Text(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Text(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Text );		}
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_File_Name : public CSG_Parameter_String
+{
+public:
+	CSG_Parameter_File_Name(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_File_Name(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_FilePath );	}
+
+	void						Set_Filter				(const SG_Char *Filter);
+	const SG_Char *				Get_Filter				(void);
+
+	void						Set_Flag_Save			(bool bFlag);
+	bool						is_Save					(void)	{	return( m_bSave );		}
+
+	void						Set_Flag_Multiple		(bool bFlag);
+	bool						is_Multiple				(void)	{	return( m_bMultiple );	}
+
+	void						Set_Flag_Directory		(bool bFlag);
+	bool						is_Directory			(void)	{	return( m_bDirectory );	}
+
+	bool						Get_FilePaths			(CSG_Strings &FilePaths);
+
+
+protected:
+
+	bool						m_bSave, m_bMultiple, m_bDirectory;
+
+	CSG_String					m_Filter;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Font : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Font(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Font(void);
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Font );		}
+
+	virtual bool				Set_Value				(int Value);
+	virtual bool				Set_Value				(void *Value);
+
+	virtual int					asInt					(void)	{	return( m_Color );	}
+	virtual void *				asPointer				(void)	{	return( m_pFont );	}
+
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	int							m_Color;
+
+	class wxFont				*m_pFont;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Color : public CSG_Parameter_Int
+{
+public:
+	CSG_Parameter_Color(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Color(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Color );		}
+
+
+protected:
+
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Colors : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Colors(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Colors(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Colors );	}
+
+	virtual int					asInt					(void)	{	return( m_Colors.Get_Count() );	}
+	virtual void *				asPointer				(void)	{	return( &m_Colors );	}
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	CSG_Colors					m_Colors;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Fixed_Table : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Fixed_Table(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Fixed_Table(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_FixedTable );	}
+
+	virtual void *				asPointer				(void)	{	return( &m_Table );	}
+
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	CSG_Table					m_Table;
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Grid_System : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Grid_System(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Grid_System(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Grid_System );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+	virtual void *				asPointer				(void)	{	return( &m_System );}
+
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	CSG_Grid_System				m_System;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Table_Field : public CSG_Parameter_Int
+{
+public:
+	CSG_Parameter_Table_Field(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Table_Field(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)	{	return( PARAMETER_TYPE_Table_Field );	}
+
+	virtual const SG_Char *		asString				(void);
+
+	virtual bool				Set_Value				(int Value);
+
+	CSG_Table *					Get_Table				(void);
+
+
+protected:
+
+	bool						m_bAllowNone;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Data_Object : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Data_Object(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Data_Object(void)	{}
+
+	virtual bool				is_Valid				(void);
+
+	virtual bool				Set_Value				(int Value)	{	return( Set_Value((void *)Value) );	}
+	virtual bool				Set_Value				(void *Value);
+
+	virtual void *				asPointer				(void)		{	return( m_pDataObject );	}
+
+	virtual const SG_Char *		asString				(void);
+
+
+protected:
+
+	CSG_Data_Object				*m_pDataObject;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Data_Object_Output : public CSG_Parameter_Data_Object
+{
+public:
+	CSG_Parameter_Data_Object_Output(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Data_Object_Output(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_DataObject_Output );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+	bool						Set_DataObject_Type		(TSG_Data_Object_Type Type);
+	TSG_Data_Object_Type		Get_DataObject_Type		(void)		{	return( m_Type );	}
+
+
+protected:
+
+	TSG_Data_Object_Type		m_Type;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Grid : public CSG_Parameter_Data_Object
+{
+public:
+	CSG_Parameter_Grid(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Grid(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Grid );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+	void						Set_Preferred_Type		(TSG_Data_Type Type);
+	TSG_Data_Type				Get_Preferred_Type		(void)		{	return( m_Type );	}
+
+	CSG_Grid_System *			Get_System				(void);
+
+
+protected:
+
+	TSG_Data_Type				m_Type;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Table : public CSG_Parameter_Data_Object
+{
+public:
+	CSG_Parameter_Table(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Table(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Table );		}
+
+	virtual bool				Set_Value				(void *Value);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Shapes : public CSG_Parameter_Data_Object
+{
+public:
+	CSG_Parameter_Shapes(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Shapes(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Shapes );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+	void						Set_Shape_Type			(TSG_Shape_Type Type);
+	TSG_Shape_Type				Get_Shape_Type			(void)		{	return( m_Type );	}
+
+
+protected:
+
+	TSG_Shape_Type				m_Type;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_TIN : public CSG_Parameter_Data_Object
+{
+public:
+	CSG_Parameter_TIN(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_TIN(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_TIN );		}
+
+	virtual bool				Set_Value				(void *Value);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_PointCloud : public CSG_Parameter_Data_Object
+{
+public:
+	CSG_Parameter_PointCloud(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_PointCloud(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_PointCloud );	}
+
+	virtual bool				Set_Value				(void *Value);
+
+
+protected:
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_List : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_List(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_List(void);
+
+	virtual const SG_Char *		asString				(void);
+	virtual int					asInt					(void)			{	return( m_nObjects );	}
+	virtual void *				asPointer				(void)			{	return( m_Objects );	}
+
+	void						Add_Item				(CSG_Data_Object *pItem);
+	int							Del_Item				(int Index);
+	int							Del_Item				(CSG_Data_Object *pItem);
+	void						Del_Items				(void);
+
+	int							Get_Count				(void)			{	return( m_nObjects );	}
+	CSG_Data_Object *			asDataObject			(int iObject)	{	return( iObject >= 0 && iObject < m_nObjects ? m_Objects[iObject] : NULL );	}
+
+
+protected:
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+
+private:
+
+	int							m_nObjects;
+
+	CSG_Data_Object				**m_Objects;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Grid_List : public CSG_Parameter_List
+{
+public:
+	CSG_Parameter_Grid_List(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Grid_List(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Grid_List );		}
+
+	CSG_Grid_System *			Get_System				(void);
+
+	CSG_Grid *					asGrid					(int Index)	{	return( (CSG_Grid *)asDataObject(Index) );	}
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Table_List : public CSG_Parameter_List
+{
+public:
+	CSG_Parameter_Table_List(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Table_List(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Table_List );		}
+
+	CSG_Table *					asTable					(int Index)	{	return( (CSG_Table *)asDataObject(Index) );	}
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Shapes_List : public CSG_Parameter_List
+{
+public:
+	CSG_Parameter_Shapes_List(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Shapes_List(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Shapes_List );		}
+
+	void						Set_Shape_Type			(TSG_Shape_Type Type);
+	TSG_Shape_Type				Get_Shape_Type			(void)		{	return( m_Type );}
+
+	CSG_Shapes *				asShapes				(int Index)	{	return( (CSG_Shapes *)asDataObject(Index) );	}
+
+
+protected:
+
+	TSG_Shape_Type				m_Type;
+
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_TIN_List : public CSG_Parameter_List
+{
+public:
+	CSG_Parameter_TIN_List(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_TIN_List(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_TIN_List );		}
+
+	CSG_TIN *					asTIN					(int Index)	{	return( (CSG_TIN *)asDataObject(Index) );	}
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_PointCloud_List : public CSG_Parameter_List
+{
+public:
+	CSG_Parameter_PointCloud_List(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_PointCloud_List(void)	{}
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_PointCloud_List );		}
+
+	CSG_PointCloud *			asPointCloud			(int Index)	{	return( (CSG_PointCloud *)asDataObject(Index) );	}
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter_Parameters : public CSG_Parameter_Data
+{
+public:
+	CSG_Parameter_Parameters(CSG_Parameter *pOwner, long Constraint);
+	virtual ~CSG_Parameter_Parameters(void);
+
+	virtual TSG_Parameter_Type	Get_Type				(void)		{	return( PARAMETER_TYPE_Parameters );	}
+
+	virtual const SG_Char *		asString				(void);
+	virtual void *				asPointer				(void)		{	return( m_pParameters );	}
+
+
+protected:
+
+	virtual void				On_Assign				(CSG_Parameter_Data *pSource);
+	virtual bool				On_Serialize			(CSG_MetaData &Entry, bool bSave);
+
+
+private:
+
+	CSG_Parameters				*m_pParameters;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					CSG_Parameter						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameter
+{
+	friend class CSG_Parameters;
+
+public:
+
+	//-----------------------------------------------------
+	CSG_Parameters *			Get_Owner				(void)	{	return( m_pOwner );							}
+	CSG_Parameter *				Get_Parent				(void)	{	return( m_pParent );						}
+	TSG_Parameter_Type			Get_Type				(void)	{	return( m_pData->Get_Type() );				}
+	const SG_Char *				Get_Type_Identifier		(void)	{	return( m_pData->Get_Type_Identifier() );	}
+	const SG_Char *				Get_Type_Name			(void)	{	return( m_pData->Get_Type_Name() );			}
+	CSG_Parameter_Data *		Get_Data				(void)	{	return( m_pData );							}
+
+	const SG_Char *				Get_Identifier			(void);
+	const SG_Char *				Get_Name				(void);
+	const SG_Char *				Get_Description			(void);
+	CSG_String					Get_Description			(int Flags);
+	CSG_String					Get_Description			(int Flags, const SG_Char *Separator);
+
+	bool						Set_Enabled				(bool bEnabled);
+	bool						is_Enabled				(void)	{	return( m_bEnabled );				}
+
+	bool						is_Valid				(void)	{	return( m_pData->is_Valid() );		}
+	bool						is_Input				(void)	{	return( !!(m_pData->Get_Constraint() & PARAMETER_INPUT)	      );	}
+	bool						is_Output				(void)	{	return( !!(m_pData->Get_Constraint() & PARAMETER_OUTPUT)      );	}
+	bool						is_Optional				(void)	{	return( !!(m_pData->Get_Constraint() & PARAMETER_OPTIONAL)    );	}
+	bool						is_Information			(void)	{	return( !!(m_pData->Get_Constraint() & PARAMETER_INFORMATION) );	}
+	bool						is_Option				(void);
+	bool						is_DataObject			(void);
+	bool						is_DataObject_List		(void);
+	bool						is_Parameters			(void);
+	bool						is_Serializable			(void);
+
+	int							Get_Children_Count		(void)			{	return( m_nChildren );		}
+	CSG_Parameter *				Get_Child				(int iChild)	{	return( iChild >= 0 && iChild < m_nChildren ? m_Children[iChild] : NULL );	}
+
+	//-----------------------------------------------------
+	bool						Set_Value				(int            Value);
+	bool						Set_Value				(double         Value);
+	bool						Set_Value				(void          *Value);
+	bool						Set_Value				(const SG_Char *Value);
+
+	bool						has_Changed				(void);
+
+	bool						asBool					(void)	{	return( (bool          )!!m_pData->asInt	() );	}
+	int							asInt					(void)	{	return( (int           )m_pData->asInt		() );	}
+	long						asColor					(void)	{	return( (long          )m_pData->asInt		() );	}
+	double						asDouble				(void)	{	return( (double        )m_pData->asDouble	() );	}
+
+	void *						asPointer				(void)	{	return( (void            *)m_pData->asPointer	() );	}
+
+	const SG_Char *				asString				(void)	{	return( (const SG_Char   *)m_pData->asString	() );	}
+	class wxFont *				asFont					(void)	{	return( (wxFont          *)m_pData->asPointer	() );	}
+	CSG_Colors *				asColors				(void)	{	return( (CSG_Colors      *)m_pData->asPointer	() );	}
+	CSG_Grid_System *			asGrid_System			(void)	{	return( (CSG_Grid_System *)m_pData->asPointer	() );	}
+
+	CSG_Data_Object *			asDataObject			(void)	{	return( (CSG_Data_Object *)m_pData->asPointer	() );	}
+	CSG_Grid *					asGrid					(void)	{	return( (CSG_Grid        *)m_pData->asPointer	() );	}
+	CSG_Table *					asTable					(void)	{	return( (CSG_Table       *)m_pData->asPointer	() );	}
+	CSG_Shapes *				asShapes				(void)	{	return( (CSG_Shapes      *)m_pData->asPointer	() );	}
+	CSG_TIN *					asTIN					(void)	{	return( (CSG_TIN         *)m_pData->asPointer	() );	}
+	CSG_PointCloud *			asPointCloud			(void)	{	return( (CSG_PointCloud  *)m_pData->asPointer	() );	}
+
+	CSG_Parameter_Value *		asValue					(void)	{	return( (CSG_Parameter_Value       *)m_pData );		}
+	CSG_Parameter_Choice *		asChoice				(void)	{	return( (CSG_Parameter_Choice      *)m_pData );		}
+	CSG_Parameter_Range *		asRange					(void)	{	return( (CSG_Parameter_Range       *)m_pData );		}
+	CSG_Parameter_File_Name *	asFilePath				(void)	{	return( (CSG_Parameter_File_Name   *)m_pData );		}
+
+	CSG_Parameter_List *		asList					(void)	{	return( (CSG_Parameter_List        *)m_pData );		}
+	CSG_Parameter_Grid_List *	asGridList				(void)	{	return( (CSG_Parameter_Grid_List   *)m_pData );		}
+	CSG_Parameter_Table_List *	asTableList				(void)	{	return( (CSG_Parameter_Table_List  *)m_pData );		}
+	CSG_Parameter_Shapes_List *	asShapesList			(void)	{	return( (CSG_Parameter_Shapes_List *)m_pData );		}
+	CSG_Parameter_TIN_List *	asTINList				(void)	{	return( (CSG_Parameter_TIN_List    *)m_pData );		}
+	CSG_Parameter_PointCloud_List *	asPointCloudList	(void)	{	return( (CSG_Parameter_PointCloud_List *)m_pData );	}
+
+	CSG_Parameters *			asParameters			(void)	{	return( (CSG_Parameters *)m_pData->asPointer	() );	}
+
+	//-----------------------------------------------------
+	bool						Assign					(CSG_Parameter *pSource);
+
+	CSG_MetaData *				Serialize				(CSG_MetaData &MetaData, bool bSave);
+
+
+private:
+
+	CSG_Parameter(CSG_Parameters *pOwner, CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, int Constraint);
+
+	virtual ~CSG_Parameter(void);
+
+	void						_Add_Child				(CSG_Parameter *pChild);
+
+
+	bool						m_bEnabled;
+
+	int							m_nChildren;
+
+	CSG_Parameter				**m_Children;
+
+	CSG_String					m_Identifier, m_Name, m_Description;
+
+	CSG_Parameter_Data			*m_pData;
+
+	CSG_Parameter				*m_pParent;
+
+	CSG_Parameters				*m_pOwner;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					CSG_Parameters						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Parameters
+{
+	friend class CSG_Parameter;
+	friend class CSG_Module;
+
+public:
+	CSG_Parameters(void);
+	virtual ~CSG_Parameters(void);
+
+								CSG_Parameters			(void *pOwner, const SG_Char *Name, const SG_Char *Description, const SG_Char *Identifier = NULL, bool bGrid_System = false);
+	void						Create					(void *pOwner, const SG_Char *Name, const SG_Char *Description, const SG_Char *Identifier = NULL, bool bGrid_System = false);
+
+	void						Destroy					(void);
+
+	//-----------------------------------------------------
+	void *						Get_Owner				(void)	{	return( m_pOwner );			}
+	int							Get_Count				(void)	{	return( m_nParameters );	}
+
+	void						Set_Identifier			(const SG_Char *String);
+	const SG_Char *				Get_Identifier			(void);
+
+	void						Set_Name				(const SG_Char *String);
+	const SG_Char *				Get_Name				(void);
+
+	void						Set_Description			(const SG_Char *String);
+	const SG_Char *				Get_Description			(void);
+
+	void						Set_Translation			(CSG_Translator &Translator);
+
+	void						Set_Enabled				(bool bEnabled);
+
+	//-----------------------------------------------------
+	void						Set_Callback_On_Parameter_Changed	(TSG_PFNC_Parameter_Changed pCallback);
+	void						Set_Callback			(bool bActive = true);
+
+	//-----------------------------------------------------
+	CSG_Parameter *				Get_Parameter			(int iParameter);
+	CSG_Parameter *				operator()				(int iParameter)			{	return( Get_Parameter(iParameter) );	}
+
+	CSG_Parameter *				Get_Parameter			(const SG_Char *Identifier);
+	CSG_Parameter *				operator()				(const SG_Char *Identifier)	{	return( Get_Parameter(Identifier) );	}
+
+	//-----------------------------------------------------
+	CSG_Parameter *				Add_Node				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+
+	CSG_Parameter *				Add_Value				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value = 0.0, double Minimum = 0.0, bool bMinimum = false, double Maximum = 0.0, bool bMaximum = false);
+	CSG_Parameter *				Add_Info_Value			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value = 0.0);
+
+	CSG_Parameter *				Add_Range				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min = 0.0, double Range_Max = 0.0, double Minimum = 0.0, bool bMinimum = false, double Maximum = 0.0, bool bMaximum = false);
+	CSG_Parameter *				Add_Info_Range			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min = 0.0, double Range_Max = 0.0);
+
+	CSG_Parameter *				Add_Choice				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Items, int Default = 0);
+
+	CSG_Parameter *				Add_String				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText = false, bool bPassword = false);
+	CSG_Parameter *				Add_Info_String			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText = false);
+
+	CSG_Parameter *				Add_FilePath			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Filter = NULL, const SG_Char *Default = NULL, bool bSave = false, bool bDirectory = false, bool bMultiple = false);
+
+	CSG_Parameter *				Add_Font				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, class wxFont *pInit = NULL);
+	CSG_Parameter *				Add_Colors				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Colors      *pInit = NULL);
+	CSG_Parameter *				Add_FixedTable			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Table   *pTemplate = NULL);
+
+	CSG_Parameter *				Add_Grid_System			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Grid_System *pInit = NULL);
+	CSG_Parameter *				Add_Grid				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent = true, TSG_Data_Type Preferred_Type = SG_DATATYPE_Undefined);
+	CSG_Parameter *				Add_Grid_Output			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Grid_List			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent = true);
+
+	CSG_Parameter *				Add_Table_Field			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bAllowNone = false);
+	CSG_Parameter *				Add_Table				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_Table_Output		(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Table_List			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+
+	CSG_Parameter *				Add_Shapes				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Shape_Type = SHAPE_TYPE_Undefined);
+	CSG_Parameter *				Add_Shapes_Output		(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Shapes_List			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type = SHAPE_TYPE_Undefined);
+
+	CSG_Parameter *				Add_TIN					(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_TIN_Output			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_TIN_List			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+
+	CSG_Parameter *				Add_PointCloud			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_PointCloud_Output	(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_PointCloud_List		(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+
+	CSG_Parameter *				Add_Parameters			(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description);
+
+	//-----------------------------------------------------
+	bool						Set_Parameter			(const SG_Char *Identifier, CSG_Parameter *pSource);
+	bool						Set_Parameter			(const SG_Char *Identifier, int Type, int           Value);
+	bool						Set_Parameter			(const SG_Char *Identifier, int Type, double        Value);
+	bool						Set_Parameter			(const SG_Char *Identifier, int Type, void          *Value);
+	bool						Set_Parameter			(const SG_Char *Identifier, int Type, const SG_Char *Value);
+
+	int							Assign					(CSG_Parameters *pSource);
+	int							Assign_Values			(CSG_Parameters *pSource);
+
+	bool						Serialize				(const CSG_String &File_Name, bool bSave);
+	bool						Serialize				(CSG_MetaData &Entry        , bool bSave);
+	bool						Serialize_Compatibility	(CSG_File &Stream);
+
+	//-----------------------------------------------------
+	bool						DataObjects_Check		(bool bSilent = false);
+
+	//-----------------------------------------------------
+	bool						Get_String				(CSG_String &String, bool bOptionsOnly);
+	bool						Msg_String				(bool bOptionsOnly);
+
+	bool						Set_History				(CSG_MetaData &History, bool bOptions = true, bool bDataObjects = true);
+
+	CSG_Grid_System *			Get_Grid_System			(void)	{	return( m_pGrid_System ? m_pGrid_System->asGrid_System() : NULL );	}
+
+	bool						is_Managed				(void)	{	return( m_bManaged );	}
+
+
+#ifdef _SAGA_UNICODE
+	CSG_Parameter *				Get_Parameter			(const char *Identifier);
+	CSG_Parameter *				operator()				(const char *Identifier)	{	return( Get_Parameter(Identifier) );	}
+	CSG_Parameter *				Add_Node				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Value				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value = 0.0, double Minimum = 0.0, bool bMinimum = false, double Maximum = 0.0, bool bMaximum = false);
+	CSG_Parameter *				Add_Info_Value			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, double Value = 0.0);
+	CSG_Parameter *				Add_Range				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min = 0.0, double Range_Max = 0.0, double Minimum = 0.0, bool bMinimum = false, double Maximum = 0.0, bool bMaximum = false);
+	CSG_Parameter *				Add_Info_Range			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, double Range_Min = 0.0, double Range_Max = 0.0);
+	CSG_Parameter *				Add_Choice				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Items, int Default = 0);
+	CSG_Parameter *				Add_String				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText = false, bool bPassword = false);
+	CSG_Parameter *				Add_Info_String			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *String, bool bLongText = false);
+	CSG_Parameter *				Add_FilePath			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, const SG_Char *Filter = NULL, const SG_Char *Default = NULL, bool bSave = false, bool bDirectory = false, bool bMultiple = false);
+	CSG_Parameter *				Add_Font				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, class wxFont *pInit = NULL);
+	CSG_Parameter *				Add_Colors				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Colors      *pInit = NULL);
+	CSG_Parameter *				Add_FixedTable			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Table   *pTemplate = NULL);
+	CSG_Parameter *				Add_Grid_System			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, CSG_Grid_System *pInit = NULL);
+	CSG_Parameter *				Add_Grid				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent = true, TSG_Data_Type Preferred_Type = SG_DATATYPE_Undefined);
+	CSG_Parameter *				Add_Grid_Output			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Grid_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, bool bSystem_Dependent = true);
+	CSG_Parameter *				Add_Table_Field			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bAllowNone = false);
+	CSG_Parameter *				Add_Table				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_Table_Output		(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Table_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_Shapes				(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Shape_Type = SHAPE_TYPE_Undefined);
+	CSG_Parameter *				Add_Shapes_Output		(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_Shapes_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint, TSG_Shape_Type Shape_Type = SHAPE_TYPE_Undefined);
+	CSG_Parameter *				Add_TIN					(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_TIN_Output			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_TIN_List			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_PointCloud			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_PointCloud_Output	(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+	CSG_Parameter *				Add_PointCloud_List		(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description, int Constraint);
+	CSG_Parameter *				Add_Parameters			(CSG_Parameter *pParent, const char *Identifier, const SG_Char *Name, const SG_Char *Description);
+#endif
+
+
+private:
+
+	void						*m_pOwner;
+
+	bool						m_bCallback, m_bManaged;
+
+	CSG_String					m_Identifier, m_Name, m_Description;
+
+	int							m_nParameters;
+
+	CSG_Parameter				**m_Parameters, *m_pGrid_System;
+
+	TSG_PFNC_Parameter_Changed	m_Callback;
+
+
+	void						_On_Construction		(void);
+
+	bool						_On_Parameter_Changed	(CSG_Parameter *pSender);
+
+	CSG_Parameter *				_Add_Value				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bInformation, TSG_Parameter_Type Type, double Value, double Minimum, bool bMinimum, double Maximum, bool bMaximum);
+	CSG_Parameter *				_Add_Range				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bInformation, double Range_Min, double Range_Max, double Minimum, bool bMinimum, double Maximum, bool bMaximum);
+	CSG_Parameter *				_Add_String				(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, bool bInformation, const SG_Char *String, bool bLongText, bool bPassword);
+
+	CSG_Parameter *				_Add					(CSG_Parameter *pParent, const SG_Char *Identifier, const SG_Char *Name, const SG_Char *Description, TSG_Parameter_Type Type, int Constraint);
+	CSG_Parameter *				_Add					(CSG_Parameter *pSource);
+
+	bool						DataObjects_Create		(void);
+	bool						DataObjects_Synchronize	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__parameters_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,878 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    pointcloud.cpp                     //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "pointcloud.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define POINTCLOUD_FILE_VERSION	"SGPC01"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_PointCloud * SG_Create_PointCloud(void)
+{
+	return( new CSG_PointCloud );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud * SG_Create_PointCloud(const CSG_PointCloud &PointCloud)
+{
+	return( new CSG_PointCloud(PointCloud) );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud * SG_Create_PointCloud(const CSG_String &File_Name)
+{
+	return( new CSG_PointCloud(File_Name) );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud * SG_Create_PointCloud(CSG_PointCloud *pStructure)
+{
+	return( new CSG_PointCloud(pStructure) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_PointCloud::CSG_PointCloud(void)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+}
+
+bool CSG_PointCloud::Create(void)
+{
+	Destroy();
+
+	Add_Field(SG_T(""), SG_DATATYPE_Undefined);	// add x, y, z fields
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud::CSG_PointCloud(const CSG_PointCloud &PointCloud)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(PointCloud);
+}
+
+bool CSG_PointCloud::Create(const CSG_PointCloud &PointCloud)
+{
+	if( Assign((CSG_Data_Object *)&PointCloud) )
+	{
+		Set_Name(PointCloud.Get_Name());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud::CSG_PointCloud(const CSG_String &File_Name)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(File_Name);
+}
+
+bool CSG_PointCloud::Create(const CSG_String &File_Name)
+{
+	return( _Load(File_Name) );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud::CSG_PointCloud(CSG_PointCloud *pStructure)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(pStructure);
+}
+
+bool CSG_PointCloud::Create(CSG_PointCloud *pStructure)
+{
+	Destroy();
+
+	if( pStructure && pStructure->Get_Field_Count() > 0 )
+	{
+		for(int i=0; i<pStructure->Get_Field_Count(); i++)
+		{
+			_Add_Field(pStructure->Get_Field_Name(i), pStructure->Get_Field_Type(i));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_PointCloud::_On_Construction(void)
+{
+	m_nFields		= 0;
+	m_Field_Name	= NULL;
+	m_Field_Type	= NULL;
+	m_Field_Stats	= NULL;
+	m_Field_Offset	= NULL;
+
+	m_Points		= NULL;
+	m_nPoints		= 0;
+	m_nBuffer		= 0;
+	m_nPointBytes	= 0;
+
+	m_Cursor		= NULL;
+	m_bXYZPrecDbl	= true;
+	m_NoData_Value	= -999999;
+
+	Set_Update_Flag();
+}
+
+//---------------------------------------------------------
+CSG_PointCloud::~CSG_PointCloud(void)
+{
+	Destroy();
+}
+
+bool CSG_PointCloud::Destroy(void)
+{
+	Del_Points();
+
+	if( m_nFields > 0 )
+	{
+		for(int i=0; i<m_nFields; i++)
+		{
+			delete(m_Field_Name [i]);
+			delete(m_Field_Stats[i]);
+		}
+
+		SG_Free(m_Field_Name);
+		SG_Free(m_Field_Type);
+		SG_Free(m_Field_Stats);
+		SG_Free(m_Field_Offset);
+
+		_On_Construction();
+	}
+
+	CSG_Data_Object::Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						File							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Load(const CSG_String &File_Name)
+{
+	TSG_Data_Type	Type;
+
+	char		ID[6];
+	int			i, iBuffer, nPointBytes, nFields;
+	char		Name[1024];
+	CSG_File	Stream;
+
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Load point cloud"), File_Name.c_str()), true);
+
+	//-----------------------------------------------------
+	if( !Stream.Open(File_Name, SG_FILE_R, true) )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] file could not be opened."));
+
+		return( false );
+	}
+
+	if( !Stream.Read(ID, 6) || strncmp(ID, POINTCLOUD_FILE_VERSION, 5) != 0 )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] incompatible file."));
+
+		return( false );
+	}
+
+	if( !Stream.Read(&nPointBytes, sizeof(int)) || nPointBytes < 3 * sizeof(float) )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] incompatible file."));
+
+		return( false );
+	}
+
+	if( !Stream.Read(&nFields, sizeof(int)) || nFields < 3 )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] incompatible file."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	Destroy();
+
+	for(i=0; i<nFields; i++)
+	{
+		if( !Stream.Read(&Type		, sizeof(TSG_Data_Type))
+		||	!Stream.Read(&iBuffer	, sizeof(int)) || !(iBuffer > 0 && iBuffer < 1024)
+		||	!Stream.Read(Name		, iBuffer) )
+		{
+			SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+			SG_UI_Msg_Add_Error(LNG("[ERR] incompatible file."));
+
+			return( false );
+		}
+
+		if( ID[5] == '0' )	// Data Type Definition changed!!!
+		{
+			switch( Type )
+			{
+			default:	Type	= SG_DATATYPE_Undefined;	break;
+			case 1:		Type	= SG_DATATYPE_Char;			break;
+			case 2:		Type	= SG_DATATYPE_Short;		break;
+			case 3:		Type	= SG_DATATYPE_Int;			break;
+			case 4:		Type	= SG_DATATYPE_Long;			break;
+			case 5:		Type	= SG_DATATYPE_Float;		break;
+			case 6:		Type	= SG_DATATYPE_Double;		break;
+			}
+		}
+
+		Name[iBuffer]	= '\0';
+
+		if( !_Add_Field(CSG_String((const char *)Name), Type) )
+		{
+			SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+			SG_UI_Msg_Add_Error(LNG("[ERR] incompatible file."));
+
+			return( false );
+		}
+	}
+
+	if( m_nPointBytes != nPointBytes )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] incompatible file."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	int		fLength	= Stream.Length();
+
+	while( _Inc_Array() && Stream.Read(m_Cursor, m_nPointBytes) && SG_UI_Process_Set_Progress(Stream.Tell(), fLength) )
+	{}
+
+	_Dec_Array();
+
+	Set_File_Name(File_Name);
+
+	Load_MetaData(File_Name);
+
+	if( m_nPoints <= 0 )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] no records in file."));
+
+		return( false );
+	}
+
+	SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Save(const CSG_String &File_Name)
+{
+	CSG_File	Stream;
+
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save point cloud"), File_Name.c_str()), true);
+
+	if( Stream.Open(File_Name, SG_FILE_W, true) == false )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+		SG_UI_Msg_Add_Error(LNG("[ERR] unable to create file."));
+
+		return( false );
+	}
+
+	int		i, iBuffer;
+
+	Stream.Write((void *)POINTCLOUD_FILE_VERSION, 6);
+	Stream.Write(&m_nPointBytes	, sizeof(int));
+	Stream.Write(&m_nFields		, sizeof(int));
+
+	for(i=0; i<m_nFields; i++)
+	{
+		Stream.Write(&m_Field_Type[i], sizeof(TSG_Data_Type));
+
+		iBuffer	= m_Field_Name[i]->Length();	if( iBuffer >= 1024 - 1 )	iBuffer	= 1024 - 1;
+		Stream.Write(&iBuffer, sizeof(int));
+		Stream.Write((void *)m_Field_Name[i]->b_str(), sizeof(char), iBuffer);
+	}
+
+	for(i=0; i<m_nPoints && SG_UI_Process_Set_Progress(i, m_nPoints); i++)
+	{
+		Stream.Write(m_Points[i], m_nPointBytes);
+	}
+
+	Set_Modified(false);
+
+	Set_File_Name(SG_File_Make_Path(NULL, File_Name, SG_T("spc")));
+
+	Save_MetaData(File_Name);
+
+	SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+
+	return( true );
+}
+
+bool CSG_PointCloud::Save(const CSG_String &File_Name, int Format)
+{
+	return( _Save(File_Name) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Assign							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PointCloud::Assign(CSG_Data_Object *pObject)
+{
+	if( pObject && pObject->is_Valid() && pObject->Get_ObjectType() == Get_ObjectType() )
+	{
+		Destroy();
+
+		CSG_PointCloud	*pPointCloud	= (CSG_PointCloud *)pObject;
+
+		Get_History()	= pPointCloud->Get_History();
+
+		for(int iField=0; iField<pPointCloud->m_nFields; iField++)
+		{
+			_Add_Field(pPointCloud->m_Field_Name[iField]->c_str(), pPointCloud->m_Field_Type[iField]);
+		}
+
+		for(int iPoint=0; iPoint<pPointCloud->m_nPoints; iPoint++)
+		{
+			if( _Inc_Array() )
+			{
+				memcpy(m_Points[iPoint], pPointCloud->m_Points[iPoint], m_nPointBytes);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Checks							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PointCloud::is_Compatible(CSG_PointCloud *pPointCloud) const
+{
+	if( Get_Field_Count() == pPointCloud->Get_Field_Count() )
+	{
+		for(int i=0; i<Get_Field_Count(); i++)
+		{
+			if( Get_Field_Type(i) != pPointCloud->Get_Field_Type(i) )
+			{
+				return( false );
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Fields							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Add_Field(const SG_Char *Name, TSG_Data_Type Type)
+{
+	if( SG_Data_Type_Get_Size(Type) <= 0 )
+	{
+		return( false );
+	}
+
+	m_Field_Name	= (CSG_String            **)SG_Realloc(m_Field_Name  , (m_nFields + 1) * sizeof(CSG_String *));
+	m_Field_Type	= (TSG_Data_Type          *)SG_Realloc(m_Field_Type  , (m_nFields + 1) * sizeof(TSG_Data_Type));
+	m_Field_Stats	= (CSG_Simple_Statistics **)SG_Realloc(m_Field_Stats , (m_nFields + 1) * sizeof(CSG_Simple_Statistics *));
+	m_Field_Offset	= (int                    *)SG_Realloc(m_Field_Offset, (m_nFields + 1) * sizeof(int));
+
+	m_Field_Name  [m_nFields]	= new CSG_String(Name);
+	m_Field_Type  [m_nFields]	= Type;
+	m_Field_Stats [m_nFields]	= new CSG_Simple_Statistics();
+	m_Field_Offset[m_nFields]	= m_nFields == 0 ? 0 : m_Field_Offset[m_nFields - 1] + SG_Data_Type_Get_Size(m_Field_Type[m_nFields - 1]);
+
+	m_nPointBytes	+= SG_Data_Type_Get_Size(m_Field_Type[m_nFields]);
+	m_nFields		++;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::Add_Field(const SG_Char *Name, TSG_Data_Type Type)
+{
+	if( m_nPoints == 0 )
+	{
+		if( m_nFields == 0 )
+		{
+			_Add_Field(SG_T("X"), m_bXYZPrecDbl ? SG_DATATYPE_Double : SG_DATATYPE_Float);
+			_Add_Field(SG_T("Y"), m_bXYZPrecDbl ? SG_DATATYPE_Double : SG_DATATYPE_Float);
+			_Add_Field(SG_T("Z"), m_bXYZPrecDbl ? SG_DATATYPE_Double : SG_DATATYPE_Float);
+		}
+
+		if( Name && SG_Data_Type_Get_Size(Type) > 0 )
+		{
+			return( _Add_Field(Name, Type) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+#ifdef _SAGA_UNICODE
+bool CSG_PointCloud::Add_Field(const char *Name, TSG_Data_Type Type)
+{	return( Add_Field(CSG_String(Name), Type) );	}
+#endif
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Set_Field_Value(char *pPoint, int iField, double Value)
+{
+	if( pPoint && iField >= 0 && iField < m_nFields )
+	{
+		pPoint	= ((char *)pPoint) + m_Field_Offset[iField];
+
+		switch( m_Field_Type[iField] )
+		{
+		default:
+		case SG_DATATYPE_Undefined:	break;
+		case SG_DATATYPE_Byte:		*((BYTE   *)pPoint)	= (BYTE  )Value;	break;
+		case SG_DATATYPE_Char:		*((char   *)pPoint)	= (char  )Value;	break;
+		case SG_DATATYPE_Word:		*((WORD   *)pPoint)	= (WORD  )Value;	break;
+		case SG_DATATYPE_Short:		*((short  *)pPoint)	= (short )Value;	break;
+		case SG_DATATYPE_DWord:		*((DWORD  *)pPoint)	= (DWORD )Value;	break;
+		case SG_DATATYPE_Int:		*((int    *)pPoint)	= (int   )Value;	break;
+		case SG_DATATYPE_Long:		*((long   *)pPoint)	= (long  )Value;	break;
+		case SG_DATATYPE_Float:		*((float  *)pPoint)	= (float )Value;	break;
+		case SG_DATATYPE_Double:	*((double *)pPoint)	= (double)Value;	break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CSG_PointCloud::_Get_Field_Value(char *pPoint, int iField) const
+{
+	if( pPoint && iField >= 0 && iField < m_nFields )
+	{
+		pPoint	= ((char *)pPoint) + m_Field_Offset[iField];
+
+		switch( m_Field_Type[iField] )
+		{
+		case SG_DATATYPE_Undefined:		default:	break;
+		case SG_DATATYPE_Byte:			return( *((BYTE   *)pPoint) );
+		case SG_DATATYPE_Char:			return( *((char   *)pPoint) );
+		case SG_DATATYPE_Word:			return( *((WORD   *)pPoint) );
+		case SG_DATATYPE_Short:			return( *((short  *)pPoint) );
+		case SG_DATATYPE_DWord:			return( *((DWORD  *)pPoint) );
+		case SG_DATATYPE_Int:			return( *((int    *)pPoint) );
+		case SG_DATATYPE_Long:			return( *((long   *)pPoint) );
+		case SG_DATATYPE_Float:			return( *((float  *)pPoint) );
+		case SG_DATATYPE_Double:		return( *((double *)pPoint) );
+		}
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_Point_3D CSG_PointCloud::Get_Point(void)	const
+{
+	TSG_Point_3D	p;
+
+	if( m_Cursor )
+	{
+		p.x	= _Get_Field_Value(m_Cursor, 0);
+		p.y	= _Get_Field_Value(m_Cursor, 1);
+		p.z	= _Get_Field_Value(m_Cursor, 2);
+	}
+	else
+	{
+		p.x	= p.y	= p.z	= 0.0;
+	}
+
+	return( p );
+}
+
+//---------------------------------------------------------
+TSG_Point_3D CSG_PointCloud::Get_Point(int iPoint)	const
+{
+	TSG_Point_3D	p;
+
+	if( iPoint >= 0 && iPoint < m_nPoints )
+	{
+		char	*pPoint	= m_Points[iPoint];
+
+		p.x	= _Get_Field_Value(pPoint, 0);
+		p.y	= _Get_Field_Value(pPoint, 1);
+		p.z	= _Get_Field_Value(pPoint, 2);
+	}
+	else
+	{
+		p.x	= p.y	= p.z	= 0.0;
+	}
+
+	return( p );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::Set_NoData_Value(double NoData_Value)
+{
+	if( NoData_Value != m_NoData_Value )
+	{
+		for(int i=3; i<m_nFields; i++)
+		{
+			m_Field_Stats[i]->Invalidate();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PointCloud::Add_Point(double x, double y, double z)
+{
+	if( _Inc_Array() )
+	{
+		_Set_Field_Value(m_Cursor, 0, x);
+		_Set_Field_Value(m_Cursor, 1, y);
+		_Set_Field_Value(m_Cursor, 2, z);
+
+		Set_Modified();
+
+		Set_Update_Flag();
+
+		_Stats_Invalidate();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::Del_Point(int iPoint)
+{
+	if( iPoint >= 0 && iPoint < m_nPoints )
+	{
+		m_Cursor	= NULL;
+
+		delete(m_Points[iPoint]);
+
+		m_nPoints--;
+
+		for(int i=iPoint, j=iPoint+1; i<m_nPoints; i++, j++)
+		{
+			m_Points[i]	= m_Points[i + 1];
+		}
+
+		_Dec_Array();
+
+		Set_Modified();
+
+		Set_Update_Flag();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::Del_Points(void)
+{
+	if( m_nBuffer > 0 )
+	{
+		for(int iPoint=0; iPoint<m_nPoints; iPoint++)
+		{
+			SG_Free(m_Points[iPoint]);
+		}
+
+		SG_Free(m_Points);
+		m_Points	= NULL;
+		m_nPoints	= 0;
+		m_nBuffer	= 0;
+		m_Cursor	= NULL;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_GROW_SIZE(n)	(n < 256 ? 1 : (n < 8192 ? 128 : 1024))
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Inc_Array(void)
+{
+	if( m_nFields > 0 )
+	{
+		if( (m_nPoints + 1) >= m_nBuffer )
+		{
+			char	**pPoints	= (char **)SG_Realloc(m_Points, (m_nBuffer + GET_GROW_SIZE(m_nBuffer)) * sizeof(char *));
+
+			if( pPoints )
+			{
+				m_Points	= pPoints;
+				m_nBuffer	+= GET_GROW_SIZE(m_nBuffer);
+			}
+			else
+			{
+				return( false );
+			}
+		}
+
+		m_Cursor	= m_Points[m_nPoints]	= (char *)SG_Calloc(m_nPointBytes, sizeof(char));
+		m_nPoints	++;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Dec_Array(void)
+{
+	if( m_nPoints > 0 )
+	{
+		_Stats_Invalidate();
+
+		m_Cursor	= NULL;
+		m_nPoints	--;
+
+		SG_Free(m_Points[m_nPoints]);
+
+		if( (m_nPoints - 1) < m_nBuffer - GET_GROW_SIZE(m_nBuffer) )
+		{
+			char	**pPoints	= (char **)SG_Realloc(m_Points, (m_nBuffer - GET_GROW_SIZE(m_nBuffer)) * sizeof(char *));
+
+			if( pPoints )
+			{
+				m_Points	= pPoints;
+				m_nBuffer	-= GET_GROW_SIZE(m_nBuffer);
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Statistics						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const CSG_Rect & CSG_PointCloud::Get_Extent(void)
+{
+	if( m_nFields >= 2 )
+	{
+		_Stats_Update(0);
+		_Stats_Update(1);
+
+		m_Extent.Assign(
+			m_Field_Stats[0]->Get_Minimum(), m_Field_Stats[1]->Get_Minimum(),
+			m_Field_Stats[0]->Get_Maximum(), m_Field_Stats[1]->Get_Maximum()
+		);
+	}
+
+	return( m_Extent );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Stats_Invalidate(void) const
+{
+	for(int iField=0; iField<m_nFields; iField++)
+	{
+		_Stats_Invalidate(iField);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Stats_Invalidate(int iField) const
+{
+	if( iField >= 0 && iField < m_nFields )
+	{
+		m_Field_Stats[iField]->Invalidate();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_PointCloud::_Stats_Update(int iField) const
+{
+	if( iField >= 0 && iField < m_nFields && m_nPoints > 0 )
+	{
+		if( !m_Field_Stats[iField]->is_Evaluated() )
+		{
+			char	**pPoint	= m_Points;
+
+			for(int iPoint=0; iPoint<m_nPoints; iPoint++, pPoint++)
+			{
+				double	Value	= _Get_Field_Value(*pPoint, iField);
+
+				if( iField < 3 || Value != m_NoData_Value )
+				{
+					m_Field_Stats[iField]->Add_Value(Value);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/pointcloud.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,242 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     pointcloud.h                      //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__pointcloud_H
+#define HEADER_INCLUDED__SAGA_API__pointcloud_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dataobject.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_PointCloud : public CSG_Data_Object
+{
+public:
+
+									CSG_PointCloud		(void);
+	bool							Create				(void);
+
+									CSG_PointCloud		(const CSG_PointCloud &PointCloud);
+	bool							Create				(const CSG_PointCloud &PointCloud);
+
+									CSG_PointCloud		(const CSG_String &File_Name);
+	bool							Create				(const CSG_String &File_Name);
+
+									CSG_PointCloud		(CSG_PointCloud *pStructure);
+	bool							Create				(CSG_PointCloud *pStructure);
+
+	virtual ~CSG_PointCloud(void);
+
+	virtual bool					Destroy				(void);
+
+	virtual TSG_Data_Object_Type	Get_ObjectType		(void)	const			{	return( DATAOBJECT_TYPE_PointCloud );	}
+
+	virtual bool					Assign				(CSG_Data_Object *pSource);
+
+	virtual bool					Save				(const CSG_String &File_Name, int Format = 0);
+
+	const CSG_Rect &				Get_Extent			(void);
+
+	void							Set_XYZ_Precision	(bool bDouble)			{	m_bXYZPrecDbl	= bDouble;	}
+
+	//-----------------------------------------------------
+	virtual bool					is_Valid			(void)	const			{	return( m_nPoints > 0 );	}
+	bool							is_Compatible		(CSG_PointCloud *pPointCloud)	const;
+
+	//-----------------------------------------------------
+	bool							Add_Field			(const SG_Char *Name, TSG_Data_Type Type);
+#ifdef _SAGA_UNICODE
+	bool							Add_Field			(const char    *Name, TSG_Data_Type Type);
+#endif
+
+	int								Get_Field_Count		(void)			const	{	return( m_nFields );	}
+	const SG_Char *					Get_Field_Name		(int iField)	const	{	return( iField >= 0 && iField < m_nFields ? m_Field_Name[iField]->c_str() : NULL );				}
+	TSG_Data_Type					Get_Field_Type		(int iField)	const	{	return( iField >= 0 && iField < m_nFields ? m_Field_Type[iField] : SG_DATATYPE_Undefined );	}
+
+	int								Get_Attribute_Count	(void)			const	{	return( m_nFields );	}
+	const SG_Char *					Get_Attribute_Name	(int iField)	const	{	return( iField >= 0 && iField < m_nFields ? m_Field_Name[iField]->c_str() : NULL );				}
+	TSG_Data_Type					Get_Attribute_Type	(int iField)	const	{	return( iField >= 0 && iField < m_nFields ? m_Field_Type[iField] : SG_DATATYPE_Undefined );	}
+
+	double							Get_Minimum			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Minimum()  : 0.0 );	}
+	double							Get_Maximum			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Maximum()  : 0.0 );	}
+	double							Get_Range			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Range()    : 0.0 );	}
+	double							Get_Mean			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Mean()     : 0.0 );	}
+	double							Get_StdDev			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_StdDev()   : 0.0 );	}
+	double							Get_Variance		(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Variance() : 0.0 );	}
+
+	//-----------------------------------------------------
+	bool							Add_Point			(double x, double y, double z);
+	bool							Del_Point			(int iPoint);
+	bool							Del_Points			(void);
+
+	int								Get_Point_Count		(void)			const	{	return( m_nPoints );	}
+	int								Get_Count			(void)			const	{	return( m_nPoints );	}
+
+	//-----------------------------------------------------
+	bool							Set_Cursor			(int iPoint)				{	return( (m_Cursor = iPoint >= 0 && iPoint < m_nPoints ? m_Points[iPoint] : NULL) != NULL );	}
+	bool							Set_Value			(int iField, double Value)	{	return( _Set_Field_Value(m_Cursor, iField, Value) );	}
+	double							Get_Value			(int iField)	const		{	return( _Get_Field_Value(m_Cursor, iField) );			}
+	double							Get_X				(void)			const		{	return( _Get_Field_Value(m_Cursor, 0) );				}
+	double							Get_Y				(void)			const		{	return( _Get_Field_Value(m_Cursor, 1) );				}
+	double							Get_Z				(void)			const		{	return( _Get_Field_Value(m_Cursor, 2) );				}
+	bool							Set_Attribute		(int iField, double Value)	{	return( Set_Value(iField + 3, Value) );					}
+	double							Get_Attribute		(int iField)	const		{	return( Get_Value(iField + 3) );						}
+	bool							Set_NoData			(int iField)				{	return( Set_Attribute(iField, m_NoData_Value) );		}
+	bool							is_NoData			(int iField)	const		{	return( Get_Attribute(iField) == m_NoData_Value );		}
+
+	bool							Set_Value			(int iPoint, int iField, double Value)	{	return( _Set_Field_Value(iPoint >= 0 && iPoint < m_nPoints ? m_Points[iPoint] : NULL, iField, Value) );	}
+	double							Get_Value			(int iPoint, int iField)	const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nPoints ? m_Points[iPoint] : NULL, iField) );		}
+	double							Get_X				(int iPoint)				const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nPoints ? m_Points[iPoint] : NULL, 0) );				}
+	double							Get_Y				(int iPoint)				const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nPoints ? m_Points[iPoint] : NULL, 1) );				}
+	double							Get_Z				(int iPoint)				const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nPoints ? m_Points[iPoint] : NULL, 2) );				}
+	bool							Set_Attribute		(int iPoint, int iField, double Value)	{	return( Set_Value(iPoint, iField + 3, Value) );				}
+	double							Get_Attribute		(int iPoint, int iField)	const		{	return( Get_Value(iPoint, iField + 3) );					}
+	bool							Set_NoData			(int iPoint, int iField)				{	return( Set_Attribute(iPoint, iField, m_NoData_Value) );	}
+	bool							is_NoData			(int iPoint, int iField)	const		{	return( Get_Attribute(iPoint, iField) == m_NoData_Value );	}
+
+	TSG_Point_3D					Get_Point			(void)			const;
+	TSG_Point_3D					Get_Point			(int iPoint)	const;
+
+	double							Get_NoData_Value	(void)			const		{	return( m_NoData_Value );	}
+	bool							Set_NoData_Value	(double NoData_Value);
+
+	virtual void					Set_Modified		(bool bModified = true)	{	CSG_Data_Object::Set_Modified(bModified);	}
+
+
+protected:
+
+	bool							m_bXYZPrecDbl;
+
+	char							**m_Points, *m_Cursor;
+
+	int								m_nFields, m_nPoints, m_nBuffer, m_nPointBytes, *m_Field_Offset;
+
+	double							m_NoData_Value;
+
+	TSG_Data_Type					*m_Field_Type;
+
+	CSG_Simple_Statistics			**m_Field_Stats;
+
+	CSG_String						**m_Field_Name;
+
+	CSG_Rect						m_Extent;
+
+
+	virtual void					_On_Construction	(void);
+
+	bool							_Load				(const CSG_String &File_Name);
+	bool							_Save				(const CSG_String &File_Name);
+
+	bool							_Add_Field			(const SG_Char *Name, TSG_Data_Type Type);
+	bool							_Set_Field_Value	(char *pPoint, int iField, double Value);
+	double							_Get_Field_Value	(char *pPoint, int iField)	const;
+	int								_Get_Field_Bytes	(TSG_Data_Type Type);
+
+	bool							_Inc_Array			(void);
+	bool							_Dec_Array			(void);
+
+	bool							_Stats_Invalidate	(void)			const;
+	bool							_Stats_Invalidate	(int iField)	const;
+	bool							_Stats_Update		(int iField)	const;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/** Safe Point Cloud construction */
+SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(void);
+
+/** Safe Point Cloud construction */
+SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(const CSG_PointCloud &PointCloud);
+
+/** Safe Point Cloud construction */
+SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(const CSG_String &File_Name);
+
+/** Safe Point Cloud construction */
+SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(CSG_PointCloud *pStructure);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__pointcloud_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/projections.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/projections.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/projections.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,534 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    projections.cpp                    //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "geo_tools.h"
+
+#include "table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Projections		gSG_Projections;
+
+//---------------------------------------------------------
+CSG_Projections &	SG_Get_Projections(void)
+{
+	return( gSG_Projections );
+}
+
+//---------------------------------------------------------
+CSG_String			SG_Get_Projection_Type_Name(TSG_Projection_Type Type)
+{
+	switch( Type )
+	{
+	default:
+	case SG_PROJ_TYPE_CS_Undefined:		return( LNG("Undefined Coordinate System") );
+	case SG_PROJ_TYPE_CS_Projected:		return( LNG("Projected Coordinate System") );
+	case SG_PROJ_TYPE_CS_Geographic:	return( LNG("Geographic Coordinate System") );
+	case SG_PROJ_TYPE_CS_Geocentric:	return( LNG("Geocentric Coordinate System") );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Projection::CSG_Projection(void)
+{
+	_Reset();
+}
+
+CSG_Projection::~CSG_Projection(void)
+{}
+
+//---------------------------------------------------------
+CSG_Projection::CSG_Projection(const CSG_Projection &Projection)
+{
+	_Reset();
+
+	Create(Projection);
+}
+
+bool CSG_Projection::Create(const CSG_Projection &Projection)
+{
+	return( Assign(Projection) );
+}
+
+//---------------------------------------------------------
+CSG_Projection::CSG_Projection(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4)
+{
+	_Reset();
+
+	Create(SRID, Authority, OpenGIS, Proj4);
+}
+
+bool CSG_Projection::Create(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4)
+{
+	return( Assign(SRID, Authority, OpenGIS, Proj4) );
+}
+
+//---------------------------------------------------------
+void CSG_Projection::_Reset(void)
+{
+	m_SRID		= -1;
+	m_Type		= SG_PROJ_TYPE_CS_Undefined;
+	m_Name		= LNG("undefined");
+	m_OpenGIS	.Clear();
+	m_Proj4		.Clear();
+	m_Authority	.Clear();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Projection::Assign(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4)
+{
+	_Reset();
+
+	if( !OpenGIS )
+	{
+		if( !_Get_OpenGIS_from_Proj4(Proj4) )
+		{
+			return( false );
+		}
+	}
+	else
+	{
+		m_OpenGIS	= OpenGIS;
+	}
+
+	CSG_String	s(m_OpenGIS.BeforeFirst('['));
+
+	if( !s.Cmp(SG_T("PROJCS")) )
+	{
+		m_Type	= SG_PROJ_TYPE_CS_Projected;
+	}
+	else if( !s.Cmp(SG_T("GEOGCS")) )
+	{
+		m_Type	= SG_PROJ_TYPE_CS_Geographic;
+	}
+	else if( !s.Cmp(SG_T("GEOCCS")) )
+	{
+		m_Type	= SG_PROJ_TYPE_CS_Geocentric;
+	}
+	else
+	{
+		return( false );
+	}
+
+	if( !Proj4 )
+	{
+		_Get_Proj4_from_OpenGIS(OpenGIS);
+	}
+	else
+	{
+		m_Proj4		= Proj4;
+	}
+
+	m_SRID		= SRID;
+	m_Authority	= Authority ? Authority : SG_T("");
+	m_Name		= m_OpenGIS.AfterFirst('\"').BeforeFirst('\"');
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Projection::Assign(const CSG_Projection &Projection)
+{
+	m_SRID		= Projection.m_SRID;
+	m_Type		= Projection.m_Type;
+	m_Name		= Projection.m_Name;
+	m_OpenGIS	= Projection.m_OpenGIS;
+	m_Proj4		= Projection.m_Proj4;
+	m_Authority	= Projection.m_Authority;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Projection::is_Equal(const CSG_Projection &Projection)	const
+{
+	return(	m_SRID == Projection.m_SRID
+		&&	m_Type == Projection.m_Type
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Projection::_Get_OpenGIS_from_Proj4(const SG_Char *Text)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Projection::_Get_Proj4_from_OpenGIS(const SG_Char *Text)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Projection::from_ESRI(const CSG_String &ESRI_PRJ)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Projection::to_ESRI(CSG_String &ESRI_PRJ)	const
+{
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_String CSG_Projection::asString(void) const
+{
+	return( m_Name );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define PRJ_FIELD_SRID			0
+#define PRJ_FIELD_AUTH_NAME		1
+#define PRJ_FIELD_AUTH_SRID		2
+#define PRJ_FIELD_SRTEXT		3
+#define PRJ_FIELD_PROJ4TEXT		4
+
+//---------------------------------------------------------
+CSG_Projections *CSG_Projections::s_pProjections	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Projections::CSG_Projections(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Projections::CSG_Projections(const CSG_String &File_Name)
+{
+	_On_Construction();
+
+	Create(File_Name);
+}
+
+bool CSG_Projections::Create(const CSG_String &File_Name)
+{
+	CSG_Table	Projections(File_Name);
+
+	return( Create(&Projections) );
+}
+
+//---------------------------------------------------------
+CSG_Projections::CSG_Projections(CSG_Table *pProjections)
+{
+	_On_Construction();
+
+	Create(pProjections);
+}
+
+bool CSG_Projections::Create(CSG_Table *pProjections)
+{
+	Destroy();
+
+	if( !pProjections )
+	{
+		return( false );
+	}
+
+	for(int i=0; i<pProjections->Get_Count() && SG_UI_Process_Set_Progress(i, pProjections->Get_Count()); i++)
+	{
+		CSG_Projection		Projection;
+		CSG_Table_Record	*pRecord	= pProjections->Get_Record(i);
+
+		if( Projection.Assign(
+			pRecord->asInt   (PRJ_FIELD_SRID),
+			pRecord->asString(PRJ_FIELD_AUTH_NAME),
+			pRecord->asString(PRJ_FIELD_SRTEXT),
+			pRecord->asString(PRJ_FIELD_PROJ4TEXT)) )
+		{
+			Add(Projection);
+		}
+	}
+
+	return( Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+void CSG_Projections::_On_Construction(void)
+{
+	m_pProjections	= NULL;
+	m_nProjections	= 0;
+	m_nBuffer		= 0;
+
+	m_pIdx_Names	= new CSG_Index;
+	m_pIdx_SRIDs	= new CSG_Index;
+}
+
+//---------------------------------------------------------
+CSG_Projections::~CSG_Projections(void)
+{
+	Destroy();
+
+	delete(m_pIdx_Names);
+	delete(m_pIdx_SRIDs);
+}
+
+//---------------------------------------------------------
+void CSG_Projections::Destroy(void)
+{
+	if( m_pProjections )
+	{
+		for(int i=0; i<m_nProjections; i++)
+		{
+			delete(m_pProjections[i]);
+		}
+
+		SG_Free(m_pProjections);
+
+		m_pProjections	= NULL;
+		m_nProjections	= 0;
+		m_nBuffer		= 0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Projections::Load(const CSG_String &File_Name)
+{
+	return( Create(File_Name) );
+}
+
+//---------------------------------------------------------
+bool CSG_Projections::Save(const CSG_String &File_Name)
+{
+	CSG_Table	Table;
+
+	Table.Add_Field(SG_T("srid")		, SG_DATATYPE_Int);
+	Table.Add_Field(SG_T("auth_name")	, SG_DATATYPE_String);
+	Table.Add_Field(SG_T("auth_srid")	, SG_DATATYPE_Int);
+	Table.Add_Field(SG_T("srtext")		, SG_DATATYPE_String);
+	Table.Add_Field(SG_T("proj4text")	, SG_DATATYPE_String);
+
+	for(int i=0; i<m_nProjections && SG_UI_Process_Set_Progress(i, m_nProjections); i++)
+	{
+		CSG_Projection		*pProjection	= m_pProjections[i];
+		CSG_Table_Record	*pRecord		= Table.Add_Record();
+
+		pRecord->Set_Value(PRJ_FIELD_SRID		, pProjection->Get_SRID());
+		pRecord->Set_Value(PRJ_FIELD_AUTH_NAME	, pProjection->Get_Authority());
+		pRecord->Set_Value(PRJ_FIELD_AUTH_SRID	, pProjection->Get_SRID());
+		pRecord->Set_Value(PRJ_FIELD_SRTEXT		, pProjection->Get_OpenGIS());
+		pRecord->Set_Value(PRJ_FIELD_PROJ4TEXT	, pProjection->Get_Proj4());
+	}
+
+	return( Table.Save(File_Name) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_GROW_SIZE(n)	(n < 64 ? 1 : (n < 1024 ? 64 : 1024))
+
+//---------------------------------------------------------
+CSG_Projection * CSG_Projections::_Add(void)
+{
+	if( (m_nProjections + 1) >= m_nBuffer )
+	{
+		CSG_Projection	**pProjections	= (CSG_Projection **)SG_Realloc(m_pProjections, (m_nBuffer + GET_GROW_SIZE(m_nBuffer)) * sizeof(char *));
+
+		if( !pProjections )
+		{
+			return( NULL );
+		}
+
+		m_pProjections	 = pProjections;
+		m_nBuffer		+= GET_GROW_SIZE(m_nBuffer);
+	}
+
+	return( m_pProjections[m_nProjections++] = new CSG_Projection );
+}
+
+//---------------------------------------------------------
+bool CSG_Projections::Add(const CSG_Projection &Projection)
+{
+	CSG_Projection	*pProjection	= _Add();
+
+	if( pProjection )
+	{
+		return( pProjection->Assign(Projection) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Projections::Add(int SRID, const SG_Char *Authority, const SG_Char *OpenGIS, const SG_Char *Proj4)
+{
+	CSG_Projection	Projection;
+
+	return( Projection.Create(SRID, Authority, OpenGIS, Proj4) && Add(Projection) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Projections::_Cmp_Names(const int iElement_1, const int iElement_2)
+{
+	return(	(*s_pProjections)[iElement_1].Get_Type() ==  (*s_pProjections)[iElement_2].Get_Type()
+		?	(*s_pProjections)[iElement_1].Get_Name().Cmp((*s_pProjections)[iElement_2].Get_Name())
+		:	(*s_pProjections)[iElement_1].Get_Type()  -  (*s_pProjections)[iElement_2].Get_Type()	);
+}
+
+//---------------------------------------------------------
+int CSG_Projections::_Cmp_SRIDs(const int iElement_1, const int iElement_2)
+{
+	return( (*s_pProjections)[iElement_1].Get_SRID()  -  (*s_pProjections)[iElement_2].Get_SRID() );
+}
+
+//---------------------------------------------------------
+CSG_String CSG_Projections::Get_Names(void) const
+{
+	s_pProjections	= (CSG_Projections *)this;
+
+	if( m_pIdx_Names->Get_Count() != m_nProjections )
+	{
+		m_pIdx_Names->Create(m_nProjections, (TSG_PFNC_Compare)CSG_Projections::_Cmp_Names, true);
+	}
+
+	if( m_pIdx_SRIDs->Get_Count() != m_nProjections )
+	{
+		m_pIdx_SRIDs->Create(m_nProjections, _Cmp_SRIDs, true);
+	}
+
+	//-----------------------------------------------------
+	CSG_String	s;
+
+	for(int i=0; i<m_nProjections; i++)
+	{
+		CSG_Projection	*pProjection	= m_pProjections[(*m_pIdx_Names)[i]];
+
+		s	+= CSG_String::Format(SG_T("[%s] %s|"),
+				pProjection->Get_Type_Name().c_str(),
+				pProjection->Get_Name().c_str()
+			);
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+int CSG_Projections::Get_SRID_byNamesIndex(int i) const
+{
+	if( i >= 0 && i < Get_Count() )
+	{
+		return( Get_Projection((*m_pIdx_Names)[i]).Get_SRID() );
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/quadtree.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/quadtree.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/quadtree.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,610 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     quadtree.cpp                      //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_PRQuadTree_Node::CSG_PRQuadTree_Node(double xCenter, double yCenter, double Size)
+	: CSG_PRQuadTree_Item(xCenter, yCenter, Size)
+{
+	m_pChildren[0]	=
+	m_pChildren[1]	=
+	m_pChildren[2]	=
+	m_pChildren[3]	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_PRQuadTree_Node::~CSG_PRQuadTree_Node(void)
+{
+	for(int i=0; i<4; i++)
+	{
+		if( m_pChildren[i] )
+		{
+			if( m_pChildren[i]->is_Leaf() )
+			{
+				delete((CSG_PRQuadTree_Leaf *)m_pChildren[i]);
+			}
+			else
+			{
+				delete((CSG_PRQuadTree_Node *)m_pChildren[i]);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_PRQuadTree_Node::Add_Point(double x, double y, double z)
+{
+	if( Contains(x, y) )
+	{
+		int		i	=  y < m_yCenter ? (x < m_xCenter ? 0 : 3) : (x < m_xCenter ? 1 : 2);
+
+		//-------------------------------------------------
+		if( m_pChildren[i] == NULL )
+		{
+			double	Size	= 0.5 * m_Size;
+
+			switch( i )
+			{
+			case 0:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter - Size, m_yCenter - Size, Size, x, y, z);	break;
+			case 1:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter - Size, m_yCenter + Size, Size, x, y, z);	break;
+			case 2:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter + Size, m_yCenter + Size, Size, x, y, z);	break;
+			case 3:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter + Size, m_yCenter - Size, Size, x, y, z);	break;
+			}
+
+			return( true );
+		}
+
+		//-----------------------------------------------------
+		else if( m_pChildren[i]->is_Leaf() )
+		{
+			CSG_PRQuadTree_Leaf	*pLeaf	= (CSG_PRQuadTree_Leaf *)m_pChildren[i];
+
+			if( x != pLeaf->Get_X() || y != pLeaf->Get_Y() )
+			{
+				CSG_PRQuadTree_Node	*pNode	= new CSG_PRQuadTree_Node(pLeaf->m_xCenter, pLeaf->m_yCenter, pLeaf->m_Size);
+
+				pNode->Add_Point(pLeaf->Get_X(), pLeaf->Get_Y(), pLeaf->Get_Z());
+				pNode->Add_Point(x, y, z);
+
+				m_pChildren[i]	= pNode;
+
+				delete(pLeaf);
+
+				return( true );
+			}
+		}
+
+		//-------------------------------------------------
+		else // if( m_pChildren[i]->is_Node() )
+		{
+			return( ((CSG_PRQuadTree_Node *)m_pChildren[i])->Add_Point(x, y, z) );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_PRQuadTree::CSG_PRQuadTree(void)
+{
+	m_pRoot		= NULL;
+	m_nSelected	= 0;
+	m_nPoints	= 0;
+}
+
+//---------------------------------------------------------
+CSG_PRQuadTree::CSG_PRQuadTree(const TSG_Rect &Extent)
+{
+	m_pRoot		= NULL;
+	m_nSelected	= 0;
+	m_nPoints	= 0;
+
+	Create(Extent);
+}
+
+//---------------------------------------------------------
+CSG_PRQuadTree::CSG_PRQuadTree(CSG_Shapes *pShapes, int Attribute)
+{
+	m_pRoot		= NULL;
+	m_nSelected	= 0;
+	m_nPoints	= 0;
+
+	Create(pShapes, Attribute);
+}
+
+//---------------------------------------------------------
+CSG_PRQuadTree::~CSG_PRQuadTree(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool CSG_PRQuadTree::Create(const CSG_Rect &Extent)
+{
+	Destroy();
+
+	if( Extent.Get_XRange() > 0.0 && Extent.Get_YRange() > 0.0 )
+	{
+		m_pRoot	= new CSG_PRQuadTree_Node(
+			Extent.Get_XCenter(),
+			Extent.Get_YCenter(),
+			(0.5 + 0.01) * (Extent.Get_XRange() > Extent.Get_YRange() ? Extent.Get_XRange() : Extent.Get_YRange())
+		);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_PRQuadTree::Create(CSG_Shapes *pShapes, int Attribute)
+{
+	Destroy();
+
+	if( pShapes && pShapes->is_Valid() && Create(pShapes->Get_Extent()) )
+	{
+		for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					TSG_Point	p	= pShape->Get_Point(iPoint, iPart);
+
+					Add_Point(p.x, p.y, pShape->asDouble(Attribute));
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_PRQuadTree::Destroy(void)
+{
+	if( m_pRoot )
+	{
+		delete(m_pRoot);
+
+		m_pRoot	= NULL;
+	}
+
+	m_Selected.Destroy();
+	m_nSelected	= 0;
+	m_nPoints	= 0;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PRQuadTree::Add_Point(double x, double y, double z)
+{
+	if( m_pRoot && m_pRoot->Add_Point(x, y, z) )
+	{
+		m_nPoints++;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_PRQuadTree::Get_Nearest_Point(double x, double y, TSG_Point &Point, double &Value, double &Distance)
+{
+	if( m_pRoot && m_pRoot->Contains(x, y) )
+	{
+		double	maxDistance	= -1.0, p[4];
+
+		_Get_Nearest_Point(m_pRoot, x, y, maxDistance, p);
+
+		Point.x		= p[0];
+		Point.y		= p[1];
+		Value		= p[2];
+		Distance	= p[3];
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSG_PRQuadTree::_Get_Nearest_Point(CSG_PRQuadTree_Item *pItem, double x, double y, double &maxDistance, double Point[4])
+{
+	int		i;
+
+	if( pItem->is_Leaf() )
+	{
+		CSG_PRQuadTree_Leaf	*pLeaf	= (CSG_PRQuadTree_Leaf *)pItem;
+
+		double	d	= SG_Get_Distance(x, y, pLeaf->Get_X(), pLeaf->Get_Y());
+
+		if( maxDistance < 0.0 || maxDistance > d )
+		{
+			Point[0]	= pLeaf->Get_X();
+			Point[1]	= pLeaf->Get_Y();
+			Point[2]	= pLeaf->Get_Z();
+			Point[3]	= maxDistance	= d;
+		}
+	}
+	else
+	{
+		CSG_PRQuadTree_Item	*pChild;
+
+		for(i=0; i<4; i++)
+		{
+			if( (pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i)) != NULL && pChild->Contains(x, y) == true )
+			{
+				_Get_Nearest_Point(pChild, x, y, maxDistance, Point);
+			}
+		}
+
+		for(i=0; i<4; i++)
+		{
+			if( (pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i)) != NULL && pChild->Contains(x, y) == false )
+			{
+				if( maxDistance < 0.0
+				||	(	maxDistance > (x < pChild->Get_xCenter() ? pChild->Get_xMin() - x : x - pChild->Get_xMax())
+					&&	maxDistance > (y < pChild->Get_yCenter() ? pChild->Get_yMin() - y : y - pChild->Get_yMax())	) )
+				{
+					_Get_Nearest_Point(pChild, x, y, maxDistance, Point);
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CSG_PRQuadTree::_Quadrant_Contains(double x, double y, int iQuadrant, const TSG_Point &p)
+{
+	switch( iQuadrant )
+	{
+	case 0:	return( x <  p.x && y <  p.y );	// lower left
+	case 1:	return( x <  p.x && y >= p.y );	// upper left
+	case 2:	return( x >= p.x && y >= p.y );	// upper right
+	case 3:	return( x >= p.x && y <  p.y );	// lower right
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CSG_PRQuadTree::_Radius_Contains(double x, double y, double r, const TSG_Point &p)
+{
+	double	dx, dy;
+
+	if( fabs(dx = x - p.x) <= r && fabs(dy = y - p.y) <= r )
+	{
+		return( dx*dx + dy*dy < r*r );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline bool CSG_PRQuadTree::_Radius_Contains(double x, double y, double r, int iQuadrant, const TSG_Point &p)
+{
+	return( _Quadrant_Contains(x, y, iQuadrant, p) && _Radius_Contains(x, y, r, p) );
+}
+
+//---------------------------------------------------------
+inline bool CSG_PRQuadTree::_Quadrant_Intersects(double x, double y, int iQuadrant, CSG_PRQuadTree_Item *pItem)
+{
+	switch( iQuadrant )
+	{
+	case 0:	return( x <  pItem->Get_xMax() && y <  pItem->Get_yMax() );	// lower left
+	case 1:	return( x <  pItem->Get_xMax() && y >= pItem->Get_yMin() );	// upper left
+	case 2:	return( x >= pItem->Get_xMin() && y >= pItem->Get_yMin() );	// upper right
+	case 3:	return( x >= pItem->Get_xMin() && y <  pItem->Get_yMax() );	// lower right
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+inline bool CSG_PRQuadTree::_Radius_Intersects(double x, double y, double r, CSG_PRQuadTree_Item *pItem)
+{
+	if( r <= 0.0 )
+	{
+		return( true );
+	}
+
+	if(	pItem->Get_xMax() < x - r || pItem->Get_xMin() > x + r
+	||	pItem->Get_yMax() < y - r || pItem->Get_yMin() > y + r )
+	{
+		return( false );
+	}
+
+	if( (pItem->Get_xMin() <= x && x <= pItem->Get_xMax())
+	||	(pItem->Get_yMin() <= y && y <= pItem->Get_yMax()) )
+	{
+		return( true );
+	}
+
+	TSG_Point	p;
+
+	if( pItem->Get_xMax() < x )
+	{
+		p.x	= pItem->Get_xMax();
+		p.y	= pItem->Get_yMax() < y ? pItem->Get_yMax() : pItem->Get_yMin();
+	}
+	else // if( pItem->Get_xMin() >= x )
+	{
+		p.x	= pItem->Get_xMin();
+		p.y	= pItem->Get_yMax() < y ? pItem->Get_yMax() : pItem->Get_yMin();
+	}
+
+	return( _Radius_Contains(x, y, r, p) );
+}
+
+//---------------------------------------------------------
+inline bool CSG_PRQuadTree::_Radius_Intersects(double x, double y, double r, int iQuadrant, CSG_PRQuadTree_Item *pItem)
+{
+	return( _Quadrant_Intersects(x, y, iQuadrant, pItem) && _Radius_Intersects(x, y, r, pItem) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_PRQuadTree::Select_Nearest_Points(double x, double y, int maxPoints, double Radius, int iQuadrant)
+{
+	m_nSelected	= 0;
+
+	if( m_pRoot )
+	{
+		double	maxDistance;
+
+		if( maxPoints < 1 )
+		{
+			maxPoints	= m_nPoints;
+		}
+
+		if( iQuadrant != 4 )
+		{
+			if( m_Selected.Get_NY() != maxPoints )
+			{
+				m_Selected.Create(4, maxPoints);
+			}
+
+			_Get_Nearest_Points(m_pRoot, x, y, maxDistance = 0.0, Radius, iQuadrant);
+		}
+		else // if( iQuadrant == 4 )	// quadrant-wise search
+		{
+			int			n[4];
+			CSG_Matrix	m[4];
+
+			m_Selected.Create(4, (int)(maxPoints / 4.0));
+
+			for(iQuadrant=0; iQuadrant<4; iQuadrant++)
+			{
+				m_nSelected	= 0;
+
+				_Get_Nearest_Points(m_pRoot, x, y, maxDistance = 0.0, Radius, iQuadrant);
+
+				m[iQuadrant].Create(m_Selected);
+				n[iQuadrant]	= m_nSelected;
+			}
+
+			m_Selected.Create(4, maxPoints);
+
+			for(iQuadrant=0, m_nSelected=0; iQuadrant<4; iQuadrant++)
+			{
+				for(int i=0; i<n[iQuadrant]; i++, m_nSelected++)
+				{
+					m_Selected[m_nSelected][0]	= m[iQuadrant][i][0];
+					m_Selected[m_nSelected][1]	= m[iQuadrant][i][1];
+					m_Selected[m_nSelected][2]	= m[iQuadrant][i][2];
+					m_Selected[m_nSelected][3]	= m[iQuadrant][i][3];
+				}
+			}
+		}
+	}
+
+	return( m_nSelected );
+}
+
+//---------------------------------------------------------
+void CSG_PRQuadTree::_Get_Nearest_Points(CSG_PRQuadTree_Item *pItem, double x, double y, double &maxDistance, double Radius, int iQuadrant)
+{
+	int		i;
+
+	//-----------------------------------------------------
+	if( pItem->is_Leaf() )
+	{
+		CSG_PRQuadTree_Leaf	*pLeaf	= (CSG_PRQuadTree_Leaf *)pItem;
+
+		if( _Quadrant_Contains(x, y, iQuadrant, pLeaf->Get_Point()) == false )
+		{
+			return;
+		}
+		
+		double	d	= SG_Get_Distance(x, y, pLeaf->Get_X(), pLeaf->Get_Y());
+
+		if( Radius > 0.0 && Radius < d )
+		{
+			return;
+		}
+
+		//-------------------------------------------------
+		if( m_nSelected < m_Selected.Get_NY() )
+		{
+			if( maxDistance < d )
+			{
+				maxDistance	= d;
+			}
+
+			m_Selected[m_nSelected][0]	= pLeaf->Get_X();
+			m_Selected[m_nSelected][1]	= pLeaf->Get_Y();
+			m_Selected[m_nSelected][2]	= pLeaf->Get_Z();
+			m_Selected[m_nSelected][3]	= d;
+
+			m_nSelected++;
+		}
+		else if( d < maxDistance )
+		{
+			for(i=0; i<m_Selected.Get_NY(); i++)
+			{
+				if( m_Selected[i][3] >= maxDistance )
+				{
+					m_Selected[i][0]	= pLeaf->Get_X();
+					m_Selected[i][1]	= pLeaf->Get_Y();
+					m_Selected[i][2]	= pLeaf->Get_Z();
+					m_Selected[i][3]	= d;
+
+					break;
+				}
+			}
+
+			for(i=0, maxDistance=d; i<m_Selected.Get_NY(); i++)
+			{
+				if( m_Selected[i][3] > maxDistance )
+				{
+					maxDistance	= m_Selected[i][3];
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else // if( pItem->is_Node() )
+	{
+		CSG_PRQuadTree_Item	*pChild;
+
+		for(i=0; i<4; i++)
+		{
+			if( (pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i)) != NULL && pChild->Contains(x, y) == true )
+			{
+				_Get_Nearest_Points(pChild, x, y, maxDistance, Radius, iQuadrant);
+			}
+		}
+
+		for(i=0; i<4; i++)
+		{
+			if( (pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i)) != NULL && pChild->Contains(x, y) == false )
+			{
+				if( _Radius_Intersects(x, y, Radius, iQuadrant, pChild) )
+				{
+					if( m_nSelected < m_Selected.Get_NY()
+					||	(	maxDistance > (x < pChild->Get_xCenter() ? pChild->Get_xMin() - x : x - pChild->Get_xMax())
+						&&	maxDistance > (y < pChild->Get_yCenter() ? pChild->Get_yMin() - y : y - pChild->Get_yMax())	) )
+					{
+						_Get_Nearest_Points(pChild, x, y, maxDistance, Radius, iQuadrant);
+					}
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,85 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    saga_api.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "saga_api.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char *	SAGA_API_Get_Version(void)
+{
+	return( SG_T("SAGA Application Programming Interface - Version: ") SAGA_API_VERSION );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/saga_api.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,145 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     saga_api.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef SWIG
+
+//---------------------------------------------------------
+%module saga_api
+%{
+#include "api_core.h"
+#include "dataobject.h"
+#include "doc_html.h"
+#include "doc_pdf.h"
+#include "doc_svg.h"
+#include "geo_tools.h"
+#include "grid.h"
+#include "grid_pyramid.h"
+#include "mat_tools.h"
+#include "metadata.h"
+#include "module.h"
+#include "module_library.h"
+#include "parameters.h"
+#include "pointcloud.h"
+#include "saga_api.h"
+#include "shapes.h"
+#include "table.h"
+#include "table_dbase.h"
+#include "table_value.h"
+#include "tin.h"
+%}
+
+//---------------------------------------------------------
+#endif	// #ifdef SWIG
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__saga_api_H
+#define HEADER_INCLUDED__SAGA_API__saga_api_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "module_library.h"
+
+#include "doc_pdf.h"
+#include "doc_html.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT const SG_Char *	SAGA_API_Get_Version(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SAGA_API_VERSION			SG_T("2.0.4")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__saga_api_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shape.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shape.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shape.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,220 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      shape.cpp                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape::CSG_Shape(CSG_Shapes *pOwner, int Index)
+	: CSG_Table_Record(pOwner, Index)
+{
+}
+
+//---------------------------------------------------------
+CSG_Shape::~CSG_Shape(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Shape::Destroy(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_Shape_Type CSG_Shape::Get_Type(void)
+{
+	return( ((CSG_Shapes *)m_pTable)->Get_Type() );
+}
+
+//---------------------------------------------------------
+int CSG_Shape::Get_Point_Count(void)
+{
+	int		i, n;
+
+	for(i=0, n=0; i<Get_Part_Count(); i++)
+	{
+		n	+= Get_Point_Count(i);
+	}
+
+	return( n );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape::Add_Point(TSG_Point Point, int iPart)
+{
+	return( Add_Point(Point.x, Point.y, iPart) );
+}
+
+//---------------------------------------------------------
+int CSG_Shape::Ins_Point(TSG_Point Point, int iPoint, int iPart)
+{
+	return( Ins_Point(Point.x, Point.y, iPoint, iPart) );
+}
+
+//---------------------------------------------------------
+int CSG_Shape::Set_Point(TSG_Point Point, int iPoint, int iPart)
+{
+	return( Set_Point(Point.x, Point.y, iPoint, iPart) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CSG_Shape::_Invalidate(void)
+{
+	((CSG_Shapes *)m_pTable)->Set_Update_Flag();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape::Intersects(TSG_Rect _Region)
+{
+	switch( Get_Extent().Intersects(_Region) )
+	{
+	case INTERSECTION_None:
+		return( INTERSECTION_None );
+
+	case INTERSECTION_Identical:
+	case INTERSECTION_Contained:
+		return( INTERSECTION_Contained );
+
+	default:
+	case INTERSECTION_Contains:
+	case INTERSECTION_Overlaps:
+		return( On_Intersects(_Region) );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape::Assign(CSG_Shape *pShape)
+{
+	return( Assign(pShape, true) );
+}
+
+bool CSG_Shape::Assign(CSG_Shape *pShape, bool bAssign_Attributes)
+{
+	if( pShape && Get_Type() == pShape->Get_Type() && On_Assign(pShape) )
+	{
+		if( bAssign_Attributes )
+		{
+			CSG_Table_Record::Assign(pShape);
+		}
+ 
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_line.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_line.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_line.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,201 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    shape_line.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape_Line::CSG_Shape_Line(CSG_Shapes *pOwner, int Index)
+	: CSG_Shape_Points(pOwner, Index)
+{}
+
+//---------------------------------------------------------
+CSG_Shape_Line::~CSG_Shape_Line(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Line::On_Intersects(TSG_Rect Extent)
+{
+	for(int iPart=0; iPart<m_nParts; iPart++)
+	{
+		if( m_pParts[iPart]->Get_Count() > 1 )
+		{
+			TSG_Point	*pA, *pB, Crossing;
+
+			pB	= m_pParts[iPart]->m_Points;
+			pA	= pB + 1;
+
+			for(int iPoint=1; iPoint<m_pParts[iPart]->Get_Count(); iPoint++, pB=pA++)
+			{
+				if( SG_Get_Crossing_InRegion(Crossing, *pA, *pB, Extent) )
+				{
+					return( INTERSECTION_Overlaps );
+				}
+			}
+		}
+	}
+
+	return( INTERSECTION_None );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Shape_Line::Get_Length(void)
+{
+	int		iPart;
+	double	Length;
+
+	for(iPart=0, Length=0.0; iPart<m_nParts; iPart++)
+	{
+		Length	+= Get_Length(iPart);
+	}
+
+	return( Length );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Line::Get_Length(int iPart)
+{
+	int			iPoint;
+	double		Length;
+	TSG_Point	*pA, *pB;
+
+	if( iPart >= 0 && iPart < m_nParts && m_pParts[iPart]->Get_Count() > 1 )
+	{
+		pB	= m_pParts[iPart]->m_Points;
+		pA	= pB + 1;
+
+		for(iPoint=1, Length=0.0; iPoint<m_pParts[iPart]->Get_Count(); iPoint++, pB=pA++)
+		{
+			Length	+= SG_Get_Distance(*pA, *pB);
+		}
+
+		return( Length );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Shape_Line::Get_Distance(TSG_Point Point, TSG_Point &Next, int iPart)
+{
+	int			i;
+	double		d, Distance;
+	TSG_Point	*pA, *pB, pt;
+
+	Distance	= -1.0;
+
+	if( iPart >= 0 && iPart < m_nParts && m_pParts[iPart]->Get_Count() > 1 )
+	{
+		pB	= m_pParts[iPart]->m_Points;
+		pA	= pB + 1;
+
+		Distance	= SG_Get_Nearest_Point_On_Line(Point, *pA, *pB, Next);
+
+		for(i=1; i<m_pParts[iPart]->Get_Count() && Distance!=0.0; i++, pB=pA++)
+		{
+			if(	(d = SG_Get_Nearest_Point_On_Line(Point, *pA, *pB, pt)) >= 0.0
+			&&	(d < Distance || Distance < 0.0) )
+			{
+				Distance	= d;
+				Next		= pt;
+			}
+		}
+	}
+
+	return( Distance );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_part.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_part.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_part.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,319 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    shape_part.cpp                     //
+//                                                       //
+//          Copyright (C) 2008 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <memory.h>
+
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape_Part::CSG_Shape_Part(CSG_Shape_Points *pOwner)
+{
+	m_pOwner	= pOwner;
+
+	m_Points	= NULL;
+	m_nPoints	= 0;
+	m_nBuffer	= 0;
+
+	m_bUpdate	= true;
+}
+
+//---------------------------------------------------------
+CSG_Shape_Part::~CSG_Shape_Part(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_GROW_SIZE(n)	(n < 128 ? 1 : (n < 2048 ? 32 : 256))
+
+//---------------------------------------------------------
+bool CSG_Shape_Part::_Alloc_Memory(int nPoints)
+{
+	if( m_nPoints != nPoints )
+	{
+		int		nGrow	= GET_GROW_SIZE(nPoints),
+				nBuffer = (nPoints / nGrow) * nGrow;
+
+		while( nBuffer < nPoints )
+		{
+			nBuffer	+= nGrow;
+		}
+
+		if( m_nBuffer != nBuffer )
+		{
+			m_nBuffer	= nBuffer;
+
+			TSG_Point	*Points	= (TSG_Point *)SG_Realloc(m_Points, m_nBuffer * sizeof(TSG_Point));
+
+			if( Points == NULL )
+			{
+				return( false );
+			}
+
+			m_Points	= Points;
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape_Part::Destroy(void)
+{
+	if( m_Points != NULL )
+	{
+		SG_Free(m_Points);
+	}
+
+	m_Points	= NULL;
+	m_nPoints	= 0;
+	m_nBuffer	= 0;
+
+	m_bUpdate	= true;
+
+	_Invalidate();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Shape_Part::Assign(CSG_Shape_Part *pPart)
+{
+	if( _Alloc_Memory(pPart->Get_Count()) )
+	{
+		memcpy(m_Points, pPart->m_Points, pPart->m_nPoints * sizeof(TSG_Point));
+ 
+		m_Extent	= pPart->m_Extent;
+		m_bUpdate	= pPart->m_bUpdate;
+
+		if( m_pOwner )
+		{
+			m_pOwner->_Invalidate();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Part::Add_Point(double x, double y)
+{
+	return( Ins_Point(x, y, m_nPoints) );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Part::Ins_Point(double x, double y, int iPoint)
+{
+	if( iPoint >= 0 && iPoint <= m_nPoints && _Alloc_Memory(m_nPoints + 1) )
+	{
+		for(int i=m_nPoints; i>iPoint; i--)
+		{
+			m_Points[i]	= m_Points[i - 1];
+		}
+
+		m_nPoints++;
+
+		m_Points[iPoint].x	= x;
+		m_Points[iPoint].y	= y;
+
+		_Invalidate();
+
+		return( m_nPoints );
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Part::Set_Point(double x, double y, int iPoint)
+{
+	if( iPoint >= 0 && iPoint < m_nPoints )
+	{
+		m_Points[iPoint].x	= x;
+		m_Points[iPoint].y	= y;
+
+		_Invalidate();
+
+		return( 1 );
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Part::Del_Point(int del_Point)
+{
+	if( del_Point >= 0 && del_Point < m_nPoints )
+	{
+		m_nPoints--;
+
+		for(int iPoint=del_Point; iPoint<m_nPoints; iPoint++)
+		{
+			m_Points[iPoint]	= m_Points[iPoint + 1];
+		}
+
+		_Alloc_Memory(m_nPoints);
+
+		_Invalidate();
+
+		return( 1 );
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CSG_Shape_Part::_Invalidate(void)
+{
+	m_bUpdate	= true;
+
+	if( m_pOwner )
+	{
+		m_pOwner->_Invalidate();
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Shape_Part::_Update_Extent(void)
+{
+	if( m_bUpdate )
+	{
+		if( m_nPoints > 0 )
+		{
+			int			i;
+			TSG_Point	*p	= m_Points;
+			TSG_Rect	*r	= &m_Extent.m_rect;
+
+			r->xMin	= r->xMax	= p->x;
+			r->yMin	= r->yMax	= p->y;
+
+			for(i=1, p++; i<m_nPoints; i++, p++)
+			{
+				if( r->xMin > p->x )
+				{
+					r->xMin	= p->x;
+				}
+				else if( r->xMax < p->x )
+				{
+					r->xMax	= p->x;
+				}
+
+				if( r->yMin > p->y )
+				{
+					r->yMin	= p->y;
+				}
+				else if( r->yMax < p->y )
+				{
+					r->yMax	= p->y;
+				}
+			}
+		}
+
+		m_bUpdate	= false;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_point.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_point.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_point.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,155 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                    Library: Shapes                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    shape_point.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape_Point::CSG_Shape_Point(CSG_Shapes *pOwner, int Index)
+	: CSG_Shape(pOwner, Index)
+{}
+
+//---------------------------------------------------------
+CSG_Shape_Point::~CSG_Shape_Point(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape_Point::On_Assign(CSG_Shape *pShape)
+{
+	if( pShape->Get_Point_Count(0) > 0 )
+	{
+		CSG_Shape::Add_Point(pShape->Get_Point(0));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Point::Add_Point(double x, double y, int iPart)
+{
+	m_Point.x	= x;
+	m_Point.y	= y;
+
+	_Invalidate();
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const CSG_Rect & CSG_Shape_Point::Get_Extent(void)
+{
+	static CSG_Rect	Extent;
+
+	Extent.Assign(m_Point.x, m_Point.y, m_Point.x, m_Point.y);
+
+	return( Extent );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Point::On_Intersects(TSG_Rect Extent)
+{
+	if(	Extent.xMin <= m_Point.x && m_Point.x <= Extent.xMax
+	&&	Extent.yMin <= m_Point.y && m_Point.y <= Extent.yMax )
+	{
+		return( INTERSECTION_Overlaps );
+	}
+
+	return( INTERSECTION_None );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,361 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   shape_points.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape_Points::CSG_Shape_Points(CSG_Shapes *pOwner, int Index)
+	: CSG_Shape(pOwner, Index)
+{
+	m_pParts	= NULL;
+	m_nParts	= 0;
+
+	m_bUpdate	= true;
+}
+
+//---------------------------------------------------------
+CSG_Shape_Points::~CSG_Shape_Points(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Shape_Points::Destroy(void)
+{
+	CSG_Shape::Destroy();
+
+	Del_Parts();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape_Points::On_Assign(CSG_Shape *pShape)
+{
+	Del_Parts();
+
+	for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			CSG_Shape::Add_Point(pShape->Get_Point(iPoint, iPart), iPart);
+		}
+	}
+ 
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Points::_Add_Part(void)
+{
+	m_pParts			= (CSG_Shape_Part **)SG_Realloc(m_pParts , (m_nParts + 1) * sizeof(CSG_Shape_Part *));
+	m_pParts[m_nParts]	= _Get_Part();
+
+	m_nParts++;
+
+	return( m_nParts );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Points::Del_Part(int del_Part)
+{
+	if( del_Part >= 0 && del_Part < m_nParts )
+	{
+		delete(m_pParts[del_Part]);
+
+		m_nParts--;
+
+		for(int iPart=del_Part; iPart<m_nParts; iPart++)
+		{
+			m_pParts[iPart]	= m_pParts[iPart + 1];
+		}
+
+		m_pParts	= (CSG_Shape_Part **)SG_Realloc(m_pParts , m_nParts * sizeof(CSG_Shape_Part *));
+
+		_Invalidate();
+	}
+
+	return( m_nParts );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Points::Del_Parts(void)
+{
+	for(int iPart=m_nParts-1; iPart>=0; iPart--)
+	{
+		Del_Part(iPart);
+	}
+
+	return( m_nParts );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Points::Add_Point(double x, double y, int iPart)
+{
+	if( iPart >= m_nParts )
+	{
+		for(int i=m_nParts; i<=iPart; i++)
+		{
+			_Add_Part();
+		}
+	}
+
+	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Add_Point(x, y) : 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Points::Ins_Point(double x, double y, int iPoint, int iPart)
+{
+	if( iPart >= m_nParts )
+	{
+		for(int i=m_nParts; i<=iPart; i++)
+		{
+			_Add_Part();
+		}
+	}
+
+	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Ins_Point(x, y, iPoint) : 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Points::Set_Point(double x, double y, int iPoint, int iPart)
+{
+	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Set_Point(x, y, iPoint) : 0 );
+}
+
+//---------------------------------------------------------
+int CSG_Shape_Points::Del_Point(int del_Point, int iPart)
+{
+	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Del_Point(del_Point) : 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Shape_Points::_Update_Extent(void)
+{
+	if( m_bUpdate )
+	{
+		bool	bOkay	= false;
+
+		for(int iPart=0; iPart<m_nParts; iPart++)
+		{
+			if( m_pParts[iPart]->Get_Count() > 0 )
+			{
+				if( !bOkay )
+				{
+					bOkay		= true;
+					m_Extent	= m_pParts[iPart]->Get_Extent();
+				}
+				else
+				{
+					m_Extent.Union(m_pParts[iPart]->Get_Extent());
+				}
+			}
+		}
+
+		m_bUpdate	= false;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Shape_Points::Get_Distance(TSG_Point Point)
+{
+	TSG_Point	Next;
+
+	return( Get_Distance(Point, Next) );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Points::Get_Distance(TSG_Point Point, TSG_Point &Next)
+{
+	int			iPart;
+	double		d, Distance;
+	TSG_Point	pt;
+
+	Distance	= Get_Distance(Point, Next, 0);
+
+	for(iPart=1; iPart<m_nParts && Distance!=0.0; iPart++)
+	{
+		if(	(d = Get_Distance(Point, pt, iPart)) >= 0.0
+		&&	(d < Distance || Distance < 0.0) )
+		{
+			Distance	= d;
+			Next		= pt;
+		}
+	}
+
+	return( Distance );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Points::Get_Distance(TSG_Point Point, int iPart)
+{
+	TSG_Point	Next;
+
+	return( Get_Distance(Point, Next, iPart) );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Points::Get_Distance(TSG_Point Point, TSG_Point &Next, int iPart)
+{
+	int			i;
+	double		d, Distance;
+	TSG_Point	*pA;
+
+	Distance	= -1.0;
+
+	if( iPart >= 0 && iPart < m_nParts )
+	{
+		for(i=0, pA=m_pParts[iPart]->m_Points; i<m_pParts[iPart]->Get_Count() && Distance!=0.0; i++, pA++)
+		{
+			if(	(d = SG_Get_Distance(Point, *pA)) < Distance || Distance < 0.0 )
+			{
+				Distance	= d;
+				Next		= *pA;
+			}
+		}
+	}
+
+	return( Distance );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Points::On_Intersects(TSG_Rect Extent)
+{
+	for(int iPart=0; iPart<m_nParts; iPart++)
+	{
+		TSG_Point	*p	= m_pParts[iPart]->m_Points;
+
+		for(int iPoint=0; iPoint<m_pParts[iPart]->Get_Count(); iPoint++, p++)
+		{
+			if(	Extent.xMin <= p->x && p->x <= Extent.xMax
+			&&	Extent.yMin <= p->y && p->y <= Extent.yMax	)
+			{
+				return( INTERSECTION_Overlaps );
+			}
+		}
+	}
+
+	return( INTERSECTION_None );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_polygon.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_polygon.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shape_polygon.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,571 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   shape_polygon.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define BOOL3_NOTSET	-1
+#define BOOL3_FALSE		 0
+#define BOOL3_TRUE		 1
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape_Polygon_Part::CSG_Shape_Polygon_Part(CSG_Shape_Points *pOwner)
+	: CSG_Shape_Part(pOwner)
+{
+	m_bLake			= BOOL3_NOTSET;
+	m_bClockwise	= BOOL3_NOTSET;
+}
+
+//---------------------------------------------------------
+CSG_Shape_Polygon_Part::~CSG_Shape_Polygon_Part(void)
+{}
+
+//---------------------------------------------------------
+void CSG_Shape_Polygon_Part::_Invalidate(void)
+{
+	CSG_Shape_Part::_Invalidate();
+
+	m_bLake			= BOOL3_NOTSET;
+	m_bClockwise	= BOOL3_NOTSET;
+}
+
+//---------------------------------------------------------
+void CSG_Shape_Polygon_Part::_Update_Area(void)
+{
+	if( m_nPoints > 2 && m_bClockwise == BOOL3_NOTSET )
+	{
+		TSG_Point	*pA, *pB;
+
+		m_Area			= 0.0;
+		m_Perimeter		= 0.0;
+
+		m_Centroid.x	= 0.0;
+		m_Centroid.y	= 0.0;
+
+		pB				= m_Points + m_nPoints - 1;
+		pA				= m_Points;
+
+		for(int iPoint=0; iPoint<m_nPoints; iPoint++, pB=pA++)
+		{
+			double	d		 = pA->x * pB->y - pB->x * pA->y;
+
+			m_Centroid.x	+= d * (pA->x + pB->x);
+			m_Centroid.y	+= d * (pA->y + pB->y);
+
+			m_Area			+= d;
+
+			m_Perimeter		+= SG_Get_Distance(*pA, *pB);
+		}
+
+		if( m_Area != 0.0 )
+		{
+			m_Centroid.x	/= (3.0 * m_Area);
+			m_Centroid.y	/= (3.0 * m_Area);
+		}
+
+		m_bClockwise	= m_Area > 0.0 ? BOOL3_TRUE : BOOL3_FALSE;
+
+		m_Area			= fabs(m_Area) / 2.0;
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon_Part::is_Containing(const TSG_Point &Point)
+{
+	return( is_Containing(Point.x, Point.y) );
+}
+
+bool CSG_Shape_Polygon_Part::is_Containing(double x, double y)
+{
+	if(	m_nPoints > 2 && Get_Extent().Contains(x, y) )
+	{
+		int			nCrossings;
+		TSG_Point	A, B, C, *pA, *pB;
+
+		nCrossings	= 0;
+
+		A.x			= Get_Extent().Get_XMin();
+		B.x			= x;
+		A.y = B.y	= y;
+
+		pB	= m_Points + m_nPoints - 1;
+		pA	= m_Points;
+
+		for(int iPoint=0, goNext=0; iPoint<m_nPoints; iPoint++, pB=pA++)
+		{
+			if( pA->y != pB->y )
+			{
+				if( pA->y == y )
+				{
+					goNext	= pA->y > pB->y ? 1 : -1;
+				}
+				else if( goNext )	// pB->y == y
+				{
+					if( ((goNext > 0 && pA->y > pB->y) || (goNext < 0 && pA->y < pB->y)) && pB->x <= B.x )
+						nCrossings++;
+
+					goNext	= 0;
+				}
+				else if( ((pB->y < y && y <= pA->y) || (pB->y > y && y >= pA->y)) && (pB->x < x || pA->x < x) )
+				{
+					if( SG_Get_Crossing(C, *pA, *pB, A, B) )
+					{
+						nCrossings++;
+					}
+				}
+			}
+		}
+
+		return( nCrossings % 2 != 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Polygon_Part::Get_Distance(TSG_Point Point, TSG_Point &Next)
+{
+	if( m_nPoints > 2 && !is_Containing(Point) )
+	{
+		double		Distance;
+		TSG_Point	*pA, *pB, C;
+
+		pB			= m_Points + m_nPoints - 1;
+		pA			= m_Points;
+
+		Distance	= SG_Get_Nearest_Point_On_Line(Point, *pA, *pB, Next);
+
+		for(int iPoint=0; iPoint<m_nPoints && Distance>0.0; iPoint++, pB=pA++)
+		{
+			double	d	= SG_Get_Nearest_Point_On_Line(Point, *pA, *pB, C);
+
+			if(	d >= 0.0 && d < Distance )
+			{
+				Distance	= d;
+				Next		= C;
+			}
+		}
+
+		return( Distance );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape_Polygon::CSG_Shape_Polygon(CSG_Shapes *pOwner, int Index)
+	: CSG_Shape_Points(pOwner, Index)
+{}
+
+//---------------------------------------------------------
+CSG_Shape_Polygon::~CSG_Shape_Polygon(void)
+{}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Shape_Polygon::_Invalidate(void)
+{
+	CSG_Shape_Points::_Invalidate();
+
+	if( m_bUpdate_Lakes )
+	{
+		m_bUpdate_Lakes	= false;
+
+		for(int i=0; i<m_nParts; i++)
+		{
+			Get_Polygon_Part(i)->m_bLake	= BOOL3_NOTSET;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shape_Polygon::On_Intersects(TSG_Rect Region)
+{
+	TSG_Point	*pa, *pb, r00, r10, r01, r11, c;
+
+	//-----------------------------------------------------
+	// 1. Line Intersection...
+
+	r00.x	= r01.x	= Region.xMin;
+	r11.x	= r10.x	= Region.xMax;
+	r00.y	= r10.y	= Region.yMin;
+	r11.y	= r01.y	= Region.yMax;
+
+	for(int iPart=0; iPart<m_nParts; iPart++)
+	{
+		CSG_Shape_Part	*pPart	= m_pParts[iPart];
+
+		if( pPart->Get_Extent().Intersects(Region) )
+		{
+			pb	= m_pParts[iPart]->m_Points + m_pParts[iPart]->m_nPoints - 1;
+
+			for(int iPoint=0; iPoint<m_pParts[iPart]->m_nPoints; iPoint++)
+			{
+				pa	= pb;
+				pb	= m_pParts[iPart]->m_Points + iPoint;
+
+				if(	SG_Get_Crossing(c, *pa, *pb, r00, r10, true)
+				||	SG_Get_Crossing(c, *pa, *pb, r00, r01, true)
+				||	SG_Get_Crossing(c, *pa, *pb, r11, r10, true)
+				||	SG_Get_Crossing(c, *pa, *pb, r11, r01, true)	)
+				{
+					return( INTERSECTION_Overlaps );
+				}
+			}
+		}
+	}
+
+
+	//-----------------------------------------------------
+	// 2. Is region completly within polygon...
+
+	if(	is_Containing(r00)
+	||	is_Containing(r01)
+	||	is_Containing(r11)
+	||	is_Containing(r10)	)
+	{
+		return( INTERSECTION_Contains );
+	}
+
+	return( INTERSECTION_None );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon::is_Lake(int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	if( pPart && pPart->m_nPoints > 2 && m_nParts > 1 )
+	{
+		if( pPart->m_bLake == BOOL3_NOTSET )
+		{
+			int		nOuter	= 0;
+
+			for(iPart=0; iPart<m_nParts; iPart++)
+			{
+				if( pPart != m_pParts[iPart] && m_pParts[iPart]->m_nPoints > 2 )
+				{
+					if( is_Containing(pPart->Get_Point(0), iPart) )
+					{
+						nOuter++;
+					}
+				}
+			}
+
+			pPart->m_bLake	= nOuter % 2 ? 1 : 0;
+
+			m_bUpdate_Lakes	= true;
+		}
+
+		return( pPart->m_bLake == BOOL3_TRUE );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon::is_Clockwise(int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	return(	pPart && pPart->is_Clockwise() );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Polygon::Get_Perimeter(int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	return( pPart ? pPart->Get_Perimeter() : 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Polygon::Get_Perimeter(void)
+{
+	double	Perimeter	= 0.0;
+
+	for(int iPart=0; iPart<m_nParts; iPart++)
+	{
+		Perimeter	+= Get_Perimeter(iPart);
+	}
+
+	return( Perimeter );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Polygon::Get_Area(int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	return( pPart ? pPart->Get_Area() : 0.0 );
+}
+
+//---------------------------------------------------------
+double CSG_Shape_Polygon::Get_Area(void)
+{
+	double	Area	= 0.0;
+
+	for(int iPart=0; iPart<m_nParts; iPart++)
+	{
+		Area	+= is_Lake(iPart) ? -Get_Area(iPart) : Get_Area(iPart);
+	}
+
+	return( Area );
+}
+
+//---------------------------------------------------------
+TSG_Point CSG_Shape_Polygon::Get_Centroid(int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	if(	pPart )
+	{
+		return( pPart->Get_Centroid() );
+	}
+
+	return( CSG_Point(0.0, 0.0) );
+}
+
+//---------------------------------------------------------
+TSG_Point CSG_Shape_Polygon::Get_Centroid(void)
+{
+	int			iPart, nParts;
+	TSG_Point	Centroid;
+
+	Centroid.x	= 0.0;
+	Centroid.y	= 0.0;
+
+	for(iPart=0, nParts=0; iPart<m_nParts; iPart++)
+	{
+		if( !is_Lake(iPart) )
+		{
+			TSG_Point	p	= Get_Centroid(iPart);
+
+			Centroid.x	+= p.x;
+			Centroid.y	+= p.y;
+
+			nParts++;
+		}
+	}
+
+	if( nParts > 1 )
+	{
+		Centroid.x	/= nParts;
+		Centroid.y	/= nParts;
+	}
+
+	return( Centroid );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon::is_Containing(const TSG_Point &Point, int iPart)
+{
+	return( is_Containing(Point.x, Point.y, iPart) );
+}
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon::is_Containing(const TSG_Point &Point)
+{
+	return( is_Containing(Point.x, Point.y) );
+}
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon::is_Containing(double x, double y, int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	return(	pPart && pPart->is_Containing(x, y) );
+}
+
+//---------------------------------------------------------
+bool CSG_Shape_Polygon::is_Containing(double x, double y)
+{
+	if( Get_Extent().Contains(x, y) )
+	{
+		int			nCrossings;
+		TSG_Point	A, B, C, *pA, *pB;
+
+		nCrossings	= 0;
+
+		A.x			= Get_Extent().Get_XMin();
+		B.x			= x;
+		A.y = B.y	= y;
+
+		for(int iPart=0; iPart<m_nParts; iPart++)
+		{
+			CSG_Shape_Part	*pPart	= m_pParts[iPart];
+
+			if( pPart->m_nPoints > 2 && pPart->Get_Extent().Contains(x, y) )
+			{
+				pB	= pPart->m_Points + pPart->m_nPoints - 1;
+				pA	= pPart->m_Points;
+
+				for(int iPoint=0, goNext=0; iPoint<pPart->m_nPoints; iPoint++, pB=pA++)
+				{
+					if( pA->y != pB->y )
+					{
+						if( pA->y == y )
+						{
+							goNext	= pA->y > pB->y ? 1 : -1;
+						}
+						else if( goNext )	// pB->y == y
+						{
+							if( ((goNext > 0 && pA->y > pB->y) || (goNext < 0 && pA->y < pB->y)) && pB->x <= B.x )
+								nCrossings++;
+
+							goNext	= 0;
+						}
+						else if( ((pB->y < y && y <= pA->y) || (pB->y > y && y >= pA->y)) && (pB->x < x || pA->x < x) )
+						{
+							if( SG_Get_Crossing(C, *pA, *pB, A, B) )
+							{
+								nCrossings++;
+							}
+						}
+					}
+				}
+			}
+		}
+
+		return( nCrossings % 2 != 0 );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double CSG_Shape_Polygon::Get_Distance(TSG_Point Point, TSG_Point &Next, int iPart)
+{
+	CSG_Shape_Polygon_Part	*pPart	= Get_Polygon_Part(iPart);
+
+	return(	pPart && pPart->Get_Distance(Point, Next) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,453 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     shapes.cpp                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char *	SG_Get_ShapeType_Name(TSG_Shape_Type Type)
+{
+	switch( Type )
+	{
+	case SHAPE_TYPE_Point:		return( LNG("[DAT] Point") );
+	case SHAPE_TYPE_Points:		return( LNG("[DAT] Points") );
+	case SHAPE_TYPE_Line:		return( LNG("[DAT] Line") );
+	case SHAPE_TYPE_Polygon:	return( LNG("[DAT] Polygon") );
+
+	default:
+	case SHAPE_TYPE_Undefined:	return( LNG("[DAT] Undefined") );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes *		SG_Create_Shapes(void)
+{
+	return( new CSG_Shapes );
+}
+
+//---------------------------------------------------------
+CSG_Shapes *		SG_Create_Shapes(const CSG_Shapes &Shapes)
+{
+	return( new CSG_Shapes(Shapes) );
+}
+
+//---------------------------------------------------------
+CSG_Shapes *		SG_Create_Shapes(const CSG_String &File_Name)
+{
+	return( new CSG_Shapes(File_Name) );
+}
+
+//---------------------------------------------------------
+CSG_Shapes *		SG_Create_Shapes(TSG_Shape_Type Type, const SG_Char *Name, CSG_Table *pStructure)
+{
+	return( new CSG_Shapes(Type, Name, pStructure) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes::CSG_Shapes(void)
+	: CSG_Table()
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Shapes::CSG_Shapes(const CSG_Shapes &Shapes)
+	: CSG_Table()
+{
+	_On_Construction();
+
+	Create(Shapes);
+}
+
+//---------------------------------------------------------
+CSG_Shapes::CSG_Shapes(const CSG_String &File_Name)
+	: CSG_Table()
+{
+	_On_Construction();
+
+	Create(File_Name);
+}
+
+//---------------------------------------------------------
+CSG_Shapes::CSG_Shapes(TSG_Shape_Type Type, const SG_Char *Name, CSG_Table *pStructure)
+	: CSG_Table()
+{
+	_On_Construction();
+
+	Create(Type, Name, pStructure);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Shapes::_On_Construction(void)
+{
+	CSG_Table::_On_Construction();
+
+	m_Type	= SHAPE_TYPE_Undefined;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes::Create(const CSG_Shapes &Shapes)
+{
+	return( Assign((CSG_Data_Object *)&Shapes) );
+}
+
+//---------------------------------------------------------
+bool CSG_Shapes::Create(const CSG_String &File_Name)
+{
+	Destroy();
+
+	if( _Load_ESRI(File_Name) )
+	{
+		for(int iShape=Get_Count()-1; iShape >= 0; iShape--)
+		{
+			if( !Get_Shape(iShape)->is_Valid() )
+			{
+				Del_Shape(iShape);
+			}
+		}
+
+		Set_File_Name(File_Name);
+
+		Load_MetaData(File_Name);
+
+		return( true );
+	}
+
+	Destroy();	// loading failure...
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Shapes::Create(TSG_Shape_Type Type, const SG_Char *Name, CSG_Table *pStructure)
+{
+	Destroy();
+
+	_Create(pStructure);
+
+	Set_Name(Name);
+
+	m_Type	= Type;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes::~CSG_Shapes(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool CSG_Shapes::Destroy(void)
+{
+	return( CSG_Table::Destroy() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes::Assign(CSG_Data_Object *pObject)
+{
+	int			iShape;
+	CSG_Shape	*pShape;
+	CSG_Shapes	*pShapes;
+
+	//-----------------------------------------------------
+	if(	pObject && pObject->is_Valid() && pObject->Get_ObjectType() == Get_ObjectType() )
+	{
+		pShapes	= (CSG_Shapes *)pObject;
+
+		Create(pShapes->Get_Type(), pShapes->Get_Name(), pShapes);
+
+		for(iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			pShape	= Add_Shape();
+			pShape->Assign(pShapes->Get_Shape(iShape));
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		Update();
+
+		Get_History()	= pObject->Get_History();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes::Save(const CSG_String &File_Name, int Format)
+{
+	bool		bResult		= false;
+	CSG_String	sFile_Name	= SG_File_Make_Path(NULL, File_Name, SG_T("shp"));
+
+	switch( Format )
+	{
+	case 0: default:
+		bResult	= _Save_ESRI(sFile_Name);
+		break;
+	}
+
+	if( bResult )
+	{
+		Set_Modified(false);
+
+		Set_File_Name(sFile_Name);
+
+		Save_MetaData(File_Name);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table_Record * CSG_Shapes::_Get_New_Record(int Index)
+{
+	switch( m_Type )
+	{
+	case SHAPE_TYPE_Point:		return( new CSG_Shape_Point		(this, Index) );
+	case SHAPE_TYPE_Points:		return( new CSG_Shape_Points	(this, Index) );
+	case SHAPE_TYPE_Line:		return( new CSG_Shape_Line		(this, Index) );
+	case SHAPE_TYPE_Polygon:	return( new CSG_Shape_Polygon	(this, Index) );
+	default:					return( NULL );
+	}
+}
+
+//---------------------------------------------------------
+CSG_Shape * CSG_Shapes::Add_Shape(CSG_Table_Record *pCopy, TSG_ADD_Shape_Copy_Mode mCopy)
+{
+	CSG_Shape	*pShape	= (CSG_Shape *)Add_Record();
+
+	if( pShape && pCopy )
+	{
+		if( mCopy == SHAPE_COPY || mCopy == SHAPE_COPY_ATTR )
+		{
+			((CSG_Table_Record *)pShape)->Assign(pCopy);
+		}
+
+		if( mCopy == SHAPE_COPY || mCopy == SHAPE_COPY_GEOM && pCopy->Get_Table()->Get_ObjectType() == DATAOBJECT_TYPE_Shapes )
+		{
+			pShape->Assign((CSG_Shape *)pCopy, false);
+		}
+	}
+
+	return( pShape );
+}
+
+//---------------------------------------------------------
+bool CSG_Shapes::Del_Shape(CSG_Shape *pShape)
+{
+	return( Del_Record(pShape->Get_Index()) );
+}
+
+bool CSG_Shapes::Del_Shape(int iShape)
+{
+	return( Del_Record(iShape) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes::On_Update(void)
+{
+	if( Get_Count() > 0 )
+	{
+		m_Extent	= Get_Shape(0)->Get_Extent();
+
+		for(int i=1; i<Get_Count(); i++)
+		{
+			m_Extent.Union(Get_Shape(i)->Get_Extent());
+		}
+	}
+	else
+	{
+		m_Extent.Assign(0.0, 0.0, 0.0, 0.0);
+	}
+
+	return( CSG_Table::On_Update() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape * CSG_Shapes::Get_Shape(TSG_Point Point, double Epsilon)
+{
+	int			iShape;
+	double		d, dNearest;
+	CSG_Rect	r(Point.x - Epsilon, Point.y - Epsilon, Point.x + Epsilon, Point.y + Epsilon);
+	CSG_Shape	*pShape, *pNearest;
+
+	pNearest	= NULL;
+
+	if( r.Intersects(Get_Extent()) != INTERSECTION_None )
+	{
+		for(iShape=0, dNearest=-1.0; iShape<Get_Count(); iShape++)
+		{
+			pShape	= Get_Shape(iShape);
+
+			if( pShape->Intersects(r) )
+			{
+				for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					if( r.Intersects(pShape->Get_Extent(iPart)) )
+					{
+						d	= pShape->Get_Distance(Point, iPart);
+
+						if( d == 0.0 )
+						{
+							return( pShape );
+						}
+						else if( d > 0.0 && d <= Epsilon && (pNearest == NULL || d < dNearest) )
+						{
+							dNearest	= d;
+							pNearest	= pShape;
+						}
+					}
+				}
+			}
+		}
+	}
+
+	return( pNearest );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,844 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       shapes.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__shapes_H
+#define HEADER_INCLUDED__SAGA_API__shapes_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Shape_Type
+{
+	SHAPE_TYPE_Undefined		= 0,
+	SHAPE_TYPE_Point,
+	SHAPE_TYPE_Points,
+	SHAPE_TYPE_Line,
+	SHAPE_TYPE_Polygon
+}
+TSG_Shape_Type;
+
+//---------------------------------------------------------
+SAGA_API_DLL_EXPORT const SG_Char *	SG_Get_ShapeType_Name	(TSG_Shape_Type Type);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape : public CSG_Table_Record
+{
+	friend class CSG_Shapes;
+
+public:
+
+	//-----------------------------------------------------
+	virtual void				Destroy				(void);
+
+	virtual bool				Assign				(CSG_Shape *pShape);
+	virtual bool				Assign				(CSG_Shape *pShape, bool bAssign_Attributes);
+
+	TSG_Shape_Type				Get_Type			(void);
+
+	virtual bool				is_Valid			(void)											= 0;
+
+	//-----------------------------------------------------
+	virtual int					Add_Point			(double x, double y,             int iPart = 0)	= 0;
+	virtual int					Ins_Point			(double x, double y, int iPoint, int iPart = 0)	= 0;
+	virtual int					Set_Point			(double x, double y, int iPoint, int iPart = 0)	= 0;
+	virtual int					Del_Point			(                    int iPoint, int iPart = 0)	= 0;
+
+	virtual int					Add_Point			(TSG_Point Point,                int iPart = 0);
+	virtual int					Ins_Point			(TSG_Point Point,    int iPoint, int iPart = 0);
+	virtual int					Set_Point			(TSG_Point Point,    int iPoint, int iPart = 0);
+
+	virtual int					Del_Part			(int iPart)										= 0;
+	virtual int					Del_Parts			(void)											= 0;
+
+	virtual int					Get_Part_Count		(void)											= 0;
+	virtual int					Get_Point_Count		(void);
+	virtual int					Get_Point_Count		(int iPart)										= 0;
+	virtual TSG_Point			Get_Point			(int iPoint, int iPart = 0)						= 0;
+
+
+	//-----------------------------------------------------
+	virtual const CSG_Rect &	Get_Extent			(void)											= 0;
+	virtual const CSG_Rect &	Get_Extent			(int iPart)	{	return( Get_Extent() );		}
+
+	int							Intersects			(TSG_Rect Extent);
+
+	virtual double				Get_Distance		(TSG_Point Point)								= 0;
+	virtual double				Get_Distance		(TSG_Point Point, int iPart)					= 0;
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next)				= 0;
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart)	= 0;
+
+
+protected:
+
+	CSG_Shape(class CSG_Shapes *pOwner, int Index);
+	virtual ~CSG_Shape(void);
+
+	virtual bool				On_Assign			(CSG_Shape *pShape)								= 0;
+	virtual int					On_Intersects		(TSG_Rect Extent)								= 0;
+
+	virtual void				_Invalidate			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Point							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape_Point : public CSG_Shape
+{
+	friend class CSG_Shapes;
+
+public:
+
+	virtual bool				is_Valid			(void)												{	return( true );				}
+
+	virtual int					Add_Point			(double x, double y,             int iPart = 0);
+	virtual int					Ins_Point			(double x, double y, int iPoint, int iPart = 0)		{	return( Add_Point(x, y) );	}
+	virtual int					Set_Point			(double x, double y, int iPoint, int iPart = 0)		{	return( Add_Point(x, y) );	}
+	virtual int					Del_Point			(                    int iPoint, int iPart = 0)		{	return( -1 );				}
+
+	virtual int					Del_Part			(int iPart)											{	return( -1 );				}
+	virtual int					Del_Parts			(void)												{	return( -1 );				}
+
+	virtual int					Get_Part_Count		(void)												{	return( 1 );				}
+	virtual int					Get_Point_Count		(int iPart)											{	return( 1 );				}
+	virtual TSG_Point			Get_Point			(int iPoint, int iPart = 0)							{	return( m_Point );			}
+
+	virtual const CSG_Rect &	Get_Extent			(void);
+
+	virtual double				Get_Distance		(TSG_Point Point)									{	return( SG_Get_Distance(Point, m_Point) );	}
+	virtual double				Get_Distance		(TSG_Point Point, int iPart)						{	return( SG_Get_Distance(Point, m_Point) );	}
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next)					{	Next = m_Point; return( SG_Get_Distance(Point, m_Point) );	}
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart)		{	Next = m_Point; return( SG_Get_Distance(Point, m_Point) );	}
+
+
+protected:
+
+	CSG_Shape_Point(class CSG_Shapes *pOwner, int Index);
+	virtual ~CSG_Shape_Point(void);
+
+
+	TSG_Point					m_Point;
+
+
+	virtual bool				On_Assign			(CSG_Shape *pShape);
+	virtual int					On_Intersects		(TSG_Rect Region);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Points							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape_Part
+{
+	friend class CSG_Shape_Points;
+	friend class CSG_Shape_Line;
+	friend class CSG_Shape_Polygon;
+
+public:
+
+	bool						Destroy				(void);
+
+	bool						Assign				(CSG_Shape_Part *pPart);
+
+	const CSG_Rect &			Get_Extent			(void)	{	_Update_Extent();	return( m_Extent );	}
+
+	int							Get_Count			(void)	{	return( m_nPoints );	}
+
+	TSG_Point					Get_Point			(int iPoint)
+	{
+		if( iPoint >= 0 && iPoint < m_nPoints )
+		{
+			return( m_Points[iPoint] );
+		}
+
+		return( CSG_Point(0.0, 0.0) );
+	}
+
+	int							Add_Point			(TSG_Point Point               )	{	return( Add_Point(Point.x, Point.y)         );	}
+	int							Ins_Point			(TSG_Point Point,    int iPoint)	{	return( Ins_Point(Point.x, Point.y, iPoint) );	}
+	int							Set_Point			(TSG_Point Point,    int iPoint)	{	return( Set_Point(Point.x, Point.y, iPoint) );	}
+
+	int							Add_Point			(double x, double y            );
+	int							Ins_Point			(double x, double y, int iPoint);
+	int							Set_Point			(double x, double y, int iPoint);
+	int							Del_Point			(                    int iPoint);
+
+
+protected:
+
+	CSG_Shape_Part(class CSG_Shape_Points *pOwner);
+	virtual ~CSG_Shape_Part(void);
+
+
+	bool						m_bUpdate;
+
+	int							m_nPoints, m_nBuffer;
+
+	TSG_Point					*m_Points;
+
+	CSG_Rect					m_Extent;
+
+	CSG_Shape_Points			*m_pOwner;
+
+
+	bool						_Alloc_Memory		(int nPoints);
+
+	virtual void				_Invalidate			(void);
+
+	virtual void				_Update_Extent		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Points							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape_Points : public CSG_Shape
+{
+	friend class CSG_Shapes;
+	friend class CSG_Shape_Part;
+
+public:
+
+	virtual void				Destroy				(void);
+
+	virtual bool				is_Valid			(void)		{	return( m_nParts > 0 && m_pParts[0]->Get_Count() > 0 );	}
+
+	virtual int					Add_Point			(double x, double y,             int iPart = 0);
+	virtual int					Ins_Point			(double x, double y, int iPoint, int iPart = 0);
+	virtual int					Set_Point			(double x, double y, int iPoint, int iPart = 0);
+	virtual int					Del_Point			(                    int iPoint, int iPart = 0);
+
+	virtual int					Del_Part			(int iPart);
+	virtual int					Del_Parts			(void);
+
+	virtual int					Get_Part_Count		(void)		{	return( m_nParts );		}
+	virtual CSG_Shape_Part *	Get_Part			(int iPart)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart] : NULL );	}
+	virtual int					Get_Point_Count		(int iPart)	{	return( iPart >= 0 && iPart < m_nParts ? m_pParts[iPart]->Get_Count() : 0 );	}
+
+	virtual TSG_Point			Get_Point			(int iPoint, int iPart = 0)
+	{
+		if( iPart >= 0 && iPart < m_nParts && iPoint >= 0 && iPoint < m_pParts[iPart]->Get_Count() )
+		{
+			return( m_pParts[iPart]->Get_Point(iPoint) );
+		}
+
+		return( CSG_Point(0.0, 0.0) );
+	}
+
+	virtual const CSG_Rect &	Get_Extent			(void)		{	_Update_Extent();	return( m_Extent );	}
+
+	virtual double				Get_Distance		(TSG_Point Point);
+	virtual double				Get_Distance		(TSG_Point Point, int iPart);
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next);
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart);
+
+
+protected:
+
+	CSG_Shape_Points(class CSG_Shapes *pOwner, int Index);
+	virtual ~CSG_Shape_Points(void);
+
+
+	bool						m_bUpdate;
+
+	int							m_nParts;
+
+	CSG_Rect					m_Extent;
+
+	CSG_Shape_Part				**m_pParts;
+
+
+	int							_Add_Part			(void);
+
+	virtual CSG_Shape_Part *	_Get_Part			(void)	{	return( new CSG_Shape_Part(this) );	}
+
+	virtual void				_Invalidate			(void)
+	{
+		if( !m_bUpdate )
+		{
+			m_bUpdate	= true;
+
+			CSG_Shape::_Invalidate();
+		}
+	}
+
+	void						_Update_Extent		(void);
+
+	virtual bool				On_Assign			(CSG_Shape *pShape);
+
+	virtual int					On_Intersects		(TSG_Rect Region);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Line							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape_Line : public CSG_Shape_Points
+{
+	friend class CSG_Shapes;
+
+public:
+
+	virtual bool				is_Valid			(void)	{	return( m_nParts > 0 && m_pParts[0]->Get_Count() > 1 );	}
+
+	double						Get_Length			(void);
+	double						Get_Length			(int iPart);
+
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart);
+
+
+protected:
+
+	CSG_Shape_Line(class CSG_Shapes *pOwner, int Index);
+	virtual ~CSG_Shape_Line(void);
+
+	virtual int					On_Intersects		(TSG_Rect Region);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Polygon							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape_Polygon_Part : public CSG_Shape_Part
+{
+	friend class CSG_Shape_Polygon;
+
+public:
+
+	bool						is_Clockwise		(void)	{	_Update_Area();	return( m_bClockwise == 1 );	}
+
+	double						Get_Perimeter		(void)	{	_Update_Area();	return( m_Perimeter );	}
+
+	double						Get_Area			(void)	{	_Update_Area();	return( m_Area );	}
+
+	const TSG_Point &			Get_Centroid		(void)	{	_Update_Area();	return( m_Centroid );	}
+
+	bool						is_Containing		(const TSG_Point &Point);
+	bool						is_Containing		(double x, double y);
+
+	double						Get_Distance		(TSG_Point Point, TSG_Point &Next);
+
+
+protected:
+
+	CSG_Shape_Polygon_Part(class CSG_Shape_Points *pOwner);
+	virtual ~CSG_Shape_Polygon_Part(void);
+
+
+	int							m_bClockwise, m_bLake;
+
+	double						m_Area, m_Perimeter;
+
+	TSG_Point					m_Centroid;
+
+
+	virtual void				_Invalidate			(void);
+
+	void						_Update_Area		(void);
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shape_Polygon : public CSG_Shape_Points
+{
+	friend class CSG_Shapes;
+
+public:
+
+	virtual bool				is_Valid			(void)		{	return( m_nParts > 0 && m_pParts[0]->Get_Count() > 2 );	}
+
+
+	CSG_Shape_Polygon_Part *	Get_Polygon_Part	(int iPart)	{	return( (CSG_Shape_Polygon_Part *)Get_Part(iPart) );	}
+
+	bool						is_Lake				(int iPart);
+
+	bool						is_Clockwise		(int iPart);
+
+	double						Get_Perimeter		(int iPart);
+	double						Get_Perimeter		(void);
+
+	double						Get_Area			(int iPart);
+	double						Get_Area			(void);
+
+	TSG_Point					Get_Centroid		(int iPart);
+	TSG_Point					Get_Centroid		(void);
+
+	bool						is_Containing		(const TSG_Point &Point, int iPart);
+	bool						is_Containing		(const TSG_Point &Point);
+	bool						is_Containing		(double x, double y, int iPart);
+	bool						is_Containing		(double x, double y);
+
+	virtual double				Get_Distance		(TSG_Point Point, TSG_Point &Next, int iPart);
+
+
+protected:
+
+	CSG_Shape_Polygon(class CSG_Shapes *pOwner, int Index);
+	virtual ~CSG_Shape_Polygon(void);
+
+
+	int							m_bUpdate_Lakes;
+
+
+	virtual CSG_Shape_Part *	_Get_Part			(void)	{	return( new CSG_Shape_Polygon_Part(this) );	}
+
+	virtual void				_Invalidate			(void);
+
+	virtual int					On_Intersects		(TSG_Rect Region);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Shapes							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Shape_Copy_Mode
+{
+	SHAPE_NO_COPY	= 0,
+	SHAPE_COPY_GEOM,
+	SHAPE_COPY_ATTR,
+	SHAPE_COPY
+}
+TSG_ADD_Shape_Copy_Mode;
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shapes : public CSG_Table
+{
+	friend class CSG_Shape;
+
+public:
+
+	CSG_Shapes(void);
+
+									CSG_Shapes	(const CSG_Shapes &Shapes);
+	bool							Create		(const CSG_Shapes &Shapes);
+
+									CSG_Shapes	(const CSG_String &File_Name);
+	bool							Create		(const CSG_String &File_Name);
+
+									CSG_Shapes	(TSG_Shape_Type Type, const SG_Char *Name = NULL, CSG_Table *pStructure = NULL);
+	bool							Create		(TSG_Shape_Type Type, const SG_Char *Name = NULL, CSG_Table *pStructure = NULL);
+
+	virtual ~CSG_Shapes(void);
+
+	virtual bool					Destroy					(void);
+
+	virtual TSG_Data_Object_Type	Get_ObjectType			(void)	const			{	return( DATAOBJECT_TYPE_Shapes );	}
+
+	virtual bool					Assign					(CSG_Data_Object *pObject);
+
+	virtual bool					Save					(const CSG_String &File_Name, int Format = 0);
+
+	virtual bool					is_Valid				(void)	const			{	return( m_Type != SHAPE_TYPE_Undefined && Get_Count() >= 0 );		}
+
+	TSG_Shape_Type					Get_Type				(void)	const			{	return( m_Type );		}
+
+	const CSG_Rect &				Get_Extent				(void)					{	Update();	return( m_Extent );	}
+
+	//-----------------------------------------------------
+	CSG_Shape *						Add_Shape				(CSG_Table_Record *pCopy = NULL, TSG_ADD_Shape_Copy_Mode mCopy = SHAPE_COPY);
+	bool							Del_Shape				(int iShape);
+	bool							Del_Shape				(CSG_Shape *pShape);
+	bool							Del_Shapes				(void)					{	return( Del_Records() );	}
+
+	CSG_Shape *						Get_Shape				(TSG_Point Point, double Epsilon = 0.0);
+	CSG_Shape *						Get_Shape				(int iShape)	const	{	return( (CSG_Shape *)Get_Record(iShape) );	}
+	CSG_Shape *						Get_Shape_byIndex		(int Index)		const	{	return( (CSG_Shape *)Get_Record_byIndex(Index) );	}
+
+	//-----------------------------------------------------
+	virtual CSG_Shape *				Get_Selection			(int Index = 0)			{	return( (CSG_Shape *)CSG_Table::Get_Selection(Index) );	};
+	const CSG_Rect &				Get_Selection_Extent	(void);
+
+	virtual bool					Select					(CSG_Shape *pShape = NULL, bool bInvert = false);
+	virtual bool					Select					(TSG_Rect Extent         , bool bInvert = false);
+	virtual bool					Select					(TSG_Point Point         , bool bInvert = false);
+
+
+protected:
+
+	TSG_Shape_Type					m_Type;
+
+	CSG_Rect						m_Extent, m_Extent_Selected;
+
+
+	virtual void					_On_Construction		(void);
+
+	virtual CSG_Table_Record *		_Get_New_Record			(int Index);
+
+	virtual bool					On_Update				(void);
+
+	bool							_Load_ESRI				(const CSG_String &File_Name);
+	bool							_Save_ESRI				(const CSG_String &File_Name);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/** Safe shapes construction */
+SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(void);
+
+/** Safe shapes construction */
+SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(const CSG_Shapes &Shapes);
+
+/** Safe shapes construction */
+SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(const CSG_String &File_Name);
+
+/** Safe shapes construction */
+SAGA_API_DLL_EXPORT CSG_Shapes *	SG_Create_Shapes	(TSG_Shape_Type Type, const SG_Char *Name = NULL, CSG_Table *pStructure = NULL);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//				Point Region QuadTree					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Item
+{
+public:
+
+	virtual bool			is_Leaf			(void)	const	{	return( false );	}
+	virtual bool			is_Node			(void)	const	{	return( false );	}
+
+	CSG_Rect				Get_Extent		(void)	const	{	return( CSG_Rect(m_xCenter - m_Size, m_yCenter - m_Size, m_xCenter + m_Size, m_yCenter + m_Size) );	}
+	double					Get_xMin		(void)	const	{	return( m_xCenter - m_Size );	}
+	double					Get_yMin		(void)	const	{	return( m_yCenter - m_Size );	}
+	double					Get_xCenter		(void)	const	{	return( m_xCenter          );	}
+	double					Get_yCenter		(void)	const	{	return( m_yCenter          );	}
+	double					Get_xMax		(void)	const	{	return( m_xCenter + m_Size );	}
+	double					Get_yMax		(void)	const	{	return( m_yCenter + m_Size );	}
+	double					Get_Size		(void)	const	{	return( m_Size * 2.0       );	}
+
+	bool					Contains		(double x, double y)	const
+	{
+		return(	m_xCenter - m_Size <= x && x < m_xCenter + m_Size
+			&&	m_yCenter - m_Size <= y && y < m_yCenter + m_Size );
+	}
+
+	class CSG_PRQuadTree_Leaf *	asLeaf		(void)	const	{	return( (class CSG_PRQuadTree_Leaf *)this );	}
+	class CSG_PRQuadTree_Node *	asNode		(void)	const	{	return( (class CSG_PRQuadTree_Node *)this );	}
+
+
+protected:
+
+	CSG_PRQuadTree_Item(double xCenter, double yCenter, double Size)
+	{
+		m_xCenter	= xCenter;
+		m_yCenter	= yCenter;
+		m_Size		= Size;
+	}
+
+
+	double					m_xCenter, m_yCenter, m_Size;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Leaf : public CSG_PRQuadTree_Item
+{
+	friend class CSG_PRQuadTree_Node;
+
+public:
+
+	virtual bool			is_Leaf			(void)	const	{	return( true );		}
+
+	const TSG_Point &		Get_Point		(void)	const	{	return( m_Point );		}
+	double					Get_X			(void)	const	{	return( m_Point.x );	}
+	double					Get_Y			(void)	const	{	return( m_Point.y );	}
+	double					Get_Z			(void)	const	{	return( m_z );			}
+
+
+protected:
+
+	CSG_PRQuadTree_Leaf(double xCenter, double yCenter, double Size, double x, double y, double z)
+		: CSG_PRQuadTree_Item(xCenter, yCenter, Size)
+	{
+		m_Point.x	= x;
+		m_Point.y	= y;
+		m_z			= z;
+	}
+
+
+	double					m_z;
+
+	TSG_Point				m_Point;
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_PRQuadTree_Node : public CSG_PRQuadTree_Item
+{
+	friend class CSG_PRQuadTree;
+
+public:
+
+	virtual bool			is_Node			(void)	const	{	return( true );		}
+
+	CSG_PRQuadTree_Item *	Get_Child		(int i)	const	{	return( i >= 0 && i < 4 ? m_pChildren[i] : NULL );	}
+
+	bool					Add_Point		(double x, double y, double z);
+
+
+protected:
+
+	CSG_PRQuadTree_Node(double xCenter, double yCenter, double Size);
+	CSG_PRQuadTree_Node(CSG_PRQuadTree_Leaf *pLeaf);
+	virtual ~CSG_PRQuadTree_Node(void);
+
+
+	CSG_PRQuadTree_Item		*m_pChildren[4];
+
+};
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_PRQuadTree
+{
+public:
+	CSG_PRQuadTree(void);
+	CSG_PRQuadTree(const TSG_Rect &Extent);
+	CSG_PRQuadTree(CSG_Shapes *pShapes, int Attribute);
+	virtual ~CSG_PRQuadTree(void);
+
+	bool						Create					(const CSG_Rect &Extent);
+	bool						Create					(CSG_Shapes *pShapes, int Attribute);
+	void						Destroy					(void);
+
+	bool						Add_Point				(double x, double y, double z);
+
+	const CSG_PRQuadTree_Node &	Get_Root				(void) const	{	return( *m_pRoot );			}
+
+	bool						is_Okay					(void) const	{	return( m_pRoot != NULL );	}
+
+	bool						Get_Nearest_Point		(double x, double y, TSG_Point &Point, double &Value, double &Distance);
+
+	int							Select_Nearest_Points	(double x, double y, int maxPoints, double Radius = 0.0, int iQuadrant = -1);
+
+	int							Get_Selected_Count		(void) const	{	return( m_nSelected );		}
+
+	bool						Get_Selected_Point		(int i, double &x, double &y, double &z) const
+	{
+		if( i >= 0 && i < m_nSelected )
+		{
+			x	= m_Selected[i][0];
+			y	= m_Selected[i][1];
+			z	= m_Selected[i][2];
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+
+private:
+
+	int							m_nSelected, m_nPoints;
+
+	CSG_Matrix					m_Selected;
+
+	CSG_PRQuadTree_Node			*m_pRoot;
+
+	bool						_Quadrant_Contains		(double x, double y, int iQuadrant, const TSG_Point &p);
+	bool						_Radius_Contains		(double x, double y, double r, const TSG_Point &p);
+	bool						_Radius_Contains		(double x, double y, double r, int iQuadrant, const TSG_Point &p);
+	bool						_Quadrant_Intersects	(double x, double y, int iQuadrant, CSG_PRQuadTree_Item *pItem);
+	bool						_Radius_Intersects		(double x, double y, double r, CSG_PRQuadTree_Item *pItem);
+	bool						_Radius_Intersects		(double x, double y, double r, int iQuadrant, CSG_PRQuadTree_Item *pItem);
+
+	void						_Get_Nearest_Point		(CSG_PRQuadTree_Item *pItem, double x, double y, double &maxDistance, double Point[4]);
+	void						_Get_Nearest_Points		(CSG_PRQuadTree_Item *pItem, double x, double y, double &maxDistance, double Radius, int iQuadrant);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					Search Engine						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Shapes_Search
+{
+public:
+	CSG_Shapes_Search(void);
+	CSG_Shapes_Search(CSG_Shapes *pPoints);
+
+	virtual ~CSG_Shapes_Search(void);
+
+	bool						Create				(CSG_Shapes *pPoints);
+	void						Destroy				(void);
+
+	bool						is_Valid			(void)	{	return( m_nPoints > 0 );	}
+
+	CSG_Shape *					Get_Point_Nearest	(double x, double y);
+	CSG_Shape *					Get_Point_Nearest	(double x, double y, int iQuadrant);
+
+	int							Select_Radius		(double x, double y, double Radius, bool bSort = false, int MaxPoints = -1, int iQuadrant = -1);
+	int							Select_Quadrants	(double x, double y, double Radius, int MaxPoints, int MinPoints = 0);
+	int							Get_Selected_Count	(void)	{	return( m_nSelected );		}
+
+	CSG_Shape *					Get_Selected_Point	(int iSelected)
+	{
+		if( iSelected >= 0 && iSelected < m_nSelected )
+		{
+			return( m_nSelected == m_Selected_Idx.Get_Count()
+				? m_Selected[m_Selected_Idx[iSelected]]
+				: m_Selected               [iSelected]
+			);
+		}
+
+		return( NULL );
+	}
+
+
+protected:
+
+	bool						m_bDestroy;
+
+	int							m_nPoints, m_nSelected, m_Selected_Buf;
+
+	double						*m_Selected_Dst;
+
+	TSG_Point					*m_Pos;
+
+	CSG_Index					m_Idx, m_Selected_Idx;
+
+	CSG_Shape					**m_Selected;
+
+	CSG_Shapes					*m_pPoints;
+
+
+	void						_On_Construction	(void);
+
+	int							_Get_Index_Next		(double Position);
+	int							_Get_Point_Nearest	(double x, double y, int iQuadrant);
+	void						_Select_Add			(CSG_Shape *pPoint, double Distance);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__shapes_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_io.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_io.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_io.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,598 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    shapes_io.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes::_Load_ESRI(const CSG_String &File_Name)
+{
+	bool		bError;
+
+	char		buf_Header[100];
+
+	int			Type_File, Type_Shape, Type_Ext,
+				FileCode, FileLength, Version,
+				RecordNumber, ContentLength,
+				iShape, iPart, nParts, iPoint, nPoints,
+				buf_nParts, *buf_nPoints;
+
+	TSG_Point	dPoint;
+
+	TSG_Rect	dRect;
+
+	CSG_String	fName;
+
+	CSG_File	Stream;
+
+
+	//-----------------------------------------------------
+	// Open Shapes File...
+
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Load shapes"), File_Name.c_str()), true);
+
+	fName	= SG_File_Make_Path(NULL, File_Name, SG_T("shp"));
+
+	if( !Stream.Open(fName, SG_FILE_R, true) )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Shape file could not be opened."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	// Load File-Header (100-Bytes)...
+
+	Stream.Read(buf_Header, sizeof(char), 100);
+
+	FileCode	= SG_Mem_Get_Int	(buf_Header +  0, true );	// Byte 0		-> File Code 9994 Integer Big...
+	// ...														// Byte 4-20	-> Unused 0 Integer Big...
+	FileLength	= SG_Mem_Get_Int	(buf_Header + 24, true );	// Byte 24		-> File Length File Length Integer Big...
+	Version		= SG_Mem_Get_Int	(buf_Header + 28, false);	// Byte 28		-> Version 1000 Integer Little...
+	Type_File	= SG_Mem_Get_Int	(buf_Header + 32, false);	// Byte 32		-> Shape m_Type Shape m_Type Integer Little...
+	dRect.xMin	= SG_Mem_Get_Double	(buf_Header + 36, false);	// Byte 36		-> Bounding Box Xmin Double Little...
+	dRect.yMin	= SG_Mem_Get_Double	(buf_Header + 44, false);	// Byte 44		-> Bounding Box Ymin Double Little...
+	dRect.xMax	= SG_Mem_Get_Double	(buf_Header + 52, false);	// Byte 52		-> Bounding Box Xmax Double Little...
+	dRect.yMax	= SG_Mem_Get_Double	(buf_Header + 60, false);	// Byte 60		-> Bounding Box Ymax Double Little...
+	// ...														// Byte 68*		-> Bounding Box Zmin Double Little...
+	// ...														// Byte 76*		-> Bounding Box Zmax Double Little...
+	// ...														// Byte 84*		-> Bounding Box Mmin Double Little...
+	// ...														// Byte 92*		-> Bounding Box Mmax Double Little...
+
+	m_Extent.Assign(dRect);
+
+	switch( Type_File )
+	{
+	default:	m_Type	= SHAPE_TYPE_Undefined;	break;	// unsupported...
+	case 31:	m_Type	= SHAPE_TYPE_Undefined;	break;	// unsupported: MultiPatch...
+
+	case 1:		m_Type	= SHAPE_TYPE_Point;		Type_Ext	= 0;	break;	// Point
+	case 8:		m_Type	= SHAPE_TYPE_Points;	Type_Ext	= 0;	break;	// MultiPoint
+	case 3:		m_Type	= SHAPE_TYPE_Line;		Type_Ext	= 0;	break;	// PolyLine
+	case 5:		m_Type	= SHAPE_TYPE_Polygon;	Type_Ext	= 0;	break;	// Polygon
+
+	case 11:	m_Type	= SHAPE_TYPE_Point;		Type_Ext	= 2;	break;	// PointZ
+	case 18:	m_Type	= SHAPE_TYPE_Points;	Type_Ext	= 2;	break;	// MultiPointZ
+	case 13:	m_Type	= SHAPE_TYPE_Line;		Type_Ext	= 2;	break;	// PolyLineZ
+	case 15:	m_Type	= SHAPE_TYPE_Polygon;	Type_Ext	= 2;	break;	// PolygonZ
+
+	case 21:	m_Type	= SHAPE_TYPE_Point;		Type_Ext	= 1;	break;	// PointM
+	case 28:	m_Type	= SHAPE_TYPE_Points;	Type_Ext	= 1;	break;	// MultiPointM
+	case 23:	m_Type	= SHAPE_TYPE_Line;		Type_Ext	= 1;	break;	// PolyLineM
+	case 25:	m_Type	= SHAPE_TYPE_Polygon;	Type_Ext	= 1;	break;	// PolygonM
+	}
+
+	if( Stream.is_EOF() || FileCode != 9994 || Version != 1000 || m_Type == SHAPE_TYPE_Undefined )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Shape file invalid or of unsupported type."));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	// Load Attributes...
+
+	fName	= SG_File_Make_Path(NULL, File_Name, SG_T("dbf"));
+
+	SG_UI_Msg_Lock(true);
+
+	if( !_Create(fName.c_str(), TABLE_FILETYPE_DBase, SG_T("")) || Get_Count() == 0 )
+	{
+		SG_UI_Msg_Lock(false);
+
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] DBase file could not be opened or it did not contain any records."));
+
+		return( false );
+	}
+
+	SG_UI_Msg_Lock(false);
+
+	//-------------------------------------------------
+	// Load Shapes...
+
+	buf_nParts	= 0;
+	buf_nPoints	= NULL;
+
+	for(iShape=0, bError=false; iShape<Get_Count() && SG_UI_Process_Set_Progress(iShape, Get_Count()); iShape++)
+	{
+		CSG_Shape	*pShape	= Get_Shape(iShape);
+
+		RecordNumber	= Stream.Read_Int(true);
+		ContentLength	= Stream.Read_Int(true);
+
+		Stream.Read(&Type_Shape, sizeof(int));
+
+		if( Type_Shape != Type_File || Stream.is_EOF() )
+		{
+			bError	= true;
+		}
+		else
+		{
+			switch( m_Type )
+			{
+			default:
+				SG_UI_Msg_Add_Error(LNG("[ERR] Corrupted shape file."));
+				break;
+
+			//---------------------------------------------
+			case SHAPE_TYPE_Point:
+
+				Stream.Read(&dPoint	, sizeof(TSG_Point));
+				pShape->Add_Point(dPoint.x, dPoint.y);
+
+				//-----------------------------------------
+				if( Type_Ext != 0 )
+				{
+					if( Type_Ext == 1 )	// read Z
+					{
+						Stream.Read_Double(false);
+					}
+
+					// read M (optional)
+					Stream.Read_Double(false);
+				}
+				break;
+
+			//---------------------------------------------
+			case SHAPE_TYPE_Points:
+
+				Stream.Read(&dRect	, sizeof(TSG_Rect));
+				Stream.Read(&nPoints, sizeof(int));
+
+				for(iPoint=0; iPoint<nPoints; iPoint++)
+				{
+					Stream.Read(&dPoint, sizeof(TSG_Point));
+					pShape->Add_Point(dPoint.x, dPoint.y);
+				}
+
+				//-----------------------------------------
+				if( Type_Ext != 0 )
+				{
+					if( Type_Ext == 1 )	// read Z
+					{
+						Stream.Read_Double(false);
+						Stream.Read_Double(false);
+
+						for(iPoint=0; iPoint<nPoints; iPoint++)
+							Stream.Read_Double(false);
+					}
+
+					// read M (optional)
+					Stream.Read_Double(false);
+					Stream.Read_Double(false);
+
+					for(iPoint=0; iPoint<nPoints; iPoint++)
+						Stream.Read_Double(false);
+					break;
+				}
+				break;
+
+			//---------------------------------------------
+			case SHAPE_TYPE_Line:
+			case SHAPE_TYPE_Polygon:
+
+				Stream.Read(&dRect	, sizeof(TSG_Rect));
+				Stream.Read(&nParts	, sizeof(int));
+				Stream.Read(&nPoints, sizeof(int));
+
+				//-----------------------------------------
+				if( buf_nParts <= nParts )
+				{
+					buf_nParts	= nParts + 1;
+					buf_nPoints	= (int *)SG_Realloc(buf_nPoints, buf_nParts * sizeof(int));
+				}
+
+				for(iPart=0; iPart<nParts; iPart++)
+				{
+					Stream.Read(buf_nPoints + iPart, sizeof(int));
+				}
+
+				buf_nPoints[nParts]	= nPoints;
+
+				//-----------------------------------------
+				for(iPoint=0, iPart=0; iPoint<nPoints; iPoint++)
+				{
+					if( iPoint >= buf_nPoints[iPart + 1] && iPart < nParts - 1 )
+					{
+						iPart++;
+					}
+
+					Stream.Read(&dPoint, sizeof(TSG_Point));
+					pShape->Add_Point(dPoint.x, dPoint.y, iPart);
+				}
+
+				//-----------------------------------------
+				if( Type_Ext != 0 )
+				{
+					if( Type_Ext == 1 )	// read Z
+					{
+						Stream.Read_Double(false);
+						Stream.Read_Double(false);
+
+						for(iPoint=0; iPoint<nPoints; iPoint++)
+							Stream.Read_Double(false);
+					}
+
+					// read M (optional)
+					Stream.Read_Double(false);
+					Stream.Read_Double(false);
+
+					for(iPoint=0; iPoint<nPoints; iPoint++)
+						Stream.Read_Double(false);
+				}
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	// Clean up...
+
+	if( buf_nPoints )
+	{
+		SG_Free(buf_nPoints);
+	}
+
+	if( bError )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Shape file is corrupted."));
+	}
+	else
+	{
+		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+	}
+
+	SG_UI_Process_Set_Ready();
+
+	return( bError == false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define Save_ESRI_RecordHeader	Stream    .Write_Int(RecordNumber++, true);\
+								Stream    .Write_Int(ContentLength , true);\
+								Stream_Idx.Write_Int(FileLength	   , true);\
+								Stream_Idx.Write_Int(ContentLength , true);\
+								FileLength		+= 4 + ContentLength;\
+								FileLength_idx	+= 4;\
+
+//---------------------------------------------------------
+bool CSG_Shapes::_Save_ESRI(const CSG_String &File_Name)
+{
+	char		buf_Header[100];
+
+	int			FileLength, FileLength_idx, Type_File,
+				RecordNumber, ContentLength,
+				iShape, iPoint, iPart, nPoints;
+
+	TSG_Point	dPoint;
+
+	TSG_Rect	dRect;
+
+	CSG_String	fName;
+
+	CSG_File	Stream, Stream_Idx;
+
+	CSG_Shape	*pShape;
+
+
+	//-----------------------------------------------------
+	// Set Shape m_Type...
+
+	switch( m_Type )
+	{
+	case SHAPE_TYPE_Point:		// Point...
+		Type_File	= 1;
+		break;
+
+	case SHAPE_TYPE_Points:		// Multipoint...
+		Type_File	= 8;
+		break;
+
+	case SHAPE_TYPE_Line:		// Line, Polyline...
+		Type_File	= 3;
+		break;
+
+	case SHAPE_TYPE_Polygon:	// Polygon...
+		Type_File	= 5;
+		break;
+
+	default:					// unsupported...
+		return( false );
+	}
+
+
+	//-----------------------------------------------------
+	// File Access...
+
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save shapes"), File_Name.c_str()), true);
+
+	fName	= SG_File_Make_Path(NULL, File_Name, SG_T("shx"));
+
+	if( !Stream_Idx.Open(fName, SG_FILE_W, true) )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Shape index file could not be opened."));
+
+		return( false );
+	}
+
+	fName	= SG_File_Make_Path(NULL, File_Name, SG_T("shp"));
+
+	if( !Stream.Open(fName, SG_FILE_W, true) )
+	{
+		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+		SG_UI_Msg_Add_Error(LNG("[ERR] Shape file could not be opened."));
+
+		return( false );
+	}
+
+	SG_UI_Process_Set_Text(CSG_String::Format(SG_T("%s: %s"), LNG("[DAT] Save shapes"), fName.c_str() ));
+
+	//-----------------------------------------------------
+	// Save Header...
+
+	Update();
+
+	dRect	= m_Extent.m_rect;
+
+	SG_Mem_Set_Int		(buf_Header	+  0, 9994		, true );	// Byte 0	-> File Code 9994 Integer Big...
+	SG_Mem_Set_Int		(buf_Header +  4, 0			, true );	// Byte 4	-> unused Integer Big...
+	SG_Mem_Set_Int		(buf_Header +  8, 0			, true );	// Byte 8	-> unused Integer Big...
+	SG_Mem_Set_Int		(buf_Header + 12, 0			, true );	// Byte 12	-> unused Integer Big...
+	SG_Mem_Set_Int		(buf_Header + 16, 0			, true );	// Byte 16	-> unused Integer Big...
+	SG_Mem_Set_Int		(buf_Header + 20, 0			, true );	// Byte 20	-> unused Integer Big...
+	SG_Mem_Set_Int		(buf_Header + 24, 0			, true );	// Byte 24	-> File Length File Length Integer Big...
+	SG_Mem_Set_Int		(buf_Header + 28, 1000		, false);	// Byte 28	-> Version 1000 Integer Little...
+	SG_Mem_Set_Int		(buf_Header + 32, Type_File	, false);	// Byte 32	-> Shape m_Type Shape m_Type Integer Little...
+	SG_Mem_Set_Double	(buf_Header + 36, dRect.xMin, false);	// Byte 36	-> Bounding Box Xmin Double Little...
+	SG_Mem_Set_Double	(buf_Header + 44, dRect.yMin, false);	// Byte 44	-> Bounding Box Ymin Double Little...
+	SG_Mem_Set_Double	(buf_Header + 52, dRect.xMax, false);	// Byte 52	-> Bounding Box Xmax Double Little...
+	SG_Mem_Set_Double	(buf_Header + 60, dRect.yMax, false);	// Byte 60	-> Bounding Box Ymax Double Little...
+	SG_Mem_Set_Double	(buf_Header + 68, 0			, false);	// Byte 68	-> Bounding Box Zmin Double Little...
+	SG_Mem_Set_Double	(buf_Header + 76, 0			, false);	// Byte 76	-> Bounding Box Zmax Double Little...
+	SG_Mem_Set_Double	(buf_Header + 84, 0			, false);	// Byte 84	-> Bounding Box Mmin Double Little...
+	SG_Mem_Set_Double	(buf_Header + 92, 0			, false);	// Byte 92	-> Bounding Box Mmax Double Little...
+
+	Stream		.Write(buf_Header, sizeof(char), 100);
+	Stream_Idx	.Write(buf_Header, sizeof(char), 100);
+
+	FileLength		= 50;	// FileLength measured in 16-bit words...
+	FileLength_idx	= 50;	// FileLength measured in 16-bit words...
+
+	RecordNumber	= 1;
+
+	//-----------------------------------------------------
+	// Save Shapes...
+
+	for(iShape=0; iShape<Get_Count() && SG_UI_Process_Set_Progress(iShape, Get_Count()); iShape++)
+	{
+		pShape	= Get_Shape(iShape);
+
+		switch( Type_File )
+		{
+		//-------------------------------------------------
+		case 1:			// Point...
+			//---------------------------------------------
+			// Record-Header...
+			ContentLength	= 10;	// ShapeType + Point...
+			Save_ESRI_RecordHeader;
+
+			//---------------------------------------------
+			// Shape-Header...
+			Stream.Write(&Type_File	, sizeof(Type_File));
+
+			//---------------------------------------------
+			// Shape-Points...
+			dPoint			= pShape->Get_Point(0);
+			Stream.Write(&dPoint	, sizeof(TSG_Point));
+			break;
+
+		//-------------------------------------------------
+		case 8:			// Multipoint...
+			//---------------------------------------------
+			// Total Number of Points in Shape...
+			for(iPart=0, nPoints=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				nPoints	+= pShape->Get_Point_Count(iPart);
+			}
+
+			//-----------------------------------------
+			// Record-Header...
+			ContentLength	= 10;	// ShapeType + Point...
+			Save_ESRI_RecordHeader;
+
+			//-----------------------------------------
+			// Shape-Header...
+			dRect			= pShape->Get_Extent();
+
+			Stream.Write(&Type_File	, sizeof(Type_File));
+			Stream.Write(&dRect		, sizeof(TSG_Rect));
+			Stream.Write(&nPoints	, sizeof(int));
+
+			//-----------------------------------------
+			// Shape-Points...
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					dPoint		= pShape->Get_Point(iPoint, iPart);
+					Stream.Write(&dPoint, sizeof(TSG_Point));
+				}
+			}
+			break;
+
+		//-------------------------------------------------
+		case 3: case 5:	// Line, Polygon...
+			//---------------------------------------------
+			// Total Number of Points in Shape...
+			for(iPart=0, nPoints=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				nPoints	+= pShape->Get_Point_Count(iPart);
+			}
+
+			//---------------------------------------------
+			// Record-Header...
+			ContentLength	= 22 + 2 * pShape->Get_Part_Count() + 8 * nPoints;	// ShapeType + nParts + nParts*Offsets + nPoints...
+			Save_ESRI_RecordHeader;
+
+			//---------------------------------------------
+			// Shape-Header...
+			dRect			= pShape->Get_Extent();
+			iPart			= pShape->Get_Part_Count();
+
+			Stream.Write(&Type_File	, sizeof(Type_File));
+			Stream.Write(&dRect		, sizeof(TSG_Rect));
+			Stream.Write(&iPart		, sizeof(int));
+			Stream.Write(&nPoints	, sizeof(int));
+
+			for(iPart=0, iPoint=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				Stream.Write(&iPoint, sizeof(int));
+				iPoint	+= pShape->Get_Point_Count(iPart);
+			}
+
+			//---------------------------------------------
+			// Shape-Points...
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					dPoint		= pShape->Get_Point(iPoint, iPart);
+					Stream.Write(&dPoint, sizeof(TSG_Point));
+				}
+			}
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	// File Sizes...
+
+	Stream		.Seek(24);
+	Stream_Idx	.Seek(24);
+
+	Stream		.Write_Int(FileLength    , true);
+	Stream_Idx	.Write_Int(FileLength_idx, true);
+
+	SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+
+	SG_UI_Process_Set_Ready();
+
+	//-----------------------------------------------------
+	// Attributes...
+
+	fName	= SG_File_Make_Path(NULL, File_Name, SG_T("dbf"));
+
+	return( CSG_Table::Save(fName, TABLE_FILETYPE_DBase) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_search.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_search.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_search.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,616 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  shapes_search.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes_Search::CSG_Shapes_Search(void)
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Shapes_Search::CSG_Shapes_Search(CSG_Shapes *pPoints)
+{
+	_On_Construction();
+
+	Create(pPoints);
+}
+
+//---------------------------------------------------------
+void CSG_Shapes_Search::_On_Construction(void)
+{
+	m_pPoints		= NULL;
+	m_nPoints		= 0;
+	m_bDestroy		= false;
+
+	m_nSelected		= 0;
+	m_Selected		= NULL;
+	m_Selected_Dst	= NULL;
+	m_Selected_Buf	= 0;
+
+	m_Pos			= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shapes_Search::~CSG_Shapes_Search(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+void CSG_Shapes_Search::Destroy(void)
+{
+	if( m_nPoints > 0 )
+	{
+		SG_Free(m_Pos);
+	}
+
+	m_Pos			= NULL;
+	m_Idx			.Destroy();
+
+	//-----------------------------------------------------
+	if( m_bDestroy && m_pPoints )
+	{
+		delete(m_pPoints);
+	}
+
+	m_pPoints		= NULL;
+	m_nPoints		= 0;
+	m_bDestroy		= false;
+
+	//-----------------------------------------------------
+	if( m_Selected )
+	{
+		SG_Free(m_Selected);
+		SG_Free(m_Selected_Dst);
+	}
+
+	m_Selected		= NULL;
+	m_Selected_Dst	= NULL;
+	m_nSelected		= 0;
+	m_Selected_Buf	= 0;
+
+	m_Selected_Idx	.Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes_Search::Create(CSG_Shapes *pShapes)
+{
+	int		iShape, iPart, iPoint;
+	CSG_Shape	*pShape, *pPoint;
+	double	*Value;
+
+	Destroy();
+
+	//-----------------------------------------------------
+	if( pShapes && pShapes->is_Valid() )
+	{
+		if( pShapes->Get_Type() == SHAPE_TYPE_Point )
+		{
+			m_bDestroy	= false;
+			m_pPoints	= pShapes;
+		}
+		else
+		{
+			m_bDestroy	= true;
+			m_pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, NULL, pShapes);
+
+			for(iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+			{
+				pShape	= pShapes->Get_Shape(iShape);
+
+				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+				{
+					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+					{
+						pPoint	= m_pPoints->Add_Shape(pShape);
+						pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_pPoints->Get_Count() > 1 )
+		{
+			m_nPoints	= m_pPoints->Get_Count();
+
+			Value		= (double    *)SG_Malloc(m_nPoints * sizeof(double));
+			m_Pos		= (TSG_Point *)SG_Malloc(m_nPoints * sizeof(TSG_Point));
+
+			for(iPoint=0; iPoint<m_nPoints; iPoint++)
+			{
+				Value[iPoint]	= m_pPoints->Get_Shape(iPoint)->Get_Point(0).x;
+			}
+
+			m_Idx.Create(m_nPoints, Value, true);
+
+			for(iPoint=0; iPoint<m_nPoints; iPoint++)
+			{
+				m_Pos[iPoint]	= m_pPoints->Get_Shape(m_Idx[iPoint])->Get_Point(0);
+			}
+
+			SG_Free(Value);
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	Destroy();
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Shapes_Search::_Get_Index_Next(double Position)
+{
+	int		i, iLo, iHi;
+
+	if( m_Pos[0].x > Position )
+	{
+		return( 0 );
+	}
+	else if( m_Pos[m_nPoints - 1].x < Position )
+	{
+		return( m_nPoints - 1 );
+	}
+
+	for(iLo=0, iHi=m_nPoints-1; iHi-iLo>1; )
+	{
+		i	= iLo + (iHi - iLo) / 2;
+
+		if( m_Pos[i].x <= Position )
+		{
+			iLo	= i;
+		}
+		else
+		{
+			iHi	= i;
+		}
+	}
+
+	return( Position - m_Pos[iLo].x < m_Pos[iHi].x - Position ? iLo : iHi );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape * CSG_Shapes_Search::Get_Point_Nearest(double x, double y)
+{
+	int			ax, ix, iPoint_Min;
+	double		dx, dy, Dist, Dist_Min;
+
+	//-----------------------------------------------------
+	iPoint_Min	= -1;
+	ax			= _Get_Index_Next(x);
+
+	//-----------------------------------------------------
+	for(ix=ax, Dist_Min=-1.0; ix<m_nPoints; ix++)
+	{
+		dy		= m_Pos[ix].y - y;
+		dx		= m_Pos[ix].x - x;
+
+		if( iPoint_Min >= 0 && Dist_Min < dx )
+		{
+			break;
+		}
+		else
+		{
+			Dist	= sqrt(dx*dx + dy*dy);
+
+			if( iPoint_Min < 0 || Dist < Dist_Min )
+			{
+				iPoint_Min	= m_Idx[ix];
+				Dist_Min	= Dist;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	for(ix=ax-1; ix>=0; ix--)
+	{
+		dy		= m_Pos[ix].y - y;
+		dx		= m_Pos[ix].x - x;
+
+		if( iPoint_Min >= 0 && Dist_Min < dx )
+		{
+			break;
+		}
+		else
+		{
+			Dist	= sqrt(dx*dx + dy*dy);
+
+			if( iPoint_Min < 0 || Dist < Dist_Min )
+			{
+				iPoint_Min	= m_Idx[ix];
+				Dist_Min	= Dist;
+			}
+		}
+	}
+
+	return( iPoint_Min < 0 ? NULL : m_pPoints->Get_Shape(iPoint_Min) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Shape * CSG_Shapes_Search::Get_Point_Nearest(double x, double y, int Quadrant)
+{
+	int		iPoint;
+
+	iPoint	= _Get_Point_Nearest(x, y, Quadrant);
+
+	return( iPoint >= 0 && iPoint < m_nPoints ? m_pPoints->Get_Shape(iPoint) : NULL );
+}
+
+//---------------------------------------------------------
+int CSG_Shapes_Search::_Get_Point_Nearest(double x, double y, int Quadrant)
+{
+	int		ax, ix, iPoint_Min;
+	double	dx, dy, Dist, Dist_Min;
+
+	//-----------------------------------------------------
+	Dist_Min	= -1.0;
+	iPoint_Min	= -1;
+	ax			= _Get_Index_Next(x);
+
+	switch( Quadrant )
+	{
+	//-----------------------------------------------------
+	case 0:	// +x +y
+		if( m_Pos[ax].x < x )
+		{
+			ax++;
+		}
+
+		for(ix=ax; ix<m_nPoints; ix++)
+		{
+			if( (dy = m_Pos[ix].y - y) >= 0.0 )
+			{
+				dx		= m_Pos[ix].x - x;
+
+				if( iPoint_Min >= 0 && Dist_Min < dx )
+				{
+					return( iPoint_Min );
+				}
+
+				Dist	= sqrt(dx*dx + dy*dy);
+
+				if( iPoint_Min < 0 || Dist < Dist_Min )
+				{
+					iPoint_Min	= m_Idx[ix];
+					Dist_Min	= Dist;
+				}
+			}
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 1:	// +x -y
+		if( m_Pos[ax].x < x )
+		{
+			ax++;
+		}
+
+		for(ix=ax; ix<m_nPoints; ix++)
+		{
+			if( (dy = m_Pos[ix].y - y) <= 0.0 )
+			{
+				dx		= m_Pos[ix].x - x;
+
+				if( iPoint_Min >= 0 && Dist_Min < dx )
+				{
+					return( iPoint_Min );
+				}
+
+				Dist	= sqrt(dx*dx + dy*dy);
+
+				if( iPoint_Min < 0 || Dist < Dist_Min )
+				{
+					iPoint_Min	= m_Idx[ix];
+					Dist_Min	= Dist;
+				}
+			}
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 2:	// -x -y
+		if( m_Pos[ax].x > x )
+		{
+			ax--;
+		}
+
+		for(ix=ax; ix>=0; ix--)
+		{
+			if( (dy = m_Pos[ix].y - y) <= 0.0 )
+			{
+				dx		= m_Pos[ix].x - x;
+
+				if( iPoint_Min >= 0 && Dist_Min < dx )
+				{
+					return( iPoint_Min );
+				}
+
+				Dist	= sqrt(dx*dx + dy*dy);
+
+				if( iPoint_Min < 0 || Dist < Dist_Min )
+				{
+					iPoint_Min	= m_Idx[ix];
+					Dist_Min	= Dist;
+				}
+			}
+		}
+		break;
+
+	//-----------------------------------------------------
+	case 3:	// -x +y
+		if( m_Pos[ax].x > x )
+		{
+			ax--;
+		}
+
+		for(ix=ax; ix>=0; ix--)
+		{
+			if( (dy = m_Pos[ix].y - y) >= 0.0 )
+			{
+				dx		= m_Pos[ix].x - x;
+
+				if( iPoint_Min >= 0 && Dist_Min < dx )
+				{
+					return( iPoint_Min );
+				}
+
+				Dist	= sqrt(dx*dx + dy*dy);
+
+				if( iPoint_Min < 0 || Dist < Dist_Min )
+				{
+					iPoint_Min	= m_Idx[ix];
+					Dist_Min	= Dist;
+				}
+			}
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	return( iPoint_Min );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Shapes_Search::_Select_Add(CSG_Shape *pPoint, double Distance)
+{
+	if( m_nSelected >= m_Selected_Buf )
+	{
+		m_Selected_Buf	+= 8;
+
+		m_Selected		= (CSG_Shape **)SG_Realloc(m_Selected    , m_Selected_Buf * sizeof(CSG_Shape *));
+		m_Selected_Dst	= (double     *)SG_Realloc(m_Selected_Dst, m_Selected_Buf * sizeof(double     ));
+	}
+
+	m_Selected    [m_nSelected]	= pPoint;
+	m_Selected_Dst[m_nSelected]	= Distance;
+	m_nSelected++;
+}
+
+//---------------------------------------------------------
+int CSG_Shapes_Search::Select_Radius(double x, double y, double Radius, bool bSort, int MaxPoints, int iQuadrant)
+{
+	int		xLeft, xRight;
+	double	yBottom, yTop, Radius_2;
+
+	m_nSelected	= 0;
+
+	Radius_2	= Radius*Radius;
+
+	switch( iQuadrant )
+	{
+	default:	// all
+		xLeft	= _Get_Index_Next(x - Radius);
+		xRight	= _Get_Index_Next(x + Radius);
+		yBottom	= -Radius;
+		yTop	=  Radius;
+		break;
+
+	case 0:	// upper right
+		xLeft	= _Get_Index_Next(x);
+		xRight	= _Get_Index_Next(x + Radius);
+		yBottom	=  0.0;
+		yTop	=  Radius;
+		break;
+
+	case 1:	// lower right
+		xLeft	= _Get_Index_Next(x);
+		xRight	= _Get_Index_Next(x + Radius);
+		yBottom	= -Radius;
+		yTop	=  0.0;
+		break;
+
+	case 2:	// upper left
+		xLeft	= _Get_Index_Next(x - Radius);
+		xRight	= _Get_Index_Next(x);
+		yBottom	=  0.0;
+		yTop	=  Radius;
+		break;
+
+	case 3:	// lower left
+		xLeft	= _Get_Index_Next(x - Radius);
+		xRight	= _Get_Index_Next(x);
+		yBottom	= -Radius;
+		yTop	=  0.0;
+		break;
+	}
+
+	for(int ix=xLeft; ix<=xRight; ix++)
+	{
+		double	d	= m_Pos[ix].y - y;
+
+		if( yBottom <= d && d < yTop && (d = d*d + SG_Get_Square(m_Pos[ix].x - x)) <= Radius_2 )
+		{
+			_Select_Add(m_pPoints->Get_Shape(m_Idx[ix]), d);
+		}
+	}
+
+	if( bSort || (MaxPoints > 0 && MaxPoints < m_nSelected) )
+	{
+		m_Selected_Idx.Create(m_nSelected, m_Selected_Dst, true);
+	}
+
+	return( MaxPoints <= 0 || MaxPoints > m_nSelected ? m_nSelected : MaxPoints );
+}
+
+//---------------------------------------------------------
+int CSG_Shapes_Search::Select_Quadrants(double x, double y, double Radius, int MaxPoints, int MinPoints)
+{
+	if( MaxPoints <= 0 )
+	{
+		return( Select_Radius(x, y, Radius, true, MaxPoints) );
+	}
+
+	int			iQuadrant, i, n, nTotal;
+
+	CSG_Shape	**Selected		= (CSG_Shape **)SG_Malloc(4 * MaxPoints * sizeof(CSG_Shape *));
+
+
+	for(iQuadrant=0, nTotal=0; iQuadrant<4; iQuadrant++)
+	{
+		n	= Select_Radius(x, y, Radius, false, MaxPoints, iQuadrant);
+
+		if( n < MinPoints )
+		{
+			return( 0 );
+		}
+
+		for(i=0; i<n; i++)
+		{
+			Selected[nTotal + i]	= Get_Selected_Point(i);
+		}
+
+		nTotal	+= n;
+	}
+
+
+	for(i=0, m_nSelected=0; i<nTotal; i++)
+	{
+		_Select_Add(Selected[i], -1.0);
+	}
+
+	SG_Free(Selected);
+
+	return( m_nSelected );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_selection.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_selection.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/shapes_selection.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,148 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                shapes_selection.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Shapes::Select(CSG_Shape *pShape, bool bInvert)
+{
+	return( CSG_Table::Select(pShape, bInvert) );
+}
+
+//---------------------------------------------------------
+bool CSG_Shapes::Select(TSG_Rect Extent, bool bInvert)
+{
+	if( !bInvert )
+	{
+		CSG_Table::Select();
+	}
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( Get_Shape(i)->Intersects(Extent) )
+		{
+			CSG_Table::Select(i, true);
+		}
+	}
+
+	return( Get_Selection_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Shapes::Select(TSG_Point Point, bool bInvert)
+{
+	if( Get_Type() != SHAPE_TYPE_Polygon )
+	{
+		return( Select(CSG_Rect(Point, Point), bInvert) );
+	}
+
+	if( !bInvert )
+	{
+		CSG_Table::Select();
+	}
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( ((CSG_Shape_Polygon *)Get_Shape(i))->is_Containing(Point) )
+		{
+			CSG_Table::Select(i, true);
+		}
+	}
+
+	return( Get_Selection_Count() > 0 );
+}
+
+//---------------------------------------------------------
+const CSG_Rect & CSG_Shapes::Get_Selection_Extent(void)
+{
+	if( Get_Selection_Count() > 0 )
+	{
+		m_Extent_Selected	= Get_Selection(0)->Get_Extent();
+
+		for(int i=1; i<Get_Selection_Count(); i++)
+		{
+			m_Extent_Selected.Union(Get_Selection(i)->Get_Extent());
+		}
+	}
+	else
+	{
+		m_Extent_Selected.Assign(0.0, 0.0, 0.0, 0.0);
+	}
+
+	return( m_Extent_Selected );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       table.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "table.h"
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table * SG_Create_Table(void)
+{
+	return( new CSG_Table );
+}
+
+//---------------------------------------------------------
+CSG_Table * SG_Create_Table(const CSG_Table &Table)
+{
+	return( new CSG_Table(Table) );
+}
+
+//---------------------------------------------------------
+CSG_Table * SG_Create_Table(const CSG_String &File_Name)
+{
+	return( new CSG_Table(File_Name) );
+}
+
+//---------------------------------------------------------
+CSG_Table * SG_Create_Table(CSG_Table *pStructure)
+{
+	return( new CSG_Table(pStructure) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table::CSG_Table(void)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_Table::CSG_Table(const CSG_Table &Table)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(Table);
+}
+
+bool CSG_Table::Create(const CSG_Table &Table)
+{
+	return( is_Private() ? false : _Create(Table) );
+}
+
+bool CSG_Table::_Create(const CSG_Table &Table)
+{
+	if( Assign((CSG_Data_Object *)&Table) )
+	{
+		Set_Name(Table.Get_Name());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CSG_Table::CSG_Table(const CSG_String &File_Name, TSG_Table_File_Type Format)
+{
+	_On_Construction();
+
+	Create(File_Name, Format);
+}
+
+bool CSG_Table::Create(const CSG_String &File_Name, TSG_Table_File_Type Format)
+{
+	return( is_Private() ? false : _Create(File_Name, Format, SG_T("\t")) );
+}
+
+//---------------------------------------------------------
+CSG_Table::CSG_Table(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(File_Name, Format, Separator);
+}
+
+bool CSG_Table::Create(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator)
+{
+	return( is_Private() ? false : _Create(File_Name, Format, Separator) );
+}
+
+bool CSG_Table::_Create(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator)
+{
+	return( _Load(File_Name, Format, !Separator || !Separator[0] ? SG_T("\t") : Separator) );
+}
+
+//---------------------------------------------------------
+CSG_Table::CSG_Table(CSG_Table *pStructure)
+	: CSG_Data_Object()
+{
+	_On_Construction();
+
+	Create(pStructure);
+}
+
+bool CSG_Table::Create(CSG_Table *pStructure)
+{
+	return( is_Private() ? false : _Create(pStructure) );
+}
+
+bool CSG_Table::_Create(CSG_Table *pStructure)
+{
+	_Destroy();
+
+	if( pStructure && pStructure->Get_Field_Count() > 0 )
+	{
+		for(int i=0; i<pStructure->Get_Field_Count(); i++)
+		{
+			Add_Field(pStructure->Get_Field_Name(i), pStructure->Get_Field_Type(i));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Table::_On_Construction(void)
+{
+	m_pOwner		= NULL;
+
+	m_nFields		= 0;
+	m_Field_Name	= NULL;
+	m_Field_Type	= NULL;
+	m_Field_Stats	= NULL;
+
+	m_Records		= NULL;
+	m_nRecords		= 0;
+	m_nBuffer		= 0;
+
+	m_nSelected		= 0;
+	m_Selected		= NULL;
+
+	m_Index			= NULL;
+
+	Set_Update_Flag();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table::~CSG_Table(void)
+{
+	_Destroy();
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Destroy(void)
+{
+	return( is_Private() ? false : _Destroy() );
+}
+
+bool CSG_Table::_Destroy(void)
+{
+	_Destroy_Selection();
+
+	_Del_Records();
+
+	if( m_nFields > 0 )
+	{
+		for(int i=0; i<m_nFields; i++)
+		{
+			delete(m_Field_Name [i]);
+			delete(m_Field_Stats[i]);
+		}
+
+		m_nFields		= 0;
+
+		SG_Free(m_Field_Name);
+		SG_Free(m_Field_Type);
+		SG_Free(m_Field_Stats);
+
+		m_Field_Name	= NULL;
+		m_Field_Type	= NULL;
+		m_Field_Stats	= NULL;
+	}
+
+	CSG_Data_Object::Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Assign							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::Assign(CSG_Data_Object *pObject)
+{
+	return( is_Private() ? false : _Assign(pObject) );
+}
+
+bool CSG_Table::_Assign(CSG_Data_Object *pObject)
+{
+	int			i;
+	CSG_Table	*pTable;
+
+	if( pObject && pObject->is_Valid() && pObject->Get_ObjectType() == Get_ObjectType() )
+	{
+		_Destroy();
+
+		pTable	= (CSG_Table *)pObject;
+
+		for(i=0; i<pTable->m_nFields; i++)
+		{
+			Add_Field(pTable->m_Field_Name[i]->c_str(), pTable->m_Field_Type[i]);
+		}
+
+		for(i=0; i<pTable->m_nRecords; i++)
+		{
+			_Add_Record(pTable->m_Records[i]);
+		}
+
+		Get_History()	= pTable->Get_History();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Assign_Values(CSG_Table *pTable)
+{
+	int		i;
+
+	if( is_Compatible(pTable) )
+	{
+		if( is_Private() )
+		{
+			if( Get_Record_Count() == pTable->Get_Record_Count() )
+			{
+				_Index_Destroy();
+
+				for(i=0; i<pTable->Get_Record_Count(); i++)
+				{
+					Get_Record(i)->Assign(pTable->Get_Record(i));
+				}
+
+				return( true );
+			}
+		}
+		else
+		{
+			Del_Records();
+
+			for(i=0; i<pTable->Get_Record_Count(); i++)
+			{
+				Add_Record(pTable->Get_Record(i));
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Checks							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::is_Compatible(CSG_Table *pTable, bool bExactMatch) const
+{
+	if( Get_Field_Count() == pTable->Get_Field_Count() )
+	{
+		for(int i=0; i<Get_Field_Count(); i++)
+		{
+			if( bExactMatch )
+			{
+				if( Get_Field_Type(i) != pTable->Get_Field_Type(i) )
+				{
+					return( false );
+				}
+			}
+			else switch( Get_Field_Type(i) )
+			{
+			case SG_DATATYPE_String:
+//				if( pTable->Get_Field_Type(i) != SG_DATATYPE_String )
+//				{
+//					return( false );
+//				}
+				break;
+
+			default:
+				if( pTable->Get_Field_Type(i) == SG_DATATYPE_String )
+				{
+					return( false );
+				}
+				break;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Fields							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Table::Add_Field(const SG_Char *Name, TSG_Data_Type Type, int add_Field)
+{
+	int		iField, iRecord;
+
+	//-----------------------------------------------------
+	if( add_Field < 0 || add_Field > m_nFields )
+	{
+		add_Field	= m_nFields;
+	}
+
+	//-----------------------------------------------------
+	m_nFields++;
+
+	m_Field_Name	= (CSG_String            **)SG_Realloc(m_Field_Name , m_nFields * sizeof(CSG_String *));
+	m_Field_Type	= (TSG_Data_Type          *)SG_Realloc(m_Field_Type , m_nFields * sizeof(TSG_Data_Type));
+	m_Field_Stats	= (CSG_Simple_Statistics **)SG_Realloc(m_Field_Stats, m_nFields * sizeof(CSG_Simple_Statistics *));
+
+	//-----------------------------------------------------
+	for(iField=m_nFields-1; iField>add_Field; iField--)
+	{
+		m_Field_Name [iField]	= m_Field_Name [iField - 1];
+		m_Field_Type [iField]	= m_Field_Type [iField - 1];
+		m_Field_Stats[iField]	= m_Field_Stats[iField - 1];
+	}
+
+	//-----------------------------------------------------
+	m_Field_Name [add_Field]	= new CSG_String(Name);
+	m_Field_Type [add_Field]	= Type;
+	m_Field_Stats[add_Field]	= new CSG_Simple_Statistics();
+
+	//-----------------------------------------------------
+	for(iRecord=0; iRecord<m_nRecords; iRecord++)
+	{
+		m_Records[iRecord]->_Add_Field(add_Field);
+	}
+
+	Set_Modified();
+}
+
+//---------------------------------------------------------
+#ifdef _SAGA_UNICODE
+void CSG_Table::Add_Field(const char *Name, TSG_Data_Type Type, int iField)
+{	Add_Field(CSG_String(Name), Type, iField);	}
+#endif
+
+//---------------------------------------------------------
+bool CSG_Table::Del_Field(int del_Field)
+{
+	int		iRecord, iField;
+
+	if( del_Field >= 0 && del_Field < m_nFields )
+	{
+		m_nFields--;
+
+		//-------------------------------------------------
+		delete(m_Field_Name [del_Field]);
+		delete(m_Field_Stats[del_Field]);
+
+		//-------------------------------------------------
+		for(iField=del_Field; iField<m_nFields; iField++)
+		{
+			m_Field_Name [iField]	= m_Field_Name [iField + 1];
+			m_Field_Type [iField]	= m_Field_Type [iField + 1];
+			m_Field_Stats[iField]	= m_Field_Stats[iField + 1];
+		}
+
+		//-------------------------------------------------
+		m_Field_Name	= (CSG_String            **)SG_Realloc(m_Field_Name , m_nFields * sizeof(CSG_String *));
+		m_Field_Type	= (TSG_Data_Type          *)SG_Realloc(m_Field_Type , m_nFields * sizeof(TSG_Data_Type));
+		m_Field_Stats	= (CSG_Simple_Statistics **)SG_Realloc(m_Field_Stats, m_nFields * sizeof(CSG_Simple_Statistics *));
+
+		//-------------------------------------------------
+		for(iRecord=0; iRecord<m_nRecords; iRecord++)
+		{
+			m_Records[iRecord]->_Del_Field(del_Field);
+		}
+
+		Set_Modified();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Set_Field_Name(int iField, const SG_Char *Name)
+{
+	if( iField >= 0 && iField < m_nFields && Name && *Name )
+	{
+		*(m_Field_Name[iField])	= Name;
+
+		Set_Modified();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Records							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_GROW_SIZE(n)	(n < 256 ? 1 : (n < 8192 ? 128 : 1024))
+
+//---------------------------------------------------------
+bool CSG_Table::_Inc_Array(void)
+{
+	if( m_nRecords >= m_nBuffer )
+	{
+		CSG_Table_Record	**pRecords	= (CSG_Table_Record **)SG_Realloc(m_Records, (m_nBuffer + GET_GROW_SIZE(m_nBuffer)) * sizeof(CSG_Table_Record *));
+
+		if( pRecords )
+		{
+			m_Records	= pRecords;
+			m_nBuffer	+= GET_GROW_SIZE(m_nBuffer);
+
+			if( is_Indexed() )
+			{
+				int		*Index	= (int *)SG_Realloc(m_Index, m_nBuffer * sizeof(int));
+
+				if( Index )
+				{
+					m_Index	= Index;
+				}
+				else
+				{
+					_Index_Destroy();
+				}
+			}
+		}
+		else
+		{
+			return( false );
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::_Dec_Array(void)
+{
+	if( m_nRecords >= 0 && m_nRecords < m_nBuffer - GET_GROW_SIZE(m_nBuffer) )
+	{
+		CSG_Table_Record	**pRecords	= (CSG_Table_Record **)SG_Realloc(m_Records, (m_nBuffer - GET_GROW_SIZE(m_nBuffer)) * sizeof(CSG_Table_Record *));
+
+		if( pRecords )
+		{
+			m_Records	= pRecords;
+			m_nBuffer	-= GET_GROW_SIZE(m_nBuffer);
+
+			if( is_Indexed() )
+			{
+				int		*Index	= (int *)SG_Realloc(m_Index, m_nBuffer * sizeof(int));
+
+				if( Index )
+				{
+					m_Index	= Index;
+				}
+				else
+				{
+					_Index_Destroy();
+				}
+			}
+		}
+		else
+		{
+			return( false );
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+CSG_Table_Record * CSG_Table::_Get_New_Record(int Index)
+{
+	return( new CSG_Table_Record(this, Index) );
+}
+
+//---------------------------------------------------------
+CSG_Table_Record * CSG_Table::Add_Record(CSG_Table_Record *pCopy)
+{
+	return( is_Private() ? NULL : _Add_Record(pCopy) );
+}
+
+CSG_Table_Record * CSG_Table::_Add_Record(CSG_Table_Record *pCopy)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( _Inc_Array() && (pRecord = _Get_New_Record(m_nRecords)) != NULL )
+	{
+		if( pCopy )
+		{
+			if( Get_ObjectType() == DATAOBJECT_TYPE_Shapes && pCopy->Get_Table()->Get_ObjectType() == DATAOBJECT_TYPE_Shapes )
+			{
+				((CSG_Shape *)pRecord)->Assign((CSG_Shape *)pCopy, true);
+			}
+			else
+			{
+				pRecord->Assign(pCopy);
+			}
+		}
+
+		if( is_Indexed() )
+		{
+			m_Index[m_nRecords]	= m_nRecords;
+		}
+
+		m_Records[m_nRecords]	= pRecord;
+		m_nRecords++;
+
+		Set_Modified();
+
+		Set_Update_Flag();
+
+		_Stats_Invalidate();
+
+		return( pRecord );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Table_Record * CSG_Table::Ins_Record(int iRecord, CSG_Table_Record *pCopy)
+{
+	return( is_Private() ? NULL : _Ins_Record(iRecord, pCopy) );
+}
+
+CSG_Table_Record * CSG_Table::_Ins_Record(int iRecord, CSG_Table_Record *pCopy)
+{
+	if( iRecord >= m_nRecords )
+	{
+		return( _Add_Record(pCopy) );
+	}
+	else if( iRecord < 0 )
+	{
+		iRecord	= 0;
+	}
+
+	//-----------------------------------------------------
+	CSG_Table_Record	*pRecord;
+
+	if( _Inc_Array() && (pRecord = _Get_New_Record(m_nRecords)) != NULL )
+	{
+		if( pCopy )
+		{
+			pRecord->Assign(pCopy);
+		}
+
+		for(int i=m_nRecords; i>iRecord; i--)
+		{
+			if( is_Indexed() )
+			{
+				m_Index[i]		= m_Index[i - 1];
+			}
+
+			m_Records[i]			= m_Records[i - 1];
+			m_Records[i]->m_Index	= i;
+		}
+
+		if( is_Indexed() )
+		{
+			m_Index[iRecord]	= iRecord;
+		}
+
+		m_Records[iRecord]		= pRecord;
+		m_nRecords++;
+
+		Set_Modified();
+
+		Set_Update_Flag();
+
+		_Stats_Invalidate();
+
+		return( pRecord );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Del_Record(int iRecord)
+{
+	return( is_Private() ? false : _Del_Record(iRecord) );
+}
+
+bool CSG_Table::_Del_Record(int iRecord)
+{
+	int		i, j;
+
+	if( iRecord >= 0 && iRecord < m_nRecords )
+	{
+		delete(m_Records[iRecord]);
+
+		m_nRecords--;
+
+		for(i=iRecord, j=iRecord+1; i<m_nRecords; i++, j++)
+		{
+			m_Records[i]			= m_Records[i + 1];
+			m_Records[i]->m_Index	= i;
+		}
+
+		if( is_Indexed() )
+		{
+			for(i=0; i<m_nRecords; i++)
+			{
+				if( m_Index[i] == iRecord )
+				{
+					for(; i<m_nRecords; i++)
+					{
+						m_Index[i]	= m_Index[i + 1];
+					}
+				}
+			}
+
+			for(i=0; i<m_nRecords; i++)
+			{
+				if( m_Index[i] > iRecord )
+				{
+					m_Index[i]--;
+				}
+			}
+		}
+
+		_Dec_Array();
+
+		Set_Modified();
+
+		Set_Update_Flag();
+
+		_Stats_Invalidate();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Del_Records(void)
+{
+	return( is_Private() ? false : _Del_Records() );
+}
+
+bool CSG_Table::_Del_Records(void)
+{
+	if( m_Records > 0 )
+	{
+		_Index_Destroy();
+
+		for(int iRecord=0; iRecord<m_nRecords; iRecord++)
+		{
+			delete(m_Records[iRecord]);
+		}
+
+		SG_Free(m_Records);
+		m_Records	= NULL;
+		m_nRecords	= 0;
+		m_nBuffer	= 0;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Value Access					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::Set_Value(int iRecord, int iField, const SG_Char  *Value)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( iField >= 0 && iField < m_nFields && (pRecord = Get_Record(iRecord)) != NULL )
+	{
+		return( pRecord->Set_Value(iField, Value) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Set_Value(int iRecord, int iField, double       Value)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( iField >= 0 && iField < m_nFields && (pRecord = Get_Record(iRecord)) != NULL )
+	{
+		return( pRecord->Set_Value(iField, Value) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Get_Value(int iRecord, int iField, CSG_String &Value) const
+{
+	CSG_Table_Record	*pRecord;
+
+	if( iField >= 0 && iField < m_nFields && (pRecord = Get_Record(iRecord)) != NULL )
+	{
+		Value	= pRecord->asString(iField);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Get_Value(int iRecord, int iField, double      &Value) const
+{
+	CSG_Table_Record	*pRecord;
+
+	if( iField >= 0 && iField < m_nFields && (pRecord = Get_Record(iRecord)) != NULL )
+	{
+		Value	= pRecord->asDouble(iField);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Statistics						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::_Stats_Invalidate(void) const
+{
+	for(int iField=0; iField<m_nFields; iField++)
+	{
+		m_Field_Stats[iField]->Invalidate();
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::_Stats_Invalidate(int iField) const
+{
+	if( iField >= 0 && iField < m_nFields )
+	{
+		m_Field_Stats[iField]->Invalidate();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::_Stats_Update(int iField) const
+{
+	if( iField >= 0 && iField < m_nFields && m_nRecords > 0 )
+	{
+		if( !m_Field_Stats[iField]->is_Evaluated() )
+		{
+			CSG_Table_Record	**ppRecord	= m_Records;
+
+			for(int iRecord=0; iRecord<m_nRecords; iRecord++, ppRecord++)
+			{
+				m_Field_Stats[iField]->Add_Value((*ppRecord)->asDouble(iField));
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Index							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::Set_Index(int Field_1, TSG_Table_Index_Order Order_1, int Field_2, TSG_Table_Index_Order Order_2, int Field_3, TSG_Table_Index_Order Order_3)
+{
+	m_Index_Field[0]	= m_Index_Field[1]	= m_Index_Field[2]	= -1;
+	m_Index_Order[0]	= m_Index_Order[1]	= m_Index_Order[2]	= TABLE_INDEX_None;
+
+	if( Field_1 >= 0 && Field_1 < m_nFields && Order_1 != TABLE_INDEX_None )
+	{
+		m_Index_Field[0]	= Field_1;
+		m_Index_Order[0]	= Order_1;
+
+		if( Field_2 >= 0 && Field_2 < m_nFields && Order_2 != TABLE_INDEX_None )
+		{
+			m_Index_Field[1]	= Field_2;
+			m_Index_Order[1]	= Order_2;
+
+			if( Field_3 >= 0 && Field_3 < m_nFields && Order_3 != TABLE_INDEX_None )
+			{
+				m_Index_Field[2]	= Field_3;
+				m_Index_Order[2]	= Order_3;
+			}
+		}
+
+		_Index_Create();
+	}
+	else
+	{
+		_Index_Destroy();
+	}
+
+	return( is_Indexed() );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Del_Index(void)
+{
+	_Index_Destroy();
+
+	return( is_Indexed() );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Toggle_Index(int iField)
+{
+	if( iField >= 0 && iField < m_nFields )
+	{
+		if( iField != m_Index_Field[0] )
+		{
+			return( Set_Index(iField, TABLE_INDEX_Ascending) );
+		}
+		else if( m_Index_Order[0] == TABLE_INDEX_Ascending )
+		{
+			return( Set_Index(iField, TABLE_INDEX_Descending) );
+		}
+		else
+		{
+			return( Set_Index(iField, TABLE_INDEX_None) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+#define SORT_SWAP(a,b)	{itemp=(a);(a)=(b);(b)=itemp;}
+
+void CSG_Table::_Index_Create(void)
+{
+	const int	M	= 7;
+
+	int		indxt, itemp, *istack,
+			i, j, k, a,
+			l		= 0,
+			ir		= m_nRecords - 1,
+			nstack	= 64,
+			jstack	= 0;
+
+	//-----------------------------------------------------
+	if( m_Index == NULL )
+	{
+		m_Index	= (int *)SG_Malloc(m_nBuffer * sizeof(int));
+	}
+
+	for(j=0; j<m_nRecords; j++)
+	{
+		m_Index[j]	= j;
+	}
+
+	istack	= (int *)SG_Malloc(nstack * sizeof(int));
+
+	//-----------------------------------------------------
+	for(;;)
+	{
+		if( ir - l < M )
+		{
+			for(j=l+1; j<=ir; j++)
+			{
+				a		= indxt	= m_Index[j];
+
+				for(i=j-1; i>=0; i--)
+				{
+					if( _Index_Compare(m_Index[i], a) <= 0 )
+					{
+						break;
+					}
+
+					m_Index[i + 1]	= m_Index[i];
+				}
+
+				m_Index[i + 1]	= indxt;
+			}
+
+			if( jstack == 0 )
+			{
+				break;
+			}
+
+			ir		= istack[jstack--];
+			l		= istack[jstack--];
+		}
+		else
+		{
+			k		= (l + ir) >> 1;
+			SORT_SWAP(m_Index[k], m_Index[l + 1]);
+
+			if( _Index_Compare(m_Index[l + 1], m_Index[ir]) > 0 )
+				SORT_SWAP(     m_Index[l + 1], m_Index[ir]);
+
+			if( _Index_Compare(m_Index[l    ], m_Index[ir]) > 0 )
+				SORT_SWAP(     m_Index[l    ], m_Index[ir]);
+
+			if( _Index_Compare(m_Index[l + 1], m_Index[l ]) > 0 )
+				SORT_SWAP(     m_Index[l + 1], m_Index[l ]);
+
+			i		= l + 1;
+			j		= ir;
+			a		= indxt	= m_Index[l];
+
+			for(;;)
+			{
+				do	i++;	while( _Index_Compare(m_Index[i], a) < 0 );
+				do	j--;	while( _Index_Compare(m_Index[j], a) > 0 );
+
+				if( j < i )
+				{
+					break;
+				}
+
+				SORT_SWAP(m_Index[i], m_Index[j]);
+			}
+
+			m_Index[l]	= m_Index[j];
+			m_Index[j]	= indxt;
+			jstack		+= 2;
+
+			if( jstack >= nstack )
+			{
+				nstack	+= 64;
+				istack	= (int *)SG_Realloc(istack, nstack * sizeof(int));
+			}
+
+			if( ir - i + 1 >= j - l )
+			{
+				istack[jstack]		= ir;
+				istack[jstack - 1]	= i;
+				ir					= j - 1;
+			}
+			else
+			{
+				istack[jstack]		= j - 1;
+				istack[jstack - 1]	= l;
+				l					= i;
+			}
+		}
+	}
+
+	SG_Free(istack);
+}
+
+#undef SORT_SWAP
+
+//---------------------------------------------------------
+void CSG_Table::_Index_Destroy(void)
+{
+	m_Index_Field[0]	= -1;
+
+	if( m_Index )
+	{
+		SG_Free(m_Index);
+
+		m_Index	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+inline int CSG_Table::_Index_Compare(int a, int b)
+{
+	int		Result	= _Index_Compare(a, b, 0);
+
+	if( Result == 0 && m_Index_Field[1] >= 0 )
+	{
+		Result	= _Index_Compare(a, b, 1);
+
+		if( Result == 0 && m_Index_Field[2] >= 0 )
+		{
+			Result	= _Index_Compare(a, b, 2);
+		}
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+inline int CSG_Table::_Index_Compare(int a, int b, int Field)
+{
+	double	Result;
+
+	switch( m_Field_Type[m_Index_Field[Field]] )
+	{
+	case SG_DATATYPE_String:
+		Result	= SG_STR_CMP(
+					m_Records[a]->asString(m_Index_Field[Field]),
+					m_Records[b]->asString(m_Index_Field[Field])
+				);
+		break;
+
+	default:
+		Result	= m_Records[a]->asDouble(m_Index_Field[Field])
+				- m_Records[b]->asDouble(m_Index_Field[Field]);
+		break;
+	}
+
+	return( m_Index_Order[Field] == TABLE_INDEX_Ascending
+		? (Result < 0.0 ? -1 : (Result > 0.0 ? 1 : 0))
+		: (Result > 0.0 ? -1 : (Result < 0.0 ? 1 : 0))
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,390 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       table.h                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__table_H
+#define HEADER_INCLUDED__SAGA_API__table_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dataobject.h"
+#include "table_value.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum ESG_Table_FileType
+{
+	TABLE_FILETYPE_Undefined	= 0,
+	TABLE_FILETYPE_Text,
+	TABLE_FILETYPE_Text_NoHeadLine,
+	TABLE_FILETYPE_DBase
+}
+TSG_Table_File_Type;
+
+//---------------------------------------------------------
+typedef enum ESG_Table_Index_Order
+{
+	TABLE_INDEX_None			= 0,
+	TABLE_INDEX_Ascending,
+	TABLE_INDEX_Descending
+}
+TSG_Table_Index_Order;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Table_Record
+{
+	friend class CSG_Table;
+
+public:
+
+	class CSG_Table *			Get_Table		(void)				{	return( m_pTable );	}
+	int							Get_Index		(void)	const		{	return( m_Index );	}
+
+	bool						Set_Value		(int           iField, const SG_Char *Value);
+	bool						Set_Value		(const SG_Char *Field, const SG_Char *Value);
+	bool						Set_Value		(int           iField, double         Value);
+	bool						Set_Value		(const SG_Char *Field, double         Value);
+	bool						Add_Value		(int           iField, double         Value);
+	bool						Add_Value		(const SG_Char *Field, double         Value);
+	bool						Mul_Value		(int           iField, double         Value);
+	bool						Mul_Value		(const SG_Char *Field, double         Value);
+
+	bool						Set_NoData		(int           iField);
+	bool						Set_NoData		(const SG_Char *Field);
+	bool						is_NoData		(int           iField)	const;
+	bool						is_NoData		(const SG_Char *Field)	const;
+
+	const SG_Char *				asString		(int           iField, int Decimals = -1)	const;
+	const SG_Char *				asString		(const SG_Char *Field, int Decimals = -1)	const;
+
+	SG_Char						asChar			(int           iField)	const	{	return( (SG_Char)asInt   (iField) );	}
+	SG_Char						asChar			(const SG_Char *Field)	const	{	return( (SG_Char)asInt   ( Field) );	}
+	short						asShort			(int           iField)	const	{	return( (short  )asInt   (iField) );	}
+	short						asShort			(const SG_Char *Field)	const	{	return( (short  )asInt   ( Field) );	}
+	int							asInt			(int           iField)	const;
+	int							asInt			(const SG_Char *Field)	const;
+
+	float						asFloat			(int           iField)	const	{	return( (float  )asDouble(iField) );	}
+	float						asFloat			(const SG_Char *Field)	const	{	return( (float  )asDouble( Field) );	}
+	double						asDouble		(int           iField)	const;
+	double						asDouble		(const SG_Char *Field)	const;
+
+	CSG_Table_Value &			operator []		(int           iField)	const	{	return( *m_Values[iField] );	}
+
+	virtual bool				Assign			(CSG_Table_Record *pRecord);
+
+	bool						is_Selected		(void)					const	{	return( m_bSelected );	}
+
+
+protected:
+
+	CSG_Table_Record(class CSG_Table *pTable, int Index);
+	virtual ~CSG_Table_Record(void);
+
+
+	bool						m_bSelected;
+
+	int							m_Index;
+
+	class CSG_Table_Value		**m_Values;
+
+	class CSG_Table				*m_pTable;
+
+
+	class CSG_Table_Value *		_Create_Value	(TSG_Data_Type Type);
+
+	bool						_Add_Field		(int add_Field);
+	bool						_Del_Field		(int del_Field);
+
+	int							_Get_Field	 	(const SG_Char *Field)	const;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_Table : public CSG_Data_Object
+{
+	friend class CSG_Table_Record;
+	friend class CSG_TIN;
+
+public:
+
+	CSG_Table(void);
+
+									CSG_Table			(const CSG_Table &Table);
+	bool							Create				(const CSG_Table &Table);
+
+									CSG_Table			(const CSG_String &File_Name, TSG_Table_File_Type Format = TABLE_FILETYPE_Undefined);
+	bool							Create				(const CSG_String &File_Name, TSG_Table_File_Type Format = TABLE_FILETYPE_Undefined);
+
+									CSG_Table			(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator);
+	bool							Create				(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator);
+
+									CSG_Table			(CSG_Table *pStructure);
+	bool							Create				(CSG_Table *pStructure);
+
+	virtual ~CSG_Table(void);
+
+	virtual bool					Destroy				(void);
+
+	virtual TSG_Data_Object_Type	Get_ObjectType		(void)	const			{	return( DATAOBJECT_TYPE_Table );	}
+
+	virtual bool					Assign				(CSG_Data_Object *pSource);
+	bool							Assign_Values		(CSG_Table *pTable);
+
+	virtual bool					Save				(const CSG_String &File_Name, int Format = 0);
+	virtual bool					Save				(const CSG_String &File_Name, int Format, const SG_Char *Separator);
+	bool							Serialize			(CSG_File &Stream, bool bSave);
+
+	//-----------------------------------------------------
+	CSG_Data_Object *				Get_Owner			(void)					{	return( m_pOwner );			}
+	bool							is_Private			(void)	const			{	return( m_pOwner != NULL );	}
+
+	virtual bool					is_Valid			(void)	const			{	return( m_nFields > 0 );	}
+	bool							is_Compatible		(CSG_Table *pTable, bool bExactMatch = false)	const;
+
+	//-----------------------------------------------------
+	void							Add_Field			(const SG_Char *Name, TSG_Data_Type Type, int iField = -1);
+#ifdef _SAGA_UNICODE
+	void							Add_Field			(const char    *Name, TSG_Data_Type Type, int iField = -1);
+#endif
+	bool							Del_Field			(int iField);
+
+	int								Get_Field_Count		(void)			const	{	return( m_nFields );	}
+	const SG_Char *					Get_Field_Name		(int iField)	const	{	return( iField >= 0 && iField < m_nFields ? m_Field_Name[iField]->c_str() : NULL );			}
+	TSG_Data_Type					Get_Field_Type		(int iField)	const	{	return( iField >= 0 && iField < m_nFields ? m_Field_Type[iField] : SG_DATATYPE_Undefined );	}
+
+	bool							Set_Field_Name		(int iField, const SG_Char *Name);
+
+	double							Get_Minimum			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Minimum()  : 0.0 );	}
+	double							Get_Maximum			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Maximum()  : 0.0 );	}
+	double							Get_Range			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Range()    : 0.0 );	}
+	double							Get_Mean			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Mean()     : 0.0 );	}
+	double							Get_StdDev			(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_StdDev()   : 0.0 );	}
+	double							Get_Variance		(int iField)	const	{	return( _Stats_Update(iField) ? m_Field_Stats[iField]->Get_Variance() : 0.0 );	}
+
+	//-----------------------------------------------------
+	CSG_Table_Record *				Add_Record			(             CSG_Table_Record *pCopy = NULL);
+	CSG_Table_Record *				Ins_Record			(int iRecord, CSG_Table_Record *pCopy = NULL);
+	bool							Del_Record			(int iRecord);
+	bool							Del_Records			(void);
+
+	int								Get_Count			(void)			const	{	return( m_nRecords );	}
+	int								Get_Record_Count	(void)			const	{	return( m_nRecords );	}
+	CSG_Table_Record *				Get_Record			(int iRecord)	const	{	return( iRecord >= 0 && iRecord < m_nRecords ? m_Records[iRecord] : NULL );	}
+	CSG_Table_Record &				operator []			(int iRecord)	const	{	return( *Get_Record(iRecord) );	}
+
+	int								Get_Index			(int Index)		const	{	return( Index >= 0 && Index < m_nRecords ? (m_Index ? m_Index[Index] : Index) : -1 );	}
+
+	CSG_Table_Record *				Get_Record_byIndex	(int Index)		const
+	{
+		if( Index >= 0 && Index < m_nRecords )
+		{
+			if( m_Index != NULL )
+			{
+				return( m_Records[m_Index[Index]] );
+			}
+
+			return( m_Records[Index] );
+		}
+
+		return( NULL );
+	}
+
+	//-----------------------------------------------------
+	bool							Set_Value			(int iRecord, int iField, const SG_Char  *Value);
+	bool							Set_Value			(int iRecord, int iField, double          Value);
+
+	bool							Get_Value			(int iRecord, int iField, CSG_String     &Value)	const;
+	bool							Get_Value			(int iRecord, int iField, double         &Value)	const;
+
+	virtual void					Set_Modified		(bool bModified = true)	{	CSG_Data_Object::Set_Modified(bModified);	if( m_pOwner )	m_pOwner->Set_Modified(bModified);	}
+
+	//-----------------------------------------------------
+	int								Get_Selection_Count	(void)			const	{	return( m_nSelected );	}
+	CSG_Table_Record *				Get_Selection		(int Index = 0)	const	{	return( Index >= 0 && Index < m_nSelected ? m_Selected[Index] : NULL );	}
+
+	virtual bool					Select				(int iRecord						, bool bInvert = false);
+	virtual bool					Select				(CSG_Table_Record *pRecord = NULL	, bool bInvert = false);
+
+	int								Del_Selection		(void);
+	int								Inv_Selection		(void);
+
+	//-----------------------------------------------------
+	bool							Set_Index			(int Field_1, TSG_Table_Index_Order Order_1, int Field_2 = -1, TSG_Table_Index_Order Order_2 = TABLE_INDEX_None, int Field_3 = -1, TSG_Table_Index_Order Order_3 = TABLE_INDEX_None);
+	bool							Del_Index			(void);
+	bool							Toggle_Index		(int iField);
+
+	bool							is_Indexed			(void)	const		{	return( m_Index != NULL );	}
+
+	int								Get_Index_Field		(int i)	const		{	return( i >= 0 && i < 3 ? m_Index_Field[i] : -1 );	}
+	TSG_Table_Index_Order			Get_Index_Order		(int i)	const		{	return( i >= 0 && i < 3 ? m_Index_Order[i] : TABLE_INDEX_None );	}
+
+
+protected:
+
+	int								m_nFields, m_nRecords, m_nBuffer, m_nSelected, *m_Index, m_Index_Field[3];
+
+	TSG_Data_Type			*m_Field_Type;
+
+	TSG_Table_Index_Order			m_Index_Order[3];
+
+	CSG_Simple_Statistics			**m_Field_Stats;
+
+	CSG_Table_Record				**m_Records, **m_Selected;
+
+	CSG_String						**m_Field_Name;
+
+	CSG_Data_Object					*m_pOwner;
+
+
+	virtual void					_On_Construction	(void);
+
+	virtual CSG_Table_Record *		_Get_New_Record		(int Index);
+
+	bool							_Create				(const CSG_Table &Table);
+	bool							_Create				(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator);
+	bool							_Create				(CSG_Table *pStructure);
+
+	bool							_Destroy			(void);
+	bool							_Destroy_Selection	(void);
+
+	bool							_Assign				(CSG_Data_Object *pObject);
+
+	bool							_Inc_Array			(void);
+	bool							_Dec_Array			(void);
+
+	CSG_Table_Record *				_Add_Record			(             CSG_Table_Record *pValues = NULL);
+	CSG_Table_Record *				_Ins_Record			(int iRecord, CSG_Table_Record *pValues = NULL);
+	bool							_Del_Record			(int iRecord);
+	bool							_Del_Records		(void);
+
+	bool							_Stats_Invalidate	(void)			const;
+	bool							_Stats_Invalidate	(int iField)	const;
+	bool							_Stats_Update		(int iField)	const;
+
+	bool							_Load				(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator);
+	bool							_Load_Text			(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator);
+	bool							_Save_Text			(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator);
+	bool							_Load_DBase			(const CSG_String &File_Name);
+	bool							_Save_DBase			(const CSG_String &File_Name);
+
+	void							_Index_Create		(void);
+	void							_Index_Destroy		(void);
+	int								_Index_Compare		(int a, int b);
+	int								_Index_Compare		(int a, int b, int Field);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/** Safe table construction */
+SAGA_API_DLL_EXPORT CSG_Table *	SG_Create_Table	(void);
+
+/** Safe table construction */
+SAGA_API_DLL_EXPORT CSG_Table *	SG_Create_Table	(const CSG_Table &Table);
+
+/** Safe table construction */
+SAGA_API_DLL_EXPORT CSG_Table *	SG_Create_Table	(const CSG_String &File_Name);
+
+/** Safe table construction */
+SAGA_API_DLL_EXPORT CSG_Table *	SG_Create_Table	(CSG_Table *pStructure);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__table_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,723 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   table_dbase.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "api_core.h"
+#include "table_dbase.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define XBASE_FLDHDR_SZ			32
+#define TRIM_DBF_WHITESPACE
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table_DBase::CSG_Table_DBase(void)
+{
+	bOpen			= false;
+
+	hFile			= NULL;
+
+	Record			= NULL;
+	FieldOffset		= NULL;
+	FieldDesc		= NULL;
+	nFields			= 0;
+
+	Result_String	= NULL;
+}
+
+//---------------------------------------------------------
+CSG_Table_DBase::~CSG_Table_DBase(void)
+{
+	Close();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// Creates a new DBase-File using FieldDescription...
+bool CSG_Table_DBase::Open(const SG_Char *FileName, int anFields, TFieldDesc *aFieldDesc)
+{
+	Close();
+
+#if defined(_SAGA_LINUX) && defined(_SAGA_UNICODE)
+	if( (hFile = SG_FILE_OPEN(CSG_String(FileName).b_str(), "w+b")) != NULL )
+#else
+	if( (hFile = SG_FILE_OPEN(FileName, SG_T("w+b"))) != NULL )
+#endif
+	{
+		bOpen		= true;
+		bReadOnly	= false;
+
+		nFields		= anFields;
+		FieldDesc	= (TFieldDesc *)SG_Malloc(nFields * sizeof(TFieldDesc));
+		memcpy(FieldDesc, aFieldDesc, nFields * sizeof(TFieldDesc));
+
+		Header_Write();
+
+		nFileBytes	= nHeaderBytes;
+	}
+
+	return( bOpen );
+}
+
+
+//---------------------------------------------------------
+// Opens an existing DBase-File...
+bool CSG_Table_DBase::Open(const SG_Char *FileName)
+{
+	Close();
+
+#if defined(_SAGA_LINUX) && defined(_SAGA_UNICODE)
+	if( (hFile = SG_FILE_OPEN(CSG_String(FileName).b_str(), "rb")) != NULL )
+#else
+	if( (hFile = SG_FILE_OPEN(FileName, SG_T("rb"))) != NULL )
+#endif
+	{
+		bOpen		= true;
+		bReadOnly	= true;
+
+		if( Header_Read() )
+		{
+			fseek(hFile, 0, SEEK_END);
+			nFileBytes	= ftell(hFile);
+			fseek(hFile, 0, SEEK_SET);
+		}
+	}
+
+	return( bOpen );
+}
+
+//---------------------------------------------------------
+// Closes DBase-File if one was opened...
+void CSG_Table_DBase::Close(void)
+{
+	//-----------------------------------------------------
+	if( bOpen )
+	{
+		Flush_Record();
+		Header_Write();
+		bOpen			= false;
+
+		fclose(hFile);
+		hFile			= NULL;
+	}
+
+	//-----------------------------------------------------
+	if( Record )
+	{
+		SG_Free(Record);
+		Record			= NULL;
+	}
+
+	if( FieldOffset )
+	{
+		SG_Free(FieldOffset);
+		FieldOffset		= NULL;
+	}
+
+	if( FieldDesc )
+	{
+		SG_Free(FieldDesc);
+		FieldDesc		= NULL;
+	}
+
+	nFields			= 0;
+
+	if( Result_String )
+	{
+		SG_Free(Result_String);
+		Result_String	= NULL;
+	}
+
+	//-----------------------------------------------------
+	bModified		= false;
+	bRecModified	= false;
+
+	//-----------------------------------------------------
+	FileType		= 0;
+	nRecords		= 0;
+	nHeaderBytes	= 0;
+	nRecordBytes	= 0;
+	Transaction		= 0;
+	bEncrypted		= 0;
+	ProductionIdx	= 0;
+	LanguageDrvID	= 0;
+
+	nFileBytes		= 0;
+
+	memset(LastUpdate, 0, 3 * sizeof(char));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _SAGA_LINUX
+char * _strupr(char *String)
+{
+	if( String )
+		for(char *p=String; *p; p++)
+			if( 'a' <= *p && *p <= 'z' )
+				*p	+= 'A' - 'a';
+
+	return( String );
+}
+#endif
+
+//---------------------------------------------------------
+void CSG_Table_DBase::Header_Write(void)
+{
+	char		buf[16];
+	int			iField;
+	time_t		ltime;
+	struct tm	*pTime;
+	CSG_String	s;
+
+	if( bOpen && !bReadOnly )
+	{
+		//-------------------------------------------------
+		// Initializations...
+
+		FileType		= 0x03;
+
+
+		time( &ltime );
+		pTime			= localtime( &ltime );
+		LastUpdate[0]	= (unsigned char)pTime->tm_year;
+		LastUpdate[1]	= (unsigned char)pTime->tm_mon + 1;
+		LastUpdate[2]	= (unsigned char)pTime->tm_mday;
+
+		nHeaderBytes	= (nFields + 1) * 32 + 1;
+
+		nRecordBytes	= 1;	// Delete-Flag = Byte 0...
+
+		for(iField=0; iField<nFields; iField++)
+		{
+			nRecordBytes	+= FieldDesc[iField].Width;
+		}
+
+		Init_Record();
+
+		fseek(hFile, 0, SEEK_SET);
+
+		memset(buf, 0, 16 * sizeof(char));
+
+		//-------------------------------------------------
+		// Bytes 0-31: File Header...
+
+		fwrite(&FileType		, sizeof(char),  1, hFile);	// 00		FoxBase+, FoxPro, dBaseIII+, dBaseIV, no memo	- 0x03
+															//			FoxBase+, dBaseIII+ with memo					- 0x83
+															//			FoxPro with memo								- 0xF5
+															//			dBaseIV with memo								- 0x8B
+															//			dBaseIV with SQL Table							- 0x8E
+		fwrite(&LastUpdate		, sizeof(char),  3, hFile);	// 01-03	Last update, format YYYYMMDD   **correction: it is YYMMDD**
+		fwrite(&nRecords		, sizeof(char),  4, hFile);	// 04-07	Number of records in file (32-bit number)
+		fwrite(&nHeaderBytes	, sizeof(char),  2, hFile);	// 08-09	Number of bytes in header (16-bit number)
+		fwrite(&nRecordBytes	, sizeof(char),  2, hFile);	// 10-11	Number of bytes in record (16-bit number)
+		fwrite( buf				, sizeof(char),  2, hFile);	// 12-13	Reserved, fill with 0x00
+		fwrite(&Transaction		, sizeof(char),  1, hFile);	// 14		dBaseIV flag, incomplete transaction
+															//			Begin Transaction sets it to					- 0x01
+															//			End Transaction or RollBack reset it to			- 0x00
+		fwrite(&bEncrypted		, sizeof(char),  1, hFile);	// 15		Encryption flag, encrypted 0x01 else 0x00
+															//			Changing the flag does not encrypt or decrypt the records
+		fwrite( buf				, sizeof(char), 12, hFile);	// 16-27	dBaseIV multi-user environment use
+		fwrite(&ProductionIdx	, sizeof(char),  1, hFile);	// 28		Production index exists - 0x01 else 0x00
+		fwrite(&LanguageDrvID	, sizeof(char),  1, hFile);	// 29		dBaseIV language driver ID
+		fwrite( buf				, sizeof(char),  2, hFile);	// 30-31	Reserved fill with 0x00
+
+
+		//-------------------------------------------------
+		// Bytes 32-n: Field Descriptor Array...
+		for(iField=0; iField<nFields; iField++)
+		{
+			FieldDesc[iField].Name[11]	= '\0';
+			_strupr(FieldDesc[iField].Name);
+
+			fwrite( FieldDesc[iField].Name			, sizeof(char), 11, hFile);	// 00-10	Field Name ASCII padded with 0x00
+			fwrite(&FieldDesc[iField].Type			, sizeof(char),  1, hFile);	// 11		Field Type Identifier (see table)
+			fwrite(&FieldDesc[iField].Displacement	, sizeof(char),  4, hFile);	// 12-15	Displacement of field in record
+			fwrite(&FieldDesc[iField].Width			, sizeof(char),  1, hFile);	// 16		Field length in bytes
+			fwrite(&FieldDesc[iField].Decimals		, sizeof(char),  1, hFile);	// 17		Field decimal places
+			fwrite( buf								, sizeof(char),  2, hFile);	// 18-19	Reserved
+			fwrite(&FieldDesc[iField].WorkAreaID	, sizeof(char),  1, hFile);	// 20		dBaseIV work area ID
+			fwrite( buf								, sizeof(char), 10, hFile);	// 21-30	Reserved
+			fwrite(&FieldDesc[iField].ProductionIdx	, sizeof(char),  1, hFile);	// 31	 	Field is part of production index - 0x01 else 0x00
+		}
+
+		//-------------------------------------------------
+		// Byte n+1: Header Record Terminator (0x0D)...
+		buf[0]	= 0x0D;
+		fwrite( buf				, sizeof(char),  1, hFile);
+	}
+}
+
+//---------------------------------------------------------
+bool CSG_Table_DBase::Header_Read(void)
+{
+	bool	Result	= false;
+	char	buf[16];
+
+	if( bOpen )
+	{
+		//-------------------------------------------------
+		// Initializations...
+
+		fseek(hFile, 0, SEEK_SET);
+
+
+		//-------------------------------------------------
+		// Bytes 0-31: File Header...
+
+		fread(&FileType			, sizeof(char),  1, hFile);	// 00		FoxBase+, FoxPro, dBaseIII+, dBaseIV, no memo	- 0x03
+															//			FoxBase+, dBaseIII+ with memo					- 0x83
+															//			FoxPro with memo								- 0xF5
+															//			dBaseIV with memo								- 0x8B
+															//			dBaseIV with SQL Table							- 0x8E
+		fread(&LastUpdate		, sizeof(char),  3, hFile);	// 01-03	Last update, format YYYYMMDD   **correction: it is YYMMDD**
+		fread(&nRecords			, sizeof(char),  4, hFile);	// 04-07	Number of records in file (32-bit number)
+		fread(&nHeaderBytes		, sizeof(char),  2, hFile);	// 08-09	Number of bytes in header (16-bit number)
+		fread(&nRecordBytes		, sizeof(char),  2, hFile);	// 10-11	Number of bytes in record (16-bit number)
+		fread( buf				, sizeof(char),  2, hFile);	// 12-13	Reserved, fill with 0x00
+		fread(&Transaction		, sizeof(char),  1, hFile);	// 14		dBaseIV flag, incomplete transaction
+															//			Begin Transaction sets it to					- 0x01
+															//			End Transaction or RollBack reset it to			- 0x00
+		fread(&bEncrypted		, sizeof(char),  1, hFile);	// 15		Encryption flag, encrypted 0x01 else 0x00
+															//			Changing the flag does not encrypt or decrypt the records
+		fread( buf				, sizeof(char), 12, hFile);	// 16-27	dBaseIV multi-user environment use
+		fread(&ProductionIdx	, sizeof(char),  1, hFile);	// 28		Production index exists - 0x01 else 0x00
+		fread(&LanguageDrvID	, sizeof(char),  1, hFile);	// 29		dBaseIV language driver ID
+		fread( buf				, sizeof(char),  2, hFile);	// 30-31	Reserved fill with 0x00
+
+
+		//-------------------------------------------------
+		// Bytes 32-n: Field Descriptor Array...
+
+		while(	ftell(hFile) < (long)nHeaderBytes - 1 && !feof(hFile) )
+		{
+			FieldDesc	= (TFieldDesc *)SG_Realloc(FieldDesc, (nFields + 1) * sizeof(TFieldDesc));
+			FieldDesc[nFields].Name[12]	= '\0';
+
+			fread( FieldDesc[nFields].Name			, sizeof(char), 11, hFile);	// 0-10		Field Name ASCII padded with 0x00
+			fread(&FieldDesc[nFields].Type			, sizeof(char),  1, hFile);	// 11		Field Type Identifier (see table)
+			fread(&FieldDesc[nFields].Displacement	, sizeof(char),  4, hFile);	// 12-15	Displacement of field in record
+			fread(&FieldDesc[nFields].Width			, sizeof(char),  1, hFile);	// 16		Field length in bytes
+			fread(&FieldDesc[nFields].Decimals		, sizeof(char),  1, hFile);	// 17		Field decimal places
+			fread( buf								, sizeof(char),  2, hFile);	// 18-19	Reserved
+			fread(&FieldDesc[nFields].WorkAreaID	, sizeof(char),  1, hFile);	// 20		dBaseIV work area ID
+			fread( buf								, sizeof(char), 10, hFile);	// 21-30	Reserved
+			fread(&FieldDesc[nFields].ProductionIdx	, sizeof(char),  1, hFile);	// 31	 	Field is part of production index - 0x01 else 0x00
+
+			nFields++;
+		}
+
+
+		//-------------------------------------------------
+		// Byte n+1: Header Record Terminator (0x0D)...
+		fread( buf				, sizeof(char),  1, hFile);
+
+		if( buf[0] == 0x0d )
+		{
+			Init_Record();
+			Move_First();
+
+			Result	= true;
+		}
+	}
+
+	//-----------------------------------------------------
+	if( !Result )
+	{
+		fclose(hFile);
+		hFile	= NULL;
+		bOpen	= false;
+		Close();
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+void CSG_Table_DBase::Init_Record(void)
+{
+	int		iField, iPos;
+
+	Record		= (char *)SG_Realloc(Record		, nRecordBytes	* sizeof(char));
+	FieldOffset	= (int  *)SG_Realloc(FieldOffset	, nFields		* sizeof(int )); 
+
+	for(iField=0, iPos=1; iField<nFields; iField++)
+	{
+		FieldOffset[iField]	= iPos;
+		iPos	+= FieldDesc[iField].Width;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Table_DBase::Get_File_Position(void)
+{
+	return( hFile ? ftell(hFile) : 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table_DBase::Move_First(void)
+{
+	bool	Result	= false;
+
+	if( bOpen )
+	{
+		Flush_Record();
+
+		fseek(hFile, nHeaderBytes, SEEK_SET);
+
+		if( fread(Record, nRecordBytes, sizeof(char), hFile) == 1 )
+		{
+			Result	= true;
+		}
+
+		fseek(hFile, nHeaderBytes, SEEK_SET);
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_DBase::Move_Next(void)
+{
+	bool	Result	= false;
+
+	if( bOpen )
+	{
+		Flush_Record();
+
+		fseek(hFile, nRecordBytes, SEEK_CUR);
+
+		if( fread(Record, nRecordBytes, sizeof(char), hFile) == 1 )
+		{
+			Result	= true;
+		}
+
+		fseek(hFile, -nRecordBytes, SEEK_CUR);
+	}
+
+	return( Result );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_Table_DBase::Add_Record(void)
+{
+	if( bOpen )
+	{
+		bRecModified	= true;
+
+		memset(Record, 0, nRecordBytes);
+
+		fseek(hFile, 0, SEEK_END);
+		fwrite(Record, nRecordBytes, sizeof(char), hFile);
+		fseek(hFile, -nRecordBytes, SEEK_END);
+
+		nRecords++;
+
+		nFileBytes		+= nRecordBytes;
+	}
+}
+
+//---------------------------------------------------------
+void CSG_Table_DBase::Flush_Record(void)
+{
+	if( bOpen && !bReadOnly && bRecModified )
+	{
+		bRecModified	= false;
+		fwrite(Record, nRecordBytes, sizeof(char), hFile);
+		fseek(hFile, -nRecordBytes, SEEK_CUR);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Table_DBase::asInt(int iField)
+{
+	char	*s;
+	int		Result	= 0;
+
+	if( bOpen && iField >= 0 && iField < nFields )
+	{
+		if( FieldDesc[iField].Type == DBF_FT_NUMERIC )
+		{
+			s		= (char *)SG_Calloc(FieldDesc[iField].Width + 1, sizeof(char));
+			memcpy(s, Record + FieldOffset[iField], FieldDesc[iField].Width);
+			Result	= atoi(s);
+			SG_Free(s);
+		}
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+double CSG_Table_DBase::asDouble(int iField)
+{
+	char	*s;
+	double	Result	= 0;
+
+	if( bOpen && iField >= 0 && iField < nFields )
+	{
+		if( FieldDesc[iField].Type == DBF_FT_NUMERIC )
+		{
+			s		= (char *)SG_Calloc(FieldDesc[iField].Width + 1, sizeof(char));
+			memcpy(s, Record + FieldOffset[iField], FieldDesc[iField].Width);
+
+			Result	= atof(s);
+
+			SG_Free(s);
+		}
+		else if( FieldDesc[iField].Type == DBF_FT_DATE )
+		{
+			s		= (char *)SG_Calloc(FieldDesc[iField].Width + 1, sizeof(char));
+			memcpy(s, Record + FieldOffset[iField], FieldDesc[iField].Width);
+
+			int	d	= atoi(s + 6);	s[6]	= '\0';	if( d < 1 )	d	= 1;	else if( d > 31 )	d	= 31;
+			int	m	= atoi(s + 4);	s[4]	= '\0';	if( m < 1 )	m	= 1;	else if( m > 12 )	m	= 12;
+			int	y	= atoi(s);		
+
+			Result	= 10000 * y + 100 * m + 1 * d;
+
+			SG_Free(s);
+		}
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+char * CSG_Table_DBase::asString(int iField)
+{
+	int		i;
+
+	if( bOpen && iField >= 0 && iField < nFields )
+	{
+		i					= FieldDesc[iField].Width;
+		Result_String		= (char *)SG_Realloc(Result_String, (i + 1) * sizeof(char));
+		memcpy(Result_String, Record + FieldOffset[iField], FieldDesc[iField].Width);
+
+		Result_String[i--]	= '\0';
+
+		while( i >= 0 && Result_String[i] == ' ' )
+		{
+			Result_String[i--]	= '\0';
+		}
+
+		return( Result_String );
+	}
+
+	return( "" );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table_DBase::Set_Value(int iField, double Value)
+{
+	static char	s[256]	= "";
+
+	int		n;
+
+	if( bOpen && iField >= 0 && iField < nFields && FieldDesc[iField].Width > 0 )
+	{
+		if( FieldDesc[iField].Type == DBF_FT_NUMERIC )
+		{
+			bRecModified	= true;
+
+			if( FieldDesc[iField].Decimals > 0 )
+			{
+				sprintf(s, "%.*f", FieldDesc[iField].Decimals, Value);
+			}
+			else
+			{
+				sprintf(s, "%d", (int)Value);
+			}
+
+			if( (n = strlen(s)) > FieldDesc[iField].Width )
+			{
+				n	= FieldDesc[iField].Width;
+			}
+
+			memset(Record + FieldOffset[iField], ' ', FieldDesc[iField].Width);
+			memcpy(Record + FieldOffset[iField], s	, n);
+
+			return( true );
+		}
+		
+		if( FieldDesc[iField].Type == DBF_FT_DATE )
+		{
+			int		y	= (int)(Value / 10000);	Value	-= y * 10000;
+			int		m	= (int)(Value / 100);	Value	-= m * 100;
+			int		d	= (int)(Value / 1);
+
+			bRecModified	= true;
+
+			sprintf(s, "%04d%02d%02d", y, m, d);
+
+			if( (n = strlen(s)) > FieldDesc[iField].Width )
+			{
+				n	= FieldDesc[iField].Width;
+			}
+
+			memset(Record + FieldOffset[iField], ' ', FieldDesc[iField].Width);
+			memcpy(Record + FieldOffset[iField], s	, n);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_DBase::Set_Value(int iField, const char *Value)
+{
+	int		n;
+
+	if( bOpen && iField >= 0 && iField < nFields && FieldDesc[iField].Width > 0 )
+	{
+		if( FieldDesc[iField].Type == DBF_FT_CHARACTER && Value )
+		{
+			bRecModified	= true;
+
+			if( (n = strlen(Value)) > FieldDesc[iField].Width )
+			{
+				n	= FieldDesc[iField].Width;
+			}
+
+			memset(Record + FieldOffset[iField], ' '	, FieldDesc[iField].Width);
+			memcpy(Record + FieldOffset[iField], Value	, n);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table_dbase.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,203 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    table_dbase.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//		Interface for the CSG_Table_DBase class.		 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H
+#define HEADER_INCLUDED__SAGA_API__table_dbase_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <stdio.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DBF_FT_NONE				'\0'
+#define DBF_FT_CHARACTER		'C'
+#define DBF_FT_DATE				'D'
+#define DBF_FT_FLOAT			'F'
+#define DBF_FT_GENERAL			'G'
+#define DBF_FT_LOGICAL			'L'
+#define DBF_FT_MEMO				'M'
+#define DBF_FT_NUMERIC			'N'
+#define DBF_FT_PICTURE			'P'
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Table_DBase  
+{
+public:
+	//-----------------------------------------------------
+	typedef struct
+	{
+		char					Name[14],
+								Type,
+								Displacement[4],
+								WorkAreaID,
+								ProductionIdx;
+
+		unsigned char			Width,
+								Decimals;
+	}
+	TFieldDesc;
+
+
+public:
+	CSG_Table_DBase(void);
+	virtual ~CSG_Table_DBase(void);
+
+	//-----------------------------------------------------
+	bool						Open				(const SG_Char *FileName);
+	bool						Open				(const SG_Char *FileName, int nFields, TFieldDesc *FieldDesc);
+
+	void						Close				(void);
+
+	//-----------------------------------------------------
+	int							Get_FieldCount		(void)
+	{	return( nFields );	}
+
+	const char *				Get_FieldName		(int iField)
+	{	return( iField >= 0 && iField < nFields ? FieldDesc[iField].Name     : NULL );	}
+
+	char						Get_FieldType		(int iField)
+	{	return( iField >= 0 && iField < nFields ? FieldDesc[iField].Type     : DBF_FT_NONE );	}
+
+	int							Get_FieldWidth		(int iField)
+	{	return( iField >= 0 && iField < nFields ? FieldDesc[iField].Width    : 0 );	}
+
+	int							Get_FieldDecimals	(int iField)
+	{	return( iField >= 0 && iField < nFields ? FieldDesc[iField].Decimals : 0 );	}
+
+
+	//-----------------------------------------------------
+	int							Get_File_Position	(void);
+	int							Get_File_Length		(void)	{	return( nFileBytes );	}
+	int							Get_Record_Count	(void)	{	return( nRecords );		}
+
+	//-----------------------------------------------------
+	bool						Move_First			(void);
+	bool						Move_Next			(void);
+
+	//-----------------------------------------------------
+	void						Add_Record			(void);
+	void						Flush_Record		(void);
+
+	//-----------------------------------------------------
+	int							asInt				(int iField);
+	double						asDouble			(int iField);
+	char *						asString			(int iField);
+
+	//-----------------------------------------------------
+	bool						Set_Value			(int iField, double Value);
+	bool						Set_Value			(int iField, const char *Value);
+
+
+protected:
+
+	bool						bOpen, bReadOnly, bModified, bRecModified;
+
+	char						LastUpdate[3], Transaction, LanguageDrvID, ProductionIdx,
+								*Record, *Result_String;
+
+	unsigned char				FileType, bEncrypted;
+
+	short						nHeaderBytes, nRecordBytes;
+
+	int							nFields, nRecords, *FieldOffset, nFileBytes;
+
+	FILE						*hFile;
+
+	TFieldDesc					*FieldDesc;
+
+
+	void						Header_Write		(void);
+	bool						Header_Read			(void);
+
+	void						Init_Record			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table_io.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table_io.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table_io.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,684 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    table_io.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "table.h"
+#include "table_dbase.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::_Load(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator)
+{
+	bool		bResult;
+	CSG_String	fName, sSeparator(Separator);
+
+	_Destroy();
+
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Load table"), File_Name.c_str()), true);
+
+	//-----------------------------------------------------
+	if( Format == TABLE_FILETYPE_Undefined )
+	{
+		if( SG_File_Cmp_Extension(File_Name, SG_T("dbf")) )
+		{
+			Format	= TABLE_FILETYPE_DBase;
+		}
+		else if( SG_File_Cmp_Extension(File_Name, SG_T("csv")) )
+		{
+			Format	= TABLE_FILETYPE_Text;
+			sSeparator	= ";";
+		}
+		else //if( SG_File_Cmp_Extension(File_Name, SG_T("txt")) )
+		{
+			Format	= TABLE_FILETYPE_Text;
+		}
+	}
+
+	//-----------------------------------------------------
+	switch( Format )
+	{
+	case TABLE_FILETYPE_Text:
+		bResult	= _Load_Text (File_Name, true , sSeparator);
+		break;
+
+	case TABLE_FILETYPE_Text_NoHeadLine:
+		bResult	= _Load_Text (File_Name, false, sSeparator);
+		break;
+
+	case TABLE_FILETYPE_DBase:
+		bResult	= _Load_DBase(File_Name);
+		break;
+
+	default:
+		bResult	= false;
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		Set_Modified(false);
+
+		Set_Update_Flag();
+
+		Set_File_Name(File_Name);
+
+		Load_MetaData(File_Name);
+
+		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+
+		return( true );
+	}
+
+	SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Save(const CSG_String &File_Name, int Format)
+{
+	return( Save(File_Name, Format, SG_T("\t")) );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Save(const CSG_String &File_Name, int Format, const SG_Char *Separator)
+{
+	bool		bResult;
+	CSG_String	sSeparator(Separator);
+
+	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save table"), File_Name.c_str()), true);
+
+	//-----------------------------------------------------
+	if( Format <= TABLE_FILETYPE_Undefined || Format > TABLE_FILETYPE_DBase )
+	{
+		if( SG_File_Cmp_Extension(File_Name, SG_T("dbf")) )
+		{
+			Format	= TABLE_FILETYPE_DBase;
+		}
+		else if( SG_File_Cmp_Extension(File_Name, SG_T("csv")) )
+		{
+			Format	= TABLE_FILETYPE_Text;
+			sSeparator	= ';';
+		}
+		else //if( SG_File_Cmp_Extension(File_Name, SG_T("txt")) )
+		{
+			Format	= TABLE_FILETYPE_Text;
+		}
+	}
+
+	switch( Format )
+	{
+	case TABLE_FILETYPE_Text:
+		bResult	= _Save_Text (File_Name, true , Separator);
+		break;
+
+	case TABLE_FILETYPE_Text_NoHeadLine:
+		bResult	= _Save_Text (File_Name, false, Separator);
+		break;
+
+	case TABLE_FILETYPE_DBase:
+		bResult	= _Save_DBase(File_Name);
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( bResult )
+	{
+		Set_Modified(false);
+
+		Set_Update_Flag();
+
+		Set_File_Type(Format);
+
+		Set_File_Name(File_Name);
+
+		Save_MetaData(File_Name);
+
+		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+
+		return( true );
+	}
+
+	SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Text							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::_Load_Text(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator)
+{
+	int			i, iField, fLength;
+	CSG_String	sLine, sField;
+	CSG_File	Stream;
+	CSG_Table	Table;
+
+	//-----------------------------------------------------
+	if( Stream.Open(File_Name, SG_FILE_R, false) == false )
+	{
+		return( false );
+	}
+
+	if( !Stream.Read_Line(sLine) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	sLine	+= Separator;
+
+	while( (i = sLine.Find(Separator)) >= 0 )
+	{
+		sField.Printf(bHeadline ? sLine.Left(i) : SG_T("FIELD_%02d"), Table.Get_Field_Count() + 1);
+
+		if( sField[0] == SG_T('\"') && sField[(int)(sField.Length() - 1)] == SG_T('\"') )	// remove quota
+		{
+			sField	= sField.AfterFirst('\"').BeforeLast('\"');
+		}
+
+		Table.Add_Field(sField, SG_DATATYPE_String);
+
+		sLine.Remove(0, i + 1);
+	}
+
+	//-----------------------------------------------------
+	TSG_Data_Type	*Type	= new TSG_Data_Type[Table.Get_Field_Count()];
+
+	for(iField=0; iField<Table.Get_Field_Count(); iField++)
+	{
+		Type[iField]	= SG_DATATYPE_Int;
+	}
+
+	if( !bHeadline )
+	{
+		Stream.Seek_Start();
+	}
+
+	fLength	= Stream.Length();
+
+	while( Stream.Read_Line(sLine) && sLine.Length() > 0 && SG_UI_Process_Set_Progress(Stream.Tell(), fLength) )
+	{
+		CSG_Table_Record	*pRecord	= Table._Add_Record();
+
+		sLine	+= Separator;
+
+		for(iField=0; iField<Table.Get_Field_Count(); iField++)
+		{
+			if( (i = sLine.Find(Separator)) >= 0 )
+			{
+				sField.Printf(sLine.Left(i));
+
+				if( sField[0] == SG_T('\"') && sField[(int)(sField.Length() - 1)] == SG_T('\"') )	// remove quota
+				{
+					sField	= sField.AfterFirst('\"').BeforeLast('\"');
+				}
+
+				if( Type[iField] != SG_DATATYPE_String )
+				{
+					double	Value;
+
+					if( SG_SSCANF(sField, SG_T("%lf"), &Value) != 1 )
+					{
+						Type[iField]	= SG_DATATYPE_String;
+					}
+					else if( Type[iField] != SG_DATATYPE_Double && Value - (int)Value != 0.0 )
+					{
+						Type[iField]	= SG_DATATYPE_Double;
+					}
+				}
+
+				pRecord->Set_Value(iField, sField);
+
+				sLine.Remove(0, i + 1);
+			}
+			else
+			{
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( Table.Get_Count() > 0 )
+	{
+		for(iField=0; iField<Table.Get_Field_Count(); iField++)
+		{
+			Add_Field(Table.Get_Field_Name(iField), Type[iField]);
+		}
+
+		for(int iRecord=0; iRecord<Table.Get_Count() && SG_UI_Process_Set_Progress(iRecord, Table.Get_Count()); iRecord++)
+		{
+			CSG_Table_Record	*pRecord	= _Add_Record();
+
+			for(iField=0; iField<Get_Field_Count(); iField++)
+			{
+				switch( Get_Field_Type(iField) )
+				{
+				default:						pRecord->Set_Value(iField, Table[iRecord].asString(iField));	break;
+				case SG_DATATYPE_Int:		pRecord->Set_Value(iField, Table[iRecord].asInt   (iField));	break;
+				case SG_DATATYPE_Double:	pRecord->Set_Value(iField, Table[iRecord].asDouble(iField));	break;
+				}
+			}
+		}
+	}
+
+	delete[](Type);
+
+	SG_UI_Process_Set_Ready();
+
+	return( Get_Field_Count() > 0 );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::_Save_Text(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator)
+{
+	int			iField, iRecord;
+	CSG_File	Stream;
+
+	if( Get_Field_Count() > 0 )
+	{
+		if( Stream.Open(File_Name, SG_FILE_W, false) )
+		{
+			for(iField=0; iField<Get_Field_Count(); iField++)
+			{
+				Stream.Printf(SG_T("%s%s"), Get_Field_Name(iField), iField < Get_Field_Count() - 1 ? Separator : SG_T("\n"));
+			}
+
+			for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++)
+			{
+				for(iField=0; iField<Get_Field_Count(); iField++)
+				{
+					Stream.Printf(SG_T("%s"), Get_Record(iRecord)->asString(iField));
+					Stream.Printf(SG_T("%s"), iField < Get_Field_Count() - 1 ? Separator : SG_T("\n"));
+				}
+			}
+
+			SG_UI_Process_Set_Ready();
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						DBase							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::_Load_DBase(const CSG_String &File_Name)
+{
+	int					iField;
+	CSG_Table_DBase		dbf;
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	if( dbf.Open(File_Name) )
+	{
+		Destroy();
+
+		for(iField=0; iField<dbf.Get_FieldCount(); iField++)
+		{
+			TSG_Data_Type	Type;
+
+			switch( dbf.Get_FieldType(iField) )
+			{
+			case DBF_FT_LOGICAL:
+				Type	= SG_DATATYPE_Char;
+				break;
+
+			case DBF_FT_CHARACTER:	default:
+				Type	= SG_DATATYPE_String;
+				break;
+
+			case DBF_FT_DATE:
+				Type	= SG_DATATYPE_Date;
+				break;
+
+			case DBF_FT_NUMERIC:
+				Type	= dbf.Get_FieldDecimals(iField) > 0
+						? SG_DATATYPE_Double
+						: SG_DATATYPE_Long;
+				break;
+			}
+
+			Add_Field(SG_STR_MBTOSG(dbf.Get_FieldName(iField)), Type);
+		}
+
+		//-------------------------------------------------
+		if( dbf.Move_First() && dbf.Get_Record_Count() > 0 )
+		{
+			m_nRecords		= m_nBuffer	= dbf.Get_Record_Count();
+			m_Records		= (CSG_Table_Record **)SG_Malloc(m_nRecords * sizeof(CSG_Table_Record *));
+
+			for(int iRecord=0; iRecord<m_nRecords && SG_UI_Process_Set_Progress(iRecord, m_nRecords); iRecord++)
+			{
+				m_Records[iRecord]	= pRecord	= _Get_New_Record(iRecord);
+
+				for(iField=0; iField<Get_Field_Count(); iField++)
+				{
+					switch( Get_Field_Type(iField) )
+					{
+					case SG_DATATYPE_Char:
+						pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) );
+						break;
+
+					case SG_DATATYPE_String:	default:
+						pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) );
+						break;
+
+					case SG_DATATYPE_Date:
+						pRecord->Set_Value(iField, dbf.asDouble(iField) );
+						break;
+
+					case SG_DATATYPE_Long:
+						pRecord->Set_Value(iField, dbf.asInt(iField) );
+						break;
+
+					case SG_DATATYPE_Double:
+						pRecord->Set_Value(iField, dbf.asDouble(iField) );
+						break;
+					}
+				}
+
+				dbf.Move_Next();
+			}
+
+			SG_UI_Process_Set_Ready();
+
+			Set_Modified(false);
+
+			Set_Update_Flag();
+
+			_Stats_Invalidate();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::_Save_DBase(const CSG_String &File_Name)
+{
+	int							iField, iRecord;
+	size_t						*nStringBytes;
+	CSG_Table_Record			*pRecord;
+	CSG_Table_DBase				dbf;
+	CSG_Table_DBase::TFieldDesc	*dbfFieldDesc;
+
+	//-----------------------------------------------------
+	for(iField=0, nStringBytes=NULL; iField<Get_Field_Count(); iField++)
+	{
+		if( Get_Field_Type(iField) == SG_DATATYPE_String )
+		{
+			if( nStringBytes == NULL )
+			{
+				nStringBytes	= new size_t[Get_Field_Count()];
+			}
+
+			nStringBytes[iField]	= 8;
+		}
+	}
+
+	if( nStringBytes )
+	{
+		for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++)
+		{
+			pRecord	= Get_Record(iRecord);
+
+			for(iField=0; iField<Get_Field_Count(); iField++)
+			{
+				if( Get_Field_Type(iField) == SG_DATATYPE_String && SG_STR_LEN(pRecord->asString(iField)) > nStringBytes[iField] )
+				{
+					nStringBytes[iField]	= SG_STR_LEN(pRecord->asString(iField));
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	dbfFieldDesc	= (CSG_Table_DBase::TFieldDesc *)SG_Calloc(Get_Field_Count(), sizeof(CSG_Table_DBase::TFieldDesc));
+
+	for(iField=0; iField<Get_Field_Count(); iField++)
+	{
+		strncpy(dbfFieldDesc[iField].Name, SG_STR_SGTOMB(Get_Field_Name(iField)), 11);
+
+		switch( Get_Field_Type(iField) )
+		{
+		default:
+			dbfFieldDesc[iField].Type		= DBF_FT_CHARACTER;
+			dbfFieldDesc[iField].Width		= (char)64;
+			break;
+
+		case SG_DATATYPE_String:
+			dbfFieldDesc[iField].Type		= DBF_FT_CHARACTER;
+			dbfFieldDesc[iField].Width		= (char)nStringBytes[iField];
+			break;
+
+		case SG_DATATYPE_Date:
+			dbfFieldDesc[iField].Type		= DBF_FT_DATE;
+			dbfFieldDesc[iField].Width		= (char)8;
+			break;
+
+		case SG_DATATYPE_Char:
+			dbfFieldDesc[iField].Type		= DBF_FT_CHARACTER;
+			dbfFieldDesc[iField].Width		= (char)1;
+			break;
+
+		case SG_DATATYPE_Short:
+		case SG_DATATYPE_Int:
+		case SG_DATATYPE_Long:
+		case SG_DATATYPE_Color:
+			dbfFieldDesc[iField].Type		= DBF_FT_NUMERIC;
+			dbfFieldDesc[iField].Width		= (char)16;
+			dbfFieldDesc[iField].Decimals	= (char)0;
+			break;
+
+		case SG_DATATYPE_Float:
+		case SG_DATATYPE_Double:
+			dbfFieldDesc[iField].Type		= DBF_FT_NUMERIC;
+			dbfFieldDesc[iField].Width		= (char)16;
+			dbfFieldDesc[iField].Decimals	= (char)8;
+			break;
+		}
+	}
+
+	dbf.Open(File_Name, Get_Field_Count(), dbfFieldDesc);
+
+	SG_Free(dbfFieldDesc);
+
+	if( nStringBytes )
+	{
+		delete[](nStringBytes);
+	}
+
+	//-----------------------------------------------------
+	for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++)
+	{
+		pRecord	= Get_Record(iRecord);
+
+		dbf.Add_Record();
+
+		for(iField=0; iField<Get_Field_Count(); iField++)
+		{
+			switch( dbf.Get_FieldType(iField) )
+			{
+			case DBF_FT_CHARACTER:
+				dbf.Set_Value(iField, SG_STR_SGTOMB(pRecord->asString(iField)));
+				break;
+
+			case DBF_FT_DATE:
+				dbf.Set_Value(iField, pRecord->asDouble(iField));
+				break;
+
+			case DBF_FT_NUMERIC:
+				dbf.Set_Value(iField, pRecord->asDouble(iField));
+				break;
+			}
+		}
+
+		dbf.Flush_Record();
+	}
+
+	SG_UI_Process_Set_Ready();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Serialize						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::Serialize(CSG_File &Stream, bool bSave)
+{
+	SG_Char				Separator	= SG_T('\t');
+	int					iField, nFields, iRecord, nRecords, FieldType;
+	CSG_Table_Record	*pRecord;
+	CSG_String			s, sLine;
+
+	//-----------------------------------------------------
+	if( bSave )
+	{
+		Stream.Printf(SG_T("%d %d\n"), m_nFields, m_nRecords);
+
+		for(iField=0; iField<m_nFields; iField++)
+		{
+			Stream.Printf(SG_T("%d \"%s\"\n"), Get_Field_Type(iField), Get_Field_Name(iField));
+		}
+
+		for(iRecord=0; iRecord<m_nRecords; iRecord++)
+		{
+			for(iField=0; iField<m_nFields; iField++)
+			{
+				Stream.Printf(SG_T("%s%c"), Get_Record(iRecord)->asString(iField), iField < m_nFields - 1 ? Separator : '\n');
+			}
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	else if( Stream.Read_Line(sLine) && SG_SSCANF(sLine, SG_T("%d %d"), &nFields, &nRecords) == 2 && nFields > 0 )
+	{
+		_Destroy();
+
+		for(iField=0; iField<nFields; iField++)
+		{
+			if( Stream.Read_Line(sLine) && SG_SSCANF(sLine, SG_T("%d"), &FieldType) == 1 )
+			{
+				Add_Field(sLine.AfterFirst(SG_T('\"')).BeforeFirst(SG_T('\"')), (TSG_Data_Type)FieldType);
+			}
+		}
+
+		for(iRecord=0; iRecord<nRecords; iRecord++)
+		{
+			if( Stream.Read_Line(sLine) )
+			{
+				pRecord	= _Add_Record();
+
+				for(iField=0; iField<m_nFields; iField++)
+				{
+					pRecord->Set_Value(iField, sLine.BeforeFirst(Separator));
+
+					sLine	= sLine.AfterFirst(Separator);
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table_record.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table_record.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table_record.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,407 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   table_record.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <string.h>
+
+#include "table.h"
+#include "table_value.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table_Record::CSG_Table_Record(CSG_Table *pTable, int Index)
+{
+	m_pTable	= pTable;
+	m_Index		= Index;
+	m_bSelected	= false;
+
+	if( m_pTable && m_pTable->Get_Field_Count() > 0 )
+	{
+		m_Values	= (CSG_Table_Value **)SG_Malloc(m_pTable->Get_Field_Count() * sizeof(CSG_Table_Value *));
+
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			m_Values[iField]	= _Create_Value(m_pTable->Get_Field_Type(iField));
+		}
+	}
+	else
+	{
+		m_Values	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+CSG_Table_Record::~CSG_Table_Record(void)
+{
+	if( m_bSelected )
+	{
+		m_pTable->Select(m_Index, true);
+	}
+
+	if( m_pTable->Get_Field_Count() > 0 )
+	{
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			delete(m_Values[iField]);
+		}
+
+		SG_Free(m_Values);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table_Value * CSG_Table_Record::_Create_Value(TSG_Data_Type Type)
+{
+	switch( Type )
+	{
+	default:
+	case SG_DATATYPE_String:	return( new CSG_Table_Value_String() );
+
+	case SG_DATATYPE_Date:		return( new CSG_Table_Value_Date() );
+
+	case SG_DATATYPE_Color:
+	case SG_DATATYPE_Byte:
+	case SG_DATATYPE_Char:
+	case SG_DATATYPE_Word:
+	case SG_DATATYPE_Short:
+	case SG_DATATYPE_DWord:
+	case SG_DATATYPE_Int:
+	case SG_DATATYPE_ULong:
+	case SG_DATATYPE_Long:		return( new CSG_Table_Value_Int() );
+
+	case SG_DATATYPE_Float:
+	case SG_DATATYPE_Double:	return( new CSG_Table_Value_Double() );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table_Record::_Add_Field(int add_Field)
+{
+	if( add_Field < 0 )
+	{
+		add_Field	= 0;
+	}
+	else if( add_Field >= m_pTable->Get_Field_Count() )
+	{
+		add_Field	= m_pTable->Get_Field_Count() - 1;
+	}
+
+	m_Values	= (CSG_Table_Value **)SG_Realloc(m_Values, m_pTable->Get_Field_Count() * sizeof(CSG_Table_Value *));
+
+	for(int iField=m_pTable->Get_Field_Count()-1; iField>add_Field; iField--)
+	{
+		m_Values[iField]	= m_Values[iField - 1];
+	}
+
+	m_Values[add_Field]	= _Create_Value(m_pTable->Get_Field_Type(add_Field));
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_Record::_Del_Field(int del_Field)
+{
+	delete(m_Values[del_Field]);
+
+	for(int iField=del_Field; iField<m_pTable->Get_Field_Count(); iField++)
+	{
+		m_Values[iField]	= m_Values[iField + 1];
+	}
+
+	m_Values	= (CSG_Table_Value **)SG_Realloc(m_Values, m_pTable->Get_Field_Count() * sizeof(CSG_Table_Value *));
+
+	return( true );
+}
+
+//---------------------------------------------------------
+int CSG_Table_Record::_Get_Field(const SG_Char *Field) const
+{
+	if( Field && *Field )
+	{
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			if( !SG_STR_CMP(Field, m_pTable->Get_Field_Name(iField)) )
+			{
+				return( iField );
+			}
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table_Record::Set_Value(int iField, const SG_Char *Value)
+{
+	if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
+	{
+		if( m_Values[iField]->Set_Value(Value) )
+		{
+			m_pTable->Set_Modified();
+			m_pTable->Set_Update_Flag();
+			m_pTable->_Stats_Invalidate(iField);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+bool CSG_Table_Record::Set_Value(const SG_Char *Field, const SG_Char *Value)
+{
+	return( Set_Value(_Get_Field(Field), Value) );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_Record::Set_Value(int iField, double Value)
+{
+	if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
+	{
+		if( m_Values[iField]->Set_Value(Value) )
+		{
+			m_pTable->Set_Modified();
+			m_pTable->Set_Update_Flag();
+			m_pTable->_Stats_Invalidate(iField);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+bool CSG_Table_Record::Set_Value(const SG_Char *Field, double Value)
+{
+	return( Set_Value(_Get_Field(Field), Value) );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_Record::Add_Value(int iField, double Value)
+{
+	if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
+	{
+		return( Set_Value(iField, asDouble(iField) + Value) );
+	}
+
+	return( false );
+}
+
+bool CSG_Table_Record::Add_Value(const SG_Char *Field, double Value)
+{
+	return( Add_Value(_Get_Field(Field), Value) );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_Record::Mul_Value(int iField, double Value)
+{
+	if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
+	{
+		return( Set_Value(iField, asDouble(iField) * Value) );
+	}
+
+	return( false );
+}
+
+bool CSG_Table_Record::Mul_Value(const SG_Char *Field, double Value)
+{
+	return( Mul_Value(_Get_Field(Field), Value) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table_Record::Set_NoData(int iField)
+{
+	if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
+	{
+		if( m_Values[iField]->Set_NoData() )
+		{
+			m_pTable->Set_Modified();
+			m_pTable->Set_Update_Flag();
+			m_pTable->_Stats_Invalidate(iField);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+bool CSG_Table_Record::Set_NoData(const SG_Char *Field)
+{
+	return( Set_NoData(_Get_Field(Field)) );
+}
+
+//---------------------------------------------------------
+bool CSG_Table_Record::is_NoData(int iField) const
+{
+	return( iField >= 0 && iField < m_pTable->Get_Field_Count() ? m_Values[iField]->is_NoData() : true );
+}
+
+bool CSG_Table_Record::is_NoData(const SG_Char *Field) const
+{
+	return( is_NoData(_Get_Field(Field)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const SG_Char * CSG_Table_Record::asString(int iField, int Decimals) const
+{
+	return( iField >= 0 && iField < m_pTable->Get_Field_Count() ? m_Values[iField]->asString(Decimals) : NULL );
+}
+
+const SG_Char * CSG_Table_Record::asString(const SG_Char *Field, int Decimals) const
+{
+	return( asString(_Get_Field(Field), Decimals) );
+}
+
+//---------------------------------------------------------
+int CSG_Table_Record::asInt(int iField) const
+{
+	return( iField >= 0 && iField < m_pTable->Get_Field_Count() ? m_Values[iField]->asInt() : 0 );
+}
+
+int CSG_Table_Record::asInt(const SG_Char *Field) const
+{
+	return( asInt(_Get_Field(Field)) );
+}
+
+//---------------------------------------------------------
+double CSG_Table_Record::asDouble(int iField) const
+{
+	return( iField >= 0 && iField < m_pTable->Get_Field_Count() ? m_Values[iField]->asDouble() : 0.0 );
+}
+
+double CSG_Table_Record::asDouble(const SG_Char *Field) const
+{
+	return( asDouble(_Get_Field(Field)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table_Record::Assign(CSG_Table_Record *pRecord)
+{
+	if( pRecord )
+	{
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			Set_Value(iField, pRecord->asString(iField));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table_selection.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table_selection.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table_selection.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,216 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 table_selection.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::_Destroy_Selection(void)
+{
+	if( m_nSelected > 0 )
+	{
+		for(int iRecord=0; iRecord<m_nSelected; iRecord++)
+		{
+			m_Selected[iRecord]->m_bSelected	= false;
+		}
+
+		SG_Free(m_Selected);
+		m_Selected	= NULL;
+		m_nSelected	= 0;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_Table::Select(int iRecord, bool bInvert)
+{
+	int				i;
+	CSG_Table_Record	*pRecord;
+
+	if( !bInvert )
+	{
+		_Destroy_Selection();
+	}
+
+	if( (pRecord = Get_Record(iRecord)) != NULL )
+	{
+		if( pRecord->m_bSelected == false )
+		{
+			m_nSelected++;
+			m_Selected	= (CSG_Table_Record **)SG_Realloc(m_Selected, m_nSelected * sizeof(CSG_Table_Record *));
+			m_Selected[m_nSelected - 1]	= pRecord;
+			pRecord->m_bSelected		= true;
+		}
+		else
+		{
+			m_nSelected--;
+
+			for(i=0; i<m_nSelected; i++)
+			{
+				if( pRecord == m_Selected[i] )
+				{
+					for(; i<m_nSelected; i++)
+					{
+						m_Selected[i]	= m_Selected[i + 1];
+					}
+				}
+			}
+
+			m_Selected	= (CSG_Table_Record **)SG_Realloc(m_Selected, m_nSelected * sizeof(CSG_Table_Record *));
+			pRecord->m_bSelected		= false;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_Table::Select(CSG_Table_Record *pRecord, bool bInvert)
+{
+	return( Select(pRecord ? pRecord->Get_Index() : -1, bInvert) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CSG_Table::Del_Selection(void)
+{
+	int		n	= 0;
+
+	if( !is_Private() && m_nSelected > 0 )
+	{
+		for(int i=m_nSelected-1; i>=0; i--)
+		{
+			CSG_Table_Record	*pRecord	= m_Selected[i];
+
+			pRecord->m_bSelected	= false;
+
+			if( _Del_Record(pRecord->Get_Index()) )
+			{
+				n++;
+			}
+		}
+
+		SG_Free(m_Selected);
+		m_Selected	= NULL;
+		m_nSelected	= 0;
+	}
+
+	return( n );
+}
+
+//---------------------------------------------------------
+int CSG_Table::Inv_Selection(void)
+{
+	CSG_Table_Record	**pRecord	= m_Records + 0;
+
+	if( Get_Record_Count() > 0 )
+	{
+		m_nSelected	= m_nRecords - m_nSelected;
+		m_Selected	= (CSG_Table_Record **)SG_Realloc(m_Selected, m_nSelected * sizeof(CSG_Table_Record *));
+
+		for(int i=0, j=0; i<m_nRecords; i++, pRecord++)
+		{
+			if( (*pRecord)->m_bSelected )
+			{
+				(*pRecord)->m_bSelected	= false;
+			}
+			else
+			{
+				(*pRecord)->m_bSelected	= true;
+				m_Selected[j++]			= (*pRecord);
+			}
+		}
+	}
+
+	return( Get_Selection_Count() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/table_value.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/table_value.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/table_value.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,364 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    table_value.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__table_value_H
+#define HEADER_INCLUDED__SAGA_API__table_value_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "api_core.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define NODATA_STRING	SG_T("[NO DATA]")
+#define NODATA_INT		-2147483647
+#define NODATA_DOUBLE	2.2204460492503131e-016
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Table_Value
+{
+public:
+	CSG_Table_Value(void)			{}
+	virtual ~CSG_Table_Value(void)	{}
+
+	virtual bool				Set_Value		(const SG_Char *Value)		= 0;
+	virtual bool				Set_Value		(double         Value)		= 0;
+
+	virtual bool				Set_NoData		(void)						= 0;
+	virtual bool				is_NoData		(void)				const	= 0;
+
+	virtual const SG_Char *		asString		(int Decimals = -1)	const	= 0;
+	virtual int					asInt			(void)				const	= 0;
+	virtual double				asDouble		(void)				const	= 0;
+
+	operator const SG_Char *					(void)				const	{	return( asString() );	}
+	operator double								(void)				const	{	return( asDouble() );	}
+
+	virtual CSG_Table_Value &	operator = (const SG_Char         *Value)	{	Set_Value(Value);	return( *this );	}
+	virtual CSG_Table_Value &	operator = (double                 Value)	{	Set_Value(Value);	return( *this );	}
+	virtual CSG_Table_Value &	operator = (const CSG_Table_Value &Value)	= 0;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Table_Value_String : public CSG_Table_Value
+{
+public:
+	CSG_Table_Value_String(void) {}
+	virtual ~CSG_Table_Value_String(void) {}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(const SG_Char *Value)
+	{
+		if( Value && m_Value.Cmp(Value) )
+		{
+			m_Value.Printf(Value);
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(double      Value)
+	{
+		CSG_String	s;
+
+		s.Printf(SG_T("%f"), Value);
+
+		return( Set_Value(s.c_str()) );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_NoData		(void)						{	return( Set_Value(NODATA_STRING) );			}
+	virtual bool				is_NoData		(void)				const	{	return( m_Value.Cmp(NODATA_STRING) == 0 );	}
+
+	//-----------------------------------------------------
+	virtual const SG_Char *		asString		(int Decimals = -1)	const	{	return( m_Value );				}
+	virtual int					asInt			(void)				const	{	return( m_Value.asInt() );		}
+	virtual double				asDouble		(void)				const	{	return( m_Value.asDouble() );	}
+
+	virtual CSG_Table_Value &	operator = (const CSG_Table_Value &Value)	{	Set_Value(Value.asString());	return( *this );	}
+
+
+private:
+
+	CSG_String					m_Value;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Table_Value_Date : public CSG_Table_Value
+{
+public:
+	CSG_Table_Value_Date(void) {	Set_Value(SG_T("0"));	}
+	virtual ~CSG_Table_Value_Date(void) {}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(const SG_Char *Value)
+	{
+		return( Set_Value(SG_Date_To_Double(Value)) );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(double      Value)
+	{
+		if( m_Value != (int)Value )
+		{
+			m_Date	= SG_Double_To_Date(Value);
+			m_Value	= (int)Value;
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_NoData		(void)						{	return( Set_Value(NODATA_INT) );	}
+	virtual bool				is_NoData		(void)				const	{	return( m_Value == NODATA_INT );	}
+
+	//-----------------------------------------------------
+	virtual const SG_Char *		asString		(int Decimals = -1)	const	{	return( m_Date );	}
+	virtual int					asInt			(void)				const	{	return( m_Value );	}
+	virtual double				asDouble		(void)				const	{	return( m_Value );	}
+
+	virtual CSG_Table_Value &	operator = (const CSG_Table_Value &Value)	{	Set_Value(Value.asString());	return( *this );	}
+
+
+private:
+
+	int							m_Value;
+
+	CSG_String					m_Date;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Table_Value_Int : public CSG_Table_Value
+{
+public:
+	CSG_Table_Value_Int(void)	{	m_Value	= 0;	}
+	virtual ~CSG_Table_Value_Int(void) {}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(const SG_Char *Value)
+	{
+		double		d;
+		CSG_String	s(Value);
+
+		return( s.asDouble(d) ? Set_Value(d) : false );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(double      Value)
+	{
+		if( m_Value != Value )
+		{
+			m_Value	= (int)Value;
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_NoData		(void)						{	return( Set_Value(NODATA_INT) );	}
+	virtual bool				is_NoData		(void)				const	{	return( m_Value == NODATA_INT );	}
+
+	//-----------------------------------------------------
+	virtual const SG_Char *		asString		(int Decimals = -1)	const
+	{
+		static CSG_String	s;
+
+		s.Printf(SG_T("%d"), m_Value);
+
+		return( s.c_str() );
+	}
+
+	//-----------------------------------------------------
+	virtual int					asInt			(void)				const	{	return( m_Value );	}
+	virtual double				asDouble		(void)				const	{	return( m_Value );	}
+
+	virtual CSG_Table_Value &	operator = (const CSG_Table_Value &Value)	{	Set_Value(Value.asInt());	return( *this );	}
+
+
+private:
+
+	int							m_Value;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSG_Table_Value_Double : public CSG_Table_Value
+{
+public:
+	CSG_Table_Value_Double(void) {	m_Value	= 0.0;	}
+	virtual ~CSG_Table_Value_Double(void) {}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(const SG_Char *Value)
+	{
+		double		d;
+		CSG_String	s(Value);
+
+		return( s.asDouble(d) ? Set_Value(d) : false );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_Value		(double      Value)
+	{
+		if( m_Value != Value )
+		{
+			m_Value	= Value;
+
+			return( true );
+		}
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	virtual bool				Set_NoData		(void)						{	return( Set_Value(NODATA_DOUBLE) );	}
+	virtual bool				is_NoData		(void)				const	{	return( m_Value == NODATA_DOUBLE );	}
+
+	//-----------------------------------------------------
+	virtual const SG_Char *		asString		(int Decimals = -1)	const
+	{
+		static CSG_String	s;
+
+		s	= SG_Get_String(m_Value, Decimals, false);
+
+		return( s.c_str() );
+	}
+
+	//-----------------------------------------------------
+	virtual int					asInt			(void)				const	{	return( (int)m_Value );	}
+	virtual double				asDouble		(void)				const	{	return( m_Value );		}
+
+	virtual CSG_Table_Value &	operator = (const CSG_Table_Value &Value)	{	Set_Value(Value.asDouble());	return( *this );	}
+
+
+private:
+
+	double						m_Value;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__table_value_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,514 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       tin.cpp                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "tin.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_TIN * SG_Create_TIN(void)
+{
+	return( new CSG_TIN );
+}
+
+//---------------------------------------------------------
+CSG_TIN * SG_Create_TIN(const CSG_TIN &TIN)
+{
+	return( new CSG_TIN(TIN) );
+}
+
+//---------------------------------------------------------
+CSG_TIN * SG_Create_TIN(const CSG_String &File_Name)
+{
+	return( new CSG_TIN(File_Name) );
+}
+
+//---------------------------------------------------------
+CSG_TIN * SG_Create_TIN(CSG_Shapes *pShapes)
+{
+	return( new CSG_TIN(pShapes) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_TIN::CSG_TIN(void)
+	: CSG_Table()
+{
+	_On_Construction();
+}
+
+//---------------------------------------------------------
+CSG_TIN::CSG_TIN(const CSG_TIN &TIN)
+	: CSG_Table()
+{
+	_On_Construction();
+
+	Create(TIN);
+}
+
+//---------------------------------------------------------
+CSG_TIN::CSG_TIN(const CSG_String &File_Name)
+	: CSG_Table()
+{
+	_On_Construction();
+
+	Create(File_Name);
+}
+
+//---------------------------------------------------------
+CSG_TIN::CSG_TIN(CSG_Shapes *pShapes)
+	: CSG_Table()
+{
+	_On_Construction();
+
+	Create(pShapes);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSG_TIN::_On_Construction(void)
+{
+	CSG_Table::_On_Construction();
+
+	m_Edges				= NULL;
+	m_nEdges			= 0;
+
+	m_Triangles			= NULL;
+	m_nTriangles		= 0;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::Create(const CSG_TIN &TIN)
+{
+	return( Assign((CSG_Data_Object *)&TIN) );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::Create(const CSG_String &File_Name)
+{
+	CSG_Shapes	Shapes(File_Name);
+
+	if( Create(&Shapes) )
+	{
+		Get_History().Add_Child(LNG("[HST] Created from file"), File_Name);
+		Get_History()	+= Shapes.Get_History();
+
+		Set_File_Name(File_Name);
+		Set_Modified(false);
+		Set_Update_Flag();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::Create(CSG_Shapes *pShapes)
+{
+	Destroy();
+
+	if( pShapes && pShapes->is_Valid() )
+	{
+		SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Create TIN from shapes"), pShapes->Get_Name()), true);
+
+		_Create(pShapes);
+
+		Set_Name(pShapes->Get_Name());
+
+		//-------------------------------------------------
+		for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
+		{
+			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);
+
+			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					Add_Node(pShape->Get_Point(iPoint, iPart), pShape, false);
+				}
+			}
+		}
+
+		SG_UI_Process_Set_Ready();
+
+		if( Update() )
+		{
+			SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
+
+			return( true );
+		}
+	}
+
+	SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_TIN::~CSG_TIN(void)
+{
+	Destroy();
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::Destroy(void)
+{
+	_Destroy_Triangles();
+	_Destroy_Edges();
+	_Destroy_Nodes();
+
+	CSG_Table::Destroy();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::_Destroy_Nodes(void)
+{
+	return( Del_Records() );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::_Destroy_Edges(void)
+{
+	if( m_nEdges > 0 )
+	{
+		for(int i=0; i<m_nEdges; i++)
+		{
+			delete(m_Edges[i]);
+		}
+
+		SG_Free(m_Edges);
+		m_Edges			= NULL;
+		m_nEdges		= 0;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::_Destroy_Triangles(void)
+{
+	if( m_nTriangles > 0 )
+	{
+		for(int i=0; i<m_nTriangles; i++)
+		{
+			delete(m_Triangles[i]);
+		}
+
+		SG_Free(m_Triangles);
+		m_Triangles		= NULL;
+		m_nTriangles	= 0;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::Assign(CSG_Data_Object *pObject)
+{
+	if(	pObject && pObject->is_Valid() && pObject->Get_ObjectType() == Get_ObjectType() )
+	{
+		CSG_TIN	*pTIN	= (CSG_TIN *)pObject;
+
+		Destroy();
+
+		_Create(pTIN);
+
+		Set_Name(pTIN->Get_Name());
+
+		Get_History()	= pTIN->Get_History();
+
+		//-------------------------------------------------
+		for(int iNode=0; iNode<pTIN->Get_Node_Count(); iNode++)
+		{
+			CSG_TIN_Node	*pNode	= pTIN->Get_Node(iNode);
+
+			Add_Node(pNode->Get_Point(), pNode, false);
+		}
+
+		//-------------------------------------------------
+		for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++)
+		{
+			CSG_TIN_Triangle	*pTriangle	= pTIN->Get_Triangle(iTriangle);
+
+			_Add_Triangle(
+				Get_Node(pTriangle->Get_Node(0)->Get_Index()),
+				Get_Node(pTriangle->Get_Node(1)->Get_Index()),
+				Get_Node(pTriangle->Get_Node(2)->Get_Index())
+			);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::Save(const CSG_String &File_Name, int Format)
+{
+	bool	bResult	= false;
+
+	if( Get_Triangle_Count() > 0 )
+	{
+		switch( Format )
+		{
+		case 0:	default:
+			{
+				CSG_Shapes	Points;
+
+				Points.Create(SHAPE_TYPE_Point, Get_Name(), this);
+
+				for(int i=0; i<Get_Node_Count(); i++)
+				{
+					CSG_TIN_Node	*pNode	= Get_Node(i);
+
+					Points.Add_Shape(pNode)->Add_Point(pNode->Get_Point());
+				}
+
+				bResult	= Points.Save(File_Name);
+			}
+			break;
+		}
+	}
+
+	if( bResult )
+	{
+		Set_Modified(false);
+
+		Set_File_Name(File_Name);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Table_Record * CSG_TIN::_Get_New_Record(int Index)
+{
+	return( new CSG_TIN_Node(this, Index) );
+}
+
+//---------------------------------------------------------
+CSG_TIN_Node * CSG_TIN::Add_Node(TSG_Point Point, CSG_Table_Record *pRecord, bool bUpdateNow)
+{
+	CSG_TIN_Node	*pNode	= (CSG_TIN_Node *)Add_Record(pRecord);
+
+	if( pNode )
+	{
+		pNode->m_Point	= Point;
+
+		if( bUpdateNow )
+		{
+			Update();
+		}
+	}
+
+	return( pNode );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::Del_Node(int iNode, bool bUpdateNow)
+{
+	if( Del_Record(iNode) )
+	{
+		if( bUpdateNow )
+		{
+			Update();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline bool CSG_TIN::_Add_Edge(CSG_TIN_Node *a, CSG_TIN_Node *b)
+{
+	m_Edges		= (CSG_TIN_Edge **)SG_Realloc(m_Edges, (m_nEdges + 1) * sizeof(CSG_TIN_Edge *));
+	m_Edges[m_nEdges++]	= new CSG_TIN_Edge(a, b);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN::_Add_Triangle(CSG_TIN_Node *a, CSG_TIN_Node *b, CSG_TIN_Node *c)
+{
+	CSG_TIN_Triangle	*pTriangle;
+
+	m_Triangles	= (CSG_TIN_Triangle **)SG_Realloc(m_Triangles, (m_nTriangles + 1) * sizeof(CSG_TIN_Triangle *));
+	m_Triangles[m_nTriangles++]	= pTriangle = new CSG_TIN_Triangle(a, b, c);
+
+	if( a->_Add_Neighbor(b) )
+	{
+		b->_Add_Neighbor(a);
+		_Add_Edge(a, b);
+	}
+
+	if( b->_Add_Neighbor(c) )
+	{
+		c->_Add_Neighbor(b);
+		_Add_Edge(b, c);
+	}
+
+	if( c->_Add_Neighbor(a) )
+	{
+		a->_Add_Neighbor(c);
+		_Add_Edge(c, a);
+	}
+
+	a->_Add_Triangle(pTriangle);
+	b->_Add_Triangle(pTriangle);
+	c->_Add_Triangle(pTriangle);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::On_Update(void)
+{
+	return( _Triangulate() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/tin.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,327 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        tin.h                          //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_API__tin_H
+#define HEADER_INCLUDED__SAGA_API__tin_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_TIN_Node : public CSG_Table_Record
+{
+	friend class CSG_TIN;
+
+public:
+
+	int							Get_ID					(void)			{	return( m_ID );			}
+
+	const TSG_Point &			Get_Point				(void)			{	return( m_Point );		}
+	double						Get_X					(void)			{	return( m_Point.x );	}
+	double						Get_Y					(void)			{	return( m_Point.y );	}
+
+	int							Get_Neighbor_Count		(void)			{	return( m_nNeighbors );	}
+	CSG_TIN_Node *				Get_Neighbor			(int iNeighbor)	{	return( iNeighbor >= 0 && iNeighbor < m_nNeighbors ? m_Neighbors[iNeighbor] : NULL );	}
+	double						Get_Gradient			(int iNeighbor, int iField);
+
+	int							Get_Triangle_Count		(void)			{	return( m_nTriangles );	}
+	class CSG_TIN_Triangle *	Get_Triangle			(int iTriangle)	{	return( iTriangle >= 0 && iTriangle < m_nTriangles ? m_Triangles[iTriangle] : NULL );	}
+
+	bool						Get_Polygon				(CSG_Points &Points);
+	double						Get_Polygon_Area		(void);
+
+
+private:
+
+	CSG_TIN_Node(CSG_TIN *pOwner, int Index);
+	virtual ~CSG_TIN_Node(void);
+
+
+	int							m_ID, m_nNeighbors, m_nTriangles;
+
+	TSG_Point					m_Point;
+
+	CSG_TIN_Node				**m_Neighbors;
+
+	class CSG_TIN_Triangle		**m_Triangles;
+
+
+	bool						_Add_Neighbor			(CSG_TIN_Node *pNeighbor);
+	bool						_Add_Triangle			(class CSG_TIN_Triangle *pTriangle);
+
+	bool						_Del_Relations			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_TIN_Edge
+{
+	friend class CSG_TIN;
+
+public:
+
+	CSG_TIN_Node *				Get_Node				(int iNode)	{	return( m_Nodes[iNode % 2] );	}
+
+
+private:
+
+	CSG_TIN_Edge(CSG_TIN_Node *a, CSG_TIN_Node *b);
+	virtual ~CSG_TIN_Edge(void);
+
+
+	CSG_TIN_Node				*m_Nodes[2];
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_TIN_Triangle
+{
+	friend class CSG_TIN;
+
+public:
+
+	CSG_TIN_Node *				Get_Node				(int iNode)		{	return( m_Nodes[iNode % 3] );	}
+
+	const CSG_Rect &			Get_Extent				(void)			{	return( m_Extent );	}
+
+	double						Get_Area				(void)			{	return( m_Area );	}
+
+	bool						is_Containing			(const TSG_Point &Point);
+	bool						is_Containing			(double x, double y);
+
+	bool						Get_Gradient			(int zField, double &Decline, double &Azimuth);
+
+	void						Get_CircumCircle		(TSG_Point &Point, double &Radius)	{	Point	= m_Center;	Radius	= m_Radius;	}
+	double						Get_CircumCircle_Radius	(void)			{	return( m_Radius );	}
+	TSG_Point					Get_CircumCircle_Point	(void)			{	return( m_Center );	}
+
+
+private:
+
+	CSG_TIN_Triangle(CSG_TIN_Node *a, CSG_TIN_Node *b, CSG_TIN_Node *c);
+	virtual ~CSG_TIN_Triangle(void);
+
+
+	double						m_Area, m_Radius;
+
+	TSG_Point					m_Center;
+
+	CSG_Rect					m_Extent;
+
+	CSG_TIN_Node				*m_Nodes[3];
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SAGA_API_DLL_EXPORT CSG_TIN : public CSG_Table
+{
+public:
+
+	CSG_TIN(void);
+
+									CSG_TIN		(const CSG_TIN &TIN);
+	bool							Create		(const CSG_TIN &TIN);
+
+									CSG_TIN		(CSG_Shapes *pShapes);
+	bool							Create		(CSG_Shapes *pShapes);
+
+									CSG_TIN		(const CSG_String &File_Name);
+	bool							Create		(const CSG_String &File_Name);
+
+	virtual ~CSG_TIN(void);
+
+	virtual bool					Destroy					(void);
+
+	virtual TSG_Data_Object_Type	Get_ObjectType			(void)	const			{	return( DATAOBJECT_TYPE_TIN );	}
+
+	virtual bool					Assign					(CSG_Data_Object *pObject);
+
+	virtual bool					Save					(const CSG_String &File_Name, int Format = 0);
+
+	virtual bool					is_Valid				(void)	const			{	return( Get_Count() >= 3 );	}
+
+	const CSG_Rect &				Get_Extent				(void)					{	Update();	return( m_Extent );	}
+
+
+	//-----------------------------------------------------
+	CSG_TIN_Node *					Add_Node				(TSG_Point Point, CSG_Table_Record *pRecord, bool bUpdateNow);
+	bool							Del_Node				(int iNode, bool bUpdateNow);
+
+	int								Get_Node_Count			(void)		const	{	return( Get_Count() );	}
+	CSG_TIN_Node *					Get_Node				(int Index)	const	{	return( (CSG_TIN_Node *)Get_Record(Index) );	}
+
+	int								Get_Edge_Count			(void)		const	{	return( m_nEdges );		}
+	CSG_TIN_Edge *					Get_Edge				(int Index)	const	{	return( Index >= 0 && Index < m_nEdges     ? m_Edges[Index]     : NULL );	}
+
+	int								Get_Triangle_Count		(void)		const	{	return( m_nTriangles );	}
+	CSG_TIN_Triangle *				Get_Triangle			(int Index)	const	{	return( Index >= 0 && Index < m_nTriangles ? m_Triangles[Index] : NULL );	}
+
+
+protected:
+
+	typedef struct
+	{
+		int							p1, p2;
+	}
+	TTIN_Edge;
+
+	typedef struct
+	{
+		int							p1, p2, p3;
+	}
+	TTIN_Triangle;
+
+
+protected:
+
+	int								m_nEdges, m_nTriangles;
+
+	CSG_Rect						m_Extent;
+
+	CSG_TIN_Edge					**m_Edges;
+
+	CSG_TIN_Triangle				**m_Triangles;
+
+
+	void							_On_Construction		(void);
+
+	virtual CSG_Table_Record *		_Get_New_Record			(int Index);
+
+	virtual bool					On_Update				(void);
+
+	bool							_Destroy_Nodes			(void);
+	bool							_Destroy_Edges			(void);
+	bool							_Destroy_Triangles		(void);
+
+	bool							_Add_Edge				(CSG_TIN_Node *a, CSG_TIN_Node *b);
+	bool							_Add_Triangle			(CSG_TIN_Node *a, CSG_TIN_Node *b, CSG_TIN_Node *c);
+
+	bool							_Triangulate			(void);
+	bool							_Triangulate			(CSG_TIN_Node **Nodes, int nNodes, TTIN_Triangle *Triangles, int &nTriangles);
+	int								_CircumCircle			(double xp, double yp, double x1, double y1, double x2, double y2, double x3, double y3, double *xc, double *yc, double *r);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+/** Safe TIN construction */
+SAGA_API_DLL_EXPORT CSG_TIN *	SG_Create_TIN			(void);
+
+/** Safe TIN construction */
+SAGA_API_DLL_EXPORT CSG_TIN *	SG_Create_TIN			(const CSG_TIN &TIN);
+
+/** Safe TIN construction */
+SAGA_API_DLL_EXPORT CSG_TIN *	SG_Create_TIN			(CSG_Shapes *pShapes);
+
+/** Safe TIN construction */
+SAGA_API_DLL_EXPORT CSG_TIN *	SG_Create_TIN			(const CSG_String &File_Name);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_API__tin_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_elements.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_elements.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_elements.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,423 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  tin_elements.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "tin.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_TIN_Node::CSG_TIN_Node(CSG_TIN *pOwner, int Index)
+	: CSG_Table_Record(pOwner, Index)
+{
+	m_Point.x		= m_Point.y	= 0.0;
+
+	m_Neighbors		= NULL;
+	m_nNeighbors	= 0;
+
+	m_Triangles		= NULL;
+	m_nTriangles	= 0;
+}
+
+//---------------------------------------------------------
+CSG_TIN_Node::~CSG_TIN_Node(void)
+{
+	_Del_Relations();
+}
+
+//---------------------------------------------------------
+bool CSG_TIN_Node::_Add_Triangle(CSG_TIN_Triangle *pTriangle)
+{
+	for(int i=0; i<m_nTriangles; i++)
+	{
+		if( m_Triangles[i] == pTriangle )
+		{
+			return( false );
+		}
+	}
+
+	m_Triangles	= (CSG_TIN_Triangle **)SG_Realloc(m_Triangles, (m_nTriangles + 1) * sizeof(CSG_TIN_Triangle *));
+	m_Triangles[m_nTriangles++]	= pTriangle;
+
+//	_Add_Neighbor(pTriangle->Get_Point(0));
+//	_Add_Neighbor(pTriangle->Get_Point(1));
+//	_Add_Neighbor(pTriangle->Get_Point(2));
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN_Node::_Add_Neighbor(CSG_TIN_Node *pNeighbor)
+{
+	if( pNeighbor == this )
+	{
+		return( false );
+	}
+
+	for(int i=0; i<m_nNeighbors; i++)
+	{
+		if( m_Neighbors[i] == pNeighbor )
+		{
+			return( false );
+		}
+	}
+
+	m_Neighbors	= (CSG_TIN_Node **)SG_Realloc(m_Neighbors, (m_nNeighbors + 1) * sizeof(CSG_TIN_Node *));
+	m_Neighbors[m_nNeighbors++]	= pNeighbor;
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN_Node::_Del_Relations(void)
+{
+	if( m_nTriangles > 0 )
+	{
+		SG_Free(m_Triangles);
+		m_Triangles		= NULL;
+		m_nTriangles	= 0;
+	}
+
+	if( m_nNeighbors > 0 )
+	{
+		SG_Free(m_Neighbors);
+		m_Neighbors		= NULL;
+		m_nNeighbors	= 0;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+double CSG_TIN_Node::Get_Gradient(int iNeighbor, int iField)
+{
+	double		dx, dy, dz;
+	CSG_TIN_Node	*pNeighbor;
+
+	if( (pNeighbor = Get_Neighbor(iNeighbor)) != NULL )
+	{
+		dx	= Get_X() - pNeighbor->Get_X();
+		dy	= Get_Y() - pNeighbor->Get_Y();
+		dz	= asDouble(iField) - pNeighbor->asDouble(iField);
+
+		if( (dx = sqrt(dx*dx + dy*dy)) > 0.0 )
+		{
+			return( dz / dx );
+		}
+	}
+
+	return( 0.0 );
+}
+
+//---------------------------------------------------------
+int SG_TIN_Compare_Triangle_Center(const void *pz1, const void *pz2)
+{
+	double	z1	= ((TSG_Point_3D *)pz1)->z,
+			z2	= ((TSG_Point_3D *)pz2)->z;
+
+	if( z1 < z2 )
+	{
+		return( -1 );
+	}
+
+	if( z1 > z2 )
+	{
+		return(  1 );
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+#define M_GET_DIRECTION(a, b)	(b.x != a.x ? M_PI_180 - atan2(b.y - a.y, b.x - a.x) : (b.y > a.y ? M_PI_270 : (b.y < a.y ? M_PI_090 : 0.0)))
+
+//---------------------------------------------------------
+bool CSG_TIN_Node::Get_Polygon(CSG_Points &Points)
+{
+	if( m_nTriangles >= 3 )
+	{
+		int				i;
+		TSG_Point		c;
+		CSG_Points_3D	p;
+
+		for(i=0; i<m_nTriangles; i++)
+		{
+			c	= m_Triangles[i]->Get_CircumCircle_Point();
+
+			p.Add(c.x, c.y, M_GET_DIRECTION(m_Point, c));
+		}
+
+		qsort(&(p[0]), p.Get_Count(), sizeof(TSG_Point_3D), SG_TIN_Compare_Triangle_Center);
+
+		Points.Clear();
+
+		for(i=0; i<m_nTriangles; i++)
+		{
+			Points.Add(p[i].x, p[i].y);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+double CSG_TIN_Node::Get_Polygon_Area(void)
+{
+	CSG_Points	Points;
+
+	if( Get_Polygon(Points) )
+	{
+		return( SG_Get_Polygon_Area(Points) );
+	}
+
+	return( 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_TIN_Edge::CSG_TIN_Edge(CSG_TIN_Node *a, CSG_TIN_Node *b)
+{
+	m_Nodes[0]		= a;
+	m_Nodes[1]		= b;
+}
+
+//---------------------------------------------------------
+CSG_TIN_Edge::~CSG_TIN_Edge(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_TIN_Triangle::CSG_TIN_Triangle(CSG_TIN_Node *a, CSG_TIN_Node *b, CSG_TIN_Node *c)
+{
+	m_Nodes[0]		= a;
+	m_Nodes[1]		= b;
+	m_Nodes[2]		= c;
+
+	//-----------------------------------------------------
+	double	xMin, yMin, xMax, yMax;
+
+	xMin	= xMax	= a->Get_X();
+	yMin	= yMax	= a->Get_Y();
+
+	if(			xMin	> b->Get_X() )
+				xMin	= b->Get_X();
+	else if(	xMax	< b->Get_X() )
+				xMax	= b->Get_X();
+
+	if(			yMin	> b->Get_Y() )
+				yMin	= b->Get_Y();
+	else if(	yMax	< b->Get_Y() )
+				yMax	= b->Get_Y();
+
+	if(			xMin	> c->Get_X() )
+				xMin	= c->Get_X();
+	else if(	xMax	< c->Get_X() )
+				xMax	= c->Get_X();
+
+	if(			yMin	> c->Get_Y() )
+				yMin	= c->Get_Y();
+	else if(	yMax	< c->Get_Y() )
+				yMax	= c->Get_Y();
+
+	m_Extent.Assign(xMin, yMin, xMax, yMax);
+
+	//-----------------------------------------------------
+	m_Area	= fabs(	a->Get_X() * (b->Get_Y() - c->Get_Y())
+				+	b->Get_X() * (c->Get_Y() - a->Get_Y())
+				+	c->Get_X() * (a->Get_Y() - b->Get_Y())	) / 2.0;
+
+	//-----------------------------------------------------
+	TSG_Point	Points[3];
+
+	Points[0]	= m_Nodes[0]->Get_Point();
+	Points[1]	= m_Nodes[1]->Get_Point();
+	Points[2]	= m_Nodes[2]->Get_Point();
+
+	SG_Get_Triangle_CircumCircle(Points, m_Center, m_Radius);
+}
+
+//---------------------------------------------------------
+CSG_TIN_Triangle::~CSG_TIN_Triangle(void)
+{}
+
+
+//---------------------------------------------------------
+bool CSG_TIN_Triangle::is_Containing(const TSG_Point &Point)
+{
+	return( is_Containing(Point.x, Point.y) );
+}
+
+//---------------------------------------------------------
+#define IS_ONLINE(A, B)	(A.y == B.y && ((A.x <= x && x <= B.x) || (B.x <= x && x <= A.x)))
+
+//---------------------------------------------------------
+bool CSG_TIN_Triangle::is_Containing(double x, double y)
+{
+	if( m_Extent.Contains(x, y) )
+	{
+		int			nCrossings;
+		TSG_Point	A, B, C;
+
+		if(	(x == m_Nodes[0]->Get_Point().x && y == m_Nodes[0]->Get_Point().y)
+		||	(x == m_Nodes[1]->Get_Point().x && y == m_Nodes[1]->Get_Point().y)
+		||	(x == m_Nodes[2]->Get_Point().x && y == m_Nodes[2]->Get_Point().y) )
+			return( true );
+
+		if( y == m_Extent.Get_YMin() || y == m_Extent.Get_YMax() )
+		{
+			if(	IS_ONLINE(m_Nodes[0]->Get_Point(), m_Nodes[1]->Get_Point())
+			||	IS_ONLINE(m_Nodes[1]->Get_Point(), m_Nodes[2]->Get_Point())
+			||	IS_ONLINE(m_Nodes[2]->Get_Point(), m_Nodes[0]->Get_Point()) )
+				return( true );
+		}
+
+		nCrossings	= 0;
+
+		if(	(y == m_Nodes[0]->Get_Point().y && x > m_Nodes[0]->Get_Point().x)
+		||	(y == m_Nodes[1]->Get_Point().y && x > m_Nodes[1]->Get_Point().x)
+		||	(y == m_Nodes[2]->Get_Point().y && x > m_Nodes[2]->Get_Point().x) )
+			nCrossings	= -1;
+
+		A.x			= m_Extent.m_rect.xMin - 1.0;
+		B.x			= x;
+		A.y = B.y	= y;
+
+		if( SG_Get_Crossing(C, m_Nodes[0]->Get_Point(), m_Nodes[1]->Get_Point(), A, B) )
+			nCrossings++;
+
+		if( SG_Get_Crossing(C, m_Nodes[1]->Get_Point(), m_Nodes[2]->Get_Point(), A, B) )
+			nCrossings++;
+
+		if( SG_Get_Crossing(C, m_Nodes[2]->Get_Point(), m_Nodes[0]->Get_Point(), A, B) )
+			nCrossings++;
+
+		return( nCrossings == 1 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CSG_TIN_Triangle::Get_Gradient(int zField, double &Decline, double &Azimuth)
+{
+	int		i;
+	double	x[3], y[3], z[3], A, B, C;
+
+	for(i=0; i<3; i++)
+	{
+		x[i]	= m_Nodes[i]->Get_X();
+		y[i]	= m_Nodes[i]->Get_Y();
+		z[i]	= m_Nodes[i]->asDouble(zField);
+	}
+
+	A		= z[0] * (x[1] - x[2]) + z[1] * (x[2] - x[0]) + z[2] * (x[0] - x[1]);
+	B		= y[0] * (z[1] - z[2]) + y[1] * (z[2] - z[0]) + y[2] * (z[0] - z[1]);
+	C		= x[0] * (y[1] - y[2]) + x[1] * (y[2] - y[0]) + x[2] * (y[0] - y[1]);
+
+	if( C != 0.0 )
+	{
+		A		= - A / C;
+		B		= - B / C;
+
+		Decline	= atan(sqrt(A*A + B*B));
+
+		if( A != 0.0 )
+			Azimuth	= M_PI_180 + atan2(B, A);
+		else
+			Azimuth	= B > 0.0 ? M_PI_270 : (B < 0.0 ? M_PI_090 : -1.0);
+
+		return( true );
+	}
+
+	Decline	= -1.0;
+	Azimuth	= -1.0;
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_triangulation.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_triangulation.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_api/tin_triangulation.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,509 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_API                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                tin_triangulation.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'.                              //
+//                                                       //
+// This library is free software; you can redistribute   //
+// it and/or modify it under the terms of the GNU Lesser //
+// General Public License as published by the Free       //
+// Software Foundation, version 2.1 of the License.      //
+//                                                       //
+// This library is distributed in the hope that it will  //
+// be useful, but WITHOUT ANY WARRANTY; without even the //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU Lesser General Public //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU Lesser     //
+// General Public License along with this program; if    //
+// not, write to the Free Software Foundation, Inc.,     //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// The Delaunay Triangulation algorithm used here is based
+// on Paul Bourke's C source codes, which can be found at:
+//
+//     http://astronomy.swin.edu.au/~pbourke/
+//
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "tin.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int SG_TIN_Compare(const void *pp1, const void *pp2)
+{
+	CSG_TIN_Node	*p1	= *((CSG_TIN_Node **)pp1),
+					*p2	= *((CSG_TIN_Node **)pp2);
+
+	if( p1->Get_X() < p2->Get_X() )
+	{
+		return( -1 );
+	}
+
+	if( p1->Get_X() > p2->Get_X() )
+	{
+		return(  1 );
+	}
+
+	if( p1->Get_Y() < p2->Get_Y() )
+	{
+		return( -1 );
+	}
+
+	if( p1->Get_Y() > p2->Get_Y() )
+	{
+		return(  1 );
+	}
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::_Triangulate(void)
+{
+	bool			bResult;
+	int				i, j, n, nTriangles;
+	CSG_TIN_Node	**Nodes;
+	TTIN_Triangle	*Triangles;
+
+	//-----------------------------------------------------
+	_Destroy_Edges();
+	_Destroy_Triangles();
+
+	//-----------------------------------------------------
+	Nodes	= (CSG_TIN_Node **)SG_Malloc((Get_Node_Count() + 3) * sizeof(CSG_TIN_Node *));
+
+	for(i=0; i<Get_Node_Count(); i++)
+	{
+		Nodes[i]	= Get_Node(i);
+		Nodes[i]	->_Del_Relations();
+	}
+
+	//-----------------------------------------------------
+	qsort(Nodes, Get_Node_Count(), sizeof(CSG_TIN_Node *), SG_TIN_Compare);
+
+	for(i=0, j=0, n=Get_Node_Count(); j<n; i++)	// remove duplicates
+	{
+		Nodes[i]	= Nodes[j++];
+
+		while(	j < n
+			&&	Nodes[i]->Get_X() == Nodes[j]->Get_X()
+			&&	Nodes[i]->Get_Y() == Nodes[j]->Get_Y() )
+		{
+			Del_Node(Nodes[j++]->Get_Index(), false);
+		}
+	}
+
+	//-----------------------------------------------------
+	for(i=Get_Node_Count(); i<Get_Node_Count()+3; i++)
+	{
+		Nodes[i]	= new CSG_TIN_Node(this, 0);
+	}
+
+	//-----------------------------------------------------
+	Triangles	= (TTIN_Triangle *)SG_Malloc(3 * Get_Node_Count() * sizeof(TTIN_Triangle));
+
+	if( (bResult = _Triangulate(Nodes, Get_Node_Count(), Triangles, nTriangles)) == true )
+	{
+		for(i=0; i<nTriangles && SG_UI_Process_Set_Progress(i, nTriangles); i++)
+		{
+			_Add_Triangle(Nodes[Triangles[i].p1], Nodes[Triangles[i].p2], Nodes[Triangles[i].p3]);
+		}
+	}
+
+	SG_Free(Triangles);
+
+	//-----------------------------------------------------
+	for(i=Get_Node_Count(); i<Get_Node_Count()+3; i++)
+	{
+		delete(Nodes[i]);
+	}
+
+	SG_Free(Nodes);
+
+	SG_UI_Process_Set_Ready();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSG_TIN::_Triangulate(CSG_TIN_Node **Points, int nPoints, TTIN_Triangle *Triangles, int &nTriangles)
+{
+	int			i, j, k, inside, trimax,
+				nedge		= 0,
+				emax		= 200,
+				status		= 0,
+				*complete	= NULL;
+
+	double		dmax, xp, yp, x1, y1, x2, y2, x3, y3, xc, yc, r;
+
+	TTIN_Edge	*edges		= NULL;
+
+	//-----------------------------------------------------
+	// Update extent...
+	if( nPoints >= 3 )
+	{
+		TSG_Rect	r;
+
+		m_Extent.Assign(
+			Points[0]->Get_X(), Points[0]->Get_Y(),
+			Points[0]->Get_X(), Points[0]->Get_Y()
+		);
+
+		for(i=1; i<nPoints; i++)
+		{
+			r.xMin	= r.xMax	= Points[i]->Get_X();
+			r.yMin	= r.yMax	= Points[i]->Get_Y();
+
+			m_Extent.Union(r);
+		}
+	}
+	else
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	// Allocate memory for the completeness list, flag for each triangle
+	trimax	= 4 * nPoints;
+	if( (complete	= (int       *)SG_Malloc(trimax * sizeof(int))) == NULL )
+	{
+		status	= 1;
+		goto skip;
+	}
+
+	//-----------------------------------------------------
+	// Allocate memory for the edge list
+	if( (edges		= (TTIN_Edge *)SG_Malloc(emax   * sizeof(TTIN_Edge))) == NULL )
+	{
+		status	= 2;
+		goto skip;
+	}
+
+	//-----------------------------------------------------
+	//	Find the maximum and minimum vertex bounds.
+	//	This is to allow calculation of the bounding triangle
+	//	Set up the supertriangle
+	//	This is a triangle which encompasses all the sample points.
+	//	The supertriangle coordinates are added to the end of the
+	//	vertex list. The supertriangle is the first triangle in
+	//	the triangle list.
+
+	dmax	= m_Extent.Get_XRange() > m_Extent.Get_YRange() ? m_Extent.Get_XRange() : m_Extent.Get_YRange();
+
+	Points[nPoints + 0]->m_Point.x	= m_Extent.Get_XCenter() - 20 * dmax;
+	Points[nPoints + 1]->m_Point.x	= m_Extent.Get_XCenter();
+	Points[nPoints + 2]->m_Point.x	= m_Extent.Get_XCenter() + 20 * dmax;
+
+	Points[nPoints + 0]->m_Point.y	= m_Extent.Get_YCenter() -      dmax;
+	Points[nPoints + 1]->m_Point.y	= m_Extent.Get_YCenter() + 20 * dmax;
+	Points[nPoints + 2]->m_Point.y	= m_Extent.Get_YCenter() -      dmax;
+
+	Triangles[0].p1	= nPoints;
+	Triangles[0].p2	= nPoints + 1;
+	Triangles[0].p3	= nPoints + 2;
+
+	complete [0]	= false;
+
+	nTriangles		= 1;
+
+	//-----------------------------------------------------
+	//	Include each point one at a time into the existing mesh
+	for(i=0; i<nPoints && SG_UI_Process_Set_Progress(i, nPoints); i++)
+	{
+		xp		= Points[i]->Get_X();
+		yp		= Points[i]->Get_Y();
+		nedge	= 0;
+
+		//-------------------------------------------------
+		//	Set up the edge buffer.
+		//	If the point (xp,yp) lies inside the circumcircle then the
+		//	three edges of that triangle are added to the edge buffer
+		//	and that triangle is removed.
+		for(j=0; j<nTriangles; j++)
+		{
+			if( complete[j] )
+			{
+				continue;
+			}
+
+			x1		= Points[Triangles[j].p1]->Get_X();
+			y1		= Points[Triangles[j].p1]->Get_Y();
+			x2		= Points[Triangles[j].p2]->Get_X();
+			y2		= Points[Triangles[j].p2]->Get_Y();
+			x3		= Points[Triangles[j].p3]->Get_X();
+			y3		= Points[Triangles[j].p3]->Get_Y();
+
+			inside	= _CircumCircle(xp, yp, x1, y1, x2, y2, x3, y3, &xc, &yc, &r);
+
+			if( xc + r < xp )
+			{
+				complete[j]	= true;
+			}
+
+			if( inside )
+			{
+				// Check that we haven't exceeded the edge list size
+				if( nedge + 3 >= emax )
+				{
+					emax	+= 100;
+
+					if( (edges = (TTIN_Edge *)SG_Realloc(edges, emax * sizeof(TTIN_Edge))) == NULL )
+					{
+						status	= 3;
+						goto skip;
+					}
+				}
+
+				edges[nedge + 0].p1	= Triangles[j].p1;
+				edges[nedge + 0].p2	= Triangles[j].p2;
+				edges[nedge + 1].p1	= Triangles[j].p2;
+				edges[nedge + 1].p2	= Triangles[j].p3;
+				edges[nedge + 2].p1	= Triangles[j].p3;
+				edges[nedge + 2].p2	= Triangles[j].p1;
+
+				nedge	+= 3;
+
+				Triangles[j]	= Triangles[nTriangles - 1];
+				complete [j]	= complete [nTriangles - 1];
+
+				nTriangles--;
+				j--;
+			}
+		}
+
+		//-------------------------------------------------
+		//	Tag multiple edges
+		//	Note: if all triangles are specified anticlockwise then all
+		//	      interior edges are opposite pointing in direction.
+		for(j=0; j<nedge-1; j++)
+		{
+			for(k=j+1; k<nedge; k++)
+			{
+				if( (edges[j].p1 == edges[k].p2) && (edges[j].p2 == edges[k].p1) )
+				{
+					edges[j].p1 = -1;
+					edges[j].p2 = -1;
+					edges[k].p1 = -1;
+					edges[k].p2 = -1;
+				}
+
+				// Shouldn't need the following, see note above
+				if( (edges[j].p1 == edges[k].p1) && (edges[j].p2 == edges[k].p2) )
+				{
+					edges[j].p1 = -1;
+					edges[j].p2 = -1;
+					edges[k].p1 = -1;
+					edges[k].p2 = -1;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		//	Form new triangles for the current point
+		//	Skipping over any tagged edges.
+		//	All edges are arranged in clockwise order.
+		for(j=0; j<nedge; j++)
+		{
+			if( edges[j].p1 < 0 || edges[j].p2 < 0 )
+			{
+				continue;
+			}
+
+			if( nTriangles >= trimax )
+			{
+				status	= 4;
+				goto skip;
+			}
+
+			Triangles[nTriangles].p1	= edges[j].p1;
+			Triangles[nTriangles].p2	= edges[j].p2;
+			Triangles[nTriangles].p3	= i;
+			complete [nTriangles]		= false;
+			nTriangles++;
+		}
+	}
+
+	//-----------------------------------------------------
+	//	Remove triangles with supertriangle vertices
+	//	These are triangles which have a vertex number greater than nPoints
+	for(i=0; i<nTriangles; i++)
+	{
+		if(	Triangles[i].p1 >= nPoints
+		||	Triangles[i].p2 >= nPoints
+		||	Triangles[i].p3 >= nPoints )
+		{
+			Triangles[i] = Triangles[nTriangles - 1];
+			nTriangles--;
+			i--;
+		}
+	}
+
+	//-----------------------------------------------------
+	skip:
+
+	if( edges )
+	{
+		SG_Free(edges);
+	}
+
+	if( complete )
+	{
+		SG_Free(complete);
+	}
+
+	return( status == 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+//	Return true if a point (xp,yp) is inside the circumcircle made up
+//	of the points (x1,y1), (x2,y2), (x3,y3)
+//	The circumcircle centre is returned in (xc,yc) and the radius r
+//	NOTE: A point on the edge is inside the circumcircle
+//
+
+//---------------------------------------------------------
+#define IS_IDENTICAL(a, b)	(a == b)
+//#define IS_IDENTICAL(a, b)	(fabs(a - b) < 0.0001)
+
+//---------------------------------------------------------
+int CSG_TIN::_CircumCircle(double xp, double yp, double x1, double y1, double x2, double y2, double x3, double y3, double *xc, double *yc, double *r)
+{
+	double	m1, m2, mx1, mx2, my1, my2,
+			dx, dy, rsqr, drsqr;
+
+	// Check for coincident points
+	if( IS_IDENTICAL(y1, y2) && IS_IDENTICAL(y2, y3) )
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( IS_IDENTICAL(y2, y1) )
+	{
+		m2	= -(x3 - x2) / (y3 - y2);
+		mx2	=  (x2 + x3) / 2.0;
+		my2	=  (y2 + y3) / 2.0;
+		*xc	=  (x2 + x1) / 2.0;
+
+		*yc	= m2 * (*xc - mx2) + my2;
+	}
+	else if( IS_IDENTICAL(y3, y2) )
+	{
+		m1	= -(x2 - x1) / (y2 - y1);
+		mx1	=  (x1 + x2) / 2.0;
+		my1	=  (y1 + y2) / 2.0;
+		*xc	=  (x3 + x2) / 2.0;
+
+		*yc	= m1 * (*xc - mx1) + my1;
+	}
+	else
+	{
+		m1	= -(x2 - x1) / (y2 - y1);
+		m2	= -(x3 - x2) / (y3 - y2);
+		mx1	=  (x1 + x2) / 2.0;
+		mx2	=  (x2 + x3) / 2.0;
+		my1	=  (y1 + y2) / 2.0;
+		my2	=  (y2 + y3) / 2.0;
+
+		*xc	= (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2);
+		*yc	= m1 * (*xc - mx1) + my1;
+	}
+
+	//-----------------------------------------------------
+	dx		= x2 - *xc;
+	dy		= y2 - *yc;
+	rsqr	= dx*dx + dy*dy;
+	*r		= sqrt(rsqr);
+
+	dx		= xp - *xc;
+	dy		= yp - *yc;
+	drsqr	= dx*dx + dy*dy;
+
+	return( drsqr <= rsqr ? 1 : 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,415 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                   Program: SAGA_CMD                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Callback.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/utils.h>
+
+#include "callback.h"
+
+#include "module_library.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+static bool				g_bSilent	= false;
+
+static CModule_Library	*g_pLibrary	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int		Callback(TSG_UI_Callback_ID ID, long Param_1, long Param_2)
+{
+	static int	iBuisy		= 0;
+
+	const SG_Char	Buisy[4]	= {	'|', '/', '-', '\\'	};
+
+	int		Result;
+	double	d1, d2;
+
+	Result	= 1;
+
+	//-----------------------------------------------------
+	switch( ID )
+	{
+	default:
+
+		Result	= 0;
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_GET_OKAY:
+
+		if( Param_1 != 0 )
+		{
+			SG_PRINTF(SG_T("\r%c   "), Buisy[iBuisy++]);
+			iBuisy	%= 4;
+		}
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_OKAY:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_PROGRESS:
+
+		d1	= *((double *)Param_1);
+		d2	= *((double *)Param_2);
+
+		SG_PRINTF(SG_T("\r%3d%%"), d2 != 0.0 ? 1 + (int)(100.0 * d1 / d2) : 100);
+
+		break;
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_READY:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_TEXT:
+
+		SG_PRINTF(SG_T("\n%s\n"), (SG_Char *)Param_1);
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_MESSAGE_ADD:
+
+		SG_PRINTF(SG_T("\n%s\n"), (SG_Char *)Param_1);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_MESSAGE_ADD_ERROR:
+
+		SG_PRINTF(SG_T("\n%s: %s\n"), LNG("error"), (SG_Char *)Param_1);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_MESSAGE_ADD_EXECUTION:
+
+		SG_PRINTF(SG_T("\n%s\n"), (SG_Char *)Param_1);
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_MESSAGE:
+
+		SG_PRINTF(SG_T("\n%s: %s\n"), (const SG_Char *)Param_2, (const SG_Char *)Param_1);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_CONTINUE:
+
+		Result	= Get_YesNo((const SG_Char *)Param_2, (const SG_Char *)Param_1);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_ERROR:
+
+		Result	= Get_YesNo((const SG_Char *)Param_2, (const SG_Char *)Param_1);
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_CHECK:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_ADD:
+
+		Result	= 0;
+
+		if( g_pLibrary )
+		{
+			Result	= g_pLibrary->Add_DataObject((CSG_Data_Object *)Param_1) ? 1 : 0;
+		}
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_UPDATE:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_SHOW:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_COLORS_GET:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_COLORS_SET:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_PARAMS_GET:
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_PARAMS_SET:
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_PARAMETERS:
+
+		Result	= 0;
+
+		if( g_pLibrary )
+		{
+			Result	= g_pLibrary->Get_Parameters((CSG_Parameters *)Param_1) ? 1 : 0;
+		}
+
+		break;
+	}
+
+	return( Result );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_PFNC_UI_Callback	Get_Callback	(void)
+{
+	return( &Callback );
+}
+
+//---------------------------------------------------------
+void			Set_Library		(CModule_Library *pLibrary)
+{
+	g_pLibrary	= pLibrary;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void			Set_Silent		(bool bOn)
+{
+	g_bSilent	= bOn;
+}
+
+//---------------------------------------------------------
+#ifdef _SAGA_MSW
+
+#include <conio.h>
+
+//---------------------------------------------------------
+void			Get_Pause		(void)
+{
+	if( !g_bSilent )
+	{
+		SG_PRINTF(SG_T("\n%s..."), LNG("press any key"));
+
+		_getch();
+	}
+}
+
+//---------------------------------------------------------
+bool			Get_YesNo		(const SG_Char *caption, const SG_Char *message)
+{
+	SG_PRINTF(SG_T("\n%s: %s\n"), caption, message);
+
+	if( !g_bSilent )
+	{
+		CSG_String	sKey, sYes(SG_T("y")), sNo(SG_T("n"));
+
+		SG_PRINTF(SG_T("%s? (%s/%s)"), LNG("continue"), sYes.c_str(), sNo.c_str());
+
+		do
+		{
+			sKey.Printf(SG_T("%c"), _getch());
+		}
+		while( sYes.CmpNoCase(sKey) && sNo.CmpNoCase(sKey) );
+
+		return( sYes.CmpNoCase(sKey) == 0 );
+	}
+
+	return( true );
+}
+
+#else
+
+//---------------------------------------------------------
+void			Get_Pause		(void)
+{
+	if( !g_bSilent )
+	{
+		SG_PRINTF(SG_T("\n%s..."), LNG("press any key"));
+	}
+}
+
+//---------------------------------------------------------
+bool			Get_YesNo		(const SG_Char *caption, const SG_Char *message)
+{
+	return( true );
+}
+
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void			Print_Error		(const SG_Char *Error)
+{
+	SG_PRINTF(SG_T("\n%s: %s\n"), LNG("error"), Error);
+}
+
+//---------------------------------------------------------
+void			Print_Error		(const SG_Char *Error, const SG_Char *Info)
+{
+	Print_Error(CSG_String::Format(SG_T("%s [%s]"), Error, Info));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_cmd/callback.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,104 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                Command Line Interface                 //
+//                                                       //
+//                   Program: SAGA_CMD                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Callback.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_CMD__Callback_H
+#define _HEADER_INCLUDED__SAGA_CMD__Callback_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_PFNC_UI_Callback	Get_Callback	(void);
+
+void					Set_Library		(class CModule_Library *pLibrary);
+
+//---------------------------------------------------------
+void					Set_Silent		(bool bOn);
+
+void					Get_Pause		(void);
+bool					Get_YesNo		(const SG_Char *caption, const SG_Char *message);
+
+//---------------------------------------------------------
+void					Print_Error		(const SG_Char *Error);
+void					Print_Error		(const SG_Char *Error, const SG_Char *Info);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_CMD__Callback_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,757 @@
+ 
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                Command Line Interface                 //
+//                                                       //
+//                   Program: SAGA_CMD                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  module_library.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/cmdline.h>
+
+#include <saga_api/saga_api.h>
+
+#include "callback.h"
+
+#include "module_library.h"
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_ID1(p)		(p->Get_Owner()->Get_Identifier() && *(p->Get_Owner()->Get_Identifier()) \
+						? wxString::Format(wxT("%s_%s"), p->Get_Owner()->Get_Identifier(), p->Get_Identifier()) \
+						: wxString::Format(p->Get_Identifier()))
+
+#define GET_ID2(p, s)	wxString::Format(wxT("%s_%s"), GET_ID1(p).c_str(), s)
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CModule_Library::CModule_Library(void)
+{
+	m_nModules	= 0;
+	m_Modules	= NULL;
+	m_pSelected	= NULL;
+	m_pCMD		= NULL;
+}
+
+//---------------------------------------------------------
+CModule_Library::~CModule_Library(void)
+{
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CModule_Library::Create(const SG_Char *FileName, const SG_Char *FilePath)
+{
+	TSG_PFNC_MLB_Initialize		MLB_Initialize;
+	TSG_PFNC_MLB_Get_Interface	MLB_Get_Interface;
+
+	CSG_Module_Library_Interface	*pInterface;
+	CSG_Module						*pModule;
+
+	//-----------------------------------------------------
+	Destroy();
+
+	m_FileName	= SG_File_Make_Path(FilePath, FileName, NULL).c_str();
+
+	m_Library.Load(m_FileName);
+
+	//-----------------------------------------------------
+	if( !m_Library.IsLoaded() )
+	{
+		Print_Error(LNG("[ERR] Library could not be loaded"), FileName);
+	}
+	else
+	{
+		MLB_Initialize		= (TSG_PFNC_MLB_Initialize)		m_Library.GetSymbol(SYMBOL_MLB_Initialize);
+		MLB_Get_Interface	= (TSG_PFNC_MLB_Get_Interface)	m_Library.GetSymbol(SYMBOL_MLB_Get_Interface);
+
+		if(	!MLB_Get_Interface	|| !(pInterface = MLB_Get_Interface())
+		||	!MLB_Initialize		|| !MLB_Initialize(m_FileName) )
+		{
+			Print_Error(LNG("[ERR] Invalid library"), FileName);
+		}
+		else
+		{
+			while( (pModule = pInterface->Get_Module(m_nModules)) != NULL )
+			{
+				m_Modules	= (CSG_Module **)SG_Realloc(m_Modules, (m_nModules + 1) * sizeof(CSG_Module *));
+				m_Modules[m_nModules++]	= pModule;
+			}
+
+			if( m_nModules > 0 )
+			{
+				return( true );
+			}
+
+			Print_Error(LNG("[ERR] Library does not contain any modules"), FileName);
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CModule_Library::Destroy(void)
+{
+	if( m_nModules > 0 )
+	{
+		SG_Free(m_Modules);
+		m_nModules	= 0;
+		m_Modules	= NULL;
+		m_pSelected	= NULL;
+	}
+
+	if( m_pCMD )
+	{
+		delete(m_pCMD);
+		m_pCMD		= NULL;
+	}
+
+	if( m_Library.IsLoaded() )
+	{
+		m_Library.Unload();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Module * CModule_Library::Select(const SG_Char *ModuleName)
+{
+	int			i;
+	wxString	Description;
+
+	//-----------------------------------------------------
+	if( m_pCMD )
+	{
+		delete(m_pCMD);
+		m_pCMD	= NULL;
+	}
+
+	for(i=0, m_pSelected=NULL; i<m_nModules && !m_pSelected; i++)
+	{
+		if( !SG_STR_CMP(ModuleName, Get_Module(i)->Get_Name()) )
+		{
+			m_pSelected	= Get_Module(i);
+		}
+	}
+
+	if( !m_pSelected )
+	{
+		long		l;
+		wxString	s(ModuleName);
+
+		if( s.ToLong(&l) )
+		{
+			m_pSelected	= Get_Module((int)l);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_pSelected )
+	{
+		m_pCMD	= new wxCmdLineParser;
+
+		_Set_CMD(m_pSelected->Get_Parameters(), false);
+
+		for(i=0; i<m_pSelected->Get_Parameters_Count(); i++)
+		{
+			_Set_CMD(m_pSelected->Get_Parameters(i), true);
+		}
+	}
+
+	return( m_pSelected );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CModule_Library::Execute(int argc, char *argv[])
+{
+	bool	bResult	= false;
+
+	if( m_pSelected && m_pCMD )
+	{
+		m_pCMD->SetCmdLine(argc, argv);
+
+		if( argc == 1 )
+		{
+			m_pCMD->Usage();
+			return( true );
+		}
+
+		if( _Get_CMD(m_pSelected->Get_Parameters()) )
+		{
+			bResult	= m_pSelected->Execute();
+
+			_Destroy_DataObjects(bResult);
+		}
+	}
+
+	if( !bResult )
+	{
+		Print_Error(LNG("executing module"), m_pSelected->Get_Name());
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CModule_Library::Get_Parameters(CSG_Parameters *pParameters)
+{
+	return( _Get_CMD(pParameters) );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CModule_Library::_Set_CMD(CSG_Parameters *pParameters, bool bExtra)
+{
+	CSG_Parameter	*pParameter;
+	wxString	Description;
+
+	//-----------------------------------------------------
+	if( m_pCMD && pParameters )
+	{
+		m_pCMD->SetSwitchChars(SG_T("-"));
+
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			pParameter	= pParameters->Get_Parameter(i);
+			Description	= pParameter->Get_Description(
+							PARAMETER_DESCRIPTION_NAME|PARAMETER_DESCRIPTION_TYPE|PARAMETER_DESCRIPTION_PROPERTIES, SG_T("\n\t")
+						).c_str();
+
+			if( pParameter->is_Input() || pParameter->is_Output() )
+			{
+				m_pCMD->AddOption(
+					GET_ID1(pParameter), wxEmptyString, Description,
+					wxCMD_LINE_VAL_STRING,
+					wxCMD_LINE_NEEDS_SEPARATOR | (pParameter->is_Optional() || bExtra ? wxCMD_LINE_PARAM_OPTIONAL : wxCMD_LINE_OPTION_MANDATORY)
+				);
+			}
+			else if( pParameter->is_Option() && !pParameter->is_Information() )
+			{
+				switch( pParameter->Get_Type() )
+				{
+				default:
+					break;
+
+				case PARAMETER_TYPE_Bool:
+					m_pCMD->AddSwitch(GET_ID1(pParameter), wxEmptyString, Description, wxCMD_LINE_PARAM_OPTIONAL);
+					break;
+
+				case PARAMETER_TYPE_Int:
+				case PARAMETER_TYPE_Choice:
+				case PARAMETER_TYPE_Table_Field:
+					m_pCMD->AddOption(GET_ID1(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
+					break;
+
+				case PARAMETER_TYPE_Double:
+				case PARAMETER_TYPE_Degree:
+					m_pCMD->AddOption(GET_ID1(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+					break;
+
+				case PARAMETER_TYPE_Range:
+					m_pCMD->AddOption(GET_ID2(pParameter, wxT("MIN")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+					m_pCMD->AddOption(GET_ID2(pParameter, wxT("MAX")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+					break;
+
+				case PARAMETER_TYPE_String:
+				case PARAMETER_TYPE_Text:
+				case PARAMETER_TYPE_FilePath:
+					m_pCMD->AddOption(GET_ID1(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+					break;
+
+				case PARAMETER_TYPE_FixedTable:
+					m_pCMD->AddOption(GET_ID1(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+					break;
+
+				case PARAMETER_TYPE_Grid_System:
+					if( pParameter->Get_Children_Count() == 0 )
+					{
+						m_pCMD->AddOption(GET_ID2(pParameter, wxT("NX")), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
+						m_pCMD->AddOption(GET_ID2(pParameter, wxT("NY")), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
+						m_pCMD->AddOption(GET_ID2(pParameter, wxT( "X")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+						m_pCMD->AddOption(GET_ID2(pParameter, wxT( "Y")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+						m_pCMD->AddOption(GET_ID2(pParameter, wxT( "D")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
+					}
+					break;
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CModule_Library::_Get_CMD(CSG_Parameters *pParameters)
+{
+	//-----------------------------------------------------
+	if( m_pCMD == NULL || pParameters == NULL )
+	{
+		Print_Error(LNG("[ERR] Internal system error"));
+
+		return( false );
+	}
+
+	if( m_pCMD->Parse(false) != 0 || _Create_DataObjects(pParameters) == false )
+	{
+		m_pCMD->Usage();
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	for(int i=0; i<pParameters->Get_Count(); i++)
+	{
+		long			l;
+		double			d;
+		wxString		s;
+
+		CSG_Parameter	*pParameter	= pParameters->Get_Parameter(i);
+
+		switch( pParameter->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Bool:
+			pParameter->Set_Value(m_pCMD->Found(GET_ID1(pParameter)) ? 1 : 0);
+			break;
+
+		case PARAMETER_TYPE_Int:
+		case PARAMETER_TYPE_Choice:
+		case PARAMETER_TYPE_Table_Field:
+			if( m_pCMD->Found(GET_ID1(pParameter), &l) )
+			{
+				pParameter->Set_Value((int)l);
+			}
+			break;
+
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+			if( m_pCMD->Found(GET_ID1(pParameter), &s) && s.ToDouble(&d) )
+			{
+				pParameter->Set_Value(d);
+			}
+			break;
+
+		case PARAMETER_TYPE_Range:
+			if( m_pCMD->Found(GET_ID2(pParameter, wxT("MIN")), &s) && s.ToDouble(&d) )
+			{
+				pParameter->asRange()->Set_LoVal(d);
+			}
+
+			if( m_pCMD->Found(GET_ID2(pParameter, wxT("MAX")), &s) && s.ToDouble(&d) )
+			{
+				pParameter->asRange()->Set_HiVal(d);
+			}
+			break;
+
+		case PARAMETER_TYPE_String:
+		case PARAMETER_TYPE_Text:
+			if( m_pCMD->Found(GET_ID1(pParameter), &s) )
+			{
+				pParameter->Set_Value(s.c_str());
+			}
+			break;
+
+		case PARAMETER_TYPE_FilePath:
+			if( m_pCMD->Found(GET_ID1(pParameter), &s) )
+			{
+				if( pParameter->asFilePath()->is_Multiple() )
+				{
+					s.Prepend(wxT("\""));
+					s.Replace(wxT(";"), wxT("\" \""));
+					s.Append (wxT("\""));
+				}
+
+				pParameter->Set_Value(s.c_str());
+			}
+			break;
+
+		case PARAMETER_TYPE_FixedTable:
+			if( m_pCMD->Found(GET_ID1(pParameter), &s) )
+			{
+				CSG_Table	Table(s.c_str());
+				pParameter->asTable()->Assign_Values(&Table);
+			}
+			break;
+
+		case PARAMETER_TYPE_Grid_System:
+			if( pParameter->Get_Children_Count() == 0 )
+			{
+				long	nx, ny;
+				double	d, x, y;
+
+				if(	!m_pCMD->Found(GET_ID2(pParameter, wxT("NX")), &nx)
+				||	!m_pCMD->Found(GET_ID2(pParameter, wxT("NY")), &ny)
+				||	!m_pCMD->Found(GET_ID2(pParameter, wxT( "X")), &s) || !s.ToDouble(&x)
+				||	!m_pCMD->Found(GET_ID2(pParameter, wxT( "Y")), &s) || !s.ToDouble(&y)
+				||	!m_pCMD->Found(GET_ID2(pParameter, wxT( "D")), &s) || !s.ToDouble(&d) )
+				{
+					d	= -1.0;
+				}
+
+				pParameter->asGrid_System()->Assign(d, x, y, (int)nx, (int)ny);
+			}
+			break;
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CModule_Library::_Create_DataObjects(CSG_Parameters *pParameters)
+{
+	//-----------------------------------------------------
+	if( m_pCMD == NULL || pParameters == NULL )
+	{
+		Print_Error(LNG("[ERR] Internal system error"));
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	bool	bObjects	= false;
+	int		nObjects	= 0;
+
+	for(int i=0; i<pParameters->Get_Count(); i++)
+	{
+		wxString		s;
+		CSG_Data_Object	*pObject;
+
+		CSG_Parameter	*pParameter	= pParameters->Get_Parameter(i);
+
+		if(	pParameter->is_DataObject() || pParameter->is_DataObject_List() )
+		{
+			bObjects	= true;
+
+			if( m_pCMD->Found(GET_ID1(pParameter), &s) )
+			{
+				if( pParameter->is_Input() )
+				{
+					if( pParameter->is_DataObject() )
+					{
+						switch( pParameter->Get_Type() )
+						{
+						default:
+							pObject	= NULL;
+							break;
+
+						case PARAMETER_TYPE_Grid:
+							pObject	= new CSG_Grid  (s.c_str());
+							if( pObject && pObject->is_Valid() )
+							{
+								pParameter->Get_Parent()->asGrid_System()->Assign(((CSG_Grid *)pObject)->Get_System());
+								pParameter->Set_Value(pObject);
+							}
+							break;
+
+						case PARAMETER_TYPE_TIN:
+							pParameter->Set_Value(pObject = new CSG_TIN   (s.c_str()));
+							break;
+
+						case PARAMETER_TYPE_Shapes:
+							pParameter->Set_Value(pObject = new CSG_Shapes(s.c_str()));
+							break;
+
+						case PARAMETER_TYPE_Table:
+							pParameter->Set_Value(pObject = new CSG_Table (s.c_str()));
+							break;
+						}
+
+						if( !pObject || !pObject->is_Valid() )
+						{
+							Print_Error(LNG("input file"), s);
+
+							return( false );
+						}
+
+						nObjects++;
+					}
+					else if( pParameter->is_DataObject_List() )
+					{
+						if( !_Create_DataObject_List(pParameter, s) && !pParameter->is_Optional() )
+						{
+							Print_Error(LNG("empty input list"), GET_ID1(pParameter));
+
+							return( false );
+						}
+
+						nObjects++;
+					}
+				}
+				else if( pParameter->is_Output() )
+				{
+					pParameter->Set_Value(DATAOBJECT_CREATE);
+
+					nObjects++;
+				}
+			}
+			else if( !pParameter->is_Optional() )
+			{
+				return( false );
+			}
+		}
+	}
+
+	return( bObjects == false || nObjects > 0 );
+}
+
+//---------------------------------------------------------
+bool CModule_Library::_Create_DataObject_List(CSG_Parameter *pParameter, wxString sList)
+{
+	CSG_Data_Object		*pObject;
+	wxString		s;
+
+	if( pParameter && pParameter->is_DataObject_List() )
+	{
+		do
+		{
+			s		= sList.BeforeFirst	(';');
+			sList	= sList.AfterFirst	(';');
+
+			switch( pParameter->Get_Type() )
+			{
+			default:								pObject	= NULL;								break;
+			case PARAMETER_TYPE_Grid_List:			pObject	= new CSG_Grid      (s.c_str());	break;
+			case PARAMETER_TYPE_TIN_List:			pObject	= new CSG_TIN       (s.c_str());	break;
+			case PARAMETER_TYPE_PointCloud_List:	pObject	= new CSG_PointCloud(s.c_str());	break;
+			case PARAMETER_TYPE_Shapes_List:		pObject	= new CSG_Shapes    (s.c_str());	break;
+			case PARAMETER_TYPE_Table_List:			pObject	= new CSG_Table     (s.c_str());	break;
+			}
+
+			if( pObject && pObject->is_Valid() )
+			{
+				if( pParameter->Get_Type() == PARAMETER_TYPE_Grid_List && (pParameter->Get_Parent() && pParameter->Get_Parent()->Get_Type() == PARAMETER_TYPE_Grid_System) )
+				{	// grid system dependent grid list: first grid defines the grid system to be used!
+					if( pParameter->asList()->Get_Count() == 0 )
+					{
+						pParameter->Get_Parent()->asGrid_System()->Assign  (((CSG_Grid *)pObject)->Get_System());
+					}
+
+					if( pParameter->Get_Parent()->asGrid_System()->is_Equal(((CSG_Grid *)pObject)->Get_System()) )
+					{
+						pParameter->asList()->Add_Item(pObject);
+					}
+				}
+				else
+				{
+					pParameter->asList()->Add_Item(pObject);
+				}
+			}
+			else if( pObject )
+			{
+				delete(pObject);
+
+				Print_Error(LNG("input file"), s);
+			}
+		}
+		while( sList.Length() > 0 );
+
+		return( pParameter->asList()->Get_Count() > 0 );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CModule_Library::Add_DataObject(CSG_Data_Object *pObject)
+{
+	// leaves unsaved data and a memory leak, if <pObject> is not kept in parameters list either !!!
+	// to be done...
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CModule_Library::_Destroy_DataObjects(bool bSave)
+{
+	if( m_pSelected && m_pCMD )
+	{
+		_Destroy_DataObjects(bSave, m_pSelected->Get_Parameters());
+
+		for(int i=0; i<m_pSelected->Get_Parameters_Count(); i++)
+		{
+			// to be done...
+			_Destroy_DataObjects(bSave, m_pSelected->Get_Parameters(i));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CModule_Library::_Destroy_DataObjects(bool bSave, CSG_Parameters *pParameters)
+{
+	int			i, j;
+	CSG_Parameter	*pParameter;
+	wxString	s;
+
+	if( pParameters && m_pCMD )
+	{
+		for(j=0; j<pParameters->Get_Count(); j++)
+		{
+			pParameter	= pParameters->Get_Parameter(j);
+
+			if( bSave && pParameter->is_Output() && m_pCMD->Found(GET_ID1(pParameter), &s) )
+			{
+				if( pParameter->is_DataObject() )
+				{
+					if( pParameter->asDataObject() )
+					{
+						pParameter->asDataObject()->Save(s.c_str());
+					}
+				}
+				else if( pParameter->is_DataObject_List() )
+				{
+					if( pParameter->asList()->Get_Count() == 1 )
+					{
+						pParameter->asList()->asDataObject(0)->Save(s.c_str());
+					}
+					else
+					{
+						for(i=0; i<pParameter->asList()->Get_Count(); i++)
+						{
+							pParameter->asList()->asDataObject(i)->Save(CSG_String::Format(SG_T("%s_%02d"), s.c_str(), i + 1));
+						}
+					}
+				}
+			}
+
+			if( pParameter->is_DataObject() )
+			{
+				if( pParameter->asDataObject() )
+				{
+					delete(pParameter->asDataObject());
+					pParameter->Set_Value(DATAOBJECT_NOTSET);
+				}
+			}
+			else if( pParameter->is_DataObject_List() )
+			{
+				for(i=pParameter->asList()->Get_Count()-1; i>=0; i--)
+				{
+					delete(pParameter->asList()->asDataObject(i));
+				}
+
+				pParameter->asList()->Del_Items();
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_cmd/module_library.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                Command Line Interface                 //
+//                                                       //
+//                   Program: SAGA_CMD                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   module_library.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_CMD__Module_Library_H
+#define _HEADER_INCLUDED__SAGA_CMD__Module_Library_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dynlib.h>
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CModule_Library  
+{
+public:
+	CModule_Library(void);
+	virtual ~CModule_Library(void);
+
+	bool						Create					(const SG_Char *FileName, const SG_Char *FilePath);
+	void						Destroy					(void);
+
+	int							Get_Count				(void)		{	return( m_nModules );	}
+	class CSG_Module *			Get_Module				(int i)		{	return( i >= 0 && i < m_nModules ? m_Modules[i] : NULL );	}
+
+	bool						is_Valid				(void)		{	return( m_nModules > 0 );	}
+
+	wxString					Get_FileName			(void)		{	return( m_FileName );	}
+
+	class CSG_Module *			Select					(const SG_Char *ModuleName);
+	class CSG_Module *			Get_Selected			(void)		{	return( m_pSelected );	}
+
+	bool						Execute					(int argc, char *argv[]);
+
+	bool						Get_Parameters			(class CSG_Parameters *pParameters);
+	bool						Add_DataObject			(class CSG_Data_Object *pObject);
+
+
+private:
+
+	int							m_nModules;
+
+	class CSG_Module			**m_Modules, *m_pSelected;
+
+	wxString					m_FileName;
+
+	wxDynamicLibrary			m_Library;
+
+	class wxCmdLineParser		*m_pCMD;
+
+
+	void						_Set_CMD				(class CSG_Parameters *pParameters, bool bExtra);
+	bool						_Get_CMD				(class CSG_Parameters *pParameters);
+
+	bool						_Create_DataObjects		(class CSG_Parameters *pParameters);
+	bool						_Create_DataObject_List	(class CSG_Parameter *pParameter, wxString sList);
+
+	bool						_Destroy_DataObjects	(bool bSave);
+	bool						_Destroy_DataObjects	(bool bSave, class CSG_Parameters *pParameters);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_CMD__Module_Library_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_cmd/saga_cmd.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_cmd/saga_cmd.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_cmd/saga_cmd.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,503 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                Command Line Interface                 //
+//                                                       //
+//                   Program: SAGA_CMD                   //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     SAGA_CMD.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/app.h>
+#include <wx/utils.h>
+#include <wx/dir.h>
+
+#include <saga_api/saga_api.h>
+
+#include "callback.h"
+
+#include "module_library.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SAGA_CMD_VERSION	SG_T("2.0")
+#define SAGA_ENV_LIBPATH	SG_T("SAGA_MLB")
+
+#define SYS_ENV_PATH		SG_T("PATH")
+
+#define OPT_CREATE_BATCH	SG_T("-create_batch")
+#define OPT_SILENT			SG_T("-silent")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		Execute			(const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName, int argc, char *argv[]);
+
+void		Error_Library	(const SG_Char *MLB_Path);
+void		Error_Module	(const SG_Char *MLB_Path, const SG_Char *FileName);
+
+void		Print_Logo		(const SG_Char *MLB_Path);
+void		Print_Execution	(const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName, const SG_Char *Author);
+void		Print_Help		(void);
+
+void		Create_Example	(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int		main	(int argc, char *argv[])
+{
+//---------------------------------------------------------
+#if !defined(_DEBUG) && defined(_SAGA_VC)
+#define _MODULE_EXCEPTION
+_try 
+{
+#endif
+//---------------------------------------------------------
+
+	bool	bResult	= false;
+
+	if( wxInitialize() )
+	{
+		wxString	MLB_Path, ENV_Path;
+
+		MLB_Path	= wxGetenv(SAGA_ENV_LIBPATH) ? wxGetenv(SAGA_ENV_LIBPATH) : wxGetCwd();
+
+		if( wxGetEnv(SYS_ENV_PATH, &ENV_Path) && ENV_Path.Length() > 0 )
+		{
+			wxSetEnv(SYS_ENV_PATH, wxString::Format(wxT("%s;%s"), ENV_Path.c_str(), MLB_Path.c_str()));
+		}
+		else
+		{
+			wxSetEnv(SYS_ENV_PATH, MLB_Path);
+		}
+
+		Print_Logo(MLB_Path);
+
+		SG_Set_UI_Callback(Get_Callback());
+
+		SG_Get_Translator() .Create(SG_File_Make_Path(wxGetCwd(), wxT("saga"), wxT("lng")), false);
+		SG_Get_Projections().Create(SG_File_Make_Path(wxGetCwd(), wxT("saga"), wxT("srs")));
+
+		//-------------------------------------------------
+		switch( argc )
+		{
+		case 1: 
+			Error_Library		(MLB_Path);
+			break;
+
+		case 2:
+			Error_Module		(MLB_Path, SG_STR_MBTOSG(argv[1]));
+			break;
+
+		default:
+ 			bResult	= Execute	(MLB_Path, SG_STR_MBTOSG(argv[1]), SG_STR_MBTOSG(argv[2]), argc, argv);
+			break;
+		}
+
+		//-------------------------------------------------
+		if( ENV_Path.Length() > 0 )
+		{
+			wxSetEnv(SYS_ENV_PATH, ENV_Path);
+		}
+		else
+		{
+			wxUnsetEnv(SYS_ENV_PATH);
+		}
+
+		wxUninitialize();
+	}
+
+//---------------------------------------------------------
+#ifdef _DEBUG
+	Get_Pause();
+#endif
+
+#ifdef _MODULE_EXCEPTION
+}
+_except(1)
+{
+	Print_Error(LNG("access violation"));
+}
+#endif
+//---------------------------------------------------------
+
+	return( bResult ? 0 : 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		Execute(const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName, int argc, char *argv[])
+{
+	bool			bResult	= false;
+	int				i;
+	CModule_Library	Library;
+
+	if( !Library.Create(FileName, MLB_Path) )
+	{
+		Error_Library(MLB_Path);
+	}
+	else if( !Library.Select(ModuleName) )
+	{
+		Library.Destroy();
+
+		Print_Error(LNG("module not found"), ModuleName);
+
+		Error_Module(MLB_Path, FileName);
+	}
+	else if( Library.Get_Selected()->is_Interactive() )
+	{
+		Library.Destroy();
+
+		Print_Error(LNG("cannot execute interactive module"), ModuleName);
+
+		Error_Module(MLB_Path, FileName);
+	}
+	else
+	{
+		Print_Execution(MLB_Path, FileName, Library.Get_Selected()->Get_Name(), Library.Get_Selected()->Get_Author());
+
+		if( argc > 3 && !SG_STR_CMP(OPT_SILENT, SG_STR_MBTOSG(argv[3])) )
+		{
+			i	= 3;
+
+			Set_Silent(true);
+		}
+		else
+		{
+			i	= 2;
+		}
+
+		Set_Library(&Library);
+		bResult	= Library.Execute(argc - i, argv + i);
+		Set_Library(NULL);
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Error_Library	(const SG_Char *MLB_Path)
+{
+	int				nLibraries;
+	wxDir			Dir;
+	wxString		FileName;
+	CModule_Library Library;
+
+	if( !Dir.Open(MLB_Path) )
+	{
+		Print_Error(LNG("invalid module libraries path"), MLB_Path);
+	}
+	else if(	!Dir.GetFirst(&FileName, wxT("*.dll"), wxDIR_FILES|wxDIR_HIDDEN)
+			&&	!Dir.GetFirst(&FileName, wxT("*.so" ), wxDIR_FILES|wxDIR_HIDDEN) )
+	{
+		Print_Error(LNG("no valid module library found in path"), MLB_Path);
+	}
+	else
+	{
+		Print_Error(LNG("module library"));
+
+		SG_PRINTF(SG_T("\n%s:\n"), LNG("available module libraries"));
+
+		nLibraries	= 0;
+
+		do
+		{
+			if( Library.Create(FileName, Dir.GetName()) )
+			{
+				SG_PRINTF(SG_T("- %s\n"), FileName.c_str());
+				nLibraries++;
+			}
+		}
+		while( Dir.GetNext(&FileName) );
+
+		SG_PRINTF(SG_T("\n%d %s\n"), nLibraries, LNG("SAGA Module Libraries"));
+	}
+
+	SG_PRINTF(SG_T("\n"));
+	SG_PRINTF(LNG("type -h or --help for further information"));
+	SG_PRINTF(SG_T("\n"));
+}
+
+//---------------------------------------------------------
+void		Error_Module	(const SG_Char *MLB_Path, const SG_Char *FileName)
+{
+	CModule_Library	Library;
+
+	if( !SG_STR_CMP(SG_T("-h"), FileName) || !SG_STR_CMP(SG_T("--help"), FileName) )
+	{
+		Print_Help();
+	}
+	else if( !SG_STR_CMP(OPT_CREATE_BATCH, FileName) )
+	{
+		Create_Example();
+	}
+	else 
+	{
+		if( !Library.Create(FileName, MLB_Path) )
+		{
+			Library.Destroy();
+
+			Print_Error(LNG("module library not found"), FileName);
+
+			Error_Library(MLB_Path);
+		}
+		else
+		{
+			Print_Error(LNG("module"));
+
+			SG_PRINTF(SG_T("\n%s:\n"), LNG("available modules"));
+
+			for(int i=0; i<Library.Get_Count(); i++)
+			{
+				if( Library.Get_Module(i)->is_Interactive() )
+				{
+					SG_PRINTF(SG_T("[%d]\t- [%s] %s\n"), i, LNG("interactive"), Library.Get_Module(i)->Get_Name());
+				}
+				else
+				{
+					SG_PRINTF(SG_T(" %d\t- %s\n"), i, Library.Get_Module(i)->Get_Name());
+				}
+			}
+		}
+
+		SG_PRINTF(SG_T("\n"));
+		SG_PRINTF(LNG("type -h or --help for further information"));
+		SG_PRINTF(SG_T("\n"));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                                                       //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Print_Logo		(const SG_Char *MLB_Path)
+{
+	SG_PRINTF(SG_T("_____________________________________________\n"));
+	SG_PRINTF(SG_T("  #####   ##   #####    ##\n"));
+	SG_PRINTF(SG_T(" ###     ###  ##       ###\n"));
+	SG_PRINTF(SG_T("  ###   # ## ##  #### # ##\n"));
+	SG_PRINTF(SG_T("   ### ##### ##    # #####\n"));
+	SG_PRINTF(SG_T("##### #   ##  ##### #   ##\n"));
+	SG_PRINTF(SG_T("\n"));
+	SG_PRINTF(SG_T("SAGA CMD ") SAGA_API_VERSION SG_T("\n"));
+	SG_PRINTF(SG_T("_____________________________________________\n"));
+}
+
+//---------------------------------------------------------
+void		Print_Execution	(const SG_Char *MLB_Path, const SG_Char *FileName, const SG_Char *ModuleName, const SG_Char *Author)
+{
+	SG_PRINTF(SG_T("%s:\t%s\n"), LNG("library path"), MLB_Path);
+	SG_PRINTF(SG_T("%s:\t%s\n"), LNG("library name"), FileName);
+	SG_PRINTF(SG_T("%s:\t%s\n"), LNG("module name "), ModuleName);
+	SG_PRINTF(SG_T("%s:\t%s\n"), LNG("author      "), Author);
+	SG_PRINTF(SG_T("_____________________________________________\n"));
+	SG_PRINTF(SG_T("go...\n"));
+}
+
+//---------------------------------------------------------
+void		Print_Help		(void)
+{
+	SG_PRINTF(
+		SG_T("(C) 2005-08 by O.Conrad\n")
+		SG_T("under GNU General Public License (GPL)\n")
+		SG_T("\n")
+		SG_T("Usage:\n")
+		SG_T("\n")
+		SG_T("saga_cmd [-h, --help]\n")
+		SG_T("saga_cmd [") OPT_CREATE_BATCH SG_T("]\n")
+		SG_T("saga_cmd <LIBRARY> <MODULE> [") OPT_SILENT SG_T("] <module specific options...>\n")
+		SG_T("\n")
+		SG_T("[-h], [--help]\t")				SG_T(": help on usage\n")
+		SG_T("[") OPT_CREATE_BATCH SG_T("]\t")	SG_T(": create a batch file example\n")
+		SG_T("[") OPT_SILENT SG_T("]\t")		SG_T(": don't wait for user response on errors\n")
+		SG_T("<LIBRARY>\t")						SG_T(": file name of the library\n")
+		SG_T("<MODULE>\t")						SG_T(": either name or index of the module\n")
+		SG_T("\n")
+		SG_T("example:\n")
+		SG_T("  saga_cmd ta_morphometry \n")
+		SG_T("           \"Local Morphometry\"\n")
+		SG_T("           -ELEVATION c:\\dem.sgrd\n")
+		SG_T("           -SLOPE     d:\\slope.sgrd\n")
+		SG_T("           -ASPECT    d:\\aspect.sgrd\n")
+		SG_T("           -METHOD    1\n")
+		SG_T("\n")
+		SG_T("_____________________________________________\n")
+		SG_T("Module libraries are expected to be located in\n")
+		SG_T("the directory, that is specified by the environment\n")
+		SG_T("variable \'") SAGA_ENV_LIBPATH SG_T("\'. If this is not found the\n")
+		SG_T("current working directory will be searched for instead.\n")
+		SG_T("\n")
+		SG_T("SAGA CMD is particularly useful for the automated\n")
+		SG_T("execution of a series of analysis steps, because it\n")
+		SG_T("allows you to execute modules using batch files.\n")
+		SG_T("Calling saga_cmd with the option \'") OPT_CREATE_BATCH SG_T("\'\n")
+		SG_T("creates a batch file example. You probably have to edit\n")
+		SG_T("the path definitions to make the batch file run on your\n")
+		SG_T("computer.\n")
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Create_Example	(void)
+{
+	CSG_String	FileName(CSG_String::Format(SG_T("%s\\saga_cmd_example.bat"), wxGetCwd().c_str()));
+	CSG_File	Stream;
+
+	SG_PRINTF(SG_T("\n%s...\n"), LNG("creating batch file example"));
+
+	if( Stream.Open(FileName, SG_FILE_W, false) )
+	{
+		Stream.Printf(
+			SG_T("@echo off\n")
+			SG_T("\n")
+			SG_T("set SAGA=.\n")
+			SG_T("set SAGA_MLB=%%SAGA%%\\modules\n")
+			SG_T("PATH=PATH;%%SAGA%%;%%SAGA_MLB%%\n")
+			SG_T("\n")
+			SG_T("if exist .\\srtm.asc goto :SRTM\n")
+			SG_T("echo _____________________________________________\n")
+			SG_T("echo import SRTM-DEM from ESRI ASCII grid\n")
+			SG_T("saga_cmd.exe recreations_fractals 5 -GRID .\\dem.sgrd -NX 400 -NY 400 -H 0.75\n")
+			SG_T("\n")
+			SG_T("goto :GO\n")
+			SG_T("\n")
+			SG_T(":SRTM\n")
+			SG_T("echo _____________________________________________\n")
+			SG_T("echo import SRTM-DEM from ESRI ASCII grid\n")
+			SG_T("saga_cmd.exe io_grid              1 -FILE .\\srtm.asc -GRID .\\srtm.sgrd\n")
+			SG_T("\n")
+			SG_T("echo _____________________________________________\n")
+			SG_T("echo projection from geodetic to UTM zone 32\n")
+			SG_T("\n")
+			SG_T("saga_cmd.exe pj_proj4             1 -SOURCE .\\srtm.sgrd -OUT_GRID .\\dem.sgrd -PROJ_TYPE 109 -utm_zone 32 -TARGET_TYPE 1 -GET_AUTOFIT_GRIDSIZE 90.0\n")
+			SG_T("\n")
+			SG_T(":GO\n")
+			SG_T("echo _____________________________________________\n")
+			SG_T("echo create contour lines from DEM\n")
+			SG_T("\n")
+			SG_T("saga_cmd.exe shapes_grid          5 -INPUT .\\dem.sgrd -CONTOUR .\\contour.shp -ZSTEP 25.0\n")
+			SG_T("\n")
+			SG_T("echo _____________________________________________\n")
+			SG_T("echo do some terrain analysis\n")
+			SG_T("\n")
+			SG_T("saga_cmd.exe ta_preprocessor      1 -DEM .\\dem.sgrd -DEM_PREPROC .\\dem.sgrd\n")
+			SG_T("saga_cmd.exe ta_lighting          0 -ELEVATION .\\dem.sgrd -SHADE .\\shade.sgrd -METHOD 0 -AZIMUTH -45 -DECLINATION 45\n")
+			SG_T("saga_cmd.exe ta_morphometry       0 -ELEVATION .\\dem.sgrd -SLOPE .\\slope.sgrd -ASPECT .\\aspect.sgrd -HCURV .\\hcurv.sgrd -VCURV .\\vcurv.sgrd\n")
+			SG_T("saga_cmd.exe ta_hydrology         0 -ELEVATION .\\dem.sgrd -CAREA .\\carea.sgrd\n")
+			SG_T("saga_cmd.exe ta_hydrology        14 -SLOPE .\\slope.sgrd -AREA .\\carea.sgrd -WETNESS .\\wetness.sgrd -STREAMPOW .\\streampow.sgrd -LSFACTOR .\\lsfactor.sgrd\n")
+			SG_T("\n")
+			SG_T("echo _____________________________________________\n")
+			SG_T("echo perform cluster analysis\n")
+			SG_T("\n")
+			SG_T("saga_cmd.exe grid_discretisation  1 -INPUT .\\dem.sgrd;.\\slope.sgrd;.\\hcurv.sgrd;.\\vcurv.sgrd -RESULT .\\cluster.sgrd -STATISTICS .\\cluster.txt -NORMALISE -NCLUSTER 10\n")
+			SG_T("\n")
+			SG_T("pause\n")
+		);
+
+		SG_PRINTF(SG_T("%s\n"), LNG("okay"));
+	}
+	else
+	{
+		SG_PRINTF(SG_T("%s\n"), LNG("failed"));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,71 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     saga_gdi.cpp                      //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "saga_gdi.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/saga_gdi.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,93 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      saga_gdi.h                       //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_GDI_saga_gdi_H
+#define HEADER_INCLUDED__SAGA_GDI_saga_gdi_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "sgdi_dialog.h"
+#include "sgdi_diagram.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_GDI_saga_gdi_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,250 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    sgdi_diagram.cpp                   //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#include <wx/settings.h>
+#include <wx/dc.h>
+#include <wx/dcclient.h>
+
+//---------------------------------------------------------
+#include "sgdi_diagram.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CSGDI_Diagram, wxPanel)
+	EVT_PAINT				(CSGDI_Diagram::_On_Paint)
+	EVT_LEFT_DOWN			(CSGDI_Diagram::_On_Mouse_Click_Left)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSGDI_Diagram::CSGDI_Diagram(wxWindow *pParent)
+	: wxPanel(pParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxSUNKEN_BORDER)
+{
+	SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+
+	m_xName		= LNG("X");
+	m_yName		= LNG("Y");
+}
+
+//---------------------------------------------------------
+CSGDI_Diagram::~CSGDI_Diagram(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSGDI_Diagram::_On_Mouse_Click_Left(wxMouseEvent &WXUNUSED(event))
+{
+//	wxMessageBox("Sonk", "Sonk");
+}
+
+//---------------------------------------------------------
+void CSGDI_Diagram::_On_Paint(wxPaintEvent &WXUNUSED(event))
+{
+	wxPaintDC	dc(this);
+
+	_Draw(dc);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define RULER_LABEL_HEIGHT	20
+
+//---------------------------------------------------------
+bool CSGDI_Diagram::_Draw(wxDC &dc)
+{
+	if( m_xMin < m_xMax && m_yMin < m_yMax )
+	{
+		double	dx, dy;
+
+		m_rDiagram	= wxRect(RULER_LABEL_HEIGHT, 0, GetClientSize().x - RULER_LABEL_HEIGHT, GetClientSize().y - RULER_LABEL_HEIGHT);
+
+		dc.SetTextForeground(wxColour(0, 0, 0));
+		dc.SetFont(wxFont((int)(0.5 * RULER_LABEL_HEIGHT), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
+
+		Draw_Text(dc, TEXTALIGN_TOPCENTER   , 0, m_rDiagram.GetY() + m_rDiagram.GetHeight() / 2, 90, m_yName);
+		Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, m_rDiagram.GetX() + m_rDiagram.GetWidth() / 2, GetClientSize().y, m_xName);
+
+		Draw_Ruler(dc, m_rDiagram, true , m_xMin, m_xMax);
+		Draw_Ruler(dc, m_rDiagram, false, m_yMin, m_yMax);
+
+		//---------------------------------------------------------------------
+		dx	= m_rDiagram.GetWidth()  / (m_xMax - m_xMin);
+		dy	= m_rDiagram.GetHeight() / (m_yMax - m_yMin);
+
+		On_Draw(dc, m_rDiagram);
+
+		return( true );
+	}
+
+	dc.DrawLine(0, 0, GetClientSize().x, GetClientSize().y);
+	dc.DrawLine(0, GetClientSize().y, GetClientSize().x, 0);
+
+	return( false );
+}
+
+//---------------------------------------------------------
+#define DIAGRAM_BUFFER	100
+
+//---------------------------------------------------------
+int CSGDI_Diagram::Get_xToScreen(double x, bool bKeepInRange)
+{
+	int		i	= m_rDiagram.GetX() + (int)(m_rDiagram.GetWidth () * (x - m_xMin) / (m_xMax - m_xMin));
+
+	if( bKeepInRange )
+	{
+		if( i		< m_rDiagram.GetLeft  () - DIAGRAM_BUFFER )
+			i		= m_rDiagram.GetLeft  () - DIAGRAM_BUFFER;
+		else if( i	> m_rDiagram.GetRight () + DIAGRAM_BUFFER )
+			i		= m_rDiagram.GetRight () + DIAGRAM_BUFFER;
+	}
+
+	return( i );
+}
+
+//---------------------------------------------------------
+int CSGDI_Diagram::Get_yToScreen(double y, bool bKeepInRange)
+{
+	int		i	= m_rDiagram.GetY() - (int)(m_rDiagram.GetHeight() * (y - m_yMin) / (m_yMax - m_yMin)) + m_rDiagram.GetHeight();
+
+	if( bKeepInRange )
+	{
+		if( i		< m_rDiagram.GetTop   () - DIAGRAM_BUFFER )
+			i		= m_rDiagram.GetTop   () - DIAGRAM_BUFFER;
+		else if( i	> m_rDiagram.GetBottom() + DIAGRAM_BUFFER )
+			i		= m_rDiagram.GetBottom() + DIAGRAM_BUFFER;
+	}
+
+	return( i );
+}
+
+//---------------------------------------------------------
+bool CSGDI_Diagram::Get_ToScreen(wxPoint &Point, double x, double y)
+{
+	bool	bResult	= true;
+
+	Point.x	= Get_xToScreen(x, false);
+
+	if( Point.x			< m_rDiagram.GetLeft  () - DIAGRAM_BUFFER )
+	{
+		Point.x			= m_rDiagram.GetLeft  () - DIAGRAM_BUFFER;
+		bResult			= false;
+	}
+	else if( Point.x	> m_rDiagram.GetRight () + DIAGRAM_BUFFER )
+	{
+		Point.x			= m_rDiagram.GetRight () + DIAGRAM_BUFFER;
+		bResult			= false;
+	}
+
+	Point.y	= Get_yToScreen(y, false);
+
+	if( Point.y			< m_rDiagram.GetTop   () - DIAGRAM_BUFFER )
+	{
+		Point.y			= m_rDiagram.GetTop   () - DIAGRAM_BUFFER;
+		bResult			= false;
+	}
+	else if( Point.y	> m_rDiagram.GetBottom() + DIAGRAM_BUFFER )
+	{
+		Point.y			= m_rDiagram.GetBottom() + DIAGRAM_BUFFER;
+		bResult			= false;
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_diagram.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,138 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    sgdi_diagram.h                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_GDI_sgdi_diagram_H
+#define HEADER_INCLUDED__SAGA_GDI_sgdi_diagram_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "sgdi_helper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SGDI_API_DLL_EXPORT CSGDI_Diagram : public wxPanel
+{
+public:
+	CSGDI_Diagram(wxWindow *pParent);
+	virtual ~CSGDI_Diagram(void);
+
+	wxString			m_xName, m_yName;
+
+	bool				Set_xScale				(double Minimum, double Maximum);
+	bool				Set_yScale				(double Minimum, double Maximum);
+
+
+protected:
+
+	double				m_xMin, m_xMax, m_yMin, m_yMax;
+
+	int					Get_xToScreen			(double x, bool bKeepInRange = true);
+	int					Get_yToScreen			(double y, bool bKeepInRange = true);
+	bool				Get_ToScreen			(wxPoint &Point, double x, double y);
+
+
+	virtual void		On_Draw					(wxDC &dc, wxRect rDraw)	{}
+
+
+private:
+
+	wxRect				m_rDiagram;
+
+	void				_On_Mouse_Click_Left	(wxMouseEvent	&event);
+	void				_On_Paint				(wxPaintEvent	&event);
+
+	bool				_Draw					(wxDC &dc);
+
+
+	DECLARE_EVENT_TABLE()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_GDI_sgdi_diagram_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,295 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    sgui_dialog.cpp                    //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#include <wx/settings.h>
+#include <wx/dc.h>
+#include <wx/sizer.h>
+#include <wx/stattext.h>
+
+#include <saga_api/saga_api.h>
+
+//---------------------------------------------------------
+#include "sgdi_dialog.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CSGDI_Dialog, wxDialog)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSGDI_Dialog::CSGDI_Dialog(const wxString &Name, int Style)
+	: wxDialog((wxWindow *)SG_UI_Get_Window_Main(), wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
+{
+	wxRect	r(0, 0, wxSystemSettings::GetMetric(wxSYS_SCREEN_X), wxSystemSettings::GetMetric(wxSYS_SCREEN_Y));
+	r.Deflate((int)(0.1 * r.GetWidth()), (int)(0.1 * r.GetHeight()));
+	SetSize(r);
+
+	if( Style & SGDI_DLG_STYLE_START_MAXIMISED )
+	{
+		Maximize();
+	}
+
+	m_Ctrl_Color	= *wxBLACK;
+
+	m_pSizer_Ctrl	= new wxStaticBoxSizer(wxVERTICAL, this, wxT(""));
+	m_pSizer_Output	= new wxStaticBoxSizer(wxVERTICAL, this, wxT(""));
+
+	wxSizer	*pSizer	= new wxBoxSizer(wxHORIZONTAL);
+
+	if( Style & SGDI_DLG_STYLE_CTRLS_RIGHT )
+	{
+		pSizer->Add(m_pSizer_Output	, 1, wxALIGN_RIGHT|wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+		pSizer->Add(m_pSizer_Ctrl	, 0, wxALIGN_LEFT |wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+	}
+	else
+	{
+		pSizer->Add(m_pSizer_Ctrl	, 0, wxALIGN_LEFT |wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+		pSizer->Add(m_pSizer_Output	, 1, wxALIGN_RIGHT|wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+	}
+
+	pSizer->SetVirtualSizeHints(this);
+
+	SetSizer(pSizer);
+}
+
+//---------------------------------------------------------
+CSGDI_Dialog::~CSGDI_Dialog(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSGDI_Dialog::Add_Output(wxWindow *pOutput)
+{
+	m_pSizer_Output->Add(pOutput, 1, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSGDI_Dialog::Add_Output(wxWindow *pOutput_A, wxWindow *pOutput_B, int Proportion_A, int Proportion_B)
+{
+	m_pSizer_Output->Add(pOutput_A, Proportion_A, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+	m_pSizer_Output->Add(pOutput_B, Proportion_B, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSGDI_Dialog::Add_Spacer(int Space)
+{
+	m_pSizer_Ctrl->AddSpacer(Space);
+}
+
+//---------------------------------------------------------
+wxButton * CSGDI_Dialog::Add_Button(const wxString &Name, int ID, const wxSize &Size)
+{
+	wxButton	*pButton	= new wxButton(this, ID, Name, wxDefaultPosition, Size);
+
+	m_pSizer_Ctrl->Add(pButton, 0, wxALIGN_CENTER|wxALL|wxEXPAND, SGDI_CTRL_SMALLSPACE);
+
+	return( pButton );
+}
+
+//---------------------------------------------------------
+wxChoice * CSGDI_Dialog::Add_Choice(const wxString &Name, const wxArrayString &Choices, int iSelect, int ID)
+{
+	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
+	wxChoice		*pChoice	= new wxChoice(this, ID, wxDefaultPosition, wxDefaultSize, Choices);
+
+	pLabel	->SetForegroundColour(m_Ctrl_Color);
+	pChoice	->SetSelection(iSelect);
+
+	m_pSizer_Ctrl->Add(pLabel , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP   |wxEXPAND, SGDI_CTRL_SMALLSPACE);
+	m_pSizer_Ctrl->Add(pChoice, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
+
+	return( pChoice );
+}
+
+//---------------------------------------------------------
+wxCheckBox * CSGDI_Dialog::Add_CheckBox(const wxString &Name, bool bCheck, int ID)
+{
+	wxCheckBox		*pCheckBox	= new wxCheckBox(this, ID, Name, wxDefaultPosition, wxDefaultSize, 0);
+
+	pCheckBox->SetForegroundColour(m_Ctrl_Color);
+	pCheckBox->SetValue(bCheck);
+
+	m_pSizer_Ctrl->Add(pCheckBox, 0, wxALIGN_LEFT|wxALL, SGDI_CTRL_SMALLSPACE);
+
+	return( pCheckBox );
+}
+
+//---------------------------------------------------------
+wxTextCtrl * CSGDI_Dialog::Add_TextCtrl(const wxString &Name, int Style, const wxString &Text, int ID)
+{
+	int				Stretch		= Style & wxTE_MULTILINE;
+
+	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
+	wxTextCtrl		*pTextCtrl	= new wxTextCtrl(this, ID, Text, wxDefaultPosition, SGDI_BTN_SIZE, Style);
+
+	pLabel	->SetForegroundColour(m_Ctrl_Color);
+
+	m_pSizer_Ctrl->Add(pLabel   ,       0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP            , SGDI_CTRL_SMALLSPACE);
+	m_pSizer_Ctrl->Add(pTextCtrl, Stretch, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
+
+	if( Style & wxTE_READONLY )
+	{
+		pTextCtrl->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
+	}
+
+	return( pTextCtrl );
+}
+
+//-----------------------------------------------------------------------------
+CSGDI_Slider * CSGDI_Dialog::Add_Slider(const wxString &Name, double Value, double minValue, double maxValue, bool bValueAsPercent, int ID, int Width)
+{
+	if( bValueAsPercent && maxValue > minValue )
+	{
+		Value	= minValue + Value * (maxValue - minValue) / 100.0;
+	}
+
+//	wxSizer			*pSizer_	= new wxBoxSizer(wxHORIZONTAL);
+	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
+	CSGDI_Slider	*pSlider	= new CSGDI_Slider(this, ID, Value, minValue, maxValue, wxDefaultPosition, wxSize(Width, wxDefaultCoord), wxSL_AUTOTICKS|wxSL_LABELS|wxSL_TOP);
+
+	pLabel			->SetForegroundColour(m_Ctrl_Color);
+
+//	pSizer_			->Add(new wxStaticText(this, wxID_ANY,  "0", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
+//	pSizer_			->Add(pSlider, 0);
+//	pSizer_			->Add(new wxStaticText(this, wxID_ANY, "10", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
+
+	m_pSizer_Ctrl	->Add(pLabel , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP            , SGDI_CTRL_SMALLSPACE);
+//	m_pSizer_Ctrl	->Add(pSizer_, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
+	m_pSizer_Ctrl	->Add(pSlider, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
+
+	return( pSlider );
+}
+
+//-----------------------------------------------------------------------------
+CSGDI_SpinCtrl * CSGDI_Dialog::Add_SpinCtrl(const wxString &Name, double Value, double minValue, double maxValue, bool bValueAsPercent, int ID, int Width)
+{
+//	wxSizer			*pSizer_	= new wxBoxSizer(wxHORIZONTAL);
+	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
+	CSGDI_SpinCtrl	*pSpinCtrl	= new CSGDI_SpinCtrl(this, ID, Value, minValue, maxValue, bValueAsPercent, wxDefaultPosition, wxSize(Width, wxDefaultCoord), wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER);
+
+	pLabel			->SetForegroundColour(m_Ctrl_Color);
+
+//	pSizer_			->Add(new wxStaticText(this, wxID_ANY,  "0", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
+//	pSizer_			->Add(pSpinCtrl, 0);
+//	pSizer_			->Add(new wxStaticText(this, wxID_ANY, "10", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
+
+	m_pSizer_Ctrl	->Add(pLabel   , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP   , SGDI_CTRL_SMALLSPACE);
+//	m_pSizer_Ctrl	->Add(pSizer_  , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM, SGDI_CTRL_SMALLSPACE);
+	m_pSizer_Ctrl	->Add(pSpinCtrl, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
+
+	return( pSpinCtrl );
+}
+
+//---------------------------------------------------------
+void CSGDI_Dialog::Add_CustomCtrl(const wxString &Name, wxWindow *pControl)
+{
+	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
+
+	pLabel	->SetForegroundColour(m_Ctrl_Color);
+
+	m_pSizer_Ctrl->Add(pLabel  , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP   , SGDI_CTRL_SMALLSPACE);
+	m_pSizer_Ctrl->Add(pControl, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM, SGDI_CTRL_SMALLSPACE);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_dialog.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,144 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     sgdi_dialog.h                     //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_GDI_sgdi_dialog_H
+#define HEADER_INCLUDED__SAGA_GDI_sgdi_dialog_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "sgdi_helper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SGDI_DLG_STYLE_CTRLS_RIGHT			0x01
+#define SGDI_DLG_STYLE_START_MAXIMISED		0x02
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SGDI_API_DLL_EXPORT CSGDI_Dialog : public wxDialog
+{
+public:
+	CSGDI_Dialog(const wxString &Name, int Style = 0);
+	virtual ~CSGDI_Dialog(void);
+
+
+protected:
+
+	void					Add_Spacer			(int Space = SGDI_CTRL_SPACE);
+	wxButton *				Add_Button			(const wxString &Name, int ID, const wxSize &Size = SGDI_BTN_SIZE);
+	wxChoice *				Add_Choice			(const wxString &Name, const wxArrayString &Choices, int iSelect = 0, int ID = wxID_ANY);
+	wxCheckBox *			Add_CheckBox		(const wxString &Name, bool bCheck, int ID = wxID_ANY);
+	wxTextCtrl *			Add_TextCtrl		(const wxString &Name, int Style = 0, const wxString &Text = wxT(""), int ID = wxID_ANY);
+	CSGDI_Slider *			Add_Slider			(const wxString &Name, double Value, double minValue, double maxValue, bool bValueAsPercent = false, int ID = wxID_ANY, int Width = SGDI_CTRL_WIDTH);
+	CSGDI_SpinCtrl *		Add_SpinCtrl		(const wxString &Name, double Value, double minValue, double maxValue, bool bValueAsPercent = false, int ID = wxID_ANY, int Width = SGDI_CTRL_WIDTH);
+	void					Add_CustomCtrl		(const wxString &Name, wxWindow *pControl);
+
+	bool					Add_Output			(wxWindow *pOutput);
+	bool					Add_Output			(wxWindow *pOutput_A, wxWindow *pOutput_B, int Proportion_A = 1, int Proportion_B = 0);
+
+
+private:
+
+	wxColour				m_Ctrl_Color;
+
+	wxSizer					*m_pSizer_Ctrl, *m_pSizer_Output;
+
+
+	DECLARE_EVENT_TABLE()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_GDI_sgdi_dialog_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,408 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    sgdi_helper.cpp                    //
+//                                                       //
+//                 Copyright (C) 2008 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#include <wx/dc.h>
+
+//---------------------------------------------------------
+#include "sgdi_helper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef M_PI
+#define M_PI						3.141592653589793
+#endif
+
+#ifndef M_DEG_TO_RAD
+#define M_DEG_TO_RAD				(M_PI / 180.0)
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Draw_Text(wxDC &dc, int Align, int x, int y, const wxString &Text)
+{
+	wxCoord	xSize, ySize;
+
+	if( Align != TEXTALIGN_TOPLEFT )
+	{
+		dc.GetTextExtent(Text, &xSize, &ySize);
+
+		//-------------------------------------------------
+		if		( Align & TEXTALIGN_XCENTER )
+		{
+			x	-= xSize / 2;
+		}
+		else if	( Align & TEXTALIGN_RIGHT )
+		{
+			x	-= xSize;
+		}
+
+		//-------------------------------------------------
+		if		( Align & TEXTALIGN_YCENTER )
+		{
+			y	-= ySize / 2;
+		}
+		else if	( Align & TEXTALIGN_BOTTOM )
+		{
+			y	-= ySize;
+		}
+	}
+
+	dc.DrawText(Text, x, y);
+}
+
+//---------------------------------------------------------
+void		Draw_Text(wxDC &dc, int Align, int x, int y, double Angle, const wxString &Text)
+{
+	double	d;
+	wxCoord	xSize, ySize;
+
+	if( Align != TEXTALIGN_TOPLEFT )
+	{
+		dc.GetTextExtent(Text, &xSize, &ySize);
+
+		//-------------------------------------------------
+		d	 = M_DEG_TO_RAD * Angle;
+
+		if		( Align & TEXTALIGN_XCENTER )
+		{
+			x	-= (int)(xSize * cos(d) / 2.0);
+			y	+= (int)(xSize * sin(d) / 2.0);
+		}
+		else if	( Align & TEXTALIGN_RIGHT )
+		{
+			x	-= (int)(xSize * cos(d));
+			y	+= (int)(xSize * sin(d));
+		}
+
+		//-------------------------------------------------
+		d	 = M_DEG_TO_RAD * (Angle - 90.0);
+
+		if		( Align & TEXTALIGN_YCENTER )
+		{
+			x	-= (int)(ySize * cos(d) / 2.0);
+			y	+= (int)(ySize * sin(d) / 2.0);
+		}
+		else if	( Align & TEXTALIGN_BOTTOM )
+		{
+			x	-= (int)(ySize * cos(d));
+			y	+= (int)(ySize * sin(d));
+		}
+	}
+
+	dc.DrawRotatedText(Text, x, y, Angle);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define RULER_TEXT_SPACE	4
+
+//---------------------------------------------------------
+bool		Draw_Ruler(wxDC &dc, const wxRect &r, bool bHorizontal, double zMin, double zMax, bool bAscendent, int FontSize, const wxColour &Colour)
+{
+	int			xMin, xMax, yMin, yMax, Decimals, dxFont, dyFont, zPos;
+	double		Width, z, dz, zToDC, zDC;
+	wxString	s;
+
+	//-----------------------------------------------------
+	if( zMin < zMax && r.GetWidth() > 0 && r.GetHeight() > 0 )
+	{
+		dc.SetPen(wxPen(Colour));
+		dc.SetFont(wxFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
+
+		Width		= bHorizontal ? r.GetWidth() : r.GetHeight();
+
+		xMin		= r.GetX();
+		xMax		= r.GetX() + r.GetWidth();
+		yMin		= r.GetY() + r.GetHeight();
+		yMax		= r.GetY();
+
+		//-------------------------------------------------
+		zToDC		= (double)Width / (zMax - zMin);
+
+		dz			= pow(10.0, floor(log10(zMax - zMin)) - 1.0);
+		Decimals	= dz >= 1.0 ? 0 : (int)fabs(log10(dz));
+
+		s.Printf(wxT("%.*f"), Decimals, zMax);
+		dyFont		= RULER_TEXT_SPACE + dc.GetTextExtent(s).y;
+		dxFont		= RULER_TEXT_SPACE;
+
+		zDC			= 2 * dc.GetTextExtent(s).x;
+		while( zToDC * dz < zDC + RULER_TEXT_SPACE )
+		{
+			dz	*= 2;
+		}
+
+		//-------------------------------------------------
+		z			= dz * floor(zMin / dz);
+		if( z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			s.Printf(wxT("%.*f"), Decimals, z);
+
+			zDC	= bAscendent ? zToDC * (z - zMin) : Width - zToDC * (z - zMin);
+
+			if( bHorizontal )
+			{
+				zPos	= (int)(xMin + zDC);
+				dc.DrawLine(zPos, yMin, zPos, yMax);
+				dc.DrawText(s, zPos + dxFont, yMin - dyFont);
+			}
+			else
+			{
+				zPos	= (int)(yMin - zDC);
+				dc.DrawLine(xMin, zPos, xMax, zPos);
+				dc.DrawText(s, xMin + dxFont, zPos - dyFont);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SLIDER_RANGE	100
+
+//---------------------------------------------------------
+CSGDI_Slider::CSGDI_Slider(wxWindow *pParent, int ID, double Value, double minValue, double maxValue, const wxPoint &Point, const wxSize &Size, long Style)
+	: wxSlider(pParent, ID, 0, 0, SLIDER_RANGE, Point, Size, Style)
+{
+	Set_Range(minValue, maxValue);
+
+	Set_Value(Value);
+
+	SetTickFreq(SLIDER_RANGE / 10, 0);
+}
+
+//---------------------------------------------------------
+CSGDI_Slider::~CSGDI_Slider(void)
+{}
+
+//---------------------------------------------------------
+bool CSGDI_Slider::Set_Value(double Value)
+{
+	int		Position	= (int)((double)SLIDER_RANGE * (Value - m_Min) / (m_Max - m_Min));
+
+	if( Position <= 0 )
+	{
+		SetValue(0);
+	}
+	else if( Position >= SLIDER_RANGE )
+	{
+		SetValue(SLIDER_RANGE);
+	}
+	else
+	{
+		SetValue(Position);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+double CSGDI_Slider::Get_Value(void)
+{
+	return( m_Min + GetValue() * (m_Max - m_Min) / (double)SLIDER_RANGE );
+}
+
+//---------------------------------------------------------
+bool CSGDI_Slider::Set_Range(double minValue, double maxValue)
+{
+	if( maxValue == minValue )
+	{
+		minValue	= 0.0;
+		maxValue	= 1.0;
+	}
+
+	m_Min	= minValue;
+	m_Max	= maxValue;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSGDI_SpinCtrl::CSGDI_SpinCtrl(wxWindow *pParent, int ID, double Value, double minValue, double maxValue, bool bPercent, const wxPoint &Point, const wxSize &Size, long Style)
+	: wxSpinCtrl(pParent, ID, wxEmptyString, Point, Size, Style, bPercent ? 0 : (int)minValue, bPercent ? 100 : (int)maxValue)
+{
+	m_bPercent	= bPercent;
+
+	Set_Range(minValue, maxValue);
+
+	Set_Value(Value);
+}
+
+//---------------------------------------------------------
+CSGDI_SpinCtrl::~CSGDI_SpinCtrl(void)
+{}
+
+//---------------------------------------------------------
+bool CSGDI_SpinCtrl::Set_Value(double Value)
+{
+	if( m_bPercent )
+	{
+		int		Position	= (int)((double)SLIDER_RANGE * (Value - m_Min) / (m_Max - m_Min));
+
+		if( Position <= 0 )
+		{
+			SetValue(0);
+		}
+		else if( Position >= SLIDER_RANGE )
+		{
+			SetValue(SLIDER_RANGE);
+		}
+		else
+		{
+			SetValue(Position);
+		}
+	}
+	else
+	{
+		if( Value <= m_Min )
+		{
+			SetValue((int)m_Min);
+		}
+		else if( Value >= m_Max )
+		{
+			SetValue((int)m_Max);
+		}
+		else
+		{
+			SetValue((int)Value);
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+double CSGDI_SpinCtrl::Get_Value(void)
+{
+	if( m_bPercent )
+	{
+		return( m_Min + GetValue() * (m_Max - m_Min) / (double)SLIDER_RANGE );
+	}
+
+	return( GetValue() );
+}
+
+//---------------------------------------------------------
+bool CSGDI_SpinCtrl::Set_Range(double minValue, double maxValue)
+{
+	if( maxValue == minValue )
+	{
+		minValue	= 0.0;
+		maxValue	= 1.0;
+	}
+
+	m_Min	= minValue;
+	m_Max	= maxValue;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gdi/sgdi_helper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,230 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//           Application Programming Interface           //
+//                                                       //
+//                  Library: SAGA_GDI                    //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    sgdi_helper.h                      //
+//                                                       //
+//                 Copyright (C) 2009 by                 //
+//                      Olaf Conrad                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstr. 55                          //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef HEADER_INCLUDED__SAGA_GDI_sgdi_helper_H
+#define HEADER_INCLUDED__SAGA_GDI_sgdi_helper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#ifdef _SAGA_GDI_EXPORTS
+	#define	SGDI_API_DLL_EXPORT		_SAGA_DLL_EXPORT
+#else
+ 	#define	SGDI_API_DLL_EXPORT		_SAGA_DLL_IMPORT
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#include <wx/dc.h>
+#include <wx/button.h>
+#include <wx/choice.h>
+#include <wx/checkbox.h>
+#include <wx/textctrl.h>
+#include <wx/slider.h>
+#include <wx/spinctrl.h>
+#include <wx/dialog.h>
+#include <wx/panel.h>
+#include <wx/image.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SGDI_CTRL_WIDTH				100
+#define SGDI_CTRL_SPACE				10
+#define SGDI_CTRL_SMALLSPACE		2
+
+#define SGDI_BTN_HEIGHT				25
+#define SGDI_BTN_WIDTH				SGDI_CTRL_WIDTH
+#define SGDI_BTN_SIZE				wxSize(SGDI_BTN_WIDTH, SGDI_BTN_HEIGHT)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define TEXTALIGN_LEFT				0x01
+#define TEXTALIGN_XCENTER			0x02
+#define TEXTALIGN_RIGHT				0x04
+#define TEXTALIGN_TOP				0x08
+#define TEXTALIGN_YCENTER			0x10
+#define TEXTALIGN_BOTTOM			0x20
+
+#define TEXTALIGN_TOPLEFT			(TEXTALIGN_TOP    |TEXTALIGN_LEFT)
+#define TEXTALIGN_TOPCENTER			(TEXTALIGN_TOP    |TEXTALIGN_XCENTER)
+#define TEXTALIGN_TOPRIGHT			(TEXTALIGN_TOP    |TEXTALIGN_RIGHT)
+#define TEXTALIGN_CENTERLEFT		(TEXTALIGN_YCENTER|TEXTALIGN_LEFT)
+#define TEXTALIGN_CENTER			(TEXTALIGN_YCENTER|TEXTALIGN_XCENTER)
+#define TEXTALIGN_CENTERRIGHT		(TEXTALIGN_YCENTER|TEXTALIGN_RIGHT)
+#define TEXTALIGN_BOTTOMLEFT		(TEXTALIGN_BOTTOM |TEXTALIGN_LEFT)
+#define TEXTALIGN_BOTTOMCENTER		(TEXTALIGN_BOTTOM |TEXTALIGN_XCENTER)
+#define TEXTALIGN_BOTTOMRIGHT		(TEXTALIGN_BOTTOM |TEXTALIGN_RIGHT)
+
+//---------------------------------------------------------
+SGDI_API_DLL_EXPORT void	Draw_Text	(wxDC &dc, int Align, int x, int y, const wxString &Text);
+SGDI_API_DLL_EXPORT void	Draw_Text	(wxDC &dc, int Align, int x, int y, double Angle, const wxString &Text);
+
+SGDI_API_DLL_EXPORT bool	Draw_Ruler	(wxDC &dc, const wxRect &r, bool bHorizontal, double zMin, double zMax, bool bAscendent = true, int FontSize = 7, const wxColour &Colour = wxColour(127, 127, 127));
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SGDI_API_DLL_EXPORT CSGDI_Slider : public wxSlider
+{
+public:
+	CSGDI_Slider(wxWindow *pParent, int ID, double Value, double minValue, double maxValue, const wxPoint &Point = wxDefaultPosition, const wxSize &Size = wxDefaultSize, long Style = wxSL_HORIZONTAL);
+	virtual ~CSGDI_Slider(void);
+
+	bool				Set_Value			(double Value);
+	double				Get_Value			(void);
+
+	double				Get_Min				(void)	{	return( m_Min );	}
+	double				Get_Max				(void)	{	return( m_Max );	}
+	double				Get_Range			(void)	{	return( m_Max - m_Min );	}
+	bool				Set_Range			(double minValue, double maxValue);
+
+
+private:
+
+	double				m_Min, m_Max;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class SGDI_API_DLL_EXPORT CSGDI_SpinCtrl : public wxSpinCtrl
+{
+public:
+	CSGDI_SpinCtrl(wxWindow *pParent, int ID, double Value, double minValue, double maxValue, bool bPercent = false, const wxPoint &Point = wxDefaultPosition, const wxSize &Size = wxDefaultSize, long Style = wxSP_ARROW_KEYS);
+	virtual ~CSGDI_SpinCtrl(void);
+
+	bool				Set_Value			(double Value);
+	double				Get_Value			(void);
+
+	double				Get_Min				(void)	{	return( m_Min );	}
+	double				Get_Max				(void)	{	return( m_Max );	}
+	double				Get_Range			(void)	{	return( m_Max - m_Min );	}
+	bool				Set_Range			(double minValue, double maxValue);
+
+
+private:
+
+	bool				m_bPercent;
+
+	double				m_Min, m_Max;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef HEADER_INCLUDED__SAGA_GDI_sgdi_helper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.am
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.am	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.am	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,225 @@
+#
+# $Id: Makefile.am,v 1.17 2009/09/01 14:12:31 oconrad Exp $
+#
+INCS = -I.. -I.
+if DEBUG
+DBGFLAGS = -g -DDEBUG
+endif
+MLIBPATH = "MODULE_LIBRARY_PATH=\"$(prefix)/lib/saga\""
+
+BASEFLAGS = -fPIC -D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -D_SAGA_DONOTUSE_HARU -D$(MLIBPATH) $(DBGFLAGS) $(INCS)
+if SAGA_UNICODE
+AM_CXXFLAGS = $(BASEFLAGS) `wx-config --unicode=yes --cxxflags` -D_SAGA_UNICODE
+AM_LDFLAGS = -fPIC `wx-config --unicode=yes --libs` -lm 
+else
+AM_CXXFLAGS = $(BASEFLAGS) `wx-config --unicode=no --cxxflags`
+AM_LDFLAGS = -fPIC `wx-config --unicode=no --libs` -lm
+endif
+
+bin_PROGRAMS = saga_gui
+
+saga_gui_SOURCES =\
+active.cpp\
+active_attributes.cpp\
+active_description.cpp\
+active_history.cpp\
+active_HTMLExtraInfo.cpp\
+active_legend.cpp\
+active_parameters.cpp\
+callback.cpp\
+dc_helper.cpp\
+dlg_about.cpp\
+dlg_about_logo.cpp\
+dlg_base.cpp\
+dlg_colors.cpp\
+dlg_colors_control.cpp\
+dlg_list_base.cpp\
+dlg_list_grid.cpp\
+dlg_list_pointcloud.cpp\
+dlg_list_shapes.cpp\
+dlg_list_table.cpp\
+dlg_list_tin.cpp\
+dlg_parameters.cpp\
+dlg_table.cpp\
+dlg_text.cpp\
+helper.cpp\
+info.cpp\
+info_messages.cpp\
+parameters_control.cpp\
+parameters_properties.cpp\
+project.cpp\
+res_commands.cpp\
+res_controls.cpp\
+res_dialogs.cpp\
+res_images.cpp\
+saga.cpp\
+saga_frame.cpp\
+saga_frame_droptarget.cpp\
+svg_interactive_map.cpp\
+view_base.cpp\
+view_histogram.cpp\
+view_layout.cpp\
+view_layout_control.cpp\
+view_layout_info.cpp\
+view_layout_printout.cpp\
+view_map.cpp\
+view_map_3d.cpp\
+view_map_3d_image.cpp\
+view_map_control.cpp\
+view_ruler.cpp\
+view_scatterplot.cpp\
+view_table.cpp\
+view_table_control.cpp\
+view_table_diagram.cpp\
+wksp.cpp\
+wksp_base_control.cpp\
+wksp_base_item.cpp\
+wksp_base_manager.cpp\
+wksp_data_control.cpp\
+wksp_data_layers.cpp\
+wksp_data_manager.cpp\
+wksp_data_menu_file.cpp\
+wksp_data_menu_files.cpp\
+wksp_grid.cpp\
+wksp_grid_manager.cpp\
+wksp_grid_system.cpp\
+wksp_layer.cpp\
+wksp_layer_classify.cpp\
+wksp_layer_legend.cpp\
+wksp_map.cpp\
+wksp_map_buttons.cpp\
+wksp_map_control.cpp\
+wksp_map_dc.cpp\
+wksp_map_layer.cpp\
+wksp_map_manager.cpp\
+wksp_module.cpp\
+wksp_module_control.cpp\
+wksp_module_library.cpp\
+wksp_module_manager.cpp\
+wksp_module_menu.cpp\
+wksp_pointcloud.cpp\
+wksp_pointcloud_manager.cpp\
+wksp_shapes.cpp\
+wksp_shapes_edit.cpp\
+wksp_shapes_line.cpp\
+wksp_shapes_manager.cpp\
+wksp_shapes_point.cpp\
+wksp_shapes_points.cpp\
+wksp_shapes_polygon.cpp\
+wksp_shapes_type.cpp\
+wksp_table.cpp\
+wksp_table_manager.cpp\
+wksp_tin.cpp\
+wksp_tin_manager.cpp\
+active.h\
+active_attributes.h\
+active_description.h\
+active_history.h\
+active_HTMLExtraInfo.h\
+active_legend.h\
+active_parameters.h\
+callback.h\
+dc_helper.h\
+dlg_about.h\
+dlg_about_logo.h\
+dlg_base.h\
+dlg_colors.h\
+dlg_colors_control.h\
+dlg_list_base.h\
+dlg_list_grid.h\
+dlg_list_pointcloud.h\
+dlg_list_shapes.h\
+dlg_list_table.h\
+dlg_list_tin.h\
+dlg_parameters.h\
+dlg_table.h\
+dlg_text.h\
+helper.h\
+info.h\
+info_messages.h\
+parameters_control.h\
+parameters_properties.h\
+project.h\
+res_commands.h\
+res_controls.h\
+res_dialogs.h\
+res_images.h\
+saga.h\
+saga_frame.h\
+saga_frame_droptarget.h\
+svg_interactive_map.h\
+view_base.h\
+view_histogram.h\
+view_layout.h\
+view_layout_control.h\
+view_layout_info.h\
+view_layout_printout.h\
+view_map.h\
+view_map_3d.h\
+view_map_3d_image.h\
+view_map_control.h\
+view_ruler.h\
+view_scatterplot.h\
+view_table.h\
+view_table_control.h\
+view_table_diagram.h\
+wksp.h\
+wksp_base_control.h\
+wksp_base_item.h\
+wksp_base_manager.h\
+wksp_data_control.h\
+wksp_data_layers.h\
+wksp_data_manager.h\
+wksp_data_menu_file.h\
+wksp_data_menu_files.h\
+wksp_grid.h\
+wksp_grid_manager.h\
+wksp_grid_system.h\
+wksp_layer.h\
+wksp_layer_classify.h\
+wksp_layer_legend.h\
+wksp_map.h\
+wksp_map_buttons.h\
+wksp_map_control.h\
+wksp_map_dc.h\
+wksp_map_layer.h\
+wksp_map_manager.h\
+wksp_module.h\
+wksp_module_control.h\
+wksp_module_library.h\
+wksp_module_manager.h\
+wksp_module_menu.h\
+wksp_pointcloud.h\
+wksp_pointcloud_manager.h\
+wksp_shapes.h\
+wksp_shapes_line.h\
+wksp_shapes_manager.h\
+wksp_shapes_point.h\
+wksp_shapes_points.h\
+wksp_shapes_polygon.h\
+wksp_shapes_type.h\
+wksp_table.h\
+wksp_table_manager.h\
+wksp_tin.h\
+wksp_tin_manager.h\
+wx/propgrid/advprops.cpp\
+wx/propgrid/advprops.h\
+wx/propgrid/editors.cpp\
+wx/propgrid/editors.h\
+wx/propgrid/extras.cpp\
+wx/propgrid/extras.h\
+wx/propgrid/manager.cpp\
+wx/propgrid/manager.h\
+wx/propgrid/odcombo.cpp\
+wx/propgrid/odcombo.h\
+wx/propgrid/propdev.h\
+wx/propgrid/propgrid.cpp\
+wx/propgrid/propgrid.h\
+wx/propgrid/props.cpp\
+wx/propgrid/props.h
+
+saga_gui_LDADD = ../saga_api/libsaga_api.la
+
+dist-hook:
+	 mkdir $(distdir)/res
+	 cp -Rp $(srcdir)/res/* $(distdir)/res/

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.in
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.in	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/Makefile.in	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,978 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = saga_gui$(EXEEXT)
+subdir = src/saga_core/saga_gui
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_saga_gui_OBJECTS = active.$(OBJEXT) active_attributes.$(OBJEXT) \
+	active_description.$(OBJEXT) active_history.$(OBJEXT) \
+	active_HTMLExtraInfo.$(OBJEXT) active_legend.$(OBJEXT) \
+	active_parameters.$(OBJEXT) callback.$(OBJEXT) \
+	dc_helper.$(OBJEXT) dlg_about.$(OBJEXT) \
+	dlg_about_logo.$(OBJEXT) dlg_base.$(OBJEXT) \
+	dlg_colors.$(OBJEXT) dlg_colors_control.$(OBJEXT) \
+	dlg_list_base.$(OBJEXT) dlg_list_grid.$(OBJEXT) \
+	dlg_list_pointcloud.$(OBJEXT) dlg_list_shapes.$(OBJEXT) \
+	dlg_list_table.$(OBJEXT) dlg_list_tin.$(OBJEXT) \
+	dlg_parameters.$(OBJEXT) dlg_table.$(OBJEXT) \
+	dlg_text.$(OBJEXT) helper.$(OBJEXT) info.$(OBJEXT) \
+	info_messages.$(OBJEXT) parameters_control.$(OBJEXT) \
+	parameters_properties.$(OBJEXT) project.$(OBJEXT) \
+	res_commands.$(OBJEXT) res_controls.$(OBJEXT) \
+	res_dialogs.$(OBJEXT) res_images.$(OBJEXT) saga.$(OBJEXT) \
+	saga_frame.$(OBJEXT) saga_frame_droptarget.$(OBJEXT) \
+	svg_interactive_map.$(OBJEXT) view_base.$(OBJEXT) \
+	view_histogram.$(OBJEXT) view_layout.$(OBJEXT) \
+	view_layout_control.$(OBJEXT) view_layout_info.$(OBJEXT) \
+	view_layout_printout.$(OBJEXT) view_map.$(OBJEXT) \
+	view_map_3d.$(OBJEXT) view_map_3d_image.$(OBJEXT) \
+	view_map_control.$(OBJEXT) view_ruler.$(OBJEXT) \
+	view_scatterplot.$(OBJEXT) view_table.$(OBJEXT) \
+	view_table_control.$(OBJEXT) view_table_diagram.$(OBJEXT) \
+	wksp.$(OBJEXT) wksp_base_control.$(OBJEXT) \
+	wksp_base_item.$(OBJEXT) wksp_base_manager.$(OBJEXT) \
+	wksp_data_control.$(OBJEXT) wksp_data_layers.$(OBJEXT) \
+	wksp_data_manager.$(OBJEXT) wksp_data_menu_file.$(OBJEXT) \
+	wksp_data_menu_files.$(OBJEXT) wksp_grid.$(OBJEXT) \
+	wksp_grid_manager.$(OBJEXT) wksp_grid_system.$(OBJEXT) \
+	wksp_layer.$(OBJEXT) wksp_layer_classify.$(OBJEXT) \
+	wksp_layer_legend.$(OBJEXT) wksp_map.$(OBJEXT) \
+	wksp_map_buttons.$(OBJEXT) wksp_map_control.$(OBJEXT) \
+	wksp_map_dc.$(OBJEXT) wksp_map_layer.$(OBJEXT) \
+	wksp_map_manager.$(OBJEXT) wksp_module.$(OBJEXT) \
+	wksp_module_control.$(OBJEXT) wksp_module_library.$(OBJEXT) \
+	wksp_module_manager.$(OBJEXT) wksp_module_menu.$(OBJEXT) \
+	wksp_pointcloud.$(OBJEXT) wksp_pointcloud_manager.$(OBJEXT) \
+	wksp_shapes.$(OBJEXT) wksp_shapes_edit.$(OBJEXT) \
+	wksp_shapes_line.$(OBJEXT) wksp_shapes_manager.$(OBJEXT) \
+	wksp_shapes_point.$(OBJEXT) wksp_shapes_points.$(OBJEXT) \
+	wksp_shapes_polygon.$(OBJEXT) wksp_shapes_type.$(OBJEXT) \
+	wksp_table.$(OBJEXT) wksp_table_manager.$(OBJEXT) \
+	wksp_tin.$(OBJEXT) wksp_tin_manager.$(OBJEXT) \
+	advprops.$(OBJEXT) editors.$(OBJEXT) extras.$(OBJEXT) \
+	manager.$(OBJEXT) odcombo.$(OBJEXT) propgrid.$(OBJEXT) \
+	props.$(OBJEXT)
+saga_gui_OBJECTS = $(am_saga_gui_OBJECTS)
+saga_gui_DEPENDENCIES = ../saga_api/libsaga_api.la
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(saga_gui_SOURCES)
+DIST_SOURCES = $(saga_gui_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+POW_LIB = @POW_LIB@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+
+#
+# $Id: Makefile.am,v 1.17 2009/09/01 14:12:31 oconrad Exp $
+#
+INCS = -I.. -I.
+ at DEBUG_TRUE@DBGFLAGS = -g -DDEBUG
+MLIBPATH = "MODULE_LIBRARY_PATH=\"$(prefix)/lib/saga\""
+BASEFLAGS = -fPIC -D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -D_SAGA_DONOTUSE_HARU -D$(MLIBPATH) $(DBGFLAGS) $(INCS)
+ at SAGA_UNICODE_FALSE@AM_CXXFLAGS = $(BASEFLAGS) `wx-config --unicode=no --cxxflags`
+ at SAGA_UNICODE_TRUE@AM_CXXFLAGS = $(BASEFLAGS) `wx-config --unicode=yes --cxxflags` -D_SAGA_UNICODE
+ at SAGA_UNICODE_FALSE@AM_LDFLAGS = -fPIC `wx-config --unicode=no --libs` -lm
+ at SAGA_UNICODE_TRUE@AM_LDFLAGS = -fPIC `wx-config --unicode=yes --libs` -lm 
+saga_gui_SOURCES = \
+active.cpp\
+active_attributes.cpp\
+active_description.cpp\
+active_history.cpp\
+active_HTMLExtraInfo.cpp\
+active_legend.cpp\
+active_parameters.cpp\
+callback.cpp\
+dc_helper.cpp\
+dlg_about.cpp\
+dlg_about_logo.cpp\
+dlg_base.cpp\
+dlg_colors.cpp\
+dlg_colors_control.cpp\
+dlg_list_base.cpp\
+dlg_list_grid.cpp\
+dlg_list_pointcloud.cpp\
+dlg_list_shapes.cpp\
+dlg_list_table.cpp\
+dlg_list_tin.cpp\
+dlg_parameters.cpp\
+dlg_table.cpp\
+dlg_text.cpp\
+helper.cpp\
+info.cpp\
+info_messages.cpp\
+parameters_control.cpp\
+parameters_properties.cpp\
+project.cpp\
+res_commands.cpp\
+res_controls.cpp\
+res_dialogs.cpp\
+res_images.cpp\
+saga.cpp\
+saga_frame.cpp\
+saga_frame_droptarget.cpp\
+svg_interactive_map.cpp\
+view_base.cpp\
+view_histogram.cpp\
+view_layout.cpp\
+view_layout_control.cpp\
+view_layout_info.cpp\
+view_layout_printout.cpp\
+view_map.cpp\
+view_map_3d.cpp\
+view_map_3d_image.cpp\
+view_map_control.cpp\
+view_ruler.cpp\
+view_scatterplot.cpp\
+view_table.cpp\
+view_table_control.cpp\
+view_table_diagram.cpp\
+wksp.cpp\
+wksp_base_control.cpp\
+wksp_base_item.cpp\
+wksp_base_manager.cpp\
+wksp_data_control.cpp\
+wksp_data_layers.cpp\
+wksp_data_manager.cpp\
+wksp_data_menu_file.cpp\
+wksp_data_menu_files.cpp\
+wksp_grid.cpp\
+wksp_grid_manager.cpp\
+wksp_grid_system.cpp\
+wksp_layer.cpp\
+wksp_layer_classify.cpp\
+wksp_layer_legend.cpp\
+wksp_map.cpp\
+wksp_map_buttons.cpp\
+wksp_map_control.cpp\
+wksp_map_dc.cpp\
+wksp_map_layer.cpp\
+wksp_map_manager.cpp\
+wksp_module.cpp\
+wksp_module_control.cpp\
+wksp_module_library.cpp\
+wksp_module_manager.cpp\
+wksp_module_menu.cpp\
+wksp_pointcloud.cpp\
+wksp_pointcloud_manager.cpp\
+wksp_shapes.cpp\
+wksp_shapes_edit.cpp\
+wksp_shapes_line.cpp\
+wksp_shapes_manager.cpp\
+wksp_shapes_point.cpp\
+wksp_shapes_points.cpp\
+wksp_shapes_polygon.cpp\
+wksp_shapes_type.cpp\
+wksp_table.cpp\
+wksp_table_manager.cpp\
+wksp_tin.cpp\
+wksp_tin_manager.cpp\
+active.h\
+active_attributes.h\
+active_description.h\
+active_history.h\
+active_HTMLExtraInfo.h\
+active_legend.h\
+active_parameters.h\
+callback.h\
+dc_helper.h\
+dlg_about.h\
+dlg_about_logo.h\
+dlg_base.h\
+dlg_colors.h\
+dlg_colors_control.h\
+dlg_list_base.h\
+dlg_list_grid.h\
+dlg_list_pointcloud.h\
+dlg_list_shapes.h\
+dlg_list_table.h\
+dlg_list_tin.h\
+dlg_parameters.h\
+dlg_table.h\
+dlg_text.h\
+helper.h\
+info.h\
+info_messages.h\
+parameters_control.h\
+parameters_properties.h\
+project.h\
+res_commands.h\
+res_controls.h\
+res_dialogs.h\
+res_images.h\
+saga.h\
+saga_frame.h\
+saga_frame_droptarget.h\
+svg_interactive_map.h\
+view_base.h\
+view_histogram.h\
+view_layout.h\
+view_layout_control.h\
+view_layout_info.h\
+view_layout_printout.h\
+view_map.h\
+view_map_3d.h\
+view_map_3d_image.h\
+view_map_control.h\
+view_ruler.h\
+view_scatterplot.h\
+view_table.h\
+view_table_control.h\
+view_table_diagram.h\
+wksp.h\
+wksp_base_control.h\
+wksp_base_item.h\
+wksp_base_manager.h\
+wksp_data_control.h\
+wksp_data_layers.h\
+wksp_data_manager.h\
+wksp_data_menu_file.h\
+wksp_data_menu_files.h\
+wksp_grid.h\
+wksp_grid_manager.h\
+wksp_grid_system.h\
+wksp_layer.h\
+wksp_layer_classify.h\
+wksp_layer_legend.h\
+wksp_map.h\
+wksp_map_buttons.h\
+wksp_map_control.h\
+wksp_map_dc.h\
+wksp_map_layer.h\
+wksp_map_manager.h\
+wksp_module.h\
+wksp_module_control.h\
+wksp_module_library.h\
+wksp_module_manager.h\
+wksp_module_menu.h\
+wksp_pointcloud.h\
+wksp_pointcloud_manager.h\
+wksp_shapes.h\
+wksp_shapes_line.h\
+wksp_shapes_manager.h\
+wksp_shapes_point.h\
+wksp_shapes_points.h\
+wksp_shapes_polygon.h\
+wksp_shapes_type.h\
+wksp_table.h\
+wksp_table_manager.h\
+wksp_tin.h\
+wksp_tin_manager.h\
+wx/propgrid/advprops.cpp\
+wx/propgrid/advprops.h\
+wx/propgrid/editors.cpp\
+wx/propgrid/editors.h\
+wx/propgrid/extras.cpp\
+wx/propgrid/extras.h\
+wx/propgrid/manager.cpp\
+wx/propgrid/manager.h\
+wx/propgrid/odcombo.cpp\
+wx/propgrid/odcombo.h\
+wx/propgrid/propdev.h\
+wx/propgrid/propgrid.cpp\
+wx/propgrid/propgrid.h\
+wx/propgrid/props.cpp\
+wx/propgrid/props.h
+
+saga_gui_LDADD = ../saga_api/libsaga_api.la
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cpp .lo .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/saga_core/saga_gui/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu src/saga_core/saga_gui/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p || test -f $$p1; \
+	  then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	    echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+	    $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-binPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' `; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+	@list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+saga_gui$(EXEEXT): $(saga_gui_OBJECTS) $(saga_gui_DEPENDENCIES) 
+	@rm -f saga_gui$(EXEEXT)
+	$(CXXLINK) $(saga_gui_OBJECTS) $(saga_gui_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active_HTMLExtraInfo.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active_attributes.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active_description.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active_history.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active_legend.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/active_parameters.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/advprops.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/callback.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dc_helper.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_about.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_about_logo.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_base.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_colors.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_colors_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_list_base.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_list_grid.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_list_pointcloud.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_list_shapes.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_list_table.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_list_tin.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_parameters.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_table.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/dlg_text.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/editors.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/extras.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/helper.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/info.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/info_messages.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/odcombo.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/parameters_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/parameters_properties.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/project.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/propgrid.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/props.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/res_commands.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/res_controls.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/res_dialogs.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/res_images.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/saga.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/saga_frame.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/saga_frame_droptarget.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/svg_interactive_map.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_base.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_histogram.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_layout.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_layout_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_layout_info.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_layout_printout.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_map.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_map_3d.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_map_3d_image.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_map_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_ruler.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_scatterplot.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_table.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_table_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/view_table_diagram.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_base_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_base_item.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_base_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_data_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_data_layers.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_data_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_data_menu_file.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_data_menu_files.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_grid.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_grid_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_grid_system.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_layer.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_layer_classify.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_layer_legend.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_map.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_map_buttons.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_map_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_map_dc.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_map_layer.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_map_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_module.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_module_control.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_module_library.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_module_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_module_menu.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_pointcloud.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_pointcloud_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_edit.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_line.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_point.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_points.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_polygon.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_shapes_type.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_table.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_table_manager.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_tin.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/wksp_tin_manager.Po at am__quote@
+
+.cpp.o:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ $<
+
+.cpp.obj:
+ at am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cpp.lo:
+ at am__fastdepCXX_TRUE@	$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(LTCXXCOMPILE) -c -o $@ $<
+
+advprops.o: wx/propgrid/advprops.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT advprops.o -MD -MP -MF $(DEPDIR)/advprops.Tpo -c -o advprops.o `test -f 'wx/propgrid/advprops.cpp' || echo '$(srcdir)/'`wx/propgrid/advprops.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/advprops.Tpo $(DEPDIR)/advprops.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/advprops.cpp' object='advprops.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o advprops.o `test -f 'wx/propgrid/advprops.cpp' || echo '$(srcdir)/'`wx/propgrid/advprops.cpp
+
+advprops.obj: wx/propgrid/advprops.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT advprops.obj -MD -MP -MF $(DEPDIR)/advprops.Tpo -c -o advprops.obj `if test -f 'wx/propgrid/advprops.cpp'; then $(CYGPATH_W) 'wx/propgrid/advprops.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/advprops.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/advprops.Tpo $(DEPDIR)/advprops.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/advprops.cpp' object='advprops.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o advprops.obj `if test -f 'wx/propgrid/advprops.cpp'; then $(CYGPATH_W) 'wx/propgrid/advprops.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/advprops.cpp'; fi`
+
+editors.o: wx/propgrid/editors.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT editors.o -MD -MP -MF $(DEPDIR)/editors.Tpo -c -o editors.o `test -f 'wx/propgrid/editors.cpp' || echo '$(srcdir)/'`wx/propgrid/editors.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/editors.Tpo $(DEPDIR)/editors.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/editors.cpp' object='editors.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o editors.o `test -f 'wx/propgrid/editors.cpp' || echo '$(srcdir)/'`wx/propgrid/editors.cpp
+
+editors.obj: wx/propgrid/editors.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT editors.obj -MD -MP -MF $(DEPDIR)/editors.Tpo -c -o editors.obj `if test -f 'wx/propgrid/editors.cpp'; then $(CYGPATH_W) 'wx/propgrid/editors.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/editors.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/editors.Tpo $(DEPDIR)/editors.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/editors.cpp' object='editors.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o editors.obj `if test -f 'wx/propgrid/editors.cpp'; then $(CYGPATH_W) 'wx/propgrid/editors.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/editors.cpp'; fi`
+
+extras.o: wx/propgrid/extras.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT extras.o -MD -MP -MF $(DEPDIR)/extras.Tpo -c -o extras.o `test -f 'wx/propgrid/extras.cpp' || echo '$(srcdir)/'`wx/propgrid/extras.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/extras.Tpo $(DEPDIR)/extras.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/extras.cpp' object='extras.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o extras.o `test -f 'wx/propgrid/extras.cpp' || echo '$(srcdir)/'`wx/propgrid/extras.cpp
+
+extras.obj: wx/propgrid/extras.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT extras.obj -MD -MP -MF $(DEPDIR)/extras.Tpo -c -o extras.obj `if test -f 'wx/propgrid/extras.cpp'; then $(CYGPATH_W) 'wx/propgrid/extras.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/extras.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/extras.Tpo $(DEPDIR)/extras.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/extras.cpp' object='extras.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o extras.obj `if test -f 'wx/propgrid/extras.cpp'; then $(CYGPATH_W) 'wx/propgrid/extras.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/extras.cpp'; fi`
+
+manager.o: wx/propgrid/manager.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT manager.o -MD -MP -MF $(DEPDIR)/manager.Tpo -c -o manager.o `test -f 'wx/propgrid/manager.cpp' || echo '$(srcdir)/'`wx/propgrid/manager.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/manager.Tpo $(DEPDIR)/manager.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/manager.cpp' object='manager.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o manager.o `test -f 'wx/propgrid/manager.cpp' || echo '$(srcdir)/'`wx/propgrid/manager.cpp
+
+manager.obj: wx/propgrid/manager.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT manager.obj -MD -MP -MF $(DEPDIR)/manager.Tpo -c -o manager.obj `if test -f 'wx/propgrid/manager.cpp'; then $(CYGPATH_W) 'wx/propgrid/manager.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/manager.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/manager.Tpo $(DEPDIR)/manager.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/manager.cpp' object='manager.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o manager.obj `if test -f 'wx/propgrid/manager.cpp'; then $(CYGPATH_W) 'wx/propgrid/manager.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/manager.cpp'; fi`
+
+odcombo.o: wx/propgrid/odcombo.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT odcombo.o -MD -MP -MF $(DEPDIR)/odcombo.Tpo -c -o odcombo.o `test -f 'wx/propgrid/odcombo.cpp' || echo '$(srcdir)/'`wx/propgrid/odcombo.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/odcombo.Tpo $(DEPDIR)/odcombo.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/odcombo.cpp' object='odcombo.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o odcombo.o `test -f 'wx/propgrid/odcombo.cpp' || echo '$(srcdir)/'`wx/propgrid/odcombo.cpp
+
+odcombo.obj: wx/propgrid/odcombo.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT odcombo.obj -MD -MP -MF $(DEPDIR)/odcombo.Tpo -c -o odcombo.obj `if test -f 'wx/propgrid/odcombo.cpp'; then $(CYGPATH_W) 'wx/propgrid/odcombo.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/odcombo.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/odcombo.Tpo $(DEPDIR)/odcombo.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/odcombo.cpp' object='odcombo.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o odcombo.obj `if test -f 'wx/propgrid/odcombo.cpp'; then $(CYGPATH_W) 'wx/propgrid/odcombo.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/odcombo.cpp'; fi`
+
+propgrid.o: wx/propgrid/propgrid.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT propgrid.o -MD -MP -MF $(DEPDIR)/propgrid.Tpo -c -o propgrid.o `test -f 'wx/propgrid/propgrid.cpp' || echo '$(srcdir)/'`wx/propgrid/propgrid.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/propgrid.Tpo $(DEPDIR)/propgrid.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/propgrid.cpp' object='propgrid.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o propgrid.o `test -f 'wx/propgrid/propgrid.cpp' || echo '$(srcdir)/'`wx/propgrid/propgrid.cpp
+
+propgrid.obj: wx/propgrid/propgrid.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT propgrid.obj -MD -MP -MF $(DEPDIR)/propgrid.Tpo -c -o propgrid.obj `if test -f 'wx/propgrid/propgrid.cpp'; then $(CYGPATH_W) 'wx/propgrid/propgrid.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/propgrid.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/propgrid.Tpo $(DEPDIR)/propgrid.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/propgrid.cpp' object='propgrid.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o propgrid.obj `if test -f 'wx/propgrid/propgrid.cpp'; then $(CYGPATH_W) 'wx/propgrid/propgrid.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/propgrid.cpp'; fi`
+
+props.o: wx/propgrid/props.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT props.o -MD -MP -MF $(DEPDIR)/props.Tpo -c -o props.o `test -f 'wx/propgrid/props.cpp' || echo '$(srcdir)/'`wx/propgrid/props.cpp
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/props.Tpo $(DEPDIR)/props.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/props.cpp' object='props.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o props.o `test -f 'wx/propgrid/props.cpp' || echo '$(srcdir)/'`wx/propgrid/props.cpp
+
+props.obj: wx/propgrid/props.cpp
+ at am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT props.obj -MD -MP -MF $(DEPDIR)/props.Tpo -c -o props.obj `if test -f 'wx/propgrid/props.cpp'; then $(CYGPATH_W) 'wx/propgrid/props.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/props.cpp'; fi`
+ at am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/props.Tpo $(DEPDIR)/props.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='wx/propgrid/props.cpp' object='props.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o props.obj `if test -f 'wx/propgrid/props.cpp'; then $(CYGPATH_W) 'wx/propgrid/props.cpp'; else $(CYGPATH_W) '$(srcdir)/wx/propgrid/props.cpp'; fi`
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	$(MAKE) $(AM_MAKEFLAGS) \
+	  top_distdir="$(top_distdir)" distdir="$(distdir)" \
+	  dist-hook
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+	for dir in "$(DESTDIR)$(bindir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+	clean-generic clean-libtool ctags dist-hook distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-binPROGRAMS install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-binPROGRAMS
+
+
+dist-hook:
+	 mkdir $(distdir)/res
+	 cp -Rp $(srcdir)/res/* $(distdir)/res/
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,490 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     ACTIVE.cpp                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/treectrl.h>
+#include <wx/imaglist.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "active.h"
+#include "active_parameters.h"
+#include "active_description.h"
+#include "active_history.h"
+#include "active_attributes.h"
+#include "active_legend.h"
+#include "active_HTMLExtraInfo.h"
+
+#include "wksp_module.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_data_layers.h"
+#include "wksp_map_buttons.h"
+
+#include "wksp_layer.h"
+#include "wksp_map_layer.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+// #define ACTIVE_SHOW_ALL_PAGES
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_PARAMETERS	= 0,
+	IMG_DESCRIPTION,
+	IMG_HISTORY,
+	IMG_ATTRIBUTES,
+	IMG_LEGEND
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE	*g_pACTIVE	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE, wxNotebook)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE::CACTIVE(wxWindow *pParent)
+	: wxNotebook(pParent, ID_WND_ACTIVE, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE, LNG("[CAP] Object Properties"))
+{
+	g_pACTIVE		= this;
+
+	m_pItem			= NULL;
+	m_pLayer		= NULL;
+	m_pObject		= NULL;
+
+	//-----------------------------------------------------
+	AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));
+
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_PARAMETERS);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_DESCRIPTION);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_HISTORY);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_ATTRIBUTES);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_ACTIVE_LEGEND);
+
+	//-----------------------------------------------------
+	m_pParameters	= new CACTIVE_Parameters	(this);	m_pParameters	->SetName(LNG("[CAP] Settings"));
+	m_pDescription	= new CACTIVE_Description	(this);	m_pDescription	->SetName(LNG("[CAP] Description"));
+	m_pHistory		= new CACTIVE_History		(this);	m_pHistory		->SetName(LNG("[CAP] History"));
+	m_pLegend		= new CACTIVE_Legend		(this);	m_pLegend		->SetName(LNG("[CAP] Legend"));
+	m_pAttributes	= new CACTIVE_Attributes	(this);	m_pAttributes	->SetName(LNG("[CAP] Attributes"));
+
+#if defined(_SAGA_MSW)
+	m_pParameters	->Hide();
+	m_pDescription	->Hide();
+	m_pHistory		->Hide();
+	m_pLegend		->Hide();
+	m_pAttributes	->Hide();
+#endif
+}
+
+//---------------------------------------------------------
+void CACTIVE::Add_Pages(void)
+{
+	_Show_Page(m_pParameters);
+	_Show_Page(m_pDescription);
+#ifdef ACTIVE_SHOW_ALL_PAGES
+	_Show_Page(m_pHistory);
+	_Show_Page(m_pLegend);
+	_Show_Page(m_pAttributes);
+#endif
+}
+
+//---------------------------------------------------------
+CACTIVE::~CACTIVE(void)
+{
+	g_pACTIVE		= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CACTIVE::Set_Active(CWKSP_Base_Item *pItem)
+{
+	if( pItem == m_pItem )
+	{
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	CWKSP_Base_Item	*pLegend, *pHistory;
+
+	m_pItem		= pItem;
+	m_pLayer	= NULL;
+	pLegend		= NULL;
+	pHistory	= NULL;
+
+	STATUSBAR_Set_Text(SG_T(""), STATUSBAR_VIEW_X);
+	STATUSBAR_Set_Text(SG_T(""), STATUSBAR_VIEW_Y);
+	STATUSBAR_Set_Text(SG_T(""), STATUSBAR_VIEW_Z);
+
+	if( m_pParameters )
+	{
+		m_pParameters->Set_Parameters(m_pItem);
+	}
+
+	Update_Description();
+
+	if( m_pItem == NULL )
+	{
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	switch( m_pItem->Get_Type() )
+	{
+	default:
+		break;
+
+	case WKSP_ITEM_Map:
+		pLegend		= m_pItem;
+		break;
+
+	case WKSP_ITEM_Map_Layer:
+		pLegend		= pHistory	= m_pLayer	= ((CWKSP_Map_Layer *)m_pItem)->Get_Layer();
+		break;
+
+	case WKSP_ITEM_Table:
+		pHistory	= m_pItem;
+		break;
+
+	case WKSP_ITEM_Shapes:
+	case WKSP_ITEM_TIN:
+	case WKSP_ITEM_PointCloud:
+	case WKSP_ITEM_Grid:
+		pLegend		= pHistory	= m_pLayer	= (CWKSP_Layer *)m_pItem;
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( pLegend )
+	{
+		m_pLegend->Set_Item(pLegend);
+
+		_Show_Page(m_pLegend);
+	}
+	else
+	{
+		_Hide_Page(m_pLegend);
+	}
+
+	if( pHistory )
+	{
+		m_pHistory->Set_Item(pHistory);
+
+		_Show_Page(m_pHistory);
+	}
+	else
+	{
+		_Hide_Page(m_pHistory);
+	}
+
+	if( m_pLayer )
+	{
+		m_pAttributes->Set_Layer(m_pLayer);
+
+		_Show_Page(m_pAttributes);
+	}
+	else
+	{
+		_Hide_Page(m_pAttributes);
+	}
+
+	//-----------------------------------------------------
+	if( g_pData_Buttons )
+	{
+		g_pData_Buttons->Refresh(false);
+	}
+
+	if( g_pMap_Buttons )
+	{
+		g_pMap_Buttons->Refresh(false);
+	}
+
+	//-----------------------------------------------------
+	if( m_pLayer )
+	{
+		m_pObject	= m_pLayer->Get_Object();
+
+		if( g_pData->Exists(m_pObject) && m_pObject->Get_ObjectType() == DATAOBJECT_TYPE_Shapes && ((CSG_Shapes *)m_pObject)->Get_Selection_Count() > 0 )
+		{
+			g_pData->Update_Views(m_pObject);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CACTIVE::_Show_Page(wxWindow *pPage)
+{
+	int		Image_ID	= -1;
+
+	//-----------------------------------------------------
+	if( pPage == m_pParameters )	Image_ID	= IMG_PARAMETERS;
+	if( pPage == m_pDescription )	Image_ID	= IMG_DESCRIPTION;
+	if( pPage == m_pHistory )		Image_ID	= IMG_HISTORY;
+	if( pPage == m_pLegend )		Image_ID	= IMG_LEGEND;
+	if( pPage == m_pAttributes )	Image_ID	= IMG_ATTRIBUTES;
+
+	//-----------------------------------------------------
+	if( pPage )
+	{
+		for(int i=0; i<(int)GetPageCount(); i++)
+		{
+			if( GetPage(i) == pPage )
+			{
+				return( true );
+			}
+		}
+
+		AddPage(pPage, pPage->GetName(), false, Image_ID);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CACTIVE::_Hide_Page(wxWindow *pPage)
+{
+#ifndef ACTIVE_SHOW_ALL_PAGES
+	for(int i=0; i<(int)GetPageCount(); i++)
+	{
+		if( GetPage(i) == pPage )
+		{
+			if( i == GetSelection() )
+			{
+				SetSelection(i - 1);
+			}
+
+			RemovePage(i);
+
+			return( true );
+		}
+	}
+#endif
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CACTIVE::Update_Description(void)
+{
+	if( m_pItem != NULL )
+	{
+		STATUSBAR_Set_Text(m_pItem->Get_Name(), STATUSBAR_ACTIVE);
+
+		//-------------------------------------------------
+		if( m_pDescription )
+		{
+			switch( m_pItem->Get_Type() )
+			{
+			default:
+				m_pDescription->SetPage(m_pItem->Get_Description());
+				break;
+
+			case WKSP_ITEM_Module:
+				{
+					wxFileName	FileName;
+
+					FileName.Assign		(((CWKSP_Module *)m_pItem)->Get_File_Name());
+					FileName.AppendDir	(FileName.GetName());
+					FileName.SetName	(wxString::Format(wxT("%s_%02d"), FileName.GetName().c_str(), m_pItem->Get_Index()));
+
+					FileName.SetExt		(wxT("html"));
+
+					if( !FileName.FileExists() || !m_pDescription->LoadPage(FileName.GetFullPath()) )
+					{
+						FileName.SetExt		(wxT("htm"));
+
+						if( !FileName.FileExists() || !m_pDescription->LoadPage(FileName.GetFullPath()) )
+						{
+							m_pDescription->SetPage(m_pItem->Get_Description());
+						}
+					}
+				}
+				break;
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		STATUSBAR_Set_Text(wxT(""), STATUSBAR_ACTIVE);
+
+		if( m_pDescription )
+		{
+			m_pDescription->SetPage(LNG("[TXT] No description available"));
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CACTIVE::Update(CWKSP_Base_Item *pItem, bool bSave)
+{
+	if( m_pItem && m_pItem == pItem )
+	{
+		if( m_pParameters )
+		{
+			m_pParameters->Update_Parameters(pItem->Get_Parameters(), bSave);
+		}
+
+		if( !bSave )
+		{
+			Update_Description();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CACTIVE::Update_DataObjects(void)
+{
+	if( m_pParameters )
+	{
+		m_pParameters->Update_DataObjects();
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,143 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      ACTIVE.h                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/notebook.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE : public wxNotebook
+{
+public:
+	CACTIVE(wxWindow *pParent);
+	virtual ~CACTIVE(void);
+
+	void							Add_Pages				(void);
+
+	class CACTIVE_Parameters *		Get_Parameters			(void)	{	return( m_pParameters );	}
+	class CACTIVE_Description *		Get_Description			(void)	{	return( m_pDescription );	}
+	class CACTIVE_History *			Get_History				(void)	{	return( m_pHistory );	}
+	class CACTIVE_Attributes *		Get_Attributes			(void)	{	return( m_pAttributes );	}
+	class CACTIVE_Legend *			Get_Legend				(void)	{	return( m_pLegend );		}
+
+	bool							Set_Active				(class CWKSP_Base_Item *pItem);
+	class CWKSP_Base_Item *			Get_Item				(void)	{	return( m_pItem );			}
+	class CWKSP_Layer *				Get_Layer				(void)	{	return( m_pLayer );			}
+
+	bool							Update					(class CWKSP_Base_Item *pItem, bool bSave);
+	bool							Update_DataObjects		(void);
+	bool							Update_Description		(void);
+
+
+private:
+
+	class CACTIVE_Parameters		*m_pParameters;
+
+	class CACTIVE_Description		*m_pDescription;
+
+	class CACTIVE_History			*m_pHistory;
+
+	class CACTIVE_Attributes		*m_pAttributes;
+
+	class CACTIVE_Legend			*m_pLegend;
+
+	class CWKSP_Base_Item			*m_pItem;
+
+	class CWKSP_Layer				*m_pLayer;
+
+	class CSG_Data_Object			*m_pObject;
+
+
+	bool							_Show_Page				(wxWindow *pPage);
+	bool							_Hide_Page				(wxWindow *pPage);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CACTIVE						*g_pACTIVE;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               ACTIVE_HTMLExtraInfo.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_controls.h"
+
+#include "helper.h"
+
+#include "active_HTMLExtraInfo.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CACTIVE_HTMLExtraInfo, wxHtmlWindow)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE_HTMLExtraInfo, wxHtmlWindow)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE_HTMLExtraInfo::CACTIVE_HTMLExtraInfo(wxWindow *pParent)
+	: wxHtmlWindow(pParent, ID_WND_ACTIVE_HTMLEXTRAINFO , wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxSUNKEN_BORDER)
+{
+}
+
+//---------------------------------------------------------
+CACTIVE_HTMLExtraInfo::~CACTIVE_HTMLExtraInfo(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_HTMLExtraInfo::OnLinkClicked(const wxHtmlLinkInfo &Link)
+{
+	Open_WebBrowser(Link.GetHref());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_HTMLExtraInfo.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,98 @@
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               ACTIVE_HTMLExtraInfo.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_HTMLExtraInfo_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_HTMLExtraInfo_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/html/htmlwin.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE_HTMLExtraInfo : public wxHtmlWindow
+{
+	DECLARE_CLASS(CACTIVE_HTMLExtraInfo)
+
+public:
+	CACTIVE_HTMLExtraInfo(wxWindow *pParent);
+	virtual ~CACTIVE_HTMLExtraInfo(void);
+
+	virtual void			OnLinkClicked	(const wxHtmlLinkInfo &Link);
+
+
+private:
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_HTMLExtraInfo_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,258 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 ACTIVE_Attributes.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/event.h>
+#include <wx/button.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_dialogs.h"
+
+#include "wksp_layer.h"
+#include "view_table_control.h"
+
+#include "active_attributes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CACTIVE_Attributes, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE_Attributes, wxPanel)
+	EVT_SIZE			(CACTIVE_Attributes::On_Size)
+
+	EVT_BUTTON			(ID_BTN_APPLY	, CACTIVE_Attributes::On_Apply)
+	EVT_UPDATE_UI		(ID_BTN_APPLY	, CACTIVE_Attributes::On_Apply_UI)
+	EVT_BUTTON			(ID_BTN_RESTORE	, CACTIVE_Attributes::On_Restore)
+	EVT_UPDATE_UI		(ID_BTN_RESTORE	, CACTIVE_Attributes::On_Restore_UI)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE_Attributes::CACTIVE_Attributes(wxWindow *pParent)
+	: wxPanel(pParent, ID_WND_INFO_ATTRIBUTES)//, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
+{
+	m_pAttributes	= new CSG_Table;
+	m_pControl		= new CVIEW_Table_Control(this, m_pAttributes, TABLE_CTRL_FIXED_TABLE|TABLE_CTRL_COL1ISLABEL);
+	m_pLayer		= NULL;
+
+	//-----------------------------------------------------
+	m_Btn_Apply		= new wxButton(this, ID_BTN_APPLY	, CTRL_Get_Name(ID_BTN_APPLY)	, wxPoint(0, 0));
+	m_Btn_Restore	= new wxButton(this, ID_BTN_RESTORE	, CTRL_Get_Name(ID_BTN_RESTORE)	, wxPoint(0, 0));
+
+	m_btn_height	= m_Btn_Apply->GetDefaultSize().y;
+
+	//-----------------------------------------------------
+	m_pAttributes->Set_Modified(false);
+}
+
+//---------------------------------------------------------
+CACTIVE_Attributes::~CACTIVE_Attributes(void)
+{
+	delete(m_pAttributes);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::On_Size(wxSizeEvent &WXUNUSED(event))
+{
+	_Set_Positions();
+}
+
+//---------------------------------------------------------
+#define BUTTON_DIST			1
+#define BUTTON_DIST2		2 * BUTTON_DIST
+
+#define SET_BTN_POS(BTN)	if( BTN->IsShown() ) { BTN->SetSize(r); r.SetLeft(r.GetLeft() + r.GetWidth() + BUTTON_DIST2); }
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::_Set_Positions(void)
+{
+	int		nButtons	= 2;
+	wxRect	r(wxPoint(0, 0), GetSize());
+
+	r.SetHeight(r.GetHeight() - m_btn_height);
+	m_pControl->SetSize(r);
+
+	r.SetTop(r.GetHeight() + BUTTON_DIST);
+	r.SetHeight(m_btn_height - BUTTON_DIST);
+	r.SetWidth(r.GetWidth() / nButtons - BUTTON_DIST2);
+	r.SetLeft(BUTTON_DIST);
+
+	SET_BTN_POS(m_Btn_Apply);
+	SET_BTN_POS(m_Btn_Restore);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::On_Apply(wxCommandEvent &event)
+{
+	_Save_Changes();
+}
+
+void CACTIVE_Attributes::On_Apply_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(m_pAttributes->is_Modified());
+}
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::On_Restore(wxCommandEvent &event)
+{
+	Set_Attributes();
+}
+
+void CACTIVE_Attributes::On_Restore_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(m_pAttributes->is_Modified());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::Set_Layer(CWKSP_Layer *pLayer)
+{
+	if( m_pLayer != pLayer )
+	{
+		_Save_Changes();
+
+		m_pLayer	= pLayer;
+
+		Set_Attributes();
+	}
+}
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::Set_Attributes(void)
+{
+	if( m_pLayer && m_pLayer->Edit_Get_Attributes()->is_Valid() )
+	{
+		_Save_Changes();
+
+		m_pAttributes->Assign(m_pLayer->Edit_Get_Attributes());
+
+		m_pControl->Set_Labeling(m_pLayer->Get_Object()->Get_ObjectType() == DATAOBJECT_TYPE_Shapes);
+	}
+	else
+	{
+		m_pAttributes->Destroy();
+	}
+
+	m_pAttributes->Set_Modified(false);
+
+	m_pControl->Update_Table();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Attributes::_Save_Changes(void)
+{
+	if( m_pLayer && m_pAttributes->is_Modified() && DLG_Message_Confirm(LNG("[DLG] Save changes?"), LNG("[CAP] Attributes")) )
+	{
+		m_pLayer->Edit_Get_Attributes()->Assign_Values(m_pAttributes);
+		m_pLayer->Edit_Set_Attributes();
+
+		m_pAttributes->Set_Modified(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_attributes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,132 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 ACTIVE_Attributes.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Attributes_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Attributes_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE_Attributes : public wxPanel
+{
+	DECLARE_CLASS(CACTIVE_Attributes)
+
+public:
+	CACTIVE_Attributes(wxWindow *pParent);
+	virtual ~CACTIVE_Attributes(void);
+
+	void						On_Size				(wxSizeEvent &event);
+
+	void						On_Apply			(wxCommandEvent &event);
+	void						On_Apply_UI			(wxUpdateUIEvent &event);
+	void						On_Restore			(wxCommandEvent &event);
+	void						On_Restore_UI		(wxUpdateUIEvent &event);
+
+	void						Set_Layer			(class CWKSP_Layer *pLayer);
+
+	void						Set_Attributes		(void);
+
+
+protected:
+
+	int							m_btn_height;
+
+	class wxButton				*m_Btn_Restore, *m_Btn_Apply;
+
+	class CSG_Table				*m_pAttributes;
+
+	class CVIEW_Table_Control	*m_pControl;
+
+	class CWKSP_Layer			*m_pLayer;
+
+
+	void						_Set_Positions		(void);
+
+	void						_Save_Changes		(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Attributes_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,147 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 ACTIVE_Description.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/clipbrd.h>
+#include <wx/dataobj.h>
+
+#include "res_controls.h"
+
+#include "helper.h"
+
+#include "active_description.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CACTIVE_Description, wxHtmlWindow)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE_Description, wxHtmlWindow)
+	EVT_KEY_DOWN		(CACTIVE_Description::On_Key_Down)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE_Description::CACTIVE_Description(wxWindow *pParent)
+	: wxHtmlWindow(pParent, ID_WND_ACTIVE_DESCRIPTION , wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxSUNKEN_BORDER)
+{
+}
+
+//---------------------------------------------------------
+CACTIVE_Description::~CACTIVE_Description(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Description::On_Key_Down(wxKeyEvent &event)
+{
+	if( event.ControlDown() )
+	{
+		switch( event.GetKeyCode() )
+		{
+		default:
+			event.Skip();
+			break;
+
+		case 'C':
+		case 'c':
+			if( wxTheClipboard->Open() )
+			{
+				wxTheClipboard->SetData(new wxTextDataObject(SelectionToText()));
+				wxTheClipboard->Close();
+			}
+			break;
+		}
+
+	}
+}
+
+//---------------------------------------------------------
+void CACTIVE_Description::OnLinkClicked(const wxHtmlLinkInfo &Link)
+{
+	Open_WebBrowser(Link.GetHref());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_description.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 ACTIVE_Description.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Description_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Description_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/html/htmlwin.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE_Description : public wxHtmlWindow
+{
+	DECLARE_CLASS(CACTIVE_Description)
+
+public:
+	CACTIVE_Description(wxWindow *pParent);
+	virtual ~CACTIVE_Description(void);
+
+	void						On_Key_Down		(wxKeyEvent &event);
+
+	virtual void				OnLinkClicked	(const wxHtmlLinkInfo &Link);
+
+
+private:
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Description_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,249 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  ACTIVE_History.cpp                   //
+//                                                       //
+//          Copyright (C) 2008 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/imaglist.h>
+
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "wksp_table.h"
+#include "wksp_layer.h"
+
+#include "active_history.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_DATA	= 0,
+	IMG_DATE,
+	IMG_NAME,
+	IMG_ENTRY,
+	IMG_ENTRY_DATA
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CACTIVE_History, wxTreeCtrl)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE_History, wxTreeCtrl)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE_History::CACTIVE_History(wxWindow *pParent)
+	: wxTreeCtrl(pParent, ID_WND_ACTIVE_HISTORY , wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS)
+{
+	AssignImageList(new wxImageList(IMG_SIZE_TREECTRL, IMG_SIZE_TREECTRL, true, 0));
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_DATA_MANAGER);	// DATA
+	IMG_ADD_TO_TREECTRL(ID_IMG_NB_INFO_EXECUTION);	// DATE
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MODULE);		// NAME
+	IMG_ADD_TO_TREECTRL(ID_IMG_TB_INFO);			// ENTRY
+	IMG_ADD_TO_TREECTRL(ID_IMG_TB_MAP_ZOOM_NEXT);	// ENTRY_DATA
+
+	Set_Item(NULL);
+}
+
+//---------------------------------------------------------
+CACTIVE_History::~CACTIVE_History(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CACTIVE_History::Set_Item(CWKSP_Base_Item *pItem)
+{
+	CSG_Data_Object	*pObject	= NULL;
+
+	if( pItem )
+	{
+		switch( pItem->Get_Type() )
+		{
+		default:
+			pObject	= NULL;
+			break;
+
+		case WKSP_ITEM_Table:
+			pObject	= ((CWKSP_Table *)pItem)->Get_Table();
+			break;
+
+		case WKSP_ITEM_Shapes:
+		case WKSP_ITEM_TIN:
+		case WKSP_ITEM_PointCloud:
+		case WKSP_ITEM_Grid:
+			pObject	= ((CWKSP_Layer *)pItem)->Get_Object();
+			break;
+		}
+	}
+
+	Freeze();
+
+	DeleteAllItems();
+
+	if( pObject == NULL || pObject->Get_History().Get_Children_Count() <= 0 )
+	{
+		AddRoot(LNG("No history available"), IMG_DATA);
+	}
+	else
+	{
+		_Add_History(AddRoot(pObject->Get_Name(), IMG_DATA), pObject->Get_History());
+
+		Expand(GetRootItem());
+	}
+
+	Thaw();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CACTIVE_History::_Add_History(wxTreeItemId Parent, CSG_MetaData &History)
+{
+	if( Parent.IsOk() && History.Get_Children_Count() > 0 )
+	{
+		CSG_MetaData	*pEntry;
+
+		if( (pEntry = History.Get_Child("MODULE")) != NULL )
+		{
+			AppendItem(Parent, pEntry->Get_Content().c_str(), IMG_NAME);
+		}
+
+		for(int i=0; i<History.Get_Children_Count(); i++)
+		{
+			wxTreeItemId	Entry;
+			wxString		s;
+			CSG_String		Name, Type;
+
+			pEntry	= History.Get_Child(i);
+
+			if( !pEntry->Get_Name().Cmp(SG_T("MODULE")) )
+			{
+				// nop
+			}
+			else if( !pEntry->Get_Name().Cmp(SG_T("OPTION")) )
+			{
+				if( !pEntry->Get_Property(SG_T("name"), Name) )	Name	= LNG("Option");
+
+				Entry	= AppendItem(Parent, wxString::Format(wxT("%s [%s]"), Name.c_str(), pEntry->Get_Content().c_str()), IMG_ENTRY);
+			}
+			else if( !pEntry->Get_Name().Cmp(SG_T("DATA")) )
+			{
+				if( !pEntry->Get_Property(SG_T("name"), Name) )	Name	= LNG("Data");
+				if( !pEntry->Get_Property(SG_T("type"), Type) )	Type	= LNG("unknown type");
+
+				Entry	= AppendItem(Parent, wxString::Format(wxT("%s [%s]"), Name.c_str(), Type.c_str()), IMG_ENTRY_DATA);
+
+				_Add_History(Entry, *pEntry);
+			}
+			else if( pEntry->Get_Children_Count() )
+			{
+				Entry	= AppendItem(Parent, wxString::Format(wxT("%s"), pEntry->Get_Name().c_str()), IMG_NAME);
+
+				_Add_History(Entry, *pEntry);
+			}
+			else
+			{
+				Entry	= AppendItem(Parent, wxString::Format(wxT("%s [%s]"), pEntry->Get_Name().c_str(), pEntry->Get_Content().c_str()), IMG_ENTRY_DATA);
+			}
+
+			if( Entry.IsOk() )
+			{
+				Expand(Entry);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_history.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   ACTIVE_History.h                    //
+//                                                       //
+//          Copyright (C) 2008 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_History_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_History_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/treectrl.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE_History : public wxTreeCtrl
+{
+	DECLARE_CLASS(CACTIVE_History)
+
+public:
+	CACTIVE_History(wxWindow *pParent);
+	virtual ~CACTIVE_History(void);
+
+
+	bool				Set_Item				(class CWKSP_Base_Item *pItem);
+
+
+private:
+
+
+	bool				_Add_History			(wxTreeItemId Parent, CSG_MetaData &History);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_History_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,206 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   active_legend.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_controls.h"
+
+#include "helper.h"
+
+#include "wksp_map.h"
+#include "wksp_layer.h"
+#include "wksp_layer_legend.h"
+
+#include "active_legend.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SCROLL_RATE		5
+
+#define SCROLL_BAR_DX	wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)
+#define SCROLL_BAR_DY	wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CACTIVE_Legend, wxScrolledWindow)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE_Legend, wxScrolledWindow)
+	EVT_KEY_DOWN		(CACTIVE_Legend::On_Key_Down)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE_Legend::CACTIVE_Legend(wxWindow *pParent)
+	: wxScrolledWindow(pParent, ID_WND_ACTIVE_LEGEND, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE)
+{
+	SYS_Set_Color_BG(this, wxSYS_COLOUR_WINDOW);
+
+	m_pItem		= NULL;
+
+	m_xScroll	= 0;
+	m_yScroll	= 0;
+
+	m_Layout	= LEGEND_LAYOUT_VERTICAL;	// LEGEND_LAYOUT_HORIZONTAL;
+	m_Zoom		= 1.0;
+}
+
+//---------------------------------------------------------
+CACTIVE_Legend::~CACTIVE_Legend(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Legend::Set_Item(CWKSP_Base_Item *pItem)
+{
+	m_pItem	= pItem;
+
+	Refresh();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Legend::On_Key_Down(wxKeyEvent &event)
+{
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Legend::OnDraw(wxDC &dc)
+{
+	wxPoint	p(5, 5);
+	wxSize	s(0, 0);
+
+	if( m_pItem && m_pItem->GetId().IsOk() )
+	{
+		switch( m_pItem->Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Grid:
+		case WKSP_ITEM_Shapes:
+		case WKSP_ITEM_TIN:
+		case WKSP_ITEM_PointCloud:
+			((CWKSP_Layer *)m_pItem)->Get_Legend()->Draw(dc, m_Zoom, 1.0, p, &s, (m_Layout & LEGEND_LAYOUT_VERTICAL) != 0);
+			break;
+
+		case WKSP_ITEM_Map:
+			((CWKSP_Map   *)m_pItem)->Draw_Legend(dc, m_Zoom, 1.0, p, &s, m_Layout);
+			break;
+		}
+	}
+
+	s.x	+= p.x + SCROLL_BAR_DX;
+	s.y	+= p.y + SCROLL_BAR_DY;
+
+	if(	m_xScroll != s.x || m_yScroll != s.y )
+	{
+		m_xScroll	= s.x;
+		m_yScroll	= s.y;
+
+		SetScrollbars(SCROLL_RATE, SCROLL_RATE, m_xScroll / SCROLL_RATE, m_yScroll / SCROLL_RATE);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_legend.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   active_legend.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Legend_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Legend_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/scrolwin.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE_Legend : public wxScrolledWindow
+{
+	DECLARE_CLASS(CACTIVE_Legend)
+
+public:
+	CACTIVE_Legend(wxWindow *pParent);
+	virtual ~CACTIVE_Legend(void);
+
+	void						On_Key_Down		(wxKeyEvent &event);
+
+	virtual void				OnDraw			(wxDC &dc);
+
+	void						Set_Item		(class CWKSP_Base_Item *pItem);
+
+
+private:
+
+	int							m_xScroll, m_yScroll, m_Layout;
+
+	double						m_Zoom;
+
+	class CWKSP_Base_Item		*m_pItem;
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Legend_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,352 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 ACTIVE_Parameters.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/event.h>
+#include <wx/button.h>
+
+#include "res_controls.h"
+
+#include "wksp_layer.h"
+#include "wksp_module.h"
+#include "wksp_map_manager.h"
+
+#include "parameters_control.h"
+
+#include "active_parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CACTIVE_Parameters, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CACTIVE_Parameters, wxPanel)
+	EVT_SIZE			(CACTIVE_Parameters::On_Size)
+
+	EVT_BUTTON			(ID_BTN_APPLY	, CACTIVE_Parameters::On_Apply)
+	EVT_UPDATE_UI		(ID_BTN_APPLY	, CACTIVE_Parameters::On_Apply_UI)
+	EVT_BUTTON			(ID_BTN_RESTORE	, CACTIVE_Parameters::On_Restore)
+	EVT_UPDATE_UI		(ID_BTN_RESTORE	, CACTIVE_Parameters::On_Restore_UI)
+
+	EVT_BUTTON			(ID_BTN_EXECUTE	, CACTIVE_Parameters::On_Execute)
+	EVT_BUTTON			(ID_BTN_LOAD	, CACTIVE_Parameters::On_Load)
+	EVT_BUTTON			(ID_BTN_SAVE	, CACTIVE_Parameters::On_Save)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CACTIVE_Parameters::CACTIVE_Parameters(wxWindow *pParent)
+	: wxPanel(pParent, ID_WND_ACTIVE_PARAMETERS, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
+{
+	m_pItem			= NULL;
+	m_pControl		= new CParameters_Control(this);
+
+	//-----------------------------------------------------
+	m_Btn_Apply		= new wxButton(this, ID_BTN_APPLY	, CTRL_Get_Name(ID_BTN_APPLY)	, wxPoint(0, 0));
+	m_Btn_Restore	= new wxButton(this, ID_BTN_RESTORE	, CTRL_Get_Name(ID_BTN_RESTORE)	, wxPoint(0, 0));
+	m_Btn_Execute	= new wxButton(this, ID_BTN_EXECUTE	, CTRL_Get_Name(ID_BTN_EXECUTE)	, wxPoint(0, 0));
+	m_Btn_Load		= new wxButton(this, ID_BTN_LOAD	, CTRL_Get_Name(ID_BTN_LOAD)	, wxPoint(0, 0));
+	m_Btn_Save		= new wxButton(this, ID_BTN_SAVE	, CTRL_Get_Name(ID_BTN_SAVE)	, wxPoint(0, 0));
+
+	m_Btn_Apply		->Show(false);
+	m_Btn_Restore	->Show(false);
+	m_Btn_Execute	->Show(false);
+	m_Btn_Load		->Show(false);
+	m_Btn_Save		->Show(false);
+
+	m_btn_height	= m_Btn_Apply->GetDefaultSize().y;
+
+	m_pControl->Set_Parameters(NULL);
+
+	Set_Parameters(NULL);
+}
+
+//---------------------------------------------------------
+CACTIVE_Parameters::~CACTIVE_Parameters(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::On_Size(wxSizeEvent &WXUNUSED(event))
+{
+	_Set_Positions();
+}
+
+//---------------------------------------------------------
+#define BUTTON_DIST			1
+#define BUTTON_DIST2		2 * BUTTON_DIST
+
+#define SET_BTN_POS(BTN)	if( BTN->IsShown() ) { BTN->SetSize(r); r.SetLeft(r.GetLeft() + r.GetWidth() + BUTTON_DIST2); }
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::_Set_Positions(void)
+{
+	int		nButtons;
+
+	nButtons	= (m_Btn_Apply	->IsShown() ? 1 : 0)
+				+ (m_Btn_Restore->IsShown() ? 1 : 0)
+				+ (m_Btn_Execute->IsShown() ? 1 : 0)
+				+ (m_Btn_Load	->IsShown() ? 1 : 0)
+				+ (m_Btn_Save	->IsShown() ? 1 : 0);
+
+	if( nButtons > 0 )
+	{
+		wxSize	Size(GetClientSize());
+
+		Size.y	-= m_btn_height;
+
+		m_pControl->SetSize(Size);
+
+		wxRect	r(wxPoint(0, 0), Size);
+
+		r.SetTop(r.GetHeight() + BUTTON_DIST);
+		r.SetHeight(m_btn_height - BUTTON_DIST);
+		r.SetWidth(r.GetWidth() / nButtons - BUTTON_DIST2);
+		r.SetLeft(BUTTON_DIST);
+
+		SET_BTN_POS(m_Btn_Apply);
+		SET_BTN_POS(m_Btn_Restore);
+		SET_BTN_POS(m_Btn_Execute);
+		SET_BTN_POS(m_Btn_Load);
+		SET_BTN_POS(m_Btn_Save);
+	}
+	else
+	{
+		m_pControl->SetSize(GetClientSize());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::On_Apply(wxCommandEvent &event)
+{
+	if( m_pItem )
+	{
+		Update_Parameters(m_pItem->Get_Parameters(), true);
+	}
+}
+
+void CACTIVE_Parameters::On_Apply_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(m_pControl->is_Modified());
+}
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::On_Restore(wxCommandEvent &event)
+{
+	Restore_Parameters();
+}
+
+void CACTIVE_Parameters::On_Restore_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(m_pControl->is_Modified());
+}
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::On_Execute(wxCommandEvent &event)
+{
+	if( m_pItem && m_pItem->Get_Type() == WKSP_ITEM_Module )
+	{
+		m_pControl->Save_Changes(true);
+
+		((CWKSP_Module *)m_pItem)->Execute(false);
+	}
+}
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::On_Load(wxCommandEvent &event)
+{
+	m_pControl->Load();
+}
+
+//---------------------------------------------------------
+void CACTIVE_Parameters::On_Save(wxCommandEvent &event)
+{
+	m_pControl->Save();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CACTIVE_Parameters::Set_Parameters(CWKSP_Base_Item *pItem)
+{
+	if( m_pItem && m_pControl->Save_Changes(false) )
+	{
+		m_pItem->Parameters_Changed();
+
+		switch( m_pItem->Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Shapes:
+		case WKSP_ITEM_TIN:
+		case WKSP_ITEM_PointCloud:
+		case WKSP_ITEM_Grid:
+			g_pMaps->Update((CWKSP_Layer *)m_pItem, false);
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	if( m_pItem != pItem )
+	{
+		m_pItem	= pItem;
+
+		if( m_pItem && m_pItem->Get_Parameters() )
+		{
+			m_pControl->Set_Parameters(m_pItem->Get_Parameters());
+
+			m_Btn_Apply		->Show(true);
+			m_Btn_Restore	->Show(true);
+			m_Btn_Execute	->Show(m_pItem->Get_Type() == WKSP_ITEM_Module);
+			m_Btn_Load		->Show(true);
+			m_Btn_Save		->Show(true);
+		}
+		else
+		{
+			m_pControl->Set_Parameters(NULL);
+
+			m_Btn_Apply		->Show(false);
+			m_Btn_Restore	->Show(false);
+			m_Btn_Execute	->Show(false);
+			m_Btn_Load		->Show(false);
+			m_Btn_Save		->Show(false);
+		}
+
+		if( m_pItem )
+		{
+			_Set_Positions();
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CACTIVE_Parameters::Update_Parameters(CSG_Parameters *pParameters, bool bSave)
+{
+	if( pParameters && m_pItem && (m_pItem->Get_Parameters() == pParameters || m_pControl->Get_Parameters() == pParameters) )
+	{
+		if( bSave )
+		{
+			m_pControl->Save_Changes(true);
+
+			m_pItem->Parameters_Changed();
+		}
+		else
+		{
+			m_pControl->Set_Parameters(pParameters);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CACTIVE_Parameters::Update_DataObjects(void)
+{
+	return( m_pControl->Update_DataObjects() );
+}
+
+//---------------------------------------------------------
+bool CACTIVE_Parameters::Restore_Parameters(void)
+{
+	return( m_pControl->Restore() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/active_parameters.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,132 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 ACTIVE_Parameters.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Parameters_H
+#define _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Parameters_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CACTIVE_Parameters : public wxPanel
+{
+	DECLARE_CLASS(CACTIVE_Parameters)
+
+public:
+	CACTIVE_Parameters(wxWindow *pParent);
+	virtual ~CACTIVE_Parameters(void);
+
+	void						On_Size				(wxSizeEvent     &event);
+
+	void						On_Apply			(wxCommandEvent  &event);
+	void						On_Apply_UI			(wxUpdateUIEvent &event);
+	void						On_Restore			(wxCommandEvent  &event);
+	void						On_Restore_UI		(wxUpdateUIEvent &event);
+	void						On_Execute			(wxCommandEvent  &event);
+	void						On_Load				(wxCommandEvent  &event);
+	void						On_Save				(wxCommandEvent  &event);
+
+	bool						Set_Parameters		(class CWKSP_Base_Item *pItem);
+	bool						Update_Parameters	(class CSG_Parameters *pParameters, bool bSave);
+	bool						Update_DataObjects	(void);
+	bool						Restore_Parameters	(void);
+
+
+private:
+
+	int							m_btn_height;
+
+	class wxButton				*m_Btn_Restore, *m_Btn_Apply, *m_Btn_Execute, *m_Btn_Load, *m_Btn_Save;
+
+	class CWKSP_Base_Item		*m_pItem;
+
+	class CParameters_Control	*m_pControl;
+
+
+	void						_Set_Positions		(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__ACTIVE_Parameters_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,351 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    Callback.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_data_manager.h"
+
+#include "callback.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int		Callback(TSG_UI_Callback_ID ID, long Param_1, long Param_2)
+{
+	int		Result, *iArray;
+
+	Result	= 1;
+
+	//-----------------------------------------------------
+	switch( ID )
+	{
+	default:
+
+		Result	= 0;
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_GET_OKAY:
+
+		Result	= PROCESS_Get_Okay(Param_1 != 0);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_OKAY:
+
+		Result	= PROCESS_Set_Okay(Param_1 != 0);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_PROGRESS:
+
+		Result	= PROGRESSBAR_Set_Position(*((double *)Param_1), *((double *)Param_2));
+
+		break;
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_READY:
+
+		Result	= PROGRESSBAR_Set_Position(0);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_PROCESS_SET_TEXT:
+
+		STATUSBAR_Set_Text((wxChar *)Param_1);
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_MESSAGE_ADD:
+
+		iArray	= (int *)Param_2;
+
+		MSG_General_Add		((wxChar *)Param_1, iArray[0] != 0, iArray[0] != 0, (TSG_UI_MSG_STYLE)iArray[1]);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_MESSAGE_ADD_ERROR:
+
+		MSG_Error_Add		((wxChar *)Param_1, true);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_MESSAGE_ADD_EXECUTION:
+
+		iArray	= (int *)Param_2;
+
+		MSG_Execution_Add	((wxChar *)Param_1, iArray[0] != 0, iArray[0] != 0, (TSG_UI_MSG_STYLE)iArray[1]);
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_MESSAGE:
+
+		DLG_Message_Show((wxChar *)Param_1, (wxChar *)Param_2);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_CONTINUE:
+
+		Result	= DLG_Message_Confirm((wxChar *)Param_1, (wxChar *)Param_2);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_ERROR:
+
+		Result	= DLG_Message_Show_Error((wxChar *)Param_1, (wxChar *)Param_2);
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_DLG_PARAMETERS:
+
+		Result	= DLG_Parameters((CSG_Parameters *)Param_1) ? 1 : 0;
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_FIND_BY_FILE:
+
+		Result	= (long)g_pData->Get_byFileName((const wxChar *)Param_1, Param_2);
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_CHECK:
+
+		Result	= g_pData->Exists((CSG_Data_Object *)Param_1, Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_ADD:
+
+		Result	= g_pData->Add((CSG_Data_Object *)Param_1) ? 1 : 0;
+
+		if( Result && Param_2 )
+		{
+			g_pData->Show((CSG_Data_Object *)Param_1, false);
+		}
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_UPDATE:
+
+		Result	= g_pData->Update((CSG_Data_Object *)Param_1, (CSG_Parameters *)Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_SHOW:
+
+		Result	= g_pData->Show((CSG_Data_Object *)Param_1, Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_ASIMAGE:
+
+		Result	= g_pData->asImage((CSG_Data_Object *)Param_1, (CSG_Grid *)Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_COLORS_GET:
+
+		Result	= g_pData->Get_Colors((CSG_Data_Object *)Param_1, (CSG_Colors *)Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_COLORS_SET:
+
+		Result	= g_pData->Set_Colors((CSG_Data_Object *)Param_1, (CSG_Colors *)Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_PARAMS_GET:
+
+		Result	= g_pData->Get_Parameters((CSG_Data_Object *)Param_1, (CSG_Parameters *)Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_PARAMS_SET:
+
+		Result	= g_pData->Set_Parameters((CSG_Data_Object *)Param_1, (CSG_Parameters *)Param_2) ? 1 : 0;
+
+		break;
+
+
+	//-----------------------------------------------------
+	case CALLBACK_DATAOBJECT_GET_ALL:
+
+		Result	= g_pData->Get_DataObject_List((CSG_Parameters *)Param_1) ? 1 : 0;
+
+		break;
+
+
+	///////////////////////////////////////////////////////
+	//                                                   //
+	//                                                   //
+	//                                                   //
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	case CALLBACK_GUI_GET_WINDOW:
+
+		Result	= (long)MDI_Get_Frame();
+
+		break;
+	}
+
+	return( Result );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_PFNC_UI_Callback	Get_Callback(void)
+{
+	return( &Callback );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/callback.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,92 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Callback.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__Callback_H
+#define _HEADER_INCLUDED__SAGA_GUI__Callback_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+TSG_PFNC_UI_Callback	Get_Callback	(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__Callback_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,411 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DC_Helper.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+#include "dc_helper.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Draw_Edge(wxDC &dc, int Edge_Style, int ax, int ay, int bx, int by)
+{
+	wxPen	oldPen;
+
+	switch( Edge_Style )
+	{
+	//-----------------------------------------------------
+	case EDGE_STYLE_SIMPLE:
+		dc.DrawLine(bx, ay, bx, by);
+		dc.DrawLine(bx, by, ax, by);
+		dc.DrawLine(ax, ay, bx, ay);
+		dc.DrawLine(ax, by, ax, ay);
+		break;
+
+	//-----------------------------------------------------
+	case EDGE_STYLE_STATIC:
+		Draw_Edge(dc, EDGE_STYLE_SUNKEN, ax + 0, ay + 0, bx - 0, by - 0);
+		Draw_Edge(dc, EDGE_STYLE_RAISED, ax + 1, ay + 1, bx - 1, by - 1);
+		break;
+
+	//-----------------------------------------------------
+	case EDGE_STYLE_SUNKEN:
+		oldPen	= dc.GetPen();
+
+		dc.SetPen(wxPen(SYS_Get_Color(wxSYS_COLOUR_BTNHIGHLIGHT), 0, wxSOLID));
+		dc.DrawLine(bx, ay, bx, by);
+		dc.DrawLine(bx, by, ax, by);
+
+		dc.SetPen(wxPen(SYS_Get_Color(wxSYS_COLOUR_BTNSHADOW   ), 0, wxSOLID));
+		dc.DrawLine(ax, by, ax, ay);
+		dc.DrawLine(ax, ay, bx, ay);
+
+		dc.SetPen(oldPen);
+		break;
+
+	//-----------------------------------------------------
+	case EDGE_STYLE_RAISED:
+		oldPen	= dc.GetPen();
+
+		dc.SetPen(wxPen(SYS_Get_Color(wxSYS_COLOUR_BTNSHADOW   ), 0, wxSOLID));
+		dc.DrawLine(bx, ay, bx, by);
+		dc.DrawLine(bx, by, ax, by);
+
+		dc.SetPen(wxPen(SYS_Get_Color(wxSYS_COLOUR_BTNHIGHLIGHT), 0, wxSOLID));
+		dc.DrawLine(ax, by, ax, ay);
+		dc.DrawLine(ax, ay, bx, ay);
+
+		dc.SetPen(oldPen);
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void		Draw_Edge(wxDC &dc, int Edge_Style, wxRect r)
+{
+	Draw_Edge(dc, Edge_Style, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Draw_Rect(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by)
+{
+	Draw_FillRect(dc, Color, ax, ay, bx, by);
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, ax, ay, bx, by);
+}
+
+//---------------------------------------------------------
+void		Draw_Rect(wxDC &dc, wxColour Color, wxRect r)
+{
+	Draw_Rect(dc, Color, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Draw_FillRect(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by)
+{
+	int		i;
+	wxPen	Pen, oldPen;
+
+	//-----------------------------------------------------
+	oldPen	= dc.GetPen();
+	Pen.SetColour(Color);
+	dc.SetPen(Pen);
+
+	if( ax > bx )
+	{
+		i	= ax;	ax	= bx;	bx	= i;
+	}
+
+	if( ay > by )
+	{
+		i	= ay;	ay	= by;	by	= i;
+	}
+
+	//-----------------------------------------------------
+	if( bx - ax < by - ay )
+	{
+		for(i=ax; i<bx; i++)
+		{
+			dc.DrawLine(i, ay, i, by);
+		}
+	}
+	else
+	{
+		for(i=ay; i<by; i++)
+		{
+			dc.DrawLine(ax, i, bx, i);
+		}
+	}
+
+	//-----------------------------------------------------
+	dc.SetPen(oldPen);
+}
+
+//---------------------------------------------------------
+void		Draw_FillRect(wxDC &dc, wxColour Color, wxRect r)
+{
+	Draw_FillRect(dc, Color, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Draw_Text(wxDC &dc, int Align, int x, int y, const wxString &Text)
+{
+	wxCoord	xSize, ySize;
+
+	if( Align != TEXTALIGN_TOPLEFT )
+	{
+		dc.GetTextExtent(Text, &xSize, &ySize);
+
+		//-------------------------------------------------
+		if		( Align & TEXTALIGN_XCENTER )
+		{
+			x	-= xSize / 2;
+		}
+		else if	( Align & TEXTALIGN_RIGHT )
+		{
+			x	-= xSize;
+		}
+
+		//-------------------------------------------------
+		if		( Align & TEXTALIGN_YCENTER )
+		{
+			y	-= ySize / 2;
+		}
+		else if	( Align & TEXTALIGN_BOTTOM )
+		{
+			y	-= ySize;
+		}
+	}
+
+	dc.DrawText(Text, x, y);
+}
+
+//---------------------------------------------------------
+void		Draw_Text(wxDC &dc, int Align, int x, int y, double Angle, const wxString &Text)
+{
+	double	d;
+	wxCoord	xSize, ySize;
+
+	if( Align != TEXTALIGN_TOPLEFT )
+	{
+		dc.GetTextExtent(Text, &xSize, &ySize);
+
+		//-------------------------------------------------
+		d	 = M_DEG_TO_RAD * Angle;
+
+		if		( Align & TEXTALIGN_XCENTER )
+		{
+			x	-= (int)(xSize * cos(d) / 2.0);
+			y	+= (int)(xSize * sin(d) / 2.0);
+		}
+		else if	( Align & TEXTALIGN_RIGHT )
+		{
+			x	-= (int)(xSize * cos(d));
+			y	+= (int)(xSize * sin(d));
+		}
+
+		//-------------------------------------------------
+		d	 = M_DEG_TO_RAD * (Angle - 90.0);
+
+		if		( Align & TEXTALIGN_YCENTER )
+		{
+			x	-= (int)(ySize * cos(d) / 2.0);
+			y	+= (int)(ySize * sin(d) / 2.0);
+		}
+		else if	( Align & TEXTALIGN_BOTTOM )
+		{
+			x	-= (int)(ySize * cos(d));
+			y	+= (int)(ySize * sin(d));
+		}
+	}
+
+	dc.DrawRotatedText(Text, x, y, Angle);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define TEXTSPACE	6
+
+//---------------------------------------------------------
+void		Draw_Scale(wxDC &dc, wxRect r, double zMin, double zMax, bool bHorizontal, bool bAscendent, bool bTickAtTop)
+{
+	int			xOff, yOff, Width, Height, Height_Tick, Decimals, zDC, yDC, Style, x, y, n;
+	double		z, dz, zToDC;
+	wxString	s;
+	wxFont		Font, oldFont;
+
+	//-----------------------------------------------------
+	Style	= bTickAtTop ? 1 : 2;
+
+	Width	= bHorizontal ? r.GetWidth() : r.GetHeight();
+	Height	= bHorizontal ? r.GetHeight() : r.GetWidth();
+
+	if( zMin < zMax && Width > 0 && Height > 0 )
+	{
+		xOff		= r.GetLeft();
+		yOff		= r.GetTop();
+
+		oldFont		= dc.GetFont();
+		yDC			= (int)((Style == 0 ? 0.60 : 0.45) * (double)Height);
+		Font.Create(yDC, wxSWISS, wxNORMAL, wxNORMAL);
+		dc.SetFont(Font);
+
+		Height_Tick	= (int)((Style == 0 ? 1.00 : 0.30) * (double)Height);
+
+		//-------------------------------------------------
+		zToDC		= (double)Width / (zMax - zMin);
+
+		dz			= pow(10.0, floor(log10(zMax - zMin)) - 1.0);
+		Decimals	= dz >= 1.0 ? 0 : (int)floor(-log10(dz));
+
+		s.Printf(wxT("%.*f"), Decimals, zMax);
+		dc.GetTextExtent(s, &zDC, &yDC);
+		while( zToDC * dz < zDC + TEXTSPACE )
+		{
+			dz	*= 2;
+		}
+
+		//-------------------------------------------------
+		z			= dz * floor(zMin / dz);
+		if( Style != 0 && z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			s.Printf(wxT("%.*f"), Decimals, z);
+
+			zDC	= bAscendent ? (int)(zToDC * (z - zMin)) : Width - 1 - (int)(zToDC * (z - zMin));
+
+			if( bHorizontal )
+			{
+				x	= xOff + zDC;
+				y	= yOff;
+				n	= yOff + Height;
+
+				switch( Style )
+				{
+				case 0:	// ...
+					dc.DrawLine(x, y, x, y + Height_Tick);
+					Draw_Text(dc, TEXTALIGN_CENTERLEFT  , x + 2, y + Height / 2, s);
+					break;
+
+				case 1:	// tick at top...
+					dc.DrawLine(x, y, x, y + Height_Tick);
+					Draw_Text(dc, TEXTALIGN_TOPCENTER   , x, y + Height_Tick, s);
+					break;
+
+				case 2: // tick at bottom...
+					dc.DrawLine(x, n, x, n - Height_Tick);
+					Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, x, n - Height_Tick, s);
+					break;
+				}
+			}
+			else
+			{
+				x	= xOff;
+				y	= yOff + zDC;
+				n	= xOff + Height;
+
+				switch( Style )
+				{
+				case 0: // ...
+					dc.DrawLine(x, y, x + Height_Tick, y);
+					Draw_Text(dc, TEXTALIGN_CENTERLEFT  , x + Height / 2, y - 2, 90.0, s);
+					break;
+
+				case 1:	// tick at top...
+					dc.DrawLine(x, y, x + Height_Tick, y);
+					Draw_Text(dc, TEXTALIGN_TOPCENTER   , x + Height_Tick, y, 90.0, s);
+					break;
+
+				case 2: // tick at bottom...
+					dc.DrawLine(n, y, n - Height_Tick, y);
+					Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, n - Height_Tick, y, 90.0, s);
+					break;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		dc.SetFont(oldFont);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dc_helper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,149 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     DC_Helper.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DC_Helper_H
+#define _HEADER_INCLUDED__SAGA_GUI__DC_Helper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dc.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	EDGE_STYLE_SIMPLE,
+	EDGE_STYLE_STATIC,
+	EDGE_STYLE_SUNKEN,
+	EDGE_STYLE_RAISED
+};
+
+//---------------------------------------------------------
+void			Draw_Edge			(wxDC &dc, int Edge_Style, int ax, int ay, int bx, int by);
+void			Draw_Edge			(wxDC &dc, int Edge_Style, wxRect r);
+
+//---------------------------------------------------------
+void			Draw_Rect			(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by);
+void			Draw_Rect			(wxDC &dc, wxColour Color, wxRect r);
+
+//---------------------------------------------------------
+void			Draw_FillRect		(wxDC &dc, wxColour Color, int ax, int ay, int bx, int by);
+void			Draw_FillRect		(wxDC &dc, wxColour Color, wxRect r);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define TEXTALIGN_LEFT				0x01
+#define TEXTALIGN_XCENTER			0x02
+#define TEXTALIGN_RIGHT				0x04
+#define TEXTALIGN_TOP				0x08
+#define TEXTALIGN_YCENTER			0x10
+#define TEXTALIGN_BOTTOM			0x20
+
+#define TEXTALIGN_TOPLEFT			(TEXTALIGN_TOP    |TEXTALIGN_LEFT)
+#define TEXTALIGN_TOPCENTER			(TEXTALIGN_TOP    |TEXTALIGN_XCENTER)
+#define TEXTALIGN_TOPRIGHT			(TEXTALIGN_TOP    |TEXTALIGN_RIGHT)
+#define TEXTALIGN_CENTERLEFT		(TEXTALIGN_YCENTER|TEXTALIGN_LEFT)
+#define TEXTALIGN_CENTER			(TEXTALIGN_YCENTER|TEXTALIGN_XCENTER)
+#define TEXTALIGN_CENTERRIGHT		(TEXTALIGN_YCENTER|TEXTALIGN_RIGHT)
+#define TEXTALIGN_BOTTOMLEFT		(TEXTALIGN_BOTTOM |TEXTALIGN_LEFT)
+#define TEXTALIGN_BOTTOMCENTER		(TEXTALIGN_BOTTOM |TEXTALIGN_XCENTER)
+#define TEXTALIGN_BOTTOMRIGHT		(TEXTALIGN_BOTTOM |TEXTALIGN_RIGHT)
+
+//---------------------------------------------------------
+void			Draw_Text			(wxDC &dc, int Align, int x, int y, const wxString &Text);
+void			Draw_Text			(wxDC &dc, int Align, int x, int y, double Angle, const wxString &Text);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void			Draw_Scale			(wxDC &dc, wxRect r, double min_Value, double max_Value, bool bHorizontal, bool bAscendent, bool bTickAtTop);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DC_Helper_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1233 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_About.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/notebook.h>
+#include <wx/textctrl.h>
+
+#include <wx/scrolwin.h>
+#include <wx/toolbar.h>
+#include <wx/stattext.h>
+#include <wx/dcclient.h>
+#include <wx/button.h>
+#include <wx/propgrid/propgrid.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "res_controls.h"
+
+#include "saga.h"
+
+#include "dlg_about.h"
+#include "dlg_about_logo.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_About, CDLG_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_About, CDLG_Base)
+	EVT_TEXT_URL(wxID_ANY, CDLG_About::On_URL_Version)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_About::CDLG_About(void)
+	: CDLG_Base(-1, LNG("About SAGA"), false)
+{
+	wxTextCtrl	*pText;
+
+	m_pControl	= new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE);
+	
+	m_pControl->AddPage(new CDLG_About_Logo(m_pControl), LNG("Logo"), false, -1);
+
+	//-----------------------------------------------------
+	m_pVersion	=
+	pText		= new wxTextCtrl(m_pControl, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_CENTRE|wxTE_RICH|wxTE_AUTO_URL|wxBORDER_SUNKEN);
+	pText->AppendText(_Get_Version());
+	m_pControl->AddPage(pText, LNG("Version"), false, -1);
+	pText->ShowPosition(0);
+
+	//-----------------------------------------------------
+	pText		= new wxTextCtrl(m_pControl, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_CENTRE);
+	pText->AppendText(_Get_GPL());
+	m_pControl->AddPage(pText, SG_T("GPL"), false, -1);
+	pText->ShowPosition(0);
+
+	//-----------------------------------------------------
+	pText		= new wxTextCtrl(m_pControl, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_CENTRE);
+	pText->AppendText(_Get_LGPL());
+	m_pControl->AddPage(pText, SG_T("LGPL"), false, -1);
+	pText->ShowPosition(0);
+
+	//-----------------------------------------------------
+	pText		= new wxTextCtrl(m_pControl, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_CENTRE);
+	pText->AppendText(_Get_Acknowledgements());
+	m_pControl->AddPage(pText, LNG("Acknowledgements"), false, -1);
+	pText->ShowPosition(0);
+
+	//-----------------------------------------------------
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+CDLG_About::~CDLG_About(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_About::Set_Position(wxRect r)
+{
+	m_pControl->SetSize(r);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_About::On_URL_Version(wxTextUrlEvent &event)
+{
+	if( !event.GetMouseEvent().Moving() )
+	{
+		Open_WebBrowser(m_pVersion->GetValue().Mid(event.GetURLStart(), event.GetURLEnd() - event.GetURLStart()));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CDLG_About::_Get_Version(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("\nSAGA\n"));
+
+	s.Append(SG_Translate(
+		wxT("System for Automated Geoscientific Analyses\n")
+	));
+
+	s.Append(
+		wxT("http://www.saga-gis.org\n")
+	);
+
+#ifdef _SAGA_UNICODE
+	s.Append(wxT("_______________________\n\n"));
+
+	s.Append(
+		wxT("UNICODE\n")
+	);
+#endif
+
+	s.Append(wxT("_______________________\n\n"));
+
+	s.Append(wxString::Format(
+		wxT("SAGA GUI\nSAGA Graphical User Interface - Version: %s\n")
+		wxT("\n")
+		wxT("Copyrights (c) 2005-2008 by Olaf Conrad\n")
+		wxT("\n")
+		wxT("GNU General Public License (GPL)\n"),
+		SAGA_GUI_Get_Version()
+	));
+
+	s.Append(wxT("_______________________\n\n"));
+
+	s.Append(wxString::Format(
+		wxT("SAGA API\n%s\n")
+		wxT("\n")
+		wxT("Copyrights (c) 2002-2009 by Olaf Conrad\n")
+		wxT("Portions (c) 2002 by Andre Ringeler\n")	// " (mat_formula.cpp)\n")
+		wxT("Portions (c) 2005-2006 by Victor Olaya\n")
+		wxT("\n")
+		wxT("GNU Lesser General Public License (LGPL)\n"),
+		SAGA_API_Get_Version()
+	));
+
+	s.Append(wxT("_______________________\n\n"));
+
+	s.Append(wxString::Format(
+		wxT("SAGA uses the portable C++ GUI toolkit wxWidgets\n")
+		wxT("http://www.wxwidgets.org\n\n")
+		wxT("%s\n")
+		wxT("wxPropertyGrid"),
+		wxVERSION_STRING
+	));
+
+	int		Version	= wxPG_VERSION;
+	s.Append(wxString::Format(wxT(" %d"), Version / 1000));
+	Version	-= (Version / 1000) * 1000;
+	s.Append(wxString::Format(wxT(".%d"), Version / 100));
+	Version	-= (Version / 100 ) * 100;
+	s.Append(wxString::Format(wxT(".%d"), Version / 10));
+	Version	-= (Version / 10  ) * 10;
+	s.Append(wxT("\n"));
+
+	if( CSG_Doc_PDF::Get_Version() != NULL )
+	{
+		s.Append(wxT("_______________________\n\n"));
+
+		s.Append(
+			wxT("SAGA uses\n")
+		);
+
+		s.Append(
+			CSG_Doc_PDF::Get_Version()
+		);
+
+		s.Append(
+			wxT("\n")
+			wxT("http://sourceforge.net/projects/libharu\n")
+		);
+	}
+
+	s.Append(wxT("_______________________\n\n"));
+
+	s.Append(
+		wxT("Compiled with\n")
+		#  if	defined(__BORLANDC__)
+			wxT("Borland C++")
+		#elif	defined(__DJGPP__)
+			wxT("DJGPP")
+		#elif	defined(__DIGITALMARS__)
+			wxT("Digital Mars")
+		#elif	defined(__MINGW32__)
+			wxT("MinGW")
+		#elif	defined(__GNUWIN32__)
+			wxT("Gnu-Win32 compiler")
+		#elif	defined(__GNUG__)
+			wxT("Gnu C++")
+		#elif	defined(__MWERKS__)
+			wxT("CodeWarrior MetroWerks compiler")
+		#elif	defined(__SUNCC__)
+			wxT("Sun CC")
+		#elif	defined(__SYMANTECC__)
+			wxT("Symantec C++")
+		#elif	defined(__VISAGECPP__)
+			wxT("IBM Visual Age (OS/2)")
+		#elif	defined(__VISUALC__)	// The value of this macro corresponds to the compiler version: 1020 for 4.2 (the first supported version), 1100 for 5.0, 1200 for 6.0 and so on
+			#if   __VISUALC__ == 1020
+				wxT("Microsoft Visual C++ 4.2")
+			#elif __VISUALC__ >= 1100 && __VISUALC__ < 1200
+				wxT("Microsoft Visual C++ 5")
+			#elif __VISUALC__ >= 1200 && __VISUALC__ < 1300
+				wxT("Microsoft Visual C++ 6")
+			#elif __VISUALC__ >= 1300 && __VISUALC__ < 1400
+				wxT("Microsoft Visual C++ 7")
+			#elif __VISUALC__ >= 1400 && __VISUALC__ < 1500
+				wxT("Microsoft Visual C++ 8")
+			#elif __VISUALC__ >= 1500 && __VISUALC__ < 1600
+				wxT("Microsoft Visual C++ 9")
+			#elif __VISUALC__ >= 1600 && __VISUALC__ < 1700
+				wxT("Microsoft Visual C++ 10")
+			#else
+				wxT("Microsoft Visual C++")
+			#endif
+		#elif	defined(__XLC__)
+			wxT("AIX compiler")
+		#elif	defined(__WATCOMC__)
+			wxT("Watcom C++")
+		#elif	defined(_WIN32_WCE)
+			wxT("Windows CE version")
+		#else
+			wxT("unknown compiler")
+		#endif
+		wxT("\n")
+	);
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxString CDLG_About::_Get_Acknowledgements(void)
+{
+	return( SG_STR_MBTOSG(
+		"\n"
+		"Acknowledgements\n"
+		"\n"
+		"...to the growing list of developers and contributors.\n"
+		"(please let us know, if you feel your name should appear here too)\n"
+		"_______________________\n"
+		"\n"
+		"Benni Bechtel\n"
+		"Michael Bock\n"
+		"Juergen Boehner\n"
+		"Antonio Boggia\n"
+		"Alex Brenning\n"
+		"Vern Cimmery\n"
+		"Olaf Conrad\n"
+		"Frank Haselein\n"
+		"Tobias Heckmann\n"
+		"Ruediger Koethe\n"
+		"Angela Kreikemeyer\n"
+		"Stefan Liersch\n"
+		"Gianluca Massei\n"
+		"Victor Olaya\n"
+		"Andre Ringeler\n"
+		"Thomas Schmeja\n"
+		"Thomas Schorr\n"
+		"Johan Van de Wauw\n"
+		"Volker Wichmann\n"
+		"Thomas Wutzler\n"
+		"_______________________\n"
+		"\n"
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CDLG_About::_Get_GPL(void)
+{
+	return( SG_STR_MBTOSG(
+		"\n"
+		"GNU GENERAL PUBLIC LICENSE\n"
+		"Version 2, June 1991\n"
+		"\n"
+		"Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"
+		"59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
+		"Everyone is permitted to copy and distribute verbatim copies\n"
+		"of this license document, but changing it is not allowed.\n"
+		"\n"
+		"Preamble\n"
+		"\n"
+		"The licenses for most software are designed to take away your\n"
+		"freedom to share and change it.  By contrast, the GNU General Public\n"
+		"License is intended to guarantee your freedom to share and change free\n"
+		"software--to make sure the software is free for all its users.  This\n"
+		"General Public License applies to most of the Free Software\n"
+		"Foundation's software and to any other program whose authors commit to\n"
+		"using it.  (Some other Free Software Foundation software is covered by\n"
+		"the GNU Library General Public License instead.)  You can apply it to\n"
+		"your programs, too.\n"
+		"\n"
+		"When we speak of free software, we are referring to freedom, not\n"
+		"price.  Our General Public Licenses are designed to make sure that you\n"
+		"have the freedom to distribute copies of free software (and charge for\n"
+		"this service if you wish), that you receive source code or can get it\n"
+		"if you want it, that you can change the software or use pieces of it\n"
+		"in new free programs; and that you know you can do these things.\n"
+		"\n"
+		"To protect your rights, we need to make restrictions that forbid\n"
+		"anyone to deny you these rights or to ask you to surrender the rights.\n"
+		"These restrictions translate to certain responsibilities for you if you\n"
+		"distribute copies of the software, or if you modify it.\n"
+		"\n"
+		"For example, if you distribute copies of such a program, whether\n"
+		"gratis or for a fee, you must give the recipients all the rights that\n"
+		"you have.  You must make sure that they, too, receive or can get the\n"
+		"source code.  And you must show them these terms so they know their\n"
+		"rights.\n"
+		"\n"
+		"We protect your rights with two steps: (1) copyright the software, and\n"
+		"(2) offer you this license which gives you legal permission to copy,\n"
+		"distribute and/or modify the software.\n"
+		"\n"
+		"Also, for each author's protection and ours, we want to make certain\n"
+		"that everyone understands that there is no warranty for this free\n"
+		"software.  If the software is modified by someone else and passed on, we\n"
+		"want its recipients to know that what they have is not the original, so\n"
+		"that any problems introduced by others will not reflect on the original\n"
+		"authors' reputations.\n"
+		"\n"
+		"Finally, any free program is threatened constantly by software\n"
+		"patents.  We wish to avoid the danger that redistributors of a free\n"
+		"program will individually obtain patent licenses, in effect making the\n"
+		"program proprietary.  To prevent this, we have made it clear that any\n"
+		"patent must be licensed for everyone's free use or not licensed at all.\n"
+		"\n"
+		"The precise terms and conditions for copying, distribution and\n"
+		"modification follow.\n"
+		"\n"
+		"GNU GENERAL PUBLIC LICENSE\n"
+		"TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
+		"\n"
+		"0. This License applies to any program or other work which contains\n"
+		"a notice placed by the copyright holder saying it may be distributed\n"
+		"under the terms of this General Public License.  The \"Program\", below,\n"
+		"refers to any such program or work, and a \"work based on the Program\"\n"
+		"means either the Program or any derivative work under copyright law:\n"
+		"that is to say, a work containing the Program or a portion of it,\n"
+		"either verbatim or with modifications and/or translated into another\n"
+		"language.  (Hereinafter, translation is included without limitation in\n"
+		"the term \"modification\".)  Each licensee is addressed as \"you\".\n"
+		"\n"
+		"Activities other than copying, distribution and modification are not\n"
+		"covered by this License; they are outside its scope.  The act of\n"
+		"running the Program is not restricted, and the output from the Program\n"
+		"is covered only if its contents constitute a work based on the\n"
+		"Program (independent of having been made by running the Program).\n"
+		"Whether that is true depends on what the Program does.\n"
+		"\n"
+		"1. You may copy and distribute verbatim copies of the Program's\n"
+		"source code as you receive it, in any medium, provided that you\n"
+		"conspicuously and appropriately publish on each copy an appropriate\n"
+		"copyright notice and disclaimer of warranty; keep intact all the\n"
+		"notices that refer to this License and to the absence of any warranty;\n"
+		"and give any other recipients of the Program a copy of this License\n"
+		"along with the Program.\n"
+		"\n"
+		"You may charge a fee for the physical act of transferring a copy, and\n"
+		"you may at your option offer warranty protection in exchange for a fee.\n"
+		"\n"
+		"2. You may modify your copy or copies of the Program or any portion\n"
+		"of it, thus forming a work based on the Program, and copy and\n"
+		"distribute such modifications or work under the terms of Section 1\n"
+		"above, provided that you also meet all of these conditions:\n"
+		"\n"
+		"a) You must cause the modified files to carry prominent notices\n"
+		"stating that you changed the files and the date of any change.\n"
+		"\n"
+		"b) You must cause any work that you distribute or publish, that in\n"
+		"whole or in part contains or is derived from the Program or any\n"
+		"part thereof, to be licensed as a whole at no charge to all third\n"
+		"parties under the terms of this License.\n"
+		"\n"
+		"c) If the modified program normally reads commands interactively\n"
+		"when run, you must cause it, when started running for such\n"
+		"interactive use in the most ordinary way, to print or display an\n"
+		"announcement including an appropriate copyright notice and a\n"
+		"notice that there is no warranty (or else, saying that you provide\n"
+		"a warranty) and that users may redistribute the program under\n"
+		"these conditions, and telling the user how to view a copy of this\n"
+		"License.  (Exception: if the Program itself is interactive but\n"
+		"does not normally print such an announcement, your work based on\n"
+		"the Program is not required to print an announcement.)\n"
+		"\n"
+		"These requirements apply to the modified work as a whole.  If\n"
+		"identifiable sections of that work are not derived from the Program,\n"
+		"and can be reasonably considered independent and separate works in\n"
+		"themselves, then this License, and its terms, do not apply to those\n"
+		"sections when you distribute them as separate works.  But when you\n"
+		"distribute the same sections as part of a whole which is a work based\n"
+		"on the Program, the distribution of the whole must be on the terms of\n"
+		"this License, whose permissions for other licensees extend to the\n"
+		"entire whole, and thus to each and every part regardless of who wrote it.\n"
+		"\n"
+		"Thus, it is not the intent of this section to claim rights or contest\n"
+		"your rights to work written entirely by you; rather, the intent is to\n"
+		"exercise the right to control the distribution of derivative or\n"
+		"collective works based on the Program.\n"
+		"\n"
+		"In addition, mere aggregation of another work not based on the Program\n"
+		"with the Program (or with a work based on the Program) on a volume of\n"
+		"a storage or distribution medium does not bring the other work under\n"
+		"the scope of this License.\n"
+		"\n"
+		"3. You may copy and distribute the Program (or a work based on it,\n"
+		"under Section 2) in object code or executable form under the terms of\n"
+		"Sections 1 and 2 above provided that you also do one of the following:\n"
+		"\n"
+		"a) Accompany it with the complete corresponding machine-readable\n"
+		"source code, which must be distributed under the terms of Sections\n"
+		"1 and 2 above on a medium customarily used for software interchange; or,\n"
+		"\n"
+		"b) Accompany it with a written offer, valid for at least three\n"
+		"years, to give any third party, for a charge no more than your\n"
+		"cost of physically performing source distribution, a complete\n"
+		"machine-readable copy of the corresponding source code, to be\n"
+		"distributed under the terms of Sections 1 and 2 above on a medium\n"
+		"customarily used for software interchange; or,\n"
+		"\n"
+		"c) Accompany it with the information you received as to the offer\n"
+		"to distribute corresponding source code.  (This alternative is\n"
+		"allowed only for noncommercial distribution and only if you\n"
+		"received the program in object code or executable form with such\n"
+		"an offer, in accord with Subsection b above.)\n"
+		"\n"
+		"The source code for a work means the preferred form of the work for\n"
+		"making modifications to it.  For an executable work, complete source\n"
+		"code means all the source code for all modules it contains, plus any\n"
+		"associated interface definition files, plus the scripts used to\n"
+		"control compilation and installation of the executable.  However, as a\n"
+		"special exception, the source code distributed need not include\n"
+		"anything that is normally distributed (in either source or binary\n"
+		"form) with the major components (compiler, kernel, and so on) of the\n"
+		"operating system on which the executable runs, unless that component\n"
+		"itself accompanies the executable.\n"
+		"\n"
+		"If distribution of executable or object code is made by offering\n"
+		"access to copy from a designated place, then offering equivalent\n"
+		"access to copy the source code from the same place counts as\n"
+		"distribution of the source code, even though third parties are not\n"
+		"compelled to copy the source along with the object code.\n"
+		"\n"
+		"4. You may not copy, modify, sublicense, or distribute the Program\n"
+		"except as expressly provided under this License.  Any attempt\n"
+		"otherwise to copy, modify, sublicense or distribute the Program is\n"
+		"void, and will automatically terminate your rights under this License.\n"
+		"However, parties who have received copies, or rights, from you under\n"
+		"this License will not have their licenses terminated so long as such\n"
+		"parties remain in full compliance.\n"
+		"\n"
+		"5. You are not required to accept this License, since you have not\n"
+		"signed it.  However, nothing else grants you permission to modify or\n"
+		"distribute the Program or its derivative works.  These actions are\n"
+		"prohibited by law if you do not accept this License.  Therefore, by\n"
+		"modifying or distributing the Program (or any work based on the\n"
+		"Program), you indicate your acceptance of this License to do so, and\n"
+		"all its terms and conditions for copying, distributing or modifying\n"
+		"the Program or works based on it.\n"
+		"\n"
+		"6. Each time you redistribute the Program (or any work based on the\n"
+		"Program), the recipient automatically receives a license from the\n"
+		"original licensor to copy, distribute or modify the Program subject to\n"
+		"these terms and conditions.  You may not impose any further\n"
+		"restrictions on the recipients' exercise of the rights granted herein.\n"
+		"You are not responsible for enforcing compliance by third parties to\n"
+		"this License.\n"
+		"\n"
+		"7. If, as a consequence of a court judgment or allegation of patent\n"
+		"infringement or for any other reason (not limited to patent issues),\n"
+		"conditions are imposed on you (whether by court order, agreement or\n"
+		"otherwise) that contradict the conditions of this License, they do not\n"
+		"excuse you from the conditions of this License.  If you cannot\n"
+		"distribute so as to satisfy simultaneously your obligations under this\n"
+		"License and any other pertinent obligations, then as a consequence you\n"
+		"may not distribute the Program at all.  For example, if a patent\n"
+		"license would not permit royalty-free redistribution of the Program by\n"
+		"all those who receive copies directly or indirectly through you, then\n"
+		"the only way you could satisfy both it and this License would be to\n"
+		"refrain entirely from distribution of the Program.\n"
+		"\n"
+		"If any portion of this section is held invalid or unenforceable under\n"
+		"any particular circumstance, the balance of the section is intended to\n"
+		"apply and the section as a whole is intended to apply in other\n"
+		"circumstances.\n"
+		"\n"
+		"It is not the purpose of this section to induce you to infringe any\n"
+		"patents or other property right claims or to contest validity of any\n"
+		"such claims; this section has the sole purpose of protecting the\n"
+		"integrity of the free software distribution system, which is\n"
+		"implemented by public license practices.  Many people have made\n"
+		"generous contributions to the wide range of software distributed\n"
+		"through that system in reliance on consistent application of that\n"
+		"system; it is up to the author/donor to decide if he or she is willing\n"
+		"to distribute software through any other system and a licensee cannot\n"
+		"impose that choice.\n"
+		"\n"
+		"This section is intended to make thoroughly clear what is believed to\n"
+		"be a consequence of the rest of this License.\n"
+		"\n"
+		"8. If the distribution and/or use of the Program is restricted in\n"
+		"certain countries either by patents or by copyrighted interfaces, the\n"
+		"original copyright holder who places the Program under this License\n"
+		"may add an explicit geographical distribution limitation excluding\n"
+		"those countries, so that distribution is permitted only in or among\n"
+		"countries not thus excluded.  In such case, this License incorporates\n"
+		"the limitation as if written in the body of this License.\n"
+		"\n"
+		"9. The Free Software Foundation may publish revised and/or new versions\n"
+		"of the General Public License from time to time.  Such new versions will\n"
+		"be similar in spirit to the present version, but may differ in detail to\n"
+		"address new problems or concerns.\n"
+		"\n"
+		"Each version is given a distinguishing version number.  If the Program\n"
+		"specifies a version number of this License which applies to it and \"any\n"
+		"later version\", you have the option of following the terms and conditions\n"
+		"either of that version or of any later version published by the Free\n"
+		"Software Foundation.  If the Program does not specify a version number of\n"
+		"this License, you may choose any version ever published by the Free Software\n"
+		"Foundation.\n"
+		"\n"
+		"10. If you wish to incorporate parts of the Program into other free\n"
+		"programs whose distribution conditions are different, write to the author\n"
+		"to ask for permission.  For software which is copyrighted by the Free\n"
+		"Software Foundation, write to the Free Software Foundation; we sometimes\n"
+		"make exceptions for this.  Our decision will be guided by the two goals\n"
+		"of preserving the free status of all derivatives of our free software and\n"
+		"of promoting the sharing and reuse of software generally.\n"
+		"\n"
+		"NO WARRANTY\n"
+		"\n"
+		"11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
+		"FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\n"
+		"OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
+		"PROVIDE THE PROGRAM \"AS IS\"WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
+		"OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
+		"MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\n"
+		"TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\n"
+		"PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
+		"REPAIR OR CORRECTION.\n"
+		"\n"
+		"12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
+		"WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
+		"REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
+		"INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
+		"OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
+		"TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
+		"YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
+		"PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
+		"POSSIBILITY OF SUCH DAMAGES.\n"
+		"\n"
+		"END OF TERMS AND CONDITIONS\n"
+		"\n"
+		"How to Apply These Terms to Your New Programs\n"
+		"\n"
+		"If you develop a new program, and you want it to be of the greatest\n"
+		"possible use to the public, the best way to achieve this is to make it\n"
+		"free software which everyone can redistribute and change under these terms.\n"
+		"\n"
+		"To do so, attach the following notices to the program.  It is safest\n"
+		"to attach them to the start of each source file to most effectively\n"
+		"convey the exclusion of warranty; and each file should have at least\n"
+		"the \"copyright\"line and a pointer to where the full notice is found.\n"
+		"\n"
+		"<one line to give the program's name and a brief idea of what it does.>\n"
+		"Copyright (C) <year>  <name of author>\n"
+		"\n"
+		"This program is free software; you can redistribute it and/or modify\n"
+		"it under the terms of the GNU General Public License as published by\n"
+		"the Free Software Foundation; either version 2 of the License, or\n"
+		"(at your option) any later version.\n"
+		"\n"
+		"This program is distributed in the hope that it will be useful,\n"
+		"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+		"GNU General Public License for more details.\n"
+		"\n"
+		"You should have received a copy of the GNU General Public License\n"
+		"along with this program; if not, write to the Free Software\n"
+		"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
+		"\n"
+		"\n"
+		"Also add information on how to contact you by electronic and paper mail.\n"
+		"\n"
+		"If the program is interactive, make it output a short notice like this\n"
+		"when it starts in an interactive mode:\n"
+		"\n"
+		"Gnomovision version 69, Copyright (C) year name of author\n"
+		"Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n"
+		"This is free software, and you are welcome to redistribute it\n"
+		"under certain conditions; type `show c' for details.\n"
+		"\n"
+		"The hypothetical commands `show w' and `show c' should show the appropriate\n"
+		"parts of the General Public License.  Of course, the commands you use may\n"
+		"be called something other than `show w' and `show c'; they could even be\n"
+		"mouse-clicks or menu items--whatever suits your program.\n"
+		"\n"
+		"You should also get your employer (if you work as a programmer) or your\n"
+		"school, if any, to sign a \"copyright disclaimer\"for the program, if\n"
+		"necessary.  Here is a sample; alter the names:\n"
+		"\n"
+		"Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n"
+		"`Gnomovision' (which makes passes at compilers) written by James Hacker.\n"
+		"\n"
+		"<signature of Ty Coon>, 1 April 1989\n"
+		"Ty Coon, President of Vice\n"
+		"\n"
+		"This General Public License does not permit incorporating your program into\n"
+		"proprietary programs.  If your program is a subroutine library, you may\n"
+		"consider it more useful to permit linking proprietary applications with the\n"
+		"library.  If this is what you want to do, use the GNU Library General\n"
+		"Public License instead of this License.\n"
+	));
+}
+
+//---------------------------------------------------------
+wxString CDLG_About::_Get_LGPL(void)
+{
+	return( SG_STR_MBTOSG(
+		"\n"
+		"GNU LESSER GENERAL PUBLIC LICENSE\n"
+		"Version 2.1, February 1999\n"
+		"\n"
+		"Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n"
+		"59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
+		"Everyone is permitted to copy and distribute verbatim copies\n"
+		"of this license document, but changing it is not allowed.\n"
+		"\n"
+		"[This is the first released version of the Lesser GPL. It also counts\n"
+		"as the successor of the GNU Library Public License, version 2, hence\n"
+		"the version number 2.1.]\n"
+		"\n"
+		"Preamble\n"
+		"\n"
+		"The licenses for most software are designed to take away your\n"
+		"freedom to share and change it.  By contrast, the GNU General Public\n"
+		"Licenses are intended to guarantee your freedom to share and change\n"
+		"free software--to make sure the software is free for all its users.\n"
+		"\n"
+		"This license, the Lesser General Public License, applies to some\n"
+		"specially designated software packages--typically libraries--of the\n"
+		"Free Software Foundation and other authors who decide to use it.  You\n"
+		"can use it too, but we suggest you first think carefully about whether\n"
+		"this license or the ordinary General Public License is the better\n"
+		"strategy to use in any particular case, based on the explanations below.\n"
+		"\n"
+		"When we speak of free software, we are referring to freedom of use,\n"
+		"not price.  Our General Public Licenses are designed to make sure that\n"
+		"you have the freedom to distribute copies of free software (and charge\n"
+		"for this service if you wish); that you receive source code or can get\n"
+		"it if you want it; that you can change the software and use pieces of\n"
+		"it in new free programs; and that you are informed that you can do\n"
+		"these things.\n"
+		"\n"
+		"To protect your rights, we need to make restrictions that forbid\n"
+		"distributors to deny you these rights or to ask you to surrender these\n"
+		"rights.  These restrictions translate to certain responsibilities for\n"
+		"you if you distribute copies of the library or if you modify it.\n"
+		"\n"
+		"For example, if you distribute copies of the library, whether gratis\n"
+		"or for a fee, you must give the recipients all the rights that we gave\n"
+		"you.  You must make sure that they, too, receive or can get the source\n"
+		"code.  If you link other code with the library, you must provide\n"
+		"complete object files to the recipients, so that they can relink them\n"
+		"with the library after making changes to the library and recompiling\n"
+		"it.  And you must show them these terms so they know their rights.\n"
+		"\n"
+		"We protect your rights with a two-step method: (1) we copyright the\n"
+		"library, and (2) we offer you this license, which gives you legal\n"
+		"permission to copy, distribute and/or modify the library.\n"
+		"\n"
+		"To protect each distributor, we want to make it very clear that\n"
+		"there is no warranty for the free library.  Also, if the library is\n"
+		"modified by someone else and passed on, the recipients should know\n"
+		"that what they have is not the original version, so that the original\n"
+		"author\'s reputation will not be affected by problems that might be\n"
+		"introduced by others.\n"
+		"\n"
+		"Finally, software patents pose a constant threat to the existence of\n"
+		"any free program.  We wish to make sure that a company cannot\n"
+		"effectively restrict the users of a free program by obtaining a\n"
+		"restrictive license from a patent holder.  Therefore, we insist that\n"
+		"any patent license obtained for a version of the library must be\n"
+		"consistent with the full freedom of use specified in this license.\n"
+		"\n"
+		"Most GNU software, including some libraries, is covered by the\n"
+		"ordinary GNU General Public License.  This license, the GNU Lesser\n"
+		"General Public License, applies to certain designated libraries, and\n"
+		"is quite different from the ordinary General Public License.  We use\n"
+		"this license for certain libraries in order to permit linking those\n"
+		"libraries into non-free programs.\n"
+		"\n"
+		"When a program is linked with a library, whether statically or using\n"
+		"a shared library, the combination of the two is legally speaking a\n"
+		"combined work, a derivative of the original library.  The ordinary\n"
+		"General Public License therefore permits such linking only if the\n"
+		"entire combination fits its criteria of freedom.  The Lesser General\n"
+		"Public License permits more lax criteria for linking other code with\n"
+		"the library.\n"
+		"\n"
+		"We call this license the \"Lesser\" General Public License because it\n"
+		"does Less to protect the user\'s freedom than the ordinary General\n"
+		"Public License.  It also provides other free software developers Less\n"
+		"of an advantage over competing non-free programs.  These disadvantages\n"
+		"are the reason we use the ordinary General Public License for many\n"
+		"libraries.  However, the Lesser license provides advantages in certain\n"
+		"special circumstances.\n"
+		"\n"
+		"For example, on rare occasions, there may be a special need to\n"
+		"encourage the widest possible use of a certain library, so that it becomes\n"
+		"a de-facto standard.  To achieve this, non-free programs must be\n"
+		"allowed to use the library.  A more frequent case is that a free\n"
+		"library does the same job as widely used non-free libraries.  In this\n"
+		"case, there is little to gain by limiting the free library to free\n"
+		"software only, so we use the Lesser General Public License.\n"
+		"\n"
+		"In other cases, permission to use a particular library in non-free\n"
+		"programs enables a greater number of people to use a large body of\n"
+		"free software.  For example, permission to use the GNU C Library in\n"
+		"non-free programs enables many more people to use the whole GNU\n"
+		"operating system, as well as its variant, the GNU/Linux operating\n"
+		"system.\n"
+		"\n"
+		"Although the Lesser General Public License is Less protective of the\n"
+		"users\' freedom, it does ensure that the user of a program that is\n"
+		"linked with the Library has the freedom and the wherewithal to run\n"
+		"that program using a modified version of the Library.\n"
+		"\n"
+		"The precise terms and conditions for copying, distribution and\n"
+		"modification follow.  Pay close attention to the difference between a\n"
+		"\"work based on the library\" and a \"work that uses the library\".  The\n"
+		"former contains code derived from the library, whereas the latter must\n"
+		"be combined with the library in order to run.\n"
+		"\n"
+		"GNU LESSER GENERAL PUBLIC LICENSE\n"
+		"TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
+		"\n"
+		"0. This License Agreement applies to any software library or other\n"
+		"program which contains a notice placed by the copyright holder or\n"
+		"other authorized party saying it may be distributed under the terms of\n"
+		"this Lesser General Public License (also called \"this License\").\n"
+		"Each licensee is addressed as \"you\".\n"
+		"\n"
+		"A \"library\" means a collection of software functions and/or data\n"
+		"prepared so as to be conveniently linked with application programs\n"
+		"(which use some of those functions and data) to form executables.\n"
+		"\n"
+		"The \"Library\", below, refers to any such software library or work\n"
+		"which has been distributed under these terms.  A \"work based on the\n"
+		"Library\" means either the Library or any derivative work under\n"
+		"copyright law: that is to say, a work containing the Library or a\n"
+		"portion of it, either verbatim or with modifications and/or translated\n"
+		"straightforwardly into another language.  (Hereinafter, translation is\n"
+		"included without limitation in the term \"modification\".)\n"
+		"\n"
+		"\"Source code\" for a work means the preferred form of the work for\n"
+		"making modifications to it.  For a library, complete source code means\n"
+		"all the source code for all modules it contains, plus any associated\n"
+		"interface definition files, plus the scripts used to control compilation\n"
+		"and installation of the library.\n"
+		"\n"
+		"Activities other than copying, distribution and modification are not\n"
+		"covered by this License; they are outside its scope.  The act of\n"
+		"running a program using the Library is not restricted, and output from\n"
+		"such a program is covered only if its contents constitute a work based\n"
+		"on the Library (independent of the use of the Library in a tool for\n"
+		"writing it).  Whether that is true depends on what the Library does\n"
+		"and what the program that uses the Library does.\n"
+		"\n"
+		"1. You may copy and distribute verbatim copies of the Library\'s\n"
+		"complete source code as you receive it, in any medium, provided that\n"
+		"you conspicuously and appropriately publish on each copy an\n"
+		"appropriate copyright notice and disclaimer of warranty; keep intact\n"
+		"all the notices that refer to this License and to the absence of any\n"
+		"warranty; and distribute a copy of this License along with the\n"
+		"Library.\n"
+		"\n"
+		"You may charge a fee for the physical act of transferring a copy,\n"
+		"and you may at your option offer warranty protection in exchange for a\n"
+		"fee.\n"
+		"\n"
+		"2. You may modify your copy or copies of the Library or any portion\n"
+		"of it, thus forming a work based on the Library, and copy and\n"
+		"distribute such modifications or work under the terms of Section 1\n"
+		"above, provided that you also meet all of these conditions:\n"
+		"\n"
+		"a) The modified work must itself be a software library.\n"
+		"\n"
+		"b) You must cause the files modified to carry prominent notices\n"
+		"stating that you changed the files and the date of any change.\n"
+		"\n"
+		"c) You must cause the whole of the work to be licensed at no\n"
+		"charge to all third parties under the terms of this License.\n"
+		"\n"
+		"d) If a facility in the modified Library refers to a function or a\n"
+		"table of data to be supplied by an application program that uses\n"
+		"the facility, other than as an argument passed when the facility\n"
+		"is invoked, then you must make a good faith effort to ensure that,\n"
+		"in the event an application does not supply such function or\n"
+		"table, the facility still operates, and performs whatever part of\n"
+		"its purpose remains meaningful.\n"
+		"\n"
+		"(For example, a function in a library to compute square roots has\n"
+		"a purpose that is entirely well-defined independent of the\n"
+		"application.  Therefore, Subsection 2d requires that any\n"
+		"application-supplied function or table used by this function must\n"
+		"be optional: if the application does not supply it, the square\n"
+		"root function must still compute square roots.)\n"
+		"\n"
+		"These requirements apply to the modified work as a whole.  If\n"
+		"identifiable sections of that work are not derived from the Library,\n"
+		"and can be reasonably considered independent and separate works in\n"
+		"themselves, then this License, and its terms, do not apply to those\n"
+		"sections when you distribute them as separate works.  But when you\n"
+		"distribute the same sections as part of a whole which is a work based\n"
+		"on the Library, the distribution of the whole must be on the terms of\n"
+		"this License, whose permissions for other licensees extend to the\n"
+		"entire whole, and thus to each and every part regardless of who wrote\n"
+		"it.\n"
+		"\n"
+		"Thus, it is not the intent of this section to claim rights or contest\n"
+		"your rights to work written entirely by you; rather, the intent is to\n"
+		"exercise the right to control the distribution of derivative or\n"
+		"collective works based on the Library.\n"
+		"\n"
+		"In addition, mere aggregation of another work not based on the Library\n"
+		"with the Library (or with a work based on the Library) on a volume of\n"
+		"a storage or distribution medium does not bring the other work under\n"
+		"the scope of this License.\n"
+		"\n"
+		"3. You may opt to apply the terms of the ordinary GNU General Public\n"
+		"License instead of this License to a given copy of the Library.  To do\n"
+		"this, you must alter all the notices that refer to this License, so\n"
+		"that they refer to the ordinary GNU General Public License, version 2,\n"
+		"instead of to this License.  (If a newer version than version 2 of the\n"
+		"ordinary GNU General Public License has appeared, then you can specify\n"
+		"that version instead if you wish.)  Do not make any other change in\n"
+		"these notices.\n"
+		"\n"
+		"Once this change is made in a given copy, it is irreversible for\n"
+		"that copy, so the ordinary GNU General Public License applies to all\n"
+		"subsequent copies and derivative works made from that copy.\n"
+		"\n"
+		"This option is useful when you wish to copy part of the code of\n"
+		"the Library into a program that is not a library.\n"
+		"\n"
+		"4. You may copy and distribute the Library (or a portion or\n"
+		"derivative of it, under Section 2) in object code or executable form\n"
+		"under the terms of Sections 1 and 2 above provided that you accompany\n"
+		"it with the complete corresponding machine-readable source code, which\n"
+		"must be distributed under the terms of Sections 1 and 2 above on a\n"
+		"medium customarily used for software interchange.\n"
+		"\n"
+		"If distribution of object code is made by offering access to copy\n"
+		"from a designated place, then offering equivalent access to copy the\n"
+		"source code from the same place satisfies the requirement to\n"
+		"distribute the source code, even though third parties are not\n"
+		"compelled to copy the source along with the object code.\n"
+		"\n"
+		"5. A program that contains no derivative of any portion of the\n"
+		"Library, but is designed to work with the Library by being compiled or\n"
+		"linked with it, is called a \"work that uses the Library\".  Such a\n"
+		"work, in isolation, is not a derivative work of the Library, and\n"
+		"therefore falls outside the scope of this License.\n"
+		"\n"
+		"However, linking a \"work that uses the Library\" with the Library\n"
+		"creates an executable that is a derivative of the Library (because it\n"
+		"contains portions of the Library), rather than a \"work that uses the\n"
+		"library\".  The executable is therefore covered by this License.\n"
+		"Section 6 states terms for distribution of such executables.\n"
+		"\n"
+		"When a \"work that uses the Library\" uses material from a header file\n"
+		"that is part of the Library, the object code for the work may be a\n"
+		"derivative work of the Library even though the source code is not.\n"
+		"Whether this is true is especially significant if the work can be\n"
+		"linked without the Library, or if the work is itself a library.  The\n"
+		"threshold for this to be true is not precisely defined by law.\n"
+		"\n"
+		"If such an object file uses only numerical parameters, data\n"
+		"structure layouts and accessors, and small macros and small inline\n"
+		"functions (ten lines or less in length), then the use of the object\n"
+		"file is unrestricted, regardless of whether it is legally a derivative\n"
+		"work.  (Executables containing this object code plus portions of the\n"
+		"Library will still fall under Section 6.)\n"
+		"\n"
+		"Otherwise, if the work is a derivative of the Library, you may\n"
+		"distribute the object code for the work under the terms of Section 6.\n"
+		"Any executables containing that work also fall under Section 6,\n"
+		"whether or not they are linked directly with the Library itself.\n"
+		"\n"
+		"6. As an exception to the Sections above, you may also combine or\n"
+		"link a \"work that uses the Library\" with the Library to produce a\n"
+		"work containing portions of the Library, and distribute that work\n"
+		"under terms of your choice, provided that the terms permit\n"
+		"modification of the work for the customer\'s own use and reverse\n"
+		"engineering for debugging such modifications.\n"
+		"\n"
+		"You must give prominent notice with each copy of the work that the\n"
+		"Library is used in it and that the Library and its use are covered by\n"
+		"this License.  You must supply a copy of this License.  If the work\n"
+		"during execution displays copyright notices, you must include the\n"
+		"copyright notice for the Library among them, as well as a reference\n"
+		"directing the user to the copy of this License.  Also, you must do one\n"
+		"of these things:\n"
+		"\n"
+		"a) Accompany the work with the complete corresponding\n"
+		"machine-readable source code for the Library including whatever\n"
+		"changes were used in the work (which must be distributed under\n"
+		"Sections 1 and 2 above); and, if the work is an executable linked\n"
+		"with the Library, with the complete machine-readable \"work that\n"
+		"uses the Library\", as object code and/or source code, so that the\n"
+		"user can modify the Library and then relink to produce a modified\n"
+		"executable containing the modified Library.  (It is understood\n"
+		"that the user who changes the contents of definitions files in the\n"
+		"Library will not necessarily be able to recompile the application\n"
+		"to use the modified definitions.)\n"
+		"\n"
+		"b) Use a suitable shared library mechanism for linking with the\n"
+		"Library.  A suitable mechanism is one that (1) uses at run time a\n"
+		"copy of the library already present on the user\'s computer system,\n"
+		"rather than copying library functions into the executable, and (2)\n"
+		"will operate properly with a modified version of the library, if\n"
+		"the user installs one, as long as the modified version is\n"
+		"interface-compatible with the version that the work was made with.\n"
+		"\n"
+		"c) Accompany the work with a written offer, valid for at\n"
+		"least three years, to give the same user the materials\n"
+		"specified in Subsection 6a, above, for a charge no more\n"
+		"than the cost of performing this distribution.\n"
+		"\n"
+		"d) If distribution of the work is made by offering access to copy\n"
+		"from a designated place, offer equivalent access to copy the above\n"
+		"specified materials from the same place.\n"
+		"\n"
+		"e) Verify that the user has already received a copy of these\n"
+		"materials or that you have already sent this user a copy.\n"
+		"\n"
+		"For an executable, the required form of the \"work that uses the\n"
+		"Library\" must include any data and utility programs needed for\n"
+		"reproducing the executable from it.  However, as a special exception,\n"
+		"the materials to be distributed need not include anything that is\n"
+		"normally distributed (in either source or binary form) with the major\n"
+		"components (compiler, kernel, and so on) of the operating system on\n"
+		"which the executable runs, unless that component itself accompanies\n"
+		"the executable.\n"
+		"\n"
+		"It may happen that this requirement contradicts the license\n"
+		"restrictions of other proprietary libraries that do not normally\n"
+		"accompany the operating system.  Such a contradiction means you cannot\n"
+		"use both them and the Library together in an executable that you\n"
+		"distribute.\n"
+		"\n"
+		"7. You may place library facilities that are a work based on the\n"
+		"Library side-by-side in a single library together with other library\n"
+		"facilities not covered by this License, and distribute such a combined\n"
+		"library, provided that the separate distribution of the work based on\n"
+		"the Library and of the other library facilities is otherwise\n"
+		"permitted, and provided that you do these two things:\n"
+		"\n"
+		"a) Accompany the combined library with a copy of the same work\n"
+		"based on the Library, uncombined with any other library\n"
+		"facilities.  This must be distributed under the terms of the\n"
+		"Sections above.\n"
+		"\n"
+		"b) Give prominent notice with the combined library of the fact\n"
+		"that part of it is a work based on the Library, and explaining\n"
+		"where to find the accompanying uncombined form of the same work.\n"
+		"\n"
+		"8. You may not copy, modify, sublicense, link with, or distribute\n"
+		"the Library except as expressly provided under this License.  Any\n"
+		"attempt otherwise to copy, modify, sublicense, link with, or\n"
+		"distribute the Library is void, and will automatically terminate your\n"
+		"rights under this License.  However, parties who have received copies,\n"
+		"or rights, from you under this License will not have their licenses\n"
+		"terminated so long as such parties remain in full compliance.\n"
+		"\n"
+		"9. You are not required to accept this License, since you have not\n"
+		"signed it.  However, nothing else grants you permission to modify or\n"
+		"distribute the Library or its derivative works.  These actions are\n"
+		"prohibited by law if you do not accept this License.  Therefore, by\n"
+		"modifying or distributing the Library (or any work based on the\n"
+		"Library), you indicate your acceptance of this License to do so, and\n"
+		"all its terms and conditions for copying, distributing or modifying\n"
+		"the Library or works based on it.\n"
+		"\n"
+		"10. Each time you redistribute the Library (or any work based on the\n"
+		"Library), the recipient automatically receives a license from the\n"
+		"original licensor to copy, distribute, link with or modify the Library\n"
+		"subject to these terms and conditions.  You may not impose any further\n"
+		"restrictions on the recipients\' exercise of the rights granted herein.\n"
+		"You are not responsible for enforcing compliance by third parties with\n"
+		"this License.\n"
+		"\n"
+		"11. If, as a consequence of a court judgment or allegation of patent\n"
+		"infringement or for any other reason (not limited to patent issues),\n"
+		"conditions are imposed on you (whether by court order, agreement or\n"
+		"otherwise) that contradict the conditions of this License, they do not\n"
+		"excuse you from the conditions of this License.  If you cannot\n"
+		"distribute so as to satisfy simultaneously your obligations under this\n"
+		"License and any other pertinent obligations, then as a consequence you\n"
+		"may not distribute the Library at all.  For example, if a patent\n"
+		"license would not permit royalty-free redistribution of the Library by\n"
+		"all those who receive copies directly or indirectly through you, then\n"
+		"the only way you could satisfy both it and this License would be to\n"
+		"refrain entirely from distribution of the Library.\n"
+		"\n"
+		"If any portion of this section is held invalid or unenforceable under any\n"
+		"particular circumstance, the balance of the section is intended to apply,\n"
+		"and the section as a whole is intended to apply in other circumstances.\n"
+		"\n"
+		"It is not the purpose of this section to induce you to infringe any\n"
+		"patents or other property right claims or to contest validity of any\n"
+		"such claims; this section has the sole purpose of protecting the\n"
+		"integrity of the free software distribution system which is\n"
+		"implemented by public license practices.  Many people have made\n"
+		"generous contributions to the wide range of software distributed\n"
+		"through that system in reliance on consistent application of that\n"
+		"system; it is up to the author/donor to decide if he or she is willing\n"
+		"to distribute software through any other system and a licensee cannot\n"
+		"impose that choice.\n"
+		"\n"
+		"This section is intended to make thoroughly clear what is believed to\n"
+		"be a consequence of the rest of this License.\n"
+		"\n"
+		"12. If the distribution and/or use of the Library is restricted in\n"
+		"certain countries either by patents or by copyrighted interfaces, the\n"
+		"original copyright holder who places the Library under this License may add\n"
+		"an explicit geographical distribution limitation excluding those countries,\n"
+		"so that distribution is permitted only in or among countries not thus\n"
+		"excluded.  In such case, this License incorporates the limitation as if\n"
+		"written in the body of this License.\n"
+		"\n"
+		"13. The Free Software Foundation may publish revised and/or new\n"
+		"versions of the Lesser General Public License from time to time.\n"
+		"Such new versions will be similar in spirit to the present version,\n"
+		"but may differ in detail to address new problems or concerns.\n"
+		"\n"
+		"Each version is given a distinguishing version number.  If the Library\n"
+		"specifies a version number of this License which applies to it and\n"
+		"\"any later version\", you have the option of following the terms and\n"
+		"conditions either of that version or of any later version published by\n"
+		"the Free Software Foundation.  If the Library does not specify a\n"
+		"license version number, you may choose any version ever published by\n"
+		"the Free Software Foundation.\n"
+		"\n"
+		"14. If you wish to incorporate parts of the Library into other free\n"
+		"programs whose distribution conditions are incompatible with these,\n"
+		"write to the author to ask for permission.  For software which is\n"
+		"copyrighted by the Free Software Foundation, write to the Free\n"
+		"Software Foundation; we sometimes make exceptions for this.  Our\n"
+		"decision will be guided by the two goals of preserving the free status\n"
+		"of all derivatives of our free software and of promoting the sharing\n"
+		"and reuse of software generally.\n"
+		"\n"
+		"NO WARRANTY\n"
+		"\n"
+		"15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\n"
+		"WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\n"
+		"EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\n"
+		"OTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\n"
+		"KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\n"
+		"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n"
+		"PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\n"
+		"LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\n"
+		"THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n"
+		"\n"
+		"16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\n"
+		"WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\n"
+		"AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\n"
+		"FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\n"
+		"CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\n"
+		"LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\n"
+		"RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\n"
+		"FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\n"
+		"SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n"
+		"DAMAGES.\n"
+		"\n"
+		"END OF TERMS AND CONDITIONS\n"
+		"\n"
+		"How to Apply These Terms to Your New Libraries\n"
+		"\n"
+		"If you develop a new library, and you want it to be of the greatest\n"
+		"possible use to the public, we recommend making it free software that\n"
+		"everyone can redistribute and change.  You can do so by permitting\n"
+		"redistribution under these terms (or, alternatively, under the terms of the\n"
+		"ordinary General Public License).\n"
+		"\n"
+		"To apply these terms, attach the following notices to the library.  It is\n"
+		"safest to attach them to the start of each source file to most effectively\n"
+		"convey the exclusion of warranty; and each file should have at least the\n"
+		"\"copyright\" line and a pointer to where the full notice is found.\n"
+		"\n"
+		"<one line to give the library\'s name and a brief idea of what it does.>\n"
+		"Copyright (C) <year>  <name of author>\n"
+		"\n"
+		"This library is free software; you can redistribute it and/or\n"
+		"modify it under the terms of the GNU Lesser General Public\n"
+		"License as published by the Free Software Foundation; either\n"
+		"version 2.1 of the License, or (at your option) any later version.\n"
+		"\n"
+		"This library is distributed in the hope that it will be useful,\n"
+		"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
+		"Lesser General Public License for more details.\n"
+		"\n"
+		"You should have received a copy of the GNU Lesser General Public\n"
+		"License along with this library; if not, write to the Free Software\n"
+		"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
+		"\n"
+		"Also add information on how to contact you by electronic and paper mail.\n"
+		"\n"
+		"You should also get your employer (if you work as a programmer) or your\n"
+		"school, if any, to sign a \"copyright disclaimer\" for the library, if\n"
+		"necessary.  Here is a sample; alter the names:\n"
+		"\n"
+		"Yoyodyne, Inc., hereby disclaims all copyright interest in the\n"
+		"library `Frob\' (a library for tweaking knobs) written by James Random Hacker.\n"
+		"\n"
+		"<signature of Ty Coon>, 1 April 1990\n"
+		"Ty Coon, President of Vice\n"
+		"\n"
+		"That\'s all there is to it!\n"
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     DLG_About.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_About_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_About_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_About : public CDLG_Base
+{
+	DECLARE_CLASS(CDLG_About)
+
+public:
+	CDLG_About(void);
+	virtual ~CDLG_About(void);
+
+	void						On_URL_Version			(wxTextUrlEvent &event);
+
+
+protected:
+
+	virtual void				Set_Position			(wxRect r);
+
+
+private:
+
+	class wxNotebook			*m_pControl;
+
+	class wxTextCtrl			*m_pVersion;
+
+
+	wxString					_Get_Version			(void);
+	wxString					_Get_Acknowledgements	(void);
+
+	wxString					_Get_GPL				(void);
+	wxString					_Get_LGPL				(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_About_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,145 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DLG_About_Logo.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+#include <wx/dcclient.h>
+
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "dlg_about_logo.h"
+
+#include <saga_api/api_core.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_About_Logo, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_About_Logo, wxPanel)
+	EVT_SIZE			(CDLG_About_Logo::On_Size)
+	EVT_PAINT			(CDLG_About_Logo::On_Paint)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_About_Logo::CDLG_About_Logo(wxWindow *pParent)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_logo	= IMG_Get_Bitmap(ID_IMG_SAGA_SPLASH);
+	m_icon	= IMG_Get_Bitmap(ID_IMG_SAGA_ICON_32);
+}
+
+//---------------------------------------------------------
+CDLG_About_Logo::~CDLG_About_Logo(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_About_Logo::On_Paint(wxPaintEvent &event)
+{
+	if( m_logo.Ok() && m_icon.Ok() )
+	{
+		int			x, y;
+		wxString	s;
+		wxPaintDC	dc(this);
+
+		x	= (GetClientSize().x - m_logo.GetWidth()) / 2;
+		y	= (GetClientSize().y - (m_logo.GetHeight() + 10 + m_icon.GetHeight())) / 2;
+		dc.DrawBitmap(m_logo, x, y, true);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_About_Logo::On_Size(wxSizeEvent &event)
+{
+	Refresh();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_about_logo.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   DLG_About_Logo.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_About_Logo_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_About_Logo_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+#include <wx/bitmap.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_About_Logo : public wxPanel
+{
+	DECLARE_CLASS(CDLG_About_Logo)
+
+public:
+	CDLG_About_Logo(wxWindow *pParent);
+	virtual ~CDLG_About_Logo(void);
+
+	void						On_Size				(wxSizeEvent &event);
+	void						On_Paint			(wxPaintEvent &event);
+
+
+protected:
+
+	wxBitmap					m_logo, m_icon;
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_About_Logo_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,249 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_Base.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/panel.h>
+#include <wx/button.h>
+
+#include "res_controls.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "dlg_base.h"
+
+//---------------------------------------------------------
+#define BUTTON_WIDTH	70
+#define CONTROL_DIST	5
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_Base, wxDialog)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_Base, wxDialog)
+	EVT_SIZE			(CDLG_Base::On_Size)
+
+	EVT_BUTTON			(wxID_OK		, CDLG_Base::On_Ok)
+	EVT_BUTTON			(wxID_CANCEL	, CDLG_Base::On_Cancel)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_Base::CDLG_Base(int id, wxString Caption, bool bCancelBtn)
+	: wxDialog(MDI_Get_Frame(), id, Caption, DLG_Get_Def_Position(), DLG_Get_Def_Size(), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
+{
+	MDI_Top_Window_Push(this);
+
+	m_Panel_Buttons	= new wxPanel(this);
+
+	m_nButtons		= 0;
+
+	Add_Button(wxID_OK);
+
+	if( bCancelBtn )
+	{
+		Add_Button(wxID_CANCEL);
+	}
+
+	m_nButtons++;
+}
+
+//---------------------------------------------------------
+CDLG_Base::~CDLG_Base(void)
+{
+	MDI_Top_Window_Pop(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Base::On_Size(wxSizeEvent &event)
+{
+	bool	bResize	= false;
+	wxSize	s;
+
+	s	= event.GetSize();
+//	s	= GetClientSize();
+
+	if( s.GetWidth() < 300 )
+	{
+		s.SetWidth(300);
+		bResize	= true;
+	}
+
+	if( s.GetHeight() < 300 )
+	{
+		s.SetHeight(300);
+		bResize	= true;
+	}
+
+	if( bResize )
+	{
+		SetSize(s);
+	}
+
+//	event.Skip();
+
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+void CDLG_Base::Set_Positions(void)
+{
+	int		xDivide, yTotal;
+
+	xDivide	= GetClientSize().GetWidth() - BUTTON_WIDTH - 2 * CONTROL_DIST;
+	yTotal	= GetClientSize().GetHeight() - 2 * CONTROL_DIST;
+
+	m_Panel_Buttons->SetSize(wxRect(xDivide + CONTROL_DIST, CONTROL_DIST, BUTTON_WIDTH, yTotal));
+
+	Set_Position(wxRect(CONTROL_DIST, CONTROL_DIST, xDivide - 2 * CONTROL_DIST, yTotal));
+}
+
+//---------------------------------------------------------
+void CDLG_Base::Set_Position(wxRect r)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Base::On_Ok(wxCommandEvent &event)
+{
+	_Exit(true);
+}
+
+//---------------------------------------------------------
+void CDLG_Base::On_Cancel(wxCommandEvent &event)
+{
+	_Exit(false);
+}
+
+//---------------------------------------------------------
+void CDLG_Base::_Exit(bool bOk)
+{
+	if( bOk )
+	{
+		Save_Changes();
+
+		EndModal(wxID_OK);
+	}
+	else
+	{
+		EndModal(wxID_CANCEL);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Base::Save_Changes(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Base::Add_Button(int Button_ID)
+{
+	if( Button_ID > 0 )
+	{
+		wxButton	*b	= new wxButton(m_Panel_Buttons, Button_ID, CTRL_Get_Name(Button_ID));
+
+		b->SetSize(0, CONTROL_DIST + m_nButtons * (CONTROL_DIST + b->GetDefaultSize().y), BUTTON_WIDTH, b->GetDefaultSize().y);
+	}
+
+	m_nButtons++;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     DLG_Base.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Base_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_Base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dialog.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_Base : public wxDialog
+{
+	DECLARE_CLASS(CDLG_Base)
+
+public:
+	CDLG_Base(int ID_WMD, wxString Caption, bool bCancelBtn = true);
+	virtual ~CDLG_Base(void);
+
+	void						On_Size			(wxSizeEvent &event);
+
+	void						On_Ok			(wxCommandEvent &event);
+	void						On_Cancel		(wxCommandEvent &event);
+
+
+protected:
+
+	void						Add_Button		(int Button_ID);
+
+	void						Set_Positions	(void);
+	virtual void				Set_Position	(wxRect r);
+
+	virtual void				Save_Changes	(void);
+
+
+private:
+
+	int							m_btn_height, m_nButtons;
+
+	class wxPanel				*m_Panel_Buttons;
+
+
+	void						_Exit			(bool bOk);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Base_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,249 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_Colors.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "dlg_colors.h"
+#include "dlg_colors_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_Colors, CDLG_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_Colors, CDLG_Base)
+	EVT_BUTTON			(ID_BTN_LOAD			, CDLG_Colors::On_Load)
+	EVT_BUTTON			(ID_BTN_SAVE			, CDLG_Colors::On_Save)
+	EVT_BUTTON			(ID_BTN_COLORS_COUNT	, CDLG_Colors::On_Count)
+	EVT_BUTTON			(ID_BTN_COLORS_MIRROR	, CDLG_Colors::On_Miror)
+	EVT_BUTTON			(ID_BTN_COLORS_INVERT	, CDLG_Colors::On_Invert)
+	EVT_BUTTON			(ID_BTN_COLORS_RANDOM	, CDLG_Colors::On_Random)
+	EVT_BUTTON			(ID_BTN_COLORS_PRESET	, CDLG_Colors::On_Preset)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_Colors::CDLG_Colors(CSG_Colors *pColors)
+	: CDLG_Base(-1, wxT("[CAP] Colors"))
+{
+	m_pOriginal	= pColors;
+	m_pColors	= new CSG_Colors();
+	m_pColors->Assign(pColors);
+
+	m_pControl	= new CDLG_Colors_Control(this, m_pColors);
+
+	Add_Button(ID_BTN_LOAD);
+	Add_Button(ID_BTN_SAVE);
+	Add_Button(-1);
+	Add_Button(ID_BTN_COLORS_COUNT);
+	Add_Button(ID_BTN_COLORS_MIRROR);
+	Add_Button(ID_BTN_COLORS_INVERT);
+	Add_Button(ID_BTN_COLORS_RANDOM);
+	Add_Button(ID_BTN_COLORS_PRESET);
+
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+CDLG_Colors::~CDLG_Colors(void)
+{
+	delete(m_pColors);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Colors::Set_Position(wxRect r)
+{
+	m_pControl->SetSize(r);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Colors::Save_Changes(void)
+{
+	m_pOriginal->Assign(m_pColors);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Load(wxCommandEvent &event)
+{
+	wxString	File_Path;
+
+	if( DLG_Open(File_Path, ID_DLG_COLORS_OPEN) )
+	{
+		if( m_pColors->Load(File_Path.c_str()) == false )
+		{
+			DLG_Message_Show(LNG("Colors file could not be imported."), LNG("Load Colors"));
+		}
+		else
+		{
+			m_pControl->Refresh(false);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Save(wxCommandEvent &event)
+{
+	wxString	File_Path;
+
+	if( DLG_Save(File_Path, ID_DLG_COLORS_SAVE) )
+	{
+		if( m_pColors->Save(File_Path.c_str(), true) == false )
+		{
+			DLG_Message_Show(LNG("Colors file could not be exported."), LNG("Save Colors"));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Count(wxCommandEvent &event)
+{
+	int		Count;
+
+	if( DLG_Get_Number(Count = m_pColors->Get_Count()) )
+	{
+		m_pColors->Set_Count(Count);
+
+		m_pControl->Refresh(false);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Miror(wxCommandEvent &event)
+{
+	m_pColors->Revert();
+
+	m_pControl->Refresh(false);
+}
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Invert(wxCommandEvent &event)
+{
+	m_pColors->Invert();
+
+	m_pControl->Refresh(false);
+}
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Random(wxCommandEvent &event)
+{
+	m_pColors->Random();
+
+	m_pControl->Refresh(false);
+}
+
+//---------------------------------------------------------
+void CDLG_Colors::On_Preset(wxCommandEvent &event)
+{
+	int		Palette;
+
+	if( DLG_Colors(Palette) )
+	{
+		m_pColors->Set_Palette(Palette, false, m_pColors->Get_Count());
+
+		m_pControl->Refresh(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_Colors.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Colors_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_Colors_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_Colors : public CDLG_Base
+{
+	DECLARE_CLASS(CDLG_Colors)
+
+public:
+	CDLG_Colors(class CSG_Colors *pColors);
+	virtual ~CDLG_Colors(void);
+
+	void						On_Load			(wxCommandEvent &event);
+	void						On_Save			(wxCommandEvent &event);
+
+	void						On_Count		(wxCommandEvent &event);
+	void						On_Miror		(wxCommandEvent &event);
+	void						On_Invert		(wxCommandEvent &event);
+	void						On_Random		(wxCommandEvent &event);
+	void						On_Preset		(wxCommandEvent &event);
+
+
+protected:
+
+	class CSG_Colors				*m_pColors, *m_pOriginal;
+
+	class CDLG_Colors_Control	*m_pControl;
+
+
+	virtual void				Set_Position	(wxRect r);
+
+	virtual void				Save_Changes	(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Colors_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,465 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                DLG_Colors_Control.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/textdlg.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "dlg_colors_control.h"
+
+//---------------------------------------------------------
+#define BOX_DISTANCE	10
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_Colors_Control, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_Colors_Control, wxPanel)
+	EVT_SIZE			(CDLG_Colors_Control::On_Size)
+	EVT_PAINT			(CDLG_Colors_Control::On_Paint)
+
+	EVT_LEFT_DOWN		(CDLG_Colors_Control::On_Mouse_LDown)
+	EVT_MOTION			(CDLG_Colors_Control::On_Mouse_Motion)
+	EVT_LEFT_UP			(CDLG_Colors_Control::On_Mouse_LUp)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_Colors_Control::CDLG_Colors_Control(wxWindow *pParent, CSG_Colors *pColors)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize)
+{
+	m_pColors	= pColors;
+	m_selBox	= -1;
+}
+
+//---------------------------------------------------------
+CDLG_Colors_Control::~CDLG_Colors_Control(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::Set_Positions(void)
+{
+	int		Height, Position;
+	wxRect	r(wxPoint(0, 0), GetClientSize());
+
+	r.Deflate(BOX_DISTANCE);
+
+	Height	= (int)(r.GetHeight() / (4 + 0.25));
+
+	Position	= r.GetTop();
+	m_red		= wxRect(r.GetX(), Position, r.GetWidth(), Height - BOX_DISTANCE);
+
+	Position	+= Height;
+	m_green		= wxRect(r.GetX(), Position, r.GetWidth(), Height - BOX_DISTANCE);
+
+	Position	+= Height;
+	m_blue		= wxRect(r.GetX(), Position, r.GetWidth(), Height - BOX_DISTANCE);
+
+	Position	+= Height;
+	m_sum		= wxRect(r.GetX(), Position, r.GetWidth(), Height - BOX_DISTANCE);
+
+	Position	+= Height;
+	m_rgb		= wxRect(r.GetX(), Position, r.GetWidth(), (int)(Height * 0.25));
+
+	Refresh();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::On_Size(wxSizeEvent &event)
+{
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::On_Paint(wxPaintEvent &event)
+{
+	wxPaintDC	dc(this);
+
+	Draw_Edge(dc, EDGE_STYLE_STATIC, wxRect(wxPoint(0, 0), GetClientSize()));
+
+	Draw_Box(dc, 0);
+	Draw_Box(dc, 1);
+	Draw_Box(dc, 2);
+	Draw_Box(dc, 3);
+	Draw_Box(dc, 4);
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::Draw_Box(wxDC &dc, int BoxID)
+{
+	int		i, r, g, b, s, ax, ay, bx, by;
+	double	xStep, yStep;
+	wxRect	rBox;
+
+	//-----------------------------------------------------
+	Get_BoxRect(rBox, BoxID);
+
+	rBox.Inflate(1);
+	Draw_FillRect(dc, SYS_Get_Color(wxSYS_COLOUR_WINDOW), rBox);
+	Draw_Edge(dc, EDGE_STYLE_SUNKEN, rBox);
+	rBox.Deflate(1);
+
+	//-----------------------------------------------------
+	xStep	= (double)rBox.GetWidth() / (double)m_pColors->Get_Count();
+	yStep	= (double)rBox.GetHeight() / 255.0;
+
+	ax		= rBox.GetLeft();
+	ay		= rBox.GetBottom() + 1;
+
+	r	= g	= b	= 0;
+	s	= 255;
+
+	//-----------------------------------------------------
+	for(i=0; i<m_pColors->Get_Count(); i++)
+	{
+		switch( BoxID )
+		{
+		case 0:
+			r	= s	= m_pColors->Get_Red  (i);
+			break;
+
+		case 1:
+			g	= s	= m_pColors->Get_Green(i);
+			break;
+
+		case 2:
+			b	= s	= m_pColors->Get_Blue (i);
+			break;
+
+		case 3:
+			r	= m_pColors->Get_Red  (i);
+			g	= m_pColors->Get_Green(i);
+			b	= m_pColors->Get_Blue (i);
+			s	= (r + g + b) / 3;
+			break;
+
+		case 4:
+			r	= m_pColors->Get_Red  (i);
+			g	= m_pColors->Get_Green(i);
+			b	= m_pColors->Get_Blue (i);
+			break;
+		}
+
+		bx	= ax;
+		ax	= rBox.GetLeft() + (int)(xStep * (i + 1.0));
+		by	= ay - (int)(yStep * (double)s);
+
+		Draw_FillRect(dc, wxColour(r, g, b), ax, ay, bx, by);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::Draw_Line(wxPoint pA, wxPoint pB)
+{
+	wxClientDC	dc(this);
+
+	dc.SetLogicalFunction(wxINVERT);
+	dc.DrawLine(pA.x, pA.y, pB.x, pB.y);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::On_Mouse_LDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+
+	if( (m_selBox = Get_SelBox(m_Mouse_Down)) >= 0 )
+	{
+		CaptureMouse();
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::On_Mouse_Motion(wxMouseEvent &event)
+{
+	if( m_selBox >= 0 )
+	{
+		Draw_Line(m_Mouse_Down, m_Mouse_Move);
+		m_Mouse_Move	= event.GetPosition();
+		KeepInBoxRect(m_Mouse_Move, m_selBox);
+		Draw_Line(m_Mouse_Down, m_Mouse_Move);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::On_Mouse_LUp(wxMouseEvent &event)
+{
+	if( m_selBox >= 0 )
+	{
+		Draw_Line(m_Mouse_Down, m_Mouse_Move);
+
+		m_Mouse_Move	= event.GetPosition();
+
+		Set_Colors(m_Mouse_Down, m_Mouse_Move, m_selBox);
+
+		m_selBox		= -1;
+
+		ReleaseMouse();
+
+		Refresh(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxPoint CDLG_Colors_Control::Get_ColorPosition(wxPoint p, int BoxID)
+{
+	wxRect	r;
+
+	if( Get_BoxRect(r, BoxID) )
+	{
+		KeepInBoxRect(p, BoxID);
+
+		p.x	= (int)((double)(p.x - r.GetLeft())		* m_pColors->Get_Count() / r.GetWidth());
+		p.y	= (int)((double)(r.GetBottom() - p.y)	* 256.0 / r.GetHeight());
+	}
+
+	return( p );
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::Set_Colors(wxPoint pA, wxPoint pB, int BoxID) 
+{
+	int		i, x, Value;
+	double	dy;
+	wxPoint	p;
+
+	//-----------------------------------------------------
+	pA	= Get_ColorPosition(pA, BoxID);
+	pB	= Get_ColorPosition(pB, BoxID);
+
+	if( pA.x > pB.x )
+	{
+		p	= pA;
+		pA	= pB;
+		pB	= p;
+	}
+
+	if( pA.x < 0 )
+	{
+		pA.x	= 0;
+	}
+
+	if( pB.x >= m_pColors->Get_Count() )
+	{
+		pB.x	= m_pColors->Get_Count() - 1;
+	}
+
+	dy	= pA.x == pB.x ? 0 : (double)(pB.y - pA.y) / (double)(pB.x - pA.x);
+
+	//-----------------------------------------------------
+	for(i=pA.x, x=0; i<=pB.x; i++, x++)
+	{
+		Value	= (int)(pA.y + dy * x);
+
+		switch( BoxID )
+		{
+		case 0:
+			m_pColors->Set_Red			(i, Value);
+			break;
+
+		case 1:
+			m_pColors->Set_Green		(i, Value);
+			break;
+
+		case 2:
+			m_pColors->Set_Blue			(i, Value);
+			break;
+
+		case 3:
+			m_pColors->Set_Brightness	(i, Value);
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CDLG_Colors_Control::Get_SelBox(wxPoint p)
+{
+	for(int i=0; i<4; i++)
+	{
+		if( IsInBoxRect(p, i) )
+		{
+			return( i );
+		}
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+bool CDLG_Colors_Control::IsInBoxRect(wxPoint p, int BoxID)
+{
+	wxRect	r;
+
+	if( Get_BoxRect(r, BoxID) )
+	{
+		if(	p.x >= r.GetLeft()	&& p.x <= r.GetRight()
+		&&	p.y >= r.GetTop()	&& p.y <= r.GetBottom()	)
+		{
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CDLG_Colors_Control::KeepInBoxRect(wxPoint &p, int BoxID)
+{
+	wxRect	r;
+
+	if( Get_BoxRect(r, BoxID) )
+	{
+		if( p.x < r.GetLeft() )
+		{
+			p.x	= r.GetLeft();
+		}
+		else if( p.x > r.GetRight() )
+		{
+			p.x	= r.GetRight();
+		}
+		
+		if( p.y < r.GetTop() )
+		{
+			p.y	= r.GetTop();
+		}
+		else if( p.y > r.GetBottom() )
+		{
+			p.y	= r.GetBottom();
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CDLG_Colors_Control::Get_BoxRect(wxRect &r, int BoxID)
+{
+	switch( BoxID )
+	{
+	case 0:	r	= m_red;	break;
+	case 1:	r	= m_green;	break;
+	case 2:	r	= m_blue;	break;
+	case 3:	r	= m_sum;	break;
+	case 4:	r	= m_rgb;	break;
+	default:	return( false );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_colors_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,135 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 DLG_Colors_Control.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Colors_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_Colors_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_Colors_Control : public wxPanel
+{
+	DECLARE_CLASS(CDLG_Colors_Control)
+
+public:
+	CDLG_Colors_Control(wxWindow *pParent, class CSG_Colors *pColors);
+	virtual ~CDLG_Colors_Control(void);
+
+	void						On_Size				(wxSizeEvent &event);
+	void						On_Paint			(wxPaintEvent &event);
+
+	void						On_Mouse_LDown		(wxMouseEvent &event);
+	void						On_Mouse_Motion		(wxMouseEvent &event);
+	void						On_Mouse_LUp		(wxMouseEvent &event);
+
+	void						Set_Positions		(void);
+
+
+protected:
+
+	int							m_selBox;
+
+	wxPoint						m_Mouse_Down, m_Mouse_Move;
+
+	wxRect						m_red, m_green, m_blue, m_sum, m_rgb;
+
+	class CSG_Colors				*m_pColors;
+
+
+	void						Draw_Box			(wxDC &dc, int BoxID);
+	void						Draw_Line			(wxPoint pA, wxPoint pB);
+
+	wxPoint						Get_ColorPosition	(wxPoint p, int BoxID);
+	void						Set_Colors			(wxPoint pA, wxPoint pB, int BoxID) ;
+
+	int							Get_SelBox			(wxPoint p);
+	bool						IsInBoxRect			(wxPoint p, int BoxID);
+	void						KeepInBoxRect		(wxPoint &p, int BoxID);
+	bool						Get_BoxRect			(wxRect &r, int BoxID);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Colors_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,352 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DLG_List_Base.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+
+#include "wksp_data_manager.h"
+
+#include "dlg_list_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_List_Base, CDLG_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_List_Base, CDLG_Base)
+	EVT_BUTTON			(ID_BTN_ADD			, CDLG_List_Base::On_Add)
+	EVT_BUTTON			(ID_BTN_DELETE		, CDLG_List_Base::On_Del)
+	EVT_BUTTON			(ID_BTN_UP			, CDLG_List_Base::On_Up)
+	EVT_BUTTON			(ID_BTN_DOWN		, CDLG_List_Base::On_Down)
+
+	EVT_LISTBOX_DCLICK	(ID_LISTBOX_SELECT	, CDLG_List_Base::On_DClick_Add)
+	EVT_LISTBOX_DCLICK	(ID_LISTBOX_ADD		, CDLG_List_Base::On_DClick_Del)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_List_Base::CDLG_List_Base(CSG_Parameter_List *pList, wxString Caption)
+	: CDLG_Base(-1, Caption)
+{
+	m_pList			= pList;
+
+	m_pSelect		= new wxListBox	(this, ID_LISTBOX_SELECT, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_MULTIPLE|wxLB_NEEDED_SB|wxLB_SORT);	// |wxLB_EXTENDED
+	m_pAdd			= new wxListBox	(this, ID_LISTBOX_ADD   , wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_MULTIPLE|wxLB_NEEDED_SB);
+
+	m_pBtn_Add		= new wxButton	(this, ID_BTN_ADD   , wxT(">>"));
+	m_pBtn_Del		= new wxButton	(this, ID_BTN_DELETE, wxT("<<"));
+	m_pBtn_Up		= new wxButton	(this, ID_BTN_UP    , CTRL_Get_Name(ID_BTN_UP));
+	m_pBtn_Down		= new wxButton	(this, ID_BTN_DOWN  , CTRL_Get_Name(ID_BTN_DOWN));
+
+	m_btn_height	= m_pBtn_Add->GetDefaultSize().y;
+
+	//-----------------------------------------------------
+	int		i, Type;
+
+	switch( m_pList->Get_Type() )
+	{
+	case PARAMETER_TYPE_Grid_List:		Type	= DATAOBJECT_TYPE_Grid;		break;
+	case PARAMETER_TYPE_Table_List:		Type	= DATAOBJECT_TYPE_Table;	break;
+	case PARAMETER_TYPE_Shapes_List:	Type	= DATAOBJECT_TYPE_Shapes;	break;
+	default:	return;
+	}
+
+	for(i=m_pList->Get_Count()-1; i>=0; i--)
+	{
+		if( !g_pData->Exists(m_pList->asDataObject(i), Type) )
+		{
+			m_pList->Del_Item(i);
+		}
+	}
+
+	//-----------------------------------------------------
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+CDLG_List_Base::~CDLG_List_Base(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Base::Set_Position(wxRect r)
+{
+	int		Center;
+
+	r.Deflate(5);
+	Center	= r.GetLeft() + r.GetWidth() / 2;
+
+	r.SetWidth(r.GetWidth() / 2 - (DLG_LIST_BTN_WIDTH / 2 + DLG_LIST_BTN_DIST));
+	m_pSelect->SetSize(r);
+
+	r.SetLeft(Center            + (DLG_LIST_BTN_WIDTH / 2 + DLG_LIST_BTN_DIST));
+	m_pAdd->SetSize(r);
+
+	r		= wxRect(Center - DLG_LIST_BTN_WIDTH / 2, r.GetTop(), DLG_LIST_BTN_WIDTH, m_btn_height);
+	m_pBtn_Add->SetSize(r);
+
+	r.SetTop(r.GetBottom() + DLG_LIST_BTN_DIST);
+	m_pBtn_Del->SetSize(r);
+
+	r.SetTop(r.GetBottom() + DLG_LIST_BTN_DIST * 2);
+	m_pBtn_Up->SetSize(r);
+
+	r.SetTop(r.GetBottom() + DLG_LIST_BTN_DIST);
+	m_pBtn_Down->SetSize(r);
+}
+
+//---------------------------------------------------------
+void CDLG_List_Base::Save_Changes(void)
+{
+	m_pList->Del_Items();
+
+	for(unsigned int i=0; i<m_pAdd->GetCount(); i++)
+	{
+		m_pList->Add_Item((CSG_Data_Object *)m_pAdd->GetClientData(i));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int ArrayInt_CMP_Up(int *first, int *second)
+{
+	return( *first - *second );
+}
+
+//---------------------------------------------------------
+int ArrayInt_CMP_Down(int *first, int *second)
+{
+	return( *second - *first );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Base::On_Del(wxCommandEvent &event)
+{
+	_Del();
+}
+
+void CDLG_List_Base::On_DClick_Del(wxCommandEvent &event)
+{
+	_Del();
+}
+
+void CDLG_List_Base::_Del(void)
+{
+	int			i, j, n;
+	wxArrayInt	Selections;
+
+	if( (n = m_pAdd->GetSelections(Selections)) > 0 )
+	{
+		Selections.Sort(ArrayInt_CMP_Down);
+
+		for(i=0; i<n; i++)
+		{
+			j	= Selections.Item(i);
+
+			m_pSelect->Append(m_pAdd->GetString(j), m_pAdd->GetClientData(j));
+			m_pAdd->Delete(j);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_List_Base::On_Add(wxCommandEvent &event)
+{
+	_Add();
+}
+
+void CDLG_List_Base::On_DClick_Add(wxCommandEvent &event)
+{
+	_Add();
+}
+
+void CDLG_List_Base::_Add(void)
+{
+	int			i, j, n;
+	wxArrayInt	Selections;
+
+	if( (n = m_pSelect->GetSelections(Selections)) > 0 )
+	{
+		Selections.Sort(ArrayInt_CMP_Down);
+
+		for(i=0; i<n; i++)
+		{
+			j	= Selections.Item(i);
+
+			m_pAdd->Append(m_pSelect->GetString(j), m_pSelect->GetClientData(j));
+			m_pSelect->Delete(j);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Base::On_Up(wxCommandEvent &event)
+{
+	void			*pData;
+	unsigned int	i, j, n;
+	wxArrayInt		Selections;
+	wxString		String;
+
+	if( (n = m_pAdd->GetSelections(Selections)) > 0 && n < m_pAdd->GetCount() )
+	{
+		Selections.Sort(ArrayInt_CMP_Up);
+
+		if( Selections.Item(0) > 0 )
+		{
+			for(i=0; i<n; i++)
+			{
+				j		= Selections.Item(i);
+
+				String	= m_pAdd->GetString(j);
+				m_pAdd->SetString(j, m_pAdd->GetString(j - 1));
+				m_pAdd->SetString(j - 1, String);
+
+				pData	= m_pAdd->GetClientData(j);
+				m_pAdd->SetClientData(j, m_pAdd->GetClientData(j - 1));
+				m_pAdd->SetClientData(j - 1, pData);
+
+				m_pAdd->SetSelection(j - 1, true);
+				m_pAdd->SetSelection(j, false);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_List_Base::On_Down(wxCommandEvent &event)
+{
+	void		*pData;
+	int			i, j, n;
+	wxArrayInt	Selections;
+	wxString	String;
+
+	if( (n = m_pAdd->GetSelections(Selections)) > 0 && n < (int)m_pAdd->GetCount() )
+	{
+		Selections.Sort(ArrayInt_CMP_Down);
+
+		if( Selections.Item(0) < (int)m_pAdd->GetCount() - 1 )
+		{
+			for(i=0; i<(int)Selections.GetCount(); i++)
+			{
+				j		= Selections.Item(i);
+
+				String	= m_pAdd->GetString(j);
+				m_pAdd->SetString(j, m_pAdd->GetString(j + 1));
+				m_pAdd->SetString(j + 1, String);
+
+				pData	= m_pAdd->GetClientData(j);
+				m_pAdd->SetClientData(j, m_pAdd->GetClientData(j + 1));
+				m_pAdd->SetClientData(j + 1, pData);
+
+				m_pAdd->SetSelection(j + 1, true);
+				m_pAdd->SetSelection(j, false);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,145 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   DLG_List_Base.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Base_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_List_Base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/button.h>
+#include <wx/listbox.h>
+
+#include "dlg_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DLG_LIST_BTN_WIDTH		40
+#define DLG_LIST_BTN_DIST		4
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_List_Base : public CDLG_Base
+{
+	DECLARE_CLASS(CDLG_List_Base)
+
+public:
+	CDLG_List_Base(class CSG_Parameter_List *pList, wxString Caption);
+	virtual ~CDLG_List_Base(void);
+
+	void						On_Add			(wxCommandEvent &event);
+	void						On_DClick_Add	(wxCommandEvent &event);
+	void						On_Del			(wxCommandEvent &event);
+	void						On_DClick_Del	(wxCommandEvent &event);
+	void						On_Up			(wxCommandEvent &event);
+	void						On_Down			(wxCommandEvent &event);
+
+
+protected:
+
+	int							m_btn_height;
+
+	wxButton					*m_pBtn_Add, *m_pBtn_Del, *m_pBtn_Up, *m_pBtn_Down;
+
+	wxListBox					*m_pAdd, *m_pSelect;
+
+	class CSG_Parameter_List		*m_pList;
+
+
+	virtual void				Set_Position	(wxRect r);
+
+	virtual void				Save_Changes	(void);
+
+	virtual void				_Set_Objects	(void)	= 0;
+
+	void						_Add			(void);
+	void						_Del			(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Base_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,259 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DLG_List_Grid.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_grid_manager.h"
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+
+#include "dlg_list_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_List_Grid, CDLG_List_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_List_Grid, CDLG_List_Base)
+	EVT_CHOICE		(ID_COMBOBOX_SELECT, CDLG_List_Grid::On_Select_System)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_List_Grid::CDLG_List_Grid(CSG_Parameter_Grid_List *pList, wxString Caption)
+	: CDLG_List_Base(pList, Caption)
+{
+	CWKSP_Grid_Manager	*pManager;
+
+	if( (pManager = g_pData->Get_Grids()) != NULL )
+	{
+		if( pList->Get_System() )
+		{
+			m_pSystem	= pManager->Get_System(pList->Get_System());
+			m_pSystems	= NULL;
+		}
+		else
+		{
+			m_pSystem	= NULL;
+			m_pSystems	= new wxChoice(this, ID_COMBOBOX_SELECT, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
+
+			for(int i=0; i<pManager->Get_Count(); i++)
+			{
+				m_pSystems->Append(pManager->Get_System(i)->Get_Name());
+			}
+
+			m_pSystems->Append( LNG("[VAL] [all grid systems]") );
+			m_pSystems->SetSelection(m_pSystems->GetCount() - 1);
+
+			Set_Positions();
+		}
+
+		_Set_Objects();
+	}
+}
+
+//---------------------------------------------------------
+CDLG_List_Grid::~CDLG_List_Grid(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Grid::Set_Position(wxRect r)
+{
+	int		Width, Height;
+
+	CDLG_List_Base::Set_Position(r);
+
+	if( m_pSystems )
+	{
+		r.Deflate(5);
+
+		Height	= m_pSystems->GetSize().GetHeight();
+		Width	= r.GetWidth() / 2 - (DLG_LIST_BTN_WIDTH / 2 + DLG_LIST_BTN_DIST);
+
+		m_pSystems	->SetSize(wxRect(r.GetLeft(), r.GetTop(), Width, Height));
+		m_pSelect	->SetSize(wxRect(r.GetLeft(), r.GetTop() + Height, Width, r.GetHeight() - Height));
+		m_pSelect	->Refresh();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Grid::On_Select_System(wxCommandEvent &event)
+{
+	_Set_Grids();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Grid::_Set_Objects(void)
+{
+	//-----------------------------------------------------
+	for(int i=0; i<m_pList->Get_Count(); i++)
+	{
+		m_pAdd->Append(m_pList->asDataObject(i)->Get_Name(), m_pList->asDataObject(i));
+	}
+
+	//-----------------------------------------------------
+	if( ((CSG_Parameter_Grid_List *)m_pList)->Get_System() )
+	{
+		_Set_Grids(m_pSystem);
+	}
+	else
+	{
+		_Set_Grids();
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_List_Grid::_Set_Grids(void)
+{
+	CWKSP_Grid_Manager	*pManager;
+
+	m_pSelect->Clear();
+
+	if( (pManager = g_pData->Get_Grids()) != NULL )
+	{
+		int		i;
+
+		if( !m_pSystems || (i = m_pSystems->GetSelection()) >= pManager->Get_Count() || i < 0 )
+		{
+			for(i=0; i<pManager->Get_Count(); i++)
+			{
+				_Set_Grids(pManager->Get_System(i));
+			}
+		}
+		else
+		{
+			_Set_Grids(pManager->Get_System(i));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_List_Grid::_Set_Grids(CWKSP_Grid_System *pSystem)
+{
+	bool		bList;
+	int			i, j;
+	CSG_Grid	*pGrid;
+
+	if( pSystem )
+	{
+		for(i=0; i<pSystem->Get_Count(); i++)
+		{
+			pGrid	= pSystem->Get_Grid(i)->Get_Grid();
+
+			for(j=0, bList=true; j<(int)m_pAdd->GetCount() && bList; j++)
+			{
+				if( pGrid == m_pAdd->GetClientData(j) )
+				{
+					bList	= false;
+				}
+			}
+
+			if( bList )
+			{
+				m_pSelect->Append(pGrid->Get_Name(), pGrid);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   DLG_List_Grid.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Grid_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_List_Grid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/choice.h>
+
+#include "dlg_list_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_List_Grid : public CDLG_List_Base
+{
+	DECLARE_CLASS(CDLG_List_Grid)
+
+public:
+	CDLG_List_Grid(CSG_Parameter_Grid_List *pList, wxString Caption);
+	virtual ~CDLG_List_Grid(void);
+
+	void						On_Select_System	(wxCommandEvent &event);
+
+
+protected:
+
+	wxChoice					*m_pSystems;
+
+	class CWKSP_Grid_System		*m_pSystem;
+
+
+	virtual void				Set_Position		(wxRect r);
+
+	virtual void				_Set_Objects		(void);
+
+	void						_Set_Grids			(void);
+	void						_Set_Grids			(class CWKSP_Grid_System *pSystem);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Grid_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                DLG_List_PointCloud.cpp                //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstrasse 55                       //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_data_manager.h"
+#include "wksp_pointcloud_manager.h"
+#include "wksp_pointcloud.h"
+
+#include "dlg_list_pointcloud.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_List_PointCloud, CDLG_List_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_List_PointCloud, CDLG_List_Base)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_List_PointCloud::CDLG_List_PointCloud(CSG_Parameter_PointCloud_List *pList, wxString Caption)
+	: CDLG_List_Base(pList, Caption)
+{
+	_Set_Objects();
+}
+
+//---------------------------------------------------------
+CDLG_List_PointCloud::~CDLG_List_PointCloud(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_PointCloud::_Set_Objects(void)
+{
+	bool						bList;
+	int							i, j;
+	CWKSP_PointCloud_Manager	*pPointClouds;
+	CSG_PointCloud				*pPointCloud;
+
+	//-----------------------------------------------------
+	if( (pPointClouds = g_pData->Get_PointClouds()) != NULL )
+	{
+		for(i=0; i<m_pList->Get_Count(); i++)
+		{
+			m_pAdd->Append(m_pList->asDataObject(i)->Get_Name(), m_pList->asDataObject(i));
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<pPointClouds->Get_Count(); i++)
+		{
+			pPointCloud	= pPointClouds->Get_PointCloud(i)->Get_PointCloud();
+
+			for(j=0, bList=true; j<(int)m_pAdd->GetCount() && bList; j++)
+			{
+				if( pPointCloud == m_pAdd->GetClientData(j) )
+				{
+					bList	= false;
+				}
+			}
+
+			if( bList )
+			{
+				m_pSelect->Append(pPointCloud->Get_Name(), pPointCloud);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_pointcloud.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                DLG_List_PointCloud.h                  //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Bundesstrasse 55                       //
+//                20146 Hamburg                          //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_PointCloud_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_List_PointCloud_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_list_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_List_PointCloud : public CDLG_List_Base
+{
+	DECLARE_CLASS(CDLG_List_PointCloud)
+
+public:
+	CDLG_List_PointCloud(CSG_Parameter_PointCloud_List *pList, wxString Caption);
+	virtual ~CDLG_List_PointCloud(void);
+
+
+protected:
+
+	virtual void				_Set_Objects(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_PointCloud_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,177 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 DLG_List_Shapes.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_data_manager.h"
+#include "wksp_shapes_manager.h"
+#include "wksp_shapes_type.h"
+#include "wksp_shapes.h"
+
+#include "dlg_list_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_List_Shapes, CDLG_List_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_List_Shapes, CDLG_List_Base)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_List_Shapes::CDLG_List_Shapes(CSG_Parameter_Shapes_List *pList, wxString Caption)
+	: CDLG_List_Base(pList, Caption)
+{
+	m_Shape_Type	= pList->Get_Shape_Type();
+
+	_Set_Objects();
+}
+
+//---------------------------------------------------------
+CDLG_List_Shapes::~CDLG_List_Shapes(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Shapes::_Set_Objects(void)
+{
+	int						i;
+	CWKSP_Shapes_Manager	*pManager;
+
+	//-----------------------------------------------------
+	if( (pManager = g_pData->Get_Shapes()) != NULL )
+	{
+		for(i=0; i<m_pList->Get_Count(); i++)
+		{
+			m_pAdd->Append(m_pList->asDataObject(i)->Get_Name(), m_pList->asDataObject(i));
+		}
+
+		//-------------------------------------------------
+		if( m_Shape_Type == SHAPE_TYPE_Undefined )
+		{
+			for(i=0; i<pManager->Get_Count(); i++)
+			{
+				_Set_Shapes((CWKSP_Shapes_Type *)pManager->Get_Item(i));
+			}
+		}
+		else
+		{
+			_Set_Shapes(pManager->Get_Shapes_Type(m_Shape_Type));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_List_Shapes::_Set_Shapes(CWKSP_Shapes_Type *pType)
+{
+	bool		bList;
+	int			i, j;
+	CSG_Shapes	*pShapes;
+
+	if( pType )
+	{
+		for(i=0; i<pType->Get_Count(); i++)
+		{
+			pShapes	= pType->Get_Shapes(i)->Get_Shapes();
+
+			for(j=0, bList=true; j<(int)m_pAdd->GetCount() && bList; j++)
+			{
+				if( pShapes == m_pAdd->GetClientData(j) )
+				{
+					bList	= false;
+				}
+			}
+
+			if( bList )
+			{
+				m_pSelect->Append(pShapes->Get_Name(), pShapes);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DLG_List_Shapes.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Shapes_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_List_Shapes_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_list_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_List_Shapes : public CDLG_List_Base
+{
+	DECLARE_CLASS(CDLG_List_Shapes)
+
+public:
+	CDLG_List_Shapes(CSG_Parameter_Shapes_List *pList, wxString Caption);
+	virtual ~CDLG_List_Shapes(void);
+
+
+protected:
+
+	int							m_Shape_Type;
+
+
+	virtual void				_Set_Objects(void);
+
+	void						_Set_Shapes(class CWKSP_Shapes_Type *pType);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Shapes_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DLG_List_Table.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_data_manager.h"
+#include "wksp_table_manager.h"
+#include "wksp_table.h"
+
+#include "dlg_list_table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_List_Table, CDLG_List_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_List_Table, CDLG_List_Base)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_List_Table::CDLG_List_Table(CSG_Parameter_Table_List *pList, wxString Caption)
+	: CDLG_List_Base(pList, Caption)
+{
+	_Set_Objects();
+}
+
+//---------------------------------------------------------
+CDLG_List_Table::~CDLG_List_Table(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_Table::_Set_Objects(void)
+{
+	bool				bList;
+	int					i, j;
+	CWKSP_Table_Manager	*pTables;
+	CSG_Table			*pTable;
+
+	//-----------------------------------------------------
+	if( (pTables = g_pData->Get_Tables()) != NULL )
+	{
+		for(i=0; i<m_pList->Get_Count(); i++)
+		{
+			m_pAdd->Append(m_pList->asDataObject(i)->Get_Name(), m_pList->asDataObject(i));
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<pTables->Get_Count(); i++)
+		{
+			pTable	= pTables->Get_Table(i)->Get_Table();
+
+			for(j=0, bList=true; j<(int)m_pAdd->GetCount() && bList; j++)
+			{
+				if( pTable == m_pAdd->GetClientData(j) )
+				{
+					bList	= false;
+				}
+			}
+
+			if( bList )
+			{
+				m_pSelect->Append(pTable->Get_Name(), pTable);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   DLG_List_Table.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Table_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_List_Table_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_list_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_List_Table : public CDLG_List_Base
+{
+	DECLARE_CLASS(CDLG_List_Table)
+
+public:
+	CDLG_List_Table(CSG_Parameter_Table_List *pList, wxString Caption);
+	virtual ~CDLG_List_Table(void);
+
+
+protected:
+
+	virtual void				_Set_Objects(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_Table_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,153 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   DLG_List_TIN.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_data_manager.h"
+#include "wksp_tin_manager.h"
+#include "wksp_tin.h"
+
+#include "dlg_list_tin.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_List_TIN, CDLG_List_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_List_TIN, CDLG_List_Base)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_List_TIN::CDLG_List_TIN(CSG_Parameter_TIN_List *pList, wxString Caption)
+	: CDLG_List_Base(pList, Caption)
+{
+	_Set_Objects();
+}
+
+//---------------------------------------------------------
+CDLG_List_TIN::~CDLG_List_TIN(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_List_TIN::_Set_Objects(void)
+{
+	bool				bList;
+	int					i, j;
+	CWKSP_TIN_Manager	*pTINs;
+	CSG_TIN				*pTIN;
+
+	//-----------------------------------------------------
+	if( (pTINs = g_pData->Get_TINs()) != NULL )
+	{
+		for(i=0; i<m_pList->Get_Count(); i++)
+		{
+			m_pAdd->Append(m_pList->asDataObject(i)->Get_Name(), m_pList->asDataObject(i));
+		}
+
+		//-------------------------------------------------
+		for(i=0; i<pTINs->Get_Count(); i++)
+		{
+			pTIN	= pTINs->Get_TIN(i)->Get_TIN();
+
+			for(j=0, bList=true; j<(int)m_pAdd->GetCount() && bList; j++)
+			{
+				if( pTIN == m_pAdd->GetClientData(j) )
+				{
+					bList	= false;
+				}
+			}
+
+			if( bList )
+			{
+				m_pSelect->Append(pTIN->Get_Name(), pTIN);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_list_tin.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,108 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_List_TIN.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_TIN_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_List_TIN_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_list_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_List_TIN : public CDLG_List_Base
+{
+	DECLARE_CLASS(CDLG_List_TIN)
+
+public:
+	CDLG_List_TIN(CSG_Parameter_TIN_List *pList, wxString Caption);
+	virtual ~CDLG_List_TIN(void);
+
+
+protected:
+
+	virtual void				_Set_Objects(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_List_TIN_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,182 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  DLG_Parameters.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+
+#include "wksp_base_item.h"
+
+#include "active.h"
+#include "active_parameters.h"
+
+#include "parameters_control.h"
+
+#include "dlg_parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_Parameters, CDLG_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_Parameters, CDLG_Base)
+	EVT_BUTTON			(wxID_OK		, CDLG_Parameters::On_Ok)
+	EVT_BUTTON			(ID_BTN_LOAD	, CDLG_Parameters::On_Load)
+	EVT_BUTTON			(ID_BTN_SAVE	, CDLG_Parameters::On_Save)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_Parameters::CDLG_Parameters(CSG_Parameters *pParameters)
+	: CDLG_Base(-1, pParameters ? pParameters->Get_Name() : LNG("[CAP] Parameters"))
+{
+	m_pControl		= new CParameters_Control(this, true);
+
+	m_pParameters	= pParameters;
+
+	g_pACTIVE->Get_Parameters()->Update_Parameters(m_pParameters, true);
+
+	m_pControl->Set_Parameters(m_pParameters);
+
+	Add_Button(ID_BTN_LOAD);
+	Add_Button(ID_BTN_SAVE);
+
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+CDLG_Parameters::~CDLG_Parameters(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Parameters::On_Ok(wxCommandEvent &event)
+{
+	if( m_pControl->Get_Parameters()->DataObjects_Check() )
+	{
+		CDLG_Base::On_Ok(event);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Parameters::On_Load(wxCommandEvent &event)
+{
+	m_pControl->Load();
+}
+
+//---------------------------------------------------------
+void CDLG_Parameters::On_Save(wxCommandEvent &event)
+{
+	m_pControl->Save();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Parameters::Save_Changes(void)
+{
+	m_pControl->Save_Changes(true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Parameters::Set_Position(wxRect r)
+{
+	m_pControl->SetSize(r);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_parameters.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,119 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   DLG_Parameters.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Parameters_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_Parameters_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_Parameters : public CDLG_Base
+{
+	DECLARE_CLASS(CDLG_Parameters)
+
+public:
+	CDLG_Parameters(class CSG_Parameters *pParameters);
+	virtual ~CDLG_Parameters(void);
+
+	void						On_Ok			(wxCommandEvent &event);
+	void						On_Load			(wxCommandEvent &event);
+	void						On_Save			(wxCommandEvent &event);
+
+
+protected:
+
+	class CSG_Parameters			*m_pParameters;
+
+	class CParameters_Control	*m_pControl;
+
+
+	virtual void				Save_Changes	(void);
+
+	virtual void				Set_Position	(wxRect r);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Parameters_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,213 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_Table.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "dlg_table.h"
+#include "view_table_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_Table, CDLG_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_Table, CDLG_Base)
+	EVT_BUTTON			(ID_BTN_LOAD			, CDLG_Table::On_Load)
+	EVT_BUTTON			(ID_BTN_SAVE			, CDLG_Table::On_Save)
+	EVT_BUTTON			(ID_BTN_ADD				, CDLG_Table::On_Add)
+	EVT_BUTTON			(ID_BTN_INSERT			, CDLG_Table::On_Insert)
+	EVT_BUTTON			(ID_BTN_DELETE			, CDLG_Table::On_Delete)
+	EVT_BUTTON			(ID_BTN_DELETE_ALL		, CDLG_Table::On_Delete_All)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_Table::CDLG_Table(CSG_Table *pTable, wxString Caption)
+	: CDLG_Base(-1, Caption)
+{
+	m_pTable_Orig	= pTable;
+	m_pTable		= new CSG_Table(*m_pTable_Orig);
+	m_pControl		= new CVIEW_Table_Control(this, m_pTable, TABLE_CTRL_FIXED_COLS);
+
+	Add_Button(ID_BTN_LOAD);
+	Add_Button(ID_BTN_SAVE);
+	Add_Button(-1);
+	Add_Button(ID_BTN_ADD);
+	Add_Button(ID_BTN_INSERT);
+	Add_Button(ID_BTN_DELETE);
+	Add_Button(ID_BTN_DELETE_ALL);
+
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+CDLG_Table::~CDLG_Table(void)
+{
+	delete(m_pTable);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Table::Set_Position(wxRect r)
+{
+	m_pControl->SetSize(r);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Table::Save_Changes(void)
+{
+	m_pTable_Orig->Assign(m_pTable);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Table::On_Load(wxCommandEvent &event)
+{
+	wxString	File_Path;
+
+	if( DLG_Open(File_Path, ID_DLG_TABLES_OPEN) )
+	{
+		m_pControl->Load(File_Path);
+
+		Refresh();
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Table::On_Save(wxCommandEvent &event)
+{
+	wxString	File_Path;
+
+	if( DLG_Save(File_Path, ID_DLG_TABLES_SAVE) )
+	{
+		m_pControl->Save(File_Path);
+
+		Refresh();
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Table::On_Add(wxCommandEvent &event)
+{
+	m_pControl->Add_Record();
+}
+
+//---------------------------------------------------------
+void CDLG_Table::On_Insert(wxCommandEvent &event)
+{
+	m_pControl->Ins_Record();
+}
+
+//---------------------------------------------------------
+void CDLG_Table::On_Delete(wxCommandEvent &event)
+{
+	m_pControl->Del_Record();
+}
+
+//---------------------------------------------------------
+void CDLG_Table::On_Delete_All(wxCommandEvent &event)
+{
+	m_pControl->Del_Records();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,123 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     DLG_Table.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Table_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_Table_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_Table : public CDLG_Base
+{
+	DECLARE_CLASS(CDLG_Table)
+
+public:
+	CDLG_Table(class CSG_Table *pTable, wxString Caption);
+	virtual ~CDLG_Table(void);
+
+	void						On_Load			(wxCommandEvent &event);
+	void						On_Save			(wxCommandEvent &event);
+
+	void						On_Add			(wxCommandEvent &event);
+	void						On_Insert		(wxCommandEvent &event);
+	void						On_Delete		(wxCommandEvent &event);
+	void						On_Delete_All	(wxCommandEvent &event);
+
+
+protected:
+
+	class CSG_Table				*m_pTable, *m_pTable_Orig;
+
+	class CVIEW_Table_Control	*m_pControl;
+
+
+	virtual void				Set_Position	(wxRect r);
+
+	virtual void				Save_Changes	(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Table_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,178 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    DLG_Text.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+#include <wx/textctrl.h>
+
+#include "res_controls.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "dlg_text.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CDLG_Text, CDLG_Base)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CDLG_Text, CDLG_Base)
+	EVT_BUTTON			(ID_BTN_LOAD	, CDLG_Text::On_Load)
+	EVT_BUTTON			(ID_BTN_SAVE	, CDLG_Text::On_Save)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CDLG_Text::CDLG_Text(wxString *_pText, wxString Caption)
+	: CDLG_Base(-1, Caption)
+{
+	m_pText		= _pText;
+
+	m_pControl	= new wxTextCtrl(this, -1, *m_pText, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxSUNKEN_BORDER);
+
+	Add_Button(ID_BTN_LOAD);
+	Add_Button(ID_BTN_SAVE);
+
+	Set_Positions();
+}
+
+//---------------------------------------------------------
+CDLG_Text::~CDLG_Text(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Text::Save_Changes(void)
+{
+	if( m_pText )
+	{
+		*m_pText	= m_pControl->GetValue();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Text::Set_Position(wxRect r)
+{
+	m_pControl->SetSize(r);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CDLG_Text::On_Load(wxCommandEvent &event)
+{
+	wxString	File_Path;
+
+	if( DLG_Open(File_Path, ID_DLG_TEXT_OPEN) )
+	{
+		m_pControl->LoadFile(File_Path);
+	}
+}
+
+//---------------------------------------------------------
+void CDLG_Text::On_Save(wxCommandEvent &event)
+{
+	wxString	File_Path;
+
+	if( DLG_Save(File_Path, ID_DLG_TEXT_SAVE) )
+	{
+		m_pControl->SaveFile(File_Path);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/dlg_text.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,118 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     DLG_Text.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Text_H
+#define _HEADER_INCLUDED__SAGA_GUI__DLG_Text_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "dlg_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CDLG_Text : public CDLG_Base
+{
+	DECLARE_CLASS(CDLG_Text)
+
+public:
+	CDLG_Text(wxString *pText, wxString Caption);
+	virtual ~CDLG_Text(void);
+
+	void						On_Load			(wxCommandEvent &event);
+	void						On_Save			(wxCommandEvent &event);
+
+
+protected:
+
+	wxString					*m_pText;
+
+	class wxTextCtrl			*m_pControl;
+
+
+	virtual void				Save_Changes	(void);
+
+	virtual void				Set_Position	(wxRect r);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__DLG_Text_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,664 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Helper.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/config.h>
+#include <wx/cursor.h>
+#include <wx/utils.h>
+#include <wx/mimetype.h>
+#include <wx/filename.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "saga.h"
+#include "saga_frame.h"
+
+#include "info.h"
+#include "info_messages.h"
+
+#include "wksp_module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString	Get_SignificantDecimals_String(double Value, int maxDecimals)
+{
+	wxString	s;
+
+	s.Printf(wxT("%.*f"), SG_Get_Significant_Decimals(Value, maxDecimals), Value);
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double		Degree_To_Decimal(double Deg, double Min, double Sec)
+{
+	return( Deg > 0.0
+		? (Deg + Min / 60.0 + Sec / (60.0 * 60.0))
+		: (Deg - Min / 60.0 - Sec / (60.0 * 60.0))
+	);
+}
+
+//---------------------------------------------------------
+void		Decimal_To_Degree(double Value, double &Deg, double &Min, double &Sec)
+{
+	Value	= fmod(Value, 360.0);
+	Deg		= (int)Value;
+	Value	= 60.0 * (Value - Deg);
+	Min		= (int)Value;
+	Value	= 60.0 * (Value - Min);
+	Sec		= Value;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+double		Get_Random(double loValue, double hiValue)
+{
+	return( loValue + (hiValue - loValue) * (double)rand() / (double)RAND_MAX );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString	Get_FilePath_Relative(const wxChar *Directory, const wxChar *FileName)
+{
+	int		i, n;
+
+	if( Directory && FileName && (n = SG_STR_LEN(Directory)) < (int)SG_STR_LEN(FileName) )
+	{
+		for(i=0; i<n; i++)
+		{
+			if( Directory[i] != FileName[i] )
+			{
+				return( FileName );
+			}
+		}
+
+		return( FileName + n );
+	}
+
+	return( FileName );
+}
+
+//---------------------------------------------------------
+wxString	Get_FilePath_Absolute(const wxChar *Directory, const wxChar *FileName)
+{
+	if( wxIsAbsolutePath(FileName) )
+	{
+		return( FileName );
+	}
+
+	return( wxString::Format(wxT("%s%s"), Directory, FileName) );
+//	return( SG_File_Make_Path(Directory, FileName, NULL).c_str() );
+}
+
+//---------------------------------------------------------
+wxString		Get_TableInfo_asHTML(CSG_Table *pTable)
+{
+	wxString	s;
+
+	if( pTable && pTable->is_Valid() )
+	{
+		s.Append(wxString::Format(wxT("<table border=\"1\"><tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th>"),
+			LNG("[CAP] Field"),
+			LNG("[CAP] Name"),
+			LNG("[CAP] Type"),
+			LNG("[CAP] Minimum"),
+			LNG("[CAP] Maximum"),
+			LNG("[CAP] Mean"),
+			LNG("[CAP] Standard Deviation")
+		));
+
+		for(int i=0; i<pTable->Get_Field_Count(); i++)
+		{
+			s.Append(wxString::Format(wxT("<tr><td>%d</td><td>%s</td><td>%s</td><td>%f</td><td>%f</td><td>%f</td><td>%f</td></tr>"),
+				i + 1,
+				pTable->Get_Field_Name(i),
+				SG_Data_Type_Get_Name(pTable->Get_Field_Type(i)),
+				pTable->Get_Minimum(i),
+				pTable->Get_Maximum(i),
+				pTable->Get_Mean(i),
+				pTable->Get_StdDev(i)
+			));
+		}
+
+		s.Append(wxT("</table>"));
+	}
+
+	return( s );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxColour	Get_Color_asWX(int Color)
+{
+	return( wxColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color)) );
+}
+
+//---------------------------------------------------------
+int			Get_Color_asInt(wxColour Color)
+{
+	return( SG_GET_RGB(Color.Red(), Color.Green(), Color.Blue()) );
+}
+
+//---------------------------------------------------------
+wxColour	Get_Color_Random(int rLo, int rHi, int gLo, int gHi, int bLo, int bHi)
+{
+	return( wxColour(
+		(int)(0.5 + Get_Random(rLo, rHi)),
+		(int)(0.5 + Get_Random(gLo, gHi)),
+		(int)(0.5 + Get_Random(bLo, bHi))
+	));
+}
+
+//---------------------------------------------------------
+wxColour	SYS_Get_Color(wxSystemColour index)
+{
+	return( wxSystemSettings::GetColour(index) );
+}
+
+//---------------------------------------------------------
+void		SYS_Set_Color_BG(wxWindow *pWindow, wxSystemColour index)
+{
+	if( pWindow )
+	{
+		pWindow->SetBackgroundColour(SYS_Get_Color(index));
+	}
+}
+
+//---------------------------------------------------------
+void		SYS_Set_Color_BG_Window(wxWindow *pWindow)
+{
+	if( pWindow )
+	{
+#if defined(__WXMSW__)
+		pWindow->SetBackgroundColour(SYS_Get_Color(wxSYS_COLOUR_WINDOW));
+#else
+		pWindow->SetBackgroundColour(*wxWHITE);
+#endif
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxWindow *	MDI_Get_Frame(void)
+{
+	return( g_pSAGA_Frame );
+}
+
+//---------------------------------------------------------
+wxPoint		MDI_Get_Def_Position(void)
+{
+	static int	n	= 0;
+
+	int		Height	= wxSystemSettings::GetMetric(wxSYS_CAPTION_Y);
+
+	wxPoint	p(n * Height, n * Height);
+
+	n	= n < 10 ? n + 1 : 0;
+
+	return( p );
+}
+
+//---------------------------------------------------------
+wxSize		MDI_Get_Def_Size(void)
+{
+	return( wxSize(400, 300) );
+}
+
+//---------------------------------------------------------
+void		MDI_Top_Window_Push(wxWindow *pWindow)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->Top_Window_Push(pWindow);
+	}
+}
+
+//---------------------------------------------------------
+void		MDI_Top_Window_Pop(wxWindow *pWindow)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->Top_Window_Pop(pWindow);
+	}
+}
+
+//---------------------------------------------------------
+wxWindow *	MDI_Get_Top_Window(void)
+{
+	return( g_pSAGA_Frame ? g_pSAGA_Frame->Top_Window_Get() : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Set_Buisy_Cursor(bool bOn)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->SetCursor(bOn ? *wxHOURGLASS_CURSOR : *wxSTANDARD_CURSOR);
+	}
+}
+
+//---------------------------------------------------------
+void		Do_Beep(int Style)
+{
+	switch( Style )
+	{
+	case -1:	// no noise...
+		break;
+
+	case 0:	default:
+#if defined(__WXMSW__)
+		Beep(330, 100);
+		Beep(440, 100);
+		Beep(550, 100);
+#else
+//		wxBell();
+#endif
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		MSG_General_Add_Line(void)
+{
+	if( g_pINFO )
+	{
+		g_pINFO->Get_General()->Add_Line();
+	}
+}
+
+//---------------------------------------------------------
+void		MSG_General_Add(const wxChar *Message, bool bNewLine, bool bTime, TSG_UI_MSG_STYLE Style)
+{
+	if( g_pINFO )
+	{
+		g_pINFO->Get_General()->Add_String(Message, bNewLine, bTime, Style);
+	}
+}
+
+//---------------------------------------------------------
+void		MSG_Error_Add_Line(void)
+{
+	if( g_pINFO )
+	{
+		g_pINFO->Get_Errors()->Add_Line();
+	}
+}
+
+//---------------------------------------------------------
+void		MSG_Error_Add(const wxChar *Message, bool bNewLine, bool bTime, TSG_UI_MSG_STYLE Style)
+{
+	if( g_pINFO )
+	{
+		g_pINFO->Get_Errors()->Add_String(Message, bNewLine, bTime, Style);
+	}
+}
+
+//---------------------------------------------------------
+void		MSG_Execution_Add_Line(void)
+{
+	if( g_pINFO )
+	{
+		g_pINFO->Get_Execution()->Add_Line();
+	}
+}
+
+//---------------------------------------------------------
+void		MSG_Execution_Add(const wxChar *Message, bool bNewLine, bool bTime, TSG_UI_MSG_STYLE Style)
+{
+	if( g_pINFO )
+	{
+		g_pINFO->Get_Execution()->Add_String(Message, bNewLine, bTime, Style);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		CONFIG_Read(const wxChar *Group, const wxChar *Entry, wxString &Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Read(Entry, &Value) );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Read(const wxChar *Group, const wxChar *Entry, long &Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Read(Entry, &Value) );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Read(const wxChar *Group, const wxChar *Entry, double &Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Read(Entry, &Value) );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Read(const wxChar *Group, const wxChar *Entry, bool &Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Read(Entry, &Value) );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Write(const wxChar *Group, const wxChar *Entry, const wxChar *Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Write(Entry, Value) ? pConfig->Flush() : false );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Write(const wxChar *Group, const wxChar *Entry, long Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Write(Entry, Value) ? pConfig->Flush() : false );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Write(const wxChar *Group, const wxChar *Entry, double Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Write(Entry, Value) ? pConfig->Flush() : false );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Write(const wxChar *Group, const wxChar *Entry, bool Value)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->Write(Entry, Value) ? pConfig->Flush() : false );
+}
+
+//---------------------------------------------------------
+bool		CONFIG_Delete(const wxChar *Group)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	return( pConfig->DeleteGroup(Group) ? pConfig->Flush() : false );
+}
+
+bool		CONFIG_Delete(const wxChar *Group, const wxChar *Entry)
+{
+	wxConfigBase	*pConfig	= wxConfigBase::Get();
+
+	pConfig->SetPath(wxString::Format(wxT("/%s"), Group));
+
+	return( pConfig->DeleteEntry(Entry) ? pConfig->Flush() : false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		PROCESS_is_Executing(void)
+{
+	return( g_pModule != NULL );
+}
+
+//---------------------------------------------------------
+bool		PROCESS_Wait(void)
+{
+	if( g_pSAGA )
+	{
+		return( g_pSAGA->Process_Wait() );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		PROCESS_Get_Okay(bool bBlink)
+{
+	if( g_pSAGA_Frame )
+	{
+		return( g_pSAGA_Frame->Process_Get_Okay(bBlink) );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		PROCESS_Set_Okay(bool bOkay)
+{
+	if( g_pSAGA_Frame )
+	{
+		return( g_pSAGA_Frame->Process_Set_Okay(bOkay) );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		PROGRESSBAR_Set_Position(int Position)
+{
+	if( g_pSAGA_Frame )
+	{
+		return( g_pSAGA_Frame->ProgressBar_Set_Position(Position) );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool		PROGRESSBAR_Set_Position(double Position, double Range)
+{
+	if( g_pSAGA_Frame )
+	{
+		return( g_pSAGA_Frame->ProgressBar_Set_Position(Position, Range) );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void		STATUSBAR_Set_Text(const wxChar *Text, int iPane)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->StatusBar_Set_Text(Text, iPane);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		Open_Application(const wxChar *Reference, const wxChar *Mime_Extension)
+{
+	bool		bResult		= false;
+
+	if( Reference && Reference[0] )
+	{
+		wxString	Extension;
+		wxFileType	*pFileType;
+
+		if( Mime_Extension && Mime_Extension[0] )
+		{
+			Extension	= Mime_Extension;
+		}
+		else
+		{
+			wxFileName	FileName(Reference);
+
+			Extension	= FileName.GetExt();
+		}
+
+		if( Extension.Length() > 0 && (pFileType = wxTheMimeTypesManager->GetFileTypeFromExtension(Extension)) != NULL )
+		{
+			wxString	Command;
+
+			if( pFileType->GetOpenCommand(&Command, wxFileType::MessageParameters(Reference, wxT(""))) )
+			{
+				MSG_Execution_Add_Line();
+				MSG_Execution_Add(Command, true, true);
+
+				bResult	= wxExecute(Command) == 0;
+			}
+
+			delete(pFileType);
+		}
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool		Open_WebBrowser(const wxChar *Reference)
+{
+	return( Open_Application(Reference, wxT("html")) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/helper.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,191 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       Helper.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__Helper_H
+#define _HEADER_INCLUDED__SAGA_GUI__Helper_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/gdicmn.h>
+#include <wx/string.h>
+#include <wx/colour.h>
+#include <wx/settings.h>
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class wxString		Get_SignificantDecimals_String	(double Value, int maxDecimals = 6);
+
+//---------------------------------------------------------
+double				Degree_To_Decimal				(double Deg, double Min, double Sec);
+void				Decimal_To_Degree				(double Value, double &Deg, double &Min, double &Sec);
+
+//---------------------------------------------------------
+double				Get_Random						(double loValue, double hiValue);
+
+//---------------------------------------------------------
+wxString			Get_FilePath_Relative			(const wxChar *Directory, const wxChar *FileName);
+wxString			Get_FilePath_Absolute			(const wxChar *Directory, const wxChar *FileName);
+
+//---------------------------------------------------------
+wxString			Get_TableInfo_asHTML			(class CSG_Table *pTable);
+
+//---------------------------------------------------------
+wxColour			Get_Color_asWX					(int Color);
+int					Get_Color_asInt					(wxColour Color);
+
+wxColour			Get_Color_Random				(int rLo = 0, int rHi = 255, int gLo = 0, int gHi = 255, int bLo = 0, int bHi = 255);
+
+wxColour			SYS_Get_Color					(wxSystemColour index);
+void				SYS_Set_Color_BG				(class wxWindow *pWindow, wxSystemColour index);
+void				SYS_Set_Color_BG_Window			(wxWindow *pWindow);
+
+//---------------------------------------------------------
+class wxWindow *	MDI_Get_Frame					(void);
+
+wxPoint				MDI_Get_Def_Position			(void);
+wxSize				MDI_Get_Def_Size				(void);
+
+void				MDI_Top_Window_Push				(wxWindow *pWindow);
+void				MDI_Top_Window_Pop				(wxWindow *pWindow);
+wxWindow *			MDI_Get_Top_Window				(void);
+
+//---------------------------------------------------------
+void				Set_Buisy_Cursor				(bool bOn);
+
+void				Do_Beep							(int Style = 0);
+
+//---------------------------------------------------------
+void				MSG_General_Add_Line			(void);
+void				MSG_General_Add					(const wxChar *Message, bool bNewLine = true, bool bTime = false, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
+
+void				MSG_Error_Add_Line				(void);
+void				MSG_Error_Add					(const wxChar *Message, bool bNewLine = true, bool bTime = true , TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
+
+void				MSG_Execution_Add_Line			(void);
+void				MSG_Execution_Add				(const wxChar *Message, bool bNewLine = true, bool bTime = false, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
+
+//---------------------------------------------------------
+bool				CONFIG_Read						(const wxChar *Group, const wxChar *Entry, class wxString &Value);
+bool				CONFIG_Read						(const wxChar *Group, const wxChar *Entry, long           &Value);
+bool				CONFIG_Read						(const wxChar *Group, const wxChar *Entry, double         &Value);
+bool				CONFIG_Read						(const wxChar *Group, const wxChar *Entry, bool           &Value);
+
+bool				CONFIG_Write					(const wxChar *Group, const wxChar *Entry, const wxChar   *Value);
+bool				CONFIG_Write					(const wxChar *Group, const wxChar *Entry, long            Value);
+bool				CONFIG_Write					(const wxChar *Group, const wxChar *Entry, double          Value);
+bool				CONFIG_Write					(const wxChar *Group, const wxChar *Entry, bool            Value);
+
+bool				CONFIG_Delete					(const wxChar *Group);
+bool				CONFIG_Delete					(const wxChar *Group, const wxChar *Entry);
+
+//---------------------------------------------------------
+bool				PROCESS_is_Executing			(void);
+
+bool				PROCESS_Wait					(void);
+
+bool				PROCESS_Get_Okay				(bool bBlink);
+bool				PROCESS_Set_Okay				(bool bOkay = true);
+
+bool				PROGRESSBAR_Set_Position		(int Position);
+bool				PROGRESSBAR_Set_Position		(double Position, double Range);
+
+//---------------------------------------------------------
+bool				Open_Application				(const wxChar *Reference, const wxChar *Mime_Extension = NULL);
+bool				Open_WebBrowser					(const wxChar *Reference);
+
+//---------------------------------------------------------
+enum
+{
+	STATUSBAR_DEFAULT	= 0,
+	STATUSBAR_ACTIVE,
+	STATUSBAR_VIEW_X,
+	STATUSBAR_VIEW_Y,
+	STATUSBAR_VIEW_Z,
+	STATUSBAR_PROGRESS,
+	STATUSBAR_COUNT
+};
+
+//---------------------------------------------------------
+void				STATUSBAR_Set_Text				(const wxChar *Text, int iPane = 0);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__Helper_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,156 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       INFO.cpp                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/treectrl.h>
+#include <wx/imaglist.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "info.h"
+#include "info_messages.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_MESSAGES	= 0,
+	IMG_EXECUTION,
+	IMG_ERROR
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CINFO	*g_pINFO	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CINFO, wxNotebook)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CINFO::CINFO(wxWindow *pParent)
+	: wxNotebook(pParent, ID_WND_INFO, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE, LNG("[CAP] Messages"))
+{
+	g_pINFO		= this;
+
+	//-----------------------------------------------------
+	AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));
+
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_INFO_MESSAGES);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_INFO_EXECUTION);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_INFO_ERROR);
+	
+	//-----------------------------------------------------
+	m_pGeneral		= new CINFO_Messages(this);
+	m_pExecution	= new CINFO_Messages(this);
+	m_pErrors		= new CINFO_Messages(this);
+}
+
+//---------------------------------------------------------
+void CINFO::Add_Pages(void)
+{
+	AddPage(m_pGeneral	, LNG("[CAP] General")	, false, IMG_MESSAGES);
+	AddPage(m_pExecution, LNG("[CAP] Execution"), false, IMG_EXECUTION);
+	AddPage(m_pErrors	, LNG("[CAP] Errors")	, false, IMG_ERROR);
+}
+
+//---------------------------------------------------------
+CINFO::~CINFO(void)
+{
+	g_pINFO		= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/info.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        INFO.h                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__INFO_H
+#define _HEADER_INCLUDED__SAGA_GUI__INFO_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/notebook.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CINFO : public wxNotebook
+{
+public:
+	CINFO(wxWindow *pParent);
+	virtual ~CINFO(void);
+
+	void						Add_Pages		(void);
+
+	class CINFO_Messages *		Get_General		(void)	{	return( m_pGeneral );	}
+	class CINFO_Messages *		Get_Errors		(void)	{	return( m_pErrors );	}
+	class CINFO_Messages *		Get_Execution	(void)	{	return( m_pExecution );	}
+
+
+private:
+
+	class CINFO_Messages		*m_pGeneral, *m_pErrors, *m_pExecution;
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CINFO					*g_pINFO;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__INFO_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,322 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  INFO_Messages.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/datetime.h>
+
+#include "helper.h"
+
+#include "res_controls.h"
+#include "res_commands.h"
+
+#include "info_messages.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CINFO_Messages, wxTextCtrl)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CINFO_Messages, wxTextCtrl)
+    EVT_CONTEXT_MENU(CINFO_Messages::On_Context_Menu)
+
+	EVT_MENU		(ID_CMD_INFO_COPY	, CINFO_Messages::On_Copy)
+	EVT_MENU		(ID_CMD_INFO_CLEAR	, CINFO_Messages::On_Clear)
+
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CINFO_Messages::CINFO_Messages(wxWindow *pParent)
+	: wxTextCtrl(pParent, ID_WND_INFO_MESSAGES, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_RICH2|wxTE_NOHIDESEL|wxTE_MULTILINE|wxTE_READONLY|wxSUNKEN_BORDER)
+{
+	m_MaxLength	= 0x10000;
+
+	SetMaxLength(m_MaxLength);
+}
+
+//---------------------------------------------------------
+CINFO_Messages::~CINFO_Messages(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CINFO_Messages::On_Context_Menu(wxContextMenuEvent &event)
+{
+	wxMenu	Menu;
+
+	Menu.Append(ID_CMD_INFO_COPY		, LNG("Copy"));
+	Menu.Append(ID_CMD_INFO_CLEAR		, LNG("Clear"));
+
+	PopupMenu(&Menu);
+}
+
+//---------------------------------------------------------
+void CINFO_Messages::On_Copy(wxCommandEvent &WXUNUSED(event))
+{
+	if( GetStringSelection().IsEmpty() )
+	{
+		SetSelection(-1, -1);
+		Copy();
+		SetSelection(GetLastPosition(), GetLastPosition());
+	}
+	else
+	{
+		Copy();
+	}
+}
+
+//---------------------------------------------------------
+void CINFO_Messages::On_Clear(wxCommandEvent &WXUNUSED(event))
+{
+	Clear();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CINFO_Messages::_Add_Text(wxString Text)
+{
+	int		i, n;
+
+	if( m_MaxLength <= (int)(GetLastPosition() + Text.Length()) )
+	{
+		for(i=0, n=0; i<GetNumberOfLines() && n<(int)Text.Length(); i++)
+		{
+			n	+= 1 + GetLineLength(i);
+		}
+
+		Remove(0, n + 1);
+	}
+
+	AppendText(Text);
+}
+
+//---------------------------------------------------------
+void CINFO_Messages::_Set_Style(TSG_UI_MSG_STYLE Style)
+{
+	int			i	= 0;
+	wxColour	c	= wxColour(  0,   0,   0);
+	wxFont		f	= wxFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+	wxTextAttr	t;
+
+	switch( Style )
+	{
+	default:
+	case SG_UI_MSG_STYLE_NORMAL:
+		break;
+
+	case SG_UI_MSG_STYLE_BOLD:
+		f.SetWeight(wxFONTWEIGHT_BOLD);
+		break;
+
+	case SG_UI_MSG_STYLE_ITALIC:
+		f.SetStyle(wxFONTSTYLE_ITALIC);
+		break;
+
+	case SG_UI_MSG_STYLE_SUCCESS:
+		c	= wxColour(  0, 127,   0);
+		break;
+
+	case SG_UI_MSG_STYLE_FAILURE:
+		c	= wxColour(127,   0,   0);
+		break;
+
+	case SG_UI_MSG_STYLE_BIG:
+		f.SetWeight(wxFONTWEIGHT_BOLD);
+		f.SetPointSize(10);
+		break;
+
+	case SG_UI_MSG_STYLE_SMALL:
+		f.SetWeight(wxFONTWEIGHT_LIGHT);
+		f.SetPointSize(6);
+		break;
+
+	case SG_UI_MSG_STYLE_01:
+		i	= 50;
+		c	= wxColour(  0,   0, 127);
+		f.SetWeight(wxFONTWEIGHT_LIGHT);
+		f.SetPointSize(8);
+		break;
+
+	case SG_UI_MSG_STYLE_02:
+		break;
+
+	case SG_UI_MSG_STYLE_03:
+		c	= wxColour(  0,   0, 127);
+		f.SetWeight(wxFONTWEIGHT_BOLD);
+		break;
+	}
+
+	t.SetFlags(wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_FONT_WEIGHT|wxTEXT_ATTR_FONT_ITALIC|wxTEXT_ATTR_FONT_SIZE|wxTEXT_ATTR_LEFT_INDENT);
+
+	t.SetLeftIndent(i);
+	t.SetTextColour(c);
+	t.SetFont(f);
+
+	SetDefaultStyle(t);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CINFO_Messages::Add_Time(bool bNewLine)
+{
+	wxDateTime	Time;
+
+	if( bNewLine )
+	{
+		_Add_Text(wxT("\n"));
+	}
+
+	Time.SetToCurrent();
+
+	_Set_Style(SG_UI_MSG_STYLE_03);
+
+	_Add_Text(wxString::Format(wxT("[%s/%s]"),
+		Time.FormatISODate().c_str(),
+		Time.FormatISOTime().c_str())
+	);
+}
+
+//---------------------------------------------------------
+void CINFO_Messages::Add_Line(void)
+{
+	CSG_Colors	c;
+
+	SetDefaultStyle(wxTextAttr(wxNullColour, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)));
+
+	_Add_Text(wxT("\n\n"));
+
+	c.Set_Ramp(
+		Get_Color_asInt(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION)),
+		Get_Color_asInt(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW))
+	);
+
+	c.Set_Count(100);
+
+	for(int i=0; i<c.Get_Count(); i++)
+	{
+		SetDefaultStyle(wxTextAttr(
+			Get_Color_asWX(c.Get_Color(c.Get_Count() - 1 - i)),
+			Get_Color_asWX(c.Get_Color(i))
+		));
+
+		_Add_Text(wxT("  "));
+	}
+
+	SetDefaultStyle(wxTextAttr(wxNullColour, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)));
+}
+
+//---------------------------------------------------------
+void CINFO_Messages::Add_String(wxString sMessage, bool bNewLine, bool bTime, TSG_UI_MSG_STYLE Style)
+{
+	if( bNewLine )
+	{
+		_Add_Text(wxT("\n"));
+	}
+
+	if( bTime )
+	{
+		Add_Time(false);
+
+		_Add_Text(wxT(" "));
+	}
+
+	_Set_Style(Style);
+
+	_Add_Text(sMessage);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/info_messages.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   INFO_Messages.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__INFO_Messages_H
+#define _HEADER_INCLUDED__SAGA_GUI__INFO_Messages_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/textctrl.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CINFO_Messages : public wxTextCtrl
+{
+	DECLARE_CLASS(CINFO_Messages)
+
+public:
+	CINFO_Messages(wxWindow *pParent);
+	virtual ~CINFO_Messages(void);
+
+	void						Add_Time		(bool bNewLine = true);
+	void						Add_Line		(void);
+	void						Add_String		(wxString sMessage, bool bNewLine = true, bool bTime = false, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
+
+
+private:
+
+	int							m_MaxLength;
+
+
+	void						On_Context_Menu	(wxContextMenuEvent &event);
+
+	void						On_Copy			(wxCommandEvent &event);
+	void						On_Clear		(wxCommandEvent &event);
+
+	void						_Add_Text		(wxString Text);
+
+	void						_Set_Style		(TSG_UI_MSG_STYLE Style);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__INFO_Messages_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,818 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Parameters_Control.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_dialogs.h"
+#include "res_controls.h"
+
+#include "helper.h"
+
+#include "wksp_data_manager.h"
+
+#include "parameters_control.h"
+#include "parameters_properties.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _SAGA_LINUX
+	#define	PG_USE_MANAGER
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CParameters_Control, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CParameters_Control, wxPanel)
+	EVT_SIZE			(CParameters_Control::On_Size)
+
+	EVT_PG_SELECTED		(ID_WND_PARM_PG_ACTIVE, CParameters_Control::On_PG_Selected)
+	EVT_PG_SELECTED		(ID_WND_PARM_PG_DIALOG, CParameters_Control::On_PG_Selected)
+	EVT_PG_CHANGED		(ID_WND_PARM_PG_ACTIVE, CParameters_Control::On_PG_Changed)
+	EVT_PG_CHANGED		(ID_WND_PARM_PG_DIALOG, CParameters_Control::On_PG_Changed)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CParameters_Control::CParameters_Control(wxWindow *pParent, bool bDialog)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxCLIP_CHILDREN)
+{
+	m_pParameters	= new CSG_Parameters();
+	m_pOriginal		= NULL;
+
+#ifdef PG_USE_MANAGER
+	m_pPGM	= new wxPropertyGridManager(this, bDialog ? ID_WND_PARM_PG_DIALOG : ID_WND_PARM_PG_ACTIVE, wxDefaultPosition, wxDefaultSize,
+		 wxPG_BOLD_MODIFIED
+		|wxPG_SPLITTER_AUTO_CENTER
+	//	|wxPG_AUTO_SORT
+	//	|wxPG_HIDE_MARGIN
+	//	|wxPG_STATIC_SPLITTER
+	//	|wxPG_HIDE_CATEGORIES
+	//	|wxPG_LIMITED_EDITING
+		|wxTAB_TRAVERSAL
+	//	|wxPG_TOOLBAR
+		|wxPG_DESCRIPTION
+	//	|wxPG_COMPACTOR
+	//	|wxBORDER_SUNKEN
+		|wxBORDER_NONE
+	);
+
+	m_pPG	= m_pPGM->GetGrid();
+
+	m_pPGM->SetDescBoxHeight(bDialog ? 100 : 50);
+#else
+	m_pPG	= new wxPropertyGrid(this, bDialog ? ID_WND_PARM_PG_DIALOG : ID_WND_PARM_PG_ACTIVE, wxDefaultPosition, wxDefaultSize,
+		 wxPG_BOLD_MODIFIED
+		|wxPG_SPLITTER_AUTO_CENTER
+	//	|wxPG_AUTO_SORT
+	//	|wxPG_HIDE_MARGIN
+	//	|wxPG_STATIC_SPLITTER
+	//	|wxPG_HIDE_CATEGORIES
+	//	|wxPG_LIMITED_EDITING
+		|wxTAB_TRAVERSAL
+	//	|wxPG_TOOLBAR
+		|wxPG_DESCRIPTION
+	//	|wxPG_COMPACTOR
+	//	|wxBORDER_SUNKEN
+		|wxBORDER_NONE
+	);
+
+	m_pPGM	= NULL;
+
+#endif
+
+//	m_pPG->SetExtraStyle(wxPG_EX_HELP_AS_TOOLTIPS);
+//	m_pPG->SetCellDisabledTextColour(wxColour(200, 200, 200));
+
+	Set_Parameters(NULL);
+}
+
+//---------------------------------------------------------
+CParameters_Control::~CParameters_Control(void)
+{
+	delete(m_pParameters);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CParameters_Control::On_Size(wxSizeEvent &event)
+{
+	if( m_pPGM )
+	{
+		m_pPGM->SetSize(GetClientSize());
+	}
+	else
+	{
+		m_pPG ->SetSize(GetClientSize());
+	}
+
+	m_pPG->CenterSplitter(true);
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CParameters_Control::On_PG_Selected(wxPropertyGridEvent &WXUNUSED(event))
+{}
+
+//---------------------------------------------------------
+void CParameters_Control::On_PG_Changed(wxPropertyGridEvent &event)
+{
+	_Set_Parameter(event.GetPropertyName());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CParameters_Control::Save_Changes(bool bSilent)
+{
+	if( m_pOriginal && m_bModified && (bSilent || DLG_Message_Confirm(LNG("[DLG] Save changes?"), wxString::Format(wxT("%s: %s"), LNG("[CAP] Parameters"), m_pParameters->Get_Name()))) )
+	{
+		m_pOriginal->Assign_Values(m_pParameters);
+
+		m_bModified	= false;
+
+		m_pPG->ClearModifiedStatus();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CParameters_Control::Restore(void)
+{
+	if( m_pOriginal && m_bModified )
+	{
+		Set_Parameters(m_pOriginal);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CParameters_Control::Load(void)
+{
+	wxString	File_Path;
+
+	if( DLG_Open(File_Path, ID_DLG_PARAMETERS_OPEN) )
+	{
+		if( m_pParameters->Serialize(File_Path.c_str(), false) )
+		{
+		//	m_pPG->Freeze();
+			m_pPG->Clear();
+
+			_Add_Properties(m_pParameters);
+
+		//	m_pPG->Thaw();
+			m_pPG->Refresh();
+
+			m_bModified	= true;
+		
+			return( true );
+		}
+
+		DLG_Message_Show(LNG("Parameters file could not be imported."), LNG("Load Parameters"));
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CParameters_Control::Save(void)
+{
+	wxString	File_Path;
+
+	if( DLG_Save(File_Path, ID_DLG_PARAMETERS_SAVE) )
+	{
+		if( m_pParameters->Serialize(File_Path.c_str(), true) )
+		{
+			return( true );
+		}
+
+		DLG_Message_Show(LNG("Parameters file could not be exported."), LNG("Save Parameters"));
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CParameters_Control::Set_Parameters(CSG_Parameters *pParameters)
+{
+	if( m_pParameters == pParameters )
+	{
+		_Update_Parameters();
+
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	m_bModified	= false;
+	m_pPG->ClearModifiedStatus();
+
+//	m_pPG->Freeze();
+
+	if( m_pOriginal == pParameters )
+	{
+		m_pParameters->Assign_Values(m_pOriginal);
+
+		_Update_Parameters();
+	}
+	else
+	{
+		m_pPG->Clear();
+
+		if( (m_pOriginal = pParameters) != NULL )
+		{
+			m_pParameters->Assign(m_pOriginal);
+			m_pParameters->Set_Callback(true);
+
+			_Add_Properties(m_pParameters);
+		}
+		else
+		{
+			m_pPG->Append(new wxPropertyCategory(LNG("[TXT] No parameters available."), wxPG_LABEL));
+		}
+	}
+
+	//-----------------------------------------------------
+//	m_pPG->Thaw();
+
+	m_pPG->Refresh();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define CHECK_LIST_OUTPUT(p)	if( p->is_Output() )	{	pRoot	= NULL;	break;	}
+
+//---------------------------------------------------------
+#define CHECK_DATA_NODE(pNode, Name, ID)	if( !pNode )\
+	{\
+		pNode	= new wxPropertyCategory(Name, ID);\
+		if( !pData )\
+			m_pPG->Append(pData = new wxPropertyCategory(LNG("[PRM] Data Objects"), wxT("_DATAOBJECT_DATAOBJECTS")));\
+		m_pPG->Insert(pData, -1, pNode);\
+	}\
+	pRoot	= pNode;
+
+//---------------------------------------------------------
+void CParameters_Control::_Add_Properties(CSG_Parameters *pParameters)
+{
+	wxPGProperty	*pGrids, *pShapes, *pTables, *pTINs, *pPointClouds, *pOptions, *pData, *pRoot;
+
+	pData			= NULL;
+	pGrids			= NULL;
+	pShapes			= NULL;
+	pTables			= NULL;
+	pTINs			= NULL;
+	pPointClouds	= NULL;
+	pOptions		= NULL;
+
+	for(int i=0; i<pParameters->Get_Count(); i++)
+	{
+		if(	pParameters->Get_Parameter(i)->Get_Parent() == NULL )
+		{
+			switch( pParameters->Get_Parameter(i)->Get_Type() )
+			{
+			case PARAMETER_TYPE_DataObject_Output:
+				pRoot	= NULL;
+				break;
+
+			case PARAMETER_TYPE_Grid_System:
+				if(1|| pParameters->Get_Parameter(i)->Get_Children_Count() > 0 )
+				{
+					CHECK_DATA_NODE( pGrids	, LNG("[PRM] Grids"), wxT("_DATAOBJECT_GRIDS") );
+				}
+				else
+				{
+					pRoot	= NULL;
+				}
+				break;
+
+			case PARAMETER_TYPE_Grid_List:
+				CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
+			case PARAMETER_TYPE_Grid:
+				CHECK_DATA_NODE(pGrids		, LNG("[PRM] Grids") , wxT("_DATAOBJECT_GRIDS"));
+				break;
+
+			case PARAMETER_TYPE_Table_List:
+				CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
+			case PARAMETER_TYPE_Table:
+				CHECK_DATA_NODE(pTables		, LNG("[PRM] Tables"), wxT("_DATAOBJECT_TABLES"));
+				break;
+
+			case PARAMETER_TYPE_Shapes_List:
+				CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
+			case PARAMETER_TYPE_Shapes:
+				CHECK_DATA_NODE(pShapes		, LNG("[PRM] Shapes"), wxT("_DATAOBJECT_SHAPES"));
+				break;
+
+			case PARAMETER_TYPE_TIN_List:
+				CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
+			case PARAMETER_TYPE_TIN:
+				CHECK_DATA_NODE(pTINs		, LNG("[PRM] TIN"), wxT("_DATAOBJECT_TINS"));
+				break;
+
+			case PARAMETER_TYPE_PointCloud_List:
+				CHECK_LIST_OUTPUT(pParameters->Get_Parameter(i));
+			case PARAMETER_TYPE_PointCloud:
+				CHECK_DATA_NODE(pPointClouds, LNG("[PRM] Point Clouds"), wxT("_DATAOBJECT_POINTCLOUDS"));
+				break;
+
+			default:
+				if( !pOptions )
+				{
+					m_pPG->Append(pOptions = new wxPropertyCategory(LNG("[PRM] Options"), wxT("_DATAOBJECT_OPTIONS")));
+				}
+
+				pRoot	= pOptions;
+				break;
+			}
+
+			if( pRoot )
+			{
+				_Add_Property(pRoot, pParameters->Get_Parameter(i));
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_Control::_Add_Property(wxPGProperty *pParent, CSG_Parameter *pParameter)
+{
+	wxPGProperty	*pProperty	= _Get_Property(pParent, pParameter);
+
+	if( pParameter->Get_Children_Count() > 0 )
+	{
+		int		i;
+
+		for(i=0; i<pParameter->Get_Children_Count(); i++)
+		{
+			if( pParameter->Get_Child(i)->Get_Children_Count() == 0 )
+			{
+				_Add_Property(pProperty, pParameter->Get_Child(i));
+			}
+		}
+
+		for(i=0; i<pParameter->Get_Children_Count(); i++)
+		{
+			if( pParameter->Get_Child(i)->Get_Children_Count() > 0 )
+			{
+				_Add_Property(pProperty, pParameter->Get_Child(i));
+			}
+		}
+
+		m_pPG->Expand(pProperty);
+	}
+}
+
+//---------------------------------------------------------
+wxPGProperty * CParameters_Control::_Get_Property(wxPGProperty *pParent, CSG_Parameter *pParameter)
+{
+	wxString		Name(pParameter->Get_Name()), ID(pParameter->Get_Identifier());
+	wxPGProperty	*pProperty	= NULL;
+
+	switch( pParameter->Get_Type() )
+	{
+	case PARAMETER_TYPE_Node:	default:
+		if( pParameter->Get_Parent() == NULL || pParameter->Get_Parent()->Get_Type() == PARAMETER_TYPE_Node )
+			pProperty	= new wxPropertyCategory	(Name, ID);
+		else
+			pProperty	= new wxStringProperty		(Name, ID, wxT(""));
+		break;
+
+	case PARAMETER_TYPE_Bool:
+		pProperty	= new wxBoolProperty		(Name, ID, pParameter->asBool());
+		break;
+
+	case PARAMETER_TYPE_Int:
+		pProperty	= new wxIntProperty			(Name, ID, pParameter->asInt());
+		break;
+
+	case PARAMETER_TYPE_Double:
+		pProperty	= new wxFloatProperty		(Name, ID, pParameter->asDouble());
+		break;
+
+	case PARAMETER_TYPE_Range:
+		pProperty	= new CParameters_PG_Range	(Name, ID, pParameter);
+		break;
+
+	case PARAMETER_TYPE_Degree:
+		pProperty	= new CParameters_PG_Degree	(Name, ID, pParameter);
+		break;
+
+	case PARAMETER_TYPE_String:
+		pProperty	= new wxStringProperty		(Name, ID, pParameter->asString());
+		break;
+
+	case PARAMETER_TYPE_Color:
+		pProperty	= new wxColourProperty		(Name, ID, Get_Color_asWX(pParameter->asColor()));
+		break;
+
+	case PARAMETER_TYPE_Colors:
+		pProperty	= new CParameters_PG_Colors	(Name, ID, pParameter);
+		break;
+
+	case PARAMETER_TYPE_Text:
+	case PARAMETER_TYPE_FilePath:
+	case PARAMETER_TYPE_Font:
+	case PARAMETER_TYPE_FixedTable:
+	case PARAMETER_TYPE_Grid_List:
+	case PARAMETER_TYPE_Table_List:
+	case PARAMETER_TYPE_Shapes_List:
+	case PARAMETER_TYPE_TIN_List:
+	case PARAMETER_TYPE_PointCloud_List:
+	case PARAMETER_TYPE_Parameters:
+		pProperty	= new CParameters_PG_Dialog	(Name, ID, pParameter);
+		break;
+
+	case PARAMETER_TYPE_Choice:
+	case PARAMETER_TYPE_Table_Field:
+	case PARAMETER_TYPE_Grid_System:
+	case PARAMETER_TYPE_Grid:
+	case PARAMETER_TYPE_Table:
+	case PARAMETER_TYPE_Shapes:
+	case PARAMETER_TYPE_TIN:
+	case PARAMETER_TYPE_PointCloud:
+		pProperty	= new CParameters_PG_Choice	(pParameter);
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( pProperty )
+	{
+		if( pParent )
+		{
+			m_pPG->Insert(pParent, -1, pProperty);
+		}
+		else
+		{
+			m_pPG->Append(pProperty);
+		}
+
+		//-------------------------------------------------
+		CSG_String	s, sDesc;
+
+		sDesc	= pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE);
+
+		s		= pParameter->Get_Description(PARAMETER_DESCRIPTION_TEXT);
+		if( s.Length() > 0 )	{	sDesc.Append( wxT("\n___\n") );	sDesc.Append( s );	}
+
+		s		= pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES);
+		if( s.Length() > 0 )	{	sDesc.Append(wxT("\n___\n"));	sDesc.Append(s);	}
+
+		m_pPG->SetPropertyHelpString(pProperty, sDesc.c_str());
+
+		//-------------------------------------------------
+		switch( pParameter->Get_Type() )
+		{
+		case PARAMETER_TYPE_Node:	default:
+			if( pParameter->Get_Parent() && pParameter->Get_Parent()->Get_Type() != PARAMETER_TYPE_Node )
+			{
+				m_pPG->LimitPropertyEditing(pProperty);
+			//	m_pPG->SetPropertyCell(pProperty, 0, Name   , wxNullBitmap, SYS_Get_Color(wxSYS_COLOUR_BTNTEXT), SYS_Get_Color(wxSYS_COLOUR_BTNFACE));
+			//	m_pPG->SetPropertyCell(pProperty, 1, wxT(""), wxNullBitmap, SYS_Get_Color(wxSYS_COLOUR_BTNTEXT), SYS_Get_Color(wxSYS_COLOUR_BTNFACE));
+			}
+			break;
+
+		case PARAMETER_TYPE_Bool:
+			pProperty->SetAttribute(wxPG_BOOL_USE_CHECKBOX	, (long)true);
+			break;
+
+		case PARAMETER_TYPE_Double:
+			pProperty->SetAttribute(wxPG_FLOAT_PRECISION	, (long)16);
+			break;
+
+		case PARAMETER_TYPE_String:
+			if( ((CSG_Parameter_String *)pParameter->Get_Data())->is_Password() )
+			{
+				pProperty->SetAttribute(wxPG_STRING_PASSWORD, (long)pParameter->asString());
+			}
+			break;
+
+		case PARAMETER_TYPE_Color:
+			pProperty->SetEditor(wxPGEditor_Choice);
+			break;
+
+		case PARAMETER_TYPE_FilePath:
+			break;
+
+		case PARAMETER_TYPE_Colors:
+		case PARAMETER_TYPE_Text:
+		case PARAMETER_TYPE_Font:
+		case PARAMETER_TYPE_FixedTable:
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+		case PARAMETER_TYPE_Parameters:
+			m_pPG->LimitPropertyEditing(pProperty);
+			break;
+		}
+	}
+
+	return( pProperty );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CParameters_Control::_Set_Parameter(const wxString &Identifier)
+{
+	wxPGProperty	*pProperty	= m_pPG->GetProperty(Identifier);
+
+	if( pProperty )
+	{
+		CSG_Parameter	*pParameter	= m_pParameters->Get_Parameter(
+			!pProperty->IsSubProperty()
+			? Identifier
+			: Identifier.AfterLast(wxT('.'))
+		);
+
+		if( pParameter )
+		{
+			switch( pParameter->Get_Type() )
+			{
+			default:
+				break;
+
+			case PARAMETER_TYPE_String:
+			case PARAMETER_TYPE_FilePath:
+				pParameter->Set_Value(m_pPG->GetPropertyValueAsString(pProperty).c_str());
+				break;
+
+			case PARAMETER_TYPE_Bool:
+				pParameter->Set_Value(m_pPG->GetPropertyValueAsBool		(pProperty));
+				break;
+
+			case PARAMETER_TYPE_Int:
+				pParameter->Set_Value(m_pPG->GetPropertyValueAsInt		(pProperty));
+				break;
+
+			case PARAMETER_TYPE_Double:
+				pParameter->Set_Value(m_pPG->GetPropertyValueAsDouble	(pProperty));
+				break;
+
+			case PARAMETER_TYPE_Color:
+				pParameter->Set_Value(Get_Color_asInt(((wxColourProperty *)pProperty)->GetVal().m_colour));
+				break;
+			}
+
+			m_bModified	= true;
+
+			_Update_Parameters();
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_Control::_Update_Parameters(void)
+{
+	if( m_pParameters )
+	{
+		for(int i=0; i<m_pParameters->Get_Count(); i++)
+		{
+			_Update_Parameter(m_pParameters->Get_Parameter(i));
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_Control::_Update_Parameter(CSG_Parameter *pParameter)
+{
+	wxPGProperty	*pProperty	= m_pPG->GetProperty(pParameter->Get_Identifier());
+
+	if( pProperty )
+	{
+		m_pPG->EnableProperty(pProperty, pParameter->is_Enabled());
+
+		switch( pParameter->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_String:
+			if( m_pPG->GetPropertyValueAsString	(pProperty).Cmp(pParameter->asString()) != 0 )
+			{
+				m_pPG->SetPropertyValue(pProperty, pParameter->asString());
+			}
+			break;
+
+		case PARAMETER_TYPE_Bool:
+			if( m_pPG->GetPropertyValueAsBool	(pProperty) != pParameter->asBool() )
+			{
+				m_pPG->SetPropertyValue(pProperty, pParameter->asBool());
+			}
+			break;
+
+		case PARAMETER_TYPE_Int:
+			if( m_pPG->GetPropertyValueAsInt	(pProperty) != pParameter->asInt() )
+			{
+				m_pPG->SetPropertyValue(pProperty, pParameter->asInt());
+			}
+			break;
+
+		case PARAMETER_TYPE_Double:
+			if( m_pPG->GetPropertyValueAsDouble	(pProperty) != pParameter->asDouble() )
+			{
+				m_pPG->SetPropertyValue(pProperty, pParameter->asDouble());
+			}
+			break;
+
+		case PARAMETER_TYPE_Range:
+			((CParameters_PG_Range  *)pProperty)->Update();
+			break;
+
+		case PARAMETER_TYPE_Degree:
+			((CParameters_PG_Degree *)pProperty)->Update();
+			break;
+
+		case PARAMETER_TYPE_Choice:
+		case PARAMETER_TYPE_Table_Field:
+		case PARAMETER_TYPE_Grid_System:
+		case PARAMETER_TYPE_Grid:
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_TIN:
+		case PARAMETER_TYPE_PointCloud:
+			((CParameters_PG_Choice *)pProperty)->Update();
+		break;
+
+		case PARAMETER_TYPE_Text:
+		case PARAMETER_TYPE_FilePath:
+		case PARAMETER_TYPE_Font:
+		case PARAMETER_TYPE_FixedTable:
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+		case PARAMETER_TYPE_Parameters:
+			((CParameters_PG_Dialog *)pProperty)->Update();
+			break;
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CParameters_Control::Update_DataObjects(void)
+{
+	if( m_pParameters )
+	{
+		for(int i=0; i<m_pParameters->Get_Count(); i++)
+		{
+			CSG_Parameter	*pParameter	= m_pParameters->Get_Parameter(i);
+			wxPGProperty	*pProperty	= m_pPG->GetProperty(pParameter->Get_Identifier());
+
+			if( pProperty  )
+			{
+				switch( pParameter->Get_Type() )
+				{
+				default:
+					break;
+
+				case PARAMETER_TYPE_Grid_System:
+				case PARAMETER_TYPE_Grid:
+				case PARAMETER_TYPE_Table:
+				case PARAMETER_TYPE_Shapes:
+				case PARAMETER_TYPE_TIN:
+				case PARAMETER_TYPE_PointCloud:
+					((CParameters_PG_Choice *)pProperty)->Update();
+					break;
+
+				case PARAMETER_TYPE_Grid_List:
+				case PARAMETER_TYPE_Table_List:
+				case PARAMETER_TYPE_Shapes_List:
+				case PARAMETER_TYPE_TIN_List:
+				case PARAMETER_TYPE_PointCloud_List:
+					if( g_pData->Check_Parameter(pParameter) == false )
+					{
+					}
+					break;
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,146 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 Parameters_Control.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__Parameters_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__Parameters_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+#include <wx/scrolwin.h>
+#include <wx/toolbar.h>
+#include <wx/stattext.h>
+#include <wx/dcclient.h>
+#include <wx/button.h>
+#include <wx/propgrid/propgrid.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CParameters_Control : public wxPanel
+{
+	DECLARE_CLASS(CParameters_Control)
+
+public:
+	CParameters_Control(wxWindow *pParent, bool bDialog = false);
+	virtual ~CParameters_Control(void);
+
+	void						On_Size				(wxSizeEvent &event);
+	void						On_PG_Selected		(wxPropertyGridEvent &event);
+	void						On_PG_Changed		(wxPropertyGridEvent &event);
+
+	bool						Update_DataObjects	(void);
+
+	bool						Set_Parameters		(class CSG_Parameters *pParameters);
+	class CSG_Parameters *		Get_Parameters		(void)	{	return( m_pParameters );	}
+
+	bool						is_Modified			(void)	{	return( m_bModified );	}
+
+	bool						Save_Changes		(bool bSilent);
+	bool						Restore				(void);
+
+	bool						Load				(void);
+	bool						Save				(void);
+
+
+private:
+
+	bool						m_bModified;
+
+	class CSG_Parameters		*m_pParameters, *m_pOriginal;
+
+	class wxPropertyGrid		*m_pPG;
+
+	class wxPropertyGridManager	*m_pPGM;
+
+
+	void						_Add_Properties		(class CSG_Parameters *pParameters);
+	void						_Add_Property		(class wxPGProperty *pParent, class CSG_Parameter *pParameter);
+	class wxPGProperty *		_Get_Property		(class wxPGProperty *pParent, class CSG_Parameter *pParameter);
+
+	void						_Set_Parameter		(const wxString &Identifier);
+	void						_Update_Parameters	(void);
+	void						_Update_Parameter	(class CSG_Parameter *pParameter);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__Parameters_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,954 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               Parameters_Properties.cpp               //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_grid_manager.h"
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+
+#include "wksp_table_manager.h"
+#include "wksp_table.h"
+
+#include "wksp_shapes_manager.h"
+#include "wksp_shapes_type.h"
+#include "wksp_shapes.h"
+
+#include "wksp_tin_manager.h"
+#include "wksp_tin.h"
+
+#include "wksp_pointcloud_manager.h"
+#include "wksp_pointcloud.h"
+
+#include "parameters_properties.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_DATAOBJECT_LABEL(p)	(p->is_Option() ? wxString::Format(p->Get_Name()) : wxString::Format(wxT("%s %s"), p->is_Input() ? (p->is_Optional() ? wxT(">") : wxT(">>")) : (p->is_Optional() ? wxT("<") : wxT("<<")), p->Get_Name()))
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CParameters_PG_Choice::CParameters_PG_Choice(CSG_Parameter *pParameter)
+	: wxEnumProperty(GET_DATAOBJECT_LABEL(pParameter), pParameter->Get_Identifier(), NULL)
+{
+	m_pParameter	= pParameter;
+
+	_Create();
+}
+
+//---------------------------------------------------------
+CParameters_PG_Choice::~CParameters_PG_Choice(void)
+{
+	_Destroy();
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Choice::_Create(void)
+{
+	_Destroy();
+
+	if( m_pParameter )
+	{
+		switch( m_pParameter->Get_Type() )
+		{
+		default:							SetIndex(0);					break;
+		case PARAMETER_TYPE_Choice:			SetIndex(_Set_Choice());		break;
+		case PARAMETER_TYPE_Grid_System:	SetIndex(_Set_Grid_System());	break;
+		case PARAMETER_TYPE_Table_Field:	SetIndex(_Set_Table_Field());	break;
+		case PARAMETER_TYPE_Grid:			SetIndex(_Set_Grid());			break;
+		case PARAMETER_TYPE_Table:			SetIndex(_Set_Table());			break;
+		case PARAMETER_TYPE_Shapes:			SetIndex(_Set_Shapes());		break;
+		case PARAMETER_TYPE_TIN:			SetIndex(_Set_TIN());			break;
+		case PARAMETER_TYPE_PointCloud:		SetIndex(_Set_PointCloud());	break;
+		}
+
+		if( GetGrid() )
+		{
+			RecreateEditor();
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Choice::_Destroy(void)
+{
+	m_choices		.Clear();
+	m_choices_data	.Clear();
+
+	SetIndex(0);
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Choice::_Append(const wxChar *Label, long Value)
+{
+	m_choices		.Add(Label, Value);
+	m_choices_data	.Add((void *)NULL);
+}
+
+void CParameters_PG_Choice::_Append(const wxChar *Label, void *Value)
+{
+	m_choices		.Add(Label, m_choices_data.Count());
+	m_choices_data	.Add(Value);
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Choice::Update(void)
+{
+	_Create();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_Choice(void)
+{
+	for(int i=0; i<m_pParameter->asChoice()->Get_Count(); i++)
+	{
+		_Append(m_pParameter->asChoice()->Get_Item(i), i);
+	}
+
+	return( m_pParameter->asInt() );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_Table_Field(void)
+{
+	CSG_Parameter	*pParent;
+	CSG_Table		*pTable;
+
+	if(	(pParent = m_pParameter->Get_Parent()) != NULL)
+	{
+		switch( pParent->Get_Type() )
+		{
+	    default:					pTable	= NULL;					break;
+		case PARAMETER_TYPE_Table:	pTable	= pParent->asTable();	break;
+		case PARAMETER_TYPE_Shapes:	pTable	= pParent->asShapes();	break;
+		case PARAMETER_TYPE_TIN:	pTable	= pParent->asTIN();		break;
+		}
+
+		if( pTable )
+		{
+			for(int i=0; i<pTable->Get_Field_Count(); i++)
+			{
+				_Append(pTable->Get_Field_Name(i));
+			}
+
+			if( m_pParameter->is_Optional() || pTable->Get_Field_Count() == 0 )
+			{
+				_Append( LNG("[VAL] [not set]") );
+			}
+
+			return( m_pParameter->asInt() >= 0 ? m_pParameter->asInt() : GetItemCount() - 1);
+		}
+	}
+
+	_Append( LNG("[VAL] [not set]") );
+
+	return( GetItemCount() - 1 );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_Table(void)
+{
+	CWKSP_Table_Manager	*pTables;
+
+	if( (pTables = g_pData->Get_Tables()) != NULL )
+	{
+		for(int i=0; i<pTables->Get_Count(); i++)
+		{
+			_Append(pTables->Get_Table(i)->Get_Name(), pTables->Get_Table(i)->Get_Table());
+		}
+	}
+
+	CWKSP_Shapes_Manager	*pManager;
+
+	if( (pManager = g_pData->Get_Shapes()) != NULL )
+	{
+		for(int i=0; i<pManager->Get_Count(); i++)
+		{
+			CWKSP_Shapes_Type	*pShapes	= (CWKSP_Shapes_Type *)pManager->Get_Item(i);
+
+			for(int j=0; j<pShapes->Get_Count(); j++)
+			{
+				_Append(pShapes->Get_Shapes(j)->Get_Name(), pShapes->Get_Shapes(j)->Get_Shapes());
+			}
+		}
+	}
+
+	return( _DataObject_Init() );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_Shapes(void)
+{
+	CWKSP_Shapes_Manager	*pManager;
+
+	if( (pManager = g_pData->Get_Shapes()) != NULL )
+	{
+		int		Shape_Type	= ((CSG_Parameter_Shapes *)m_pParameter->Get_Data())->Get_Shape_Type();
+
+		for(int i=0; i<pManager->Get_Count(); i++)
+		{
+			CWKSP_Shapes_Type	*pShapes	= (CWKSP_Shapes_Type *)pManager->Get_Item(i);
+
+			if( Shape_Type == SHAPE_TYPE_Undefined || Shape_Type == pShapes->Get_Shapes_Type() )
+			{
+				for(int j=0; j<pShapes->Get_Count(); j++)
+				{
+					_Append(pShapes->Get_Shapes(j)->Get_Name(), pShapes->Get_Shapes(j)->Get_Shapes());
+				}
+			}
+		}
+	}
+
+	return( _DataObject_Init() );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_TIN(void)
+{
+	CWKSP_TIN_Manager	*pTINs;
+
+	if( (pTINs = g_pData->Get_TINs()) != NULL )
+	{
+		for(int i=0; i<pTINs->Get_Count(); i++)
+		{
+			_Append(pTINs->Get_TIN(i)->Get_Name(), pTINs->Get_TIN(i)->Get_TIN());
+		}
+	}
+
+	return( _DataObject_Init() );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_PointCloud(void)
+{
+	CWKSP_PointCloud_Manager	*pManager;
+
+	if( (pManager = g_pData->Get_PointClouds()) != NULL )
+	{
+		for(int i=0; i<pManager->Get_Count(); i++)
+		{
+			_Append(pManager->Get_PointCloud(i)->Get_Name(), pManager->Get_PointCloud(i)->Get_PointCloud());
+		}
+	}
+
+	return( _DataObject_Init() );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_Grid_System(void)
+{
+	g_pData->Check_Parameter(m_pParameter);
+
+	CWKSP_Grid_Manager	*pSystems	= g_pData->Get_Grids();
+
+	if( pSystems && pSystems->Get_Count() > 0 )
+	{
+		int	index	= pSystems->Get_Count();
+
+		for(int i=0; i<pSystems->Get_Count(); i++)
+		{
+			_Append(pSystems->Get_System(i)->Get_Name(), pSystems->Get_System(i)->Get_System());
+
+			if( m_pParameter->asGrid_System()->is_Equal(*pSystems->Get_System(i)->Get_System()) )
+			{
+				index	= i;
+			}
+		}
+
+		_Append(LNG("[VAL] [not set]"));
+
+		return( index );
+	}
+
+	_Append( LNG("[VAL] [no choice available]"));
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_Set_Grid(void)
+{
+	CSG_Parameter		*pParent	= m_pParameter->Get_Parent();
+	CWKSP_Grid_Manager	*pManager	= g_pData->Get_Grids();
+	CWKSP_Grid_System	*pSystem	= NULL;
+
+	if( pManager && pParent && pParent->Get_Type() == PARAMETER_TYPE_Grid_System && pParent->asGrid_System()->is_Valid() )
+	{
+		for(int i=0; i<pManager->Get_Count() && !pSystem; i++)
+		{
+			if( pParent->asGrid_System()->is_Equal(*pManager->Get_System(i)->Get_System()) )
+			{
+				pSystem	= pManager->Get_System(i);
+			}
+		}
+	}
+
+	if( pSystem )
+	{
+		for(int i=0; i<pSystem->Get_Count(); i++)
+		{
+			_Append(pSystem->Get_Grid(i)->Get_Name(), pSystem->Get_Grid(i)->Get_Grid());
+		}
+	}
+
+	return( _DataObject_Init() );
+}
+
+//---------------------------------------------------------
+int CParameters_PG_Choice::_DataObject_Init(void)
+{
+	if( m_pParameter->is_Output() )
+	{
+		_Append(LNG("[VAL] [create]"), DATAOBJECT_CREATE);
+	}
+
+	if( !m_pParameter->is_Output() || (m_pParameter->is_Output() && m_pParameter->is_Optional()) )
+	{
+		_Append(LNG("[VAL] [not set]"), DATAOBJECT_NOTSET);
+	}
+
+	g_pData->Check_Parameter(m_pParameter);
+
+	for(int i=0; i<(int)GetItemCount(); i++)
+	{
+		if( m_pParameter->asDataObject() == (void *)m_choices_data.Item(m_choices.GetValue(i)) )
+		{
+			return( i );
+		}
+	}
+
+	return( GetItemCount() - 1 );
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Choice::OnEvent(wxPropertyGrid *pPG, wxWindow *pPGCtrl, wxEvent &event)
+{
+	if( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
+	{
+		if( m_pParameter && m_choices.IsOk() && GetIndex() >= 0 && GetIndex() < (int)GetItemCount() )
+		{
+			switch( m_pParameter->Get_Type() )
+			{
+			default:
+				break;
+
+			case PARAMETER_TYPE_Choice:
+			case PARAMETER_TYPE_Table_Field:
+				m_pParameter->Set_Value(GetIndex());
+				break;
+
+			case PARAMETER_TYPE_Grid_System:
+				m_pParameter->Set_Value((void *)m_choices_data.Item(m_choices.GetValue(GetIndex())));
+				_Update_Grids(pPG);
+				break;
+
+			case PARAMETER_TYPE_Grid:
+				m_pParameter->Set_Value((void *)m_choices_data.Item(m_choices.GetValue(GetIndex())));
+				break;
+
+			case PARAMETER_TYPE_Table:
+			case PARAMETER_TYPE_Shapes:
+			case PARAMETER_TYPE_TIN:
+			case PARAMETER_TYPE_PointCloud:
+				m_pParameter->Set_Value((void *)m_choices_data.Item(m_choices.GetValue(GetIndex())));
+				_Update_TableFields(pPG);
+				break;
+			}
+
+			pPG->EditorsValueWasModified();
+
+			return( true );
+		}
+	}
+
+	event.Skip();
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Choice::_Update_Grids(wxPropertyGrid *pPG)
+{
+	if( m_pParameter && m_pParameter->Get_Type() == PARAMETER_TYPE_Grid_System )
+	{
+		for(int i=0; i<m_pParameter->Get_Children_Count(); i++)
+		{
+			wxPGProperty	*pProperty;
+			CSG_Parameter	*pChild	= m_pParameter->Get_Child(i);
+
+			switch( pChild->Get_Type() )
+			{
+			default:
+				break;
+				
+			case PARAMETER_TYPE_Grid_List:
+				break;
+
+			case PARAMETER_TYPE_Grid:
+				if( (pProperty = pPG->GetProperty(wxString::Format(wxT("%s.%s"), m_pParameter->Get_Identifier(), pChild->Get_Identifier()))) != NULL )
+				{
+					((CParameters_PG_Choice *)pProperty)->Update();
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Choice::_Update_TableFields(wxPropertyGrid *pPG)
+{
+	if( m_pParameter )
+	{
+		for(int i=0; i<m_pParameter->Get_Children_Count(); i++)
+		{
+			CSG_Parameter	*pChild	= m_pParameter->Get_Child(i);
+
+			if(	pChild->Get_Type() == PARAMETER_TYPE_Table_Field )
+			{
+				wxPGProperty	*pProperty	= pPG->GetProperty(wxString::Format(wxT("%s.%s"), m_pParameter->Get_Identifier(), pChild->Get_Identifier()));
+
+				if( pProperty )
+				{
+					((CParameters_PG_Choice *)pProperty)->Update();
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+WX_PG_IMPLEMENT_VARIANT_DATA(CParameters_PG_Parameter_Variant, CParameters_PG_Parameter_Value)
+
+//---------------------------------------------------------
+bool CParameters_PG_Parameter_Value::from_String(const wxString &String)
+{
+	switch( m_pParameter->Get_Type() )
+	{
+	default:
+		return( false );
+
+	case PARAMETER_TYPE_Text:
+	case PARAMETER_TYPE_FilePath:
+		m_pParameter->Set_Value(String.c_str());
+		return( true );
+	}
+}
+
+//---------------------------------------------------------
+wxString CParameters_PG_Parameter_Value::to_String(void) const
+{
+	wxString	s;
+
+	if( m_pParameter && Check() )
+	{
+		s	= m_pParameter->asString();
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Parameter_Value::Check(void) const
+{
+	if( m_pParameter )
+	{
+		switch( m_pParameter->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+		case PARAMETER_TYPE_Grid_List:
+			CSG_Parameter_List	*pList	= (CSG_Parameter_Grid_List *)m_pParameter->Get_Data();
+
+			for(int i=pList->Get_Count()-1; i>=0; i--)
+			{
+				if( !g_pData->Exists(pList->asDataObject(i)) )
+				{
+					pList->Del_Item(i);
+				}
+			}
+
+			break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Parameter_Value::Do_Dialog(void)
+{
+	bool		bModified	= false;
+	long		Color;
+	wxString	Text;
+
+	if( m_pParameter )
+	{
+		switch( m_pParameter->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Font:
+			bModified	= DLG_Font			(m_pParameter->asFont(), Color = m_pParameter->asColor());
+
+			if( bModified )
+			{
+				m_pParameter->Set_Value((int)Color);
+
+				return( true );
+			}
+			break;
+
+		case PARAMETER_TYPE_Text:
+			bModified	= DLG_Text			(m_pParameter->Get_Name(), Text = m_pParameter->asString());
+
+			if( bModified )
+			{
+				m_pParameter->Set_Value(Text.c_str());
+
+				return( true );
+			}
+			break;
+
+		case PARAMETER_TYPE_FilePath:
+			Text	= m_pParameter->asString();
+
+			if( m_pParameter->asFilePath()->is_Directory() )
+			{
+				bModified	= DLG_Directory	(Text, LNG("[CAP] Choose Directory"));
+			}
+			else if( m_pParameter->asFilePath()->is_Save() )
+			{
+				bModified	= DLG_Save		(Text, LNG("[CAP] Save"), m_pParameter->asFilePath()->Get_Filter());
+			}
+			else if( m_pParameter->asFilePath()->is_Multiple() == false )
+			{
+				bModified	= DLG_Open		(Text, LNG("[CAP] Open"), m_pParameter->asFilePath()->Get_Filter());
+			}
+			else
+			{
+				wxArrayString	Files;
+
+				bModified	= DLG_Open		(Files, LNG("[CAP] Open"), m_pParameter->asFilePath()->Get_Filter());
+
+				if( bModified )
+				{
+					if( Files.GetCount() > 0 )
+					{
+						Text.Clear();
+
+						for(size_t i=0; i<Files.GetCount(); i++)
+						{
+							Text.Append(i > 0 ? wxT(" \"") : wxT("\""));
+							Text.Append(Files.Item(i));
+							Text.Append(wxT("\""));
+						}
+					}
+					else
+					{
+						Text	= Files.Item(0);
+					}
+				}
+			}
+
+			if( bModified )
+			{
+				m_pParameter->Set_Value(Text.c_str());
+
+				return( true );
+			}
+			break;
+
+		case PARAMETER_TYPE_FixedTable:
+			bModified	= DLG_Table			(m_pParameter->Get_Name(), m_pParameter->asTable());
+			break;
+
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+			bModified	= DLG_List			(m_pParameter->Get_Name(), m_pParameter->asList());
+			break;
+
+		case PARAMETER_TYPE_Colors:
+			bModified	= DLG_Colors		(m_pParameter->asColors());
+			break;
+
+		case PARAMETER_TYPE_Parameters:
+			bModified	= DLG_Parameters	(m_pParameter->asParameters());
+			break;
+		}
+	}
+
+	if( bModified )
+	{
+		m_pParameter->has_Changed();
+	}
+
+	return( bModified );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+WX_PG_IMPLEMENT_PROPERTY_CLASS(CParameters_PG_Range, wxPGProperty, CParameters_PG_Parameter_Value, const &CParameters_PG_Parameter_Value, TextCtrl)
+
+//---------------------------------------------------------
+CParameters_PG_Range::CParameters_PG_Range(const wxString &label, const wxString &name, CSG_Parameter *pParameter)
+	: wxPGProperty(label, name)
+{
+	if( pParameter && pParameter->Get_Type() == PARAMETER_TYPE_Range )
+	{
+		m_value	= CParameters_PG_Parameter_ValueToVariant(CParameters_PG_Parameter_Value(pParameter));
+
+		AddPrivateChild( new wxFloatProperty(wxT("Minimum")	, wxPG_LABEL, pParameter->asRange()->Get_LoVal()) );
+		AddPrivateChild( new wxFloatProperty(wxT("Maximum")	, wxPG_LABEL, pParameter->asRange()->Get_HiVal()) );
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Range::RefreshChildren(void)
+{
+	const CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(m_value);
+
+	if( GetCount() == 2 && value.m_pParameter && value.m_pParameter->Get_Type() == PARAMETER_TYPE_Range )
+	{
+		Item(0)->SetValue( value.m_pParameter->asRange()->Get_LoVal() );
+		Item(1)->SetValue( value.m_pParameter->asRange()->Get_HiVal() );
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Range::ChildChanged(wxVariant &thisValue, int childIndex, wxVariant &childValue) const
+{
+	CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(thisValue);
+
+	if( GetCount() == 2 && value.m_pParameter && value.m_pParameter->Get_Type() == PARAMETER_TYPE_Range )
+	{
+		double	v;
+
+		if( wxPGVariantToDouble(childValue, &v) )
+		{
+			switch( childIndex )
+			{
+				case 0:	value.m_pParameter->asRange()->Set_LoVal(v);	break;
+				case 1:	value.m_pParameter->asRange()->Set_HiVal(v);	break;
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Range::Update(void)
+{
+	SetValue(m_value);
+
+	return( true );
+
+//	s.Printf( SG_T("%f; %f"), pParameter->asRange()->Get_LoVal(), pParameter->asRange()->Get_HiVal());
+//	m_pPG->SetPropertyValue(pProperty, s.c_str());
+//	RefreshChildren();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+WX_PG_IMPLEMENT_PROPERTY_CLASS(CParameters_PG_Degree, wxPGProperty, CParameters_PG_Parameter_Value, const &CParameters_PG_Parameter_Value, TextCtrl)
+
+//---------------------------------------------------------
+CParameters_PG_Degree::CParameters_PG_Degree(const wxString &label, const wxString &name, CSG_Parameter *pParameter)
+	: wxPGProperty(label, name)
+{
+	if( pParameter && pParameter->Get_Type() == PARAMETER_TYPE_Degree )
+	{
+		m_value	= CParameters_PG_Parameter_ValueToVariant(CParameters_PG_Parameter_Value(pParameter));
+
+		double	d, m, s;
+
+		Decimal_To_Degree(pParameter->asDouble(), d, m, s);
+
+		AddPrivateChild( new wxIntProperty  (wxT("Degree")	, wxPG_LABEL, (int)d) );
+		AddPrivateChild( new wxIntProperty  (wxT("Minute")	, wxPG_LABEL, (int)m) );
+		AddPrivateChild( new wxFloatProperty(wxT("Second")	, wxPG_LABEL,      s) );
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Degree::RefreshChildren(void)
+{
+	const CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(m_value);
+
+	if( GetCount() == 3 && value.m_pParameter && value.m_pParameter->Get_Type() == PARAMETER_TYPE_Degree )
+	{
+		double	d, m, s;
+
+		Decimal_To_Degree(value.m_pParameter->asDouble(), d, m, s);
+
+		Item(0)->SetValue((int)d);
+		Item(1)->SetValue((int)m);
+		Item(2)->SetValue(     s);
+	}
+}
+
+//---------------------------------------------------------
+void CParameters_PG_Degree::ChildChanged(wxVariant &thisValue, int childIndex, wxVariant &childValue) const
+{
+	CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(thisValue);
+
+	if( GetCount() == 3 && value.m_pParameter && value.m_pParameter->Get_Type() == PARAMETER_TYPE_Degree )
+	{
+		double	v, d, m, s;
+
+		if( wxPGVariantToDouble(childValue, &v) )
+		{
+			Decimal_To_Degree(value.m_pParameter->asDouble(), d, m, s);
+
+			switch( childIndex )
+			{
+				case 0:	d	= (int)v;	break;
+				case 1:	m	= (int)v;	break;
+				case 2:	s	=      v;	break;
+			}
+
+			value.m_pParameter->Set_Value(Degree_To_Decimal(d, m, s));
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Degree::Update(void)
+{
+	SetValue(m_value);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+WX_PG_IMPLEMENT_PROPERTY_CLASS(CParameters_PG_Dialog, wxPGProperty, CParameters_PG_Parameter_Value, const CParameters_PG_Parameter_Value &, TextCtrlAndButton)
+
+//---------------------------------------------------------
+CParameters_PG_Dialog::CParameters_PG_Dialog(const wxString &label, const wxString &name, CSG_Parameter *pParameter)
+	: wxPGProperty(pParameter ? GET_DATAOBJECT_LABEL(pParameter) : label, name)
+{
+	m_value	= CParameters_PG_Parameter_ValueToVariant(CParameters_PG_Parameter_Value(pParameter));
+}
+
+//---------------------------------------------------------
+wxString CParameters_PG_Dialog::GetValueAsString(int flags) const
+{
+	const CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(m_value);
+
+	if( value.m_pParameter )
+	{
+		return( value.to_String() );
+	}
+
+	return( wxT("---") );
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Dialog::OnEvent(wxPropertyGrid *propgrid, wxWindow *primary, wxEvent &event)
+{
+	if( propgrid->IsMainButtonEvent(event) )
+	{
+		PrepareValueForDialogEditing(propgrid);
+
+		CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(m_value);
+
+		if( value.m_pParameter && value.Do_Dialog() )
+		{
+			propgrid->EditorsValueWasModified();
+
+			SetValueInEvent(m_value);
+
+			return( true );
+		}
+	}
+	else if( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER && primary && propgrid->IsEditorsValueModified() )
+	{
+		CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(m_value);
+
+		if( value.m_pParameter && value.m_pParameter->Get_Type() == PARAMETER_TYPE_FilePath )
+		{
+			value.m_pParameter->Set_Value(((wxTextCtrl *)primary)->GetValue().c_str());
+
+			propgrid->EditorsValueWasModified();
+
+			SetValueInEvent(m_value);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CParameters_PG_Dialog::Update(void)
+{
+	SetValue(m_value);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+WX_PG_IMPLEMENT_PROPERTY_CLASS(CParameters_PG_Colors, wxPGProperty, CParameters_PG_Parameter_Value, const CParameters_PG_Parameter_Value &, TextCtrlAndButton)
+
+//---------------------------------------------------------
+CParameters_PG_Colors::CParameters_PG_Colors(const wxString &label, const wxString &name, CSG_Parameter *pParameter)
+	: CParameters_PG_Dialog(label, name, pParameter)
+{}
+
+//---------------------------------------------------------
+void CParameters_PG_Colors::OnCustomPaint(wxDC &dc, const wxRect &r, wxPGPaintData &pd)
+{
+	const CParameters_PG_Parameter_Value	&value	= CParameters_PG_Parameter_ValueFromVariant(m_value);
+
+	if( value.m_pParameter && value.m_pParameter->Get_Type() == PARAMETER_TYPE_Colors )
+	{
+		int		i, ax, bx;
+
+		CSG_Colors	*pColors	= value.m_pParameter->asColors();
+		double		dx			= r.GetWidth() / (double)pColors->Get_Count();
+
+		for(i=0, bx=r.GetLeft(); i<pColors->Get_Count(); i++)
+		{
+			ax	= bx;
+			bx	= r.GetLeft() + (int)(dx * (i + 1.0));
+
+			Draw_FillRect(dc, Get_Color_asWX(pColors->Get_Color(i)), ax, r.GetTop(), bx, r.GetBottom());
+		}
+	}
+}
+
+//---------------------------------------------------------
+wxSize CParameters_PG_Colors::OnMeasureImage(int item = -1) const
+{
+	return( wxSize(-1, -1) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/parameters_properties.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,224 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                Parameters_Properties.h                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__Parameters_Properties_H
+#define _HEADER_INCLUDED__SAGA_GUI__Parameters_Properties_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+
+#include <wx/propgrid/propgrid.h>
+#include <wx/propgrid/propdev.h>
+#include <wx/propgrid/advprops.h>
+#include <wx/propgrid/manager.h>
+#include <wx/propgrid/extras.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CParameters_PG_Choice : public wxEnumProperty
+{
+public:
+	CParameters_PG_Choice(CSG_Parameter *pParameter);
+	virtual ~CParameters_PG_Choice(void);
+
+	bool						Update				(void);
+
+	virtual bool				OnEvent				(wxPropertyGrid *pPG, wxWindow *pPGCtrl, wxEvent &event);
+
+
+protected:
+
+	class CSG_Parameter			*m_pParameter;
+
+	wxArrayPtrVoid				m_choices_data;
+
+
+	void						_Create				(void);
+	void						_Destroy			(void);
+
+	void						_Append				(const wxChar *Label, long  Value);
+	void						_Append				(const wxChar *Label, void *Value = NULL);
+
+	int							_Set_Choice			(void);
+	int							_Set_Table			(void);
+	int							_Set_Table_Field	(void);
+	int							_Set_Shapes			(void);
+	int							_Set_TIN			(void);
+	int							_Set_PointCloud		(void);
+	int							_Set_Grid_System	(void);
+	int							_Set_Grid			(void);
+
+	int							_DataObject_Init	(void);
+
+	void						_Update_Grids		(wxPropertyGrid *pPG);
+	void						_Update_TableFields	(wxPropertyGrid *pPG);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CParameters_PG_Parameter_Value
+{
+public:
+	CParameters_PG_Parameter_Value(void)							{	m_pParameter	= NULL;			}
+	CParameters_PG_Parameter_Value(CSG_Parameter *pParameter)		{	m_pParameter	= pParameter;	}
+
+	CSG_Parameter				*m_pParameter;
+
+	bool						from_String			(const wxString &String);
+	wxString					to_String			(void) const;
+	bool						Check				(void) const;
+	bool						Do_Dialog			(void);
+
+};
+
+WX_PG_DECLARE_VARIANT_DATA(CParameters_PG_Parameter_Variant, CParameters_PG_Parameter_Value, wxEMPTY_PARAMETER_VALUE)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CParameters_PG_Range : public wxPGProperty
+{
+	WX_PG_DECLARE_PROPERTY_CLASS(CParameters_PG_Range)
+
+public:
+	CParameters_PG_Range(const wxString &label = wxPG_LABEL, const wxString &name = wxPG_LABEL, CSG_Parameter *pParameter = NULL);
+
+	WX_PG_DECLARE_PARENTAL_METHODS()
+
+	bool						Update				(void);
+
+};
+
+//---------------------------------------------------------
+class CParameters_PG_Degree : public wxPGProperty
+{
+	WX_PG_DECLARE_PROPERTY_CLASS(CParameters_PG_Degree)
+
+public:
+	CParameters_PG_Degree(const wxString &label = wxPG_LABEL, const wxString &name = wxPG_LABEL, CSG_Parameter *pParameter = NULL);
+
+	WX_PG_DECLARE_PARENTAL_METHODS()
+
+	bool						Update				(void);
+
+};
+
+//---------------------------------------------------------
+class CParameters_PG_Dialog : public wxPGProperty
+{
+	WX_PG_DECLARE_PROPERTY_CLASS(CParameters_PG_Dialog)
+
+public:
+	CParameters_PG_Dialog(const wxString &label = wxPG_LABEL, const wxString &name = wxPG_LABEL, CSG_Parameter *pParameter = NULL);
+
+	virtual wxString			GetValueAsString	(int flags)	const;
+
+	WX_PG_DECLARE_EVENT_METHODS()
+
+	bool						Update				(void);
+
+};
+
+//---------------------------------------------------------
+class CParameters_PG_Colors : public CParameters_PG_Dialog
+{
+	WX_PG_DECLARE_PROPERTY_CLASS(CParameters_PG_Colors)
+
+public:
+	CParameters_PG_Colors(const wxString &label = wxPG_LABEL, const wxString &name = wxPG_LABEL, CSG_Parameter *pParameter = NULL);
+
+	WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__Parameters_Properties_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1064 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     Project.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/string.h>
+#include <wx/filename.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "res_dialogs.h"
+
+#include "saga_frame.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_data_menu_files.h"
+
+#include "wksp_table_manager.h"
+#include "wksp_table.h"
+
+#include "wksp_shapes_manager.h"
+#include "wksp_shapes_type.h"
+#include "wksp_shapes.h"
+
+#include "wksp_tin_manager.h"
+#include "wksp_tin.h"
+
+#include "wksp_pointcloud_manager.h"
+#include "wksp_pointcloud.h"
+
+#include "wksp_grid_manager.h"
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+#include "wksp_layer.h"
+
+#include "project.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DATA_ENTRIES_BEGIN	wxT("[DATA_ENTRIES_BEGIN]")
+#define DATA_ENTRIES_END	wxT("[DATA_ENTRIES_END]")
+#define DATA_ENTRY_BEGIN	wxT("[DATA_ENTRY_BEGIN]")
+#define DATA_ENTRY_END		wxT("[DATA_ENTRY_END]")
+
+//---------------------------------------------------------
+#define MAP_ENTRIES_BEGIN	wxT("[MAP_ENTRIES_BEGIN]")
+#define MAP_ENTRIES_END		wxT("[MAP_ENTRIES_END]")
+#define MAP_ENTRY_BEGIN		wxT("[MAP_ENTRY_BEGIN]")
+#define MAP_ENTRY_END		wxT("[MAP_ENTRY_END]")
+#define MAP_ENTRY_NAME		wxT("[MAP_ENTRY_NAME]")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Project::CWKSP_Project(void)
+{
+}
+
+//---------------------------------------------------------
+CWKSP_Project::~CWKSP_Project(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::Has_File_Name(void)
+{
+	return( wxFileExists(m_File_Name) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::Clr_File_Name(void)
+{
+	m_File_Name.Clear();
+
+	g_pSAGA_Frame->Set_Project_Name();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Set_Project_Name(void)
+{
+	if( Has_File_Name() )
+	{
+		wxFileName	fn(m_File_Name);
+
+		if( fn.GetFullName().CmpNoCase(wxT("saga_gui.cfg")) )
+		{
+			g_pSAGA_Frame->Set_Project_Name(m_File_Name);
+
+			return( true );
+		}
+
+		Clr_File_Name();
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::Load(bool bAdd)
+{
+	wxString	FileName;
+
+	return( DLG_Open(FileName, ID_DLG_PROJECT_OPEN) && _Load(FileName, bAdd, true) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::Load(const wxChar *FileName, bool bAdd, bool bUpdateMenu)
+{
+	return( _Load(FileName, bAdd, bUpdateMenu) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::Save(void)
+{
+	wxString	FileName;
+
+	return( DLG_Save(FileName, ID_DLG_PROJECT_SAVE) && _Save(FileName, true, true) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::Save(bool bSaveAsOnError)
+{
+	if( Has_File_Name() )
+	{
+		return( _Save(m_File_Name, true, true) );
+	}
+
+	return( bSaveAsOnError ? Save() : false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::Save(const wxChar *FileName, bool bSaveModified)
+{
+	return( _Save(FileName, bSaveModified, false) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Load(const wxChar *FileName, bool bAdd, bool bUpdateMenu)
+{
+	if( !bAdd && g_pData->Get_Count() > 0 )
+	{
+		switch( DLG_Message_YesNoCancel(LNG("[TXT] Close all data sets"), LNG("[CAP] Load Project")) )
+		{
+		case 0:
+			if( !g_pData->Close(true) )
+				return( false );
+			break;
+
+		case 2:
+			return( false );
+		}
+	}
+
+	//-------------------------------------------------
+	MSG_General_Add_Line();
+	MSG_General_Add(wxString::Format(wxT("%s: %s"), LNG("[MSG] Load project"), FileName), true, true);
+
+	//-------------------------------------------------
+	bool			bSuccess	= false;
+
+	CSG_MetaData	Project, *pNode;
+
+	if( _Compatibility_Load_Data(FileName) )
+	{
+		bSuccess	= true;
+	}
+	else if( !wxFileExists(FileName) )
+	{
+		MSG_Error_Add(LNG("[MSG] file does not exist.")				, true, true, SG_UI_MSG_STYLE_FAILURE);
+	}
+	else if( !Project.Load(FileName) )
+	{
+		MSG_Error_Add(LNG("[MSG] could not read project file.")		, true, true, SG_UI_MSG_STYLE_FAILURE);
+	}
+	else if( Project.Get_Name().Cmp(SG_T("SAGA_PROJECT")) )
+	{
+		MSG_Error_Add(LNG("[MSG] invalid project file.")			, true, true, SG_UI_MSG_STYLE_FAILURE);
+	}
+	else if( (pNode = Project.Get_Child(SG_T("DATA"))) == NULL || pNode->Get_Children_Count() <= 0 )
+	{
+		MSG_Error_Add(LNG("[MSG] no data entries in project file.")	, true, true, SG_UI_MSG_STYLE_FAILURE);
+	}
+	else
+	{
+		bSuccess	= true;
+
+		//-------------------------------------------------
+		g_pData->Get_FileMenus()->Set_Update(false);
+
+		for(int i=0; i<pNode->Get_Children_Count(); i++)
+		{
+			_Load_Data(*pNode->Get_Child(i), SG_File_Get_Path(FileName));
+		}
+
+		g_pData->Get_FileMenus()->Set_Update(true);
+
+		//-------------------------------------------------
+		if( (pNode = Project.Get_Child(SG_T("MAPS"))) != NULL && pNode->Get_Children_Count() > 0 )
+		{
+			for(int j=0; j<pNode->Get_Children_Count(); j++)
+			{
+				_Load_Map(*pNode->Get_Child(j), SG_File_Get_Path(FileName));
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( bSuccess )
+	{
+		if( bUpdateMenu )
+		{
+			g_pData->Get_FileMenus()->Recent_Add(DATAOBJECT_TYPE_Undefined, FileName);
+		}
+
+		MSG_General_Add(LNG("[MSG] Project has been successfully loaded."), true, true, SG_UI_MSG_STYLE_SUCCESS);
+
+		m_File_Name	= FileName;
+
+		_Set_Project_Name();
+
+		return( true );
+	}
+
+	if( bUpdateMenu )
+	{
+		g_pData->Get_FileMenus()->Recent_Del(DATAOBJECT_TYPE_Undefined, FileName);
+	}
+
+	MSG_General_Add(LNG("[MSG] Could not load project."), true, true, SG_UI_MSG_STYLE_FAILURE);
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Save(const wxChar *FileName, bool bSaveModified, bool bUpdateMenu)
+{
+	int							i, j;
+	CSG_String					ProjectDir, oldFileName(m_File_Name);
+	CSG_MetaData				Project, *pNode;
+	CWKSP_Table_Manager			*pTables;
+	CWKSP_Shapes_Manager		*pShapes;
+	CWKSP_TIN_Manager			*pTINs;
+	CWKSP_PointCloud_Manager	*pPointClouds;
+	CWKSP_Grid_Manager			*pGrids;
+
+	//-----------------------------------------------------
+	m_File_Name	= FileName;
+
+	if( bSaveModified && !Save_Modified(g_pData) )
+	{
+		m_File_Name	= oldFileName;
+
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	ProjectDir	= SG_File_Get_Path(FileName);
+
+	Project.Set_Name(SG_T("SAGA_PROJECT"));
+
+	//-----------------------------------------------------
+	pNode		= Project.Add_Child(SG_T("DATA"));
+
+	if( (pTables = g_pData->Get_Tables()) != NULL )
+	{
+		for(i=0; i<pTables->Get_Count(); i++)
+		{
+			_Save_Data(*pNode, ProjectDir,
+				pTables->Get_Table(i)->Get_Table(),
+				pTables->Get_Table(i)->Get_Parameters()
+			);
+		}
+	}
+
+	if( (pShapes = g_pData->Get_Shapes()) != NULL )
+	{
+		for(j=0; j<pShapes->Get_Count(); j++)
+		{
+			for(i=0; i<((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Count(); i++)
+			{
+				_Save_Data(*pNode, ProjectDir,
+					((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Shapes(i)->Get_Shapes(),
+					((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Shapes(i)->Get_Parameters()
+				);
+			}
+		}
+	}
+
+	if( (pTINs = g_pData->Get_TINs()) != NULL )
+	{
+		for(i=0; i<pTINs->Get_Count(); i++)
+		{
+			_Save_Data(*pNode, ProjectDir,
+				pTINs->Get_TIN(i)->Get_TIN(),
+				pTINs->Get_TIN(i)->Get_Parameters()
+			);
+		}
+	}
+
+	if( (pPointClouds = g_pData->Get_PointClouds()) != NULL )
+	{
+		for(i=0; i<pPointClouds->Get_Count(); i++)
+		{
+			_Save_Data(*pNode, ProjectDir,
+				pPointClouds->Get_PointCloud(i)->Get_PointCloud(),
+				pPointClouds->Get_PointCloud(i)->Get_Parameters()
+			);
+		}
+	}
+
+	if( (pGrids = g_pData->Get_Grids()) != NULL )
+	{
+		for(j=0; j<pGrids->Get_Count(); j++)
+		{
+			for(i=0; i<pGrids->Get_System(j)->Get_Count(); i++)
+			{
+				_Save_Data(*pNode, ProjectDir,
+					pGrids->Get_System(j)->Get_Grid(i)->Get_Grid(),
+					pGrids->Get_System(j)->Get_Grid(i)->Get_Parameters()
+				);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( g_pMaps->Get_Count() > 0 )
+	{
+		pNode		= Project.Add_Child(SG_T("MAPS"));
+
+		for(i=0; i<g_pMaps->Get_Count(); i++)
+		{
+			_Save_Map(*pNode, ProjectDir, g_pMaps->Get_Map(i));
+		}
+	}
+
+	//-----------------------------------------------------
+	if( Project.Save(FileName) )
+	{
+		m_File_Name	= FileName;
+
+		if( bUpdateMenu )
+			g_pData->Get_FileMenus()->Recent_Add(DATAOBJECT_TYPE_Undefined, FileName);
+
+		MSG_General_Add(LNG("[MSG] Project has been saved."), true, true, SG_UI_MSG_STYLE_SUCCESS);
+
+		_Set_Project_Name();
+
+		return( true );
+	}
+
+	m_File_Name.Clear();
+
+	if( bUpdateMenu )
+		g_pData->Get_FileMenus()->Recent_Del(DATAOBJECT_TYPE_Undefined, FileName);
+
+	MSG_General_Add(LNG("[MSG] Could not save project."), true, true, SG_UI_MSG_STYLE_FAILURE);
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Load_Data(CSG_MetaData &Entry, const wxChar *ProjectDir)
+{
+	int				Type;
+	wxString		File;
+	CWKSP_Base_Item	*pItem;
+
+	if( Entry.Get_Name().Cmp(SG_T("DATASET")) )
+	{
+		return( false );
+	}
+
+	Type	= Entry.Cmp_Property(SG_T("type"), SG_T("GRID"))	? DATAOBJECT_TYPE_Grid
+			: Entry.Cmp_Property(SG_T("type"), SG_T("TABLE"))	? DATAOBJECT_TYPE_Table
+			: Entry.Cmp_Property(SG_T("type"), SG_T("SHAPES"))	? DATAOBJECT_TYPE_Shapes
+			: Entry.Cmp_Property(SG_T("type"), SG_T("TIN"))		? DATAOBJECT_TYPE_TIN
+			: Entry.Cmp_Property(SG_T("type"), SG_T("POINTS"))	? DATAOBJECT_TYPE_PointCloud
+			: DATAOBJECT_TYPE_Undefined;
+
+	if( Type == DATAOBJECT_TYPE_Undefined )
+	{
+		return( false );
+	}
+
+	if( !Entry.Get_Child(SG_T("FILE")) )
+	{
+		return( false );
+	}
+
+	File	= Get_FilePath_Absolute(ProjectDir, Entry.Get_Child(SG_T("FILE"))->Get_Content().c_str());
+
+	if( !wxFileExists(File) )
+	{
+		return( false );
+	}
+
+	if(	(pItem = g_pData->Open(Type, File)) == NULL )
+	{
+		return( false );
+	}
+
+	if( pItem->Get_Parameters() && Entry.Get_Child(SG_T("PARAMETERS")) )
+	{
+		pItem->Get_Parameters()->Serialize(*Entry.Get_Child(SG_T("PARAMETERS")), false);
+		pItem->Parameters_Changed();
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Save_Data(CSG_MetaData &Entry, const wxChar *ProjectDir, CSG_Data_Object *pDataObject, CSG_Parameters *pParameters)
+{
+	if( !pDataObject || !pDataObject->Get_File_Name() || !wxFileExists(pDataObject->Get_File_Name()) )
+	{
+		return( false );
+	}
+
+	CSG_MetaData	*pEntry	= Entry.Add_Child(SG_T("DATASET"));
+
+	switch( pDataObject->Get_ObjectType() )
+	{
+	default:	return( false );
+	case DATAOBJECT_TYPE_Grid:			pEntry->Add_Property(SG_T("type"), SG_T("GRID"));	break;
+	case DATAOBJECT_TYPE_Table:			pEntry->Add_Property(SG_T("type"), SG_T("TABLE"));	break;
+	case DATAOBJECT_TYPE_Shapes:		pEntry->Add_Property(SG_T("type"), SG_T("SHAPES"));	break;
+	case DATAOBJECT_TYPE_TIN:			pEntry->Add_Property(SG_T("type"), SG_T("TIN"));	break;
+	case DATAOBJECT_TYPE_PointCloud:	pEntry->Add_Property(SG_T("type"), SG_T("POINTS"));	break;
+	}
+
+	pEntry->Add_Child(SG_T("FILE"), Get_FilePath_Relative(ProjectDir, pDataObject->Get_File_Name()).c_str());
+
+	if( pParameters )
+	{
+		pParameters->Serialize(*pEntry->Add_Child(SG_T("PARAMETERS")), true);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Load_Map(CSG_MetaData &Entry, const wxChar *ProjectDir)
+{
+	TSG_Rect		r;
+	CSG_MetaData	*pNode;
+	CWKSP_Base_Item	*pItem;
+	CWKSP_Map		*pMap;
+
+	if( Entry.Get_Name().Cmp(SG_T("MAP")) )
+	{
+		return( false );
+	}
+
+	if(	!Entry.Get_Child(SG_T("XMIN")) || !Entry.Get_Child(SG_T("XMIN"))->Get_Content().asDouble(r.xMin)
+	||	!Entry.Get_Child(SG_T("XMAX")) || !Entry.Get_Child(SG_T("XMAX"))->Get_Content().asDouble(r.xMax)
+	||	!Entry.Get_Child(SG_T("YMIN")) || !Entry.Get_Child(SG_T("YMIN"))->Get_Content().asDouble(r.yMin)
+	||	!Entry.Get_Child(SG_T("YMAX")) || !Entry.Get_Child(SG_T("YMAX"))->Get_Content().asDouble(r.yMax) )
+	{
+		return( false );
+	}
+
+	if( (pNode = Entry.Get_Child(SG_T("LAYERS"))) == NULL || pNode->Get_Children_Count() <= 0 )
+	{
+		return( false );
+	}
+
+	pMap	= NULL;
+
+	for(int i=0; i<pNode->Get_Children_Count(); i++)
+	{
+		if(	(pItem = _Get_byFileName(Get_FilePath_Absolute(ProjectDir, pNode->Get_Child(i)->Get_Content()))) != NULL
+		&&	(	pItem->Get_Type()	== WKSP_ITEM_Grid
+			||	pItem->Get_Type()	== WKSP_ITEM_TIN
+			||	pItem->Get_Type()	== WKSP_ITEM_PointCloud
+			||	pItem->Get_Type()	== WKSP_ITEM_Shapes) )
+		{
+			if( pMap == NULL )
+			{
+				pMap	= new CWKSP_Map;
+			}
+
+			g_pMaps->Add((CWKSP_Layer *)pItem, pMap);
+		}
+	}
+
+	if( !pMap )
+	{
+		return( false );
+	}
+
+	if( Entry.Get_Child(SG_T("NAME")) && Entry.Get_Child(SG_T("NAME"))->Get_Content().Length() > 0 )
+	{
+		pMap->Get_Parameters()->Get_Parameter("NAME")->Set_Value(Entry.Get_Child(SG_T("NAME"))->Get_Content());
+		pMap->Parameters_Changed();
+	}
+
+	pMap->Set_Extent(r, true);
+	pMap->View_Show(true);
+
+	return( true );
+}
+
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Save_Map(CSG_MetaData &Entry, const wxChar *ProjectDir, CWKSP_Map *pMap)
+{
+	if( !pMap )
+	{
+		return( false );
+	}
+
+	CSG_MetaData	*pEntry	= Entry.Add_Child(SG_T("MAP"));
+
+	pEntry->Add_Child(SG_T("NAME"), pMap->Get_Name().c_str());
+	pEntry->Add_Child(SG_T("XMIN"), pMap->Get_Extent().Get_XMin());
+	pEntry->Add_Child(SG_T("XMAX"), pMap->Get_Extent().Get_XMax());
+	pEntry->Add_Child(SG_T("YMIN"), pMap->Get_Extent().Get_YMin());
+	pEntry->Add_Child(SG_T("YMAX"), pMap->Get_Extent().Get_YMax());
+
+	pEntry	= pEntry->Add_Child(SG_T("LAYERS"));
+
+	for(int i=pMap->Get_Count()-1; i>=0; i--)
+	{
+		if( pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_File_Name() != NULL )
+		{
+			pEntry->Add_Child(SG_T("FILE"), Get_FilePath_Relative(ProjectDir, pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_File_Name()).c_str());
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Item * CWKSP_Project::_Get_byFileName(wxString FileName)
+{
+	const wxChar				*s;
+	int							i, j;
+	CWKSP_Table_Manager			*pTables;
+	CWKSP_Shapes_Manager		*pShapes;
+	CWKSP_TIN_Manager			*pTINs;
+	CWKSP_PointCloud_Manager	*pPointClouds;
+	CWKSP_Grid_Manager			*pGrids;
+
+	//-----------------------------------------------------
+	if( FileName.Length() > 0 )
+	{
+		if( (pTables = g_pData->Get_Tables()) != NULL )
+		{
+			for(i=0; i<pTables->Get_Count(); i++)
+			{
+				if( (s = pTables->Get_Table(i)->Get_Table()->Get_File_Name()) && !FileName.Cmp(s) )
+				{
+					return( pTables->Get_Table(i) );
+				}
+			}
+		}
+
+		if( (pShapes = g_pData->Get_Shapes()) != NULL )
+		{
+			for(j=0; j<pShapes->Get_Count(); j++)
+			{
+				for(i=0; i<((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Count(); i++)
+				{
+					if( (s = ((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Shapes(i)->Get_Shapes()->Get_File_Name()) && !FileName.Cmp(s) )
+					{
+						return( ((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Shapes(i) );
+					}
+				}
+			}
+		}
+
+		if( (pTINs = g_pData->Get_TINs()) != NULL )
+		{
+			for(i=0; i<pTINs->Get_Count(); i++)
+			{
+				if( (s = pTINs->Get_TIN(i)->Get_TIN()->Get_File_Name()) && !FileName.Cmp(s) )
+				{
+					return( pTINs->Get_TIN(i) );
+				}
+			}
+		}
+
+		if( (pPointClouds = g_pData->Get_PointClouds()) != NULL )
+		{
+			for(i=0; i<pPointClouds->Get_Count(); i++)
+			{
+				if( (s = pPointClouds->Get_PointCloud(i)->Get_PointCloud()->Get_File_Name()) && !FileName.Cmp(s) )
+				{
+					return( pPointClouds->Get_PointCloud(i) );
+				}
+			}
+		}
+
+		if( (pGrids = g_pData->Get_Grids()) != NULL )
+		{
+			for(j=0; j<pGrids->Get_Count(); j++)
+			{
+				for(i=0; i<pGrids->Get_System(j)->Get_Count(); i++)
+				{
+					if( (s = pGrids->Get_System(j)->Get_Grid(i)->Get_Grid()->Get_File_Name()) && !FileName.Cmp(s) )
+					{
+						return( pGrids->Get_System(j)->Get_Grid(i) );
+					}
+				}
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::Save_Modified(CWKSP_Base_Item *pItem, bool bSelections)
+{
+	CSG_Parameters	Parameters;
+
+	Parameters.Create(this, LNG("[CAP] Close and save modified data sets..."), LNG(""));
+	Parameters.Add_Value(NULL, "SAVE_ALL", LNG("Save all"), LNG(""), PARAMETER_TYPE_Bool, false);
+
+	_Modified_Get(&Parameters, pItem, bSelections);
+
+	if( Parameters.Get_Count() > 1 )
+	{
+		Parameters.Set_Callback_On_Parameter_Changed(&_Modified_Changed);
+
+		if( !DLG_Parameters(&Parameters) )
+		{
+			return( false );
+		}
+
+		_Modified_Save(&Parameters);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+int CWKSP_Project::_Modified_Changed(CSG_Parameter *pParameter)
+{
+	if( pParameter && pParameter->Get_Owner() && pParameter->Get_Owner()->Get_Owner() )
+	{
+		if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("SAVE_ALL")) )
+		{
+			for(int i=0; i<pParameter->Get_Owner()->Get_Count(); i++)
+			{
+				if( pParameter->Get_Owner()->Get_Parameter(i)->Get_Type() == PARAMETER_TYPE_Bool )
+				{
+					pParameter->Get_Owner()->Get_Parameter(i)->Set_Value(pParameter->asBool());
+				}
+			}
+		}
+		else if( pParameter->Get_Type() == PARAMETER_TYPE_Bool && pParameter->asBool() == false )
+		{
+			if( (pParameter = pParameter->Get_Owner()->Get_Parameter("SAVE_ALL")) != NULL )
+			{
+				pParameter->Set_Value(0);
+			}
+		}
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Modified_Get(CSG_Parameters *pParameters, CWKSP_Base_Item *pItem, bool bSelections)
+{
+	int		i;
+
+	if( pItem && pParameters )
+	{
+		switch( pItem->Get_Type() )
+		{
+		default:
+			break;
+
+		//-------------------------------------------------
+		case WKSP_ITEM_Data_Manager:
+		case WKSP_ITEM_Table_Manager:
+		case WKSP_ITEM_Shapes_Manager:
+		case WKSP_ITEM_Shapes_Type:
+		case WKSP_ITEM_TIN_Manager:
+		case WKSP_ITEM_PointCloud_Manager:
+		case WKSP_ITEM_Grid_Manager:
+		case WKSP_ITEM_Grid_System:
+			for(i=0; i<((CWKSP_Base_Manager *)pItem)->Get_Count(); i++)
+			{
+				_Modified_Get(pParameters, ((CWKSP_Base_Manager *)pItem)->Get_Item(i), bSelections && !pItem->is_Selected());
+			}
+			break;
+
+		//-------------------------------------------------
+		case WKSP_ITEM_Table:
+			if( !bSelections || pItem->is_Selected() )
+			{
+				_Modified_Get(pParameters, pItem, ((CWKSP_Table *)pItem)->Get_Table() );
+			}
+			break;
+
+		case WKSP_ITEM_Shapes:
+		case WKSP_ITEM_TIN:
+		case WKSP_ITEM_PointCloud:
+		case WKSP_ITEM_Grid:
+			if( !bSelections || pItem->is_Selected() )
+			{
+				_Modified_Get(pParameters, pItem, ((CWKSP_Layer *)pItem)->Get_Object());
+			}
+			break;
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Modified_Get(CSG_Parameters *pParameters, CWKSP_Base_Item *pItem, CSG_Data_Object *pObject)
+{
+	CSG_Parameter	*pNode, *pParent;
+	wxString		sFilter, sPath;
+
+	if( pObject->is_Modified() )
+	{
+		switch( pItem->Get_Type() )
+		{
+		//-------------------------------------------------
+		default:	return( false );
+		case WKSP_ITEM_Table:		sFilter	= DLG_Get_FILE_Filter(ID_DLG_TABLES_SAVE);		break;
+		case WKSP_ITEM_Shapes:		sFilter	= DLG_Get_FILE_Filter(ID_DLG_SHAPES_SAVE);		break;
+		case WKSP_ITEM_TIN:			sFilter	= DLG_Get_FILE_Filter(ID_DLG_TIN_SAVE);			break;
+		case WKSP_ITEM_PointCloud:	sFilter	= DLG_Get_FILE_Filter(ID_DLG_POINTCLOUD_SAVE);	break;
+		case WKSP_ITEM_Grid:		sFilter	= DLG_Get_FILE_Filter(ID_DLG_GRIDS_SAVE);		break;
+		}
+
+		if( (pParent = pParameters->Get_Parameter(pItem->Get_Manager()->Get_Name())) == NULL )
+		{
+			pParent	= pParameters->Add_Node(NULL, pItem->Get_Manager()->Get_Name(), pItem->Get_Manager()->Get_Name(), wxT(""));
+		}			
+
+		//-------------------------------------------------
+		pNode	= pParameters->Add_Node(
+			pParent,
+			wxString::Format(wxT("%d NODE"), (long)pObject),
+			pItem->Get_Name(), wxT("")
+		);
+
+		pParameters->Add_Value(
+			pNode,
+			wxString::Format(wxT("%d")     , (long)pObject),
+			LNG("[CAP] Save"), wxT(""), PARAMETER_TYPE_Bool, false
+		);
+
+		sPath	= pObject->Get_File_Name();
+		if( sPath.Length() == 0 )
+			sPath	= SG_File_Make_Path(SG_File_Get_Path(Get_File_Name()), pObject->Get_Name(), NULL);
+
+		pParameters->Add_FilePath(
+			pNode,
+			wxString::Format(wxT("%d FILE"), (long)pObject),
+			LNG("[CAP] File"), wxT(""), sFilter, sPath, true
+		);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Modified_Save(CSG_Parameters *pParameters)
+{
+	bool			bSaveAll	= pParameters->Get_Parameter("SAVE_ALL")->asBool();
+	CSG_Data_Object	*pObject;
+	CSG_Parameter	*pParameter, *pPath	= NULL;
+
+	for(int i=0, j=0; i<pParameters->Get_Count(); i++)
+	{
+		pParameter	= pParameters->Get_Parameter(i);
+
+		if(	pParameter->Get_Type() == PARAMETER_TYPE_Bool && (bSaveAll || pParameter->asBool())
+		&&	SG_SSCANF(pParameter->Get_Identifier(), wxT("%d"), (int *)(&pObject)) == 1 && g_pData->Exists(pObject)	)
+		{
+			CSG_String	fPath;
+
+			if(	(pPath = pParameters->Get_Parameter(wxString::Format(wxT("%d FILE"), (long)pObject))) != NULL
+			&&	pPath->asString() != NULL && SG_STR_LEN(pPath->asString()) > 0 )
+			{
+				fPath	= pPath->asString();
+			}
+			else
+			{
+				fPath	= SG_File_Make_Path(SG_File_Get_Path(Get_File_Name()), CSG_String::Format(wxT("%02d_%s"), ++j, pObject->Get_Name()), NULL);
+			}
+
+			pObject->Save(fPath);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//					v2.0 Compatibility					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Compatibility_Load_Data(const CSG_String &FileName)
+{
+	CSG_String	sLine;
+	CSG_File	Stream;
+
+	if( !Stream.Open(FileName, SG_FILE_R, true) )
+	{
+		return( false );
+	}
+
+	//-------------------------------------------------
+	while( Stream.Read_Line(sLine) && sLine.Cmp(DATA_ENTRIES_BEGIN) );
+
+	if( sLine.Cmp(DATA_ENTRIES_BEGIN) )
+	{
+		return( false );
+	}
+
+	g_pData->Get_FileMenus()->Set_Update(false);
+	while( _Compatibility_Load_Data(Stream, SG_File_Get_Path(FileName)) );
+	g_pData->Get_FileMenus()->Set_Update(true);
+
+	//-------------------------------------------------
+	while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRIES_BEGIN) );
+
+	if( !sLine.Cmp(MAP_ENTRIES_BEGIN) )
+	{
+		while( _Compatibility_Load_Map(Stream, SG_File_Get_Path(FileName)) );
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Compatibility_Load_Data(CSG_File &Stream, const wxChar *ProjectDir)
+{
+	int				Type;
+	CSG_String		sLine, sPath;
+	CWKSP_Base_Item	*pItem;
+
+	while( Stream.Read_Line(sLine) && sLine.Cmp(DATA_ENTRY_BEGIN) && sLine.Cmp(DATA_ENTRIES_END) );
+
+	if( !sLine.Cmp(DATA_ENTRY_BEGIN) )
+	{
+		if(	Stream.Read_Line(sPath) && Stream.Read_Line(sLine) && sLine.asInt(Type) )
+		{
+//			if( wxFileExists(sPath.c_str()) || wxFileExists((sPath = Get_FilePath_Absolute(ProjectDir, sPath)).c_str()) )
+			if( wxFileExists((sPath = Get_FilePath_Absolute(ProjectDir, sPath)).c_str()) )
+			{
+				if(	(pItem = g_pData->Open(Type, sPath)) != NULL )
+				{
+					if( pItem->Get_Parameters() )
+					{
+						pItem->Get_Parameters()->Serialize_Compatibility(Stream);
+						pItem->Parameters_Changed();
+					}
+				}
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Project::_Compatibility_Load_Map(CSG_File &Stream, const wxChar *ProjectDir)
+{
+	TSG_Rect		r;
+	CSG_String		sLine, sName;
+	CWKSP_Base_Item	*pItem;
+	CWKSP_Map		*pMap;
+
+	while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRY_BEGIN) && sLine.Cmp(MAP_ENTRIES_END) );
+
+	if( !sLine.Cmp(MAP_ENTRY_BEGIN) && Stream.Read_Line(sLine) )
+	{
+		if(	SG_SSCANF(sLine, wxT("%lf %lf %lf %lf"), &r.xMin, &r.xMax, &r.yMin, &r.yMax) == 4 )
+		{
+			pMap	= NULL;
+
+			while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRY_END) )
+			{
+				if( !sLine.Cmp(MAP_ENTRY_NAME) )
+				{
+					Stream.Read_Line(sName);
+				}
+				else
+				{
+					sLine	= Get_FilePath_Absolute(ProjectDir, sLine).c_str();
+
+					if(	(pItem = _Get_byFileName(sLine.c_str())) != NULL
+					&&	(	pItem->Get_Type()	== WKSP_ITEM_Grid
+						||	pItem->Get_Type()	== WKSP_ITEM_TIN
+						||	pItem->Get_Type()	== WKSP_ITEM_PointCloud
+						||	pItem->Get_Type()	== WKSP_ITEM_Shapes) )
+					{
+						if( pMap == NULL )
+						{
+							pMap	= new CWKSP_Map;
+						}
+
+						g_pMaps->Add((CWKSP_Layer *)pItem, pMap);
+					}
+				}
+			}
+
+			if( pMap )
+			{
+				if( sName.Length() > 0 )
+				{
+					pMap->Get_Parameters()->Get_Parameter("NAME")->Set_Value(sName);
+					pMap->Parameters_Changed();
+				}
+
+				pMap->Set_Extent(r, true);
+				pMap->View_Show(true);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/project.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      Project.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__Project_H
+#define _HEADER_INCLUDED__SAGA_GUI__Project_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Project
+{
+public:
+	CWKSP_Project(void);
+	virtual ~CWKSP_Project(void);
+
+	const wxChar *			Get_File_Name		(void)	{	return( m_File_Name );	}
+	bool					Has_File_Name		(void);
+	bool					Clr_File_Name		(void);
+
+	bool					Load				(bool bAdd);
+	bool					Load				(const wxChar *FileName, bool bAdd, bool bUpdateMenu);
+
+	bool					Save				(void);
+	bool					Save				(bool bSaveAsOnError);
+	bool					Save				(const wxChar *FileName, bool bSaveModified);
+
+	bool					Save_Modified		(class CWKSP_Base_Item *pItem, bool bSelections = false);
+
+
+private:
+
+	wxString				m_File_Name;
+
+	bool					_Set_Project_Name	(void);
+
+	bool					_Load				(const wxChar *FileName, bool bAdd, bool bUpdateMenu);
+	bool					_Save				(const wxChar *FileName, bool bSaveModified, bool bUpdateMenu);
+
+	bool					_Load_Data			(CSG_MetaData &Entry, const wxChar *ProjectDir);
+	bool					_Save_Data			(CSG_MetaData &Entry, const wxChar *ProjectDir, class CSG_Data_Object *pDataObject, class CSG_Parameters *pParameters);
+
+	bool					_Load_Map			(CSG_MetaData &Entry, const wxChar *ProjectDir);
+	bool					_Save_Map			(CSG_MetaData &Entry, const wxChar *ProjectDir, class CWKSP_Map *pMap);
+
+	class CWKSP_Base_Item *	_Get_byFileName		(wxString FileName);
+
+	static int				_Modified_Changed	(class CSG_Parameter  *pParameter);
+	bool					_Modified_Get		(class CSG_Parameters *pParameters, class CWKSP_Base_Item *pItem, bool bSelections);
+	bool					_Modified_Get		(class CSG_Parameters *pParameters, class CWKSP_Base_Item *pItem, class CSG_Data_Object *pObject);
+	bool					_Modified_Save		(class CSG_Parameters *pParameters);
+
+
+	//-----------------------------------------------------
+	bool	_Compatibility_Load_Data	(const CSG_String &FileName);
+	bool	_Compatibility_Load_Data	(CSG_File &Stream, const wxChar *ProjectDir);
+	bool	_Compatibility_Load_Map		(CSG_File &Stream, const wxChar *ProjectDir);
+	//-----------------------------------------------------
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__Project_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,452 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   RES_Commands.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/event.h>
+#include <wx/menu.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_images.h"
+
+#include "saga_frame.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar * CMD_Get_Name(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	case ID_CMD_FRAME_QUIT:				return( LNG("[CMD] Exit") );
+
+	case ID_CMD_FRAME_HELP:				return( LNG("[CMD] Help") );
+	case ID_CMD_FRAME_ABOUT:			return( LNG("[CMD] About SAGA") );
+	case ID_CMD_FRAME_TIPS:				return( LNG("[CMD] Tip of the Day...") );
+
+	case ID_CMD_FRAME_CASCADE:			return( LNG("[CMD] Cascade") );
+	case ID_CMD_FRAME_TILE_HORZ:		return( LNG("[CMD] Tile Horizontally") );
+	case ID_CMD_FRAME_TILE_VERT:		return( LNG("[CMD] Tile Vertically") );
+	case ID_CMD_FRAME_ARRANGEICONS:		return( LNG("[CMD] Arrange Icons") );
+	case ID_CMD_FRAME_NEXT:				return( LNG("[CMD] Next") );
+	case ID_CMD_FRAME_PREVIOUS:			return( LNG("[CMD] Previous") );
+	case ID_CMD_FRAME_CLOSE:			return( LNG("[CMD] Close") );
+	case ID_CMD_FRAME_CLOSE_ALL:		return( LNG("[CMD] Close All") );
+
+	case ID_CMD_FRAME_INFO_SHOW:		return( LNG("[CMD] Show Message Window") );
+	case ID_CMD_FRAME_WKSP_SHOW:		return( LNG("[CMD] Show Workspace") );
+	case ID_CMD_FRAME_ACTIVE_SHOW:		return( LNG("[CMD] Show Object Properties") );
+
+
+	//-----------------------------------------------------
+	// Workspace...
+
+	case ID_CMD_WKSP_ITEM_CLOSE:		return( LNG("[CMD] Close") );
+	case ID_CMD_WKSP_ITEM_SHOW:			return( LNG("[CMD] Show") );
+	case ID_CMD_WKSP_ITEM_SETTINGS_LOAD:return( LNG("[CMD] Load Settings") );
+	case ID_CMD_WKSP_ITEM_SETTINGS_COPY:return( LNG("[CMD] Copy Settings from other Layer") );
+
+	case ID_CMD_WKSP_OPEN:				return( LNG("[CMD] Load") );
+
+	case ID_CMD_INFO_CLEAR:				return( LNG("[CMD] Clear") );
+	case ID_CMD_INFO_COPY:				return( LNG("[CMD] Copy") );
+
+	case ID_CMD_MODULES_OPEN:			return( LNG("[CMD] Load Module Library") );
+	case ID_CMD_MODULES_SAVE_HTML:		return( LNG("[CMD] Create HTML Documentation") );
+	case ID_CMD_MODULES_SAVE_SCRIPT:	return( LNG("[CMD] Create Script Command File") );
+
+	case ID_CMD_DATA_PROJECT_NEW:		return( LNG("[CMD] New Project") );
+	case ID_CMD_DATA_PROJECT_OPEN:		return( LNG("[CMD] Load Project") );
+	case ID_CMD_DATA_PROJECT_OPEN_ADD:	return( LNG("[CMD] Add Project") );
+	case ID_CMD_DATA_PROJECT_SAVE:		return( LNG("[CMD] Save Project") );
+	case ID_CMD_DATA_PROJECT_SAVE_AS:	return( LNG("[CMD] Save Project As...") );
+
+	case ID_CMD_GRIDS_OPEN:				return( LNG("[CMD] Load Grid") );
+	case ID_CMD_GRIDS_SAVE:				return( LNG("[CMD] Save Grid") );
+	case ID_CMD_GRIDS_SAVEAS:			return( LNG("[CMD] Save Grid As...") );
+	case ID_CMD_GRIDS_SAVEAS_IMAGE:		return( LNG("[CMD] Save Grid As Image...") );
+	case ID_CMD_GRIDS_SHOW:				return( LNG("[CMD] Show Grid") );
+	case ID_CMD_GRIDS_HISTOGRAM:		return( LNG("[CMD] Show Histogram") );
+	case ID_CMD_GRIDS_SCATTERPLOT:		return( LNG("[CMD] Show Scatterplot") );
+	case ID_CMD_GRIDS_EQUALINTERVALS:	return( LNG("[CMD] Create Normalised Classification") );
+	case ID_CMD_GRIDS_RANGE_MINMAX:		return( LNG("[CMD] Set Range to Minmum/Maximum") );
+	case ID_CMD_GRIDS_RANGE_STDDEV150:	return( LNG("[CMD] Set Range to Standard Deviation (1.5)") );
+	case ID_CMD_GRIDS_RANGE_STDDEV200:	return( LNG("[CMD] Set Range to Standard Deviation (2.0)") );
+	case ID_CMD_GRIDS_SET_LUT:			return( LNG("[CMD] Create Lookup Table") );
+
+	case ID_CMD_SHAPES_OPEN:			return( LNG("[CMD] Load Shapes") );
+	case ID_CMD_SHAPES_SAVE:			return( LNG("[CMD] Save Shapes") );
+	case ID_CMD_SHAPES_SAVEAS:			return( LNG("[CMD] Save Shapes As...") );
+	case ID_CMD_SHAPES_SHOW:			return( LNG("[CMD] Show Shapes") );
+	case ID_CMD_SHAPES_HISTOGRAM:		return( LNG("[CMD] Show Histogram") );
+	case ID_CMD_SHAPES_SET_LUT:			return( LNG("[CMD] Create Lookup Table") );
+	case ID_CMD_SHAPES_EDIT_SHAPE:		return( LNG("[CMD] Edit Selected Shape") );
+	case ID_CMD_SHAPES_EDIT_SEL_INVERT:	return( LNG("[CMD] Invert Selection") );
+	case ID_CMD_SHAPES_EDIT_ADD_SHAPE:	return( LNG("[CMD] Add Shape") );
+	case ID_CMD_SHAPES_EDIT_ADD_PART:	return( LNG("[CMD] Add Part") );
+	case ID_CMD_SHAPES_EDIT_DEL_SHAPE:	return( LNG("[CMD] Delete Selected Shape(s)") );
+	case ID_CMD_SHAPES_EDIT_DEL_PART:	return( LNG("[CMD] Delete Selected Part") );
+	case ID_CMD_SHAPES_EDIT_DEL_POINT:	return( LNG("[CMD] Delete Selected Point") );
+
+	case ID_CMD_TABLES_OPEN:			return( LNG("[CMD] Load Table") );
+	case ID_CMD_TABLES_SAVE:			return( LNG("[CMD] Save Table") );
+	case ID_CMD_TABLES_SAVEAS:			return( LNG("[CMD] Save Table As...") );
+	case ID_CMD_TABLES_SHOW:			return( LNG("[CMD] Show Table") );
+	case ID_CMD_TABLES_DIAGRAM:			return( LNG("[CMD] Show Diagram") );
+	case ID_CMD_TABLES_SCATTERPLOT:		return( LNG("[CMD] Show Scatterplot") );
+
+	case ID_CMD_TIN_OPEN:				return( LNG("[CMD] Load TIN") );
+	case ID_CMD_TIN_SAVE:				return( LNG("[CMD] Save TIN") );
+	case ID_CMD_TIN_SAVEAS:				return( LNG("[CMD] Save TIN As...") );
+	case ID_CMD_TIN_SHOW:				return( LNG("[CMD] Show TIN") );
+
+	case ID_CMD_POINTCLOUD_OPEN:		return( LNG("[CMD] Load Point Cloud") );
+	case ID_CMD_POINTCLOUD_SAVE:		return( LNG("[CMD] Save Point Cloud") );
+	case ID_CMD_POINTCLOUD_SAVEAS:		return( LNG("[CMD] Save Point Cloud As...") );
+	case ID_CMD_POINTCLOUD_SHOW:		return( LNG("[CMD] Show Point Cloud") );
+
+	case ID_CMD_MAP_3D_SHOW:
+	case ID_CMD_MAPS_3D_SHOW:			return( LNG("[CMD] Show 3D-View") );
+	case ID_CMD_MAP_LAYOUT_SHOW:
+	case ID_CMD_MAPS_LAYOUT_SHOW:		return( LNG("[CMD] Show Print Layout") );
+	case ID_CMD_MAP_SAVE_IMAGE_ON_CHANGE:
+	case ID_CMD_MAPS_SAVE_IMAGE_ON_CHANGE:	return( LNG("[CMD] Save As Image when changed") );
+	case ID_CMD_MAP_SAVE_IMAGE:
+	case ID_CMD_MAPS_SAVE_IMAGE:		return( LNG("[CMD] Save As Image...") );
+	case ID_CMD_MAPS_SAVE_TO_CLIPBOARD:	return( LNG("[CMD] Save to Clipboard [Ctrl+C]") );
+	case ID_CMD_MAPS_SAVE_TO_CLIPBOARD_LEGEND:	return( LNG("[CMD] Save Legend to Clipboard [Ctrl+L]") );
+	case ID_CMD_MAP_SAVE_PDF_INDEXED:
+	case ID_CMD_MAPS_SAVE_PDF_INDEXED:	return( LNG("[CMD] Save As PDF") );
+	case ID_CMD_MAP_SAVE_INTERACTIVE_SVG:
+	case ID_CMD_MAPS_SAVE_INTERACTIVE_SVG:	return( LNG("[CMD] Save as Interactive SVG") );
+	case ID_CMD_MAP_SYNCHRONIZE:
+	case ID_CMD_MAPS_SYNCHRONIZE:		return( LNG("[CMD] Synchronise Map Extents") );
+
+	case ID_CMD_MAPS_SHOW:				return( LNG("[CMD] Show Map") );
+	case ID_CMD_MAPS_LAYER_SHOW:		return( LNG("[CMD] Show Layer") );
+	case ID_CMD_MAPS_MOVE_TOP:			return( LNG("[CMD] Move To Top") );
+	case ID_CMD_MAPS_MOVE_BOTTOM:		return( LNG("[CMD] Move To Bottom") );
+	case ID_CMD_MAPS_MOVE_UP:			return( LNG("[CMD] Move Up") );
+	case ID_CMD_MAPS_MOVE_DOWN:			return( LNG("[CMD] Move Down") );
+	case ID_CMD_MAPS_GRID_FITCOLORS:	return( LNG("[CMD] Fit Grid Colors To Map Extent") );
+
+	//-----------------------------------------------------
+	// Views...
+
+	case ID_CMD_MAP_MODE_ZOOM:			return( LNG("[CMD] Zoom") );
+	case ID_CMD_MAP_MODE_PAN:			return( LNG("[CMD] Pan") );
+	case ID_CMD_MAP_MODE_SELECT:		return( LNG("[CMD] Action") );
+	case ID_CMD_MAP_MODE_DISTANCE:		return( LNG("[CMD] Measure Distance") );
+	case ID_CMD_MAP_CLOSE:				return( LNG("[CMD] Close") );
+	case ID_CMD_MAP_TOOLBAR:			return( LNG("[CMD] Show Toolbar") );
+	case ID_CMD_MAP_LEGEND_VERTICAL:	return( LNG("[CMD] Show Vertical Legend") );
+	case ID_CMD_MAP_LEGEND_HORIZONTAL:	return( LNG("[CMD] Show Horizontal Legend") );
+	case ID_CMD_MAP_ZOOM_BACK:			return( LNG("[CMD] Zoom To Previous Extent") );
+	case ID_CMD_MAP_ZOOM_FORWARD:		return( LNG("[CMD] Zoom To Next Extent") );
+	case ID_CMD_MAP_ZOOM_FULL:			return( LNG("[CMD] Zoom To Full Extent") );
+	case ID_CMD_MAP_ZOOM_ACTIVE:		return( LNG("[CMD] Zoom To Active Layer") );
+	case ID_CMD_MAP_ZOOM_SELECTION:		return( LNG("[CMD] Zoom To Selection") );
+	case ID_CMD_MAP_ZOOM_EXTENT:		return( LNG("[CMD] Zoom To Extent") );
+
+	case ID_CMD_MAP3D_PARAMETERS:		return( LNG("[CMD] Properties") );
+	case ID_CMD_MAP3D_ROTATE_X_LESS:	return( LNG("[CMD] Up") );
+	case ID_CMD_MAP3D_ROTATE_X_MORE:	return( LNG("[CMD] Down") );
+	case ID_CMD_MAP3D_ROTATE_Y_LESS:	return( LNG("[CMD] Left [F3]") );
+	case ID_CMD_MAP3D_ROTATE_Y_MORE:	return( LNG("[CMD] Right [F4]") );
+	case ID_CMD_MAP3D_ROTATE_Z_LESS:	return( LNG("[CMD] Left") );
+	case ID_CMD_MAP3D_ROTATE_Z_MORE:	return( LNG("[CMD] Right") );
+	case ID_CMD_MAP3D_SHIFT_X_LESS:		return( LNG("[CMD] Left") );
+	case ID_CMD_MAP3D_SHIFT_X_MORE:		return( LNG("[CMD] Right") );
+	case ID_CMD_MAP3D_SHIFT_Y_LESS:		return( LNG("[CMD] Down") );
+	case ID_CMD_MAP3D_SHIFT_Y_MORE:		return( LNG("[CMD] Up") );
+	case ID_CMD_MAP3D_SHIFT_Z_LESS:		return( LNG("[CMD] Forward") );
+	case ID_CMD_MAP3D_SHIFT_Z_MORE:		return( LNG("[CMD] Backward") );
+	case ID_CMD_MAP3D_EXAGGERATE_LESS:	return( LNG("[CMD] Decrease Exaggeration [F1]") );
+	case ID_CMD_MAP3D_EXAGGERATE_MORE:	return( LNG("[CMD] Increase Exaggeration [F2]") );
+	case ID_CMD_MAP3D_CENTRAL_LESS:		return( LNG("[CMD] Decrease Perspectivic Distance [F5]") );
+	case ID_CMD_MAP3D_CENTRAL_MORE:		return( LNG("[CMD] Increase Perspectivic Distance [F6]") );
+	case ID_CMD_MAP3D_CENTRAL:			return( LNG("[CMD] Central Projection") );
+	case ID_CMD_MAP3D_STEREO_LESS:		return( LNG("[CMD] Decrease Eye Distance") );
+	case ID_CMD_MAP3D_STEREO_MORE:		return( LNG("[CMD] Increase Eye Distance") );
+	case ID_CMD_MAP3D_STEREO:			return( LNG("[CMD] Anaglyph [S]") );
+	case ID_CMD_MAP3D_INTERPOLATED:		return( LNG("[CMD] Interpolated Colors") );
+	case ID_CMD_MAP3D_SAVE:				return( LNG("[CMD] Save As Image...") );
+	case ID_CMD_MAP3D_SEQ_POS_ADD:		return( LNG("[CMD] Add Position [A]") );
+	case ID_CMD_MAP3D_SEQ_POS_DEL:		return( LNG("[CMD] Delete Last Position [D]") );
+	case ID_CMD_MAP3D_SEQ_POS_DEL_ALL:	return( LNG("[CMD] Delete All Positions") );
+	case ID_CMD_MAP3D_SEQ_POS_EDIT:		return( LNG("[CMD] Edit Positions") );
+	case ID_CMD_MAP3D_SEQ_PLAY:			return( LNG("[CMD] Play Once [P]") );
+	case ID_CMD_MAP3D_SEQ_PLAY_LOOP:	return( LNG("[CMD] Play Loop [L]") );
+	case ID_CMD_MAP3D_SEQ_SAVE:			return( LNG("[CMD] Play And Save As Images...") );
+
+	case ID_CMD_LAYOUT_PRINT_SETUP:		return( LNG("[CMD] Print Setup") );
+	case ID_CMD_LAYOUT_PAGE_SETUP:		return( LNG("[CMD] Page Setup") );
+	case ID_CMD_LAYOUT_PRINT:			return( LNG("[CMD] Print") );
+	case ID_CMD_LAYOUT_PRINT_PREVIEW:	return( LNG("[CMD] Print Preview") );
+	case ID_CMD_LAYOUT_FIT_SCALE:		return( LNG("[CMD] Fit Scale...") );
+
+	case ID_CMD_TABLE_FIELD_ADD:		return( LNG("[CMD] Add Field") );
+	case ID_CMD_TABLE_FIELD_DEL:		return( LNG("[CMD] Delete Fields") );
+	case ID_CMD_TABLE_FIELD_SORT:		return( LNG("[CMD] Sort Fields") );
+	case ID_CMD_TABLE_FIELD_RENAME:		return( LNG("[CMD] Rename Fields") );
+	case ID_CMD_TABLE_RECORD_ADD:		return( LNG("[CMD] Add Record") );
+	case ID_CMD_TABLE_RECORD_INS:		return( LNG("[CMD] Insert Record") );
+	case ID_CMD_TABLE_RECORD_DEL:		return( LNG("[CMD] Delete Selected Record(s)") );
+	case ID_CMD_TABLE_RECORD_DEL_ALL:	return( LNG("[CMD] Delete All Records") );
+	case ID_CMD_TABLE_AUTOSIZE_COLS:	return( LNG("[CMD] Fit Column Sizes") );
+	case ID_CMD_TABLE_AUTOSIZE_ROWS:	return( LNG("[CMD] Fit Row Sizes") );
+
+	case ID_CMD_DIAGRAM_PARAMETERS:		return( LNG("[CMD] Properties") );
+	case ID_CMD_DIAGRAM_SIZE_FIT:		return( LNG("[CMD] Fit Diagram to Window") );
+	case ID_CMD_DIAGRAM_SIZE_INC:		return( LNG("[CMD] Increase Diagram Size") );
+	case ID_CMD_DIAGRAM_SIZE_DEC:		return( LNG("[CMD] Decrease Diagram Size") );
+
+	case ID_CMD_SCATTERPLOT_PARAMETERS:	return( LNG("[CMD] Properties") );
+	case ID_CMD_SCATTERPLOT_UPDATE:		return( LNG("[CMD] Update Data") );
+
+	case ID_CMD_HISTOGRAM_CUMULATIVE:	return( LNG("[CMD] Cumulative") );
+	case ID_CMD_HISTOGRAM_AS_TABLE:		return( LNG("[CMD] Convert To Table") );
+	}
+
+	//-----------------------------------------------------
+	return( LNG("[CMD] UNRECOGNISED COMMAND ID") );
+}
+
+//---------------------------------------------------------
+const wxChar * CMD_Get_Help(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	case ID_CMD_FRAME_QUIT:				return( LNG("[CMD] Exit SAGA") );
+	case ID_CMD_FRAME_ABOUT:			return( LNG("[CMD] About SAGA") );
+	}
+
+	return( CMD_Get_Name(Cmd_ID) );
+}
+
+//---------------------------------------------------------
+int CMD_Get_ImageID(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	case ID_CMD_FRAME_WKSP_SHOW:		return( ID_IMG_TB_WKSP );
+	case ID_CMD_FRAME_INFO_SHOW:		return( ID_IMG_TB_INFO );
+	case ID_CMD_FRAME_ACTIVE_SHOW:		return( ID_IMG_TB_ACTIVE );
+	case ID_CMD_FRAME_HELP:				return( ID_IMG_TB_HELP );
+	case ID_CMD_WKSP_OPEN:				return( ID_IMG_TB_OPEN );
+	case ID_CMD_MODULES_OPEN:			return( ID_IMG_TB_OPEN_MODULE );
+	case ID_CMD_TABLES_OPEN:			return( ID_IMG_TB_OPEN_TABLE );
+	case ID_CMD_SHAPES_OPEN:			return( ID_IMG_TB_OPEN_SHAPES );
+	case ID_CMD_GRIDS_OPEN:				return( ID_IMG_TB_OPEN_GRID );
+	case ID_CMD_TIN_OPEN:				return( ID_IMG_TB_OPEN_TIN );
+	case ID_CMD_POINTCLOUD_OPEN:		return( ID_IMG_TB_OPEN_POINTCLOUD );
+
+	case ID_CMD_MAP_MODE_DISTANCE:		return( ID_IMG_TB_MAP_MODE_DISTANCE );
+	case ID_CMD_MAP_MODE_SELECT:		return( ID_IMG_TB_MAP_MODE_SELECT );
+	case ID_CMD_MAP_MODE_ZOOM:			return( ID_IMG_TB_MAP_MODE_ZOOM );
+	case ID_CMD_MAP_MODE_PAN:			return( ID_IMG_TB_MAP_MODE_PAN );
+	case ID_CMD_MAP_ZOOM_FULL:			return( ID_IMG_TB_MAP_ZOOM_FULL );
+	case ID_CMD_MAP_ZOOM_BACK:			return( ID_IMG_TB_MAP_ZOOM_LAST );
+	case ID_CMD_MAP_ZOOM_FORWARD:		return( ID_IMG_TB_MAP_ZOOM_NEXT );
+	case ID_CMD_MAP_ZOOM_ACTIVE:		return( ID_IMG_TB_MAP_ZOOM_ACTIVE );
+	case ID_CMD_MAP_ZOOM_SELECTION:		return( ID_IMG_TB_MAP_ZOOM_SELECTION );
+	case ID_CMD_MAP_ZOOM_EXTENT:		return( ID_IMG_TB_MAP_ZOOM_SELECTION );
+	case ID_CMD_MAP_3D_SHOW:			return( ID_IMG_TB_MAP_3D_SHOW );
+	case ID_CMD_MAPS_3D_SHOW:			return( ID_IMG_TB_MAP_3D_SHOW );
+	case ID_CMD_MAP_LAYOUT_SHOW:		return( ID_IMG_TB_MAP_LAYOUT_SHOW );
+	case ID_CMD_MAPS_LAYOUT_SHOW:		return( ID_IMG_TB_MAP_LAYOUT_SHOW );
+	case ID_CMD_MAPS_SAVE_TO_CLIPBOARD:
+	case ID_CMD_MAPS_SAVE_TO_CLIPBOARD_LEGEND:
+	case ID_CMD_MAPS_SAVE_IMAGE:
+	case ID_CMD_MAPS_SYNCHRONIZE:		return( ID_IMG_TB_MAP_SYNCHRONIZE );
+	case ID_CMD_MAP_LEGEND_VERTICAL:	return( ID_IMG_TB_MAP_LEGEND_VERTICAL );
+	case ID_CMD_MAP_LEGEND_HORIZONTAL:	return( ID_IMG_TB_MAP_LEGEND_HORIZONTAL );
+
+	case ID_CMD_MAP3D_PARAMETERS:		return( ID_IMG_TB_MAP3D_PROPERTIES );
+	case ID_CMD_MAP3D_CENTRAL_LESS:		return( ID_IMG_TB_MAP3D_CENTRAL_LESS );
+	case ID_CMD_MAP3D_CENTRAL_MORE:		return( ID_IMG_TB_MAP3D_CENTRAL_MORE );
+	case ID_CMD_MAP3D_EXAGGERATE_LESS:	return( ID_IMG_TB_MAP3D_EXAGGERATE_LESS );
+	case ID_CMD_MAP3D_EXAGGERATE_MORE:	return( ID_IMG_TB_MAP3D_EXAGGERATE_MORE );
+	case ID_CMD_MAP3D_INTERPOLATED:		return( ID_IMG_TB_MAP3D_INTERPOLATED );
+	case ID_CMD_MAP3D_ROTATE_X_LESS:	return( ID_IMG_TB_MAP3D_ROTATE_X_LESS );
+	case ID_CMD_MAP3D_ROTATE_X_MORE:	return( ID_IMG_TB_MAP3D_ROTATE_X_MORE );
+	case ID_CMD_MAP3D_ROTATE_Z_LESS:	return( ID_IMG_TB_MAP3D_ROTATE_Z_LESS );
+	case ID_CMD_MAP3D_ROTATE_Z_MORE:	return( ID_IMG_TB_MAP3D_ROTATE_Z_MORE );
+	case ID_CMD_MAP3D_SHIFT_X_LESS:		return( ID_IMG_TB_MAP3D_SHIFT_X_LESS );
+	case ID_CMD_MAP3D_SHIFT_X_MORE:		return( ID_IMG_TB_MAP3D_SHIFT_X_MORE );
+	case ID_CMD_MAP3D_SHIFT_Y_LESS:		return( ID_IMG_TB_MAP3D_SHIFT_Y_LESS );
+	case ID_CMD_MAP3D_SHIFT_Y_MORE:		return( ID_IMG_TB_MAP3D_SHIFT_Y_MORE );
+	case ID_CMD_MAP3D_SHIFT_Z_LESS:		return( ID_IMG_TB_MAP3D_SHIFT_Z_LESS );
+	case ID_CMD_MAP3D_SHIFT_Z_MORE:		return( ID_IMG_TB_MAP3D_SHIFT_Z_MORE );
+	case ID_CMD_MAP3D_STEREO:			return( ID_IMG_TB_MAP3D_STEREO );
+
+	case ID_CMD_LAYOUT_PRINT_SETUP:		return( ID_IMG_TB_LAYOUT_PRINT_SETUP );
+	case ID_CMD_LAYOUT_PAGE_SETUP:		return( ID_IMG_TB_LAYOUT_PAGE_SETUP );
+	case ID_CMD_LAYOUT_PRINT:			return( ID_IMG_TB_LAYOUT_PRINT );
+	case ID_CMD_LAYOUT_PRINT_PREVIEW:	return( ID_IMG_TB_LAYOUT_PRINT_PREVIEW );
+
+	case ID_CMD_HISTOGRAM_CUMULATIVE:	return( ID_IMG_TB_HISTOGRAM_CUMULATIVE );
+	case ID_CMD_HISTOGRAM_AS_TABLE:		return( ID_IMG_TB_HISTOGRAM_AS_TABLE );
+
+	case ID_CMD_TABLE_FIELD_ADD:		return( ID_IMG_TB_TABLE_COL_ADD );
+	case ID_CMD_TABLE_FIELD_DEL:		return( ID_IMG_TB_TABLE_COL_DEL );
+	case ID_CMD_TABLE_RECORD_ADD:		return( ID_IMG_TB_TABLE_ROW_ADD );
+	case ID_CMD_TABLE_RECORD_INS:		return( ID_IMG_TB_TABLE_ROW_INS );
+	case ID_CMD_TABLE_RECORD_DEL:		return( ID_IMG_TB_TABLE_ROW_DEL );
+	case ID_CMD_TABLE_RECORD_DEL_ALL:	return( ID_IMG_TB_TABLE_ROW_DEL_ALL );
+
+	case ID_CMD_SCATTERPLOT_PARAMETERS:	return( ID_IMG_TB_SCATTERPLOT_PARAMETERS );
+	case ID_CMD_SCATTERPLOT_UPDATE:		return( ID_IMG_DEFAULT );
+
+	case ID_CMD_DIAGRAM_PARAMETERS:		return( ID_IMG_TB_DIAGRAM_PARAMETERS );
+	case ID_CMD_DIAGRAM_SIZE_FIT:		break;
+	case ID_CMD_DIAGRAM_SIZE_INC:		return( ID_IMG_TB_MAP3D_CENTRAL_MORE );
+	case ID_CMD_DIAGRAM_SIZE_DEC:		return( ID_IMG_TB_MAP3D_CENTRAL_LESS );
+	}
+
+	return( ID_IMG_DEFAULT );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CMD_Menu_Add_Item(wxMenu *pMenu, bool bCheck, int Cmd_ID)
+{
+	if( bCheck )
+	{
+		pMenu->AppendCheckItem(Cmd_ID, CMD_Get_Name(Cmd_ID), CMD_Get_Help(Cmd_ID));
+	}
+	else
+	{
+		pMenu->Append         (Cmd_ID, CMD_Get_Name(Cmd_ID), CMD_Get_Help(Cmd_ID));
+	}
+}
+
+//---------------------------------------------------------
+void CMD_Menu_Ins_Item(wxMenu *pMenu, bool bCheck, int Cmd_ID, int Position)
+{
+	if( bCheck )
+	{
+		pMenu->InsertCheckItem(Position, Cmd_ID, CMD_Get_Name(Cmd_ID), CMD_Get_Help(Cmd_ID));
+	}
+	else
+	{
+		pMenu->Insert         (Position, Cmd_ID, CMD_Get_Name(Cmd_ID), CMD_Get_Help(Cmd_ID));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxToolBarBase * CMD_ToolBar_Create(int ID)
+{
+	return( g_pSAGA_Frame ? g_pSAGA_Frame->TB_Create(ID) : NULL );
+}
+
+//---------------------------------------------------------
+void CMD_ToolBar_Add(wxToolBarBase *pToolBar, const wxChar *Name)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->TB_Add(pToolBar, Name);
+	}
+}
+
+//---------------------------------------------------------
+void CMD_ToolBar_Add_Item(wxToolBarBase *pToolBar, bool bCheck, int Cmd_ID)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->TB_Add_Item(pToolBar, bCheck, Cmd_ID);
+	}
+}
+
+//---------------------------------------------------------
+void CMD_ToolBar_Add_Separator(wxToolBarBase *pToolBar)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->TB_Add_Separator(pToolBar);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_commands.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,371 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    RES_Commands.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Commands_H
+#define _HEADER_INCLUDED__SAGA_GUI__RES_Commands_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/event.h>
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define RECENT_COUNT				7
+
+//---------------------------------------------------------
+enum ID_COMMANDS
+{
+	ID_CMD_FIRST					= wxID_HIGHEST + 1000,
+
+	ID_CMD_FRAME_CASCADE,
+	ID_CMD_FRAME_TILE_HORZ,
+	ID_CMD_FRAME_TILE_VERT,
+	ID_CMD_FRAME_ARRANGEICONS,
+	ID_CMD_FRAME_NEXT,
+	ID_CMD_FRAME_PREVIOUS,
+	ID_CMD_FRAME_CLOSE,
+	ID_CMD_FRAME_CLOSE_ALL,
+
+	ID_CMD_FRAME_QUIT,
+	ID_CMD_FRAME_HELP,
+	ID_CMD_FRAME_ABOUT,
+	ID_CMD_FRAME_TIPS,
+
+	ID_CMD_FRAME_INFO_SHOW,
+	ID_CMD_FRAME_WKSP_SHOW,
+	ID_CMD_FRAME_ACTIVE_SHOW,
+
+	//-----------------------------------------------------
+	ID_CMD_WKSP_FIRST,
+	ID_CMD_WKSP_OPEN,
+	ID_CMD_WKSP_ITEM_RETURN,
+	ID_CMD_WKSP_ITEM_CLOSE,
+	ID_CMD_WKSP_ITEM_SETTINGS_LOAD,
+	ID_CMD_WKSP_ITEM_SETTINGS_COPY,
+	ID_CMD_WKSP_ITEM_SHOW,
+
+	ID_CMD_INFO_CLEAR,
+	ID_CMD_INFO_COPY,
+
+	ID_CMD_MODULES_FIRST,
+	ID_CMD_MODULES_RECENT_FIRST,
+	ID_CMD_MODULES_RECENT_LAST		= RECENT_COUNT + ID_CMD_MODULES_RECENT_FIRST,
+	ID_CMD_MODULES_OPEN,
+	ID_CMD_MODULES_SAVE_HTML,
+	ID_CMD_MODULES_SAVE_SCRIPT,
+	ID_CMD_MODULES_LAST,
+
+	ID_CMD_DATA_FIRST,
+	ID_CMD_DATA_PROJECT_RECENT_FIRST,
+	ID_CMD_DATA_PROJECT_RECENT_LAST	= RECENT_COUNT + ID_CMD_DATA_PROJECT_RECENT_FIRST,
+	ID_CMD_DATA_PROJECT_NEW,
+	ID_CMD_DATA_PROJECT_OPEN,
+	ID_CMD_DATA_PROJECT_OPEN_ADD,
+	ID_CMD_DATA_PROJECT_SAVE,
+	ID_CMD_DATA_PROJECT_SAVE_AS,
+	ID_CMD_DATA_LAST,
+
+	ID_CMD_GRIDS_FIRST,
+	ID_CMD_GRIDS_RECENT_FIRST,
+	ID_CMD_GRIDS_RECENT_LAST		= RECENT_COUNT + ID_CMD_GRIDS_RECENT_FIRST,
+	ID_CMD_GRIDS_OPEN,
+	ID_CMD_GRIDS_SAVE,
+	ID_CMD_GRIDS_SAVEAS,
+	ID_CMD_GRIDS_SAVEAS_IMAGE,
+	ID_CMD_GRIDS_SHOW,
+	ID_CMD_GRIDS_HISTOGRAM,
+	ID_CMD_GRIDS_SCATTERPLOT,
+	ID_CMD_GRIDS_EQUALINTERVALS,
+	ID_CMD_GRIDS_RANGE_MINMAX,
+	ID_CMD_GRIDS_RANGE_STDDEV150,
+	ID_CMD_GRIDS_RANGE_STDDEV200,
+	ID_CMD_GRIDS_SET_LUT,
+	ID_CMD_GRIDS_LAST,
+
+	ID_CMD_SHAPES_FIRST,
+	ID_CMD_SHAPES_RECENT_FIRST,
+	ID_CMD_SHAPES_RECENT_LAST		= RECENT_COUNT + ID_CMD_SHAPES_RECENT_FIRST,
+	ID_CMD_SHAPES_OPEN,
+	ID_CMD_SHAPES_SAVE,
+	ID_CMD_SHAPES_SAVEAS,
+	ID_CMD_SHAPES_SHOW,
+	ID_CMD_SHAPES_HISTOGRAM,
+	ID_CMD_SHAPES_RANGE_MINMAX,
+	ID_CMD_SHAPES_RANGE_STDDEV150,
+	ID_CMD_SHAPES_RANGE_STDDEV200,
+	ID_CMD_SHAPES_SET_LUT,
+	ID_CMD_SHAPES_EDIT_SHAPE,
+	ID_CMD_SHAPES_EDIT_SEL_INVERT,
+	ID_CMD_SHAPES_EDIT_ADD_SHAPE,
+	ID_CMD_SHAPES_EDIT_ADD_PART,
+	ID_CMD_SHAPES_EDIT_DEL_SHAPE,
+	ID_CMD_SHAPES_EDIT_DEL_PART,
+	ID_CMD_SHAPES_EDIT_DEL_POINT,
+	ID_CMD_SHAPES_LAST,
+
+	ID_CMD_TABLES_FIRST,
+	ID_CMD_TABLES_RECENT_FIRST,
+	ID_CMD_TABLES_RECENT_LAST		= RECENT_COUNT + ID_CMD_TABLES_RECENT_FIRST,
+	ID_CMD_TABLES_OPEN,
+	ID_CMD_TABLES_SAVE,
+	ID_CMD_TABLES_SAVEAS,
+	ID_CMD_TABLES_SHOW,
+	ID_CMD_TABLES_DIAGRAM,
+	ID_CMD_TABLES_SCATTERPLOT,
+	ID_CMD_TABLES_LAST,
+
+	ID_CMD_TIN_FIRST,
+	ID_CMD_TIN_RECENT_FIRST,
+	ID_CMD_TIN_RECENT_LAST			= RECENT_COUNT + ID_CMD_TIN_RECENT_FIRST,
+	ID_CMD_TIN_OPEN,
+	ID_CMD_TIN_SAVE,
+	ID_CMD_TIN_SAVEAS,
+	ID_CMD_TIN_SHOW,
+	ID_CMD_TIN_LAST,
+
+	ID_CMD_POINTCLOUD_FIRST,
+	ID_CMD_POINTCLOUD_RECENT_FIRST,
+	ID_CMD_POINTCLOUD_RECENT_LAST	= RECENT_COUNT + ID_CMD_POINTCLOUD_RECENT_FIRST,
+	ID_CMD_POINTCLOUD_OPEN,
+	ID_CMD_POINTCLOUD_SAVE,
+	ID_CMD_POINTCLOUD_SAVEAS,
+	ID_CMD_POINTCLOUD_SHOW,
+	ID_CMD_POINTCLOUD_RANGE_MINMAX,
+	ID_CMD_POINTCLOUD_RANGE_STDDEV150,
+	ID_CMD_POINTCLOUD_RANGE_STDDEV200,
+	ID_CMD_POINTCLOUD_LAST,
+
+	ID_CMD_MAPS_FIRST,
+	ID_CMD_MAPS_SHOW,
+	ID_CMD_MAPS_3D_SHOW,
+	ID_CMD_MAPS_LAYOUT_SHOW,
+	ID_CMD_MAPS_SAVE_IMAGE,
+	ID_CMD_MAPS_SAVE_TO_CLIPBOARD,
+	ID_CMD_MAPS_SAVE_TO_CLIPBOARD_LEGEND,
+	ID_CMD_MAPS_SAVE_IMAGE_ON_CHANGE,
+	ID_CMD_MAPS_SAVE_PDF_INDEXED,
+	ID_CMD_MAPS_SAVE_INTERACTIVE_SVG,
+	ID_CMD_MAPS_SYNCHRONIZE,
+	ID_CMD_MAPS_LAYER_SHOW,
+	ID_CMD_MAPS_MOVE_TOP,
+	ID_CMD_MAPS_MOVE_BOTTOM,
+	ID_CMD_MAPS_MOVE_UP,
+	ID_CMD_MAPS_MOVE_DOWN,
+	ID_CMD_MAPS_GRID_FITCOLORS,
+	ID_CMD_MAPS_LAST,
+
+	ID_CMD_WKSP_LAST,
+
+	//-----------------------------------------------------
+	ID_CMD_CHILD_FIRST,
+
+	ID_CMD_MAP_FIRST,
+	ID_CMD_MAP_CLOSE,
+	ID_CMD_MAP_TOOLBAR,
+	ID_CMD_MAP_3D_SHOW,
+	ID_CMD_MAP_LAYOUT_SHOW,
+	ID_CMD_MAP_SAVE_IMAGE,
+	ID_CMD_MAP_SAVE_IMAGE_ON_CHANGE,
+	ID_CMD_MAP_SAVE_PDF_INDEXED,
+	ID_CMD_MAP_SAVE_INTERACTIVE_SVG,
+	ID_CMD_MAP_SYNCHRONIZE,
+	ID_CMD_MAP_LEGEND_VERTICAL,
+	ID_CMD_MAP_LEGEND_HORIZONTAL,
+	ID_CMD_MAP_ZOOM_FULL,
+	ID_CMD_MAP_ZOOM_BACK,
+	ID_CMD_MAP_ZOOM_FORWARD,
+	ID_CMD_MAP_ZOOM_ACTIVE,
+	ID_CMD_MAP_ZOOM_SELECTION,
+	ID_CMD_MAP_ZOOM_EXTENT,
+	ID_CMD_MAP_MODE_ZOOM,
+	ID_CMD_MAP_MODE_PAN,
+	ID_CMD_MAP_MODE_SELECT,
+	ID_CMD_MAP_MODE_DISTANCE,
+	ID_CMD_MAP_LAST,
+
+	ID_CMD_MAP3D_FIRST,
+	ID_CMD_MAP3D_PARAMETERS,
+	ID_CMD_MAP3D_ROTATE_X_LESS,
+	ID_CMD_MAP3D_ROTATE_X_MORE,
+	ID_CMD_MAP3D_ROTATE_Y_LESS,
+	ID_CMD_MAP3D_ROTATE_Y_MORE,
+	ID_CMD_MAP3D_ROTATE_Z_LESS,
+	ID_CMD_MAP3D_ROTATE_Z_MORE,
+	ID_CMD_MAP3D_SHIFT_X_LESS,
+	ID_CMD_MAP3D_SHIFT_X_MORE,
+	ID_CMD_MAP3D_SHIFT_Y_LESS,
+	ID_CMD_MAP3D_SHIFT_Y_MORE,
+	ID_CMD_MAP3D_SHIFT_Z_LESS,
+	ID_CMD_MAP3D_SHIFT_Z_MORE,
+	ID_CMD_MAP3D_EXAGGERATE_LESS,
+	ID_CMD_MAP3D_EXAGGERATE_MORE,
+	ID_CMD_MAP3D_CENTRAL,
+	ID_CMD_MAP3D_CENTRAL_LESS,
+	ID_CMD_MAP3D_CENTRAL_MORE,
+	ID_CMD_MAP3D_STEREO,
+	ID_CMD_MAP3D_STEREO_LESS,
+	ID_CMD_MAP3D_STEREO_MORE,
+	ID_CMD_MAP3D_INTERPOLATED,
+	ID_CMD_MAP3D_SRC_RES_LESS,
+	ID_CMD_MAP3D_SRC_RES_MORE,
+	ID_CMD_MAP3D_SAVE,
+	ID_CMD_MAP3D_SEQ_POS_ADD,
+	ID_CMD_MAP3D_SEQ_POS_DEL,
+	ID_CMD_MAP3D_SEQ_POS_DEL_ALL,
+	ID_CMD_MAP3D_SEQ_POS_EDIT,
+	ID_CMD_MAP3D_SEQ_PLAY,
+	ID_CMD_MAP3D_SEQ_PLAY_LOOP,
+	ID_CMD_MAP3D_SEQ_SAVE,
+	ID_CMD_MAP3D_LAST,
+
+	ID_CMD_TABLE_FIRST,
+	ID_CMD_TABLE_FIELD_ADD,
+	ID_CMD_TABLE_FIELD_DEL,
+	ID_CMD_TABLE_FIELD_SORT,
+	ID_CMD_TABLE_FIELD_RENAME,
+	ID_CMD_TABLE_RECORD_ADD,
+	ID_CMD_TABLE_RECORD_INS,
+	ID_CMD_TABLE_RECORD_DEL,
+	ID_CMD_TABLE_RECORD_DEL_ALL,
+	ID_CMD_TABLE_AUTOSIZE_COLS,
+	ID_CMD_TABLE_AUTOSIZE_ROWS,
+	ID_CMD_TABLE_LAST,
+
+	ID_CMD_DIAGRAM_FIRST,
+	ID_CMD_DIAGRAM_PARAMETERS,
+	ID_CMD_DIAGRAM_SIZE_FIT,
+	ID_CMD_DIAGRAM_SIZE_INC,
+	ID_CMD_DIAGRAM_SIZE_DEC,
+	ID_CMD_DIAGRAM_LAST,
+
+	ID_CMD_SCATTERPLOT_FIRST,
+	ID_CMD_SCATTERPLOT_PARAMETERS,
+	ID_CMD_SCATTERPLOT_UPDATE,
+	ID_CMD_SCATTERPLOT_LAST,
+
+	ID_CMD_HISTOGRAM_FIRST,
+	ID_CMD_HISTOGRAM_TOOLBAR,
+	ID_CMD_HISTOGRAM_CUMULATIVE,
+	ID_CMD_HISTOGRAM_AS_TABLE,
+	ID_CMD_HISTOGRAM_LAST,
+
+	ID_CMD_LAYOUT_FIRST,
+	ID_CMD_LAYOUT_TOOLBAR,
+	ID_CMD_LAYOUT_PRINT_SETUP,
+	ID_CMD_LAYOUT_PAGE_SETUP,
+	ID_CMD_LAYOUT_PRINT,
+	ID_CMD_LAYOUT_PRINT_PREVIEW,
+	ID_CMD_LAYOUT_FIT_SCALE,
+	ID_CMD_LAYOUT_LAST,
+
+	ID_CMD_CHILD_LAST,
+
+	//-----------------------------------------------------
+	ID_CMD_MODULE_FIRST,
+	ID_CMD_MODULE_RECENT_FIRST,
+	ID_CMD_MODULE_RECENT_LAST		= RECENT_COUNT + ID_CMD_MODULE_RECENT_FIRST,
+	ID_CMD_MODULE_START,
+	ID_CMD_MODULE_LAST				= ID_CMD_MODULE_START + 1000
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar *			CMD_Get_Name				(int Cmd_ID);
+const wxChar *			CMD_Get_Help				(int Cmd_ID);
+int						CMD_Get_ImageID				(int Cmd_ID);
+
+void					CMD_Menu_Add_Item			(class wxMenu *pMenu, bool bCheck, int Cmd_ID);
+void					CMD_Menu_Ins_Item			(class wxMenu *pMenu, bool bCheck, int Cmd_ID, int Position);
+
+class wxToolBarBase *	CMD_ToolBar_Create			(int ID);
+void					CMD_ToolBar_Add				(class wxToolBarBase *pToolBar, const wxChar *Name);
+void					CMD_ToolBar_Add_Item		(class wxToolBarBase *pToolBar, bool bCheck, int Cmd_ID);
+void					CMD_ToolBar_Add_Separator	(class wxToolBarBase *pToolBar);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Commands_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,115 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   RES_Controls.cpp                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar * CTRL_Get_Name(int ID_CTRL)
+{
+	switch( ID_CTRL )
+	{
+	case wxID_OK:
+	case ID_BTN_OK:						return( LNG("[BTN] Okay") );
+	case wxID_CANCEL:
+	case ID_BTN_CANCEL:					return( LNG("[BTN] Cancel") );
+
+	case ID_BTN_APPLY:					return( LNG("[BTN] Apply") );
+	case ID_BTN_RESTORE:				return( LNG("[BTN] Restore") );
+
+	case ID_BTN_EXECUTE:				return( LNG("[BTN] Execute") );
+
+	case ID_BTN_LOAD:					return( LNG("[BTN] Load") );
+	case ID_BTN_SAVE:					return( LNG("[BTN] Save") );
+
+	case ID_BTN_ADD:					return( LNG("[BTN] Add") );
+	case ID_BTN_INSERT:					return( LNG("[BTN] Insert") );
+	case ID_BTN_DELETE:					return( LNG("[BTN] Delete") );
+	case ID_BTN_DELETE_ALL:				return( LNG("[BTN] Clear") );
+
+	case ID_BTN_UP:						return( LNG("[BTN] Up") );
+	case ID_BTN_DOWN:					return( LNG("[BTN] Down") );
+
+	case ID_BTN_COLORS_MIRROR:			return( LNG("[BTN] Mirror") );
+	case ID_BTN_COLORS_INVERT:			return( LNG("[BTN] Invert") );
+	case ID_BTN_COLORS_RANDOM:			return( LNG("[BTN] Random") );
+	case ID_BTN_COLORS_PRESET:			return( LNG("[BTN] Presets") );
+	case ID_BTN_COLORS_COUNT:			return( LNG("[BTN] Count") );
+	}
+
+	return( LNG("[BTN] Button") );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_controls.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,201 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    RES_Controls.h                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Controls_H
+#define _HEADER_INCLUDED__SAGA_GUI__RES_Controls_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/event.h>
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef __WXMSW__
+	#define NOTEBOOK_STYLE	wxNB_BOTTOM
+#else
+	#define NOTEBOOK_STYLE	wxNB_TOP
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum ID_CONTROLS
+{
+	ID_WND_START				= wxID_HIGHEST,
+
+	ID_WND_MAIN,
+
+	ID_WND_INFO,
+	ID_WND_INFO_MESSAGES,
+	ID_WND_INFO_DESCRIPTION,
+	ID_WND_INFO_ATTRIBUTES,
+
+	ID_WND_ACTIVE,
+	ID_WND_ACTIVE_PARAMETERS,
+	ID_WND_ACTIVE_DESCRIPTION,
+	ID_WND_ACTIVE_HISTORY,
+	ID_WND_ACTIVE_ATTRIBUTES,
+	ID_WND_ACTIVE_LEGEND,
+	ID_WND_ACTIVE_HTMLEXTRAINFO,
+
+	ID_WND_PARM,
+	ID_WND_PARM_PG_ACTIVE,
+	ID_WND_PARM_PG_DIALOG,
+
+	ID_WND_WKSP,
+	ID_WND_WKSP_MODULES,
+	ID_WND_WKSP_DATA,
+	ID_WND_WKSP_MAPS,
+
+	ID_WND_PROGRESSBAR,
+
+	//-----------------------------------------------------
+	ID_VIEW_TABLE,
+	ID_VIEW_TABLE_DIAGRAM,
+	ID_VIEW_MAP,
+	ID_VIEW_MAP_3D,
+	ID_VIEW_HISTOGRAM,
+	ID_VIEW_SCATTERPLOT,
+	ID_VIEW_LAYOUT,
+
+	//-----------------------------------------------------
+	ID_TB_MAIN,
+
+	ID_TB_VIEW_TABLE,
+	ID_TB_VIEW_TABLE_DIAGRAM,
+	ID_TB_VIEW_MAP,
+	ID_TB_VIEW_MAP_3D,
+	ID_TB_VIEW_HISTOGRAM,
+	ID_TB_VIEW_SCATTERPLOT,
+	ID_TB_VIEW_LAYOUT,
+
+	//-----------------------------------------------------
+	ID_LISTBOX_SELECT,
+	ID_LISTBOX_ADD,
+
+	ID_COMBOBOX_SELECT,
+
+	//-----------------------------------------------------
+	ID_BTN_OK,
+	ID_BTN_CANCEL,
+
+	ID_BTN_APPLY,
+	ID_BTN_RESTORE,
+
+	ID_BTN_ADD,
+	ID_BTN_INSERT,
+	ID_BTN_DELETE,
+	ID_BTN_DELETE_ALL,
+
+	ID_BTN_UP,
+	ID_BTN_DOWN,
+
+	ID_BTN_EXECUTE,
+
+	ID_BTN_LOAD,
+	ID_BTN_SAVE,
+
+	ID_BTN_COLORS_MIRROR,
+	ID_BTN_COLORS_INVERT,
+	ID_BTN_COLORS_RANDOM,
+	ID_BTN_COLORS_PRESET,
+	ID_BTN_COLORS_COUNT
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar *	CTRL_Get_Name		(int ID_CTRL);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Controls_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,924 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   RES_Dialogs.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/utils.h>
+#include <wx/msgdlg.h>
+#include <wx/dirdlg.h> 
+#include <wx/filedlg.h>
+#include <wx/fontdlg.h>
+#include <wx/textdlg.h>
+#include <wx/colordlg.h>
+#include <wx/choicdlg.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "dlg_parameters.h"
+#include "dlg_text.h"
+#include "dlg_table.h"
+#include "dlg_list_grid.h"
+#include "dlg_list_table.h"
+#include "dlg_list_shapes.h"
+#include "dlg_list_tin.h"
+#include "dlg_list_pointcloud.h"
+#include "dlg_colors.h"
+
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define CONFIG_GROUP_FILE_DLG	wxT("/FileDialogs")
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar * DLG_Get_Text(int ID_DLG)
+{
+	switch( ID_DLG )
+	{
+	case ID_DLG_ABOUT:					return( LNG("[TXT] SAGA\nSystem for Automated Geoscientific Analyses\nVersion 2.0") );
+	case ID_DLG_CLOSE:					return( LNG("[TXT] Do you want to exit SAGA?") );
+	case ID_DLG_DELETE:					return( LNG("[TXT] Do you want to delete the selection?") );
+	}
+
+	return( LNG("[TXT] This is not a text!") );
+}
+
+//---------------------------------------------------------
+const wxChar * DLG_Get_Caption(int ID_DLG)
+{
+	switch( ID_DLG )
+	{
+	case ID_DLG_CLOSE:					return( LNG("[CAP] Exit") );
+	case ID_DLG_ABOUT:					return( LNG("[CAP] About SAGA") );
+	case ID_DLG_DELETE:					return( LNG("[CAP] Delete") );
+	}
+
+	return( LNG("[CAP] This Is Not A Caption!") );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar * DLG_Get_FILE_Caption(int ID_DLG)
+{
+	switch( ID_DLG )
+	{
+	case ID_DLG_WKSP_OPEN:			return( LNG("[CAP] Load") );
+
+	case ID_DLG_MODULES_OPEN:		return( LNG("[CAP] Load Module Library") );
+
+	case ID_DLG_PROJECT_OPEN:		return( LNG("[CAP] Load Project") );
+	case ID_DLG_PROJECT_SAVE:		return( LNG("[CAP] Save Project") );
+
+	case ID_DLG_GRIDS_OPEN:			return( LNG("[CAP] Load Grid") );
+	case ID_DLG_GRIDS_SAVE:			return( LNG("[CAP] Save Grid") );
+
+	case ID_DLG_SHAPES_OPEN:		return( LNG("[CAP] Load Shapes") );
+	case ID_DLG_SHAPES_SAVE:		return( LNG("[CAP] Save Shapes") );
+
+	case ID_DLG_TABLES_OPEN:		return( LNG("[CAP] Load Table") );
+	case ID_DLG_TABLES_SAVE:		return( LNG("[CAP] Save Table") );
+
+	case ID_DLG_TIN_OPEN:			return( LNG("[CAP] Load TIN") );
+	case ID_DLG_TIN_SAVE:			return( LNG("[CAP] Save TIN") );
+
+	case ID_DLG_POINTCLOUD_OPEN:	return( LNG("[CAP] Load Point Cloud") );
+	case ID_DLG_POINTCLOUD_SAVE:	return( LNG("[CAP] Save Point Cloud") );
+
+	case ID_DLG_TEXT_OPEN:			return( LNG("[CAP] Load Text") );
+	case ID_DLG_TEXT_SAVE:			return( LNG("[CAP] Save Text") );
+
+	case ID_DLG_PARAMETERS_OPEN:	return( LNG("[CAP] Load Settings") );
+	case ID_DLG_PARAMETERS_SAVE:	return( LNG("[CAP] Save Settings") );
+
+	case ID_DLG_COLORS_OPEN:		return( LNG("[CAP] Load Colors") );
+	case ID_DLG_COLORS_SAVE:		return( LNG("[CAP] Save Colors") );
+	}
+
+	return( LNG("[CAP] Select File") );
+}
+
+//---------------------------------------------------------
+const wxString DLG_Get_FILE_Filter(int ID_DLG)
+{
+	switch( ID_DLG )
+	{
+	case ID_DLG_WKSP_OPEN:
+		return( wxString::Format(
+			wxT("%s|*.sprj;*.mlb;*.dll;*.so;*sgrd;*.dgm;*.grd;*.shp;*.txt;*.dbf|")
+			wxT("%s (*.sprj)|*.sprj|")
+			wxT("%s (*.dll, *.so)|*.dll;*.so;*.mlb|")
+			wxT("%s (*.sgrd)|*.sgrd;*.dgm;*.grd|")
+			wxT("%s (*.shp)|*.shp|")
+			wxT("%s (*.txt, *.dbf)|*.txt;*.dbf|")
+			wxT("%s (*.spc)|*.spc|")
+			wxT("%s|*.*"),
+			LNG("All Recognised Files"),
+			LNG("SAGA Project"),
+			LNG("SAGA Module Libraries"),
+			LNG("Grids"),
+			LNG("ESRI Shape Files"),
+			LNG("Tables"),
+			LNG("Point Clouds"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_MODULES_OPEN:
+		return( wxString::Format(
+			wxT("%s (*.dll, *.so)|*.mlb;*.dll;*.so|")
+			wxT("%s|*.*"),
+			LNG("SAGA Module Libraries"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_PROJECT_OPEN:
+	case ID_DLG_PROJECT_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.sprj)|*.sprj|")
+			wxT("%s|*.*"),
+			LNG("SAGA Projects"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_GRIDS_OPEN:
+		return( wxString::Format(
+			wxT("%s (*.sgrd)|*.sgrd;*.dgm;*.grd|")
+			wxT("%s|*.*"),
+			LNG("Grids"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_GRIDS_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.sgrd)|*.sgrd|")
+			wxT("%s|*.*"),
+			LNG("Grids"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_SHAPES_OPEN:
+	case ID_DLG_SHAPES_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.shp)|*.shp|")
+			wxT("%s|*.*"),
+			LNG("ESRI Shape Files"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_TABLES_OPEN:
+		return( wxString::Format(
+			wxT("%s (*.txt, *.dbf)|*.txt;*.dbf|")
+			wxT("%s|*.*"),
+			LNG("Tables"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_TABLES_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.txt)|*.txt|")
+			wxT("%s (*.dbf)|*.dbf|")
+			wxT("%s|*.*"),
+			LNG("Text"),
+			LNG("DBase"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_TIN_OPEN:
+	case ID_DLG_TIN_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.shp)|*.shp|")
+			wxT("%s|*.*"),
+			LNG("ESRI Shape Files"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_POINTCLOUD_OPEN:
+	case ID_DLG_POINTCLOUD_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.spc)|*.spc|")
+			wxT("%s|*.*"),
+			LNG("SAGA Point Clouds"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_TEXT_OPEN:
+	case ID_DLG_TEXT_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.txt)|*.txt|")
+			wxT("%s|*.*"),
+			LNG("Text Files"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_PARAMETERS_OPEN:
+	case ID_DLG_PARAMETERS_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.sprm)|*.sprm|")
+			wxT("%s|*.*"),
+			LNG("SAGA Parameter Files"),
+			LNG("All Files")
+		));
+
+	case ID_DLG_COLORS_OPEN:
+	case ID_DLG_COLORS_SAVE:
+		return( wxString::Format(
+			wxT("%s (*.pal)|*.pal|")
+			wxT("%s|*.*"),
+			LNG("SAGA Colors"),
+			LNG("All Files")
+		));
+	}
+
+	return( wxString::Format(wxT("%s|*.*"), LNG("All Files")) );
+}
+
+//---------------------------------------------------------
+const wxChar * DLG_Get_FILE_Config(int ID_DLG)
+{
+	switch( ID_DLG )
+	{
+	case ID_DLG_WKSP_OPEN:			return( wxT("ALL_LOAD") );
+
+	case ID_DLG_MODULES_OPEN:		return( wxT("MLB_LOAD") );
+
+	case ID_DLG_PROJECT_OPEN:		return( wxT("PRJ_LOAD") );
+	case ID_DLG_PROJECT_SAVE:		return( wxT("PRJ_SAVE") );
+
+	case ID_DLG_GRIDS_OPEN:			return( wxT("GRD_LOAD") );
+	case ID_DLG_GRIDS_SAVE:			return( wxT("GRD_SAVE") );
+
+	case ID_DLG_SHAPES_OPEN:		return( wxT("SHP_LOAD") );
+	case ID_DLG_SHAPES_SAVE:		return( wxT("SHP_SAVE") );
+
+	case ID_DLG_TABLES_OPEN:		return( wxT("TAB_LOAD") );
+	case ID_DLG_TABLES_SAVE:		return( wxT("TAB_SAVE") );
+
+	case ID_DLG_TIN_OPEN:			return( wxT("TIN_LOAD") );
+	case ID_DLG_TIN_SAVE:			return( wxT("TIN_SAVE") );
+
+	case ID_DLG_POINTCLOUD_OPEN:	return( wxT("PTS_LOAD") );
+	case ID_DLG_POINTCLOUD_SAVE:	return( wxT("PTS_SAVE") );
+
+	case ID_DLG_TEXT_OPEN:			return( wxT("TXT_LOAD") );
+	case ID_DLG_TEXT_SAVE:			return( wxT("TXT_SAVE") );
+
+	case ID_DLG_PARAMETERS_OPEN:	return( wxT("PRM_LOAD") );
+	case ID_DLG_PARAMETERS_SAVE:	return( wxT("PRM_SAVE") );
+
+	case ID_DLG_COLORS_OPEN:		return( wxT("COL_LOAD") );
+	case ID_DLG_COLORS_SAVE:		return( wxT("COL_SAVE") );
+	}
+
+	return( wxT("FILE") );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxRect		DLG_Get_Def_Rect(void)
+{
+	wxRect	r(wxGetClientDisplayRect());
+
+	r.Deflate((int)(0.15 * r.GetWidth()), (int)(0.15 * r.GetHeight()));
+
+	return( r );
+}
+
+//---------------------------------------------------------
+wxPoint		DLG_Get_Def_Position(void)
+{
+	return( DLG_Get_Def_Rect().GetPosition() );
+}
+
+//---------------------------------------------------------
+wxSize		DLG_Get_Def_Size(void)
+{
+	return( DLG_Get_Def_Rect().GetSize() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		DLG_Parameters(CSG_Parameters *pParameters)
+{
+	if( pParameters && pParameters->Get_Count() > 0 )
+	{
+		CDLG_Parameters	dlg(pParameters);
+
+		return( dlg.ShowModal() == wxID_OK );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		DLG_Text(const wxChar *Caption, wxString &Text)
+{
+	CDLG_Text		dlg(&Text, Caption);
+
+	return( dlg.ShowModal() == wxID_OK );
+}
+
+//---------------------------------------------------------
+bool		DLG_Table(const wxChar *Caption, CSG_Table *pTable)
+{
+	CDLG_Table		dlg(pTable, Caption);
+
+	return( dlg.ShowModal() == wxID_OK );
+}
+
+//---------------------------------------------------------
+bool		DLG_List(const wxChar *Caption, CSG_Parameter_List *pList)
+{
+	CDLG_List_Base	*pDialog;
+
+	switch( pList->Get_Type() )
+	{
+	default:								pDialog	= NULL;																break;
+	case PARAMETER_TYPE_Grid_List:			pDialog	= new CDLG_List_Grid      ((CSG_Parameter_Grid_List       *)pList, Caption);	break;
+	case PARAMETER_TYPE_Table_List:			pDialog	= new CDLG_List_Table     ((CSG_Parameter_Table_List      *)pList, Caption);	break;
+	case PARAMETER_TYPE_Shapes_List:		pDialog	= new CDLG_List_Shapes    ((CSG_Parameter_Shapes_List     *)pList, Caption);	break;
+	case PARAMETER_TYPE_TIN_List:			pDialog	= new CDLG_List_TIN       ((CSG_Parameter_TIN_List        *)pList, Caption);	break;
+	case PARAMETER_TYPE_PointCloud_List:	pDialog	= new CDLG_List_PointCloud((CSG_Parameter_PointCloud_List *)pList, Caption);	break;
+	}
+
+	if( pDialog )
+	{
+		bool	bResult	= pDialog->ShowModal() == wxID_OK;
+
+		delete(pDialog);
+
+		return( bResult );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		DLG_Colors(CSG_Colors *pColors)
+{
+	CDLG_Colors		dlg(pColors);
+
+	return( dlg.ShowModal() == wxID_OK );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		DLG_Colors(int &Palette)
+{
+	wxString	Palettes[SG_COLORS_COUNT];
+
+	Palettes[SG_COLORS_DEFAULT]			= LNG("default");
+	Palettes[SG_COLORS_DEFAULT_BRIGHT]	= LNG("default (same brightness)");
+	Palettes[SG_COLORS_BLACK_WHITE]		= LNG("greyscale");
+	Palettes[SG_COLORS_BLACK_RED]		= LNG("black > red");
+	Palettes[SG_COLORS_BLACK_GREEN]		= LNG("black > green");
+	Palettes[SG_COLORS_BLACK_BLUE]		= LNG("black > blue");
+	Palettes[SG_COLORS_WHITE_RED]		= LNG("white > red");
+	Palettes[SG_COLORS_WHITE_GREEN]		= LNG("white > green");
+	Palettes[SG_COLORS_WHITE_BLUE]		= LNG("white > blue");
+	Palettes[SG_COLORS_YELLOW_RED]		= LNG("yellow > red");
+	Palettes[SG_COLORS_YELLOW_GREEN]	= LNG("yellow > green");
+	Palettes[SG_COLORS_YELLOW_BLUE]		= LNG("yellow > blue");
+	Palettes[SG_COLORS_RED_GREEN]		= LNG("red > green");
+	Palettes[SG_COLORS_RED_BLUE]		= LNG("red > blue");
+	Palettes[SG_COLORS_GREEN_BLUE]		= LNG("green > blue");
+	Palettes[SG_COLORS_RED_GREY_BLUE]	= LNG("red > grey > blue");
+	Palettes[SG_COLORS_RED_GREY_GREEN]	= LNG("red > grey > green");
+	Palettes[SG_COLORS_GREEN_GREY_BLUE]	= LNG("green > grey > blue");
+	Palettes[SG_COLORS_RED_GREEN_BLUE]	= LNG("red > green > blue");
+	Palettes[SG_COLORS_RED_BLUE_GREEN]	= LNG("red > blue > green");
+	Palettes[SG_COLORS_GREEN_RED_BLUE]	= LNG("green > red > blue");
+	Palettes[SG_COLORS_RAINBOW]			= LNG("Rainbow");
+	Palettes[SG_COLORS_NEON]			= LNG("Neon");
+
+	wxSingleChoiceDialog	dlg(
+		MDI_Get_Top_Window(),
+		wxT(""),
+		LNG("[CAP] Preset Selection"),		
+		SG_COLORS_COUNT, Palettes
+	);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		Palette	= dlg.GetSelection();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		DLG_Color(long &_Colour)
+{
+	static wxColourData	Colours;
+
+	Colours.SetChooseFull(true);
+
+	wxColour		Colour(SG_GET_R(_Colour), SG_GET_G(_Colour), SG_GET_B(_Colour));
+	wxColourDialog	dlg(MDI_Get_Top_Window(), &Colours);
+
+	dlg.GetColourData().SetColour(Colour);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		Colours	= dlg.GetColourData();
+		Colour	= dlg.GetColourData().GetColour();
+		_Colour	= Get_Color_asInt(Colour);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool		DLG_Font(wxFont *pFont, long &_Colour)
+{
+	wxColour		Colour(SG_GET_R(_Colour), SG_GET_G(_Colour), SG_GET_B(_Colour));
+	wxFontDialog	dlg(MDI_Get_Top_Window());
+
+	dlg.GetFontData().SetInitialFont(*pFont);
+	dlg.GetFontData().SetColour(Colour);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		*pFont	= dlg.GetFontData().GetChosenFont();
+		Colour	= dlg.GetFontData().GetColour();
+		_Colour	= Get_Color_asInt(Colour);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		DLG_Get_Number(double &Number, const wxChar *Caption, const wxChar *Text)
+{
+	wxTextEntryDialog	dlg(MDI_Get_Top_Window(), Text, Caption, wxString::Format(wxT("%f"), Number));
+
+	return( dlg.ShowModal() == wxID_OK && dlg.GetValue().ToDouble(&Number) );
+}
+
+bool		DLG_Get_Number(double &Number)
+{
+	return( DLG_Get_Number(Number, LNG("[CAP] Input"), LNG("[DLG] Please enter a numeric value:")) );
+}
+
+//---------------------------------------------------------
+bool		DLG_Get_Number(int &Number, const wxChar *Caption, const wxChar *Text)
+{
+	long				lValue;
+	wxTextEntryDialog	dlg(MDI_Get_Top_Window(), Text, Caption, wxString::Format(wxT("%d"), Number));
+
+	if( dlg.ShowModal() == wxID_OK && dlg.GetValue().ToLong(&lValue) )
+	{
+		Number	= lValue;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Get_Number(int &Number)
+{
+	return( DLG_Get_Number(Number, LNG("[CAP] Input"), LNG("[DLG] Please enter a numeric value:")) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		DLG_Directory(wxString &Directory, const wxChar *Caption, const wxChar *def_Dir)
+{
+	wxDirDialog	dlg(MDI_Get_Top_Window(), Caption, def_Dir);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		Directory	= dlg.GetPath();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Directory(wxString &Directory, const wxChar *Caption)
+{
+	return( DLG_Directory(Directory, Caption, SG_File_Get_Path(Directory)) );
+}
+
+//---------------------------------------------------------
+bool		DLG_Save(wxString &File_Path, const wxChar *Caption, const wxChar *def_Dir, const wxChar *def_File, const wxChar *Filter)
+{
+	wxFileDialog	dlg(MDI_Get_Top_Window(), Caption, def_Dir, def_File, Filter, wxSAVE|wxOVERWRITE_PROMPT);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		File_Path	= dlg.GetPath();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Save(wxString &File_Path, int ID_DLG)
+{
+	wxString	def_Dir;
+
+	CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), def_Dir);
+
+	if( DLG_Save(File_Path, DLG_Get_FILE_Caption(ID_DLG), def_Dir, wxT(""), DLG_Get_FILE_Filter(ID_DLG)) )
+	{
+		CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), SG_File_Get_Path(File_Path));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Save(wxString &File_Path, const wxChar *Caption, const wxChar *Filter)
+{
+	return( DLG_Save(File_Path, Caption, SG_File_Get_Path(File_Path), SG_File_Get_Name(File_Path, true), Filter) );
+}
+
+//---------------------------------------------------------
+bool		DLG_Open(wxString &File_Path, const wxChar *Caption, const wxChar *def_Dir, const wxChar *def_File, const wxChar *Filter)
+{
+	wxFileDialog	dlg(MDI_Get_Top_Window(), Caption, def_Dir, def_File, Filter, wxOPEN|wxFILE_MUST_EXIST);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		File_Path	= dlg.GetPath();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Open(wxString &File_Path, int ID_DLG)
+{
+	wxString	def_Dir;
+
+	CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), def_Dir);
+
+	if( DLG_Open(File_Path, DLG_Get_FILE_Caption(ID_DLG), def_Dir, wxT(""), DLG_Get_FILE_Filter(ID_DLG)) )
+	{
+		CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), SG_File_Get_Path(File_Path));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Open(wxString &File_Path, const wxChar *Caption, const wxChar *Filter)
+{
+	return( DLG_Open(File_Path, Caption, SG_File_Get_Path(File_Path), SG_File_Get_Name(File_Path, true), Filter) );
+}
+
+//---------------------------------------------------------
+bool		DLG_Open(wxArrayString &File_Paths, const wxChar *Caption, const wxChar *def_Dir, const wxChar *Filter)
+{
+	wxFileDialog	dlg(MDI_Get_Top_Window(), Caption, def_Dir, wxT(""), Filter, wxOPEN|wxFILE_MUST_EXIST|wxMULTIPLE);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		dlg.GetPaths(File_Paths);
+
+		return( File_Paths.GetCount() > 0 );
+	}
+
+	return( false );
+}
+
+bool		DLG_Open(wxArrayString &File_Paths, int ID_DLG)
+{
+	wxString	def_Dir;
+
+	CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), def_Dir);
+
+	if( DLG_Open(File_Paths, DLG_Get_FILE_Caption(ID_DLG), def_Dir, DLG_Get_FILE_Filter(ID_DLG)) )
+	{
+		CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), SG_File_Get_Path(File_Paths[0]));
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool		DLG_Open(wxArrayString &File_Paths, const wxChar *Caption, const wxChar *Filter)
+{
+	return( DLG_Open(File_Paths, Caption, wxT(""), Filter) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool		DLG_Image_Save(wxString &File_Path, int &Type, const wxChar *def_Dir, const wxChar *def_File)
+{
+	static	int	Filter_Index	= 3;
+
+	wxFileDialog	dlg(
+		MDI_Get_Top_Window(), LNG("[CAP] Save As Image"), def_Dir, def_File, wxString::Format(
+			wxT("%s (*.bmp)|*.bmp|")
+			wxT("%s (*.jpg)|*.jpg;*.jif;*.jpeg|")
+			wxT("%s (*.tif)|*.tif;*.tiff|")
+			wxT("%s (*.png)|*.png|")
+			wxT("%s (*.gif)|*.gif|")
+			wxT("%s (*.pcx)|*.pcx"),
+			LNG("Windows or OS/2 Bitmap"),
+			LNG("JPEG - JFIF Compliant"),
+			LNG("Tagged Image File Format"),
+			LNG("Portable Network Graphics"),
+			LNG("CompuServe Graphics Interchange"),
+			LNG("Zsoft Paintbrush")
+		), wxSAVE|wxOVERWRITE_PROMPT
+	);
+
+	dlg.SetFilterIndex(Filter_Index);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		File_Path		= dlg.GetPath();
+		Filter_Index	= dlg.GetFilterIndex();
+
+		switch( Filter_Index )
+		{
+		default:
+		case 0:	Type	= wxBITMAP_TYPE_BMP;	break;
+		case 1:	Type	= wxBITMAP_TYPE_JPEG;	break;
+		case 2:	Type	= wxBITMAP_TYPE_TIF;	break;
+		case 3:	Type	= wxBITMAP_TYPE_PNG;	break;
+		case 4:	Type	= wxBITMAP_TYPE_GIF;	break;
+ 		case 5:	Type	= wxBITMAP_TYPE_PCX;	break;
+		case 6:	Type	= wxBITMAP_TYPE_PNM;	break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		DLG_Message_Show(const wxChar *Message, const wxChar *Caption)
+{
+	wxMessageDialog	dlg(MDI_Get_Top_Window(), Message, Caption, wxOK);
+
+	dlg.ShowModal();
+}
+
+void		DLG_Message_Show(int ID_DLG)
+{
+	DLG_Message_Show(DLG_Get_Text(ID_DLG), DLG_Get_Caption(ID_DLG));
+}
+
+void		DLG_Message_Show(const wxChar *Message)
+{
+	DLG_Message_Show(Message, DLG_Get_Caption(-1));
+}
+
+//---------------------------------------------------------
+int			DLG_Message_Show_Error(const wxChar *Message, const wxChar *Caption)
+{
+	wxMessageDialog	dlg(MDI_Get_Top_Window(), Message, Caption, wxOK|wxCANCEL|wxICON_ERROR);
+
+	switch( dlg.ShowModal() )
+	{
+		case wxID_OK: default:
+			return( 1 );
+
+		case wxID_CANCEL:
+			return( 0 );
+	}
+}
+
+int			DLG_Message_Show_Error(int ID_DLG)
+{
+	return( DLG_Message_Show_Error(DLG_Get_Text(ID_DLG), DLG_Get_Caption(ID_DLG)) );
+}
+
+//---------------------------------------------------------
+bool		DLG_Message_Confirm(const wxChar *Message, const wxChar *Caption)
+{
+	wxMessageDialog	dlg(MDI_Get_Top_Window(), Message, Caption, wxYES_NO|wxICON_QUESTION);
+
+	return( dlg.ShowModal() == wxID_YES );
+}
+
+bool		DLG_Message_Confirm(int ID_DLG)
+{
+	return( DLG_Message_Confirm(DLG_Get_Text(ID_DLG), DLG_Get_Caption(ID_DLG)) );
+}
+
+//---------------------------------------------------------
+int			DLG_Message_YesNoCancel(const wxChar *Message, const wxChar *Caption)
+{
+	wxMessageDialog	dlg(MDI_Get_Top_Window(), Message, Caption, wxYES|wxNO|wxCANCEL|wxICON_QUESTION);
+
+	switch( dlg.ShowModal() )
+	{
+		case wxID_YES: default:
+			return( 0 );
+
+		case wxID_NO:
+			return( 1 );
+
+		case wxID_CANCEL:
+			return( 2 );
+	}
+}
+
+int			DLG_Message_YesNoCancel(int ID_DLG)
+{
+	return( DLG_Message_YesNoCancel(DLG_Get_Text(ID_DLG), DLG_Get_Caption(ID_DLG)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int			DLG_Maps_Add(void)
+{
+	bool		bOk;
+	int			i;
+	wxString	*Maps;
+
+	if( g_pMaps )
+	{
+		if( g_pMaps->Get_Count() <= 0 )
+		{
+			return( 0 );
+		}
+		else
+		{
+			Maps	= new wxString[g_pMaps->Get_Count() + 1];
+
+			for(i=0; i<g_pMaps->Get_Count(); i++)
+			{
+				Maps[i]	= g_pMaps->Get_Map(i)->Get_Name();
+			}
+
+			Maps[i]	= LNG("[VAL] New");
+
+			wxSingleChoiceDialog	dlg(
+				MDI_Get_Top_Window(),
+				LNG("[CAP] Map Selection"),
+				LNG("[DLG] Add layer to selected map"),
+				g_pMaps->Get_Count() + 1,
+				Maps
+			);
+
+			dlg.SetSelection(g_pMaps->Get_Count());
+
+			bOk		= dlg.ShowModal() == wxID_OK;
+
+			delete[](Maps);
+
+			if( bOk )
+			{
+				return( dlg.GetSelection() );
+			}
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_dialogs.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,184 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    RES_Dialogs.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Dialogs_H
+#define _HEADER_INCLUDED__SAGA_GUI__RES_Dialogs_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/string.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum ID_DIALOGS
+{
+	ID_DLG_CLOSE,
+	ID_DLG_ABOUT,
+
+	ID_DLG_DELETE,
+
+	ID_DLG_WKSP_OPEN,
+	ID_DLG_MODULES_OPEN,
+	ID_DLG_PROJECT_OPEN,
+	ID_DLG_PROJECT_SAVE,
+	ID_DLG_TABLES_OPEN,
+	ID_DLG_TABLES_SAVE,
+	ID_DLG_SHAPES_OPEN,
+	ID_DLG_SHAPES_SAVE,
+	ID_DLG_TIN_OPEN,
+	ID_DLG_TIN_SAVE,
+	ID_DLG_POINTCLOUD_OPEN,
+	ID_DLG_POINTCLOUD_SAVE,
+	ID_DLG_GRIDS_OPEN,
+	ID_DLG_GRIDS_SAVE,
+
+	ID_DLG_TEXT_OPEN,
+	ID_DLG_TEXT_SAVE,
+
+	ID_DLG_PARAMETERS_OPEN,
+	ID_DLG_PARAMETERS_SAVE,
+
+	ID_DLG_COLORS_OPEN,
+	ID_DLG_COLORS_SAVE
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar *		DLG_Get_Text			(int ID_DLG);
+const wxChar *		DLG_Get_Caption			(int ID_DLG);
+
+const wxChar *		DLG_Get_FILE_Caption	(int ID_DLG);
+const wxString		DLG_Get_FILE_Filter		(int ID_DLG);
+const wxChar *		DLG_Get_FILE_Config		(int ID_DLG);
+
+//---------------------------------------------------------
+class wxRect		DLG_Get_Def_Rect		(void);
+class wxPoint		DLG_Get_Def_Position	(void);
+class wxSize		DLG_Get_Def_Size		(void);
+
+//---------------------------------------------------------
+bool				DLG_Parameters			(class CSG_Parameters *pParameters);
+
+bool				DLG_Text				(const wxChar *Caption, class wxString &Text);
+bool				DLG_Table				(const wxChar *Caption, class CSG_Table *pTable);
+
+bool				DLG_List				(const wxChar *Caption, class CSG_Parameter_List *pList);
+
+bool				DLG_Colors				(class CSG_Colors *pColors);
+bool				DLG_Colors				(int &Palette);
+bool				DLG_Color				(long &Colour);
+
+bool				DLG_Font				(class wxFont *pFont, long &Colour);
+
+bool				DLG_Get_Number			(double &Number, const wxChar *Caption, const wxChar *Text);
+bool				DLG_Get_Number			(double &Number);
+bool				DLG_Get_Number			(int    &Number, const wxChar *Caption, const wxChar *Text);
+bool				DLG_Get_Number			(int    &Number);
+
+bool				DLG_Directory			(class wxString &Directory, const wxChar *Caption);
+bool				DLG_Save				(class wxString &File_Path, int ID_DLG);
+bool				DLG_Save				(class wxString &File_Path, const wxChar *Caption, const wxChar *Filter);
+bool				DLG_Open				(class wxString &File_Path, int ID_DLG);
+bool				DLG_Open				(class wxString &File_Path, const wxChar *Caption, const wxChar *Filter);
+bool				DLG_Open				(class wxArrayString &File_Paths, int ID_DLG);
+bool				DLG_Open				(class wxArrayString &File_Paths, const wxChar *Caption, const wxChar *Filter);
+
+bool				DLG_Image_Save			(class wxString &File_Path, int &Type, const wxChar *def_Dir = wxT(""), const wxChar *def_File = wxT(""));
+
+void				DLG_Message_Show		(int ID_DLG);
+void				DLG_Message_Show		(const wxChar *Message);
+void				DLG_Message_Show		(const wxChar *Message, const wxChar *Caption);
+int					DLG_Message_Show_Error	(int ID_DLG);
+int					DLG_Message_Show_Error	(const wxChar *Message, const wxChar *Caption);
+bool				DLG_Message_Confirm		(int ID_DLG);
+bool				DLG_Message_Confirm		(const wxChar *Message, const wxChar *Caption);
+int					DLG_Message_YesNoCancel	(int ID_DLG);
+int					DLG_Message_YesNoCancel	(const wxChar *Message, const wxChar *Caption);
+
+//---------------------------------------------------------
+int					DLG_Maps_Add			(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Dialogs_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,387 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    RES_Images.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/image.h>
+
+#include "res_images.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "./res/xpm/default.xpm"
+#include "./res/xpm/nb_active_attributes.xpm"
+#include "./res/xpm/nb_active_description.xpm"
+#include "./res/xpm/nb_active_legend.xpm"
+#include "./res/xpm/nb_active_parameters.xpm"
+#include "./res/xpm/nb_active_htmlextrainfo.xpm"
+#include "./res/xpm/nb_info_error.xpm"
+#include "./res/xpm/nb_info_execution.xpm"
+#include "./res/xpm/nb_info_messages.xpm"
+#include "./res/xpm/nb_wksp_data.xpm"
+#include "./res/xpm/nb_wksp_maps.xpm"
+#include "./res/xpm/nb_wksp_modules.xpm"
+#include "./res/xpm/nb_wksp_thumbnails.xpm"
+#include "./res/xpm/nb_wksp_treeview.xpm"
+#include "./res/xpm/saga_icon_16.xpm"
+#include "./res/xpm/saga_icon_32.xpm"
+#include "./res/xpm/saga_splash.xpm"
+#include "./res/xpm/wnd_diagram.xpm"
+#include "./res/xpm/wnd_histogram.xpm"
+#include "./res/xpm/wnd_layout.xpm"
+#include "./res/xpm/wnd_map.xpm"
+#include "./res/xpm/wnd_map3d.xpm"
+#include "./res/xpm/wnd_scatterplot.xpm"
+#include "./res/xpm/wnd_table.xpm"
+
+#include "./res/xpm/crs_edit_point_add.xpm"
+#include "./res/xpm/crs_edit_point_move.xpm"
+#include "./res/xpm/crs_hand.xpm"
+#include "./res/xpm/crs_hand_grap.xpm"
+#include "./res/xpm/crs_info.xpm"
+#include "./res/xpm/crs_magnifier.xpm"
+#include "./res/xpm/crs_select.xpm"
+
+#include "./res/xpm/tb_active.xpm"
+#include "./res/xpm/tb_delete.xpm"
+#include "./res/xpm/tb_diagram_parameters.xpm"
+#include "./res/xpm/tb_edit_shape_add.xpm"
+#include "./res/xpm/tb_edit_shape_add_part.xpm"
+#include "./res/xpm/tb_edit_shape_del.xpm"
+#include "./res/xpm/tb_edit_shape_del_part.xpm"
+#include "./res/xpm/tb_edit_shape_del_point.xpm"
+#include "./res/xpm/tb_edit_shape_select.xpm"
+#include "./res/xpm/tb_help.xpm"
+#include "./res/xpm/tb_histogram_as_table.xpm"
+#include "./res/xpm/tb_histogram_cumulative.xpm"
+#include "./res/xpm/tb_info.xpm"
+#include "./res/xpm/tb_layout_page_setup.xpm"
+#include "./res/xpm/tb_layout_print.xpm"
+#include "./res/xpm/tb_layout_print_preview.xpm"
+#include "./res/xpm/tb_layout_print_setup.xpm"
+#include "./res/xpm/tb_map3d_central_less.xpm"
+#include "./res/xpm/tb_map3d_central_more.xpm"
+#include "./res/xpm/tb_map3d_exaggerate_less.xpm"
+#include "./res/xpm/tb_map3d_exaggerate_more.xpm"
+#include "./res/xpm/tb_map3d_interpolated.xpm"
+#include "./res/xpm/tb_map3d_properties.xpm"
+#include "./res/xpm/tb_map3d_rotate_x_less.xpm"
+#include "./res/xpm/tb_map3d_rotate_x_more.xpm"
+#include "./res/xpm/tb_map3d_rotate_z_less.xpm"
+#include "./res/xpm/tb_map3d_rotate_z_more.xpm"
+#include "./res/xpm/tb_map3d_shift_x_less.xpm"
+#include "./res/xpm/tb_map3d_shift_x_more.xpm"
+#include "./res/xpm/tb_map3d_shift_y_less.xpm"
+#include "./res/xpm/tb_map3d_shift_y_more.xpm"
+#include "./res/xpm/tb_map3d_shift_z_less.xpm"
+#include "./res/xpm/tb_map3d_shift_z_more.xpm"
+#include "./res/xpm/tb_map3d_stereo.xpm"
+#include "./res/xpm/tb_map_3d_show.xpm"
+#include "./res/xpm/tb_map_layout_show.xpm"
+#include "./res/xpm/tb_map_legend_horizontal.xpm"
+#include "./res/xpm/tb_map_legend_vertical.xpm"
+#include "./res/xpm/tb_map_mode_distance.xpm"
+#include "./res/xpm/tb_map_mode_pan.xpm"
+#include "./res/xpm/tb_map_mode_select.xpm"
+#include "./res/xpm/tb_map_mode_zoom.xpm"
+#include "./res/xpm/tb_map_synchronize.xpm"
+#include "./res/xpm/tb_map_zoom_active.xpm"
+#include "./res/xpm/tb_map_zoom_full.xpm"
+#include "./res/xpm/tb_map_zoom_last.xpm"
+#include "./res/xpm/tb_map_zoom_next.xpm"
+#include "./res/xpm/tb_map_zoom_selection.xpm"
+#include "./res/xpm/tb_open.xpm"
+#include "./res/xpm/tb_open_grid.xpm"
+#include "./res/xpm/tb_open_module.xpm"
+#include "./res/xpm/tb_open_shapes.xpm"
+#include "./res/xpm/tb_open_table.xpm"
+#include "./res/xpm/tb_open_tin.xpm"
+#include "./res/xpm/tb_save.xpm"
+#include "./res/xpm/tb_scatterplot_parameters.xpm"
+#include "./res/xpm/tb_show.xpm"
+#include "./res/xpm/tb_table_col_add.xpm"
+#include "./res/xpm/tb_table_col_del.xpm"
+#include "./res/xpm/tb_table_row_add.xpm"
+#include "./res/xpm/tb_table_row_del.xpm"
+#include "./res/xpm/tb_table_row_del_all.xpm"
+#include "./res/xpm/tb_table_row_ins.xpm"
+#include "./res/xpm/tb_wksp.xpm"
+
+#include "./res/xpm/wksp_data_manager.xpm"
+#include "./res/xpm/wksp_grid.xpm"
+#include "./res/xpm/wksp_grid_manager.xpm"
+#include "./res/xpm/wksp_grid_system.xpm"
+#include "./res/xpm/wksp_map.xpm"
+#include "./res/xpm/wksp_map_manager.xpm"
+#include "./res/xpm/wksp_module.xpm"
+#include "./res/xpm/wksp_module_library.xpm"
+#include "./res/xpm/wksp_module_manager.xpm"
+#include "./res/xpm/wksp_noitems.xpm"
+#include "./res/xpm/wksp_shapes_line.xpm"
+#include "./res/xpm/wksp_shapes_manager.xpm"
+#include "./res/xpm/wksp_shapes_point.xpm"
+#include "./res/xpm/wksp_shapes_points.xpm"
+#include "./res/xpm/wksp_shapes_polygon.xpm"
+#include "./res/xpm/wksp_table.xpm"
+#include "./res/xpm/wksp_table_manager.xpm"
+#include "./res/xpm/wksp_tin.xpm"
+#include "./res/xpm/wksp_tin_manager.xpm"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+char ** IMG_Get_XPM(int ID_IMG)
+{
+	switch( ID_IMG )
+	{
+	default:
+	case ID_IMG_DEFAULT:	return( default_xpm );
+	case ID_IMG_NB_ACTIVE_ATTRIBUTES:	return( nb_active_attributes_xpm );
+	case ID_IMG_NB_ACTIVE_DESCRIPTION:	return( nb_active_description_xpm );
+	case ID_IMG_NB_ACTIVE_LEGEND:	return( nb_active_legend_xpm );
+	case ID_IMG_NB_ACTIVE_PARAMETERS:	return( nb_active_parameters_xpm );
+	case ID_IMG_NB_ACTIVE_HTMLEXTRAINFO:	return( nb_active_htmlextrainfo_xpm );
+	case ID_IMG_NB_INFO_ERROR:	return( nb_info_error_xpm );
+	case ID_IMG_NB_INFO_EXECUTION:	return( nb_info_execution_xpm );
+	case ID_IMG_NB_INFO_MESSAGES:	return( nb_info_messages_xpm );
+	case ID_IMG_NB_WKSP_DATA:	return( nb_wksp_data_xpm );
+	case ID_IMG_NB_WKSP_MAPS:	return( nb_wksp_maps_xpm );
+	case ID_IMG_NB_WKSP_MODULES:	return( nb_wksp_modules_xpm );
+	case ID_IMG_NB_WKSP_THUMBNAILS:	return( nb_wksp_thumbnails_xpm );
+	case ID_IMG_NB_WKSP_TREEVIEW:	return( nb_wksp_treeview_xpm );
+	case ID_IMG_SAGA_ICON_16:	return( saga_icon_16_xpm );
+	case ID_IMG_SAGA_ICON_32:	return( saga_icon_32_xpm );
+	case ID_IMG_SAGA_SPLASH:	return( saga_splash_xpm );
+	case ID_IMG_WND_DIAGRAM:	return( wnd_diagram_xpm );
+	case ID_IMG_WND_HISTOGRAM:	return( wnd_histogram_xpm );
+	case ID_IMG_WND_LAYOUT:	return( wnd_layout_xpm );
+	case ID_IMG_WND_MAP:	return( wnd_map_xpm );
+	case ID_IMG_WND_MAP3D:	return( wnd_map3d_xpm );
+	case ID_IMG_WND_SCATTERPLOT:	return( wnd_scatterplot_xpm );
+	case ID_IMG_WND_TABLE:	return( wnd_table_xpm );
+
+	case ID_IMG_CRS_EDIT_POINT_ADD:	return( crs_edit_point_add_xpm );
+	case ID_IMG_CRS_EDIT_POINT_MOVE:	return( crs_edit_point_move_xpm );
+	case ID_IMG_CRS_HAND:	return( crs_hand_xpm );
+	case ID_IMG_CRS_HAND_GRAP:	return( crs_hand_grap_xpm );
+	case ID_IMG_CRS_INFO:	return( crs_info_xpm );
+	case ID_IMG_CRS_MAGNIFIER:	return( crs_magnifier_xpm );
+	case ID_IMG_CRS_SELECT:	return( crs_select_xpm );
+
+	case ID_IMG_TB_ACTIVE:	return( tb_active_xpm );
+	case ID_IMG_TB_DELETE:	return( tb_delete_xpm );
+	case ID_IMG_TB_DIAGRAM_PARAMETERS:	return( tb_diagram_parameters_xpm );
+	case ID_IMG_TB_EDIT_SHAPE_ADD:	return( tb_edit_shape_add_xpm );
+	case ID_IMG_TB_EDIT_SHAPE_ADD_PART:	return( tb_edit_shape_add_part_xpm );
+	case ID_IMG_TB_EDIT_SHAPE_DEL:	return( tb_edit_shape_del_xpm );
+	case ID_IMG_TB_EDIT_SHAPE_DEL_PART:	return( tb_edit_shape_del_part_xpm );
+	case ID_IMG_TB_EDIT_SHAPE_DEL_POINT:	return( tb_edit_shape_del_point_xpm );
+	case ID_IMG_TB_EDIT_SHAPE_SELECT:	return( tb_edit_shape_select_xpm );
+	case ID_IMG_TB_HELP:	return( tb_help_xpm );
+	case ID_IMG_TB_HISTOGRAM_AS_TABLE:	return( tb_histogram_as_table_xpm );
+	case ID_IMG_TB_HISTOGRAM_CUMULATIVE:	return( tb_histogram_cumulative_xpm );
+	case ID_IMG_TB_INFO:	return( tb_info_xpm );
+	case ID_IMG_TB_LAYOUT_PAGE_SETUP:	return( tb_layout_page_setup_xpm );
+	case ID_IMG_TB_LAYOUT_PRINT:	return( tb_layout_print_xpm );
+	case ID_IMG_TB_LAYOUT_PRINT_PREVIEW:	return( tb_layout_print_preview_xpm );
+	case ID_IMG_TB_LAYOUT_PRINT_SETUP:	return( tb_layout_print_setup_xpm );
+	case ID_IMG_TB_MAP3D_CENTRAL_LESS:	return( tb_map3d_central_less_xpm );
+	case ID_IMG_TB_MAP3D_CENTRAL_MORE:	return( tb_map3d_central_more_xpm );
+	case ID_IMG_TB_MAP3D_EXAGGERATE_LESS:	return( tb_map3d_exaggerate_less_xpm );
+	case ID_IMG_TB_MAP3D_EXAGGERATE_MORE:	return( tb_map3d_exaggerate_more_xpm );
+	case ID_IMG_TB_MAP3D_INTERPOLATED:	return( tb_map3d_interpolated_xpm );
+	case ID_IMG_TB_MAP3D_PROPERTIES:	return( tb_map3d_properties_xpm );
+	case ID_IMG_TB_MAP3D_ROTATE_X_LESS:	return( tb_map3d_rotate_x_less_xpm );
+	case ID_IMG_TB_MAP3D_ROTATE_X_MORE:	return( tb_map3d_rotate_x_more_xpm );
+	case ID_IMG_TB_MAP3D_ROTATE_Z_LESS:	return( tb_map3d_rotate_z_less_xpm );
+	case ID_IMG_TB_MAP3D_ROTATE_Z_MORE:	return( tb_map3d_rotate_z_more_xpm );
+	case ID_IMG_TB_MAP3D_SHIFT_X_LESS:	return( tb_map3d_shift_x_less_xpm );
+	case ID_IMG_TB_MAP3D_SHIFT_X_MORE:	return( tb_map3d_shift_x_more_xpm );
+	case ID_IMG_TB_MAP3D_SHIFT_Y_LESS:	return( tb_map3d_shift_y_less_xpm );
+	case ID_IMG_TB_MAP3D_SHIFT_Y_MORE:	return( tb_map3d_shift_y_more_xpm );
+	case ID_IMG_TB_MAP3D_SHIFT_Z_LESS:	return( tb_map3d_shift_z_less_xpm );
+	case ID_IMG_TB_MAP3D_SHIFT_Z_MORE:	return( tb_map3d_shift_z_more_xpm );
+	case ID_IMG_TB_MAP3D_STEREO:	return( tb_map3d_stereo_xpm );
+	case ID_IMG_TB_MAP_3D_SHOW:	return( tb_map_3d_show_xpm );
+	case ID_IMG_TB_MAP_LAYOUT_SHOW:	return( tb_map_layout_show_xpm );
+	case ID_IMG_TB_MAP_LEGEND_HORIZONTAL:	return( tb_map_legend_horizontal_xpm );
+	case ID_IMG_TB_MAP_LEGEND_VERTICAL:	return( tb_map_legend_vertical_xpm );
+	case ID_IMG_TB_MAP_MODE_DISTANCE:	return( tb_map_mode_distance_xpm );
+	case ID_IMG_TB_MAP_MODE_PAN:	return( tb_map_mode_pan_xpm );
+	case ID_IMG_TB_MAP_MODE_SELECT:	return( tb_map_mode_select_xpm );
+	case ID_IMG_TB_MAP_MODE_ZOOM:	return( tb_map_mode_zoom_xpm );
+	case ID_IMG_TB_MAP_SYNCHRONIZE:	return( tb_map_synchronize_xpm );
+	case ID_IMG_TB_MAP_ZOOM_ACTIVE:	return( tb_map_zoom_active_xpm );
+	case ID_IMG_TB_MAP_ZOOM_FULL:	return( tb_map_zoom_full_xpm );
+	case ID_IMG_TB_MAP_ZOOM_LAST:	return( tb_map_zoom_last_xpm );
+	case ID_IMG_TB_MAP_ZOOM_NEXT:	return( tb_map_zoom_next_xpm );
+	case ID_IMG_TB_MAP_ZOOM_SELECTION:	return( tb_map_zoom_selection_xpm );
+	case ID_IMG_TB_OPEN:	return( tb_open_xpm );
+	case ID_IMG_TB_OPEN_GRID:	return( tb_open_grid_xpm );
+	case ID_IMG_TB_OPEN_MODULE:	return( tb_open_module_xpm );
+	case ID_IMG_TB_OPEN_SHAPES:	return( tb_open_shapes_xpm );
+	case ID_IMG_TB_OPEN_TABLE:	return( tb_open_table_xpm );
+	case ID_IMG_TB_OPEN_TIN:	return( tb_open_tin_xpm );
+	case ID_IMG_TB_SAVE:	return( tb_save_xpm );
+	case ID_IMG_TB_SCATTERPLOT_PARAMETERS:	return( tb_scatterplot_parameters_xpm );
+	case ID_IMG_TB_SHOW:	return( tb_show_xpm );
+	case ID_IMG_TB_TABLE_COL_ADD:	return( tb_table_col_add_xpm );
+	case ID_IMG_TB_TABLE_COL_DEL:	return( tb_table_col_del_xpm );
+	case ID_IMG_TB_TABLE_ROW_ADD:	return( tb_table_row_add_xpm );
+	case ID_IMG_TB_TABLE_ROW_DEL:	return( tb_table_row_del_xpm );
+	case ID_IMG_TB_TABLE_ROW_DEL_ALL:	return( tb_table_row_del_all_xpm );
+	case ID_IMG_TB_TABLE_ROW_INS:	return( tb_table_row_ins_xpm );
+	case ID_IMG_TB_WKSP:	return( tb_wksp_xpm );
+
+	case ID_IMG_WKSP_DATA_MANAGER:	return( wksp_data_manager_xpm );
+	case ID_IMG_WKSP_GRID:	return( wksp_grid_xpm );
+	case ID_IMG_WKSP_GRID_MANAGER:	return( wksp_grid_manager_xpm );
+	case ID_IMG_WKSP_GRID_SYSTEM:	return( wksp_grid_system_xpm );
+	case ID_IMG_WKSP_MAP:	return( wksp_map_xpm );
+	case ID_IMG_WKSP_MAP_MANAGER:	return( wksp_map_manager_xpm );
+	case ID_IMG_WKSP_MODULE:	return( wksp_module_xpm );
+	case ID_IMG_WKSP_MODULE_LIBRARY:	return( wksp_module_library_xpm );
+	case ID_IMG_WKSP_MODULE_MANAGER:	return( wksp_module_manager_xpm );
+	case ID_IMG_WKSP_NOITEMS:	return( wksp_noitems_xpm );
+	case ID_IMG_WKSP_SHAPES_LINE:	return( wksp_shapes_line_xpm );
+	case ID_IMG_WKSP_SHAPES_MANAGER:	return( wksp_shapes_manager_xpm );
+	case ID_IMG_WKSP_SHAPES_POINT:	return( wksp_shapes_point_xpm );
+	case ID_IMG_WKSP_SHAPES_POINTS:	return( wksp_shapes_points_xpm );
+	case ID_IMG_WKSP_SHAPES_POLYGON:	return( wksp_shapes_polygon_xpm );
+	case ID_IMG_WKSP_TABLE:	return( wksp_table_xpm );
+	case ID_IMG_WKSP_TABLE_MANAGER:	return( wksp_table_manager_xpm );
+	case ID_IMG_WKSP_TIN:	return( wksp_tin_xpm );
+	case ID_IMG_WKSP_TIN_MANAGER:	return( wksp_tin_manager_xpm );
+	case ID_IMG_WKSP_POINTCLOUD:	return( wksp_shapes_points_xpm );
+	case ID_IMG_WKSP_POINTCLOUD_MANAGER:	return( wksp_shapes_points_xpm );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxImage		IMG_Get_Image(int ID_IMG)
+{
+	wxBitmap	BMP(IMG_Get_XPM(ID_IMG));
+	wxImage		Image(BMP.ConvertToImage());
+
+//	wxImage	Image((const wxChar **)IMG_Get_XPM(ID_IMG));
+
+//	Image.SetMaskColour(192, 192, 192);
+
+	return( Image );
+}
+
+wxImage		IMG_Get_Image(int ID_IMG, int size)
+{
+	return( IMG_Get_Image(ID_IMG).Rescale(size, size) );
+}
+
+//---------------------------------------------------------
+wxBitmap	IMG_Get_Bitmap(int ID_IMG)
+{
+	return( wxBitmap(IMG_Get_XPM(ID_IMG)) );
+}
+
+wxBitmap	IMG_Get_Bitmap(int ID_IMG, int size)
+{
+	return( wxBitmap(IMG_Get_Image(ID_IMG, size)) );
+}
+
+//---------------------------------------------------------
+wxIcon		IMG_Get_Icon(int ID_IMG)
+{
+	return( wxIcon(IMG_Get_XPM(ID_IMG)) );
+}
+
+//---------------------------------------------------------
+wxCursor	IMG_Get_Cursor(int ID_IMG)
+{
+	wxImage	Image(IMG_Get_Image(ID_IMG));
+
+	Image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 15);
+	Image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 15);
+
+	return( wxCursor(Image) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/res_images.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,240 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     RES_Images.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Images_H
+#define _HEADER_INCLUDED__SAGA_GUI__RES_Images_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/bitmap.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum ID_IMAGES
+{
+	ID_IMG_DEFAULT,
+	ID_IMG_NB_ACTIVE_ATTRIBUTES,
+	ID_IMG_NB_ACTIVE_DESCRIPTION,
+	ID_IMG_NB_ACTIVE_HISTORY,
+	ID_IMG_NB_ACTIVE_LEGEND,
+	ID_IMG_NB_ACTIVE_PARAMETERS,	
+	ID_IMG_NB_ACTIVE_HTMLEXTRAINFO,
+	ID_IMG_NB_INFO_ERROR,
+	ID_IMG_NB_INFO_EXECUTION,
+	ID_IMG_NB_INFO_MESSAGES,
+	ID_IMG_NB_WKSP_DATA,
+	ID_IMG_NB_WKSP_DATA_BUTTONS,
+	ID_IMG_NB_WKSP_MAPS,
+	ID_IMG_NB_WKSP_MAPS_BUTTONS,
+	ID_IMG_NB_WKSP_MODULES,
+	ID_IMG_NB_WKSP_THUMBNAILS,
+	ID_IMG_NB_WKSP_TREEVIEW,
+	ID_IMG_SAGA_ICON_16,
+	ID_IMG_SAGA_ICON_32,
+	ID_IMG_SAGA_SPLASH,
+	ID_IMG_WND_DIAGRAM,
+	ID_IMG_WND_HISTOGRAM,
+	ID_IMG_WND_LAYOUT,
+	ID_IMG_WND_MAP,
+	ID_IMG_WND_MAP3D,
+	ID_IMG_WND_SCATTERPLOT,
+	ID_IMG_WND_TABLE,
+
+	ID_IMG_CRS_EDIT_POINT_ADD,
+	ID_IMG_CRS_EDIT_POINT_MOVE,
+	ID_IMG_CRS_HAND,
+	ID_IMG_CRS_HAND_GRAP,
+	ID_IMG_CRS_INFO,
+	ID_IMG_CRS_MAGNIFIER,
+	ID_IMG_CRS_SELECT,
+
+	ID_IMG_TB_ACTIVE,
+	ID_IMG_TB_DELETE,
+	ID_IMG_TB_DIAGRAM_PARAMETERS,
+	ID_IMG_TB_EDIT_SHAPE_ADD,
+	ID_IMG_TB_EDIT_SHAPE_ADD_PART,
+	ID_IMG_TB_EDIT_SHAPE_DEL,
+	ID_IMG_TB_EDIT_SHAPE_DEL_PART,
+	ID_IMG_TB_EDIT_SHAPE_DEL_POINT,
+	ID_IMG_TB_EDIT_SHAPE_SELECT,
+	ID_IMG_TB_HELP,
+	ID_IMG_TB_HISTOGRAM_AS_TABLE,
+	ID_IMG_TB_HISTOGRAM_CUMULATIVE,
+	ID_IMG_TB_INFO,
+	ID_IMG_TB_LAYOUT_PAGE_SETUP,
+	ID_IMG_TB_LAYOUT_PRINT,
+	ID_IMG_TB_LAYOUT_PRINT_PREVIEW,
+	ID_IMG_TB_LAYOUT_PRINT_SETUP,
+	ID_IMG_TB_MAP3D_CENTRAL_LESS,
+	ID_IMG_TB_MAP3D_CENTRAL_MORE,
+	ID_IMG_TB_MAP3D_EXAGGERATE_LESS,
+	ID_IMG_TB_MAP3D_EXAGGERATE_MORE,
+	ID_IMG_TB_MAP3D_INTERPOLATED,
+	ID_IMG_TB_MAP3D_PROPERTIES,
+	ID_IMG_TB_MAP3D_ROTATE_X_LESS,
+	ID_IMG_TB_MAP3D_ROTATE_X_MORE,
+	ID_IMG_TB_MAP3D_ROTATE_Z_LESS,
+	ID_IMG_TB_MAP3D_ROTATE_Z_MORE,
+	ID_IMG_TB_MAP3D_SHIFT_X_LESS,
+	ID_IMG_TB_MAP3D_SHIFT_X_MORE,
+	ID_IMG_TB_MAP3D_SHIFT_Y_LESS,
+	ID_IMG_TB_MAP3D_SHIFT_Y_MORE,
+	ID_IMG_TB_MAP3D_SHIFT_Z_LESS,
+	ID_IMG_TB_MAP3D_SHIFT_Z_MORE,
+	ID_IMG_TB_MAP3D_STEREO,
+	ID_IMG_TB_MAP_3D_SHOW,
+	ID_IMG_TB_MAP_LAYOUT_SHOW,
+	ID_IMG_TB_MAP_LEGEND_HORIZONTAL,
+	ID_IMG_TB_MAP_LEGEND_VERTICAL,
+	ID_IMG_TB_MAP_MODE_DISTANCE,
+	ID_IMG_TB_MAP_MODE_PAN,
+	ID_IMG_TB_MAP_MODE_SELECT,
+	ID_IMG_TB_MAP_MODE_ZOOM,
+	ID_IMG_TB_MAP_SYNCHRONIZE,
+	ID_IMG_TB_MAP_ZOOM_ACTIVE,
+	ID_IMG_TB_MAP_ZOOM_FULL,
+	ID_IMG_TB_MAP_ZOOM_LAST,
+	ID_IMG_TB_MAP_ZOOM_NEXT,
+	ID_IMG_TB_MAP_ZOOM_SELECTION,
+	ID_IMG_TB_OPEN,
+	ID_IMG_TB_OPEN_GRID,
+	ID_IMG_TB_OPEN_MODULE,
+	ID_IMG_TB_OPEN_SHAPES,
+	ID_IMG_TB_OPEN_TABLE,
+	ID_IMG_TB_OPEN_TIN,
+	ID_IMG_TB_OPEN_POINTCLOUD,
+	ID_IMG_TB_SAVE,
+	ID_IMG_TB_SCATTERPLOT_PARAMETERS,
+	ID_IMG_TB_SHOW,
+	ID_IMG_TB_TABLE_COL_ADD,
+	ID_IMG_TB_TABLE_COL_DEL,
+	ID_IMG_TB_TABLE_ROW_ADD,
+	ID_IMG_TB_TABLE_ROW_DEL,
+	ID_IMG_TB_TABLE_ROW_DEL_ALL,
+	ID_IMG_TB_TABLE_ROW_INS,
+	ID_IMG_TB_WKSP,
+
+	ID_IMG_WKSP_DATA_MANAGER,
+	ID_IMG_WKSP_GRID,
+	ID_IMG_WKSP_GRID_MANAGER,
+	ID_IMG_WKSP_GRID_SYSTEM,
+	ID_IMG_WKSP_MAP,
+	ID_IMG_WKSP_MAP_MANAGER,
+	ID_IMG_WKSP_MODULE,
+	ID_IMG_WKSP_MODULE_LIBRARY,
+	ID_IMG_WKSP_MODULE_MANAGER,
+	ID_IMG_WKSP_NOITEMS,
+	ID_IMG_WKSP_SHAPES_LINE,
+	ID_IMG_WKSP_SHAPES_MANAGER,
+	ID_IMG_WKSP_SHAPES_POINT,
+	ID_IMG_WKSP_SHAPES_POINTS,
+	ID_IMG_WKSP_SHAPES_POLYGON,
+	ID_IMG_WKSP_TABLE,
+	ID_IMG_WKSP_TABLE_MANAGER,
+	ID_IMG_WKSP_TIN,
+	ID_IMG_WKSP_TIN_MANAGER,
+	ID_IMG_WKSP_POINTCLOUD,
+	ID_IMG_WKSP_POINTCLOUD_MANAGER
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define IMG_SIZE_NOTEBOOK			16
+#define IMG_SIZE_TREECTRL			16
+
+//---------------------------------------------------------
+#define IMG_ADD_TO_NOTEBOOK(id)		GetImageList()->Add(IMG_Get_Bitmap(id, IMG_SIZE_NOTEBOOK));
+#define IMG_ADD_TO_TREECTRL(id)		GetImageList()->Add(IMG_Get_Bitmap(id, IMG_SIZE_TREECTRL));
+
+//---------------------------------------------------------
+wxImage			IMG_Get_Image	(int ID_IMG);
+wxImage			IMG_Get_Image	(int ID_IMG, int size);
+wxBitmap		IMG_Get_Bitmap	(int ID_IMG);
+wxBitmap		IMG_Get_Bitmap	(int ID_IMG, int size);
+wxIcon			IMG_Get_Icon	(int ID_IMG);
+wxCursor		IMG_Get_Cursor	(int ID_IMG);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__RES_Images_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,345 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      SAGA.cpp                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/config.h>
+#include <wx/fileconf.h>
+#include <wx/image.h>
+#include <wx/splash.h>
+#include <wx/filename.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "res_images.h"
+
+#include "saga.h"
+#include "saga_frame.h"
+
+#include "wksp.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSAGA	*g_pSAGA	= NULL;
+
+//---------------------------------------------------------
+IMPLEMENT_APP(CSAGA)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CSAGA, wxApp)
+	EVT_KEY_DOWN		(CSAGA::On_Key_Down)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SAGA_GUI_VERSION		wxT("2.0.4")
+#define SAGA_GUI_BUILD			wxT("20090929")
+
+//---------------------------------------------------------
+const wxChar *	SAGA_GUI_Get_Version(void)
+{
+	return( SAGA_GUI_VERSION );
+}
+
+//---------------------------------------------------------
+const wxChar *	SAGA_GUI_Get_Build(void)
+{
+	return( SAGA_GUI_BUILD );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSAGA::CSAGA(void)
+{}
+
+//---------------------------------------------------------
+CSAGA::~CSAGA(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSAGA::OnInit(void)
+{
+	//-----------------------------------------------------
+	SetVendorName		(wxT("SAGA-GIS.org"));
+	SetAppName			(wxT("SAGA"));
+
+	g_pSAGA				= this;
+
+	m_Process_bContinue	= true;
+
+	_Init_Config();
+
+	wxInitAllImageHandlers();
+
+	//-----------------------------------------------------
+	long			iLogo;
+	wxSplashScreen	*pLogo;
+
+	iLogo	= CONFIG_Read(wxT("/MODULES"), wxT("START_LOGO"), iLogo) ? iLogo : 1;
+
+	switch( iLogo )
+	{
+	default:
+		pLogo	= NULL;
+		break;
+
+	case 1:
+	case 3:
+		pLogo	= new wxSplashScreen(IMG_Get_Bitmap(ID_IMG_SAGA_SPLASH), wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_NO_TIMEOUT, 0, NULL, -1);
+		break;
+
+	case 2:
+		pLogo	= new wxSplashScreen(IMG_Get_Bitmap(ID_IMG_SAGA_SPLASH), wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 20000, NULL, -1);
+		break;
+	}
+
+	wxYield();
+
+	//-----------------------------------------------------
+	SG_Get_Translator() .Create(SG_File_Make_Path(Get_App_Path(), wxT("saga"), wxT("lng")), false);
+	SG_Get_Projections().Create(SG_File_Make_Path(Get_App_Path(), wxT("saga"), wxT("srs")));
+
+	SetTopWindow(new CSAGA_Frame());
+
+	//-----------------------------------------------------
+	if( argc > 1 )
+	{
+		for(int i=1; i<argc; i++)
+		{
+			g_pWKSP->Open(argv[i]);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( pLogo && iLogo == 1 )
+	{
+		pLogo->Destroy();
+
+		wxYield();
+	}
+
+	//-----------------------------------------------------
+	g_pSAGA_Frame->Show_Tips(false);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+int CSAGA::OnExit(void)
+{
+	delete(wxConfigBase::Set((wxConfigBase *)NULL));
+
+	return( 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA::_Init_Config(void)
+{
+	wxConfigBase	*pConfig;
+
+#if defined(_SAGA_MSW)
+	wxFileName	fConfig(Get_App_Path(), wxT("saga_gui"), wxT("ini"));
+
+	if(	( fConfig.FileExists() && (!fConfig.IsFileReadable() || !fConfig.IsFileWritable()))
+	||	(!fConfig.FileExists() && (!fConfig.IsDirReadable () || !fConfig.IsDirWritable ())) )
+	{
+		fConfig.Assign(wxFileName::GetTempDir(), wxT("saga_gui"), wxT("ini"));
+	}
+
+	pConfig = new wxFileConfig(wxEmptyString, wxEmptyString, fConfig.GetFullPath(), fConfig.GetFullPath(), wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_RELATIVE_PATH);
+#else
+	pConfig	= new wxConfig;
+#endif
+
+	wxConfigBase::Set(pConfig);
+
+	//-----------------------------------------------------
+	wxString	s;
+
+	if( !CONFIG_Read(wxT("Version"), wxT("Build"), s) || s.Cmp(SAGA_GUI_Get_Build()) )
+	{
+		long	l;
+
+		pConfig->SetPath(wxT("/"));
+
+		while( pConfig->GetFirstGroup(s, l) )
+		{
+			pConfig->DeleteGroup(s);
+		}
+
+		pConfig->Flush();
+
+		CONFIG_Write(wxT("Version"), wxT("Build"), SAGA_GUI_Get_Build());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CSAGA::Get_App_Path(void)
+{
+	return( SG_File_Get_Path(argv[0]).c_str() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA::On_Key_Down(wxKeyEvent &event)
+{
+	switch( event.GetKeyCode() )
+	{
+	default:
+		event.Skip();
+		break;
+
+	case WXK_ESCAPE:
+		m_Process_bContinue	= false;
+		break;
+	}
+}
+
+//---------------------------------------------------------
+bool CSAGA::Process_Wait(void)
+{
+	while( Pending() )
+	{
+		Dispatch();
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CSAGA::Process_Set_Okay(bool bOkay)
+{
+	m_Process_bContinue	= bOkay;
+
+	return( m_Process_bContinue );
+}
+
+//---------------------------------------------------------
+bool CSAGA::Process_Get_Okay(void)
+{
+	static bool	bYield	= false;
+
+	if( !bYield )
+	{
+		bYield	= true;
+
+	//	Yield();
+	//	wxSafeYield(g_pSAGA_Frame);
+		Process_Wait();
+
+		bYield	= false;
+	}
+
+	return( m_Process_bContinue );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        SAGA.h                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _SAGA_GUI__SAGA_H
+#define _SAGA_GUI__SAGA_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/app.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar *	SAGA_GUI_Get_Version	(void);
+const wxChar *	SAGA_GUI_Get_Build		(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSAGA : public wxApp
+{
+public:
+	CSAGA(void);
+	virtual ~CSAGA(void);
+
+	bool						OnInit				(void);
+	int							OnExit				(void);
+
+	wxString					Get_App_Path		(void);
+
+	void						On_Key_Down			(wxKeyEvent &event);
+
+	bool						Process_Wait		(void);
+	bool						Process_Set_Okay	(bool bOkay);
+	bool						Process_Get_Okay	(void);
+
+
+private:
+
+	bool						m_Process_bContinue;
+
+
+	void						_Init_Config		(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CSAGA					*g_pSAGA;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _SAGA_GUI__SAGA_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    SAGA_Frame.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/frame.h>
+#include <wx/filename.h>
+#include <wx/statusbr.h>
+#include <wx/icon.h>
+#include <wx/gauge.h>
+#include <wx/choicdlg.h>
+#include <wx/toolbar.h>
+#include <wx/tipdlg.h>
+#include <wx/aui/aui.h>
+
+#include <saga_api/saga_api.h>
+
+#include "callback.h"
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_dialogs.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "saga.h"
+#include "saga_frame.h"
+#include "saga_frame_droptarget.h"
+
+#include "info.h"
+#include "wksp.h"
+#include "active.h"
+
+#include "wksp_module_manager.h"
+#include "wksp_module.h"
+#include "wksp_module_menu.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_data_menu_files.h"
+
+#include "wksp_map_manager.h"
+
+#include "view_map.h"
+#include "view_map_3d.h"
+#include "view_table.h"
+#include "view_table_diagram.h"
+#include "view_histogram.h"
+#include "view_scatterplot.h"
+#include "view_layout.h"
+
+#include "dlg_about.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _DEBUG
+	#define SAGA_CAPTION	wxT("SAGA [Debug]")
+#else
+	#define SAGA_CAPTION	wxT("SAGA")
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSAGA_Frame_StatusBar : public wxStatusBar
+{
+public:
+	CSAGA_Frame_StatusBar(wxWindow *parent, wxWindowID id, long style = wxST_SIZEGRIP, const wxString& name = wxT("statusBar"))
+		: wxStatusBar(parent, id, style, name)
+	{
+		m_pProgressBar	= new wxGauge(this, ID_WND_PROGRESSBAR, 100);
+	}
+
+	void		On_Size		(wxSizeEvent     &event)
+	{
+		wxRect	r;
+
+		if( m_pProgressBar && GetFieldRect(STATUSBAR_PROGRESS, r) )
+		{
+			m_pProgressBar->SetSize(r);
+		}
+
+		event.Skip();
+	}
+
+	wxGauge		*m_pProgressBar;
+
+	DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CSAGA_Frame_StatusBar, wxStatusBar)
+	EVT_SIZE			(CSAGA_Frame_StatusBar::On_Size)
+END_EVENT_TABLE()
+
+//---------------------------------------------------------
+wxStatusBar * CSAGA_Frame::OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name)
+{
+	CSAGA_Frame_StatusBar	*sb	= new CSAGA_Frame_StatusBar(this, id, style, name);
+
+	sb->SetFieldsCount(number);
+
+	return( sb );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSAGA_Frame	*g_pSAGA_Frame	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CSAGA_Frame, wxMDIParentFrame)
+	EVT_CLOSE			(CSAGA_Frame::On_Close)
+	EVT_SIZE			(CSAGA_Frame::On_Size)
+
+	EVT_MENU			(ID_CMD_FRAME_QUIT			, CSAGA_Frame::On_Quit)
+	EVT_MENU			(ID_CMD_FRAME_HELP			, CSAGA_Frame::On_Help)
+	EVT_MENU			(ID_CMD_FRAME_ABOUT			, CSAGA_Frame::On_About)
+	EVT_MENU			(ID_CMD_FRAME_TIPS			, CSAGA_Frame::On_Tips)
+
+	EVT_MENU			(ID_CMD_FRAME_CASCADE		, CSAGA_Frame::On_Frame_Cascade)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_CASCADE		, CSAGA_Frame::On_Frame_Cascade_UI)
+	EVT_MENU			(ID_CMD_FRAME_TILE_HORZ		, CSAGA_Frame::On_Frame_hTile)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_TILE_HORZ		, CSAGA_Frame::On_Frame_hTile_UI)
+	EVT_MENU			(ID_CMD_FRAME_TILE_VERT		, CSAGA_Frame::On_Frame_vTile)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_TILE_VERT		, CSAGA_Frame::On_Frame_vTile_UI)
+	EVT_MENU			(ID_CMD_FRAME_ARRANGEICONS	, CSAGA_Frame::On_Frame_ArrangeIcons)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_ARRANGEICONS	, CSAGA_Frame::On_Frame_ArrangeIcons_UI)
+	EVT_MENU			(ID_CMD_FRAME_NEXT			, CSAGA_Frame::On_Frame_Next)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_NEXT			, CSAGA_Frame::On_Frame_Next_UI)
+	EVT_MENU			(ID_CMD_FRAME_PREVIOUS		, CSAGA_Frame::On_Frame_Previous)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_PREVIOUS		, CSAGA_Frame::On_Frame_Previous_UI)
+	EVT_MENU			(ID_CMD_FRAME_CLOSE			, CSAGA_Frame::On_Frame_Close)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_CLOSE			, CSAGA_Frame::On_Frame_Close_UI)
+	EVT_MENU			(ID_CMD_FRAME_CLOSE_ALL		, CSAGA_Frame::On_Frame_Close_All)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_CLOSE_ALL		, CSAGA_Frame::On_Frame_Close_All_UI)
+
+	EVT_MENU			(ID_CMD_FRAME_WKSP_SHOW		, CSAGA_Frame::On_WKSP_Show)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_WKSP_SHOW		, CSAGA_Frame::On_WKSP_Show_UI)
+	EVT_MENU			(ID_CMD_FRAME_ACTIVE_SHOW	, CSAGA_Frame::On_Active_Show)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_ACTIVE_SHOW	, CSAGA_Frame::On_Active_Show_UI)
+	EVT_MENU			(ID_CMD_FRAME_INFO_SHOW		, CSAGA_Frame::On_INFO_Show)
+	EVT_UPDATE_UI		(ID_CMD_FRAME_INFO_SHOW		, CSAGA_Frame::On_INFO_Show_UI)
+
+	EVT_MENU_RANGE		(ID_CMD_WKSP_FIRST			, ID_CMD_WKSP_LAST		, CSAGA_Frame::On_Command_Workspace)
+	EVT_UPDATE_UI_RANGE	(ID_CMD_WKSP_FIRST			, ID_CMD_WKSP_LAST		, CSAGA_Frame::On_Command_Workspace_UI)
+	EVT_MENU_RANGE		(ID_CMD_MODULE_FIRST		, ID_CMD_MODULE_LAST	, CSAGA_Frame::On_Command_Module)
+	EVT_UPDATE_UI_RANGE	(ID_CMD_MODULE_FIRST		, ID_CMD_MODULE_LAST	, CSAGA_Frame::On_Command_Module_UI)
+
+	EVT_MENU_RANGE		(ID_CMD_CHILD_FIRST			, ID_CMD_CHILD_LAST		, CSAGA_Frame::On_Command_Child)
+	EVT_UPDATE_UI_RANGE	(ID_CMD_MAP_FIRST			, ID_CMD_MAP_LAST		, CSAGA_Frame::On_Command_Child_UI)
+	EVT_UPDATE_UI_RANGE	(ID_CMD_HISTOGRAM_FIRST		, ID_CMD_HISTOGRAM_LAST	, CSAGA_Frame::On_Command_Child_UI)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSAGA_Frame::CSAGA_Frame(void)
+	: wxMDIParentFrame(NULL, ID_WND_MAIN, SAGA_CAPTION, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE|wxHSCROLL|wxVSCROLL|wxFRAME_NO_WINDOW_MENU)
+{
+	//-----------------------------------------------------
+	g_pSAGA_Frame		= this;
+
+	m_nTopWindows		= 0;
+	m_pTopWindows		= NULL;
+
+	m_pINFO				= NULL;
+	m_pActive			= NULL;
+	m_pWKSP				= NULL;
+
+	SG_Set_UI_Callback	(Get_Callback());
+
+	SetIcon				(IMG_Get_Icon(ID_IMG_SAGA_ICON_32));
+
+	SetDropTarget		(new CSAGA_Frame_DropTarget);
+
+	//-----------------------------------------------------
+	int		STATUSBAR_Sizes[STATUSBAR_COUNT]	= {	-1, -1, 90, 90, 90, -1	};
+
+	CreateStatusBar		(STATUSBAR_COUNT);
+	SetStatusWidths		(STATUSBAR_COUNT, STATUSBAR_Sizes);
+	SetStatusBarPane	(STATUSBAR_DEFAULT);
+	StatusBar_Set_Text	(LNG("[VAL] ready"));
+
+	m_pProgressBar		= ((CSAGA_Frame_StatusBar *)GetStatusBar())->m_pProgressBar;
+
+	//-----------------------------------------------------
+	m_pLayout			= new wxAuiManager(this);
+
+	m_pLayout->GetArtProvider()->SetColor	(wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR,
+		wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION)
+	);
+
+	m_pLayout->GetArtProvider()->SetColor	(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR,
+		wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)
+	);
+
+	m_pLayout->GetArtProvider()->SetMetric	(wxAUI_DOCKART_GRADIENT_TYPE	, wxAUI_GRADIENT_NONE);
+	m_pLayout->GetArtProvider()->SetMetric	(wxAUI_DOCKART_CAPTION_SIZE		, 14);
+
+	m_pLayout->SetFlags(m_pLayout->GetFlags() ^ wxAUI_MGR_TRANSPARENT_DRAG);
+//	m_pLayout->SetFlags(m_pLayout->GetFlags() ^ wxAUI_MGR_ALLOW_ACTIVE_PANE);
+
+	//-----------------------------------------------------
+	_Bar_Add(m_pINFO   = new CINFO  (this), 0);
+	_Bar_Add(m_pActive = new CACTIVE(this), 1);
+	_Bar_Add(m_pWKSP   = new CWKSP  (this), 2);
+
+	m_pINFO		->Add_Pages();
+	m_pActive	->Add_Pages();
+	m_pWKSP		->Add_Pages();
+
+	//-----------------------------------------------------
+	SetMenuBar(MB_Create(NULL));
+
+	//-----------------------------------------------------
+	m_pTB_Main			= 						  _Create_ToolBar();
+	m_pTB_Map			= CVIEW_Map				::_Create_ToolBar();
+	m_pTB_Map_3D		= CVIEW_Map_3D			::_Create_ToolBar();
+	m_pTB_Layout		= CVIEW_Layout			::_Create_ToolBar();
+	m_pTB_Table			= CVIEW_Table			::_Create_ToolBar();
+	m_pTB_Diagram		= CVIEW_Table_Diagram	::_Create_ToolBar();
+	m_pTB_Histogram		= CVIEW_Histogram		::_Create_ToolBar();
+	m_pTB_ScatterPlot	= CVIEW_ScatterPlot		::_Create_ToolBar();
+
+	//-----------------------------------------------------
+	m_pLayout->GetPane(GetClientWindow()).Show().Center();
+
+	wxString	s;
+
+	if( CONFIG_Read(wxT("/FL"), wxT("MANAGER"), s) )
+	{
+		m_pLayout->LoadPerspective(s);
+	}
+	else
+	{
+		m_pLayout->GetPane(m_pINFO  ).BestSize(400, 100).FloatingSize(600, 400).Bottom();
+		m_pLayout->GetPane(m_pActive).BestSize(250, 400).FloatingSize(250, 400).Right();
+		m_pLayout->GetPane(m_pWKSP  ).BestSize(250, 400).FloatingSize(250, 400).Left();
+	}
+
+	_Bar_Show(m_pTB_Main, true);
+
+	//-----------------------------------------------------
+	m_pLayout->Update();
+
+#if !defined(_SAGA_LINUX)
+	Show(true);
+#endif
+
+	int		x, y, dx, dy;
+	long	l;
+
+	x	= CONFIG_Read(wxT("/FL"), wxT("X" ), l) ? l : -1;
+	y	= CONFIG_Read(wxT("/FL"), wxT("Y" ), l) ? l : -1;
+	dx	= CONFIG_Read(wxT("/FL"), wxT("DX"), l) ? l : 800;
+	dy	= CONFIG_Read(wxT("/FL"), wxT("DY"), l) ? l : 600;
+
+	SetSize(x, y, dx, dy);
+
+	if( !(CONFIG_Read(wxT("/FL"), wxT("STATE"), l) && l == 0) )
+	{
+		Maximize();
+	}
+
+#if defined(_SAGA_LINUX)
+	Show(true);
+#endif
+
+	Update();
+
+	//-----------------------------------------------------
+	if( g_pSAGA->argc <= 1 && g_pData->Initialise() )
+	{
+		Refresh(false);
+	}
+}
+
+//---------------------------------------------------------
+CSAGA_Frame::~CSAGA_Frame(void)
+{
+	//-----------------------------------------------------
+	if( IsIconized() )
+	{
+		Iconize(false);
+	}
+
+	if( IsMaximized() )
+	{
+		CONFIG_Write(wxT("/FL"), wxT("STATE"), (long)1);
+	}
+	else
+	{
+		CONFIG_Write(wxT("/FL"), wxT("STATE"), (long)0);
+		CONFIG_Write(wxT("/FL"), wxT("X"    ), (long)GetPosition().x);
+		CONFIG_Write(wxT("/FL"), wxT("Y"    ), (long)GetPosition().y);
+		CONFIG_Write(wxT("/FL"), wxT("DX"   ), (long)GetSize().x);
+		CONFIG_Write(wxT("/FL"), wxT("DY"   ), (long)GetSize().y);
+	}
+
+	//-----------------------------------------------------
+	CONFIG_Write(wxT("/FL"), wxT("MANAGER"), m_pLayout->SavePerspective().c_str());
+
+	m_pLayout->UnInit();
+
+	delete(m_pLayout);
+
+	//-----------------------------------------------------
+	if( m_pTopWindows )
+	{
+		delete(m_pTopWindows);
+	}
+
+	SG_Set_UI_Callback(NULL);
+
+	g_pSAGA_Frame	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Close(wxCloseEvent &event)
+{
+	if( event.CanVeto() )
+	{
+		if( !g_pModule && DLG_Message_Confirm(ID_DLG_CLOSE) && g_pData->Close(true) )
+		{
+			g_pModules->Finalise();
+
+			Destroy();
+		}
+		else
+		{
+			if( g_pModule )
+			{
+				DLG_Message_Show(LNG("Please stop module execution before exiting SAGA."), LNG("Exit SAGA"));
+			}
+
+			event.Veto();
+		}
+	}
+	else
+	{
+		g_pModules->Finalise();
+
+		g_pData->Close(true);
+
+		event.Skip();
+	}
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Size(wxSizeEvent &event)
+{
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Quit(wxCommandEvent &WXUNUSED(event))
+{
+	Close(false);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Help(wxCommandEvent &WXUNUSED(event))
+{
+	DLG_Message_Show(
+		LNG("Currently no help files exist for SAGA.\nIt depends on your support, if you will find any help at this place in future!\nThanks a lot..."),
+		LNG("SAGA Help")
+	);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_About(wxCommandEvent &WXUNUSED(event))
+{
+	CDLG_About	dlg;
+
+	dlg.ShowModal();
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Tips(wxCommandEvent &WXUNUSED(event))
+{
+	Show_Tips(true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_Cascade(wxCommandEvent &WXUNUSED(event))
+{
+	Cascade();
+}
+
+void CSAGA_Frame::On_Frame_Cascade_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_hTile(wxCommandEvent &WXUNUSED(event))
+{
+	Tile(wxHORIZONTAL);
+}
+
+void CSAGA_Frame::On_Frame_hTile_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_vTile(wxCommandEvent &WXUNUSED(event))
+{
+	Tile(wxVERTICAL);
+}
+
+void CSAGA_Frame::On_Frame_vTile_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_ArrangeIcons(wxCommandEvent &WXUNUSED(event))
+{
+	ArrangeIcons();
+}
+
+void CSAGA_Frame::On_Frame_ArrangeIcons_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_Next(wxCommandEvent &WXUNUSED(event))
+{
+	ActivateNext();
+}
+
+void CSAGA_Frame::On_Frame_Next_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_Previous(wxCommandEvent &WXUNUSED(event))
+{
+	ActivatePrevious();
+}
+
+void CSAGA_Frame::On_Frame_Previous_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_Close(wxCommandEvent &WXUNUSED(event))
+{
+	if( GetActiveChild() != NULL )
+	{
+		GetActiveChild()->Close();
+	}
+}
+
+void CSAGA_Frame::On_Frame_Close_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Frame_Close_All(wxCommandEvent &WXUNUSED(event))
+{
+	while( GetActiveChild() != NULL )
+	{
+		delete(GetActiveChild());
+	}
+}
+
+void CSAGA_Frame::On_Frame_Close_All_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(GetActiveChild() != NULL);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_WKSP_Show(wxCommandEvent &WXUNUSED(event))
+{
+	_Bar_Toggle(m_pWKSP);
+}
+
+void CSAGA_Frame::On_WKSP_Show_UI(wxUpdateUIEvent &event)
+{
+	event.Check(m_pWKSP->IsShown() && m_pLayout->GetPane(m_pWKSP).IsShown());
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Active_Show(wxCommandEvent &WXUNUSED(event))
+{
+	_Bar_Toggle(m_pActive);
+}
+
+void CSAGA_Frame::On_Active_Show_UI(wxUpdateUIEvent &event)
+{
+	event.Check(m_pActive->IsShown() && m_pLayout->GetPane(m_pActive).IsShown());
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_INFO_Show(wxCommandEvent &WXUNUSED(event))
+{
+	_Bar_Toggle(m_pINFO);
+}
+
+void CSAGA_Frame::On_INFO_Show_UI(wxUpdateUIEvent &event)
+{
+	event.Check(m_pINFO->IsShown() && m_pLayout->GetPane(m_pINFO).IsShown());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Command_Workspace(wxCommandEvent &event)
+{
+	m_pWKSP->On_Command(event);
+}
+
+void CSAGA_Frame::On_Command_Workspace_UI(wxUpdateUIEvent &event)
+{
+	m_pWKSP->On_Command_UI(event);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Command_Module(wxCommandEvent &event)
+{
+	m_pWKSP->On_Command_Module(event);
+}
+
+void CSAGA_Frame::On_Command_Module_UI(wxUpdateUIEvent &event)
+{
+	m_pWKSP->On_Command_UI_Module(event);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Command_Child(wxCommandEvent &event)
+{
+	wxMDIChildFrame	*pChild;
+
+	if( (pChild = GetActiveChild()) != NULL )
+	{
+		pChild->AddPendingEvent(event);
+	}
+}
+
+void CSAGA_Frame::On_Command_Child_UI(wxUpdateUIEvent &event)
+{
+	CVIEW_Base	*pChild;
+
+	if( (pChild = wxDynamicCast(GetActiveChild(), CVIEW_Base)) != NULL )
+	{
+		pChild->On_Command_UI(event);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::Show_Tips(bool bShow)
+{
+	bool			bTip;
+	long			iTip;
+	wxFileName		fTip(g_pSAGA->Get_App_Path(), wxT("saga_gui"), wxT("tip"));
+	wxTipProvider	*pTip;
+
+	bTip	= CONFIG_Read(wxT("/TIPS"), wxT("ATSTART"), bTip) ? bTip : true;
+
+	if( bShow || (bTip && fTip.FileExists()) )
+	{
+		iTip	= CONFIG_Read(wxT("/TIPS"), wxT("CURRENT"), iTip) ? iTip : 0;
+		pTip	= wxCreateFileTipProvider(fTip.GetFullPath(), iTip);
+
+		bTip	= wxShowTip(this, pTip, bTip);
+		iTip	= pTip->GetCurrentTip();
+
+		CONFIG_Write(wxT("/TIPS"), wxT("ATSTART"), bTip);
+		CONFIG_Write(wxT("/TIPS"), wxT("CURRENT"), iTip);
+
+		delete(pTip);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSAGA_Frame::Process_Get_Okay(bool bBlink)
+{
+	if( bBlink )
+	{
+		m_pProgressBar->Pulse();
+	}
+
+	return( g_pSAGA->Process_Get_Okay() );
+}
+
+//---------------------------------------------------------
+bool CSAGA_Frame::Process_Set_Okay(bool bOkay)
+{
+	StatusBar_Set_Text(LNG("[VAL] ready"));
+
+	ProgressBar_Set_Position(0);
+
+	g_pSAGA->Process_Set_Okay(bOkay);
+
+	return( bOkay );
+}
+
+//---------------------------------------------------------
+bool CSAGA_Frame::ProgressBar_Set_Position(int Position)
+{
+	if( Position < 0 )
+	{
+		Position	= 0;
+	}
+	else if( Position > 100 )
+	{
+		Position	= 100;
+	}
+
+	m_pProgressBar->SetValue(Position);
+
+	return( Process_Get_Okay(false) );
+}
+
+//---------------------------------------------------------
+bool CSAGA_Frame::ProgressBar_Set_Position(double Position, double Range)
+{
+	return( ProgressBar_Set_Position(Range != 0.0 ? (int)(100.0 * Position / Range) : 0) );
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::StatusBar_Set_Text(const wxChar *Text, int iPane)
+{
+	if( iPane < 0 || iPane >= STATUSBAR_PROGRESS )
+	{
+		iPane	= STATUSBAR_DEFAULT;
+	}
+
+	if( iPane == STATUSBAR_ACTIVE )
+	{
+		Set_Pane_Caption(m_pActive, Text && SG_STR_LEN(Text) > 0 ? Text : LNG("[CAP] Object Properties"));
+	}
+
+	SetStatusText(Text, iPane);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::Set_Project_Name(wxString Project_Name)
+{
+	if( Project_Name.Length() > 0 )
+	{
+		SetTitle(wxString::Format(wxT("%s [%s]"), SAGA_CAPTION, Project_Name.c_str()));
+	}
+	else
+	{
+		SetTitle(SAGA_CAPTION);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::Top_Window_Push(wxWindow *pWindow)
+{
+	if( pWindow )
+	{
+		for(int i=0; i<m_nTopWindows; i++)
+		{
+			if( m_pTopWindows[i] == pWindow )
+			{
+				return;
+			}
+		}
+
+		m_pTopWindows	= (wxWindow **)SG_Realloc(m_pTopWindows, (m_nTopWindows + 1) * sizeof(wxWindow *));
+		m_pTopWindows[m_nTopWindows++]	= pWindow;
+	}
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::Top_Window_Pop(wxWindow *pWindow)
+{
+	if( pWindow )
+	{
+		int		i, j;
+
+		for(i=j=0; j<m_nTopWindows; i++, j++)
+		{
+			if( m_pTopWindows[i] == pWindow )
+				j++;
+
+			if( i < j && j < m_nTopWindows )
+				m_pTopWindows[i]	= m_pTopWindows[j];
+		}
+
+		if( i < j )
+		{
+			m_nTopWindows--;
+			m_pTopWindows	= (wxWindow **)SG_Realloc(m_pTopWindows, m_nTopWindows * sizeof(wxWindow *));
+		}
+	}
+}
+
+//---------------------------------------------------------
+wxWindow * CSAGA_Frame::Top_Window_Get(void)
+{
+	return( m_nTopWindows > 0 ? m_pTopWindows[m_nTopWindows - 1] : this );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::On_Child_Activates(CVIEW_Base *pChild, bool bActivates)
+{
+	switch( pChild->Get_View_ID() )
+	{
+	case ID_VIEW_TABLE:
+		_Bar_Show(m_pTB_Table		, bActivates);
+		break;
+
+	case ID_VIEW_TABLE_DIAGRAM:
+		_Bar_Show(m_pTB_Diagram		, bActivates);
+		break;
+
+	case ID_VIEW_MAP:
+		_Bar_Show(m_pTB_Map			, bActivates);
+		break;
+
+	case ID_VIEW_MAP_3D:
+		_Bar_Show(m_pTB_Map_3D		, bActivates);
+		break;
+
+	case ID_VIEW_HISTOGRAM:
+		_Bar_Show(m_pTB_Histogram	, bActivates);
+		break;
+
+	case ID_VIEW_SCATTERPLOT:
+		_Bar_Show(m_pTB_ScatterPlot	, bActivates);
+		break;
+
+	case ID_VIEW_LAYOUT:
+		_Bar_Show(m_pTB_Layout		, bActivates);
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						MenuBar							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenuBar * CSAGA_Frame::MB_Create(CVIEW_Base *pChild)
+{
+	wxMenu		*pMenu;
+	wxMenuBar	*pMenuBar	= new wxMenuBar;
+
+	//-----------------------------------------------------
+	// 1. File...
+
+	pMenu		= new wxMenu;
+
+	g_pData->Get_FileMenus()->Add(pMenu);
+
+	pMenuBar->Append(pMenu, LNG("[MNU] File"));
+
+
+	//-----------------------------------------------------
+	// 2. Modules...
+
+	pMenu		= new wxMenu;
+
+	g_pModules->Get_Modules_Menu()->Add(pMenu);
+
+	pMenuBar->Append(pMenu, LNG("[MNU] Modules"));
+
+
+	//-----------------------------------------------------
+	// 3. Window...
+
+	pMenu		= new wxMenu;
+
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_FRAME_WKSP_SHOW);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_FRAME_ACTIVE_SHOW);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_FRAME_INFO_SHOW);
+
+#ifdef __WXMSW__
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_CASCADE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_TILE_HORZ);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_TILE_VERT);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_ARRANGEICONS);
+#endif	// #ifdef __WXMSW__
+
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_NEXT);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_PREVIOUS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_CLOSE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_CLOSE_ALL);
+
+	pMenuBar->Append(pMenu, LNG("[MNU] Window"));
+
+
+	//-----------------------------------------------------
+	// 4. Help...
+
+	pMenu		= new wxMenu;
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_HELP);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_TIPS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_ABOUT);
+
+	pMenuBar->Append(pMenu, LNG("[MNU] ?"));
+
+
+	//-----------------------------------------------------
+	return( pMenuBar );
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::MB_Remove(wxMenu *pMenu_File, wxMenu *pMenu_Modules)
+{
+	g_pData		->Get_FileMenus()		->Del(pMenu_File);
+	g_pModules	->Get_Modules_Menu()	->Del(pMenu_Modules);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSAGA_Frame::Set_Pane_Caption(wxWindow *pWindow, wxString Caption)
+{
+	if( m_pLayout && pWindow )
+	{
+		m_pLayout->GetPane(pWindow).Caption(Caption);
+		m_pLayout->Update();
+	}
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::_Bar_Add(wxWindow *pWindow, int Position)
+{
+	m_pLayout->AddPane(pWindow, wxAuiPaneInfo()
+		.Name		(pWindow->GetName())
+		.Caption	(pWindow->GetName())
+		.Layer		(0)
+		.Row		(0)
+		.Position	(0)
+		.MinSize	(100, 100)
+		.BestSize	(200, 100)
+	);
+
+	switch( Position )
+	{
+	default:
+	case 0:	m_pLayout->GetPane(pWindow).Bottom().FloatingSize(400, 200);	break;
+	case 1:	m_pLayout->GetPane(pWindow).Right ().FloatingSize(200, 400);	break;
+	case 2:	m_pLayout->GetPane(pWindow).Left  ().FloatingSize(200, 400);	break;
+	case 3:	m_pLayout->GetPane(pWindow).Top   ().FloatingSize(400, 200);	break;
+	}
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::_Bar_Toggle(wxWindow *pWindow)
+{
+	if( pWindow->IsShown() && m_pLayout->GetPane(pWindow).IsShown() )
+	{
+		m_pLayout->GetPane(pWindow).Hide();
+
+		if( m_pLayout->GetPane(pWindow).IsToolbar() )
+			pWindow->Hide();
+	}
+	else
+	{
+		if( m_pLayout->GetPane(pWindow).IsToolbar() )
+			pWindow->Show();
+
+		m_pLayout->GetPane(pWindow).Show();
+	}
+
+	m_pLayout->Update();
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::_Bar_Show(wxWindow *pWindow, bool bShow)
+{
+	if( pWindow && pWindow->IsShown() != bShow )
+	{
+		_Bar_Toggle(pWindow);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						ToolBar							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define TOOLBAR_SIZE_IMG		16
+
+//---------------------------------------------------------
+wxToolBarBase * CSAGA_Frame::TB_Create(int ID)
+{
+	wxToolBar	*pToolBar	= new wxToolBar(this, ID, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxTB_FLAT|wxTB_NODIVIDER);
+
+	pToolBar->SetToolBitmapSize(wxSize(TOOLBAR_SIZE_IMG, TOOLBAR_SIZE_IMG));
+
+	return( pToolBar );
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::TB_Add(wxToolBarBase *pToolBar, const wxChar *Name)
+{
+	pToolBar->Realize();
+	pToolBar->Hide();
+
+	m_pLayout->AddPane(pToolBar, wxAuiPaneInfo()
+	//	.Name			(pToolBar->GetName())
+		.Name			(Name)
+		.Caption		(Name)
+		.ToolbarPane	()
+		.Top			()
+		.LeftDockable	(false)
+		.RightDockable	(false)
+		.Hide			()
+		.BestSize		(pToolBar->GetBestSize())
+	);
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::TB_Add_Item(wxToolBarBase *pToolBar, bool bCheck, int Cmd_ID)
+{
+	if( bCheck )
+		((wxToolBar *)pToolBar)->AddTool(Cmd_ID, CMD_Get_Name(Cmd_ID), IMG_Get_Bitmap(CMD_Get_ImageID(Cmd_ID), TOOLBAR_SIZE_IMG), CMD_Get_Help(Cmd_ID), wxITEM_CHECK);
+	else
+		((wxToolBar *)pToolBar)->AddTool(Cmd_ID, CMD_Get_Name(Cmd_ID), IMG_Get_Bitmap(CMD_Get_ImageID(Cmd_ID), TOOLBAR_SIZE_IMG), CMD_Get_Help(Cmd_ID));
+}
+
+//---------------------------------------------------------
+void CSAGA_Frame::TB_Add_Separator(wxToolBarBase *pToolBar)
+{
+	((wxToolBar *)pToolBar)->AddSeparator();
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CSAGA_Frame::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= TB_Create(ID_TB_MAIN);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_WKSP_OPEN);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_FRAME_WKSP_SHOW);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_FRAME_ACTIVE_SHOW);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_FRAME_INFO_SHOW);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_FRAME_HELP);
+
+	TB_Add(pToolBar, LNG("[CAP] Standard"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,217 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     SAGA_Frame.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__SAGA_Frame_H
+#define _HEADER_INCLUDED__SAGA_GUI__SAGA_Frame_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/mdi.h>
+
+//---------------------------------------------------------
+class CSAGA_Frame_Layout;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSAGA_Frame : public wxMDIParentFrame
+{
+public:
+
+	CSAGA_Frame(void);
+	virtual ~CSAGA_Frame(void);
+
+	//-----------------------------------------------------
+	void						On_Close					(wxCloseEvent    &event);
+	void						On_Size						(wxSizeEvent     &event);
+
+	//-----------------------------------------------------
+	void						On_Quit						(wxCommandEvent  &event);
+	void						On_Help						(wxCommandEvent  &event);
+	void						On_About					(wxCommandEvent  &event);
+	void						On_Tips						(wxCommandEvent  &event);
+
+	void						On_Frame_Cascade			(wxCommandEvent  &event);
+	void						On_Frame_Cascade_UI			(wxUpdateUIEvent &event);
+	void						On_Frame_hTile				(wxCommandEvent  &event);
+	void						On_Frame_hTile_UI			(wxUpdateUIEvent &event);
+	void						On_Frame_vTile				(wxCommandEvent  &event);
+	void						On_Frame_vTile_UI			(wxUpdateUIEvent &event);
+	void						On_Frame_ArrangeIcons		(wxCommandEvent  &event);
+	void						On_Frame_ArrangeIcons_UI	(wxUpdateUIEvent &event);
+	void						On_Frame_Next				(wxCommandEvent  &event);
+	void						On_Frame_Next_UI			(wxUpdateUIEvent &event);
+	void						On_Frame_Previous			(wxCommandEvent  &event);
+	void						On_Frame_Previous_UI		(wxUpdateUIEvent &event);
+	void						On_Frame_Close				(wxCommandEvent  &event);
+	void						On_Frame_Close_UI			(wxUpdateUIEvent &event);
+	void						On_Frame_Close_All			(wxCommandEvent  &event);
+	void						On_Frame_Close_All_UI		(wxUpdateUIEvent &event);
+
+	void						On_WKSP_Show				(wxCommandEvent  &event);
+	void						On_WKSP_Show_UI				(wxUpdateUIEvent &event);
+	void						On_Active_Show				(wxCommandEvent  &event);
+	void						On_Active_Show_UI			(wxUpdateUIEvent &event);
+	void						On_INFO_Show				(wxCommandEvent  &event);
+	void						On_INFO_Show_UI				(wxUpdateUIEvent &event);
+
+	//-----------------------------------------------------
+	void						On_Command_Workspace		(wxCommandEvent  &event);
+	void						On_Command_Workspace_UI		(wxUpdateUIEvent &event);
+	void						On_Command_Module			(wxCommandEvent  &event);
+	void						On_Command_Module_UI		(wxUpdateUIEvent &event);
+
+	void						On_Command_Child			(wxCommandEvent  &event);
+	void						On_Command_Child_UI			(wxUpdateUIEvent &event);
+
+	//-----------------------------------------------------
+	void						Show_Tips					(bool bShow);
+
+	//-----------------------------------------------------
+	bool						Process_Get_Okay			(bool bBlink);
+	bool						Process_Set_Okay			(bool bOkay = true);
+
+	bool						ProgressBar_Set_Position	(int Position);
+	bool						ProgressBar_Set_Position	(double Position, double Range);
+
+	virtual wxStatusBar *		OnCreateStatusBar			(int number, long style, wxWindowID id, const wxString& name);
+
+	void						StatusBar_Set_Text			(const wxChar *Text, int iPane = 0);
+
+	void						Set_Project_Name			(wxString Project_Name = wxEmptyString);
+
+	void						Top_Window_Push				(wxWindow *pWindow);
+	void						Top_Window_Pop				(wxWindow *pWindow);
+	wxWindow *					Top_Window_Get				(void);
+
+	//-----------------------------------------------------
+	void						On_Child_Activates			(class CVIEW_Base *pChild, bool bActivates);
+
+	void						Set_Pane_Caption			(wxWindow *pWindow, wxString Caption);
+
+	wxMenuBar *					MB_Create					(class CVIEW_Base *pChild);
+	void						MB_Remove					(wxMenu *pMenu_File, wxMenu *pMenu_Modules);
+
+	class wxToolBarBase *		TB_Create					(int ID);
+	void						TB_Add						(class wxToolBarBase *pToolBar, const wxChar *Name);
+	void						TB_Add_Item					(class wxToolBarBase *pToolBar, bool bCheck, int Cmd_ID);
+	void						TB_Add_Separator			(class wxToolBarBase *pToolBar);
+
+
+private:
+
+	int							m_nTopWindows;
+
+	wxWindow					**m_pTopWindows;
+
+	class wxGauge				*m_pProgressBar;
+
+	class wxToolBarBase			*m_pTB_Main, *m_pTB_Table, *m_pTB_Diagram, *m_pTB_Map, *m_pTB_Map_3D, *m_pTB_Histogram, *m_pTB_ScatterPlot, *m_pTB_Layout;
+
+	class CINFO					*m_pINFO;
+
+	class CWKSP					*m_pWKSP;
+
+	class CACTIVE				*m_pActive;
+
+	class wxAuiManager			*m_pLayout;
+
+
+	void						_Bar_Add					(class wxWindow *pWindow, int Position);
+	void						_Bar_Toggle					(wxWindow *pWindow);
+	void						_Bar_Show					(wxWindow *pWindow, bool bShow);
+
+	class wxToolBarBase *		_Create_ToolBar				(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+extern CSAGA_Frame				*g_pSAGA_Frame;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__SAGA_Frame_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               SAGA_Frame_DropTarget.cpp               //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp.h"
+
+#include "saga_frame_droptarget.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSAGA_Frame_DropTarget::CSAGA_Frame_DropTarget(void)
+{
+}
+
+//---------------------------------------------------------
+CSAGA_Frame_DropTarget::~CSAGA_Frame_DropTarget(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CSAGA_Frame_DropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames)
+{
+	for(size_t i=0; i<filenames.GetCount(); i++)
+	{
+		g_pWKSP->Open(filenames[i]);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/saga_frame_droptarget.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,100 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                SAGA_Frame_DropTarget.h                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__SAGA_Frame_DropTarget_H
+#define _HEADER_INCLUDED__SAGA_GUI__SAGA_Frame_DropTarget_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dnd.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSAGA_Frame_DropTarget : public wxFileDropTarget
+{
+public:
+	CSAGA_Frame_DropTarget(void);
+	virtual ~CSAGA_Frame_DropTarget(void);
+
+	virtual bool				OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__SAGA_Frame_DropTarget_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,2838 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              SVG_Interactive_map.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Victor Olaya           //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_map_layer.h"
+#include "wksp_layer_classify.h"
+
+#include "svg_interactive_map.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MAP_WINDOW_WIDTH	550.
+#define MAP_WINDOW_HEIGHT	700.
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSVG_Interactive_Map::CSVG_Interactive_Map(void)
+{
+}
+
+//---------------------------------------------------------
+CSVG_Interactive_Map::~CSVG_Interactive_Map(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::Create_From_Map(CWKSP_Map *pMap, CSG_Shapes *pIndexLayer, const wxChar *Filename)
+{
+	//-----------------------------------------------------
+	m_Directory	= SG_File_Get_Path(Filename);
+
+	_Add_Opening(pMap->Get_Extent());
+
+	//-----------------------------------------------------
+	m_sSVGCode.Append(wxT("<g id=\"mainMapGroup\" transform=\"translate(0,0)\">\n"));
+
+	for(int i=pMap->Get_Count()-1; i>-1; i--)
+	{
+		switch( pMap->Get_Layer(i)->Get_Layer()->Get_Type() )
+		{
+		default:	break;
+		case WKSP_ITEM_Grid:	_Add_Grid	((CWKSP_Grid   *)pMap->Get_Layer(i)->Get_Layer());	break;
+		case WKSP_ITEM_Shapes:	_Add_Shapes	((CWKSP_Shapes *)pMap->Get_Layer(i)->Get_Layer());	break;
+		}
+	}
+
+	m_sSVGCode.Append(wxT("</g>\n</svg>\n"));
+
+	//-----------------------------------------------------
+	_Add_CheckBoxes(pMap);
+
+	_Add_ReferenceMap(pIndexLayer, pMap->Get_Extent());
+
+	m_sSVGCode.Append(_Get_Code_Closing_1());
+
+	Save(Filename);
+
+	//-----------------------------------------------------
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("checkbox")			, wxT("js")), _Get_Code_CheckBox());
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("mapApp")			, wxT("js")), _Get_Code_MapApp	());
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("timer")				, wxT("js")), _Get_Code_Timer	());
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("slider")			, wxT("js")), _Get_Code_Slider	());
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("helper_functions")	, wxT("js")), _Get_Code_Helper	());
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("button")			, wxT("js")), _Get_Code_Buttons	());
+	_Write_Code(SG_File_Make_Path(m_Directory, wxT("navigation")		, wxT("js")), CSG_String::Format(wxT("%s%s"), _Get_Code_Navigation_1(), _Get_Code_Navigation_2()));
+}
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Write_Code(const wxChar *FileName, const wxChar *Code)
+{
+	CSG_File	Stream;
+
+	if( Stream.Open(FileName, SG_FILE_W, false) )
+	{
+		Stream.Write((void *)Code, SG_STR_LEN(Code));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Add_Opening(CSG_Rect r)
+{
+	CSG_String sViewBox;
+	double Width, Height;
+	double OffsetX, OffsetY;
+
+	m_sSVGCode.Append(_Get_Opening_Code_1());
+	m_sSVGCode.Append(SG_Get_String(r.Get_XRange(),2));
+	m_sSVGCode.Append(wxT("),"));
+	m_sSVGCode.Append(SG_Get_String(r.Get_XRange() / 400.,2));
+	m_sSVGCode.Append(_Get_Opening_Code_2());
+
+	if (r.Get_XRange() / r.Get_YRange()  > MAP_WINDOW_WIDTH / MAP_WINDOW_HEIGHT)
+	{
+		Width = r.Get_XRange();
+		Height =  r.Get_XRange() * MAP_WINDOW_HEIGHT / MAP_WINDOW_WIDTH;
+	}
+	else
+	{
+		Height = r.Get_YRange();
+		Width = r.Get_YRange() / MAP_WINDOW_HEIGHT * MAP_WINDOW_WIDTH;
+	}
+
+	OffsetX = (Width - r.Get_XRange()) / 2.;
+	OffsetY = (Height - r.Get_YRange()) / 2.;
+
+	sViewBox.Append(SG_Get_String(r.Get_XMin() - OffsetX,2));
+	sViewBox.Append(wxT(" "));
+	sViewBox.Append(SG_Get_String(-r.Get_YMax() - OffsetY,2));
+	sViewBox.Append(wxT(" "));
+	sViewBox.Append(SG_Get_String(Width,2));
+	sViewBox.Append(wxT(" "));
+	sViewBox.Append(SG_Get_String(Height,2));
+
+	_AddAttribute(wxT("viewBox"), sViewBox);	
+	m_sSVGCode.Append(wxT(">\n"));
+
+	m_dWidth = Width;
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Opening_Code_1(void)
+{
+	return( SG_STR_MBTOSG(
+		"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+		"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\" [\n"
+		"<!ATTLIST svg\n"
+		"	xmlns:attrib CDATA #IMPLIED\n"
+		"	xmlns:batik CDATA #IMPLIED\n"
+		">\n"
+		"<!ATTLIST g\n"
+		"	batik:static CDATA #IMPLIED\n"
+		">\n"
+		"<!ATTLIST image\n"
+		"	batik:static CDATA #IMPLIED\n"
+		">\n"
+		"<!ATTLIST path\n"
+		"	batik:static CDATA #IMPLIED\n"
+		">\n"
+		"]>\n"
+		"<?AdobeSVGViewer save=\"snapshot\"?>\n"
+		"<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 1024 768\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:attrib=\"http://www.carto.net/attrib\" xmlns:batik=\"http://xml.apache.org/batik/ext\" onload=\"init(evt);\" zoomAndPan=\"disable\">\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"helper_functions.js\"/>\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"mapApp.js\"/>\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"timer.js\"/>\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"slider.js\"/>\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"button.js\"/>\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"checkbox.js\"/>\n"
+		"	<script type=\"text/ecmascript\" xlink:href=\"navigation.js\"/>\n"
+		"	<script type=\"text/ecmascript\"><![CDATA[\n"
+		"		//global variables for mapApp and map object\n"
+		"		var myMapApp = new mapApp();\n"
+		"		var myMainMap;\n"
+		"		function init(evt) {\n"
+		"			//dynamic layer array that allow loading from database\n"
+		"			var dynamicLayers = new Array();\n"
+		"			//initialize digiLayers (layers that allow digitizing)\n"
+		"			var digiLayers = new Array();\n"
+		"			//initialize myMainMap object\n"
+		"			myMainMap = new map(\"mainMap\"),"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Opening_Code_2(void)
+{
+	return( SG_STR_MBTOSG(
+		"),0.6,0,0,\"\"),1,true,\"coordX\"),\"coordY\"),dynamicLayers,digiLayers,\"\"));\n"
+		"			//initialize refMapDragger object\n"
+		"			myMapApp.refMapDragger = new dragObj(\"dragRectForRefMap\"),\"referenceMap\"),\"myDragCross\"),0.1,true,\"coordX\"),\"coordY\"),myMainMap);\n"
+		"			//create zoom slider	\n"
+		"			myMapApp.zoomSlider = new slider(715,75,myMainMap.minWidth,715,165,myMainMap.maxWidth,myMainMap.maxWidth,\"mapZoomSlider\"),\"dimgray\"),2,10,\"sliderSymbol\"),myMapApp.refMapDragger,true);\n"
+		"			//now initialize buttons\n"
+		"			myMapApp.buttons = new Array();\n"
+		"			//groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset\n"
+		"			myMapApp.buttons[\"zoomIn\"] = new button(\"zoomIn\"),zoomImageButtons,\"rect\"),undefined,\"magnifyerZoomIn\"),705,47,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"zoomOut\"] = new button(\"zoomOut\"),zoomImageButtons,\"rect\"),undefined,\"magnifyerZoomOut\"),705,173,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"infoButton\"] = new switchbutton(\"infoButton\"),zoomImageSwitchButtons,\"rect\"),undefined,\"infoBut\"),746,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"infoButton\"].setSwitchValue(true,false);\n"
+		"			statusChange(\"Mode: Infomode\"));\n"
+		"			myMapApp.buttons[\"zoomFull\"] = new button(\"zoomFull\"),zoomImageButtons,\"rect\"),undefined,\"magnifyerFull\"),771,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"zoomManual\"] = new switchbutton(\"zoomManual\"),zoomImageSwitchButtons,\"rect\"),undefined,\"magnifyerManual\"),796,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"panManual\"] = new switchbutton(\"panManual\"),zoomImageSwitchButtons,\"rect\"),undefined,\"symbPan\"),821,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"recenterMap\"] = new switchbutton(\"recenterMap\"),zoomImageSwitchButtons,\"rect\"),undefined,\"symbRecenter\"),846,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"backwardExtent\"] = new button(\"backwardExtent\"),zoomImageButtons,\"rect\"),undefined,\"symbArrowLeft\"),871,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			myMapApp.buttons[\"forwardExtent\"] = new button(\"forwardExtent\"),zoomImageButtons,\"rect\"),undefined,\"symbArrowRight\"),896,74,20,20,10,\"\"),\"\"),\"white\"),\"rgb(235,235,235)\"),\"dimgray\"),1);\n"
+		"			//see if we need to disable buttons\n"
+		"			myMainMap.checkButtons();\n"
+		"			//load function specific to the current map project\n"
+		"			loadProjectSpecific();\n"
+		"		}\n"
+		"		function loadProjectSpecific() {\n"
+		"			//adopt width and height of map extent\n"
+		"			document.getElementById(\"myScaleTextW\")).firstChild.nodeValue = formatNumberString(myMainMap.curWidth.toFixed(myMainMap.nrDecimals)) + myMainMap.units;\n"
+		"			document.getElementById(\"myScaleTextH\")).firstChild.nodeValue = formatNumberString(myMainMap.curHeight.toFixed(myMainMap.nrDecimals)) + myMainMap.units;\n"
+		"		}\n"
+		"]]></script>\n"
+		"	<defs>\n"
+		"		<!-- Symbols for checkboxes -->\n"
+		"		<symbol id=\"checkBoxRect\" overflow=\"visible\">\n"
+		"			<rect x=\"-6\" y=\"-6\" width=\"12\" height=\"12\" fill=\"white\" stroke=\"dimgray\" stroke-width=\"1.5\"/>\n"
+		"		</symbol>\n"
+		"		<symbol id=\"checkBoxCross\" overflow=\"visible\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"1\" pointer-events=\"none\">\n"
+		"			<line x1=\"-5\" y1=\"-5\" x2=\"5\" y2=\"5\"/>\n"
+		"			<line x1=\"-5\" y1=\"5\" x2=\"5\" y2=\"-5\"/>\n"
+		"		</symbol>\n"
+		"		<!-- Symbols for Zoom Magnifyer glasses -->\n"
+		"		<symbol id=\"magnifyerFull\" overflow=\"visible\">\n"
+		"			<text y=\"7.5\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"18px\" font-weight=\"bold\" text-anchor=\"middle\" pointer-events=\"none\">F</text>\n"
+		"		</symbol>\n"
+		"		<symbol id=\"infoBut\" overflow=\"visible\">\n"
+		"			<circle fill=\"none\" stroke=\"dimgray\" stroke-width=\"1.5\" r=\"7.5\" />\n"
+		"			<text y=\"5\" font-family=\"sans-serif\" font-size=\"13px\" font-weight=\"bold\" fill=\"dimgray\" text-anchor=\"middle\" pointer-events=\"none\">i</text>\n"
+		"		</symbol>\n"
+		"		<symbol id=\"magnifyerManual\" overflow=\"visible\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"1.5\">\n"
+		"			<rect x=\"-6\" y=\"-6\" width=\"12\" height=\"12\" stroke-dasharray=\"1.5,1.5\"/>\n"
+		"			<line x1=\"-3\" y1=\"0\" x2=\"3\" y2=\"0\" />\n"
+		"			<line x1=\"0\" y1=\"-3\" x2=\"0\" y2=\"3\" />\n"
+		"		</symbol>\n"
+		"		<symbol id=\"magnifyerZoomIn\" overflow=\"visible\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"2\">\n"
+		"			<line x1=\"-4\" y1=\"0\" x2=\"4\" y2=\"0\"/>\n"
+		"			<line x1=\"0\" y1=\"-4\" x2=\"0\" y2=\"4\"/>\n"
+		"		</symbol>\n"
+		"		<symbol id=\"magnifyerZoomOut\" overflow=\"visible\">\n"
+		"			<line x1=\"-4\" y1=\"0\" x2=\"4\" y2=\"0\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"2\" />\n"
+		"		</symbol>\n"
+		"		<!-- hand symbol for panning -->\n"
+		"		<symbol id=\"symbPan\" overflow=\"visible\">\n"
+		"			<path transform=\"scale(1.2)\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"1\" d=\"M-2 6 C -2.2 2.5 -8.0 -0 -5.7 -1.9 C -4.3 -2.5 -3.3 -0.5 -2.5 0.7 C -3.2 -2.1 -5.5 -5.2 -3.6 -5.8 C -2.1 -6.3 -1.6 -3.6 -1.1 -1.9 C -0.9 -4.2 -1.6 -6.4 -0.2 -6.6 C 1.4 -6.8 0.9 -3 1.1 -1.9 C 1.5 -3.5 1.2 -6.1 2.5 -6.1 C 3.9 -6.1 3.5 -3.2 3.6 -1.6 C 4 -2.9 4.1 -4.3 5.3 -4.4 C 7.3 -3.5 4 2.2 3 6z\"/>\n"
+		"		</symbol>\n"
+		"		<!-- Symbol for Arrows -->\n"
+		"		<symbol id=\"symbArrow\" overflow=\"visible\">\n"
+		"			<polyline fill=\"none\" stroke=\"dimgray\" stroke-width=\"1\" points=\"-3,-6 3,-6 3,1 5,1 0,7 -5,1 -3,1 -3,-5\"/>\n"
+		"		</symbol>\n"
+		"		<symbol id=\"symbArrowLeft\" overflow=\"visible\">\n"
+		"			<use xlink:href=\"#symbArrow\" transform=\"rotate(90)\" />\n"
+		"		</symbol>\n"
+		"		<symbol id=\"symbArrowRight\" overflow=\"visible\">\n"
+		"			<use xlink:href=\"#symbArrow\" transform=\"rotate(-90)\" />\n"
+		"		</symbol>\n"
+		"		<!-- Symbol for Recentering Map -->\n"
+		"		<symbol id=\"symbRecenter\" overflow=\"visible\">\n"
+		"			<circle fill=\"dimgray\" cx=\"0\" cy=\"0\" r=\"1\" pointer-events=\"none\"/>\n"
+		"			<g fill=\"none\" stroke=\"dimgray\" stroke-width=\"1.5\" pointer-events=\"none\">\n"
+		"				<line x1=\"-7\" y1=\"-7\" x2=\"-3\" y2=\"-3\"/>\n"
+		"				<line x1=\"7\" y1=\"7\" x2=\"3\" y2=\"3\"/>\n"
+		"				<line x1=\"-7\" y1=\"7\" x2=\"-3\" y2=\"3\"/>\n"
+		"				<line x1=\"7\" y1=\"-7\" x2=\"3\" y2=\"-3\"/>\n"
+		"			</g>\n"
+		"		</symbol>\n"
+		"		<!-- Symbol for Slider -->\n"
+		"		<symbol id=\"sliderSymbol\" overflow=\"visible\" pointer-events=\"none\">\n"
+		"			<line x1=\"0\" y1=\"-5\" x2=\"0\" y2=\"5\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"5\"/>\n"
+		"		</symbol>\n"
+		"		<!-- Symbol for Dragging if zoomed in far -->\n"
+		"		<symbol id=\"myDragCrossSymbol\" overflow=\"visible\" stroke-width=\"2000\" fill=\"none\" stroke=\"darkblue\" pointer-events=\"none\">\n"
+		"			<line x1=\"-7000\" y1=\"0\" x2=\"-2500\" y2=\"0\"/>\n"
+		"			<line x1=\"7000\" y1=\"0\" x2=\"2500\" y2=\"0\"/>\n"
+		"			<line x1=\"0\" y1=\"-3300\" x2=\"0\" y2=\"-7800\"/>\n"
+		"			<line x1=\"0\" y1=\"3300\" x2=\"0\" y2=\"7800\"/>\n"
+		"		</symbol>\n"
+		"		<!-- Marker for Extent-Arrows -->\n"
+		"		<marker id=\"myStartArrow\" overflow=\"visible\" orient=\"auto\">\n"
+		"			<polyline fill=\"dimgray\" points=\"-0.5,0 8,-2 8,2\"/>\n"
+		"		</marker>\n"
+		"		<marker id=\"myEndArrow\" overflow=\"visible\" orient=\"auto\">\n"
+		"			<polyline fill=\"dimgray\" points=\"0.5,0 -8,-2 -8,2\"/>\n"
+		"		</marker>\n"
+		"	</defs>\n"
+		"	<rect x=\"-500\" y=\"-500\" width=\"3000\" height=\"3000\" stroke=\"none\" fill=\"aliceblue\" />\n"
+		"	<!-- Main Map Frame -->\n"
+		"	<svg id=\"mainMap\" x=\"0\" y=\"15\" width=\"550\" height=\"700\"	cursor=\"crosshair\" "
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Add_ReferenceMap(CSG_Shapes *pIndexLayer, CSG_Rect r)
+{
+	int i;
+	CSG_String sViewBox;
+	double Line_Width, Point_Width;
+	double Width, Height;
+	double OffsetX, OffsetY;
+	CSG_Shape *pShape;
+
+	if (r.Get_XRange() / r.Get_YRange()  > MAP_WINDOW_WIDTH / MAP_WINDOW_HEIGHT)
+	{
+		Width = r.Get_XRange();
+		Height =  r.Get_XRange() * MAP_WINDOW_HEIGHT / MAP_WINDOW_WIDTH;
+	}
+	else
+	{
+		Height = r.Get_YRange();
+		Width = r.Get_YRange() / MAP_WINDOW_HEIGHT * MAP_WINDOW_WIDTH;
+	}
+
+	OffsetX = (Width - r.Get_XRange()) / 2.;
+	OffsetY = (Height - r.Get_YRange()) / 2.;
+
+	sViewBox.Append(SG_Get_String(r.Get_XMin() - OffsetX,2));
+	sViewBox.Append(wxT(" "));
+	sViewBox.Append(SG_Get_String(- r.Get_YMax() - OffsetY,2));
+	sViewBox.Append(wxT(" "));
+	sViewBox.Append(SG_Get_String(Width,2));
+	sViewBox.Append(wxT(" "));
+	sViewBox.Append(SG_Get_String(Height,2));
+
+	_AddAttribute(wxT("viewBox"), sViewBox);	
+
+	m_sSVGCode.Append(_Get_Code_3());
+	
+	if (pIndexLayer)
+	{
+		m_sSVGCode.Append(wxT("<g id=\"index\">\n"));
+		for (i = 0; i < pIndexLayer->Get_Count(); i++)
+		{
+			pShape = pIndexLayer->Get_Shape(i);
+			Line_Width = Point_Width = m_dWidth / MAP_WINDOW_WIDTH;
+			Point_Width *= 5;
+			_Add_Shape(pShape, 0, 0, Line_Width, Point_Width);
+		}
+		m_sSVGCode.Append(wxT("</g>\n"));
+	}
+
+	m_sSVGCode.Append(_Get_Code_4());
+		
+	_AddAttribute(wxT("x"), r.Get_XMin() - OffsetX);
+	_AddAttribute(wxT("y"), - r.Get_YMax() - OffsetY);
+	_AddAttribute(wxT("width"), Width);
+	_AddAttribute(wxT("height"), Height);
+
+	m_sSVGCode.Append(_Get_Code_5());
+
+}
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Add_Grid(CWKSP_Grid *pLayer)
+{
+	wxString Filename;
+	wxBitmap BMP;
+	
+	if( pLayer->Get_Image_Grid(BMP) )
+	{
+		Filename	= SG_File_Make_Path(m_Directory.c_str(), pLayer->Get_Object()->Get_Name(), wxT("jpg"));
+		BMP.SaveFile(Filename, wxBITMAP_TYPE_JPEG);
+
+		m_sSVGCode.Append(wxT("<image "));
+
+		_AddAttribute(wxT("id")			, pLayer->Get_Object()->Get_Name());
+		_AddAttribute(wxT("x")			, ((CSG_Grid *)pLayer->Get_Object())->Get_XMin());
+		_AddAttribute(wxT("y")			,-((CSG_Grid *)pLayer->Get_Object())->Get_YMax());
+		_AddAttribute(wxT("width")		, ((CSG_Grid *)pLayer->Get_Object())->Get_XRange());
+		_AddAttribute(wxT("height")		, ((CSG_Grid *)pLayer->Get_Object())->Get_YRange());
+		_AddAttribute(wxT("xlink:href")	, SG_File_Get_Name(Filename, true));
+
+		m_sSVGCode.Append(wxT("/>"));
+	}
+}
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Add_Shapes(CWKSP_Shapes *pLayer)
+{
+	int i;
+	int iColorField;
+	int Line_Color, Fill_Color; 
+	double Line_Width, Point_Width;
+	double dSize;
+	CSG_Shape *pShape;
+	CSG_String sLabel;
+
+	m_sSVGCode.Append(wxT("<g id=\""));
+	m_sSVGCode.Append(pLayer->Get_Object()->Get_Name());		
+	m_sSVGCode.Append(wxT("\" >\n"));
+	
+	iColorField = pLayer->Get_Color_Field();
+
+	m_sSVGCode.Append(wxT("<g transform=\"scale(1,-1)\">\n"));
+
+	for (i = 0; i < ((CSG_Shapes*)pLayer->Get_Object())->Get_Count(); i++)
+	{
+		pShape = pLayer->Get_Shapes()->Get_Shape(i);
+		Line_Color = Fill_Color = pLayer->Get_Classifier()->Get_Class_Color_byValue(pShape->asDouble(iColorField));
+		Line_Width = Point_Width = m_dWidth / MAP_WINDOW_WIDTH;
+		Point_Width *= 5;
+		_Add_Shape(pShape, Fill_Color, Line_Color, Line_Width, Point_Width);
+	}
+	
+	if (pLayer->Get_Label_Field() >= 0)
+	{
+		m_sSVGCode.Append(wxT("<g transform=\"scale(0.01,-0.01)\"\n>"));
+		for (i = 0; i < ((CSG_Shapes*)pLayer->Get_Object())->Get_Count(); i++)
+		{
+			pShape = pLayer->Get_Shapes()->Get_Shape(i);
+			Line_Width = Point_Width = m_dWidth / MAP_WINDOW_WIDTH;
+			sLabel = pShape->asString(pLayer->Get_Label_Field());
+			switch( pLayer->Get_Parameters()->Get_Parameter(wxT("LABEL_ATTRIB_SIZE_TYPE"))->asInt() )
+			{
+				case 0:	default:
+					dSize = Line_Width * pLayer->Get_Parameters()->Get_Parameter(wxT("LABEL_ATTRIB_FONT"))->asFont()->GetPointSize();
+					_Add_Label(sLabel, pShape, dSize, wxT("%"));
+					break;
+				case 1:
+					dSize =  pLayer->Get_Parameters()->Get_Parameter(wxT("LABEL_ATTRIB_SIZE"))->asDouble();
+					_Add_Label(sLabel, pShape, dSize, wxT(""));
+					break;
+			}
+		}
+
+		m_sSVGCode.Append(wxT("</g>\n"));
+	}
+
+	m_sSVGCode.Append(wxT("</g>\n</g>\n"));
+}
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Add_Label(const wxChar* Label, CSG_Shape *pShape, double dSize, const wxChar* Unit)
+{
+
+	int iPoint, iPart;
+	TSG_Point Point;
+
+	switch( pShape->Get_Type() )
+	{
+	case SHAPE_TYPE_Point:
+	case SHAPE_TYPE_Points:
+		for(iPoint=0; iPoint < pShape->Get_Point_Count(0); iPoint++)
+		{
+			Point = pShape->Get_Point(iPoint);
+			Draw_Text(100 * Point.x, -100 * Point.y, Label, 0, wxT("Verdana"), 100 * dSize);
+		}
+		break;
+
+	case SHAPE_TYPE_Line:
+		///************///
+		break;
+
+	case SHAPE_TYPE_Polygon:
+		
+		for (iPart = 0; iPart < pShape->Get_Part_Count(); iPart++)
+		{
+			if(! ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
+			{
+				Point = ((CSG_Shape_Polygon *)pShape)->Get_Centroid(iPart);
+				Draw_Text(100 * Point.x, -100 * Point.y, Label, 0, wxT("Verdana"), 100 * dSize);
+			}
+		}
+		break;
+	}
+
+}
+
+//---------------------------------------------------------
+bool CSVG_Interactive_Map::_Add_Shape(CSG_Shape *pShape, int Fill_Color, int Line_Color, double Line_Width, double Point_Width)
+{
+	if( pShape && pShape->is_Valid() )
+	{
+		int				iPart, iPoint;
+		TSG_Point		Point;
+		CSG_Points	Points;
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			Points.Clear();
+
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				Point = pShape->Get_Point(iPoint, iPart);
+				Points.Add(Point.x, Point.y);
+			}
+
+			switch( pShape->Get_Type() )
+			{
+			case SHAPE_TYPE_Point:
+			case SHAPE_TYPE_Points:
+				for(iPoint=0; iPoint<Points.Get_Count(); iPoint++)
+				{
+					Draw_Circle(Points[iPoint].x, Points[iPoint].y, Point_Width, Fill_Color, 0, Line_Width);
+				}
+				break;
+
+			case SHAPE_TYPE_Line:
+				Draw_Line(Points, Line_Width, Line_Color);
+				break;
+
+			case SHAPE_TYPE_Polygon:
+				if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
+				{
+					Draw_Polygon(Points, -1, 0, 0.01);
+				}
+				else
+				{
+					Draw_Polygon(Points, Fill_Color, 0, 0.01);
+				}
+				break;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CSVG_Interactive_Map::_Add_CheckBoxes(CWKSP_Map *pMap)
+{
+
+	int i;
+	CSG_String s;
+	int x,y;
+	int iRow = 1;
+	
+	m_sSVGCode.Append(_Get_Code_1());	// 2* <g> open
+	m_sSVGCode.Append(LNG("Layers"));
+	m_sSVGCode.Append(wxT("</text>\n"));
+
+	for (i = 0; i < pMap->Get_Count(); i++)
+	{
+		y = iRow * 30;
+
+		if (i % 2)
+		{
+			x = 200;		
+			iRow++;
+		}
+		else
+		{
+			x = 0;
+		}
+	
+		m_sSVGCode.Append(wxT("<g "));
+		s = wxT("translate(");
+		s.Append(SG_Get_String(x,0));
+		s.Append(wxT(" "));
+		s.Append(SG_Get_String(y,0));
+		s.Append(wxT("))"));
+		_AddAttribute(wxT("transform"), s);
+		m_sSVGCode.Append(wxT(">\n"));
+
+		m_sSVGCode.Append(wxT("<use "));
+		s = wxT("checkBox");
+		s.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
+		_AddAttribute(wxT("id"), s);
+		_AddAttribute(wxT("xlink:href"), wxT("#checkBoxRect"));
+		s = wxT("checkBoxScript(evt,'");
+		s.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
+		s.Append(wxT("');"));
+		_AddAttribute(wxT("onclick"), s);
+		m_sSVGCode.Append(wxT("/>\n"));
+
+		m_sSVGCode.Append(wxT("<use "));
+		s = wxT("checkCross");
+		s.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
+		_AddAttribute(wxT("id"), s);
+		_AddAttribute(wxT("xlink:href"), wxT("#checkBoxCross"));		
+		_AddAttribute(wxT("visibility"), wxT("visible"));
+		m_sSVGCode.Append(wxT("/>\n"));
+
+		m_sSVGCode.Append(wxT("</g>\n"));
+	}
+
+	m_sSVGCode.Append(wxT("<g font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" pointer-events=\"none\">\n"));
+	
+	iRow = 1;
+		
+	for (i = 0; i < pMap->Get_Count(); i++)
+	{
+		y = iRow * 30 + 6;
+
+		if (i % 2)
+		{
+			x = 212;
+			iRow++;
+		}
+		else
+		{
+			x = 12;
+		}
+
+		m_sSVGCode.Append(wxT("<text "));	
+		_AddAttribute(wxT("x"), x);
+		_AddAttribute(wxT("y"), y);
+		m_sSVGCode.Append(wxT(">"));
+		m_sSVGCode.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
+		m_sSVGCode.Append(wxT("</text>\n"));	
+
+	}
+
+	m_sSVGCode.Append(wxT("</g>\n"));
+
+	m_sSVGCode.Append(_Get_Code_2());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_1(void)
+{
+	return( SG_STR_MBTOSG(
+		"<g>\n"
+		"		<g font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" pointer-events=\"none\">"
+		"			<text id=\"coordX\" x=\"745\" y=\"145\">X:</text>\n"
+		"			<text id=\"coordY\" x=\"845\" y=\"145\">Y:</text>\n"
+		"		</g>\n"
+		"		<g>"
+		"			<!-- vertical line, displays current height of map extent -->\n"
+		"			<line stroke=\"dimgray\" stroke-width=\"1.5\" marker-start=\"url(#myStartArrow)\" marker-end=\"url(#myEndArrow)\" x1=\"561\" y1=\"15\" x2=\"561\" y2=\"715\"/>\n"
+		"			<rect fill=\"aliceblue\" x=\"555\" y=\"330\" width=\"12\" height=\"70\"/>\n"
+		"			<text id=\"myScaleTextH\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" text-anchor=\"middle\" transform=\"translate(556,365),rotate(90)\" pointer-events=\"none\">-</text>\n"
+		"			<!-- horizontal line, displays current width of map extent -->\n"
+		"			<line stroke=\"dimgray\" stroke-width=\"1.5\" marker-start=\"url(#myStartArrow)\" marker-end=\"url(#myEndArrow)\" x1=\"0\" y1=\"723\" x2=\"553.1\" y2=\"723\"/>\n"
+		"			<rect fill=\"aliceblue\" x=\"242\" y=\"717\" width=\"70\" height=\"12\"/>\n"
+		"			<text id=\"myScaleTextW\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" text-anchor=\"middle\" transform=\"translate(277,728)\" pointer-events=\"none\">-</text>\n"
+		"			<!-- small rectangle in lower right corner, onclick displays current map extent in real world coordinates -->\n"
+		"			<rect fill=\"dimgray\" x=\"558.5\" y=\"720.5\" width=\"5\" height=\"5\" onclick=\"showExtent()\" />\n"
+		"		</g>\n"
+		"		<g transform=\"translate(590 225)\">\n"
+		"			<text font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"18px\" font-weight=\"bold\" x=\"-10\" y=\"0\" pointer-events=\"none\">"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_2(void)
+{
+	return( SG_STR_MBTOSG(
+		"</g>\n"
+		"   <g text-rendering=\"optimizeLegibility\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"12px\">\n"
+		"		<!-- text with this id is required to show help texts -->\n"
+		"		<text id=\"statusText\" x=\"745\" y=\"125\">Statusbar: Your Status Text</text>\n"
+		"   </g>\n"
+		"</g>\n"
+		"<svg id=\"referenceMap\" x=\"580\" y=\"45\" "
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_3(void)
+{
+	return( SG_STR_MBTOSG(
+		"width=\"118.52\" height=\"150\" onmousedown=\"myMapApp.refMapDragger.handleEvent(evt)\" onmousemove=\"myMapApp.refMapDragger.handleEvent(evt)\" onmouseup=\"myMapApp.refMapDragger.handleEvent(evt)\" onmouseout=\"myMapApp.refMapDragger.handleEvent(evt)\" cursor=\"crosshair\">\n"
+		"		<g transform=\"scale(1,-1)\"\n>"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_4(void)
+{
+	return( SG_STR_MBTOSG(
+		"		</g>\n"
+		"		<rect id=\"dragRectForRefMap\" fill=\"lightskyblue\" fill-opacity=\"0.4\" "
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_5(void)
+{
+	return( SG_STR_MBTOSG(
+		" pointer-events=\"none\" />\n	"
+		"		<use id=\"myDragCross\" x=\"0\" y=\"0\" xlink:href=\"#myDragCrossSymbol\" visibility=\"hidden\" />\n"
+		"	</svg>\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Closing_1(void)
+{
+	return( SG_STR_MBTOSG(
+		"	<g>\n"
+		"		<!-- empty group where zoomSlider is later appended -->\n"
+		"		<g id=\"mapZoomSlider\"/>\n"
+		"		<!-- button for zoom-in, above slider -->\n"
+		"		<g id=\"zoomIn\" cursor=\"pointer\" />\n"
+		"		<!-- button for zoom-out, below slider -->\n"
+		"		<g id=\"zoomOut\" cursor=\"pointer\" />\n"
+		"		<!-- info button -->\n"
+		"		<g id=\"infoButton\" cursor=\"pointer\" />\n"
+		"		<!-- button for full view (f) -->\n"
+		"		<g id=\"zoomFull\" cursor=\"pointer\" />\n"
+		"		<!-- button for manual zoom (rectangle) -->\n"
+		"		<g id=\"zoomManual\" cursor=\"pointer\" />\n"
+		"		<!-- button for manual pan -->\n"
+		"		<g id=\"panManual\" cursor=\"pointer\" />\n"
+		"		<!-- button for redefining map center -->\n"
+		"		<g id=\"recenterMap\" cursor=\"pointer\" />\n"
+		"		<!-- button for backwarding map extent (extent history) -->\n"
+		"		<g id=\"backwardExtent\" cursor=\"pointer\" />\n"
+		"		<!-- button for forwarding map extent (extent history) -->\n"
+		"		<g id=\"forwardExtent\" cursor=\"pointer\" />\n"
+		"	</g>\n"
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														//
+//														//
+//														//
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_CheckBox(void)
+{
+	return( SG_STR_MBTOSG(
+		"function checkBoxScript(evt,myLayer) { //checkBox for toggling layers an contextMenue\n"
+		"	var myLayerObj = document.getElementById(myLayer);\n"
+		"	var myCheckCrossObj = document.getElementById(\"checkCross\"+myLayer);\n"
+		"	var myCheckCrossVisibility = myCheckCrossObj.getAttributeNS(null,\"visibility\"));\n"
+		"	if (evt.type == \"click\" && evt.detail == 1) {\n"
+		"	if (myCheckCrossVisibility == \"visible\")) {\n"
+		"		myLayerObj.setAttributeNS(null,\"visibility\"),\"hidden\"));\n"
+		"		myCheckCrossObj.setAttributeNS(null,\"visibility\"),\"hidden\"));\n"
+		"		//you can do if/else or switch statements to set different actions on activating a checkbox here\n"
+		"		//myLayer holds the currentLayer name\n"
+		"	}\n"
+		"	else {\n"
+		"		myLayerObj.setAttributeNS(null,\"visibility\"),\"visible\"));\n"
+		"		myCheckCrossObj.setAttributeNS(null,\"visibility\"),\"visible\"));\n"
+		"	}\n"
+		"	}\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_MapApp(void)
+{
+	return( SG_STR_MBTOSG(
+		"//holds data on window size\n"
+		"function mapApp() {\n"
+		"	if (!document.documentElement.getScreenCTM) {\n"
+		"	this.resetFactors();\n"
+		"	//add resize event to document element\n"
+		"	document.documentElement.addEventListener(\"SVGResize\"),this,false);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"mapApp.prototype.handleEvent = function(evt) {\n"
+		"	if (evt.type == \"SVGResize\")) {\n"
+		"	this.resetFactors();\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"mapApp.prototype.resetFactors = function() {\n"
+		"	if (!document.documentElement.getScreenCTM) {\n"
+		"	//case for viewers that don't support .getScreenCTM, such as ASV3\n"
+		"	//calculate ratio and offset values of app window\n"
+		"	var viewBoxArray = document.documentElement.getAttributeNS(null,\"viewBox\")).split(\" \"));\n"
+		"	var myRatio = viewBoxArray[2]/viewBoxArray[3];\n"
+		"	if ((window.innerWidth/window.innerHeight) > myRatio) { //case window is more wide than myRatio\n"
+		"		this.scaleFactor = viewBoxArray[3] / window.innerHeight;\n"
+		"	}\n"
+		"	else { //case window is more tall than myRatio\n"
+		"		this.scaleFactor = viewBoxArray[2] / window.innerWidth;\n"
+		"	}\n"
+		"	this.offsetX = (window.innerWidth - viewBoxArray[2] * 1 / this.scaleFactor) / 2;\n"
+		"	this.offsetY = (window.innerHeight - viewBoxArray[3] * 1 / this.scaleFactor) / 2;\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"mapApp.prototype.calcCoord = function(evt,ctmNode) {\n"
+		"	var svgPoint = document.documentElement.createSVGPoint();\n"
+		"	svgPoint.x = evt.clientX;\n"
+		"	svgPoint.y = evt.clientY;\n"
+		"	if (!document.documentElement.getScreenCTM) {\n"
+		"	//case ASV3 a. Corel\n"
+		"	svgPoint.x = (svgPoint.x	- this.offsetX) * this.scaleFactor;\n"
+		"	svgPoint.y = (svgPoint.y - this.offsetY) * this.scaleFactor;\n"
+		"	//undo the effect of transformations\n"
+		"	if (ctmNode) {\n"
+		"		var ctm = getTransformToRootElement(ctmNode).inverse();\n"
+		"	}\n"
+		"	else {\n"
+		"		var ctm = getTransformToRootElement(evt.target).inverse();\n"
+		"	}\n"
+		"	svgPoint = svgPoint.matrixTransform(ctm);\n"
+		"\n"
+		"	}\n"
+		"	else {\n"
+		"	if (ctmNode) {\n"
+		"		var matrix = ctmNode.getScreenCTM();\n"
+		"	}\n"
+		"	else {\n"
+		"		var matrix = evt.target.getScreenCTM();\n"
+		"	}\n"
+		"	svgPoint = svgPoint.matrixTransform(matrix.inverse());\n"
+		"	}\n"
+		"	return svgPoint;\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Timer(void)
+{
+	return( SG_STR_MBTOSG(
+		"// source/credits: \"Algorithm\": http://www.codingforums.com/showthread.php?s=&threadid=10531\n"
+		"// The constructor should be called with\n"
+		"// the parent object (optional, defaults to window).\n"
+		"\n"
+		"function Timer(){\n"
+		"	this.obj = (arguments.length)?arguments[0]:window;\n"
+		"	return this;\n"
+		"}\n"
+		"\n"
+		"// The set functions should be called with:\n"
+		"// - The name of the object method (as a string) (required)\n"
+		"// - The millisecond delay (required)\n"
+		"// - Any number of extra arguments, which will all be\n"
+		"//	passed to the method when it is evaluated.\n"
+		"\n"
+		"Timer.prototype.setInterval = function(func, msec){\n"
+		"	var i = Timer.getNew();\n"
+		"	var t = Timer.buildCall(this.obj, i, arguments);\n"
+		"	Timer.set[i].timer = window.setInterval(t,msec);\n"
+		"	return i;\n"
+		"}\n"
+		"Timer.prototype.setTimeout = function(func, msec){\n"
+		"	var i = Timer.getNew();\n"
+		"	Timer.buildCall(this.obj, i, arguments);\n"
+		"	Timer.set[i].timer = window.setTimeout(\"Timer.callOnce(\"+i+\"));\"),msec);\n"
+		"	return i;\n"
+		"}\n"
+		"\n"
+		"// The clear functions should be called with\n"
+		"// the return value from the equivalent set function.\n"
+		"\n"
+		"Timer.prototype.clearInterval = function(i){\n"
+		"	if(!Timer.set[i]) return;\n"
+		"	window.clearInterval(Timer.set[i].timer);\n"
+		"	Timer.set[i] = null;\n"
+		"}\n"
+		"Timer.prototype.clearTimeout = function(i){\n"
+		"	if(!Timer.set[i]) return;\n"
+		"	window.clearTimeout(Timer.set[i].timer);\n"
+		"	Timer.set[i] = null;\n"
+		"}\n"
+		"\n"
+		"// Private data\n"
+		"\n"
+		"Timer.set = new Array();\n"
+		"Timer.buildCall = function(obj, i, args){\n"
+		"	var t = \"\");\n"
+		"	Timer.set[i] = new Array();\n"
+		"	if(obj != window){\n"
+		"	Timer.set[i].obj = obj;\n"
+		"	t = \"Timer.set[\"+i+\"].obj.\");\n"
+		"	}\n"
+		"	t += args[0]+\"(\");\n"
+		"	if(args.length > 2){\n"
+		"	Timer.set[i][0] = args[2];\n"
+		"	t += \"Timer.set[\"+i+\"][0]\");\n"
+		"	for(var j=1; (j+2)<args.length; j++){\n"
+		"		Timer.set[i][j] = args[j+2];\n"
+		"		t += \"), Timer.set[\"+i+\"][\"+j+\"]\");\n"
+		"	}}\n"
+		"	t += \"));\");\n"
+		"	Timer.set[i].call = t;\n"
+		"	return t;\n"
+		"}\n"
+		"Timer.callOnce = function(i){\n"
+		"	if(!Timer.set[i]) return;\n"
+		"	eval(Timer.set[i].call);\n"
+		"	Timer.set[i] = null;\n"
+		"}\n"
+		"Timer.getNew = function(){\n"
+		"	var i = 0;\n"
+		"	while(Timer.set[i]) i++;\n"
+		"	return i;\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Slider(void)
+{
+	return( SG_STR_MBTOSG(
+		"//slider properties\n"
+		"function slider(x1,y1,value1,x2,y2,value2,startVal,sliderGroupId,sliderColor,visSliderWidth,invisSliderWidth,sliderSymb,functionToCall,mouseMoveBool) {\n"
+		"	this.x1 = x1;\n"
+		"	this.y1 = y1;\n"
+		"	this.value1 = value1;\n"
+		"	this.x2 = x2;\n"
+		"	this.y2 = y2;\n"
+		"	this.value2 = value2;\n"
+		"	this.startVal = startVal;\n"
+		"	this.value = startVal;\n"
+		"	this.sliderGroupId = sliderGroupId;\n"
+		"	this.sliderGroup = document.getElementById(this.sliderGroupId);\n"
+		"	this.sliderColor = sliderColor;\n"
+		"	this.visSliderWidth = visSliderWidth;\n"
+		"	this.invisSliderWidth = invisSliderWidth;\n"
+		"	this.sliderSymb = sliderSymb;\n"
+		"	this.functionToCall = functionToCall;\n"
+		"	this.mouseMoveBool = mouseMoveBool;\n"
+		"	this.length = toPolarDist((this.x2 - this.x1),(this.y2 - this.y1));\n"
+		"	this.direction = toPolarDir((this.x2 - this.x1),(this.y2 - this.y1));\n"
+		"	this.sliderLine = null;\n"
+		"	this.createSlider();\n"
+		"	this.slideStatus = 0;\n"
+		"}\n"
+		"\n"
+		"//create slider\n"
+		"slider.prototype.createSlider = function() {\n"
+		"	this.sliderLine = document.createElementNS(svgNS,\"line\"));\n"
+		"	this.sliderLine.setAttributeNS(null,\"x1\"),this.x1);\n"
+		"	this.sliderLine.setAttributeNS(null,\"y1\"),this.y1);\n"
+		"	this.sliderLine.setAttributeNS(null,\"x2\"),this.x2);\n"
+		"	this.sliderLine.setAttributeNS(null,\"y2\"),this.y2);\n"
+		"	this.sliderLine.setAttributeNS(null,\"stroke\"),this.sliderColor);\n"
+		"	this.sliderLine.setAttributeNS(null,\"stroke-width\"),this.invisSliderWidth);\n"
+		"	this.sliderLine.setAttributeNS(null,\"opacity\"),\"0\"));\n"
+		"	this.sliderLine.setAttributeNS(null,\"stroke-linecap\"),\"square\"));\n"
+		"	this.sliderLine.setAttributeNS(null,\"id\"),this.sliderGroupId+\"_invisibleSliderLine\"));\n"
+		"	this.sliderLine.addEventListener(\"mousedown\"),this,false);\n"
+		"	this.sliderGroup.appendChild(this.sliderLine);\n"
+		"	var mySliderLine = document.createElementNS(svgNS,\"line\"));\n"
+		"	mySliderLine.setAttributeNS(null,\"x1\"),this.x1);\n"
+		"	mySliderLine.setAttributeNS(null,\"y1\"),this.y1);\n"
+		"	mySliderLine.setAttributeNS(null,\"x2\"),this.x2);\n"
+		"	mySliderLine.setAttributeNS(null,\"y2\"),this.y2);\n"
+		"	mySliderLine.setAttributeNS(null,\"stroke\"),this.sliderColor);\n"
+		"	mySliderLine.setAttributeNS(null,\"stroke-width\"),this.visSliderWidth);\n"
+		"	mySliderLine.setAttributeNS(null,\"id\"),this.sliderGroupId+\"_visibleSliderLine\"));\n"
+		"	mySliderLine.setAttributeNS(null,\"pointer-events\"),\"none\"));\n"
+		"	this.sliderGroup.appendChild(mySliderLine);\n"
+		"	mySliderSymb = document.createElementNS(svgNS,\"use\"));\n"
+		"	mySliderSymb.setAttributeNS(xlinkNS,\"xlink:href\"),\"#\"+this.sliderSymb);\n"
+		"	var myStartDistance = this.length - ((this.value2 - this.startVal) / (this.value2 - this.value1)) * this.length;\n"
+		"	var myPosX = this.x1 + toRectX(this.direction,myStartDistance);\n"
+		"	var myPosY = this.y1 + toRectY(this.direction,myStartDistance);\n"
+		"	var myTransformString = \"translate(\"+myPosX+\"),\"+myPosY+\")) rotate(\" + Math.round(this.direction / Math.PI * 180) + \"))\");\n"
+		"	mySliderSymb.setAttributeNS(null,\"transform\"),myTransformString);\n"
+		"	mySliderSymb.setAttributeNS(null,\"id\"),this.sliderGroupId+\"_sliderSymbol\"));\n"
+		"	this.sliderGroup.appendChild(mySliderSymb);\n"
+		"}\n"
+		"\n"
+		"//remove all slider elements\n"
+		"slider.prototype.removeSlider = function() {\n"
+		"	var mySliderSymb = document.getElementById(this.sliderGroup+\"_sliderSymbol\"));\n"
+		"	this.sliderGroup.removeChild(mySliderSymb);\n"
+		"	var mySliderLine = document.getElementById(this.sliderGroup+\"_visibleSliderLine\"));\n"
+		"	this.sliderGroup.removeChild(mySliderLine);\n"
+		"	var mySliderLine = document.getElementById(this.sliderGroup+\"_invisibleSliderLine\"));\n"
+		"	this.sliderGroup.removeChild(mySliderLine);\n"
+		"}\n"
+		"\n"
+		"//handle events\n"
+		"slider.prototype.handleEvent = function(evt) {\n"
+		"	this.drag(evt);\n"
+		"}\n"
+		"\n"
+		"//drag slider\n"
+		"slider.prototype.drag = function(evt) {\n"
+		"	if (evt.type == \"mousedown\" || (evt.type == \"mousemove\" && this.slideStatus == 1)) {\n"
+		"	//get coordinate in slider coordinate system\n"
+		"	var coordPoint = myMapApp.calcCoord(evt,this.sliderLine);\n"
+		"	//draw normal line for first vertex\n"
+		"	var ax = this.x2 - this.x1;\n"
+		"	var ay = this.y2 - this.y1;\n"
+		"	//normal vector 1\n"
+		"	var px1 = parseFloat(this.x1) + ay * -1;\n"
+		"	var py1 = parseFloat(this.y1) + ax;\n"
+		"	//normal vector 2\n"
+		"	var px2 = parseFloat(this.x2) + ay * -1;\n"
+		"	var py2 = parseFloat(this.y2) + ax;\n"
+		"		\n"
+		"	if (leftOfTest(coordPoint.x,coordPoint.y,this.x1,this.y1,px1,py1) == 0 && leftOfTest(coordPoint.x,coordPoint.y,this.x2,this.y2,px2,py2) == 1) {\n"
+		"		if (evt.type == \"mousedown\" && evt.detail == 1) {\n"
+		"		this.slideStatus = 1;\n"
+		"		document.documentElement.addEventListener(\"mousemove\"),this,false);\n"
+		"		document.documentElement.addEventListener(\"mouseup\"),this,false);\n"
+		"		}\n"
+		"		myNewPos = intersect2lines(this.x1,this.y1,this.x2,this.y2,coordPoint.x,coordPoint.y,coordPoint.x + ay * -1,coordPoint.y + ax);\n"
+		"		var myPercentage = toPolarDist(myNewPos['x'] - this.x1,myNewPos['y'] - this.y1) / this.length;\n"
+		"		this.value = this.value1 + myPercentage * (this.value2 - this.value1);\n"
+		"	}\n"
+		"	else {\n"
+		"		var myNewPos = new Array();\n"
+		"		if (leftOfTest(coordPoint.x,coordPoint.y,this.x1,this.y1,px1,py1) == 0 && leftOfTest(coordPoint.x,coordPoint.y,this.x2,this.y2,px2,py2) == 0) {\n"
+		"		//more than max\n"
+		"		this.value = this.value2;\n"
+		"		myNewPos['x'] = this.x2;\n"
+		"		myNewPos['y'] = this.y2;\n"
+		"		}\n"
+		"		if (leftOfTest(coordPoint.x,coordPoint.y,this.x1,this.y1,px1,py1) == 1 && leftOfTest(coordPoint.x,coordPoint.y,this.x2,this.y2,px2,py2) == 1) {\n"
+		"		//less than min\n"
+		"		this.value = this.value1;\n"
+		"		myNewPos['x'] = this.x1;\n"
+		"		myNewPos['y'] = this.y1;\n"
+		"		}\n"
+		"	}\n"
+		"	var myTransformString = \"translate(\"+myNewPos['x']+\"),\"+myNewPos['y']+\")) rotate(\" + Math.round(this.direction / Math.PI * 180) + \"))\");\n"
+		"	document.getElementById(this.sliderGroupId+\"_sliderSymbol\")).setAttributeNS(null,\"transform\"),myTransformString);\n"
+		"	this.getValue();\n"
+		"	}\n"
+		"	if (evt.type == \"mouseup\" && evt.detail == 1) {\n"
+		"	if (this.slideStatus == 1) {\n"
+		"		this.slideStatus = 2;\n"
+		"		document.documentElement.removeEventListener(\"mousemove\"),this,false);\n"
+		"		document.documentElement.removeEventListener(\"mouseup\"),this,false);\n"
+		"		this.getValue();\n"
+		"	}\n"
+		"	this.slideStatus = 0;\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//this code is executed, after the slider is released\n"
+		"//you can use switch/if to detect which slider was used (use this.sliderGroup) for that\n"
+		"slider.prototype.getValue = function() {\n"
+		"	if (this.slideStatus == 1 && this.mouseMoveBool == true) {\n"
+		"	if (typeof(this.functionToCall) == \"function\")) {\n"
+		"		this.functionToCall(\"change\"),this.sliderGroupId,this.value);\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == \"object\")) {\n"
+		"		this.functionToCall.getSliderVal(\"change\"),this.sliderGroupId,this.value);\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == \"string\")) {\n"
+		"		eval(this.functionToCall+\"('change','\"+this.sliderGroupId+\"',\"+this.value+\"))\"));\n"
+		"	}\n"
+		"	}\n"
+		"	if (this.slideStatus == 2) {\n"
+		"	if (typeof(this.functionToCall) == \"function\")) {\n"
+		"		this.functionToCall(\"release\"),this.sliderGroupId,this.value);\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == \"object\")) {\n"
+		"		this.functionToCall.getSliderVal(\"release\"),this.sliderGroupId,this.value);\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == \"string\")) {\n"
+		"		eval(this.functionToCall+\"('release','\"+this.sliderGroupId+\"',\"+this.value+\"))\"));\n"
+		"	}\n"
+		"	}\n"
+		"}	\n"
+		"\n"
+		"//this is to set the value from other scripts\n"
+		"slider.prototype.setValue = function(value) {\n"
+		"	var myPercAlLine = (value - this.value1) / (this.value2 - this.value1);\n"
+		"	this.value = myPercAlLine;\n"
+		"	var myPosX = this.x1 + toRectX(this.direction,this.length * myPercAlLine);\n"
+		"	var myPosY = this.y1 + toRectY(this.direction,this.length * myPercAlLine);\n"
+		"	var myTransformString = \"translate(\"+myPosX+\"),\"+myPosY+\")) rotate(\" + Math.round(this.direction / Math.PI * 180) + \"))\");\n"
+		"	document.getElementById(this.sliderGroupId+\"_sliderSymbol\")).setAttributeNS(null,\"transform\"),myTransformString);\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Helper(void)
+{
+	return( SG_STR_MBTOSG(
+		"/*\n"
+		"ECMAScript helper functions\n"
+		"Copyright (C) <2004>	<Andreas Neumann>\n"
+		"Version 1.1, 2004-11-18\n"
+		"neumann at karto.baug.ethz.ch\n"
+		"http://www.carto.net/\n"
+		"http://www.carto.net/neumann/\n"
+		"\n"
+		"Credits: numerous people on svgdevelopers at yahoogroups.com\n"
+		"\n"
+		"This ECMA script library is free software; you can redistribute it and/or\n"
+		"modify it under the terms of the GNU Lesser General Public\n"
+		"License as published by the Free Software Foundation; either\n"
+		"version 2.1 of the License, or (at your option) any later version.\n"
+		"\n"
+		"This library is distributed in the hope that it will be useful,\n"
+		"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU\n"
+		"Lesser General Public License for more details.\n"
+		"\n"
+		"You should have received a copy of the GNU Lesser General Public\n"
+		"License along with this library (http://www.carto.net/papers/svg/resources/lesser_gpl.txt); if not, write to the Free Software\n"
+		"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA	02111-1307	USA\n"
+		"\n"
+		"----\n"
+		"\n"
+		"original document site: http://www.carto.net/papers/svg/resources/helper_functions.js\n"
+		"Please contact the author in case you want to use code or ideas commercially.\n"
+		"If you use this code, please include this copyright header, the included full\n"
+		"LGPL 2.1 text and read the terms provided in the LGPL 2.1 license\n"
+		"(http://www.gnu.org/copyleft/lesser.txt)\n"
+		"\n"
+		"-------------------------------\n"
+		"\n"
+		"Please report bugs and send improvements to neumann at karto.baug.ethz.ch\n"
+		"If you use these scripts, please link to the original (http://www.carto.net/papers/svg/navigationTools/)\n"
+		"somewhere in the source-code-comment or the \"about\" of your project and give credits, thanks!\n"
+		"\n"
+		"*/\n"
+		"\n"
+		"//global variables necessary to create elements in these namespaces, do not delete them!!!!\n"
+		"var svgNS = \"http://www.w3.org/2000/svg\");\n"
+		"var xlinkNS = \"http://www.w3.org/1999/xlink\");\n"
+		"var cartoNS = \"http://www.carto.net/attrib\");\n"
+		"var attribNS = \"http://www.carto.net/attrib\");\n"
+		"var batikNS = \"http://xml.apache.org/batik/ext\");\n"
+		"\n"
+		"/* ----------------------- helper functions to calculate stuff ---------------- */\n"
+		"/* ---------------------------------------------------------------------------- */\n"
+		"function toPolarDir(xdiff,ydiff) { // Subroutine for calculating polar Coordinates\n"
+		"	direction = (Math.atan2(ydiff,xdiff));\n"
+		"	//result is angle in radian\n"
+		"	return(direction);\n"
+		"}\n"
+		"\n"
+		"function toPolarDist(xdiff,ydiff) { // Subroutine for calculating polar Coordinates\n"
+		"	distance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);\n"
+		"	return(distance);\n"
+		"}\n"
+		"\n"
+		"function toRectX(direction,distance) { // Subroutine for calculating cartesic coordinates\n"
+		"	x = distance * Math.cos(direction);\n"
+		"	y = distance * Math.sin(direction);\n"
+		"	return(x);\n"
+		"}\n"
+		"\n"
+		"function toRectY(direction,distance) { // Subroutine for calculating cartesic coordinates\n"
+		"	x = distance * Math.cos(direction);\n"
+		"	y = distance * Math.sin(direction);\n"
+		"	return(y);\n"
+		"}\n"
+		"\n"
+		"//Converts degrees to radians.\n"
+		"function DegToRad(deg) {\n"
+		"	return (deg / 180.0 * Math.PI);\n"
+		"}\n"
+		"\n"
+		"//Converts radians to degrees.\n"
+		"function RadToDeg(rad) {\n"
+		"	return (rad / Math.PI * 180.0);\n"
+		"}\n"
+		"\n"
+		"//converts decimal degrees to degree/minutes/seconds\n"
+		"function dd2dms(dd) {\n"
+		"	var minutes = (dd - Math.floor(dd)) * 60;\n"
+		"	var seconds = (minutes - Math.floor(minutes)) * 60;\n"
+		"	var minutes = Math.floor(minutes);\n"
+		"	var degrees = Math.floor(dd);\n"
+		"	return {deg:degrees,min:minutes,sec:seconds};\n"
+		"}\n"
+		"\n"
+		"//converts degree/minutes/seconds to decimal degrees\n"
+		"function dms2dd(deg,min,sec) {\n"
+		"	return deg + (min / 60) + (sec / 3600);\n"
+		"}\n"
+		"\n"
+		"//log functions that do not exist in Math object\n"
+		"function log(x,b) {\n"
+		"	if(b==null) b=Math.E;\n"
+		"	return Math.log(x)/Math.log(b);\n"
+		"}\n"
+		"\n"
+		"//gets 4 z-values (4 corners), a position, delta x and delty and a cellsize as input and returns interpolated z-value\n"
+		"function intBilinear(za,zb,zc,zd,xpos,ypos,ax,ay,cellsize) { //bilinear interpolation function\n"
+		"	e = (xpos - ax) / cellsize;\n"
+		"	f = (ypos - ay) / cellsize;\n"
+		"\n"
+		"	//calculation of weights\n"
+		"	wa = (1 - e) * (1 - f);\n"
+		"	wb = e * (1 - f);\n"
+		"	wc = e * f;\n"
+		"	wd = f * (1 - e);\n"
+		"\n"
+		"	height_interpol = wa * zc + wb * zd + wc * za + wd * zb;\n"
+		"\n"
+		"	return (height_interpol);	\n"
+		"}\n"
+		"\n"
+		"//test if point is left of or right of, result is 1 (leftof) or 0 (rightof)\n"
+		"function leftOfTest(pointx,pointy,linex1,liney1,linex2,liney2) {\n"
+		"	result = (liney1 - pointy) * (linex2 - linex1) - (linex1 - pointx) * (liney2 - liney1);\n"
+		"	if (result < 0) {\n"
+		"	leftof = 1; //case left of\n"
+		"	}\n"
+		"	else {\n"
+		"	leftof = 0; //case left of	\n"
+		"	}\n"
+		"	return(leftof);\n"
+		"}\n"
+		"\n"
+		"//input is point coordinate, and 2 line coordinates\n"
+		"function distFromLine(xpoint,ypoint,linex1,liney1,linex2,liney2) {\n"
+		"	dx = linex2 - linex1;\n"
+		"	dy = liney2 - liney1;\n"
+		"	distance = (dy * (xpoint - linex1) - dx * (ypoint - liney1)) / Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));\n"
+		"	return(distance);\n"
+		"}\n"
+		"\n"
+		"//converts radian value to degrees\n"
+		"function radian2deg(radian) {\n"
+		"	deg = radian / Math.PI * 180;\n"
+		"	return(deg);\n"
+		"}\n"
+		"\n"
+		"//input is two vectors (a1,a2 is vector a, b1,b2 is vector b), output is angle in radian\n"
+		"//Formula: Acos from	Scalaproduct of the two vectors divided by ( norm (deutsch Betrag) vector 1 by norm vector 2\n"
+		"//see http://www.mathe-online.at/mathint/vect2/i.html#Winkel\n"
+		"function angleBetwTwoLines(a1,a2,b1,b2) {\n"
+		"	angle = Math.acos((a1 * b1 + a2 * b2) / (Math.sqrt(Math.pow(a1,2) + Math.pow(a2,2)) * Math.sqrt(Math.pow(b1,2) + Math.pow(b2,2))));\n"
+		"	return(angle);\n"
+		"}\n"
+		"\n"
+		"//input is two vectors (a1,a2 is vector a, b1,b2 is vector b), output is new vector c2 returned as array\n"
+		"//Formula: Vektor a divided by Norm Vector a (Betrag) plus Vektor b divided by Norm Vector b (Betrag)\n"
+		"//see http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale\n"
+		"function calcBisectorVector(a1,a2,b1,b2) {\n"
+		"	betraga = Math.sqrt(Math.pow(a1,2) + Math.pow(a2,2));\n"
+		"	betragb = Math.sqrt(Math.pow(b1,2) + Math.pow(b2,2));\n"
+		"	c = new Array();\n"
+		"	c[0] = a1 / betraga + b1 / betragb;\n"
+		"	c[1] = a2 / betraga + b2 / betragb;\n"
+		"	return(c);\n"
+		"}\n"
+		"\n"
+		"//input is two vectors (a1,a2 is vector a, b1,b2 is vector b), output is angle in radian\n"
+		"//Formula: Vektor a divided by Norm Vector a (Betrag) plus Vektor b divided by Norm Vector b (Betrag)\n"
+		"//see http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale\n"
+		"function calcBisectorAngle(a1,a2,b1,b2) {\n"
+		"	betraga = Math.sqrt(Math.pow(a1,2) + Math.pow(a2,2));\n"
+		"	betragb = Math.sqrt(Math.pow(b1,2) + Math.pow(b2,2));\n"
+		"	c1 = a1 / betraga + b1 / betragb;\n"
+		"	c2 = a2 / betraga + b2 / betragb;\n"
+		"	angle = toPolarDir(c1,c2);\n"
+		"	return(angle);\n"
+		"}\n"
+		"\n"
+		"function intersect2lines(line1x1,line1y1,line1x2,line1y2,line2x1,line2y1,line2x2,line2y2) {\n"
+		"	//formula see http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/\n"
+		"	var result = new Array();\n"
+		"	var denominator = (line2y2 - line2y1)*(line1x2 - line1x1) - (line2x2 - line2x1)*(line1y2 - line1y1);\n"
+		"	if (denominator == 0) {\n"
+		"	alert(\"lines are parallel\"));\n"
+		"	}\n"
+		"	else {\n"
+		"	ua = ((line2x2 - line2x1)*(line1y1 - line2y1) - (line2y2 - line2y1)*(line1x1 - line2x1)) / denominator;\n"
+		"	ub = ((line1x2 - line1x1)*(line1y1 - line2y1) - (line1y2 - line1y1)*(line1x1 - line2x1)) / denominator;\n"
+		"	}\n"
+		"	result[\"x\"] = line1x1 + ua * (line1x2 - line1x1);\n"
+		"	result[\"y\"] = line1y1 + ua * (line1y2 - line1y1);\n"
+		"	return(result);\n"
+		"}\n"
+		"\n"
+		"/* ----------------------- helper function to sort arrays ---------------- */\n"
+		"/* ----------------------------------------------------------------------- */\n"
+		"//my own sort function, uses only first part of string (population value)\n"
+		"function mySort(a,b) {\n"
+		"	var myResulta = a.split(\"+\"));\n"
+		"	var myResultb = b.split(\"+\"));\n"
+		"	if (parseFloat(myResulta[0]) < parseFloat(myResultb[0])) {\n"
+		"	return 1;\n"
+		"	}\n"
+		"	else {\n"
+		"	return -1;\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"/* ----------------------- helper function format number strings -------------- */\n"
+		"/* ---------------------------------------------------------------------------- */\n"
+		"//formatting number strings\n"
+		"//this function add's \"'\" to a number every third digit\n"
+		"function formatNumberString(myString) {\n"
+		"	//check if of type string, if number, convert it to string\n"
+		"	if (typeof(myString) == \"number\")) {\n"
+		"	myTempString = myString.toString();\n"
+		"	}\n"
+		"	else {\n"
+		"	myTempString = myString;\n"
+		"	}\n"
+		"	var myNewString=\"\");\n"
+		"	//if it contains a comma, it will be split\n"
+		"	var splitResults = myTempString.split(\".\"));\n"
+		"	var myCounter= splitResults[0].length;\n"
+		"	if (myCounter > 3) {\n"
+		"	while(myCounter > 0) {\n"
+		"		if (myCounter > 3) {\n"
+		"		myNewString = \"),\" + splitResults[0].substr(myCounter - 3,3) + myNewString;\n"
+		"		}\n"
+		"		else {\n"
+		"		myNewString = splitResults[0].substr(0,myCounter) + myNewString;\n"
+		"		}\n"
+		"		myCounter -= 3;\n"
+		"	}\n"
+		"	}\n"
+		"	else {\n"
+		"	myNewString = splitResults[0];\n"
+		"	}\n"
+		"	//concatenate if it contains a comma\n"
+		"	if (splitResults[1]) {\n"
+		"	myNewString = myNewString + \".\" + splitResults[1];\n"
+		"	}\n"
+		"	return myNewString;\n"
+		"}\n"
+		"\n"
+		"//function for status Bar\n"
+		"function statusChange(statusText) {\n"
+		"	document.getElementById(\"statusText\")).firstChild.nodeValue = \"Statusbar: \" + statusText;\n"
+		"}\n"
+		"\n"
+		"//scale an object\n"
+		"function scaleObject(evt,factor) {\n"
+		"//reference to the currently selected object\n"
+		"	var element = evt.currentTarget;\n"
+		"	var myX = element.getAttributeNS(null,\"x\"));\n"
+		"	var myY = element.getAttributeNS(null,\"y\"));\n"
+		"	var newtransform = \"scale(\" + factor + \")) translate(\" + (myX * 1 / factor - myX) + \" \" + (myY * 1 / factor - myY) +\"))\");\n"
+		"	element.setAttributeNS(null,'transform', newtransform);\n"
+		"}\n"
+		"\n"
+		"//this code is copied from Kevin Lindsey\n"
+		"//http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index.htm\n"
+		"function getTransformToRootElement(node) {\n"
+		"	try {\n"
+		"	//this part is for fully conformant players\n"
+		"	var CTM = node.getTransformToElement(document.documentElement);\n"
+		"	}\n"
+		"	catch (ex) {\n"
+		"	//this part is for ASV3 or other non-conformant players\n"
+		"	// Initialize our CTM the node's Current Transformation Matrix\n"
+		"	var CTM = node.getCTM();\n"
+		"	// Work our way through the ancestor nodes stopping at the SVG Document\n"
+		"	while ( ( node = node.parentNode ) != document ) {\n"
+		"		// Multiply the new CTM to the one with what we have accumulated so far\n"
+		"		CTM = node.getCTM().multiply(CTM);\n"
+		"	}\n"
+		"	}\n"
+		"	return CTM;\n"
+		"}\n"
+		"\n"
+		"//calculate HSV 2 RGB: HSV (h 0 to 360, sat and val are between 0 and 1), RGB between 0 and 255\n"
+		"function hsv2rgb(hue,sat,val) {\n"
+		"	//alert(\"Hue:\"+hue);\n"
+		"	var rgbArr = new Array();\n"
+		"	if ( sat == 0) {\n"
+		"	rgbArr[\"red\"] = Math.round(val * 255);\n"
+		"	rgbArr[\"green\"] = Math.round(val * 255);\n"
+		"	rgbArr[\"blue\"] = Math.round(val * 255);\n"
+		"	}\n"
+		"	else {\n"
+		"	var h = hue / 60;\n"
+		"	var i = Math.floor(h);\n"
+		"	var f = h - i;\n"
+		"	if (i % 2 == 0) {\n"
+		"		f = 1 - f;\n"
+		"	}\n"
+		"	var m = val * (1 - sat); \n"
+		"	var n = val * (1 - sat * f);\n"
+		"	switch(i) {\n"
+		"		case 0:\n"
+		"		rgbArr[\"red\"] = val;\n"
+		"		rgbArr[\"green\"] = n;\n"
+		"		rgbArr[\"blue\"] = m;\n"
+		"		break;\n"
+		"		case 1:\n"
+		"		rgbArr[\"red\"] = n;\n"
+		"		rgbArr[\"green\"] = val;\n"
+		"		rgbArr[\"blue\"] = m;\n"
+		"		break;\n"
+		"		case 2:\n"
+		"		rgbArr[\"red\"] = m;\n"
+		"		rgbArr[\"green\"] = val;\n"
+		"		rgbArr[\"blue\"] = n;\n"
+		"		break;\n"
+		"		case 3:\n"
+		"		rgbArr[\"red\"] = m;\n"
+		"		rgbArr[\"green\"] = n;\n"
+		"		rgbArr[\"blue\"] = val;\n"
+		"		break;\n"
+		"		case 4:\n"
+		"		rgbArr[\"red\"] = n;\n"
+		"		rgbArr[\"green\"] = m;\n"
+		"		rgbArr[\"blue\"] = val;\n"
+		"		break;\n"
+		"		case 5:\n"
+		"		rgbArr[\"red\"] = val;\n"
+		"		rgbArr[\"green\"] = m;\n"
+		"		rgbArr[\"blue\"] = n;\n"
+		"		break;\n"
+		"		case 6:\n"
+		"		rgbArr[\"red\"] = val;\n"
+		"		rgbArr[\"green\"] = n;\n"
+		"		rgbArr[\"blue\"] = m;\n"
+		"		break;\n"
+		"	}\n"
+		"	rgbArr[\"red\"] = Math.round(rgbArr[\"red\"] * 255);\n"
+		"	rgbArr[\"green\"] = Math.round(rgbArr[\"green\"] * 255);\n"
+		"	rgbArr[\"blue\"] = Math.round(rgbArr[\"blue\"] * 255);\n"
+		"	}\n"
+		"	return rgbArr;\n"
+		"}\n"
+		"\n"
+		"//calculate rgb to hsv values\n"
+		"function rgb2hsv (red,green,blue) {\n"
+		"	//input between 0 and 255 --> normalize to 0 to 1\n"
+		"	//result = \n"
+		"	var hsvArr = new Array();\n"
+		"	red = red / 255;\n"
+		"	green = green / 255;\n"
+		"	blue = blue / 255;\n"
+		"	myMax = Math.max(red, Math.max(green,blue));\n"
+		"	myMin = Math.min(red, Math.min(green,blue));\n"
+		"	v = myMax;\n"
+		"	if (myMax > 0) {\n"
+		"	s = (myMax - myMin) / myMax;\n"
+		"	}\n"
+		"	else {\n"
+		"	s = 0;\n"
+		"	}\n"
+		"	if (s > 0) {\n"
+		"	myDiff = myMax - myMin;\n"
+		"	rc = (myMax - red) / myDiff;\n"
+		"	gc = (myMax - green) / myDiff;\n"
+		"	bc = (myMax - blue) / myDiff;\n"
+		"	if (red == myMax) {\n"
+		"		h = (bc - gc) / 6;\n"
+		"	}\n"
+		"	if (green == myMax) {\n"
+		"		h = (2 + rc - bc) / 6;\n"
+		"	}\n"
+		"	if (blue == myMax) {\n"
+		"		h = (4 + gc - rc) / 6;\n"
+		"	}\n"
+		"	}\n"
+		"	else {\n"
+		"	h = 0;\n"
+		"	}\n"
+		"	if (h < 0) {\n"
+		"	h += 1;\n"
+		"	}\n"
+		"	hsvArr[\"hue\"] = Math.round(h * 360);\n"
+		"	hsvArr[\"sat\"] = s;\n"
+		"	hsvArr[\"val\"] = v;\n"
+		"	return hsvArr;\n"
+		"}\n"
+		"\n"
+		"//populate an array that can be addressed by both a key or an index nr\n"
+		"function assArrayPopulate(arrayKeys,arrayValues) {\n"
+		"	var returnArray = new Array();\n"
+		"	if (arrayKeys.length != arrayValues.length) {\n"
+		"	alert(\"error: arrays do not have same length!\"));\n"
+		"	}\n"
+		"	else {\n"
+		"	for (i=0;i<arrayKeys.length;i++) {\n"
+		"		returnArray[arrayKeys[i]] = arrayValues[i];\n"
+		"	}\n"
+		"	}\n"
+		"	return returnArray;\n"
+		"}\n"
+		"\n"
+		"//replace special (non-ASCII) characters with their charCode\n"
+		"function replaceSpecialChars(myString) {\n"
+		"	for (i=161;i<256;i++) {\n"
+		"		re = new RegExp(\"&#\"+i+\");\"),\"g\"));\n"
+		"		myString = myString.replace(re,String.fromCharCode(i));\n"
+		"	}\n"
+		"	return myString;\n"
+		"}\n"
+		"\n"
+		"/* ----------------------- getXMLData object ----------------------------- */\n"
+		"/* ----------------------------------------------------------------------- */\n"
+		"//this object allows to make network requests using getURL or XMLHttpRequest\n"
+		"//you may specify a url and a callBackFunction\n"
+		"//the callBackFunction receives a XML node representing the rootElement of the fragment received\n"
+		"function getXMLData(url,callBackFunction) {\n"
+		"	this.url = url;\n"
+		"	this.callBackFunction = callBackFunction;\n"
+		"	this.xmlRequest = null;\n"
+		"} \n"
+		"\n"
+		"getXMLData.prototype.getData = function() {\n"
+		"	//call getURL() if available\n"
+		"	if (window.getURL) {\n"
+		"	getURL(this.url,this);\n"
+		"	}\n"
+		"	//or call XMLHttpRequest() if available\n"
+		"	else if (window.XMLHttpRequest) {\n"
+		"	this.xmlRequest = new XMLHttpRequest();\n"
+		"	this.xmlRequest.overrideMimeType(\"text/xml\"));\n"
+		"	this.xmlRequest.open(\"GET\"),this.url,true);\n"
+		"	this.xmlRequest.onreadystatechange = this;\n"
+		"	this.xmlRequest.send(null);\n"
+		"	}\n"
+		"	//write an error message if neither method is available\n"
+		"	else {\n"
+		"	alert(\"your browser/svg viewer neither supports window.getURL nor window.XMLHttpRequest!\"));\n"
+		"	}	\n"
+		"}\n"
+		"\n"
+		"//this is the callback method for the getURL function\n"
+		"getXMLData.prototype.operationComplete = function(data) {\n"
+		"	//check if data has a success property\n"
+		"	if (data.success) {\n"
+		"	//parse content of the XML format to the variable \"node\"\n"
+		"	var node = parseXML(data.content,document);\n"
+		"	this.callBackFunction(node.firstChild);\n"
+		"	}\n"
+		"	else {\n"
+		"	alert(\"something went wrong with dynamic loading of geometry!\"));\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//this method receives data from XMLHttpRequest\n"
+		"getXMLData.prototype.handleEvent = function() {\n"
+		"	if (this.xmlRequest.readyState == 4) {\n"
+		"	this.callBackFunction(this.xmlRequest.responseXML.documentElement);\n"
+		"	}	\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Buttons(void)
+{
+	return( SG_STR_MBTOSG(
+		"function button(groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset) {\n"
+		"	if (arguments.length > 0) {\n"
+		"	this.init(groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"button.prototype.init = function(groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset) {\n"
+		"	this.groupId = groupId; //the group id where all new content is appended to\n"
+		"	this.functionToCall = functionToCall; //function to be called if button was pressed\n"
+		"	this.buttonType = buttonType; //button type: currently either \"rect\" or \"ellipse\"\n"
+		"	this.buttonText = buttonText; //default value to be filled in when textbox is created\n"
+		"	this.buttonSymbolId = buttonSymbolId; //id to a symbol to be used as a button graphics\n"
+		"	this.x = x; //left of button rectangle\n"
+		"	this.y = y; //top of button rectangle\n"
+		"	this.width = width; //button rectangle width\n"
+		"	this.height = height; //button rectangle height\n"
+		"	this.fontSize = fontSize; //font size in user units/pixels\n"
+		"	this.fontFamily = fontFamily; //font family for text element, can be an empty string for image buttons\n"
+		"	this.textFill = textFill; //the fill color of the text for text buttons, can be an empty string for image buttons\n"
+		"	this.buttonFill = buttonFill; //the fill color of the button rectangle or ellipse\n"
+		"	this.shadeLightFill = shadeLightFill; //light fill color simulating 3d effect\n"
+		"	this.shadeDarkFill = shadeDarkFill; //dark fill color simulating 3d effect\n"
+		"	this.shadowOffset = shadowOffset; //shadow offset in viewBox units\n"
+		"	this.buttonGroup = document.getElementById(this.groupId); //reference to the button group node\n"
+		"	this.upperLeftLine = null; //later a reference to the upper left line simulating 3d effect\n"
+		"	this.buttonRect = null; //later a reference to the button area (rect)\n"
+		"	this.buttonTextElement = null; //later a reference to the button text\n"
+		"	this.buttonSymbolInstance = null; //later a reference to the button symbol\n"
+		"	this.deActivateRect = null; //later a reference to a rectangle that can be used to deactivate the button\n"
+		"	this.activated = true; //a property indicating if button is activated or not\n"
+		"	this.lowerRightLine = null; //later a reference to the lower right line simulating 3d effect\n"
+		"	this.createButton(); //method to initialize button\n"
+		"	this.timer = new Timer(this); //a Timer instance for calling the functionToCall\n"
+		"	this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms\n"
+		"}\n"
+		"\n"
+		"//create button\n"
+		"button.prototype.createButton = function() {\n"
+		"	//create upper left button line or ellipse\n"
+		"	if (this.buttonType == \"rect\")) {\n"
+		"	this.upperLeftShadow = document.createElementNS(svgNS,\"rect\"));\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"x\"),this.x - this.shadowOffset);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"y\"),this.y - this.shadowOffset);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"width\"),this.width);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"height\"),this.height);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"points\"),this.x+\"),\"+(this.y+this.height)+\" \"+this.x+\"),\"+this.y+\" \"+(this.x+this.width)+\"),\"+this.y);\n"
+		"	}\n"
+		"	else if (this.buttonType == \"ellipse\")) {\n"
+		"	this.upperLeftShadow = document.createElementNS(svgNS,\"ellipse\"));\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"cx\"),this.x + this.width * 0.5 - this.shadowOffset);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"cy\"),this.y + this.height * 0.5 - this.shadowOffset);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"rx\"),this.width * 0.5);\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"ry\"),this.height * 0.5);\n"
+		"	}\n"
+		"	else {\n"
+		"	alert(\"buttonType '\"+this.buttonType+\"' not supported. You need to specify 'rect' or 'ellipse'\"));\n"
+		"	}\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"fill\"),this.shadeLightFill);\n"
+		"	this.buttonGroup.appendChild(this.upperLeftShadow);\n"
+		"\n"
+		"	//create lower right button line or ellipse\n"
+		"	if (this.buttonType == \"rect\")) {\n"
+		"	this.lowerRightShadow = document.createElementNS(svgNS,\"rect\"));\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"x\"),this.x + this.shadowOffset);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"y\"),this.y + this.shadowOffset);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"width\"),this.width);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"height\"),this.height);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"points\"),this.x+\"),\"+(this.y+this.height)+\" \"+this.x+\"),\"+this.y+\" \"+(this.x+this.width)+\"),\"+this.y);\n"
+		"	}\n"
+		"	else if (this.buttonType == \"ellipse\")) {\n"
+		"	this.lowerRightShadow = document.createElementNS(svgNS,\"ellipse\"));\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"cx\"),this.x + this.width * 0.5 + this.shadowOffset);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"cy\"),this.y + this.height * 0.5 + this.shadowOffset);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"rx\"),this.width * 0.5);\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"ry\"),this.height * 0.5);\n"
+		"	}\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"fill\"),this.shadeDarkFill);\n"
+		"	this.buttonGroup.appendChild(this.lowerRightShadow);\n"
+		"\n"
+		"	//create buttonRect\n"
+		"	if (this.buttonType == \"rect\")) {\n"
+		"	this.buttonRect = document.createElementNS(svgNS,\"rect\"));\n"
+		"	this.buttonRect.setAttributeNS(null,\"x\"),this.x);\n"
+		"	this.buttonRect.setAttributeNS(null,\"y\"),this.y);\n"
+		"	this.buttonRect.setAttributeNS(null,\"width\"),this.width);\n"
+		"	this.buttonRect.setAttributeNS(null,\"height\"),this.height);\n"
+		"	}\n"
+		"	else if (this.buttonType == \"ellipse\")) {\n"
+		"	this.buttonRect = document.createElementNS(svgNS,\"ellipse\"));\n"
+		"	this.buttonRect.setAttributeNS(null,\"cx\"),this.x + this.width * 0.5);\n"
+		"	this.buttonRect.setAttributeNS(null,\"cy\"),this.y + this.height * 0.5);\n"
+		"	this.buttonRect.setAttributeNS(null,\"rx\"),this.width * 0.5);\n"
+		"	this.buttonRect.setAttributeNS(null,\"ry\"),this.height * 0.5);\n"
+		"	}\n"
+		"	this.buttonRect.setAttributeNS(null,\"fill\"),this.buttonFill);\n"
+		"	this.buttonRect.setAttributeNS(null,\"cursor\"),\"pointer\"));\n"
+		"	this.buttonRect.addEventListener(\"mousedown\"),this,false);\n"
+		"	this.buttonRect.addEventListener(\"mouseup\"),this,false);\n"
+		"	this.buttonRect.addEventListener(\"click\"),this,false);\n"
+		"	this.buttonGroup.appendChild(this.buttonRect);\n"
+		"	\n"
+		"	if (this.buttonText != undefined) {\n"
+		"	//create text element and add clipping path attribute\n"
+		"	this.buttonTextElement = document.createElementNS(svgNS,\"text\"));\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"x\"),(this.x + this.width / 2));\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"y\"),(this.y + this.height - ((this.height - this.fontSize) / 1.75)));\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"fill\"),this.textFill);\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"font-family\"),this.fontFamily);\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"font-size\"),this.fontSize+\"px\"));\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"pointer-events\"),\"none\"));\n"
+		"	this.buttonTextElement.setAttributeNS(null,\"text-anchor\"),\"middle\"));\n"
+		"	this.buttonTextElement.setAttributeNS(\"http://www.w3.org/XML/1998/namespace\"),\"space\"),\"preserve\"));\n"
+		"	var textboxTextContent = document.createTextNode(this.buttonText);\n"
+		"	this.buttonTextElement.appendChild(textboxTextContent);\n"
+		"	this.buttonGroup.appendChild(this.buttonTextElement);\n"
+		"	}\n"
+		"	\n"
+		"	if (this.buttonSymbolId != undefined) {\n"
+		"	this.buttonSymbolInstance = document.createElementNS(svgNS,\"use\"));\n"
+		"	this.buttonSymbolInstance.setAttributeNS(null,\"x\"),(this.x + this.width / 2));\n"
+		"	this.buttonSymbolInstance.setAttributeNS(null,\"y\"),(this.y + this.height / 2));\n"
+		"	this.buttonSymbolInstance.setAttributeNS(xlinkNS,\"href\"),\"#\"+this.buttonSymbolId);\n"
+		"	this.buttonSymbolInstance.setAttributeNS(null,\"pointer-events\"),\"none\"));\n"
+		"	this.buttonGroup.appendChild(this.buttonSymbolInstance);\n"
+		"	}\n"
+		"	\n"
+		"	//create rectangle to deactivate the button\n"
+		"	if (this.buttonType == \"rect\")) {\n"
+		"	this.deActivateRect = document.createElementNS(svgNS,\"rect\"));\n"
+		"	this.deActivateRect.setAttributeNS(null,\"x\"),this.x - this.shadowOffset);\n"
+		"	this.deActivateRect.setAttributeNS(null,\"y\"),this.y - this.shadowOffset);\n"
+		"	this.deActivateRect.setAttributeNS(null,\"width\"),this.width + this.shadowOffset * 2);\n"
+		"	this.deActivateRect.setAttributeNS(null,\"height\"),this.height + this.shadowOffset * 2);\n"
+		"	}\n"
+		"	else if (this.buttonType == \"ellipse\")) {\n"
+		"	this.deActivateRect = document.createElementNS(svgNS,\"ellipse\"));\n"
+		"	this.deActivateRect.setAttributeNS(null,\"cx\"),this.x + this.width * 0.5);\n"
+		"	this.deActivateRect.setAttributeNS(null,\"cy\"),this.y + this.height * 0.5);\n"
+		"	this.deActivateRect.setAttributeNS(null,\"rx\"),this.width * 0.5 + this.shadowOffset);\n"
+		"	this.deActivateRect.setAttributeNS(null,\"ry\"),this.height * 0.5 + this.shadowOffset);\n"
+		"	}\n"
+		"	\n"
+		"	this.deActivateRect.setAttributeNS(null,\"fill\"),\"white\"));\n"
+		"	this.deActivateRect.setAttributeNS(null,\"fill-opacity\"),\"0.5\"));\n"
+		"	this.deActivateRect.setAttributeNS(null,\"stroke\"),\"none\"));\n"
+		"	this.deActivateRect.setAttributeNS(null,\"display\"),\"none\"));\n"
+		"	this.deActivateRect.setAttributeNS(null,\"cursor\"),\"default\"));\n"
+		"	this.buttonGroup.appendChild(this.deActivateRect);\n"
+		"}\n"
+		"\n"
+		"//remove all textbox elements\n"
+		"button.prototype.removeButton = function() {\n"
+		"	this.buttonGroup.removeChild(this.upperLeftShadow);\n"
+		"	this.buttonGroup.removeChild(this.lowerRightShadow);\n"
+		"	this.buttonGroup.removeChild(this.buttonRect);\n"
+		"	if (this.buttonTextElement) {\n"
+		"	this.buttonGroup.removeChild(this.buttonTextElement);	\n"
+		"	}\n"
+		"	if (this.buttonSymbolInstance) {\n"
+		"	this.buttonGroup.removeChild(this.buttonSymbolInstance);	\n"
+		"	}\n"
+		"	this.buttonGroup.removeChild(this.deActivateRect);\n"
+		"}\n"
+		"\n"
+		"//click on and write in textbox\n"
+		"button.prototype.handleEvent = function(evt) {\n"
+		"	if (evt.type == \"mousedown\")) {\n"
+		"	this.togglePressed(\"pressed\"));\n"
+		"	document.documentElement.addEventListener(\"mouseup\"),this,false);	\n"
+		"	}\n"
+		"	if (evt.type == \"mouseup\")) {\n"
+		"	this.togglePressed(\"released\"));\n"
+		"	document.documentElement.removeEventListener(\"mouseup\"),this,false);	\n"
+		"	}\n"
+		"	if (evt.type == \"click\")) {\n"
+		"	//for some strange reasons I could not forward the evt object here ;-(, the code below using a literal is a workaround\n"
+		"	//attention: only some of the evt properties are forwarded here, you can add more, if you need them\n"
+		"	var timerEvt = {x:evt.clientX,y:evt.clientY,type:evt.type,detail:evt.detail,timeStamp:evt.timeStamp}\n"
+		"	this.timer.setTimeout(\"fireFunction\"),this.timerMs,timerEvt)\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"button.prototype.togglePressed = function(type) {\n"
+		"	if (type == \"pressed\")) {\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"fill\"),this.shadeDarkFill);	\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"fill\"),this.shadeLightFill);\n"
+		"	}\n"
+		"	if (type == \"released\")) {\n"
+		"	this.upperLeftShadow.setAttributeNS(null,\"fill\"),this.shadeLightFill);	\n"
+		"	this.lowerRightShadow.setAttributeNS(null,\"fill\"),this.shadeDarkFill);	\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"button.prototype.fireFunction = function(evt) {\n"
+		"	if (typeof(this.functionToCall) == \"function\")) {\n"
+		"	if (this.buttonTextElement) {\n"
+		"		this.functionToCall(this.groupId,evt,this.buttonText);\n"
+		"	}\n"
+		"	if (this.buttonSymbolInstance) {\n"
+		"		this.functionToCall(this.groupId,evt);\n"
+		"	}\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == \"object\")) {\n"
+		"	if (this.buttonTextElement) {\n"
+		"		this.functionToCall.buttonPressed(this.groupId,evt,this.buttonText);\n"
+		"	}\n"
+		"	if (this.buttonSymbolInstance) {\n"
+		"		this.functionToCall.buttonPressed(this.groupId,evt);\n"
+		"	}\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == undefined) {\n"
+		"	return;	\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"button.prototype.getTextValue = function() {\n"
+		"	return this.buttonText;\n"
+		"}	\n"
+		"\n"
+		"button.prototype.setTextValue = function(value) {\n"
+		"	this.buttonText = value;\n"
+		"	this.buttonTextElement.firstChild.nodeValue=this.buttonText;\n"
+		"}\n"
+		"\n"
+		"button.prototype.activate = function(value) {\n"
+		"	this.deActivateRect.setAttributeNS(null,\"display\"),\"none\"));\n"
+		"	this.activated = true;\n"
+		"}\n"
+		"\n"
+		"button.prototype.deactivate = function(value) {\n"
+		"	this.deActivateRect.setAttributeNS(null,\"display\"),\"inherit\"));\n"
+		"	this.activated = false;\n"
+		"}\n"
+		"\n"
+		"//switchbutton\n"
+		"//initialize inheritance\n"
+		"switchbutton.prototype = new button();\n"
+		"switchbutton.prototype.constructor = switchbutton;\n"
+		"switchbutton.superclass = button.prototype;\n"
+		"\n"
+		"function switchbutton(groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset) {\n"
+		"	if (arguments.length > 0) {\n"
+		"	this.init(groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"switchbutton.prototype.init = function(groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset) {\n"
+		"	switchbutton.superclass.init.call(this,groupId,functionToCall,buttonType,buttonText,buttonSymbolId,x,y,width,height,fontSize,fontFamily,textFill,buttonFill,shadeLightFill,shadeDarkFill,shadowOffset);\n"
+		"	this.on = false;\n"
+		"}\n"
+		"\n"
+		"//overwriting handleEventcode\n"
+		"switchbutton.prototype.handleEvent = function(evt) {\n"
+		"	//for some strange reasons I could not forward the evt object here ;-(, the code below using a literal is a workaround\n"
+		"	//attention: only some of the evt properties are forwarded here, you can add more, if you need them\n"
+		"	var timerEvt = {x:evt.clientX,y:evt.clientY,type:evt.type,detail:evt.detail,timeStamp:evt.timeStamp}\n"
+		"	if (evt.type == \"click\")) {\n"
+		"	if (this.on) {\n"
+		"		this.on = false;\n"
+		"		this.togglePressed(\"released\"));\n"
+		"		this.timer.setTimeout(\"fireFunction\"),this.timerMs,timerEvt);\n"
+		"	}\n"
+		"	else {\n"
+		"		this.on = true;\n"
+		"		this.togglePressed(\"pressed\"));		\n"
+		"		this.timer.setTimeout(\"fireFunction\"),this.timerMs,timerEvt);\n"
+		"	}\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"switchbutton.prototype.getSwitchValue = function() {\n"
+		"	return this.on;\n"
+		"}\n"
+		"\n"
+		"switchbutton.prototype.setSwitchValue = function(onOrOff,firefunction) {\n"
+		"	this.on = onOrOff;\n"
+		"	//artificial timer event - don't use the values!\n"
+		"	var timerEvt = {x:0,y:0,type:\"click\"),detail:1,timeStamp:0}\n"
+		"	if (this.on) {\n"
+		"	this.togglePressed(\"pressed\"));\n"
+		"	if (firefunction) {\n"
+		"		this.timer.setTimeout(\"fireFunction\"),this.timerMs,timerEvt);\n"
+		"	}\n"
+		"	}\n"
+		"	else {\n"
+		"	this.togglePressed(\"released\"));		\n"
+		"	if (firefunction) {\n"
+		"		this.timer.setTimeout(\"fireFunction\"),this.timerMs,timerEvt)\n"
+		"	}\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//overwriting fireFunction code\n"
+		"switchbutton.prototype.fireFunction = function(evt) {\n"
+		"	if (typeof(this.functionToCall) == \"function\")) {\n"
+		"	if (this.buttonTextElement) {\n"
+		"		this.functionToCall(this.groupId,evt,this.on,this.buttonText);\n"
+		"	}\n"
+		"	if (this.buttonSymbolInstance) {\n"
+		"		this.functionToCall(this.groupId,evt,this.on);\n"
+		"	}\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == \"object\")) {\n"
+		"	if (this.buttonTextElement) {\n"
+		"		this.functionToCall.buttonPressed(this.groupId,evt,this.on,this.buttonText);\n"
+		"	}\n"
+		"	if (this.buttonSymbolInstance) {\n"
+		"		this.functionToCall.buttonPressed(this.groupId,evt,this.on);\n"
+		"	}\n"
+		"	}\n"
+		"	if (typeof(this.functionToCall) == undefined) {\n"
+		"	return;	\n"
+		"	}\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Navigation_1(void)
+{
+	return( SG_STR_MBTOSG(
+		"/*\n"
+		"Scripts for SVG only webmapping application navigation tools\n"
+		"Copyright (C) <2005>  <Andreas Neumann>\n"
+		"Version 1.1, 2005-10-05\n"
+		"neumann at karto.baug.ethz.ch\n"
+		"http://www.carto.net/\n"
+		"http://www.carto.net/neumann/\n"
+		"\n"
+		"Credits: numerous people on svgdevelopers at yahoogroups.com\n"
+		"\n"
+		"This ECMA script library is free software; you can redistribute it and/or\n"
+		"modify it under the terms of the GNU Lesser General Public\n"
+		"License as published by the Free Software Foundation; either\n"
+		"version 2.1 of the License, or (at your option) any later version.\n"
+		"\n"
+		"This library is distributed in the hope that it will be useful,\n"
+		"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
+		"Lesser General Public License for more details.\n"
+		"\n"
+		"You should have received a copy of the GNU Lesser General Public\n"
+		"License along with this library (http://www.carto.net/papers/svg/navigationTools/lesser_gpl.txt); if not, write to the Free Software\n"
+		"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
+		"\n"
+		"----\n"
+		"\n"
+		"current version: 1.1\n"
+		"\n"
+		"version history:\n"
+		"1.0 initial version\n"
+		"1.01 (2005-02-15) added cleanUp() method to map and dragObj objects, some fixes in the documentation\n"
+		"1.02 (2005-02-20) fixed problems with double clicks, the second click of a double click is now ignored, using the evt.detail property\n"
+		"1.03 (2005-02-22) introduced timestamp and nrLayerToLoad array for dynamic loading (getUrl)\n"
+		"1.04 (2005-09-15) introduced a few changes with coordinate calculation to support MozillaSVG, introduced epsg and unitsFactor property based on a suggestion by Bruce Rindahl\n"
+		"1.1 (2005-10-05) introduced button object (see button.js file), introduced zoom and pan \"modes\" for repeated actions in the same mode, introduced history of map extents with the ability to go back and forth in the list of previous map extents, some internal changes in the code (e.g. less global variables), added experimental support for the batik SVG 1.2 \"static\" attribute to improve performance while panning the map, added cursors to give better status feedback\n"
+		"\n"
+		"original document site: http://www.carto.net/papers/svg/navigationTools/\n"
+		"Please contact the author in case you want to use code or ideas commercially.\n"
+		"If you use this code, please include this copyright header, the included full\n"
+		"LGPL 2.1 text and read the terms provided in the LGPL 2.1 license\n"
+		"(http://www.gnu.org/copyleft/lesser.txt)\n"
+		"\n"
+		"-------------------------------\n"
+		"\n"
+		"Please report bugs and send improvements to neumann at karto.baug.ethz.ch\n"
+		"If you use these scripts, please link to the original (http://www.carto.net/papers/svg/navigationTools/)\n"
+		"somewhere in the source-code-comment or the \"about\" of your project and give credits, thanks!\n"
+		"\n"
+		"*/\n"
+		"\n"
+		"//constructor: holds data on map and initializes various references\n"
+		"function map(mapName,maxWidth,minWidth,zoomFact,nrDecimals,epsg,units,unitsFactor,showCoords,coordXId,coordYId,dynamicLayers,digiLayers,activeDigiLayer) {\n"
+		"	this.mapName = mapName; //id of svg element containing the map geometry\n"
+		"	this.mapSVG = document.getElementById(this.mapName); //reference to nested SVG element holding the map-graphics\n"
+		"	this.mainMapGroup = document.getElementById(this.mapName+\"Group\")); //group within mainmap - to be transformed when panning manually\n"
+		"	this.dynamicLayers = dynamicLayers; //an associative array holding ids of values that are loaded from the web server dynamically (.getUrl())\n"
+		"	this.nrLayerToLoad = 0; //statusVariable to indicate how many layers are still to load\n"
+		"	this.maxWidth = maxWidth; //max map width\n"
+		"	this.minWidth = minWidth; //min map width, after zooming in\n"
+		"	this.zoomFact = zoomFact; //ratio to zoom in or out in relation to previous viewBox\n"
+		"	this.digiLayers = digiLayers; //references to digiLayers (for digitizing tools)\n"
+		"	this.activeDigiLayer = activeDigiLayer; //active Digi Layer, key is final group id where geometry should be copied to after digitizing\n"
+		"	this.pixXOffset = parseFloat(this.mapSVG.getAttributeNS(null,\"x\"))); //offset from left margin of outer viewBox\n"
+		"	this.pixYOffset = parseFloat(this.mapSVG.getAttributeNS(null,\"y\"))); //offset from top margin of outer viewBox\n"
+		"	var viewBoxArray = this.mapSVG.getAttributeNS(null,\"viewBox\")).split(\" \"));\n"
+		"	this.curxOrig = parseFloat(viewBoxArray[0]); //holds the current xOrig\n"
+		"	this.curyOrig = parseFloat(viewBoxArray[1]); //holds the current yOrig\n"
+		"	this.curWidth = parseFloat(viewBoxArray[2]); //holds the current map width\n"
+		"	this.curHeight = parseFloat(viewBoxArray[3]); //holds the current map height\n"
+		"	this.pixWidth = parseFloat(this.mapSVG.getAttributeNS(null,\"width\"))); //holds width of the map in pixel coordinates\n"
+		"	this.pixHeight = parseFloat(this.mapSVG.getAttributeNS(null,\"height\"))); //holds height of the map in pixel coordinates\n"
+		"	this.pixSize = this.curWidth / this.pixWidth; //size of a screen pixel in map units\n"
+		"	this.zoomVal = this.maxWidth / this.curWidth * 100; //zoomVal in relation to initial zoom\n"
+		"	this.nrDecimals = nrDecimals; //nr of decimal places to be displayed for show coordinates or accuracy when working with digitizing\n"
+		"	this.epsg = epsg; //epsg projection code - can be used for building URL strings for loading data from a WMS or spatial database, if you don't need it just input any number\n"
+		"	this.navStatus = \"info\"); //to indicate status in navigation, default is \"info\"), no navigation mode active\n"
+		"	this.units = units; //holds a string with map units, e.g. \"m\"), alternatively String.fromCharCode(176) for degrees\n"
+		"	this.unitsFactor = unitsFactor; //a factor for unit conversion. Can be used f.e. to output feet coordinates when data is meter, If you don't need a conversion, just use a factor of 1\n"
+		"	this.showCoords = showCoords;\n"
+		"	//initialize array of timestamp/layertoLoad values\n"
+		"	this.nrLayerToLoad = new Array();\n"
+		"	this.timestamp = null; //holds the timestamp after a zoom or pan occured\n"
+		"	//initialize coordinate display if showCoords == true\n"
+		"	if (this.showCoords == true) {\n"
+		"		//add event listener for coordinate display\n"
+		"		this.mapSVG.addEventListener(\"mousemove\"),this,false);\n"
+		"		if (typeof(coordXId) == \"string\")) {\n"
+		"			this.coordXText = document.getElementById(coordXId).firstChild;\n"
+		"		}\n"
+		"		else {\n"
+		"			alert(\"Error: coordXId needs to be an id of type string\"));\n"
+		"		}\n"
+		"		if (typeof(coordYId) == \"string\")) {\n"
+		"			this.coordYText = document.getElementById(coordYId).firstChild;\n"
+		"		}\n"
+		"		else {\n"
+		"			alert(\"Error: coordYId needs to be an id of type string\"));\n"
+		"		}\n"
+		"	}\n"
+		"	//a new array containing map extents\n"
+		"	this.mapExtents = new Array();\n"
+		"	this.mapExtents.push({xmin:this.curxOrig,ymin:((this.curyOrig + this.curHeight) * -1),xmax:(this.curxOrig + this.curWidth),ymax:(this.curyOrig * -1)});\n"
+		"	this.curMapExtentIndex = 0;\n"
+		"	//create background-element to receive events for showing coordinates\n"
+		"	//this rect is also used for manual zooming and panning\n"
+		"	this.backgroundRect = document.createElementNS(svgNS,\"rect\"));\n"
+		"	this.backgroundRect.setAttributeNS(null,\"x\"),this.curxOrig);\n"
+		"	this.backgroundRect.setAttributeNS(null,\"y\"),this.curyOrig);\n"
+		"	this.backgroundRect.setAttributeNS(null,\"width\"),this.curWidth);\n"
+		"	this.backgroundRect.setAttributeNS(null,\"height\"),this.curHeight);\n"
+		"	this.backgroundRect.setAttributeNS(null,\"fill\"),\"none\"));\n"
+		"	this.backgroundRect.setAttributeNS(null,\"stroke\"),\"none\"));\n"
+		"	this.backgroundRect.setAttributeNS(null,\"pointer-events\"),\"fill\"));\n"
+		"	this.backgroundRect.setAttributeNS(null,\"id\"),\"mapBackgroundRect\"));\n"
+		"	this.backgroundRect.addEventListener(\"mousedown\"),this,false);\n"
+		"	this.backgroundRect.addEventListener(\"mousemove\"),this,false);\n"
+		"	this.backgroundRect.addEventListener(\"mouseup\"),this,false);\n"
+		"	this.backgroundRect.addEventListener(\"mouseout\"),this,false);\n"
+		"	this.backgroundRect.addEventListener(\"click\"),this,false);\n"
+		"	this.mainMapGroup.insertBefore(this.backgroundRect,this.mainMapGroup.firstChild);\n"
+		"	//determine if viewer is capable of getScreenCTM\n"
+		"	if (document.documentElement.getScreenCTM) {\n"
+		"		this.getScreenCTM = true;\n"
+		"	}\n"
+		"	else {\n"
+		"		this.getScreenCTM = false;		\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//resets viewBox of main map after zooming and panning\n"
+		"map.prototype.newViewBox = function(refRectId,history) {\n"
+		"	var myRefRect = document.getElementById(refRectId);\n"
+		"	this.curxOrig = parseFloat(myRefRect.getAttributeNS(null,\"x\")));\n"
+		"	this.curyOrig = parseFloat(myRefRect.getAttributeNS(null,\"y\")));\n"
+		"	this.curWidth = parseFloat(myRefRect.getAttributeNS(null,\"width\")));\n"
+		"	this.curHeight = parseFloat(myRefRect.getAttributeNS(null,\"height\")));\n"
+		"	var myViewBoxString = this.curxOrig + \" \" + this.curyOrig + \" \" + this.curWidth + \" \" + this.curHeight;\n"
+		"	this.pixSize = this.curWidth / this.pixWidth;\n"
+		"	this.zoomVal = this.maxWidth / this.curWidth * 100;\n"
+		"	this.mapSVG.setAttributeNS(null,\"viewBox\"),myViewBoxString);\n"
+		"	myMapApp.zoomSlider.setValue(this.curWidth);\n"
+		"	loadProjectSpecific();\n"
+		"	if (history) {\n"
+		"	    this.mapExtents.push({xmin:this.curxOrig,ymin:((this.curyOrig + this.curHeight) * -1),xmax:(this.curxOrig + this.curWidth),ymax:(this.curyOrig * -1)});\n"
+		"               this.curMapExtentIndex = (this.mapExtents.length - 1);\n"
+		"	}\n"
+		"	this.checkButtons();\n"
+		"}\n"
+		"\n"
+		"map.prototype.backwardExtent = function() {\n"
+		"    if (this.curMapExtentIndex != 0) {\n"
+		"        this.curMapExtentIndex--;\n"
+		"        this.setNewViewBox(this.mapExtents[this.curMapExtentIndex].xmin,this.mapExtents[this.curMapExtentIndex].ymin,this.mapExtents[this.curMapExtentIndex].xmax,this.mapExtents[this.curMapExtentIndex].ymax,false);\n"
+		"    }\n"
+		"}\n"
+		"\n"
+		"map.prototype.forwardExtent = function() {\n"
+		"    if (this.mapExtents.length != (this.curMapExtentIndex + 1)) {\n"
+		"        this.curMapExtentIndex++;\n"
+		"        this.setNewViewBox(this.mapExtents[this.curMapExtentIndex].xmin,this.mapExtents[this.curMapExtentIndex].ymin,this.mapExtents[this.curMapExtentIndex].xmax,this.mapExtents[this.curMapExtentIndex].ymax,false);\n"
+		"    }\n"
+		"}\n"
+		"\n"
+		"map.prototype.checkButtons = function() {\n"
+		"           //check extent history\n"
+		"           if (this.curMapExtentIndex == 0) {\n"
+		"                if (myMapApp.buttons[\"backwardExtent\"].activated) {\n"
+		"                  myMapApp.buttons[\"backwardExtent\"].deactivate();\n"
+		"                }\n"
+		"           }\n"
+		"           else {\n"
+		"                if (!myMapApp.buttons[\"backwardExtent\"].activated) {\n"
+		"                  myMapApp.buttons[\"backwardExtent\"].activate();\n"
+		"                }           \n"
+		"           }\n"
+		"           if (this.mapExtents.length == (this.curMapExtentIndex + 1)) {\n"
+		"                if (myMapApp.buttons[\"forwardExtent\"].activated) {\n"
+		"                   myMapApp.buttons[\"forwardExtent\"].deactivate();\n"
+		"                }\n"
+		"           }\n"
+		"           else {\n"
+		"                if (!myMapApp.buttons[\"forwardExtent\"].activated) {\n"
+		"                  myMapApp.buttons[\"forwardExtent\"].activate();\n"
+		"                }           \n"
+		"           }\n"
+		" \n"
+		"           //maximum map width reached, cannot zoom out further\n"
+		"           if (this.curWidth >= this.maxWidth) {\n"
+		"               if (myMapApp.buttons[\"zoomOut\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomOut\"].deactivate();\n"
+		"               }\n"
+		"               if (myMapApp.buttons[\"zoomFull\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomFull\"].deactivate();\n"
+		"               }\n"
+		"               if (myMapApp.buttons[\"panManual\"].activated) {\n"
+		"                   myMapApp.buttons[\"panManual\"].deactivate();\n"
+		"               }\n"
+		"               if (myMapApp.buttons[\"recenterMap\"].activated) {\n"
+		"                   myMapApp.buttons[\"recenterMap\"].deactivate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomIn\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomIn\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomManual\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomManual\"].activate();\n"
+		"               }\n"
+		"           }\n"
+		"           //minimum map width reached, cannot zoom in further\n"
+		"           else if (this.curWidth <= this.minWidth) {\n"
+		"               if (myMapApp.buttons[\"zoomIn\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomIn\"].deactivate();\n"
+		"               }\n"
+		"               if (myMapApp.buttons[\"zoomManual\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomManual\"].deactivate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomOut\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomOut\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomFull\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomFull\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"panManual\"].activated) {\n"
+		"                   myMapApp.buttons[\"panManual\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"recenterMap\"].activated) {\n"
+		"                   myMapApp.buttons[\"recenterMap\"].activate();\n"
+		"               }           \n"
+		"           }\n"
+		"           //in between\n"
+		"           else {\n"
+		"               if (!myMapApp.buttons[\"zoomIn\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomIn\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomManual\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomManual\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomOut\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomOut\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"zoomFull\"].activated) {\n"
+		"                   myMapApp.buttons[\"zoomFull\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"panManual\"].activated) {\n"
+		"                   myMapApp.buttons[\"panManual\"].activate();\n"
+		"               }\n"
+		"               if (!myMapApp.buttons[\"recenterMap\"].activated) {\n"
+		"                   myMapApp.buttons[\"recenterMap\"].activate();\n"
+		"               }           \n"
+		"           }           \n"
+		"}\n"
+		"\n"
+		"map.prototype.setNewViewBox = function(xmin,ymin,xmax,ymax,history) {\n"
+		"	//check if within constraints\n"
+		"	if (xmin < myMapApp.refMapDragger.constrXmin) {\n"
+		"		xmin = myMapApp.refMapDragger.constrXmin;\n"
+		"	}\n"
+		"	if (xmax > myMapApp.refMapDragger.constrXmax) {\n"
+		"		xmax = myMapApp.refMapDragger.constrXmin;\n"
+		"	}\n"
+		"	if (ymin < (myMapApp.refMapDragger.constrYmax * -1)) {\n"
+		"		ymin = myMapApp.refMapDragger.constrYmax * -1;\n"
+		"	}\n"
+		"	if (ymax > (myMapApp.refMapDragger.constrYmin * -1)) {\n"
+		"		ymax = myMapApp.refMapDragger.constrYmin * -1;\n"
+		"	}\n"
+		"	\n"
+		"	var origWidth = xmax - xmin;\n"
+		"	var origHeight = ymax - ymin;\n"
+		"	var myRatio = this.curWidth/this.curHeight;\n"
+		"	\n"
+		"	if (origWidth / origHeight > myRatio) { //case rect is more wide than ratio\n"
+		"		var newWidth = origWidth;\n"
+		"		var newHeight = origWidth * 1 / myRatio;\n"
+		"		ymin = (ymax + (newHeight - origHeight) / 2) * -1;\n"
+		"	}\n"
+		"	else {\n"
+		"		var newHeight = origHeight;\n"
+		"		var newWidth = newHeight * myRatio;\n"
+		"		xmin = xmin - (newWidth - origWidth) / 2;\n"
+		"		ymin = ymax * -1;\n"
+		"	}\n"
+		"	//check if within constraints\n"
+		"	if (xmin < myMapApp.refMapDragger.constrXmin) {\n"
+		"		xmin = myMapApp.refMapDragger.constrXmin;\n"
+		"	}\n"
+		"	if (ymin < myMapApp.refMapDragger.constrYmin) {\n"
+		"		ymin = myMapApp.refMapDragger.constrYmin;\n"
+		"	}\n"
+		"	if ((xmin + newWidth) > myMapApp.refMapDragger.constrXmax) {\n"
+		"		xmin = myMapApp.refMapDragger.constrXmax - newWidth;\n"
+		"	}\n"
+		"	if ((ymin + newHeight) > myMapApp.refMapDragger.constrYmax) {\n"
+		"		ymin = myMapApp.refMapDragger.constrYmax - newHeight;\n"
+		"	}		\n"
+		"	myMapApp.refMapDragger.newView(xmin,ymin,newWidth,newHeight);\n"
+		"	this.newViewBox(myMapApp.refMapDragger.dragId,history);\n"
+		"}\n"
+		"\n"
+		"//handles events associated with navigation\n"
+		"map.prototype.handleEvent = function(evt) {\n"
+		"	var callerId = evt.currentTarget.getAttributeNS(null,\"id\"));\n"
+		"	if (callerId.match(/\\bzoomBgRectManual/)) {\n"
+		"		this.zoomManDragRect(evt);\n"
+		"	}\n"
+		"	if (callerId.match(/\\bzoomBgRectRecenter/)) {\n"
+		"		this.recenterFinally(evt);\n"
+		"	}\n"
+		"	if (callerId.match(/\\bbgPanManual/)) {\n"
+		"		this.panManualFinally(evt);\n"
+		"	}\n"
+		"	if (callerId == \"mainMap\" && evt.type == \"mousemove\")) {\n"
+		"		if (this.navStatus != \"panmanualActive\")) {\n"
+		"		    this.showCoordinates(evt);\n"
+		"		}\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//calcs coordinates; relies on myMapApp to handle different window sizes and resizing of windows\n"
+		"map.prototype.calcCoord = function(evt) {\n"
+		"	//with getScreenCTM the values are already in the inner coordinate system\n"
+		"	if (!this.getScreenCTM) {\n"
+		"		var coords = myMapApp.calcCoord(evt,this.mapSVG);\n"
+		"		coords.x = this.curxOrig + (coords.x - this.pixXOffset) * this.pixSize;\n"
+		"		coords.y = (this.curyOrig + (coords.y - this.pixYOffset) * this.pixSize);\n"
+		"	}\n"
+		"	else {	\n"
+		"		var coords = myMapApp.calcCoord(evt,this.mainMapGroup);\n"
+		"	}\n"
+		"	return coords;\n"
+		"}\n"
+		"\n"
+		"//displays x and y coordinates in two separate text elements\n"
+		"map.prototype.showCoordinates = function(evt) {\n"
+		"	var mapCoords = this.calcCoord(evt);\n"
+		"	this.coordXText.nodeValue = \"X: \" + formatNumberString((mapCoords.x * this.unitsFactor).toFixed(this.nrDecimals)) + this.units;\n"
+		"	this.coordYText.nodeValue = \"Y: \" + formatNumberString((mapCoords.y * this.unitsFactor * -1).toFixed(this.nrDecimals)) + this.units;\n"
+		"}\n"
+		"\n"
+		"//checks for and removes temporary rectangle objects\n"
+		"map.prototype.stopNavModes = function() {\n"
+		"	if (this.navStatus != \"info\")) {\n"
+		"                    	if (this.navStatus == \"zoomManual\")) {\n"
+		"                    	    myMapApp.buttons[\"zoomManual\"].setSwitchValue(false,false);\n"
+		"                    	}\n"
+		"                     	if (this.navStatus == \"panmanual\" || this.navStatus == \"panmanualActive\")) {\n"
+		"                    	    myMapApp.buttons[\"panManual\"].setSwitchValue(false,false);\n"
+		"                    	}\n"
+		"                    	if (this.navStatus == \"recenter\")) {\n"
+		"                    	    myMapApp.buttons[\"recenterMap\"].setSwitchValue(false,false);\n"
+		"                    	}\n"
+		"                              this.backgroundRect.setAttributeNS(null,\"id\"),\"mapBackgroundRect\"));\n"
+		"		myMapApp.buttons[\"infoButton\"].setSwitchValue(true,false);\n"
+		"		this.navStatus = \"info\");\n"
+		"	               this.mapSVG.setAttributeNS(null,\"cursor\"),\"crosshair\"));\n"
+		"		statusChange(\"Mode: Infomode\"));\n"
+		"	               this.mainMapGroup.insertBefore(this.backgroundRect,this.mainMapGroup.firstChild);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//starts manual zooming mode\n"
+		"map.prototype.zoomManual = function(evt) {\n"
+		"	if (Math.round(myMainMap.curWidth) > myMainMap.minWidth && evt.detail == 1) {\n"
+		"		this.navStatus = \"zoomManual\");\n"
+		"                              this.backgroundRect.setAttributeNS(null,\"id\"),\"zoomBgRectManual\"));	\n"
+		"	               this.mainMapGroup.appendChild(this.backgroundRect);\n"
+		"	               this.mapSVG.setAttributeNS(null,\"cursor\"),\"se-resize\"));\n"
+		"		statusChange(\"Click and drag rectangle for new map extent.\"));\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//manages manual zooming by drawing a rectangle\n"
+		"map.prototype.zoomManDragRect = function(evt) {\n"
+		"	var mapCoords = this.calcCoord(evt);\n"
+		"	var myX = mapCoords.x;\n"
+		"	var myY = mapCoords.y;\n"
+		"	var myYXFact = this.curHeight / this.curWidth;\n"
+		"	if (evt.type == \"mousedown\")) {\n"
+		"		this.manZoomActive = 1;\n"
+		"		this.zoomRect = document.createElementNS(svgNS,\"rect\"));\n"
+		"		var myLineWidth = this.curWidth * 0.003;\n"
+		"		this.zoomRect.setAttributeNS(null,\"id\"),\"zoomRect\"));\n"
+		"		this.zoomRect.setAttributeNS(null,\"fill\"),\"white\"));\n"
+		"		this.zoomRect.setAttributeNS(null,\"fill-opacity\"),\"0.5\"));\n"
+		"		this.zoomRect.setAttributeNS(null,\"stroke\"),\"dimgray\"));\n"
+		"		this.zoomRect.setAttributeNS(null,\"stroke-width\"),myLineWidth);\n"
+		"		this.zoomRect.setAttributeNS(null,\"stroke-dasharray\"),(myLineWidth*3)+\"),\"+myLineWidth);\n"
+		"		this.zoomRect.setAttributeNS(null,\"pointer-events\"),\"none\"));\n"
+		"		this.zoomRect.setAttributeNS(null,\"x\"),myX);\n"
+		"		this.zoomRect.setAttributeNS(null,\"y\"),myY);\n"
+		"		this.zoomRect.setAttributeNS(null,\"width\"),this.minWidth);\n"
+		"		this.zoomRect.setAttributeNS(null,\"height\"),this.minWidth * myYXFact);\n"
+		"		this.mainMapGroup.appendChild(this.zoomRect);\n"
+		"		this.zoomRectOrigX = myX;\n"
+		"		this.zoomRectOrigY = myY;\n"
+		"	}\n"
+		"	if (evt.type == \"mousemove\" && this.manZoomActive == 1) {\n"
+		"		var myZoomWidth = myX - this.zoomRectOrigX;\n"
+		"		if (myZoomWidth < 0) {\n"
+		"			if (Math.abs(myZoomWidth) < this.minWidth) {\n"
+		"				this.zoomRect.setAttributeNS(null,\"x\"),this.zoomRectOrigX - this.minWidth);\n"
+		"				this.zoomRect.setAttributeNS(null,\"y\"),this.zoomRectOrigY - this.minWidth * myYXFact);\n"
+		"				this.zoomRect.setAttributeNS(null,\"width\"),this.minWidth);\n"
+		"				this.zoomRect.setAttributeNS(null,\"height\"),this.minWidth * myYXFact);\n"
+		"			}\n"
+		"			else {\n"
+		"				this.zoomRect.setAttributeNS(null,\"x\"),myX);\n"
+		"				this.zoomRect.setAttributeNS(null,\"y\"),this.zoomRectOrigY - Math.abs(myZoomWidth) * myYXFact);\n"
+		"				this.zoomRect.setAttributeNS(null,\"width\"),Math.abs(myZoomWidth));\n"
+		"				this.zoomRect.setAttributeNS(null,\"height\"),Math.abs(myZoomWidth) * myYXFact);			\n"
+		"			}\n"
+		"		}\n"
+		"		else {\n"
+		"			this.zoomRect.setAttributeNS(null,\"x\"),this.zoomRectOrigX);\n"
+		"			this.zoomRect.setAttributeNS(null,\"y\"),this.zoomRectOrigY);\n"
+		"			if (myZoomWidth < this.minWidth) {\n"
+		"				this.zoomRect.setAttributeNS(null,\"width\"),this.minWidth);\n"
+		"				this.zoomRect.setAttributeNS(null,\"height\"),this.minWidth * myYXFact);		\n"
+		"			}\n"
+		"			else {\n"
+		"				this.zoomRect.setAttributeNS(null,\"width\"),myZoomWidth);\n"
+		"				this.zoomRect.setAttributeNS(null,\"height\"),myZoomWidth * myYXFact);\n"
+		"			}\n"
+		"		}\n"
+		"	}\n"
+		"	if ((evt.type == \"mouseup\" || evt.type == \"mouseout\")) && this.manZoomActive == 1) {\n"
+		"		this.manZoomActive = 0;\n"
+		"		if (parseFloat(this.zoomRect.getAttributeNS(null,\"width\"))) > this.curWidth * 0.02) {\n"
+		"			myMapApp.refMapDragger.newView(parseFloat(this.zoomRect.getAttributeNS(null,\"x\"))),parseFloat(this.zoomRect.getAttributeNS(null,\"y\"))),parseFloat(this.zoomRect.getAttributeNS(null,\"width\"))),parseFloat(this.zoomRect.getAttributeNS(null,\"height\"))));\n"
+		"			this.newViewBox(myMapApp.refMapDragger.dragId,true);\n"
+		"		}\n"
+		"		this.mainMapGroup.removeChild(this.zoomRect);\n"
+		"		statusChange(\"Mode: Manual Zooming\"));\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//initializes recentering mode\n"
+		"map.prototype.recenter = function(evt) {\n"
+		"	if (evt.detail == 1) {\n"
+		"		this.navStatus = \"recenter\");\n"
+		"                              this.backgroundRect.setAttributeNS(null,\"id\"),\"zoomBgRectRecenter\"));	\n"
+		"	               this.mainMapGroup.appendChild(this.backgroundRect);\n"
+		"	               this.mapSVG.setAttributeNS(null,\"cursor\"),\"pointer\"));\n"
+		"		statusChange(\"Click in map to define new map center.\"));\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//finishes recentering after mouse-click\n"
+		"map.prototype.recenterFinally = function(evt) {\n"
+		"	if (evt.type == \"click\")) {\n"
+		"		var mapCoords = this.calcCoord(evt);\n"
+		"		var myX = mapCoords.x;\n"
+		"		var myY = mapCoords.y;\n"
+		"		var myNewX = myX - this.curWidth / 2;\n"
+		"		var myNewY = myY - this.curHeight / 2;\n"
+		"		\n"
+		"		//check if within constraints\n"
+		"		if (myNewX < myMapApp.refMapDragger.constrXmin) {\n"
+		"			myNewX = myMapApp.refMapDragger.constrXmin;\n"
+		"		}\n"
+		"		if (myNewY < myMapApp.refMapDragger.constrYmin) {\n"
+		"			myNewY = myMapApp.refMapDragger.constrYmin;\n"
+		"		}\n"
+		"		if ((myNewX + this.curWidth) > myMapApp.refMapDragger.constrXmax) {\n"
+		"			myNewX = myMapApp.refMapDragger.constrXmax - this.curWidth;\n"
+		"		}\n"
+		"		if ((myNewY + this.curHeight) > myMapApp.refMapDragger.constrYmax) {\n"
+		"			myNewY = myMapApp.refMapDragger.constrYmax - this.curHeight;\n"
+		"		}\n"
+		"		myMapApp.refMapDragger.newView(myNewX,myNewY,this.curWidth,this.curHeight);\n"
+		"		this.newViewBox(myMapApp.refMapDragger.dragId,true);\n"
+		"		statusChange(\"Mode: Recentering Map\"));\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//initializes manual panning\n"
+		"map.prototype.panManual = function(evt) {\n"
+		"	if (evt.detail == 1) {\n"
+		"		this.navStatus = \"panmanual\");\n"
+		"                              this.backgroundRect.setAttributeNS(null,\"id\"),\"bgPanManual\"));	\n"
+		"	               this.mainMapGroup.appendChild(this.backgroundRect);\n"
+		"	               this.mapSVG.setAttributeNS(null,\"cursor\"),\"move\"));\n"
+		"		statusChange(\"Mouse down and move to pan the map\"));\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//manages and finishes manual panning\n"
+		"map.prototype.panManualFinally = function(evt) {\n"
+		"	if (evt.type == \"mousedown\")) {\n"
+		"		this.navStatus = \"panmanualActive\");\n"
+		"		this.panCoords = this.calcCoord(evt);\n"
+		"		this.panCoorX = this.panCoords.x;\n"
+		"		this.panCoorY = this.panCoords.y;\n"
+		"		this.diffX = 0;\n"
+		"		this.diffY = 0;\n"
+		"		this.mainMapGroup.setAttributeNS(batikNS,\"static\"),\"true\"));\n"
+		"	}\n"
+		"	if (evt.type == \"mousemove\" && this.navStatus == \"panmanualActive\")) {\n"
+		"		var mapCoords = this.calcCoord(evt);\n"
+		"		if (this.getScreenCTM) {\n"
+		"			this.diffX = this.panCoorX - mapCoords.x + this.diffX;\n"
+		"			this.diffY = this.panCoorY - mapCoords.y + this.diffY;\n"
+		"		}\n"
+		"		else {\n"
+		"			this.diffX = this.panCoorX - mapCoords.x;\n"
+		"			this.diffY = this.panCoorY - mapCoords.y;		\n"
+		"		}\n"
+		"		var myNewX = this.curxOrig + this.diffX;\n"
+		"		var myNewY = this.curyOrig + this.diffY;\n"
+		"		//check if within constraints\n"
+		"		if (myNewX < myMapApp.refMapDragger.constrXmin) {\n"
+		"			var myNewXTemp = myMapApp.refMapDragger.constrXmin;\n"
+		"			this.diffX = this.diffX + (myNewXTemp - myNewX);\n"
+		"			myNewX = myNewXTemp;\n"
+		"		}\n"
+		"		if (myNewY < myMapApp.refMapDragger.constrYmin) {\n"
+		"			var myNewYTemp = myMapApp.refMapDragger.constrYmin;\n"
+		"			this.diffY = this.diffY + (myNewYTemp - myNewY);\n"
+		"			myNewY = myNewYTemp;\n"
+		"		}\n"
+		"		if ((myNewX + this.curWidth) > myMapApp.refMapDragger.constrXmax) {\n"
+		"			var myNewXTemp = myMapApp.refMapDragger.constrXmax - this.curWidth;\n"
+		"			this.diffX = this.diffX + (myNewXTemp - myNewX);\n"
+		"			myNewX = myNewXTemp;\n"
+		"		}\n"
+		"		if ((myNewY + this.curHeight) > myMapApp.refMapDragger.constrYmax) {\n"
+		"			var myNewYTemp = myMapApp.refMapDragger.constrYmax - this.curHeight;\n"
+		"			this.diffY = this.diffY + (myNewYTemp - myNewY);\n"
+		"			myNewY = myNewYTemp;\n"
+		"		}	\n"
+		"		var transformString = \"translate(\"+(this.diffX * -1) +\"),\"+(this.diffY * -1)+\"))\");\n"
+		"		this.mainMapGroup.setAttributeNS(null,\"transform\"),transformString);\n"
+		"		myMapApp.refMapDragger.newView(myNewX,myNewY,this.curWidth,this.curHeight);\n"
+		"	}\n"
+		"	if ((evt.type == \"mouseup\" || evt.type == \"mouseout\")) && this.navStatus == \"panmanualActive\")) {\n"
+		"		this.navStatus = \"panmanual\");\n"
+		"		this.mainMapGroup.setAttributeNS(batikNS,\"static\"),\"false\"));\n"
+		"		this.mainMapGroup.setAttributeNS(null,\"transform\"),\"translate(0,0)\"));\n"
+		"		this.newViewBox(myMapApp.refMapDragger.dragId,true);			\n"
+		"		statusChange(\"Mode: Manual Panning\"));	\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//remove all temporarily added elements and event listeners\n"
+		"map.prototype.cleanUp = function() {\n"
+		"			//remove background rect\n"
+		"			this.backgroundRect.parentNode.removeChild(this.backgroundRect);\n"
+		"			//remove eventlisteners\n"
+		"			if (this.showCoords == true) {\n"
+		"				//add event listener for coordinate display\n"
+		"				this.mapSVG.removeEventListener(\"mousemove\"),this,false);\n"
+		"			}\n"
+		"\n"
+		"}\n"
+		"\n"
+		"//make an element (rectangle) draggable within constraints\n"
+		"function dragObj(dragId,referenceMap,myDragSymbol,dragSymbThreshold,showCoords,coordXId,coordYId,mainMapObj) {\n"
+		"	this.dragId = dragId;\n"
+		"	this.myDragger = document.getElementById(this.dragId);\n"
+		"	this.myRefMap = document.getElementById(referenceMap);\n"
+		"	this.myDragSymbol = document.getElementById(myDragSymbol);	\n"
+		"	this.dragSymbThreshold = dragSymbThreshold;\n"
+		"	var viewBox = this.myRefMap.getAttributeNS(null,\"viewBox\")).split(\" \"));\n"
+		"	this.constrXmin = parseFloat(viewBox[0]);\n"
+		"	this.constrYmin = parseFloat(viewBox[1]);\n"
+		"	this.constrXmax = this.constrXmin + parseFloat(viewBox[2]);\n"
+		"	this.constrYmax = this.constrYmin + parseFloat(viewBox[3]);\n"
+		"	this.refMapX = parseFloat(this.myRefMap.getAttributeNS(null,\"x\")));\n"
+		"	this.refMapY = parseFloat(this.myRefMap.getAttributeNS(null,\"y\")));\n"
+		"	this.refMapWidth = parseFloat(this.myRefMap.getAttributeNS(null,\"width\")));\n"
+		"	this.pixSize = (this.constrXmax - this.constrXmin) / this.refMapWidth;\n"
+		"	this.mainMapObj = mainMapObj;\n"
+		"	//initialize coordinate display if showCoords == true\n"
+		"	this.showCoords = showCoords;\n"
+		"	if (this.showCoords == true) {\n"
+		"		if (typeof(coordXId) == \"string\")) {\n"
+		"			this.coordXText = document.getElementById(coordXId).firstChild;\n"
+		"		}\n"
+		"		else {\n"
+		"			alert(\"Error: coordXId needs to be an id of type string\"));\n"
+		"		}\n"
+		"		if (typeof(coordYId) == \"string\")) {\n"
+		"			this.coordYText = document.getElementById(coordYId).firstChild;\n"
+		"		}\n"
+		"		else {\n"
+		"			alert(\"Error: coordYId needs to be an id of type string\"));\n"
+		"		}\n"
+		"	}\n"
+		"	//determine if viewer is capable of getScreenCTM\n"
+		"	if (document.documentElement.getScreenCTM) {\n"
+		"		this.getScreenCTM = true;\n"
+		"	}\n"
+		"	else {\n"
+		"		this.getScreenCTM = false;		\n"
+		"	}\n"
+		"	this.status = false;\n"
+		"}\n"
+		"\n"
+		"dragObj.prototype.calcCoord = function(evt) {\n"
+		"	//with getScreenCTM the values are already in the inner coordinate system but without using the outer offset\n"
+		"	var coordPoint = myMapApp.calcCoord(evt,this.myRefMap);\n"
+		"	if (!this.getScreenCTM) {\n"
+		"		coordPoint.x = this.constrXmin + (coordPoint.x - this.refMapX) * this.pixSize;\n"
+		"		coordPoint.y = this.constrYmin + (coordPoint.y - this.refMapY) * this.pixSize;\n"
+		"	}\n"
+		"	return coordPoint;\n"
+		"}\n"
+		"\n"
+		"dragObj.prototype.handleEvent = function(evt) {\n"
+		"	if (evt.type == \"mousemove\")) {\n"
+		"		var mapCoords = this.calcCoord(evt);\n"
+		"		this.coordXText.nodeValue = \"X: \" + formatNumberString(mapCoords.x.toFixed(this.mainMapObj.nrDecimals)) + this.mainMapObj.units;\n"
+		"		this.coordYText.nodeValue = \"Y: \" + formatNumberString((mapCoords.y * -1).toFixed(this.mainMapObj.nrDecimals)) + this.mainMapObj.units;\n"
+		"	}\n"
+		"	this.drag(evt);\n"
+		"}\n"
+		"\n"
+		"dragObj.prototype.newView = function(x,y,width,height) {\n"
+		"	this.myDragger.setAttributeNS(null,\"x\"),x);\n"
+		"	this.myDragger.setAttributeNS(null,\"y\"),y);\n"
+		"	this.myDragger.setAttributeNS(null,\"width\"),width);\n"
+		"	this.myDragger.setAttributeNS(null,\"height\"),height);\n"
+		"	this.myDragSymbol.setAttributeNS(null,\"x\"),(x + width/2));\n"
+		"	this.myDragSymbol.setAttributeNS(null,\"y\"),(y + height/2));\n"
+		"	if (width < this.dragSymbThreshold) {\n"
+		"		this.myDragSymbol.setAttributeNS(null,\"visibility\"),\"visible\"));\n"
+		"	}\n"
+		"	else {\n"
+		"		this.myDragSymbol.setAttributeNS(null,\"visibility\"),\"hidden\"));	\n"
+		"	}\n"
+		"}\n"
+		"\n"
+	));
+}
+
+//---------------------------------------------------------
+const wxChar * CSVG_Interactive_Map::_Get_Code_Navigation_2(void)
+{
+	return( SG_STR_MBTOSG(
+		"//this method was previously called \"resizeDragger\" - now renamed to .getSliderVal\n"
+		"//this method receives values from the zoom slider\n"
+		"dragObj.prototype.getSliderVal = function(status,sliderGroupName,width) {\n"
+		"	var myX = parseFloat(this.myDragger.getAttributeNS(null,\"x\")));\n"
+		"	var myY = parseFloat(this.myDragger.getAttributeNS(null,\"y\")));\n"
+		"	var myWidth = parseFloat(this.myDragger.getAttributeNS(null,\"width\")));\n"
+		"	var myHeight = parseFloat(this.myDragger.getAttributeNS(null,\"height\")));\n"
+		"	var myCenterX = myX + myWidth / 2;\n"
+		"	var myCenterY = myY + myHeight / 2;\n"
+		"	var myRatio = myHeight / myWidth;\n"
+		"	var toMoveX = myCenterX - width / 2;\n"
+		"	var toMoveY = myCenterY - width * myRatio / 2;\n"
+		"	if (toMoveX < this.constrXmin) {\n"
+		"		toMoveX = this.constrXmin;\n"
+		"	}\n"
+		"	if ((toMoveX + width) > this.constrXmax) {\n"
+		"		toMoveX = this.constrXmax - width;\n"
+		"	}\n"
+		"	if (toMoveY < this.constrYmin) {\n"
+		"		toMoveY = this.constrYmin;\n"
+		"	}\n"
+		"	if ((toMoveY + width * myRatio) > this.constrYmax) {\n"
+		"		toMoveY = this.constrYmax - width * myRatio;\n"
+		"	}\n"
+		"	this.newView(toMoveX,toMoveY,width,width * myRatio);\n"
+		"	if (status == \"release\")) {\n"
+		"	           myMainMap.stopNavModes();\n"
+		"		this.mainMapObj.newViewBox(this.dragId,true);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"dragObj.prototype.drag = function(evt) {\n"
+		"	if (evt.type == \"mousedown\")) {\n"
+		"		this.myRefMap.setAttributeNS(null,\"cursor\"),\"move\"));\n"
+		"		this.status = true;\n"
+		"	}\n"
+		"	if ((evt.type == \"mousemove\" || evt.type == \"mousedown\")) && this.status == true) {\n"
+		"		var coords = this.calcCoord(evt);\n"
+		"		var newEvtX = coords.x;\n"
+		"		var newEvtY = coords.y;\n"
+		"		var myX = parseFloat(this.myDragger.getAttributeNS(null,\"x\")));\n"
+		"		var myY = parseFloat(this.myDragger.getAttributeNS(null,\"y\")));\n"
+		"		var myWidth = parseFloat(this.myDragger.getAttributeNS(null,\"width\")));\n"
+		"		var myHeight = parseFloat(this.myDragger.getAttributeNS(null,\"height\")));\n"
+		"		var toMoveX = newEvtX - myWidth / 2;\n"
+		"		var toMoveY = newEvtY - myHeight / 2;\n"
+		"		if (toMoveX < this.constrXmin) {\n"
+		"			toMoveX = this.constrXmin;\n"
+		"		}\n"
+		"		if ((toMoveX + myWidth) > this.constrXmax) {\n"
+		"			toMoveX = this.constrXmax - myWidth;\n"
+		"		}\n"
+		"		if (toMoveY < this.constrYmin) {\n"
+		"			toMoveY = this.constrYmin;\n"
+		"		}\n"
+		"		if ((toMoveY + myHeight) > this.constrYmax) {\n"
+		"			toMoveY = this.constrYmax - myHeight;\n"
+		"		}\n"
+		"		this.newView(toMoveX,toMoveY,myWidth,myHeight);\n"
+		"	}\n"
+		"	if ((evt.type == \"mouseup\" || evt.type == \"mouseout\")) && this.status == true) {\n"
+		"		this.status = false;\n"
+		"		if (evt.detail == 1) { //second click is ignored\n"
+		"		               this.myRefMap.setAttributeNS(null,\"cursor\"),\"crosshair\"));\n"
+		"			this.mainMapObj.newViewBox('dragRectForRefMap',true);\n"
+		"		}\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"dragObj.prototype.zoom = function(inOrOut) {\n"
+		"	var myOldX = this.myDragger.getAttributeNS(null,\"x\"));\n"
+		"	var myOldY = this.myDragger.getAttributeNS(null,\"y\"));\n"
+		"	var myOldWidth = this.myDragger.getAttributeNS(null,\"width\"));\n"
+		"	var myOldHeight = this.myDragger.getAttributeNS(null,\"height\"));\n"
+		"	switch (inOrOut) {\n"
+		"		case \"in\":\n"
+		"			var myNewX = parseFloat(myOldX) + myOldWidth / 2 - (myOldWidth * this.mainMapObj.zoomFact * 0.5);\n"
+		"			var myNewY = parseFloat(myOldY) + myOldHeight / 2 - (myOldHeight * this.mainMapObj.zoomFact * 0.5);\n"
+		"			var myNewWidth = myOldWidth * this.mainMapObj.zoomFact;\n"
+		"			var myNewHeight = myOldHeight * this.mainMapObj.zoomFact;\n"
+		"			if (myNewWidth < this.mainMapObj.minWidth) {\n"
+		"				var myYXFact = this.mainMapObj.curHeight / this.mainMapObj.curWidth;\n"
+		"				myNewWidth = this.mainMapObj.minWidth;\n"
+		"				myNewHeight = myNewWidth * myYXFact;\n"
+		"				myNewX = parseFloat(myOldX) + myOldWidth / 2 - (myNewWidth * 0.5);\n"
+		"				myNewY = parseFloat(myOldY) + myOldHeight / 2 - (myNewHeight * 0.5);\n"
+		"			}\n"
+		"			break;\n"
+		"		case \"out\":\n"
+		"			var myNewX = parseFloat(myOldX) + myOldWidth / 2 - (myOldWidth * (1 + this.mainMapObj.zoomFact) * 0.5);\n"
+		"			var myNewY = parseFloat(myOldY) + myOldHeight / 2 - (myOldHeight * (1 + this.mainMapObj.zoomFact) * 0.5);\n"
+		"			var myNewWidth = myOldWidth * (1 + this.mainMapObj.zoomFact);\n"
+		"			var myNewHeight = myOldHeight * (1 + this.mainMapObj.zoomFact);\n"
+		"			break;\n"
+		"		default:\n"
+		"			var myNewX = this.constrXmin;\n"
+		"			var myNewY = this.constrYmin;\n"
+		"			var myNewWidth = this.constrXmax - this.constrXmin;\n"
+		"			var myNewHeight = this.constrYmax - this.constrYmin;\n"
+		"			break;\n"
+		"	}	\n"
+		"	//check if within constraints\n"
+		"	if (myNewWidth > (this.constrXmax - this.constrXmin)) {\n"
+		"		myNewWidth = this.constrXmax - this.constrXmin;\n"
+		"	}\n"
+		"	if (myNewHeight > (this.constrYmax - this.constrYmin)) {\n"
+		"		myNewHeight = this.constrYmax - this.constrYmin;\n"
+		"	}\n"
+		"	if (myNewX < this.constrXmin) {\n"
+		"		myNewX = this.constrXmin;\n"
+		"	}\n"
+		"	if (myNewY < this.constrYmin) {\n"
+		"		myNewY = this.constrYmin;\n"
+		"	}\n"
+		"	if ((myNewX + myNewWidth) > this.constrXmax) {\n"
+		"		myNewX = this.constrXmax - myNewWidth;\n"
+		"	}\n"
+		"	if ((myNewY + myNewHeight) > this.constrYmax) {\n"
+		"		myNewY = this.constrYmax - myNewHeight;\n"
+		"	}\n"
+		"	this.newView(myNewX,myNewY,myNewWidth,myNewHeight);\n"
+		"	this.mainMapObj.newViewBox(this.dragId,true);\n"
+		"}\n"
+		"\n"
+		"dragObj.prototype.pan = function (myX,myY,howmuch) {\n"
+		"	//get values from draggable rectangle\n"
+		"	var xulcorner = parseFloat(this.myDragger.getAttributeNS(null,\"x\")));\n"
+		"	var yulcorner = parseFloat(this.myDragger.getAttributeNS(null,\"y\")));\n"
+		"	var width = parseFloat(this.myDragger.getAttributeNS(null,\"width\")));\n"
+		"	var height = parseFloat(this.myDragger.getAttributeNS(null,\"height\")));\n"
+		"\n"
+		"	//set values of draggable rectangle\n"
+		"	var rectXulcorner = xulcorner + howmuch * width * myX;\n"
+		"	var rectYulcorner = yulcorner + howmuch * height * myY;\n"
+		"	//check if within constraints\n"
+		"	if (rectXulcorner < this.constrXmin) {\n"
+		"		rectXulcorner = this.constrXmin;\n"
+		"	}\n"
+		"	if (rectYulcorner < this.constrYmin) {\n"
+		"		rectYulcorner = this.constrYmin;\n"
+		"	}\n"
+		"	if ((rectXulcorner + width) > this.constrXmax) {\n"
+		"		rectXulcorner = this.constrXmax - width;\n"
+		"	}\n"
+		"	if ((rectYulcorner + height) > this.constrYmax) {\n"
+		"		rectYulcorner = this.constrYmax - height;\n"
+		"	}\n"
+		"	this.newView(rectXulcorner,rectYulcorner,width,height);\n"
+		"\n"
+		"	//set viewport of main map\n"
+		"	if ((xulcorner != rectXulcorner) || (yulcorner != rectYulcorner)) {\n"
+		"		this.mainMapObj.newViewBox(this.dragId,true);\n"
+		"	}\n"
+		"\n"
+		"	statusChange(\"map ready ...\"));\n"
+		"}\n"
+		"\n"
+		"//remove all temporarily used elements and event listeners\n"
+		"dragObj.prototype.cleanUp = function() {\n"
+		"	//remove eventlisteners\n"
+		"	if (this.showCoords == true) {\n"
+		"		//add event listener for coordinate display\n"
+		"		this.myRefMap.removeEventListener(\"mousemove\"),this,false);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"function zoomIt(evt,inOrOut) {\n"
+		"	if (evt.detail == 1) { //only react on first click, double click: second click is ignored\n"
+		"		if (inOrOut == \"in\")) {\n"
+		"			if (Math.round(myMainMap.curWidth) > myMainMap.minWidth) {\n"
+		"				myMapApp.refMapDragger.zoom(\"in\"));\n"
+		"			}\n"
+		"			else {\n"
+		"				statusChange(\"Maximum zoom factor reached. Cannot zoom in any more.\"));\n"
+		"			}\n"
+		"		}\n"
+		"		if (inOrOut == \"out\")) {\n"
+		"			if (Math.round(myMainMap.curWidth) < myMainMap.maxWidth) {\n"
+		"				myMapApp.refMapDragger.zoom(\"out\"));\n"
+		"			}\n"
+		"			else {\n"
+		"				statusChange(\"Minimum zoom factor reached. Cannot zoom out any more.\"));\n"
+		"			}\n"
+		"		}\n"
+		"		if (inOrOut == \"full\")) {\n"
+		"			if (Math.round(myMainMap.curWidth) < myMainMap.maxWidth) {\n"
+		"				myMapApp.refMapDragger.zoom(\"full\"));\n"
+		"			}\n"
+		"			else {\n"
+		"				statusChange(\"Full view already reached.\"));\n"
+		"			}\n"
+		"		}\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//this function starts various zoom actions or map extent history functions\n"
+		"function zoomImageButtons(id,evt) {\n"
+		"	myMainMap.stopNavModes();\n"
+		"	if (id == \"zoomIn\")) {\n"
+		"		zoomIt(evt,'in');\n"
+		"	}\n"
+		"	if (id == \"zoomOut\")) {\n"
+		"		zoomIt(evt,'out');\n"
+		"	}\n"
+		"	if (id == \"zoomFull\")) {\n"
+		"		zoomIt(evt,'full');\n"
+		"	}\n"
+		"	if (id == \"backwardExtent\")) {\n"
+		"		myMainMap.backwardExtent();\n"
+		"	}\n"
+		"	if (id == \"forwardExtent\")) {\n"
+		"		myMainMap.forwardExtent();\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//this function starts various interactive zoom or pan modes\n"
+		"function zoomImageSwitchButtons(id,evt,onOrOff) {\n"
+		"	myMainMap.stopNavModes();\n"
+		"	if (onOrOff) {\n"
+		"                      if (id == \"infoButton\")) {\n"
+		"                      \n"
+		"                      }\n"
+		"                      else {\n"
+		"		    if (id == \"zoomManual\")) {\n"
+		"			    myMainMap.zoomManual(evt);\n"
+		"		    }\n"
+		"		    if (id == \"panManual\")) {\n"
+		"			    myMainMap.panManual(evt);\n"
+		"		    }\n"
+		"		    if (id == \"recenterMap\")) {\n"
+		"			    myMainMap.recenter(evt);\n"
+		"		    }\n"
+		"		    if (myMapApp.buttons[\"infoButton\"].getSwitchValue()) {\n"
+		"		        myMapApp.buttons[\"infoButton\"].setSwitchValue(false,false);\n"
+		"		    }\n"
+		"		}\n"
+		"	}\n"
+		"	else {\n"
+		"	    if (id == \"infoButton\")) {\n"
+		"	        myMapApp.buttons[\"infoButton\"].setSwitchValue(true,false);\n"
+		"	    }\n"
+		"	}\n"
+		"}\n"
+		"\n"
+		"//alert map extent\n"
+		"function showExtent() {\n"
+		"	with(myMainMap) {\n"
+		"		alert(\n"
+		"         \"Xmin=\"+curxOrig.toFixed(nrDecimals)+units+\n"
+		"         \"); Xmax=\"+(curxOrig + curWidth).toFixed(nrDecimals)+units+\n"
+		"         \"\\nYmin=\"+((curyOrig + curHeight) * -1).toFixed(nrDecimals) +units+\n"
+		"         \"); Ymax=\"+(curyOrig*-1).toFixed(nrDecimals)+units+\n"
+		"         \"\\nWidth=\"+curWidth.toFixed(nrDecimals)+units+\n"
+		"         \"); Height=\"+curHeight.toFixed(nrDecimals)+units);\n"
+		"	}\n"
+		"}\n"
+		"\n"
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/svg_interactive_map.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,135 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              SVG_Interactive_map.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Victor Olaya           //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Victor Olaya                           //
+//                                                       //
+//    e-mail:     volaya at saga-gis.org                    //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__svg_interactive_map_H
+#define _HEADER_INCLUDED__SAGA_GUI__svg_interactive_map_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/doc_svg.h>
+
+#include "wksp_map.h"
+#include "wksp_shapes.h"
+#include "wksp_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CSVG_Interactive_Map : public CSG_Doc_SVG
+{
+public:
+	CSVG_Interactive_Map(void);
+	virtual ~CSVG_Interactive_Map(void);
+
+	void				Create_From_Map				(CWKSP_Map *pMap, CSG_Shapes *pIndexLayer, const wxChar *Filename);
+
+
+private:
+
+	CSG_String			m_Directory;
+	double				m_dWidth;
+
+
+	void				_Write_Code					(const wxChar *FileName, const wxChar *Code);
+
+	void				_Add_Opening				(CSG_Rect r);
+	const wxChar *		_Get_Opening_Code_1			(void);
+	const wxChar *		_Get_Opening_Code_2			(void);
+
+	void				_Add_CheckBoxes				(CWKSP_Map *pMap);
+	void				_Add_Shapes					(CWKSP_Shapes *pLayer);
+	bool				_Add_Shape					(CSG_Shape *pShape, int Fill_Color, int Line_Color, double Line_Width, double Point_Width);
+	void				_Add_Grid					(CWKSP_Grid *pLayer);
+	void				_Add_ReferenceMap			(CSG_Shapes *pIndexLayer, CSG_Rect r);
+	void				_Add_Label					(const wxChar* Label, CSG_Shape *pShape, double dSize, const wxChar* Unit);
+
+	const wxChar *		_Get_Code_1					(void);
+	const wxChar *		_Get_Code_2					(void);
+	const wxChar *		_Get_Code_3					(void);
+	const wxChar *		_Get_Code_4					(void);
+	const wxChar *		_Get_Code_5					(void);
+	const wxChar *		_Get_Code_Closing_1			(void);
+
+	const wxChar *		_Get_Code_CheckBox			(void);
+	const wxChar *		_Get_Code_MapApp			(void);
+	const wxChar *		_Get_Code_Timer				(void);
+	const wxChar *		_Get_Code_Slider			(void);
+	const wxChar *		_Get_Code_Helper			(void);
+	const wxChar *		_Get_Code_Buttons			(void);
+	const wxChar *		_Get_Code_Navigation_1		(void);
+	const wxChar *		_Get_Code_Navigation_2		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__svg_interactive_map_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,233 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    VIEW_Base.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/icon.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "saga_frame.h"
+
+#include "helper.h"
+
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Base, wxMDIChildFrame);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Base, wxMDIChildFrame)
+	EVT_SIZE			(CVIEW_Base::On_Size)
+	EVT_ACTIVATE		(CVIEW_Base::On_Activate)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Base::CVIEW_Base(int View_ID, wxString Caption, int Icon_ID, wxMenu *pMenu, wxString Menu_Label)
+	: wxMDIChildFrame(g_pSAGA_Frame, -1, Caption, MDI_Get_Def_Position(), MDI_Get_Def_Size(), wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
+{
+	m_View_ID		= View_ID;
+
+	m_Size_Min.x	= 0;
+	m_Size_Min.y	= 0;
+
+	SetStatusBarPane(-1);
+
+	SetIcon(IMG_Get_Icon(Icon_ID));
+
+	SetMenuBar(g_pSAGA_Frame->MB_Create(this));
+	GetMenuBar()->Insert(2, pMenu, Menu_Label);
+	m_pMenu_File	= GetMenuBar()->GetMenu(0);
+	m_pMenu_Modules	= GetMenuBar()->GetMenu(1);
+
+	_Activate();
+
+	Show(true);
+}
+
+//---------------------------------------------------------
+CVIEW_Base::~CVIEW_Base(void)
+{
+	_Deactivate();
+
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->MB_Remove(m_pMenu_File, m_pMenu_Modules);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Base::Set_Size_Min(int x, int y)
+{
+	m_Size_Min.x	= x;
+	m_Size_Min.y	= y;
+}
+
+//---------------------------------------------------------
+void CVIEW_Base::On_Size(wxSizeEvent &event)
+{
+	if( event.GetSize().x < m_Size_Min.x || event.GetSize().y < m_Size_Min.y )
+	{
+		SetSize(wxSize(
+			event.GetSize().x < m_Size_Min.x ? m_Size_Min.x : event.GetSize().x,
+			event.GetSize().y < m_Size_Min.y ? m_Size_Min.y : event.GetSize().y)
+		);
+	}
+	else
+	{
+		event.Skip();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Base::On_Activate(wxActivateEvent &event)
+{
+	if( event.GetActive() )
+	{
+		_Activate();
+	}
+	else
+	{
+		_Deactivate();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Base::_Activate(void)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->On_Child_Activates(this, true);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Base::_Deactivate(void)
+{
+	if( g_pSAGA_Frame )
+	{
+		g_pSAGA_Frame->On_Child_Activates(this, false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Base::On_Quit(wxCommandEvent &WXUNUSED(event))
+{
+	Close(true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Base::On_Command_UI(wxUpdateUIEvent &event)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_base.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     VIEW_Base.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Base_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Base_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/mdi.h>
+#include <wx/menu.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Base : public wxMDIChildFrame
+{
+public:
+	CVIEW_Base(int View_ID, wxString Caption, int Icon_ID, wxMenu *pMenu, wxString Menu_Label);
+	virtual ~CVIEW_Base(void);
+
+	void						On_Size				(wxSizeEvent     &event);
+	void						On_Activate			(wxActivateEvent &event);
+
+	void						On_Quit				(wxCommandEvent  &event);
+
+	virtual void				On_Command_UI		(wxUpdateUIEvent &event);
+
+	int							Get_View_ID			(void)	{	return( m_View_ID );		}
+
+
+protected:
+
+	void						Set_Size_Min		(int x, int y);
+
+
+private:
+
+	int							m_View_ID;
+
+	wxSize						m_Size_Min;
+
+	wxMenu						*m_pMenu_File, *m_pMenu_Modules;
+
+
+	void						_Activate			(void);
+	void						_Deactivate			(void);
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Base)
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Base_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,597 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  VIEW_Histogram.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/toolbar.h>
+#include <wx/scrolwin.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_layer_classify.h"
+#include "wksp_grid.h"
+#include "wksp_shapes.h"
+
+#include "view_histogram.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Histogram_Control : public wxScrolledWindow
+{
+public:
+	CVIEW_Histogram_Control(wxWindow *pParent, class CWKSP_Layer *pLayer);
+
+	bool							Update_Histogram	(void);
+
+	bool							Get_Cumulative		(void)	{	return( m_bCumulative );	}
+	void							Set_Cumulative		(bool bOn);
+
+	void							Draw				(wxDC &dc, wxRect rDraw);
+
+
+private:
+
+	bool							m_bCumulative, m_bMouse_Down;
+
+	wxPoint							m_Mouse_Down, m_Mouse_Move;
+
+	class CWKSP_Layer				*m_pLayer;
+
+
+	void							On_Mouse_Motion		(wxMouseEvent &event);
+	void							On_Mouse_LDown		(wxMouseEvent &event);
+	void							On_Mouse_LUp		(wxMouseEvent &event);
+	void							On_Mouse_RDown		(wxMouseEvent &event);
+
+	void							On_Size				(wxSizeEvent  &event);
+	void							On_Paint			(wxPaintEvent &event);
+
+	void							_Draw_Histogram		(wxDC &dc, wxRect r);
+	void							_Draw_Frame			(wxDC &dc, wxRect r);
+	wxRect							_Draw_Get_rDiagram	(wxRect r);
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Histogram_Control)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Histogram_Control, wxScrolledWindow);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Histogram_Control, wxScrolledWindow)
+	EVT_PAINT			(CVIEW_Histogram_Control::On_Paint)
+	EVT_SIZE			(CVIEW_Histogram_Control::On_Size)
+	EVT_MOTION			(CVIEW_Histogram_Control::On_Mouse_Motion)
+	EVT_LEFT_DOWN		(CVIEW_Histogram_Control::On_Mouse_LDown)
+	EVT_LEFT_UP			(CVIEW_Histogram_Control::On_Mouse_LUp)
+	EVT_RIGHT_DOWN		(CVIEW_Histogram_Control::On_Mouse_RDown)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Histogram_Control::CVIEW_Histogram_Control(wxWindow *pParent, CWKSP_Layer *pLayer)
+	: wxScrolledWindow(pParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE)
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_pLayer		= pLayer;
+
+	m_bCumulative	= false;
+	m_bMouse_Down	= false;
+
+	Update_Histogram();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Histogram_Control::Update_Histogram(void)
+{
+	if( m_pLayer->Get_Classifier()->Histogram_Update() )
+	{
+		Refresh();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::Set_Cumulative(bool bOn)
+{
+	if( m_bCumulative != bOn )
+	{
+		m_bCumulative	= bOn;
+
+		Refresh();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::On_Mouse_Motion(wxMouseEvent &event)
+{
+	if( m_bMouse_Down )
+	{
+		wxClientDC	dc(this);
+		wxRect		r(_Draw_Get_rDiagram(wxRect(wxPoint(0, 0), GetClientSize())));
+		dc.SetLogicalFunction(wxINVERT);
+
+		dc.DrawRectangle(m_Mouse_Down.x, r.GetTop(), m_Mouse_Move.x - m_Mouse_Down.x, r.GetHeight());
+		m_Mouse_Move	= event.GetPosition();
+		dc.DrawRectangle(m_Mouse_Down.x, r.GetTop(), m_Mouse_Move.x - m_Mouse_Down.x, r.GetHeight());
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::On_Mouse_LDown(wxMouseEvent &event)
+{
+	if(	m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_METRIC
+	||	m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_SHADE )
+	{
+		m_bMouse_Down	= true;
+		m_Mouse_Move	= m_Mouse_Down	= event.GetPosition();
+
+		CaptureMouse();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::On_Mouse_LUp(wxMouseEvent &event)
+{
+	if( m_bMouse_Down )
+	{
+		ReleaseMouse();
+
+		m_bMouse_Down	= false;
+		m_Mouse_Move	= event.GetPosition();
+
+		wxRect	r(_Draw_Get_rDiagram(wxRect(wxPoint(0, 0), GetClientSize())));
+		double	zFactor	= m_pLayer->Get_Type() == WKSP_ITEM_Grid ? ((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZFactor() : 1.0;
+
+		m_pLayer->Set_Color_Range(
+			zFactor * m_pLayer->Get_Classifier()->Get_RelativeToMetric(
+				(double)(m_Mouse_Down.x - r.GetLeft()) / (double)r.GetWidth()),
+			zFactor * m_pLayer->Get_Classifier()->Get_RelativeToMetric(
+				(double)(m_Mouse_Move.x - r.GetLeft()) / (double)r.GetWidth())
+		);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::On_Mouse_RDown(wxMouseEvent &event)
+{
+	if(	m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_METRIC
+	||	m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_SHADE )
+	{
+		switch( m_pLayer->Get_Type() )
+		{
+		default:
+			return;
+
+		case WKSP_ITEM_Grid:
+			m_pLayer->Set_Color_Range(
+				((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZMin(true),
+				((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZMax(true)
+			);
+			break;
+
+		case WKSP_ITEM_Shapes:
+			m_pLayer->Set_Color_Range(
+				((CWKSP_Shapes *)m_pLayer)->Get_Shapes()->Get_Minimum(m_pLayer->Get_Parameters()->Get_Parameter("COLORS_ATTRIB")->asInt()),
+				((CWKSP_Shapes *)m_pLayer)->Get_Shapes()->Get_Maximum(m_pLayer->Get_Parameters()->Get_Parameter("COLORS_ATTRIB")->asInt())
+			);
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::On_Size(wxSizeEvent &WXUNUSED(event))
+{
+	Refresh();
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::On_Paint(wxPaintEvent &event)
+{
+	wxPaintDC	dc(this);
+	wxRect		r(wxPoint(0, 0), GetClientSize());
+
+	Draw_Edge(dc, EDGE_STYLE_SUNKEN, r);
+
+	Draw(dc, r);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::Draw(wxDC &dc, wxRect rDraw)
+{
+	wxRect		r(_Draw_Get_rDiagram(rDraw));
+	wxFont		Font;
+
+	Font.SetFamily(wxSWISS);
+	dc.SetFont(Font);
+
+	_Draw_Histogram	(dc, r);
+	_Draw_Frame		(dc, r);
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::_Draw_Histogram(wxDC &dc, wxRect r)
+{
+	int		nClasses	= m_pLayer->Get_Classifier()->Get_Class_Count();
+
+	if( nClasses > 1 )
+	{
+		int		ax, ay, bx, by;
+		double	dx, Value;
+
+		dx	= (double)r.GetWidth() / (double)nClasses;
+		ay	= r.GetBottom();
+		bx	= r.GetLeft();
+
+		for(int iClass=0; iClass<nClasses; iClass++)
+		{
+			Value	= m_bCumulative
+					? m_pLayer->Get_Classifier()->Histogram_Get_Cumulative(iClass)
+					: m_pLayer->Get_Classifier()->Histogram_Get_Count     (iClass);
+
+			ax	= bx;
+			bx	= r.GetLeft() + (int)(dx * (iClass + 1.0));
+			by	= ay - (int)(r.GetHeight() * Value);
+
+			Draw_FillRect(dc, m_pLayer->Get_Classifier()->Get_Class_Color(iClass), ax, ay, bx, by);
+		}
+	}
+	else
+	{
+		Draw_Text(dc, TEXTALIGN_CENTER, r.GetLeft() + r.GetWidth() / 2, r.GetBottom() - r.GetHeight() / 2, LNG("no histogram for unclassified data"));
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram_Control::_Draw_Frame(wxDC &dc, wxRect r)
+{
+	const int	dyFont		= 12,
+				Precision	= 3;
+
+	int		iPixel, iStep, nSteps, Maximum, nClasses;
+	double	dPixel, dPixelFont, dz, dArea	= m_pLayer->Get_Type() == WKSP_ITEM_Grid ? ((CSG_Grid *)m_pLayer->Get_Object())->Get_Cellarea() : 1.0;
+	wxFont	Font;
+
+	//-----------------------------------------------------
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);
+
+	Maximum	= m_bCumulative
+			? m_pLayer->Get_Classifier()->Histogram_Get_Total()
+			: m_pLayer->Get_Classifier()->Histogram_Get_Maximum();
+
+	if( Maximum > 0 )
+	{
+		Font	= dc.GetFont();
+		Font.SetPointSize((int)(0.7 * dyFont));
+		dc.SetFont(Font);
+
+		//-------------------------------------------------
+		dPixelFont	= dyFont;
+
+		if( (dPixel = r.GetHeight() / (double)Maximum) < dPixelFont )
+		{
+			dPixel	= dPixel * (1 + (int)(dPixelFont / dPixel));
+		}
+
+		nSteps	= (int)(r.GetHeight() / dPixel);
+		dz		= Maximum * dPixel / (double)r.GetHeight();
+
+		for(iStep=0; iStep<=nSteps; iStep++)
+		{
+			iPixel	= r.GetBottom()	- (int)(dPixel * iStep);
+			dc.DrawLine(r.GetLeft(), iPixel, r.GetLeft() - 5, iPixel);
+
+			if( 1 )
+				Draw_Text(dc, TEXTALIGN_CENTERRIGHT, r.GetLeft() - 7, iPixel,
+					wxString::Format(wxT("%d"), (int)(iStep * dz))
+				);
+			else
+				Draw_Text(dc, TEXTALIGN_CENTERRIGHT, r.GetLeft() - 7, iPixel,
+					wxString::Format(wxT("%.2f"), iStep * dz * dArea)
+				);
+		}
+
+		//-------------------------------------------------
+		nClasses	= m_pLayer->Get_Classifier()->Get_Class_Count();
+		dPixelFont	= dyFont + 5;
+
+		if( (dPixel = r.GetWidth() / (double)nClasses) < dPixelFont )
+		{
+			dPixel	= dPixel * (1 + (int)(dPixelFont / dPixel));
+		}
+
+		nSteps	= (int)(r.GetWidth() / dPixel);
+		dz		= dPixel / (double)r.GetWidth();
+
+		if( m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_LUT )
+		{
+			for(iStep=0; iStep<nSteps; iStep++)
+			{
+				iPixel	= r.GetLeft() + (int)(dPixel * iStep);
+				dc.DrawLine(iPixel, r.GetBottom(), iPixel, r.GetBottom() + 5);
+				Draw_Text(dc, TEXTALIGN_TOPRIGHT, iPixel, r.GetBottom() + 7, 45.0,
+					m_pLayer->Get_Classifier()->Get_Class_Name((int)(nClasses * iStep * dz))
+				);
+			}
+		}
+		else
+		{
+			double	zFactor	= m_pLayer->Get_Type() == WKSP_ITEM_Grid ? ((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZFactor() : 1.0;
+
+			for(iStep=0; iStep<=nSteps; iStep++)
+			{
+				iPixel	= r.GetLeft() + (int)(dPixel * iStep);
+				dc.DrawLine(iPixel, r.GetBottom(), iPixel, r.GetBottom() + 5);
+				Draw_Text(dc, TEXTALIGN_CENTERRIGHT, iPixel, r.GetBottom() + 7, 45.0,
+					wxString::Format(wxT("%.*f"), Precision, zFactor * m_pLayer->Get_Classifier()->Get_RelativeToMetric(iStep * dz))
+				);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+wxRect CVIEW_Histogram_Control::_Draw_Get_rDiagram(wxRect r)
+{
+	if( m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_LUT )
+	{
+		return(	wxRect(
+			wxPoint(r.GetLeft()  + 50, r.GetTop()    +  10),
+			wxPoint(r.GetRight() - 10, r.GetBottom() - 100)
+		));
+	}
+
+	return(	wxRect(
+		wxPoint(r.GetLeft()  + 50, r.GetTop()    + 10),
+		wxPoint(r.GetRight() - 10, r.GetBottom() - 40)
+	));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Histogram, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Histogram, CVIEW_Base)
+	EVT_MENU			(ID_CMD_HISTOGRAM_CUMULATIVE	, CVIEW_Histogram::On_Cumulative)
+	EVT_UPDATE_UI		(ID_CMD_HISTOGRAM_CUMULATIVE	, CVIEW_Histogram::On_Cumulative_UI)
+	EVT_MENU			(ID_CMD_HISTOGRAM_AS_TABLE		, CVIEW_Histogram::On_AsTable)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Histogram::CVIEW_Histogram(CWKSP_Layer *pLayer)
+	: CVIEW_Base(ID_VIEW_HISTOGRAM, pLayer->Get_Name(), ID_IMG_WND_HISTOGRAM, CVIEW_Histogram::_Create_Menu(), LNG("[CAP] Histogram"))
+{
+	m_pLayer	= pLayer;
+	m_pControl	= new CVIEW_Histogram_Control(this, pLayer);
+}
+
+//---------------------------------------------------------
+CVIEW_Histogram::~CVIEW_Histogram(void)
+{
+	m_pLayer->View_Closes(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_Histogram::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu();
+
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_HISTOGRAM_CUMULATIVE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_HISTOGRAM_AS_TABLE);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_Histogram::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_HISTOGRAM);
+
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_HISTOGRAM_CUMULATIVE);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_HISTOGRAM_AS_TABLE);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Histogram"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Histogram::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		break;
+
+	case ID_CMD_HISTOGRAM_CUMULATIVE:
+		On_Cumulative_UI(event);
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram::On_Cumulative(wxCommandEvent &event)
+{
+	m_pControl->Set_Cumulative(!m_pControl->Get_Cumulative());
+}
+
+void CVIEW_Histogram::On_Cumulative_UI(wxUpdateUIEvent &event)
+{
+	event.Check(m_pControl->Get_Cumulative());
+}
+
+//---------------------------------------------------------
+void CVIEW_Histogram::On_AsTable(wxCommandEvent &event)
+{
+	int					i, n;
+	double				dArea	= m_pLayer->Get_Type() == WKSP_ITEM_Grid ? ((CSG_Grid *)m_pLayer->Get_Object())->Get_Cellarea() : 1.0;
+	CSG_Table			*pTable;
+	CSG_Table_Record	*pRecord;
+
+	if( (n = m_pLayer->Get_Classifier()->Get_Class_Count()) > 0 )
+	{
+		pTable	= new CSG_Table;
+
+		pTable->Set_Name(wxString::Format(wxT("%s: %s"), LNG("[CAP] Histogram"), m_pLayer->Get_Name().c_str()));
+
+		pTable->Add_Field(LNG("CLASS")	, SG_DATATYPE_Int);
+		pTable->Add_Field(LNG("COUNT")	, SG_DATATYPE_Int);
+		pTable->Add_Field(LNG("AREA")	, SG_DATATYPE_Double);
+		pTable->Add_Field(LNG("NAME")	, SG_DATATYPE_String);
+
+		for(i=0; i<n; i++)
+		{
+			pRecord	= pTable->Add_Record();
+
+			pRecord->Set_Value(0, i + 1);
+			pRecord->Set_Value(1, m_pLayer->Get_Classifier()->Histogram_Get_Count(i, false));
+			pRecord->Set_Value(2, m_pLayer->Get_Classifier()->Histogram_Get_Count(i, false) * dArea);
+			pRecord->Set_Value(3, m_pLayer->Get_Classifier()->Get_Class_Name(i).c_str());
+		}
+
+		g_pData->Add(pTable);
+	}
+}
+
+//---------------------------------------------------------
+bool CVIEW_Histogram::Update_Histogram(void)
+{
+	return( m_pControl->Update_Histogram() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_histogram.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   VIEW_Histogram.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Histogram_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Histogram_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Histogram : public CVIEW_Base
+{
+public:
+	CVIEW_Histogram(class CWKSP_Layer *pLayer);
+	virtual ~CVIEW_Histogram(void);
+
+	static class wxToolBarBase *	_Create_ToolBar		(void);
+	static class wxMenu *			_Create_Menu		(void);
+
+	bool							Update_Histogram	(void);
+
+
+private:
+
+	class CWKSP_Layer				*m_pLayer;
+
+	class CVIEW_Histogram_Control	*m_pControl;
+
+
+	virtual void					On_Command_UI		(wxUpdateUIEvent &event);
+
+	void							On_Cumulative		(wxCommandEvent  &event);
+	void							On_Cumulative_UI	(wxUpdateUIEvent &event);
+	void							On_AsTable			(wxCommandEvent  &event);
+
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Histogram)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Histogram_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,285 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   VIEW_Layout.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "wksp_map.h"
+
+#include "view_ruler.h"
+
+#include "view_layout.h"
+#include "view_layout_info.h"
+#include "view_layout_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Layout, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Layout, CVIEW_Base)
+	EVT_SIZE			(CVIEW_Layout::On_Size)
+
+	EVT_MENU			(ID_CMD_LAYOUT_PRINT_SETUP		, CVIEW_Layout::On_Print_Setup)
+	EVT_MENU			(ID_CMD_LAYOUT_PAGE_SETUP		, CVIEW_Layout::On_Page_Setup)
+	EVT_MENU			(ID_CMD_LAYOUT_PRINT			, CVIEW_Layout::On_Print)
+	EVT_MENU			(ID_CMD_LAYOUT_PRINT_PREVIEW	, CVIEW_Layout::On_Print_Preview)
+	EVT_MENU			(ID_CMD_LAYOUT_FIT_SCALE		, CVIEW_Layout::On_Fit_Scale)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Layout::CVIEW_Layout(CVIEW_Layout_Info *pInfo)
+	: CVIEW_Base(ID_VIEW_LAYOUT, LNG("[CAP] Map-Layout"), ID_IMG_WND_LAYOUT, CVIEW_Layout::_Create_Menu(), LNG("[CAP] Map-Layout"))
+{
+	SYS_Set_Color_BG(this, wxSYS_COLOUR_3DFACE);
+
+	m_pInfo		= pInfo;
+
+	m_pRuler_X	= new CVIEW_Ruler(this, RULER_HORIZONTAL|RULER_EDGE_SUNKEN);
+	m_pRuler_Y	= new CVIEW_Ruler(this, RULER_VERTICAL  |RULER_EDGE_SUNKEN);
+
+	m_pControl	= new CVIEW_Layout_Control(this);
+
+	SetTitle(wxString::Format(wxT("%s - %s"), pInfo->Get_Map()->Get_Name().c_str(), LNG("[CAP] Map-Layout")));
+}
+
+//---------------------------------------------------------
+CVIEW_Layout::~CVIEW_Layout(void)
+{
+	m_pInfo->Get_Map()->View_Closes(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_Layout::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu();
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_FIT_SCALE);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_PAGE_SETUP);
+//	CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_PRINT_SETUP);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_PRINT_PREVIEW);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_LAYOUT_PRINT);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_Layout::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_LAYOUT);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_LAYOUT_PAGE_SETUP);
+//	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_LAYOUT_PRINT_SETUP);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_LAYOUT_PRINT_PREVIEW);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_LAYOUT_PRINT);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Map-Layout"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Layout::On_Size(wxSizeEvent &event)
+{
+	int		A, B, d, dX, dY;
+
+	A	= 1;
+	B	= 20;
+	d	= B - 4 * A;
+	dX	= GetClientSize().x - B;
+	dY	= GetClientSize().y - B;
+
+	Freeze();
+
+	m_pRuler_Y->SetSize(wxRect(A, B, d , dY));
+	m_pRuler_X->SetSize(wxRect(B, A, dX, d ));
+	m_pControl->SetSize(wxRect(B, B, dX, dY));
+	m_pControl->Fit_To_Size(dX, dY);
+
+	Thaw();
+
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Layout::Ruler_Set_Position(int x, int y)
+{
+	m_pRuler_X->Set_Position(x);
+	m_pRuler_Y->Set_Position(y);
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout::Ruler_Refresh(double xMin, double xMax, double yMin, double yMax)
+{
+	wxRect	r(m_pInfo->Get_Margins());
+
+	m_pRuler_X->Set_Range_Core(r.GetLeft(), r.GetLeft() + r.GetWidth());
+	m_pRuler_Y->Set_Range_Core(r.GetTop (), r.GetTop () + r.GetHeight());
+
+	m_pRuler_X->Set_Range(xMin, xMax);
+	m_pRuler_Y->Set_Range(yMin, yMax);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout::Refresh_Layout(void)
+{
+	return( m_pControl->Refresh_Layout() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Layout::On_Print_Setup(wxCommandEvent &event)
+{
+	if( m_pInfo->Setup_Print() )
+	{
+		m_pControl->Set_Dimensions();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout::On_Page_Setup(wxCommandEvent &event)
+{
+	if( m_pInfo->Setup_Page() )
+	{
+		m_pControl->Set_Dimensions();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout::On_Print(wxCommandEvent &event)
+{
+	m_pInfo->Print();
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout::On_Print_Preview(wxCommandEvent &event)
+{
+	m_pInfo->Print_Preview();
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout::On_Fit_Scale(wxCommandEvent &event)
+{
+	m_pInfo->Fit_Scale();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    VIEW_Layout.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Layout : public CVIEW_Base
+{
+public:
+	CVIEW_Layout(class CVIEW_Layout_Info *pInfo);
+	virtual ~CVIEW_Layout(void);
+
+	static class wxToolBarBase *	_Create_ToolBar		(void);
+	static class wxMenu *			_Create_Menu		(void);
+
+	void							On_Size				(wxSizeEvent  &event);
+
+	void							On_Page_Setup		(wxCommandEvent &event);
+	void							On_Print_Setup		(wxCommandEvent &event);
+	void							On_Print			(wxCommandEvent &event);
+	void							On_Print_Preview	(wxCommandEvent &event);
+	void							On_Fit_Scale		(wxCommandEvent &event);
+
+	class CVIEW_Layout_Info *		Get_Info			(void)	{	return( m_pInfo );	}
+
+	void							Ruler_Set_Position	(int x, int y);
+	void							Ruler_Refresh		(double xMin, double xMax, double yMin, double yMax);
+
+	bool							Refresh_Layout		(void);
+
+
+private:
+
+	class CVIEW_Ruler				*m_pRuler_X, *m_pRuler_Y;
+
+	class CVIEW_Layout_Info			*m_pInfo;
+
+	class CVIEW_Layout_Control		*m_pControl;
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Layout)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,327 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                VIEW_Layout_Control.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/dcmemory.h>
+#include <wx/image.h>
+
+#include "res_images.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_map.h"
+
+#include "view_layout.h"
+#include "view_layout_info.h"
+#include "view_layout_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SCROLL_RATE		5
+
+#define SCROLL_BAR_DX	wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)
+#define SCROLL_BAR_DY	wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Layout_Control, wxScrolledWindow)
+	EVT_MOTION			(CVIEW_Layout_Control::On_Mouse_Motion)
+	EVT_LEFT_DOWN		(CVIEW_Layout_Control::On_Mouse_LDown)
+	EVT_LEFT_UP			(CVIEW_Layout_Control::On_Mouse_LUp)
+	EVT_LEFT_DCLICK		(CVIEW_Layout_Control::On_Mouse_LDClick)
+	EVT_RIGHT_DOWN		(CVIEW_Layout_Control::On_Mouse_RDown)
+	EVT_RIGHT_UP		(CVIEW_Layout_Control::On_Mouse_RUp)
+	EVT_RIGHT_DCLICK	(CVIEW_Layout_Control::On_Mouse_RDClick)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Layout_Control::CVIEW_Layout_Control(CVIEW_Layout *pParent)
+	: wxScrolledWindow(pParent)
+{
+	SYS_Set_Color_BG(this, wxSYS_COLOUR_APPWORKSPACE);
+
+	m_pLayout		= pParent;
+	m_Zoom			= 1.0;
+
+	SetCursor(IMG_Get_Cursor(ID_IMG_CRS_MAGNIFIER));
+
+	Set_Dimensions();
+}
+
+//---------------------------------------------------------
+CVIEW_Layout_Control::~CVIEW_Layout_Control(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::OnDraw(wxDC &dc)
+{
+	dc.SetUserScale(m_Zoom, m_Zoom);
+	dc.DrawBitmap(wxBitmap(m_Image), 0, 0, true);
+
+	_Set_Rulers();
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Control::Refresh_Layout(void)
+{
+	return( _Draw_Layout(false) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Control::Set_Dimensions(void)
+{
+	int		w, h, r	= m_pLayout->Get_Info()->Get_Map()->Get_Print_Resolution();
+	wxSize	Size(m_pLayout->Get_Info()->Get_PaperSize());
+
+	w	= r * Size.GetWidth();
+	h	= r * Size.GetHeight();
+
+	m_Image.Create(w, h);
+
+	w	= (int)(w * m_Zoom) + SCROLL_BAR_DX;
+	h	= (int)(h * m_Zoom) + SCROLL_BAR_DY;
+
+	SetScrollbars(SCROLL_RATE, SCROLL_RATE, w / SCROLL_RATE, h / SCROLL_RATE);
+
+	_Draw_Layout(true);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Control::_Set_Zoom(double Zoom)
+{
+	if( Zoom > 0.0 && Zoom != m_Zoom )
+	{
+		m_Zoom	= Zoom;
+
+		return( Set_Dimensions() );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::_Set_Zoom_Centered(double Zoom, wxPoint Center)
+{
+	int		x, y;
+
+	GetViewStart(&x, &y);
+
+	x	= (int)((Zoom * (x * SCROLL_RATE + Center.x) - GetClientSize().x / 2) / SCROLL_RATE);
+	y	= (int)((Zoom * (y * SCROLL_RATE + Center.y) - GetClientSize().y / 2) / SCROLL_RATE);
+
+	_Set_Zoom(m_Zoom * Zoom);
+
+	Scroll(x, y);
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Control::Fit_To_Size(int x, int y)
+{
+	double	dx, dy, r	= m_pLayout->Get_Info()->Get_Map()->Get_Print_Resolution();
+	wxSize	sPage(m_pLayout->Get_Info()->Get_PaperSize());
+
+	dx		= (x - SCROLL_BAR_DX) / (r * sPage.x);
+	dy		= (y - SCROLL_BAR_DY) / (r * sPage.y);
+
+	return( _Set_Zoom(dx < dy ? dx : dy) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Control::_Draw_Layout(bool bEraseBkgrd)
+{
+	wxBitmap	dc_BMP(m_Image.GetWidth(), m_Image.GetHeight());
+	wxMemoryDC	dc;
+
+	dc.SelectObject(dc_BMP);
+	dc.SetBackground(*wxWHITE_BRUSH);
+	dc.Clear();
+
+	m_pLayout->Get_Info()->Draw(dc);
+
+	dc.SelectObject(wxNullBitmap);
+
+	m_Image	= dc_BMP.ConvertToImage();
+
+	Refresh(bEraseBkgrd);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::_Set_Rulers(void)
+{
+	int		ix, iy;
+	double	d, dx, dy, ax, ay;
+	wxSize	sPaper(m_pLayout->Get_Info()->Get_PaperSize());
+
+	d	= (double)sPaper.x / (m_Image.GetWidth()  * m_Zoom);
+
+	dx	= d * GetSize().x;
+	dy	= d * GetSize().y;
+
+	GetViewStart(&ix, &iy);
+
+	ax	= d * ix * SCROLL_RATE;
+	ay	= d * iy * SCROLL_RATE;
+
+	m_pLayout->Ruler_Refresh(ax, ax + dx, ay, ay + dy);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_LDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_LUp(wxMouseEvent &event)
+{
+	_Set_Zoom_Centered(1.5, event.GetPosition());
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_LDClick(wxMouseEvent &event)
+{
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_RDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_RUp(wxMouseEvent &event)
+{
+	_Set_Zoom_Centered(1.0 / 1.5, event.GetPosition());
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_RDClick(wxMouseEvent &event)
+{
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Control::On_Mouse_Motion(wxMouseEvent &event)
+{
+	m_Mouse_Move	= event.GetPosition();
+
+	m_pLayout->Ruler_Set_Position(m_Mouse_Move.x, m_Mouse_Move.y);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,135 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_Layout_Control.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/scrolwin.h>
+#include <wx/image.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Layout_Control : public wxScrolledWindow
+{
+public:
+	CVIEW_Layout_Control(class CVIEW_Layout *pParent);
+	virtual ~CVIEW_Layout_Control(void);
+
+	void						On_Mouse_LDown		(wxMouseEvent &event);
+	void						On_Mouse_LUp		(wxMouseEvent &event);
+	void						On_Mouse_LDClick	(wxMouseEvent &event);
+	void						On_Mouse_RDown		(wxMouseEvent &event);
+	void						On_Mouse_RUp		(wxMouseEvent &event);
+	void						On_Mouse_RDClick	(wxMouseEvent &event);
+	void						On_Mouse_Motion		(wxMouseEvent &event);
+
+	virtual void				OnDraw				(wxDC &dc);
+
+	bool						Refresh_Layout		(void);
+	bool						Set_Dimensions		(void);
+
+	bool						Fit_To_Size			(int x, int y);
+
+
+private:
+
+	double						m_Zoom;
+
+	wxPoint						m_Mouse_Down, m_Mouse_Move;
+
+	wxImage						m_Image;
+
+	class CVIEW_Layout			*m_pLayout;
+
+
+	bool						_Set_Zoom			(double Zoom);
+	void						_Set_Zoom_Centered	(double Zooming, wxPoint Center);
+
+	bool						_Draw_Layout		(bool bEraseBkgrd);
+	void						_Set_Rulers			(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,408 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_Layout_Info.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wx/wx.h"
+#include "wx/print.h"
+#include "wx/printdlg.h"
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "res_dialogs.h"
+
+#include "wksp_map.h"
+
+#include "view_layout_info.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Layout_Info::CVIEW_Layout_Info(CWKSP_Map *pMap)
+{
+	m_pMap		= pMap;
+
+	m_pPrint	= new wxPrintData;
+	m_pPrint	->SetOrientation		(wxLANDSCAPE);
+	m_pPrint	->SetPaperId			(wxPAPER_A4);
+
+	m_pPage		= new wxPageSetupDialogData;
+	m_pPage		->SetPrintData			(*m_pPrint);
+	m_pPage		->SetMarginTopLeft		(wxPoint(10, 10));
+	m_pPage		->SetMarginBottomRight	(wxPoint(10, 10));
+}
+
+//---------------------------------------------------------
+CVIEW_Layout_Info::~CVIEW_Layout_Info(void)
+{
+	delete(m_pPage);
+	delete(m_pPrint);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Info::Setup_Print(void)
+{
+	wxPrintDialogData	Data(*m_pPrint);
+	wxPrintDialog		dlg(MDI_Get_Frame(), &Data);
+
+//	dlg.GetPrintDialogData().SetSetupDialog(true);
+	
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		*m_pPrint	= dlg.GetPrintDialogData().GetPrintData();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Info::Setup_Page(void)
+{
+	(*m_pPage)	= *m_pPrint;
+
+	wxPageSetupDialog	dlg(MDI_Get_Frame(), m_pPage);
+
+	if( dlg.ShowModal() == wxID_OK )
+	{
+		(*m_pPrint) = dlg.GetPageSetupData().GetPrintData();
+		(*m_pPage)	= dlg.GetPageSetupData();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Info::Print(void)
+{
+	wxPrintDialogData	Data(*m_pPrint);
+	wxPrinter			Printer(&Data);
+
+	if( Printer.Print(MDI_Get_Frame(), Get_Printout(), true) )
+	{
+		(*m_pPrint)	= Printer.GetPrintDialogData().GetPrintData();
+		(*m_pPage)	= Printer.GetPrintDialogData().GetPrintData();
+
+		return( true );
+	}
+
+	if( wxPrinter::GetLastError() == wxPRINTER_ERROR )
+		MSG_Error_Add(LNG("[ERR] There was a problem printing.\nPerhaps your current printer is not set correctly?"));
+	else
+		MSG_Error_Add(LNG("[ERR] You canceled printing"));
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Info::Print_Preview(void)
+{
+	wxPrintDialogData	Data(*m_pPrint);
+	wxPrintPreview		*pPreview;
+	wxPreviewFrame		*pFrame;
+
+	pPreview	= new wxPrintPreview(Get_Printout(), Get_Printout(), &Data);
+
+	if( pPreview->Ok() )
+	{
+		pFrame	= new wxPreviewFrame(pPreview, (wxFrame *)MDI_Get_Frame(), LNG("[CAP] Print Preview"), wxPoint(100, 100), wxSize(600, 650), wxDEFAULT_FRAME_STYLE|wxMAXIMIZE);
+		pFrame->Centre(wxBOTH);
+		pFrame->Initialize();
+		pFrame->Show(true);
+
+		return( true );
+	}
+
+	delete(pPreview);
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Layout_Printout * CVIEW_Layout_Info::Get_Printout(void)
+{
+	return( new CVIEW_Layout_Printout(this) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxSize CVIEW_Layout_Info::Get_PaperSize(void)
+{
+	wxSize	s(m_pPage->GetPaperSize());
+
+	if(	(m_pPrint->GetOrientation() == wxLANDSCAPE && s.x < s.y)
+	||	(m_pPrint->GetOrientation() == wxPORTRAIT  && s.x > s.y) )
+	{
+		s	= wxSize(s.y, s.x);
+		m_pPage->SetPaperSize(s);
+	}
+
+	return( s );
+
+//	return( m_pPage->GetPaperSize() );
+}
+
+//---------------------------------------------------------
+wxRect CVIEW_Layout_Info::Get_Margins(void)
+{
+	wxRect	r(Get_PaperSize());
+	wxPoint	pTL(Get_Margin_TopLeft()), pBR(Get_Margin_BottomRight());
+
+	return( wxRect(pTL, wxSize(r.GetWidth() - pTL.x - pBR.x, r.GetHeight() - pTL.y - pBR.y)) );
+}
+
+//---------------------------------------------------------
+wxPoint CVIEW_Layout_Info::Get_Margin_TopLeft(void)
+{
+	return( m_pPage->GetMarginTopLeft() );
+}
+
+//---------------------------------------------------------
+wxPoint CVIEW_Layout_Info::Get_Margin_BottomRight(void)
+{
+	return( m_pPage->GetMarginBottomRight() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CVIEW_Layout_Info::Get_Name(void)
+{
+	return( LNG("SAGA: Print Map") );
+}
+
+//---------------------------------------------------------
+int CVIEW_Layout_Info::Get_Page_Count(void)
+{
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Layout_Info::Fit_Scale(void)
+{
+	int			fMap;
+	double		zMap, zLegend, Scale, dx, dy;
+	wxRect		rMap, rLegend;
+	CSG_Rect	rWorld;
+
+	if( _Get_Layout(Get_PaperSize(), zMap, fMap, rMap, zLegend, rLegend) )
+	{
+		rWorld	= m_pMap->Get_World(rMap);
+		Scale	= 100.0 * zMap * rWorld.Get_XRange() / (double)rMap.GetWidth();
+
+		if( DLG_Get_Number(Scale, LNG("[CAP] Fit Map Scale"), LNG("[DLG] Scale 1 : ")) )
+		{
+			dx	= Scale * (double)rMap.GetWidth () / zMap / 100.0 / 2.0;
+			dy	= Scale * (double)rMap.GetHeight() / zMap / 100.0 / 2.0;
+
+			rWorld.Assign(
+				rWorld.Get_XCenter() - dx, rWorld.Get_YCenter() - dy,
+				rWorld.Get_XCenter() + dx, rWorld.Get_YCenter() + dy
+			);
+
+			m_pMap->Set_Extent(rWorld);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Info::_Get_Layout(wxSize sClient, double &zMap, int &fMap, wxRect &rMap, double &zLegend, wxRect &rLegend)
+{
+	int		Space;
+	wxSize	sLegend;
+	wxRect	rFrame(Get_Margins());
+
+	//-----------------------------------------------------
+	zMap	= sClient.GetWidth() / (double)Get_PaperSize().GetWidth();
+	rFrame	= wxRect(
+				(int)(zMap * rFrame.GetLeft  ()),
+				(int)(zMap * rFrame.GetTop   ()),
+				(int)(zMap * rFrame.GetWidth ()),
+				(int)(zMap * rFrame.GetHeight())
+			);
+
+	Space	= (int)(10.0 * zMap);
+
+	//-----------------------------------------------------
+	if( m_pMap->Get_Print_Legend() && m_pMap->Get_Legend_Size(sLegend, zMap) )
+	{
+		zLegend	= (double)rFrame.GetHeight() / (double)sLegend.y;
+
+		if( zLegend * sLegend.x > 0.2 * (double)rFrame.GetWidth() )
+		{
+			zLegend	= 0.2 * (double)rFrame.GetWidth() / (double)sLegend.x;
+		}
+
+		rFrame.SetWidth (rFrame.GetWidth() - (int)(zLegend * sLegend.x + Space));
+
+		rLegend	= wxRect(rFrame.GetRight() + Space, rFrame.GetTop(), (int)(zLegend * sLegend.x), (int)(zLegend * sLegend.y));
+	}
+	else
+	{
+		rLegend	= wxRect(0, 0, 0, 0);
+	}
+
+	//-----------------------------------------------------
+	fMap	= (int)(m_pMap->Get_Print_Frame() * zMap);
+	rMap	= rFrame;
+	rMap.Deflate(fMap);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Info::Draw(wxDC &dc)
+{
+	int		fMap;
+	double	zMap, zLegend, Scale;
+	wxRect	rMap, rLegend;
+
+	if( _Get_Layout(dc.GetSize(), zMap, fMap, rMap, zLegend, rLegend) )
+	{
+		//-------------------------------------------------
+		if( rLegend.GetWidth() > 0 )
+		{
+			m_pMap->Draw_Legend(dc, zMap, zLegend, wxPoint(rLegend.GetX(), rLegend.GetY()));
+
+			Draw_Edge(dc, EDGE_STYLE_SIMPLE, rLegend.GetLeft()  - (int)(5 * zMap), rLegend.GetTop(), rLegend.GetRight(), rLegend.GetBottom());
+		}
+
+		//-------------------------------------------------
+		if( rMap.GetWidth() > 0 )
+		{
+			m_pMap->Draw_Map(dc, zMap, rMap, false);
+
+			if( fMap > 0 )
+			{
+				m_pMap->Draw_Frame(dc, rMap, fMap);
+			}
+
+			//---------------------------------------------
+			Scale	= 100.0 * zMap * m_pMap->Get_World(rMap).Get_XRange() / (double)rMap.GetWidth();
+			dc.DrawText(wxString::Format(wxT("%s 1:%s"), LNG("[CAP] Map Scale"), Get_SignificantDecimals_String(Scale).c_str()), rMap.GetLeft(), rMap.GetBottom() + fMap);
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_info.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,131 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  VIEW_Layout_Info.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Info_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Info_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_layout_printout.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Layout_Info
+{
+public:
+	CVIEW_Layout_Info(class CWKSP_Map *pMap);
+	virtual ~CVIEW_Layout_Info(void);
+
+	class CWKSP_Map *				Get_Map					(void)	{	return( m_pMap );	}
+
+	bool							Setup_Print				(void);
+	bool							Setup_Page				(void);
+	bool							Print					(void);
+	bool							Print_Preview			(void);
+
+	wxSize							Get_PaperSize			(void);
+	wxRect							Get_Margins				(void);
+	wxPoint							Get_Margin_TopLeft		(void);
+	wxPoint							Get_Margin_BottomRight	(void);
+
+	wxString						Get_Name				(void);
+	int								Get_Page_Count			(void);
+
+	CVIEW_Layout_Printout *			Get_Printout			(void);
+
+	void							Fit_Scale				(void);
+
+	bool							Draw					(wxDC &dc);
+
+
+protected:
+
+	class CWKSP_Map					*m_pMap;
+
+	class wxPrintData				*m_pPrint;
+
+	class wxPageSetupData			*m_pPage;
+
+
+	bool							_Get_Layout				(wxSize sClient, double &zMap, int &fMap, wxRect &rMap, double &zLegend, wxRect &rLegend);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Info_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               VIEW_Layout_Printout.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+
+#include "view_layout_info.h"
+#include "view_layout_printout.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Layout_Printout::CVIEW_Layout_Printout(CVIEW_Layout_Info *pInfo)
+	: wxPrintout(pInfo->Get_Name())
+{
+	m_pInfo		= pInfo;
+}
+
+//---------------------------------------------------------
+CVIEW_Layout_Printout::~CVIEW_Layout_Printout(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Printout::OnPrintPage(int iPage)
+{
+	wxDC	*pDC;
+
+	if( HasPage(iPage) && (pDC = GetDC()) != NULL )
+	{
+		return( m_pInfo->Draw(*pDC) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Layout_Printout::HasPage(int iPage)
+{
+	return( iPage > 0 && iPage <= m_pInfo->Get_Page_Count() );
+}
+
+//---------------------------------------------------------
+void CVIEW_Layout_Printout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
+{
+	*minPage		= 1;
+	*maxPage		= m_pInfo->Get_Page_Count();
+
+	*selPageFrom	= 1;
+	*selPageTo		= m_pInfo->Get_Page_Count();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_layout_printout.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                VIEW_Layout_Printout.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Printout_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Printout_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/print.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Layout_Printout : public wxPrintout
+{
+public:
+	CVIEW_Layout_Printout(class CVIEW_Layout_Info *pInfo);
+	virtual ~CVIEW_Layout_Printout(void);
+
+	virtual bool				OnPrintPage		(int iPage);
+	virtual bool				HasPage			(int iPage);
+	virtual void				GetPageInfo		(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
+
+
+protected:
+
+	class CVIEW_Layout_Info		*m_pInfo;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Layout_Printout_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,551 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     VIEW_Map.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dcclient.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "wksp_map.h"
+
+#include "view_ruler.h"
+#include "view_map.h"
+#include "view_map_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Map, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Map, CVIEW_Base)
+	EVT_PAINT			(CVIEW_Map::On_Paint)
+	EVT_SIZE			(CVIEW_Map::On_Size)
+	EVT_KEY_DOWN		(CVIEW_Map::On_Key_Down)
+
+	EVT_MENU			(ID_CMD_MAP_3D_SHOW				, CVIEW_Map::On_Map_3D_Show)
+	EVT_MENU			(ID_CMD_MAP_LAYOUT_SHOW			, CVIEW_Map::On_Map_Layout_Show)
+	EVT_MENU			(ID_CMD_MAP_SAVE_IMAGE			, CVIEW_Map::On_Map_Save_Image)
+	EVT_MENU			(ID_CMD_MAP_SAVE_IMAGE_ON_CHANGE, CVIEW_Map::On_Map_Save_Image_On_Change)
+	EVT_MENU			(ID_CMD_MAP_SAVE_PDF_INDEXED	, CVIEW_Map::On_Map_Save_PDF_Indexed)
+	EVT_MENU			(ID_CMD_MAP_SAVE_INTERACTIVE_SVG, CVIEW_Map::On_Map_Save_Interactive_SVG)
+
+	EVT_MENU			(ID_CMD_MAP_ZOOM_FULL			, CVIEW_Map::On_Map_Zoom_Full)
+	EVT_MENU			(ID_CMD_MAP_ZOOM_BACK			, CVIEW_Map::On_Map_Zoom_Back)
+	EVT_MENU			(ID_CMD_MAP_ZOOM_FORWARD		, CVIEW_Map::On_Map_Zoom_Forward)
+	EVT_MENU			(ID_CMD_MAP_ZOOM_ACTIVE			, CVIEW_Map::On_Map_Zoom_Layer)
+	EVT_MENU			(ID_CMD_MAP_ZOOM_SELECTION		, CVIEW_Map::On_Map_Zoom_Selection)
+	EVT_MENU			(ID_CMD_MAP_ZOOM_EXTENT			, CVIEW_Map::On_Map_Zoom_Extent)
+	EVT_MENU			(ID_CMD_MAP_SYNCHRONIZE			, CVIEW_Map::On_Map_Zoom_Synchronize)
+
+	EVT_MENU			(ID_CMD_MAP_MODE_ZOOM			, CVIEW_Map::On_Map_Mode_Zoom)
+	EVT_MENU			(ID_CMD_MAP_MODE_PAN			, CVIEW_Map::On_Map_Mode_Pan)
+	EVT_MENU			(ID_CMD_MAP_MODE_SELECT			, CVIEW_Map::On_Map_Mode_Select)
+	EVT_MENU			(ID_CMD_MAP_MODE_DISTANCE		, CVIEW_Map::On_Map_Mode_Distance)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Map::CVIEW_Map(CWKSP_Map *pMap, int Frame_Width)
+	: CVIEW_Base(ID_VIEW_MAP, pMap->Get_Name(), ID_IMG_WND_MAP, CVIEW_Map::_Create_Menu(), LNG("[CAP] Map"))
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_pMap			= pMap;
+
+	m_pControl		= new CVIEW_Map_Control(this, m_pMap);
+
+	m_pRuler_X1		= new CVIEW_Ruler(this, RULER_HORIZONTAL|RULER_MODE_NORMAL|RULER_TICKATBOTTOM);
+	m_pRuler_X2		= new CVIEW_Ruler(this, RULER_HORIZONTAL|RULER_MODE_SCALE );
+	m_pRuler_Y1		= new CVIEW_Ruler(this, RULER_VERTICAL  |RULER_MODE_NORMAL|RULER_DESCENDING|RULER_TICKATBOTTOM);
+	m_pRuler_Y2		= new CVIEW_Ruler(this, RULER_VERTICAL  |RULER_MODE_SCALE |RULER_DESCENDING);
+
+	m_Ruler_Size	= 20;
+
+	Ruler_Set_Width(Frame_Width);
+}
+
+//---------------------------------------------------------
+CVIEW_Map::~CVIEW_Map(void)
+{
+	m_pMap->View_Closes(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_Map::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu();
+
+//	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_TOOLBAR);
+//	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_3D_SHOW);
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_LAYOUT_SHOW);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_SAVE_IMAGE);
+//	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_SAVE_IMAGE_ON_CHANGE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_TO_CLIPBOARD);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_TO_CLIPBOARD_LEGEND);
+	if( CSG_Doc_PDF::Get_Version() != NULL )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_SAVE_PDF_INDEXED);
+	}
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_SAVE_INTERACTIVE_SVG);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_ZOOM_BACK);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_ZOOM_FORWARD);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_ZOOM_FULL);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_ZOOM_ACTIVE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_ZOOM_SELECTION);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAP_ZOOM_EXTENT);
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_SYNCHRONIZE);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_MODE_SELECT);
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_MODE_ZOOM);
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_MODE_PAN);
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_MAP_MODE_DISTANCE);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_Map::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_MAP);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP_ZOOM_BACK);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP_ZOOM_FORWARD);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP_ZOOM_FULL);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP_ZOOM_ACTIVE);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP_ZOOM_SELECTION);
+//	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP_ZOOM_EXTENT);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_SYNCHRONIZE);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_MODE_SELECT);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_MODE_ZOOM);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_MODE_PAN);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_MODE_DISTANCE);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_3D_SHOW);
+	CMD_ToolBar_Add_Item(pToolBar, true , ID_CMD_MAP_LAYOUT_SHOW);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Map"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Paint(wxPaintEvent &event)
+{
+	if( m_Ruler_Size > 1 )
+	{
+		wxPaintDC	dc(this);
+		wxRect		rClient(wxPoint(0, 0), GetClientSize()), rMap(rClient);
+
+		rMap.Deflate(m_Ruler_Size - 1);
+
+		dc.DrawLine(rMap   .GetLeft (), rClient.GetTop   (), rMap   .GetLeft (), rClient.GetBottom());
+		dc.DrawLine(rMap   .GetRight(), rClient.GetTop   (), rMap   .GetRight(), rClient.GetBottom());
+		dc.DrawLine(rClient.GetLeft (), rMap   .GetTop   (), rClient.GetRight(), rMap   .GetTop   ());
+		dc.DrawLine(rClient.GetLeft (), rMap   .GetBottom(), rClient.GetRight(), rMap   .GetBottom());
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Size(wxSizeEvent &event)
+{
+	int		minSize	= 2 * m_Ruler_Size + 10;
+	wxSize	Size(GetClientSize()), fSize(GetSize().x - Size.x, GetSize().y - Size.y);
+
+	if( Size.x < minSize || Size.y < minSize )
+	{
+		SetSize(wxSize(
+			fSize.x + (Size.x < minSize ? minSize : Size.x),
+			fSize.y + (Size.y < minSize ? minSize : Size.y)
+		));
+	}
+	else
+	{
+		_Set_Positions();
+
+		event.Skip();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::_Set_Positions(void)
+{
+	wxRect	r(wxPoint(0, 0), GetClientSize());
+
+	if( m_Ruler_Size > 0 )
+	{
+		r.Deflate(m_Ruler_Size);
+
+		m_pRuler_X1	->SetSize(wxRect(r.GetLeft()     , 0                , r.GetWidth(), m_Ruler_Size - 1));
+		m_pRuler_X2	->SetSize(wxRect(r.GetLeft()     , 2 + r.GetBottom(), r.GetWidth(), m_Ruler_Size - 1));
+
+		m_pRuler_Y1	->SetSize(wxRect(0               , r.GetTop()       , m_Ruler_Size - 1, r.GetHeight()));
+		m_pRuler_Y2	->SetSize(wxRect(2 + r.GetRight(), r.GetTop()       , m_Ruler_Size - 1, r.GetHeight()));
+
+		Refresh();
+	}
+
+	m_pControl	->SetSize(r);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Key_Down(wxKeyEvent &event)
+{
+	if( m_pControl )
+	{
+		m_pControl->On_Key_Down(event);
+	}
+	else
+	{
+		event.Skip();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map::Ruler_Set_Width(int Width)
+{
+	if( m_Ruler_Size != Width )
+	{
+		Set_Size_Min(10 + 2 * Width, 10 + 2 * Width);
+
+		m_Ruler_Size	= Width;
+
+		if( m_Ruler_Size > 0 )
+		{
+			m_pRuler_X1->Show(true);
+			m_pRuler_X2->Show(true);
+			m_pRuler_Y1->Show(true);
+			m_pRuler_Y2->Show(true);
+
+			m_pControl->SetWindowStyleFlag(wxFULL_REPAINT_ON_RESIZE);
+		}
+		else
+		{
+			m_pRuler_X1->Show(false);
+			m_pRuler_X2->Show(false);
+			m_pRuler_Y1->Show(false);
+			m_pRuler_Y2->Show(false);
+
+			m_pControl->SetWindowStyleFlag(wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE);
+		}
+
+		_Set_Positions();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::Ruler_Set_Position(int x, int y)
+{
+	if( m_Ruler_Size > 0 )
+	{
+		m_pRuler_X1->Set_Position(x);
+		m_pRuler_X2->Set_Position(x);
+		m_pRuler_Y1->Set_Position(y);
+		m_pRuler_Y2->Set_Position(y);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::Ruler_Refresh(void)
+{
+	if( m_Ruler_Size > 0 )
+	{
+		CSG_Rect	rWorld(m_pMap->Get_World(m_pControl->GetRect()));
+
+		m_pRuler_X1->Set_Range(rWorld.Get_XMin(), rWorld.Get_XMax());
+		m_pRuler_X2->Set_Range(rWorld.Get_XMin(), rWorld.Get_XMax());
+		m_pRuler_Y1->Set_Range(rWorld.Get_YMin(), rWorld.Get_YMax());
+		m_pRuler_Y2->Set_Range(rWorld.Get_YMin(), rWorld.Get_YMax());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	case ID_CMD_MAP_3D_SHOW:
+		event.Check(m_pMap->View_3D_Get() != NULL);
+		break;
+
+	case ID_CMD_MAP_LAYOUT_SHOW:
+		event.Check(m_pMap->View_Layout_Get() != NULL);
+		break;
+
+	case ID_CMD_MAP_SYNCHRONIZE:
+		event.Enable(m_pMap->Get_Manager()->Get_Count() > 1);
+		event.Check(m_pMap->is_Synchronising());
+		break;
+
+	case ID_CMD_MAP_SAVE_IMAGE_ON_CHANGE:
+		event.Check(m_pMap->is_Image_Save_Mode());
+		break;
+
+	case ID_CMD_MAP_MODE_ZOOM:
+		event.Check(m_pControl->Get_Mode() == MAP_MODE_ZOOM);
+		break;
+
+	case ID_CMD_MAP_MODE_PAN:
+		event.Check(m_pControl->Get_Mode() == MAP_MODE_PAN || m_pControl->Get_Mode() == MAP_MODE_PAN_DOWN);
+		break;
+
+	case ID_CMD_MAP_MODE_SELECT:
+		event.Check(m_pControl->Get_Mode() == MAP_MODE_SELECT);
+		break;
+
+	case ID_CMD_MAP_MODE_DISTANCE:
+		event.Check(m_pControl->Get_Mode() == MAP_MODE_DISTANCE);
+		break;
+
+	case ID_CMD_MAP_ZOOM_BACK:
+		event.Enable(m_pMap->Set_Extent_Back(true));
+		break;
+
+	case ID_CMD_MAP_ZOOM_FORWARD:
+		event.Enable(m_pMap->Set_Extent_Forward(true));
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_3D_Show(wxCommandEvent &event)
+{
+	m_pMap->View_3D_Toggle();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Layout_Show(wxCommandEvent &event)
+{
+	m_pMap->View_Layout_Toggle();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Save_Image(wxCommandEvent &event)
+{
+	m_pMap->SaveAs_Image();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Save_Image_On_Change(wxCommandEvent &event)
+{
+	m_pMap->SaveAs_Image_On_Change();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Save_PDF_Indexed(wxCommandEvent &event)
+{
+	m_pMap->SaveAs_PDF_Indexed();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Save_Interactive_SVG(wxCommandEvent &event)
+{
+	m_pMap->SaveAs_Interactive_SVG();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Full(wxCommandEvent &event)
+{
+	m_pMap->Set_Extent_Full();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Back(wxCommandEvent &event)
+{
+	m_pMap->Set_Extent_Back();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Forward(wxCommandEvent &event)
+{
+	m_pMap->Set_Extent_Forward();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Layer(wxCommandEvent &event)
+{
+	m_pMap->Set_Extent_Active();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Selection(wxCommandEvent &event)
+{
+	m_pMap->Set_Extent_Selection();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Extent(wxCommandEvent &event)
+{
+	m_pMap->Set_Extent();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Zoom_Synchronize(wxCommandEvent &event)
+{
+	m_pMap->Set_Synchronising(!m_pMap->is_Synchronising());
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Mode_Zoom(wxCommandEvent &event)
+{
+	m_pControl->Set_Mode(MAP_MODE_ZOOM);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Mode_Pan(wxCommandEvent &event)
+{
+	m_pControl->Set_Mode(MAP_MODE_PAN);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Mode_Select(wxCommandEvent &event)
+{
+	m_pControl->Set_Mode(MAP_MODE_SELECT);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map::On_Map_Mode_Distance(wxCommandEvent &event)
+{
+	m_pControl->Set_Mode(MAP_MODE_DISTANCE);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map::Refresh_Map(void)
+{
+	m_pControl->Refresh_Map();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,155 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                      VIEW_Map.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Map : public CVIEW_Base
+{
+public:
+	CVIEW_Map(class CWKSP_Map *pMap, int Frame_Width);
+	virtual ~CVIEW_Map(void);
+
+	static class wxToolBarBase *	_Create_ToolBar				(void);
+	static class wxMenu *			_Create_Menu				(void);
+
+	void							On_Paint					(wxPaintEvent    &event);
+	void							On_Size						(wxSizeEvent     &event);
+	void							On_Key_Down					(wxKeyEvent      &event);
+
+	virtual void					On_Command_UI				(wxUpdateUIEvent &event);
+
+	void							On_Map_3D_Show				(wxCommandEvent  &event);
+	void							On_Map_Layout_Show			(wxCommandEvent  &event);
+	void							On_Map_Save_Image			(wxCommandEvent  &event);
+	void							On_Map_Save_Image_On_Change	(wxCommandEvent  &event);
+	void							On_Map_Save_PDF_Indexed		(wxCommandEvent  &event);
+	void							On_Map_Save_Interactive_SVG (wxCommandEvent	 &event);
+
+	void							On_Map_Zoom_Full			(wxCommandEvent  &event);
+	void							On_Map_Zoom_Back			(wxCommandEvent  &event);
+	void							On_Map_Zoom_Forward			(wxCommandEvent  &event);
+	void							On_Map_Zoom_Layer			(wxCommandEvent  &event);
+	void							On_Map_Zoom_Selection		(wxCommandEvent  &event);
+	void							On_Map_Zoom_Extent			(wxCommandEvent  &event);
+	void							On_Map_Zoom_Synchronize		(wxCommandEvent  &event);
+
+	void							On_Map_Mode_Zoom			(wxCommandEvent  &event);
+	void							On_Map_Mode_Pan				(wxCommandEvent  &event);
+	void							On_Map_Mode_Select			(wxCommandEvent  &event);
+	void							On_Map_Mode_Distance		(wxCommandEvent  &event);
+
+	class CVIEW_Map_Control *		Get_Map_Control				(void)	{	return( m_pControl );	}
+
+	void							Refresh_Map					(void);
+
+	void							Ruler_Set_Width				(int Width);
+	void							Ruler_Set_Position			(int x, int y);
+	void							Ruler_Refresh				(void);
+
+
+private:
+
+	int								m_Ruler_Size;
+
+	class CWKSP_Map					*m_pMap;
+
+	class CVIEW_Map_Control			*m_pControl;
+
+	class CVIEW_Ruler				*m_pRuler_X1, *m_pRuler_X2, *m_pRuler_Y1, *m_pRuler_Y2;
+
+
+	void							_Set_Positions				(void);
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Map)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1120 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   VIEW_Map_3D.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/window.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_dialogs.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_map.h"
+
+#include "view_map_3d.h"
+#include "view_map_3d_image.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	MAP3D_STATUSBAR_ROTATE_X	= 0,
+	MAP3D_STATUSBAR_ROTATE_Y,
+	MAP3D_STATUSBAR_ROTATE_Z,
+	MAP3D_STATUSBAR_SHIFT_X,
+	MAP3D_STATUSBAR_SHIFT_Y,
+	MAP3D_STATUSBAR_SHIFT_Z,
+	MAP3D_STATUSBAR_EXAGGERATION,
+	MAP3D_STATUSBAR_CENTRAL,
+	MAP3D_STATUSBAR_COUNT
+};
+
+//---------------------------------------------------------
+enum
+{
+	PLAY_MODE_NONE	= 0,
+	PLAY_MODE_RUN_ONCE,
+	PLAY_MODE_RUN_LOOP,
+	PLAY_MODE_RUN_SAVE
+};
+
+//---------------------------------------------------------
+enum
+{
+	PLAY_REC_ROTATE_X	= 0,
+	PLAY_REC_ROTATE_Y,
+	PLAY_REC_ROTATE_Z,
+	PLAY_REC_SHIFT_X,
+	PLAY_REC_SHIFT_Y,
+	PLAY_REC_SHIFT_Z,
+	PLAY_REC_EXAGGERATION,
+	PLAY_REC_CENTRAL,
+	PLAY_REC_STEPS
+};
+
+//---------------------------------------------------------
+#define STEP_ROTATE		( 4.0 * M_DEG_TO_RAD)
+#define STEP_SHIFT		(10.0)
+#define STEP_EXAGGERATE	( 0.5)
+#define STEP_CENTRAL	(10.0)
+#define STEP_STEREO		( 0.5 * M_DEG_TO_RAD)
+#define STEP_SRC_RES	(50)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Map_3D, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Map_3D, CVIEW_Base)
+	EVT_PAINT			(CVIEW_Map_3D::On_Paint)
+	EVT_SIZE			(CVIEW_Map_3D::On_Size)
+	EVT_KEY_DOWN		(CVIEW_Map_3D::On_Key_Down)
+	EVT_LEFT_DOWN		(CVIEW_Map_3D::On_Mouse_LDown)
+	EVT_LEFT_UP			(CVIEW_Map_3D::On_Mouse_LUp)
+	EVT_RIGHT_DOWN		(CVIEW_Map_3D::On_Mouse_RDown)
+	EVT_RIGHT_UP		(CVIEW_Map_3D::On_Mouse_RUp)
+	EVT_MIDDLE_DOWN		(CVIEW_Map_3D::On_Mouse_MDown)
+	EVT_MIDDLE_UP		(CVIEW_Map_3D::On_Mouse_MUp)
+	EVT_MOTION			(CVIEW_Map_3D::On_Mouse_Motion)
+	EVT_MOUSEWHEEL		(CVIEW_Map_3D::On_Mouse_Wheel)
+	EVT_MENU_RANGE		(ID_CMD_MAP3D_FIRST, ID_CMD_MAP3D_LAST, CVIEW_Map_3D::On_Command)
+	EVT_UPDATE_UI_RANGE	(ID_CMD_MAP3D_FIRST, ID_CMD_MAP3D_LAST, CVIEW_Map_3D::On_Command_UI)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Map_3D::CVIEW_Map_3D(CWKSP_Map *pMap)
+	: CVIEW_Base(ID_VIEW_MAP_3D, wxString::Format(wxT("%s [%s]"), LNG("[CAP] 3D-View"), pMap->Get_Name().c_str()), ID_IMG_WND_MAP3D, CVIEW_Map_3D::_Create_Menu(), LNG("[CAP] 3D-View"))
+{
+	CreateStatusBar(MAP3D_STATUSBAR_COUNT);
+
+	//-----------------------------------------------------
+	m_pMap		= pMap;
+	m_pImage	= new CVIEW_Map_3D_Image(this, pMap);
+
+	//-----------------------------------------------------
+	m_Play_Mode	= PLAY_MODE_NONE;
+
+	m_Play.Add_Field(LNG("[FLD] Rotate X")			, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Rotate Y")			, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Rotate Z")			, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Shift X")			, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Shift Y")			, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Shift Z")			, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Exaggeration")		, SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Central Projection"), SG_DATATYPE_Double);
+	m_Play.Add_Field(LNG("[FLD] Steps to Next")		, SG_DATATYPE_Int);
+
+	//-----------------------------------------------------
+	_Parms_Create();
+
+	_Parms_Dlg();
+}
+
+//---------------------------------------------------------
+CVIEW_Map_3D::~CVIEW_Map_3D(void)
+{
+	_Play_Stop();
+
+	delete(m_pImage);
+
+	m_pMap->View_Closes(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_Map_3D::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu(), *pMenu_Sub;
+
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_PARAMETERS);
+
+	pMenu_Sub	= new wxMenu();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_ROTATE_X_LESS);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_ROTATE_X_MORE);
+//	pMenu_Sub->AppendSeparator();
+//	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_ROTATE_Y_LESS);
+//	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_ROTATE_Y_MORE);
+	pMenu_Sub->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_ROTATE_Z_LESS);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_ROTATE_Z_MORE);
+	pMenu->Append(ID_CMD_MAP3D_FIRST, LNG("[MNU] Rotation"), pMenu_Sub);
+
+	pMenu_Sub	= new wxMenu();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SHIFT_X_LESS);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SHIFT_X_MORE);
+	pMenu_Sub->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SHIFT_Y_LESS);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SHIFT_Y_MORE);
+	pMenu_Sub->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SHIFT_Z_LESS);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SHIFT_Z_MORE);
+	pMenu->Append(ID_CMD_MAP3D_FIRST, LNG("[MNU] Shift"), pMenu_Sub);
+
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_EXAGGERATE_LESS);
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_EXAGGERATE_MORE);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu    ,  true, ID_CMD_MAP3D_CENTRAL);
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_CENTRAL_LESS);
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_CENTRAL_MORE);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu    ,  true, ID_CMD_MAP3D_INTERPOLATED);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu    ,  true, ID_CMD_MAP3D_STEREO);
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_STEREO_LESS);
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_STEREO_MORE);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu    , false, ID_CMD_MAP3D_SAVE);
+
+	pMenu_Sub	= new wxMenu();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_POS_ADD);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_POS_DEL);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_POS_DEL_ALL);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_POS_EDIT);
+	pMenu_Sub->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_PLAY);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_PLAY_LOOP);
+	CMD_Menu_Add_Item(pMenu_Sub, false, ID_CMD_MAP3D_SEQ_SAVE);
+	pMenu->Append(ID_CMD_MAP3D_FIRST, LNG("[MNU] Sequencer"), pMenu_Sub);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_Map_3D::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_MAP_3D);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_PARAMETERS);
+	CMD_ToolBar_Add_Item(pToolBar,  true, ID_CMD_MAP3D_INTERPOLATED);
+	CMD_ToolBar_Add_Item(pToolBar,  true, ID_CMD_MAP3D_STEREO);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_ROTATE_X_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_ROTATE_X_MORE);
+//	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_ROTATE_Y_LESS);
+//	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_ROTATE_Y_MORE);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_ROTATE_Z_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_ROTATE_Z_MORE);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_SHIFT_X_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_SHIFT_X_MORE);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_SHIFT_Y_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_SHIFT_Y_MORE);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_SHIFT_Z_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_SHIFT_Z_MORE);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_EXAGGERATE_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_EXAGGERATE_MORE);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_CENTRAL_LESS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_MAP3D_CENTRAL_MORE);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] 3D-View"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Size(wxSizeEvent &event)
+{
+	m_pImage->Set_Image(GetClientSize().x, GetClientSize().y);
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Paint(wxPaintEvent &event)
+{
+	wxPaintDC	dc(this);
+
+	_Paint(dc);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Paint(void)
+{
+	wxClientDC	dc(this);
+
+	_Paint(dc);
+}
+
+void CVIEW_Map_3D::_Paint(wxDC &dc)
+{
+	if( m_pImage->Get_Image().Ok() )
+	{
+		dc.DrawBitmap(wxBitmap(m_pImage->Get_Image()), 0, 0, true);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Key_Down(wxKeyEvent &event)
+{
+	switch( event.GetKeyCode() )
+	{
+	default:
+		event.Skip();
+		break;
+
+	case WXK_F10:		_Parms_Command(ID_CMD_MAP3D_PARAMETERS);		break;
+
+	case WXK_UP:		_Parms_Command(ID_CMD_MAP3D_ROTATE_X_LESS);		break;
+	case WXK_DOWN:		_Parms_Command(ID_CMD_MAP3D_ROTATE_X_MORE);		break;
+
+	case WXK_F3:		_Parms_Command(ID_CMD_MAP3D_ROTATE_Y_LESS);		break;
+	case WXK_F4:		_Parms_Command(ID_CMD_MAP3D_ROTATE_Y_MORE);		break;
+
+	case WXK_LEFT:		_Parms_Command(ID_CMD_MAP3D_ROTATE_Z_LESS);		break;
+	case WXK_RIGHT:		_Parms_Command(ID_CMD_MAP3D_ROTATE_Z_MORE);		break;
+
+	case WXK_INSERT:	_Parms_Command(ID_CMD_MAP3D_SHIFT_X_LESS);		break;
+	case WXK_DELETE:	_Parms_Command(ID_CMD_MAP3D_SHIFT_X_MORE);		break;
+
+	case WXK_HOME:		_Parms_Command(ID_CMD_MAP3D_SHIFT_Y_LESS);		break;
+	case WXK_END:		_Parms_Command(ID_CMD_MAP3D_SHIFT_Y_MORE);		break;
+
+	case WXK_PRIOR:		_Parms_Command(ID_CMD_MAP3D_SHIFT_Z_LESS);		break;
+	case WXK_NEXT:		_Parms_Command(ID_CMD_MAP3D_SHIFT_Z_MORE);		break;
+
+	case WXK_F1:		_Parms_Command(ID_CMD_MAP3D_EXAGGERATE_LESS);	break;
+	case WXK_F2:		_Parms_Command(ID_CMD_MAP3D_EXAGGERATE_MORE);	break;
+
+	case 'C':			_Parms_Command(ID_CMD_MAP3D_CENTRAL);			break;
+	case WXK_F5:		_Parms_Command(ID_CMD_MAP3D_CENTRAL_LESS);		break;
+	case WXK_F6:		_Parms_Command(ID_CMD_MAP3D_CENTRAL_MORE);		break;
+
+	case 'S':			_Parms_Command(ID_CMD_MAP3D_STEREO);			break;
+//	case WXK_F5:		_Parms_Command(ID_CMD_MAP3D_STEREO_LESS);		break;
+//	case WXK_F6:		_Parms_Command(ID_CMD_MAP3D_STEREO_MORE);		break;
+
+	case 'I':			_Parms_Command(ID_CMD_MAP3D_INTERPOLATED);		break;
+
+	case WXK_F7:		_Parms_Command(ID_CMD_MAP3D_SRC_RES_LESS);		break;
+	case WXK_F8:		_Parms_Command(ID_CMD_MAP3D_SRC_RES_MORE);		break;
+
+	case 'A':			_Parms_Command(ID_CMD_MAP3D_SEQ_POS_ADD);		break;
+	case 'D':			_Parms_Command(ID_CMD_MAP3D_SEQ_POS_DEL);		break;
+	case 'P':			_Parms_Command(ID_CMD_MAP3D_SEQ_PLAY);			break;
+	case 'L':			_Parms_Command(ID_CMD_MAP3D_SEQ_PLAY_LOOP);		break;
+	case WXK_ESCAPE:	_Play_Stop();	event.Skip();					break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_MOUSE_X_RELDIFF	((double)(m_Mouse_Down.x - event.GetX()) / (double)GetClientSize().x)
+#define GET_MOUSE_Y_RELDIFF	((double)(m_Mouse_Down.y - event.GetY()) / (double)GetClientSize().y)
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Mouse_LDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= event.GetPosition();
+	m_xDown			= m_pImage->m_zRotate;
+	m_yDown			= m_pImage->m_xRotate;
+
+	CaptureMouse();
+}
+
+void CVIEW_Map_3D::On_Mouse_LUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	if( m_Mouse_Down.x != event.GetX() || m_Mouse_Down.y != event.GetY() )
+	{
+		m_pImage->m_zRotate	= m_xDown - GET_MOUSE_X_RELDIFF * M_PI_180;
+		m_pImage->m_xRotate	= m_yDown - GET_MOUSE_Y_RELDIFF * M_PI_180;
+
+		_Parms_Changed();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Mouse_RDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= event.GetPosition();
+	m_xDown			= m_pImage->m_xShift;
+	m_yDown			= m_pImage->m_yShift;
+
+	CaptureMouse();
+}
+
+void CVIEW_Map_3D::On_Mouse_RUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	if( m_Mouse_Down.x != event.GetX() || m_Mouse_Down.y != event.GetY() )
+	{
+		m_pImage->m_xShift	= m_xDown - GET_MOUSE_X_RELDIFF * 100.0;
+		m_pImage->m_yShift	= m_yDown + GET_MOUSE_Y_RELDIFF * 100.0;
+
+		_Parms_Changed();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Mouse_MDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= event.GetPosition();
+	m_xDown			= m_pImage->m_yRotate;
+	m_yDown			= m_pImage->m_zShift;
+
+	CaptureMouse();
+}
+
+void CVIEW_Map_3D::On_Mouse_MUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	if( m_Mouse_Down.x != event.GetX() || m_Mouse_Down.y != event.GetY() )
+	{
+		m_pImage->m_yRotate	= m_xDown + GET_MOUSE_X_RELDIFF * M_PI_180;
+		m_pImage->m_zShift	= m_yDown + GET_MOUSE_Y_RELDIFF * 100.0;
+
+		_Parms_Changed();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Mouse_Motion(wxMouseEvent &event)
+{
+	if( HasCapture() && event.Dragging() )
+	{
+		if( event.LeftIsDown() )
+		{
+			m_pImage->m_zRotate	= m_xDown - GET_MOUSE_X_RELDIFF * M_PI_180;
+			m_pImage->m_xRotate	= m_yDown - GET_MOUSE_Y_RELDIFF * M_PI_180;
+
+			_Parms_Changed();
+		}
+		else if( event.RightIsDown() )
+		{
+			m_pImage->m_xShift	= m_xDown - GET_MOUSE_X_RELDIFF * 100.0;
+			m_pImage->m_yShift	= m_yDown + GET_MOUSE_Y_RELDIFF * 100.0;
+
+			_Parms_Changed();
+		}
+		else if( event.MiddleIsDown() )
+		{
+			m_pImage->m_yRotate	= m_xDown + GET_MOUSE_X_RELDIFF * M_PI_180;
+			m_pImage->m_zShift	= m_yDown + GET_MOUSE_Y_RELDIFF * 100.0;
+
+			_Parms_Changed();
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Mouse_Wheel(wxMouseEvent &event)
+{
+	if( event.GetWheelRotation() )
+	{
+		m_pImage->m_zShift	+= 0.25 * event.GetWheelRotation();
+
+		_Parms_Changed();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Command(wxCommandEvent &event)
+{
+	_Parms_Command(event.GetId());
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	case ID_CMD_MAP3D_INTERPOLATED:
+		event.Check(m_pImage->m_bInterpol);
+		break;
+
+	case ID_CMD_MAP3D_CENTRAL:
+		event.Check(m_pImage->m_bCentral);
+		break;
+
+	case ID_CMD_MAP3D_STEREO:
+		event.Check(m_pImage->m_bStereo);
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::On_Source_Changed(void)
+{
+	m_pImage->m_Src_bUpdate	= true;
+
+	m_pImage->Set_Source();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Parms_Create(void)
+{
+	CSG_Parameter	*pNode;
+
+	m_Parameters.Create(NULL, LNG("[CAP] 3D-View"), LNG(""));
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Grid(
+		NULL	, "ELEVATION"		, LNG("[CAP] Elevation"),
+		LNG(""),
+		PARAMETER_INPUT
+	);
+
+	//-----------------------------------------------------
+	pNode	= m_Parameters.Add_Node(NULL, "ROTATION", LNG("[CAP] Rotation"), LNG(""));
+
+	m_Parameters.Add_Value(
+		pNode	, "ROTATION_X"		, LNG("X"),
+		LNG(""),
+		PARAMETER_TYPE_Double, -45.0, -360.0, true, 360.0, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "ROTATION_Y"		, LNG("Y"),
+		LNG(""),
+		PARAMETER_TYPE_Double,   0.0, -360.0, true, 360.0, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "ROTATION_Z"		, LNG("Z"),
+		LNG(""),
+		PARAMETER_TYPE_Double,  45.0, -360.0, true, 360.0, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= m_Parameters.Add_Node(NULL, "SHIFT", LNG("[CAP] Shift"), LNG(""));
+
+	m_Parameters.Add_Value(
+		pNode	, "SHIFT_X"			, LNG("Left/Right"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "SHIFT_Y"			, LNG("Up/Down"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "SHIFT_Z"			, LNG("In/Out"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 200.0
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		NULL	, "EXAGGERATION"	, LNG("[CAP] Exaggeration"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	//-----------------------------------------------------
+	pNode	= m_Parameters.Add_Node(NULL, "NODE_PROJECTION", LNG("[CAP] Projection"), LNG(""));
+
+	m_Parameters.Add_Choice(
+		pNode	, "CENTRAL"			, LNG("[CAP] Projection"),
+		LNG(""),
+
+		CSG_String::Format(wxT("%s|%s|"),
+			LNG("parallel"),
+			LNG("central")
+		), 1
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "CENTRAL_DIST"	, LNG("[CAP] Perspectivic Distance"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 200, 1, true
+	);
+
+	//-----------------------------------------------------
+	pNode	= m_Parameters.Add_Node(NULL, "NODE_FIGURE", LNG("[CAP] Figure"), LNG(""));
+
+	m_Parameters.Add_Choice(
+		pNode	, "FIGURE"			, LNG("[CAP] Figure"),
+		LNG(""),
+
+		CSG_String::Format(wxT("%s|%s|%s|%s|"),
+			LNG("plain"),
+			LNG("cylinder"),
+			LNG("ball"),
+			LNG("panorama")
+		), 0
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "FIGURE_WEIGHT"	, LNG("[CAP] Weight"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+	//-----------------------------------------------------
+	pNode	= m_Parameters.Add_Node(NULL, "NODE_STEREO", LNG("[CAP] Anaglyph"), LNG(""));
+
+	m_Parameters.Add_Value(
+		pNode	, "STEREO"			, LNG("[CAP] Anaglyph"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, 0.0
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "STEREO_DIST"		, LNG("[CAP] Eye Distance [Degree]"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 2.0, 0, true, 180, true
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		NULL	, "INTERPOLATED"	, LNG("[CAP] Interpolated"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Value(
+		NULL	, "BKGRD_COLOR"		, LNG("[CAP] Background Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(0, 0, 0)
+	);
+
+	m_Parameters.Add_Value(
+		NULL	, "SRC_RESOLUTION"	, LNG("Resolution"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 200, 10, true
+	);
+}
+
+//---------------------------------------------------------
+bool CVIEW_Map_3D::_Parms_Update(bool bGet)
+{
+	return( _Parms_Update(bGet, m_pImage) );
+}
+
+bool CVIEW_Map_3D::_Parms_Update(bool bGet, CVIEW_Map_3D_Image *pImage)
+{
+	//-----------------------------------------------------
+	if( bGet )
+	{
+		pImage->m_xShift		= m_Parameters("SHIFT_X")		->asDouble();
+		pImage->m_yShift		= m_Parameters("SHIFT_Y")		->asDouble();
+		pImage->m_zShift		= m_Parameters("SHIFT_Z")		->asDouble();
+
+		pImage->m_xRotate		= m_Parameters("ROTATION_X")	->asDouble() * M_DEG_TO_RAD;
+		pImage->m_yRotate		= m_Parameters("ROTATION_Y")	->asDouble() * M_DEG_TO_RAD;
+		pImage->m_zRotate		= m_Parameters("ROTATION_Z")	->asDouble() * M_DEG_TO_RAD;
+
+		pImage->m_Exaggeration	= m_Parameters("EXAGGERATION")	->asDouble();
+
+		pImage->m_bCentral		= m_Parameters("CENTRAL")		->asInt() == 1;
+		pImage->m_Central		= m_Parameters("CENTRAL_DIST")	->asDouble();
+
+		pImage->m_Figure		= m_Parameters("FIGURE")		->asInt();
+		pImage->m_Figure_Weight	= m_Parameters("FIGURE_WEIGHT")	->asDouble();
+
+		pImage->m_bStereo		= m_Parameters("STEREO")		->asBool();
+		pImage->m_Stereo		= m_Parameters("STEREO_DIST")	->asDouble() * M_DEG_TO_RAD;
+
+		pImage->m_BkColor		= m_Parameters("BKGRD_COLOR")	->asColor();
+
+		_Parms_StatusBar();
+
+		//-------------------------------------------------
+		CSG_Grid	*pDEM			= m_Parameters("ELEVATION")		->asGrid();
+
+		if( !g_pData->Exists(pDEM, DATAOBJECT_TYPE_Grid) )
+		{
+			pDEM				= NULL;
+		}
+
+		pImage->m_Src_bUpdate	= pImage->m_pDEM != pDEM ? true : pImage->m_Src_bUpdate;
+		pImage->m_pDEM			= pDEM;
+
+		//-------------------------------------------------
+		if( pImage->m_bInterpol != m_Parameters("INTERPOLATED")	->asBool() )
+		{
+			pImage->m_Src_bUpdate	= true;
+			pImage->m_bInterpol		= !pImage->m_bInterpol;
+		}
+
+		//-------------------------------------------------
+		pImage->Set_Source(m_Parameters("SRC_RESOLUTION")->asInt());
+
+		return( pImage->m_pDEM != NULL );
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		m_Parameters("SHIFT_X")			->Set_Value(pImage->m_xShift);
+		m_Parameters("SHIFT_Y")			->Set_Value(pImage->m_yShift);
+		m_Parameters("SHIFT_Z")			->Set_Value(pImage->m_zShift);
+
+		m_Parameters("ROTATION_X")		->Set_Value(fmod(pImage->m_xRotate * M_RAD_TO_DEG, 360.0));
+		m_Parameters("ROTATION_Y")		->Set_Value(fmod(pImage->m_yRotate * M_RAD_TO_DEG, 360.0));
+		m_Parameters("ROTATION_Z")		->Set_Value(fmod(pImage->m_zRotate * M_RAD_TO_DEG, 360.0));
+
+		m_Parameters("EXAGGERATION")	->Set_Value(pImage->m_Exaggeration);
+
+		m_Parameters("CENTRAL")			->Set_Value(pImage->m_bCentral ? 1 : 0);
+		m_Parameters("CENTRAL_DIST")	->Set_Value(pImage->m_Central);
+
+		m_Parameters("STEREO")			->Set_Value(pImage->m_bStereo);
+		m_Parameters("STEREO_DIST")		->Set_Value(pImage->m_Stereo * M_RAD_TO_DEG);
+
+		_Parms_StatusBar();
+
+		return( true );
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Parms_StatusBar(void)
+{
+	SetStatusText(wxString::Format(wxT("X %+.1f\xb0"), m_pImage->m_xRotate * M_RAD_TO_DEG)	, MAP3D_STATUSBAR_ROTATE_X);
+	SetStatusText(wxString::Format(wxT("Y %+.1f\xb0"), m_pImage->m_yRotate * M_RAD_TO_DEG)	, MAP3D_STATUSBAR_ROTATE_Y);
+	SetStatusText(wxString::Format(wxT("Z %+.1f\xb0"), m_pImage->m_zRotate * M_RAD_TO_DEG)	, MAP3D_STATUSBAR_ROTATE_Z);
+
+	SetStatusText(wxString::Format(wxT("X %+.1f" ), m_pImage->m_xShift)					, MAP3D_STATUSBAR_SHIFT_X);
+	SetStatusText(wxString::Format(wxT("Y %+.1f" ), m_pImage->m_yShift)					, MAP3D_STATUSBAR_SHIFT_Y);
+	SetStatusText(wxString::Format(wxT("Z %+.1f" ), m_pImage->m_zShift)					, MAP3D_STATUSBAR_SHIFT_Z);
+
+	SetStatusText(wxString::Format(wxT("E %.1f"  ), m_pImage->m_Exaggeration)			, MAP3D_STATUSBAR_EXAGGERATION);
+	SetStatusText(wxString::Format(wxT("C %.1f"  ), m_pImage->m_bCentral ? m_pImage->m_Central : 0.0)	, MAP3D_STATUSBAR_CENTRAL);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Parms_Command(int Command)
+{
+	switch( Command )
+	{
+	default:
+		return;
+
+	//-----------------------------------------------------
+	case ID_CMD_MAP3D_SEQ_POS_ADD:		_Play_Pos_Add();	return;
+	case ID_CMD_MAP3D_SEQ_POS_DEL:		_Play_Pos_Del();	return;
+	case ID_CMD_MAP3D_SEQ_POS_DEL_ALL:	_Play_Pos_Clr();	return;
+	case ID_CMD_MAP3D_SEQ_POS_EDIT:		_Play_Pos_Edit();	return;
+	case ID_CMD_MAP3D_SEQ_PLAY:			_Play_Once();		return;
+	case ID_CMD_MAP3D_SEQ_PLAY_LOOP:	_Play_Loop();		return;
+	case ID_CMD_MAP3D_SEQ_SAVE:			_Play_Save();		return;
+
+	//-----------------------------------------------------
+	case ID_CMD_MAP3D_PARAMETERS:		_Parms_Dlg();		return;
+
+	case ID_CMD_MAP3D_SAVE:				m_pImage->Save();	return;
+
+	//-----------------------------------------------------
+	case ID_CMD_MAP3D_INTERPOLATED:
+		m_Parameters("INTERPOLATED")	->Set_Value(!m_pImage->m_bInterpol);
+
+		_Parms_Update(true);
+		return;
+
+	case ID_CMD_MAP3D_SRC_RES_LESS:
+		m_Parameters("SRC_RESOLUTION")	->Set_Value(m_pImage->m_Resolution - STEP_SRC_RES);
+
+		_Parms_Update(true);
+		return;
+
+	case ID_CMD_MAP3D_SRC_RES_MORE:
+		m_Parameters("SRC_RESOLUTION")	->Set_Value(m_pImage->m_Resolution + STEP_SRC_RES);
+
+		_Parms_Update(true);
+		return;
+
+	//-----------------------------------------------------
+	case ID_CMD_MAP3D_ROTATE_X_LESS:	m_pImage->m_xRotate			-= STEP_ROTATE;				break;
+	case ID_CMD_MAP3D_ROTATE_X_MORE:	m_pImage->m_xRotate			+= STEP_ROTATE;				break;
+	case ID_CMD_MAP3D_ROTATE_Y_LESS:	m_pImage->m_yRotate			-= STEP_ROTATE;				break;
+	case ID_CMD_MAP3D_ROTATE_Y_MORE:	m_pImage->m_yRotate			+= STEP_ROTATE;				break;
+	case ID_CMD_MAP3D_ROTATE_Z_LESS:	m_pImage->m_zRotate			-= STEP_ROTATE;				break;
+	case ID_CMD_MAP3D_ROTATE_Z_MORE:	m_pImage->m_zRotate			+= STEP_ROTATE;				break;
+
+	case ID_CMD_MAP3D_SHIFT_X_LESS:		m_pImage->m_xShift			-= STEP_SHIFT;				break;
+	case ID_CMD_MAP3D_SHIFT_X_MORE:		m_pImage->m_xShift			+= STEP_SHIFT;				break;
+	case ID_CMD_MAP3D_SHIFT_Y_LESS:		m_pImage->m_yShift			-= STEP_SHIFT;				break;
+	case ID_CMD_MAP3D_SHIFT_Y_MORE:		m_pImage->m_yShift			+= STEP_SHIFT;				break;
+	case ID_CMD_MAP3D_SHIFT_Z_LESS:		m_pImage->m_zShift			-= STEP_SHIFT;				break;
+	case ID_CMD_MAP3D_SHIFT_Z_MORE:		m_pImage->m_zShift			+= STEP_SHIFT;				break;
+
+	case ID_CMD_MAP3D_EXAGGERATE_LESS:	m_pImage->m_Exaggeration	-= STEP_EXAGGERATE;			break;
+	case ID_CMD_MAP3D_EXAGGERATE_MORE:	m_pImage->m_Exaggeration	+= STEP_EXAGGERATE;			break;
+
+	case ID_CMD_MAP3D_CENTRAL_LESS:		m_pImage->m_Central			-= STEP_CENTRAL;			break;
+	case ID_CMD_MAP3D_CENTRAL_MORE:		m_pImage->m_Central			+= STEP_CENTRAL;			break;
+	case ID_CMD_MAP3D_CENTRAL:			m_pImage->m_bCentral		 = !m_pImage->m_bCentral;	break;
+
+	case ID_CMD_MAP3D_STEREO_LESS:		m_pImage->m_Stereo			-= STEP_STEREO;				break;
+	case ID_CMD_MAP3D_STEREO_MORE:		m_pImage->m_Stereo			+= STEP_STEREO;				break;
+	case ID_CMD_MAP3D_STEREO:			m_pImage->m_bStereo			 = !m_pImage->m_bStereo;	break;
+	}
+
+	_Parms_Changed();
+}
+
+//---------------------------------------------------------
+bool CVIEW_Map_3D::_Parms_Dlg(void)
+{
+	if( DLG_Parameters(&m_Parameters) )
+	{
+		_Parms_Update(true);
+
+		m_pImage->Set_Image();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Parms_Changed(void)
+{
+	_Parms_Update(false);
+
+	m_pImage->Set_Image();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Pos_Add(void)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		pRecord	= m_Play.Add_Record();
+
+		pRecord->Set_Value(PLAY_REC_ROTATE_X		, m_pImage->m_xRotate);
+		pRecord->Set_Value(PLAY_REC_ROTATE_Y		, m_pImage->m_yRotate);
+		pRecord->Set_Value(PLAY_REC_ROTATE_Z		, m_pImage->m_zRotate);
+		pRecord->Set_Value(PLAY_REC_SHIFT_X			, m_pImage->m_xShift);
+		pRecord->Set_Value(PLAY_REC_SHIFT_Y			, m_pImage->m_yShift);
+		pRecord->Set_Value(PLAY_REC_SHIFT_Z			, m_pImage->m_zShift);
+		pRecord->Set_Value(PLAY_REC_EXAGGERATION	, m_pImage->m_Exaggeration);
+		pRecord->Set_Value(PLAY_REC_CENTRAL			, m_pImage->m_Central);
+		pRecord->Set_Value(PLAY_REC_STEPS			, 10);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Pos_Del(void)
+{
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		m_Play.Del_Record(m_Play.Get_Record_Count() - 1);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Pos_Clr(void)
+{
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		m_Play.Del_Records();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Pos_Edit(void)
+{
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		DLG_Table(LNG("[CAP] 3D-View: Player Sequence"), &m_Play);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Once(void)
+{
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		m_Play_Mode	= PLAY_MODE_RUN_ONCE;
+
+		_Play();
+
+		m_Play_Mode	= PLAY_MODE_NONE;
+	}
+	else if( m_Play_Mode == PLAY_MODE_RUN_ONCE )
+	{
+		_Play_Stop();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Loop(void)
+{
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		m_Play_Mode	= PLAY_MODE_RUN_LOOP;
+
+		while( _Play() );
+	}
+	else if( m_Play_Mode == PLAY_MODE_RUN_LOOP )
+	{
+		_Play_Stop();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Save(void)
+{
+	if( m_Play_Mode == PLAY_MODE_NONE )
+	{
+		m_Play_Mode	= PLAY_MODE_RUN_SAVE;
+
+		_Play();
+
+		m_Play_Mode	= PLAY_MODE_NONE;
+	}
+	else if( m_Play_Mode == PLAY_MODE_RUN_SAVE )
+	{
+		_Play_Stop();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D::_Play_Stop(void)
+{
+	if( m_Play_Mode != PLAY_MODE_NONE )
+	{
+		m_Play_Mode	= PLAY_MODE_NONE;
+	}
+}
+
+//---------------------------------------------------------
+#define PLAYER_READ(iRec)	if( (pRecord = m_Play.Get_Record(iRec)) != NULL )			\
+							{	xRotate[1]	= pRecord->asDouble(PLAY_REC_ROTATE_X);		\
+								yRotate[1]	= pRecord->asDouble(PLAY_REC_ROTATE_Y);		\
+								zRotate[1]	= pRecord->asDouble(PLAY_REC_ROTATE_Z);		\
+								xShift [1]	= pRecord->asDouble(PLAY_REC_SHIFT_X);		\
+								yShift [1]	= pRecord->asDouble(PLAY_REC_SHIFT_Y);		\
+								zShift [1]	= pRecord->asDouble(PLAY_REC_SHIFT_Z);		\
+								Exagg  [1]	= pRecord->asDouble(PLAY_REC_EXAGGERATION);	\
+								Central[1]	= pRecord->asDouble(PLAY_REC_CENTRAL);		\
+								Steps  [1]	= pRecord->asDouble(PLAY_REC_STEPS);		}
+
+#define PLAYER_SWAP			{	xRotate[0]	= xRotate[1];	yRotate[0]	= yRotate[1];	zRotate[0]	= zRotate[1];	\
+								xShift [0]	= xShift [1];	yShift [0]	= yShift [1];	zShift [0]	= zShift [1];	\
+								Exagg  [0]	= Exagg  [1];	Central[0]	= Central[1];	Steps  [0]	= Steps  [1];	}
+
+#define PLAYER_SET(Value)	(Value[0] + d * (Value[1] - Value[0]))
+
+//---------------------------------------------------------
+bool CVIEW_Map_3D::_Play(void)
+{
+	int				iRecord, iStep, iFrame	= 0, type;
+
+	double			xRotate[2], yRotate[2], zRotate[2],
+					xShift [2], yShift [2], zShift [2],
+					Exagg  [2], Central[2], Steps  [2],
+					d;
+
+	wxString		file;
+
+	CSG_Table_Record	*pRecord;
+
+	//-----------------------------------------------------
+	if( m_Play.Get_Record_Count() > 1 && m_Play_Mode != PLAY_MODE_NONE )
+	{
+		if( m_Play_Mode == PLAY_MODE_RUN_SAVE )
+		{
+			if( !DLG_Image_Save(file, type) )
+			{
+				m_Play_Mode	= PLAY_MODE_NONE;
+
+				return( false );
+			}
+
+			iFrame	= 0;
+		}
+
+		//-------------------------------------------------
+		PLAYER_READ(0);
+
+		for(iRecord=1; iRecord<m_Play.Get_Record_Count() && m_Play_Mode!=PLAY_MODE_NONE; iRecord++)
+		{
+			PLAYER_SWAP;
+			PLAYER_READ(iRecord);
+
+			for(iStep=0; iStep<Steps[0] && m_Play_Mode!=PLAY_MODE_NONE; iStep++)
+			{
+				d							= iStep / (double)Steps[0];
+				m_pImage->m_xRotate			= PLAYER_SET(xRotate);
+				m_pImage->m_yRotate			= PLAYER_SET(yRotate);
+				m_pImage->m_zRotate			= PLAYER_SET(zRotate);
+				m_pImage->m_xShift			= PLAYER_SET(xShift );
+				m_pImage->m_yShift			= PLAYER_SET(yShift );
+				m_pImage->m_zShift			= PLAYER_SET(zShift );
+				m_pImage->m_xShift			= PLAYER_SET(xShift );
+				m_pImage->m_Exaggeration	= PLAYER_SET(Exagg  );
+				m_pImage->m_Central			= PLAYER_SET(Central);
+
+				_Parms_Changed();
+
+				if( m_Play_Mode == PLAY_MODE_RUN_SAVE )
+				{
+					m_pImage->Save(wxString::Format(wxT("%s_%03d"), file.c_str(), iFrame++), type);
+				}
+
+				PROCESS_Wait();
+			}
+		}
+
+		return( m_Play_Mode != PLAY_MODE_NONE );
+	}
+
+	m_Play_Mode	= PLAY_MODE_NONE;
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,169 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    VIEW_Map_3D.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_3D_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_3D_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Map_3D : public CVIEW_Base
+{
+	friend class CVIEW_Map_3D_Image;
+
+public:
+	CVIEW_Map_3D(class CWKSP_Map *pMap);
+	virtual ~CVIEW_Map_3D(void);
+
+	static class wxToolBarBase *	_Create_ToolBar			(void);
+	static class wxMenu *			_Create_Menu			(void);
+
+	void							On_Size					(wxSizeEvent &event);
+	void							On_Paint				(wxPaintEvent &event);
+
+	void							On_Key_Down				(wxKeyEvent &event);
+
+	void							On_Mouse_LDown			(wxMouseEvent &event);
+	void							On_Mouse_LUp			(wxMouseEvent &event);
+	void							On_Mouse_RDown			(wxMouseEvent &event);
+	void							On_Mouse_RUp			(wxMouseEvent &event);
+	void							On_Mouse_MDown			(wxMouseEvent &event);
+	void							On_Mouse_MUp			(wxMouseEvent &event);
+	void							On_Mouse_Motion			(wxMouseEvent &event);
+	void							On_Mouse_Wheel			(wxMouseEvent &event);
+
+	void							On_Command				(wxCommandEvent &event);
+	void							On_Command_UI			(wxUpdateUIEvent &event);
+
+	void							On_Source_Changed		(void);
+
+
+private:
+
+	int								m_Play_Mode;
+
+	double							m_xDown, m_yDown;
+
+	CSG_Parameters						m_Parameters;
+
+	CSG_Table							m_Play;
+
+	wxPoint							m_Mouse_Down;
+
+	class CWKSP_Map					*m_pMap;
+
+	class CVIEW_Map_3D_Image		*m_pImage;
+
+
+	void							_Paint					(void);
+	void							_Paint					(wxDC &dc);
+
+	void							_Parms_Create			(void);
+	bool							_Parms_Update			(bool bGet);
+	bool							_Parms_Update			(bool bGet, class CVIEW_Map_3D_Image *pImage);
+	void							_Parms_StatusBar		(void);
+	void							_Parms_Command			(int Command);
+	bool							_Parms_Dlg				(void);
+	void							_Parms_Changed			(void);
+
+	void							_Play_Pos_Add			(void);
+	void							_Play_Pos_Del			(void);
+	void							_Play_Pos_Clr			(void);
+	void							_Play_Pos_Edit			(void);
+	void							_Play_Once				(void);
+	void							_Play_Loop				(void);
+	void							_Play_Save				(void);
+	void							_Play_Stop				(void);
+	bool							_Play					(void);
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Map_3D)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_3D_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,976 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                VIEW_Map_3D_Image.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/window.h>
+
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_map.h"
+
+#include "view_map_3d.h"
+#include "view_map_3d_image.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define FLAG_COLOR		0x01
+#define FLAG_DATA		0x02
+#define FLAG_PROJECTION	0x04
+#define FLAG_ALL		(FLAG_COLOR|FLAG_DATA|FLAG_PROJECTION)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Map_3D_Image::CVIEW_Map_3D_Image(CVIEW_Map_3D *pParent, CWKSP_Map *pMap)
+{
+	m_pParent		= pParent;
+	m_pMap			= pMap;
+
+	m_pDEM			= NULL;
+
+	m_img_z			= NULL;
+	m_img_nx		= 0;
+	m_img_ny		= 0;
+
+	m_Points		= NULL;
+	m_nxPoints		= 0;
+	m_nyPoints		= 0;
+	m_Resolution	= 200;
+	m_xyRatio		= 1.0;
+
+	m_bInterpol		= false;
+
+	//-----------------------------------------------------
+	((BYTE *)&m_Missing)[3]	= 0xff;
+	((BYTE *)&m_Missing)[2]	= 0x7f;
+	((BYTE *)&m_Missing)[1]	= 0xff;
+	((BYTE *)&m_Missing)[0]	= 0xff;
+}
+
+//---------------------------------------------------------
+CVIEW_Map_3D_Image::~CVIEW_Map_3D_Image(void)
+{
+	if( m_img_z )
+	{
+		SG_Free(m_img_z[0]);
+		SG_Free(m_img_z);
+	}
+
+	if( m_Points )
+	{
+		SG_Free(m_Points[0]);
+		SG_Free(m_Points);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::Save(void)
+{
+	int			type;
+	wxString	file;
+	CSG_Parameters	Parameters;
+
+	//-----------------------------------------------------
+	Parameters.Create(NULL, LNG("Save 3D Image Options"), LNG(""));
+
+	Parameters.Add_Node(NULL, "NODE_RES", LNG("Image Resolution"), LNG(""));
+
+	Parameters.Add_Value(
+		Parameters("NODE_RES")	, "WIDTH"	, LNG("Width"),
+		wxT(""),
+		PARAMETER_TYPE_Int		, m_img_nx, 1, true
+	);
+
+	Parameters.Add_Value(
+		Parameters("NODE_RES")	, "HEIGHT"	, LNG("Height"),
+		wxT(""),
+		PARAMETER_TYPE_Int		, m_img_ny, 1, true
+	);
+
+	//-----------------------------------------------------
+	if( m_img.Ok() && DLG_Image_Save(file, type) && DLG_Parameters(&Parameters) )
+	{
+		Set_Buisy_Cursor(true);
+
+		if( m_pParent && (m_img_nx != Parameters("WIDTH")->asInt() || m_img_ny != Parameters("HEIGHT")->asInt()) )
+		{
+			CVIEW_Map_3D_Image	Image(NULL, m_pMap);
+
+			m_pParent->_Parms_Update(true, &Image);
+
+			Image.Set_Image(Parameters("WIDTH")->asInt(), Parameters("HEIGHT")->asInt());
+
+			Image.Save(file, type);
+		}
+		else
+		{
+			Save(file, type);
+		}
+
+		Set_Buisy_Cursor(false);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::Save(const wxChar *file, int type)
+{
+	if( m_img.Ok() && file != NULL )
+	{
+		m_img.SaveFile(file, type);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::Set_Source(int Resolution)
+{
+	BYTE		*Color, Mask[3];
+	int			x, y;
+	double		z, xPos, yPos, dx, dy, zMin, zMax, xyRatio;
+	CSG_Rect	rSource(m_pMap->Get_Extent());
+	wxImage		img;
+
+	//-----------------------------------------------------
+	xyRatio		= rSource.Get_XRange() / rSource.Get_YRange();
+
+	if( !m_Points || (Resolution > 0 && Resolution != m_Resolution) || xyRatio != m_xyRatio )
+	{
+		TPoint		*pPoint;
+
+		if( Resolution > 0 )
+			m_Resolution	= Resolution;
+
+		m_xyRatio	= xyRatio;
+
+		if( m_xyRatio > 1.0 )
+		{
+			m_nxPoints	= m_Resolution;
+			m_nyPoints	= (int)(m_Resolution / m_xyRatio);
+		}
+		else
+		{
+			m_nxPoints	= (int)(m_Resolution * m_xyRatio);
+			m_nyPoints	= m_Resolution;
+		}
+
+		pPoint		= m_Points ? m_Points[0] : NULL;
+		pPoint		= (TPoint  *)SG_Realloc( pPoint , m_nxPoints * m_nyPoints * sizeof(TPoint  ));
+		m_Points	= (TPoint **)SG_Realloc(m_Points,              m_nyPoints * sizeof(TPoint *));
+
+		for(int n=0; n<m_nyPoints; n++, pPoint+=m_nxPoints)
+		{
+			m_Points[n]	= pPoint;
+		}
+
+		m_Src_bUpdate	= true;
+	}
+
+	//-----------------------------------------------------
+	if( m_Src_bUpdate && m_Points && m_pDEM )
+	{
+		m_Src_bUpdate	= false;
+
+		if( m_bInterpol )
+			img.Create(m_nxPoints    , m_nyPoints);
+		else
+			img.Create(m_nxPoints - 1, m_nyPoints - 1);
+		m_pMap->Get_Image(img, rSource);
+
+		m_Range	= rSource.Get_XRange() > rSource.Get_YRange() ? rSource.Get_XRange() : rSource.Get_YRange();
+
+		//-------------------------------------------------
+		dx		= rSource.Get_XRange() / (double)m_nxPoints;
+		dy		= rSource.Get_YRange() / (double)m_nyPoints;
+		zMin	= 1.0;
+		zMax	= 0.0;
+
+		for(y=0, yPos=rSource.Get_YMin(); y<m_nyPoints && PROGRESSBAR_Set_Position(y, m_nyPoints); y++, yPos+=dy)
+		{
+			for(x=0, xPos=rSource.Get_XMin(); x<m_nxPoints; x++, xPos+=dx)
+			{
+				if( m_pDEM->Get_Value(xPos, yPos, z) )
+				{
+					m_Points[y][x].zDEM		= z;
+					m_Points[y][x].Flags	= FLAG_DATA;
+
+					if( zMin > zMax )
+						zMin	= zMax	= z;
+					else if( z < zMin )
+						zMin	= z;
+					else if( z > zMax )
+						zMax	= z;
+				}
+				else
+				{
+					m_Points[y][x].Flags	= 0;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		z		= zMin + (zMax - zMin) / 2.0;
+
+		for(y=0; y<m_nyPoints && PROGRESSBAR_Set_Position(y, m_nyPoints); y++)
+		{
+			for(x=0; x<m_nxPoints; x++)
+			{
+				if( (m_Points[y][x].Flags & FLAG_DATA) != 0 )
+				{
+					m_Points[y][x].zDEM	-= z;
+				}
+			}
+		}
+
+		//-----------------------------------------------------
+		Mask[0]	= img.GetMaskRed();
+		Mask[1]	= img.GetMaskGreen();
+		Mask[2]	= img.GetMaskBlue();
+
+		for(y=0; y<img.GetHeight(); y++)
+		{
+			Color	= img.GetData() + (img.GetHeight() - 1 - y) * 3 * img.GetWidth();
+
+			for(x=0; x<img.GetWidth(); x++, Color+=3)
+			{
+				if( memcmp(Color, Mask, 3 * sizeof(BYTE)) )
+				{
+					m_Points[y][x].r		 = Color[0];
+					m_Points[y][x].g		 = Color[1];
+					m_Points[y][x].b		 = Color[2];
+					m_Points[y][x].Flags	|= FLAG_COLOR;
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		PROCESS_Set_Okay(true);
+
+		Set_Image();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::Set_Image(int NX, int NY)
+{
+	int		y;
+	float	*pz;
+
+	if( !m_img_z || NX != m_img_nx || NY != m_img_ny )
+	{
+		m_img.Create(NX, NY);
+		m_img_nx	= m_img.GetWidth();
+		m_img_ny	= m_img.GetHeight();
+
+		pz		= m_img_z ? m_img_z[0] : NULL;
+		pz		= (float  *)SG_Realloc(pz     , NY * NX * sizeof(float  ));
+		m_img_z	= (float **)SG_Realloc(m_img_z, NY      * sizeof(float *));
+
+		for(y=0; y<NY; y++, pz+=NX)
+		{
+			m_img_z[y]	= pz;
+		}
+
+		Set_Image();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::Set_Image(void)
+{
+	BYTE	BkStereo, *r, *p;
+	int		i, n;
+
+	//-----------------------------------------------------
+	if( m_Points && m_img_z )
+	{
+		n	= m_img_nx * m_img_ny;
+
+		if( !m_bStereo )
+		{
+			for(i=0, p=m_img.GetData(); i<n; i++, p+=3)
+			{
+				memcpy(p, &m_BkColor, 3);
+			}
+
+			_Rotate_Matrix(m_xRotate, m_yRotate, m_zRotate);
+			_Draw_Image();
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			BkStereo	= (BYTE)((SG_GET_R(m_BkColor) + SG_GET_G(m_BkColor) + SG_GET_B(m_BkColor)) / 3.0);
+
+			//---------------------------------------------
+			// 1. Right View...
+			memset(m_img.GetData(), BkStereo, 3 * n);
+
+			_Rotate_Matrix(m_xRotate, m_yRotate + 0.5 * m_Stereo, m_zRotate);
+			_Draw_Image();
+
+			r			= (BYTE *)SG_Malloc(n * sizeof(BYTE));
+
+			for(i=0, p=m_img.GetData(); i<n; i++, p+=3)
+			{
+				r[i]	= (p[0] + p[1] + p[2]) / 3;
+			}
+
+			//---------------------------------------------
+			// 2. Left View...
+			memset(m_img.GetData(), BkStereo, 3 * n);
+
+			_Rotate_Matrix(m_xRotate, m_yRotate - 0.5 * m_Stereo, m_zRotate);
+			_Draw_Image();
+
+			for(i=0, p=m_img.GetData(); i<n; i++, p+=3)
+			{
+				p[0]	= (p[0] + p[1] + p[2]) / 3;
+				p[1]	= r[i];
+				p[2]	= BkStereo;
+			}
+
+			SG_Free(r);
+		}
+
+		if( m_pParent )
+		{
+			m_pParent->_Paint();
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define RANGE	200.0
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::_Rotate_Matrix(double xRotate, double yRotate, double zRotate)
+{
+	int		x, y;
+	double	px, py, pz, ix, iy, dx, dy, dz, xRange, yRange;
+	TPoint	*p;
+
+	if( m_xyRatio > 1.0 )
+	{
+		xRange	= RANGE;
+		yRange	= RANGE / m_xyRatio;
+	}
+	else
+	{
+		xRange	= RANGE * m_xyRatio;
+		yRange	= RANGE;
+	}
+
+	//-----------------------------------------------------
+	r_fig	= sqrt(2.0) * m_Figure_Weight * RANGE;
+
+	dx		=  xRange / m_nxPoints;
+	dy		=  yRange / m_nyPoints;
+	dz		= -RANGE * m_Exaggeration / m_Range;
+
+	r_sin_x	= sin(xRotate);
+	r_sin_y	= sin(yRotate);
+	r_sin_z	= sin(zRotate);
+
+	r_cos_x	= cos(xRotate);
+	r_cos_y	= cos(yRotate);
+	r_cos_z	= cos(zRotate);
+
+	r_ext	= RANGE;
+
+	if( m_img_ny > m_img_nx )
+	{
+		r_m		= m_img_nx / r_ext;
+		r_kx	= 0.0f;
+		r_ky	= m_img_ny - (m_img_ny - r_m * r_ext) / 2.0;
+	}
+	else
+	{
+		r_m		= m_img_ny / r_ext;
+		r_kx	= (m_img_nx - r_m * r_ext) / 2.0;
+		r_ky	= m_img_ny;
+	}
+
+	r_ext	= -r_ext / 2.0;
+
+	//-----------------------------------------------------
+	for(y=0, iy=-yRange/2.0; y<m_nyPoints; y++, iy+=dy)
+	{
+		for(x=0, ix=-xRange/2.0, p=m_Points[y]; x<m_nxPoints; x++, ix+=dx, p++)
+		{
+			if( (p->Flags & FLAG_DATA) != 0 && _Rotate_Point(ix, iy, dz * p->zDEM, px, py, pz) )
+			{
+				p->x		= (int)px;
+				p->y		= (int)py;
+				p->z		=      pz;
+				p->Flags	|=  FLAG_PROJECTION;
+			}
+			else
+			{
+				p->Flags	&= ~FLAG_PROJECTION;
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline bool CVIEW_Map_3D_Image::_Rotate_Point(double x, double y, double z, double &px, double &py, double &pz)
+{
+	//-----------------------------------------------------
+	px	= r_cos_z * x - r_sin_z *  y;
+	py	= r_sin_z * x + r_cos_z *  y;
+
+	switch( m_Figure )
+	{
+	default:
+		break;
+
+	case 1:	// cylinder around x-axis
+		x	 = r_fig*r_fig - py*py;
+		z	+= r_fig - (x > 0.0 ? sqrt(x) : 0.0);
+		break;
+
+	case 2:	// ball
+		x	 = r_fig*r_fig - py*py - px*px;
+		z	+= r_fig - (x > 0.0 ? sqrt(x) : 0.0);
+		break;
+
+	case 3:	// panaroma
+		x	 = m_Figure_Weight * 20.0 * (0.5 * RANGE - py) / RANGE;
+		z	+= x*x;
+		break;
+	}
+
+	pz	= r_cos_x * z - r_sin_x * py;
+	py	= r_sin_x * z + r_cos_x * py;
+
+	z	= pz;
+	pz	= r_cos_y * z - r_sin_y * px;
+	px	= r_sin_y * z + r_cos_y * px;
+
+	px	+= m_xShift;
+	py	+= m_yShift;
+	pz	+= m_zShift;
+
+	//-----------------------------------------------------
+	if( m_bCentral )
+	{
+		if( pz > 0.0 )
+		{
+			pz	 = m_Central / pz;
+			px	*= pz;
+			py	*= pz;
+		}
+		else
+		{
+			return( false );
+		}
+	}
+	else
+	{
+		if( m_zShift > 0.0 )
+		{
+			z	 = m_Central / m_zShift;
+			px	*= z;
+			py	*= z;
+			pz	 = -pz;
+		}
+		else
+		{
+			return( false );
+		}
+	}
+
+	//-----------------------------------------------------
+	px	= r_kx + r_m * (px - r_ext);
+	py	= r_ky - r_m * (py - r_ext);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::_Draw_Image(void)
+{
+	int		x, y;
+	TPoint	p[3];
+
+	//-----------------------------------------------------
+	for(y=0; y<m_img_ny; y++)
+	{
+		for(x=0; x<m_img_nx; x++)
+		{
+			m_img_z[y][x]	= m_Missing;
+		}
+	}
+
+	//-----------------------------------------------------
+	for(y=0; y<m_nyPoints-1; y++)
+	{
+		for(x=0; x<m_nxPoints-1; x++)
+		{
+			p[0]	= m_Points[y    ][x    ];
+			p[1]	= m_Points[y + 1][x + 1];
+			p[2]	= m_Points[y    ][x + 1];
+
+			if( m_bInterpol )
+				_Draw_Triangle_i(p);
+			else
+				_Draw_Triangle  (p);
+
+			//---------------------------------------------
+			p[0]	= m_Points[y    ][x    ];
+			p[1]	= m_Points[y + 1][x + 1];
+			p[2]	= m_Points[y + 1][x    ];
+
+			if( m_bInterpol )
+				_Draw_Triangle_i(p);
+			else
+				_Draw_Triangle  (p);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SORT_POINTS_Y(a, b)	if( p[a].y < p[b].y ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+#define SORT_POINTS_X(a, b)	if( p[a].x < p[b].x ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+
+//---------------------------------------------------------
+#define _Draw_Pixel(x, y, z, r, g, b)	if(	z > m_img_z[y][x] ) { m_img_z[y][x] = z; m_img.SetRGB(x, y, r, g, b); }
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::_Draw_Triangle(TPoint p[3])
+{
+	BYTE	r, g, b;
+	int		i, j, k, y, y_j;
+	double	dy, x[2], dx[2], z[2], dz[2];
+	TPoint	pp;
+
+	//-----------------------------------------------------
+	if(	(p[0].Flags & FLAG_COLOR)      == 0
+	||	(p[0].Flags & FLAG_PROJECTION) == 0
+	||	(p[1].Flags & FLAG_PROJECTION) == 0
+	||	(p[2].Flags & FLAG_PROJECTION) == 0 )
+	{
+		return;
+	}
+
+	//-----------------------------------------------------
+	r	= p[0].r;
+	g	= p[0].g;
+	b	= p[0].b;
+
+	SORT_POINTS_Y(1, 0);
+	SORT_POINTS_Y(2, 0);
+	SORT_POINTS_Y(2, 1);
+
+	//-----------------------------------------------------
+	if( p[2].y == p[0].y )
+	{
+		if( p[0].y >= 0 && p[0].y < m_img_ny )
+		{
+			SORT_POINTS_X(1, 0);
+			SORT_POINTS_X(2, 0);
+			SORT_POINTS_X(2, 1);
+
+			//---------------------------------------------
+			if( p[2].x == p[0].x )
+			{
+				if(	p[0].x >= 0 && p[0].x < m_img_nx )
+				{
+					i	= p[0].z > p[1].z ? (p[0].z > p[2].z ? 0 : 2) : (p[1].z > p[2].z ? 1 : 2);
+					_Draw_Pixel(p[0].x, p[0].y, p[i].z, r, g, b);
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				_Draw_Line(p[0].x, p[1].x, p[0].y, p[0].z, p[1].z, r, g, b);
+				_Draw_Line(p[1].x, p[2].x, p[0].y, p[1].z, p[2].z, r, g, b);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= m_img_ny && p[2].y >= m_img_ny)) )
+	{
+		dy		=  p[2].y - p[0].y;
+		dx[0]	= (p[2].x - p[0].x) / dy;
+		dz[0]	= (p[2].z - p[0].z) / dy;
+		x [0]	=  p[0].x;
+		z [0]	=  p[0].z;
+
+		for(i=0, j=1; i<2; i++, j++)
+		{
+			if( (dy	=  p[j].y - p[i].y) > 0.0 )
+			{
+				dx[1]	= (p[j].x - p[i].x) / dy;
+				dz[1]	= (p[j].z - p[i].z) / dy;
+				x [1]	=  p[i].x;
+				z [1]	=  p[i].z;
+
+				if( (y = p[i].y) < 0 )
+				{
+					x[1]	-= y * dx[1];
+					z[1]	-= y * dz[1];
+					y		 = 0;
+					x[0]	 = p[0].x - p[0].y * dx[0];
+					z[0]	 = p[0].z - p[0].y * dz[0];
+				}
+
+				if( (y_j = p[j].y) > m_img_ny )
+				{
+					y_j		= m_img_ny;
+				}
+
+				for( ; y<y_j; y++)
+				{
+					if( x[1] < x[0] )
+					{
+						_Draw_Line((int)x[1], (int)x[0], y, z[1], z[0], r, g, b);
+					}
+					else
+					{
+						_Draw_Line((int)x[0], (int)x[1], y, z[0], z[1], r, g, b);
+					}
+
+					for(k=0; k<=1; k++)
+					{
+						x[k]	+= dx[k];
+						z[k]	+= dz[k];
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CVIEW_Map_3D_Image::_Draw_Line(int xa, int xb, int y, double za, double zb, BYTE r, BYTE g, BYTE b)
+{
+	double	dz;
+
+	if( (dz = xb - xa) > 0.0 )
+	{
+		dz	= (zb - za) / dz;
+
+		if( xa < 0 )
+		{
+			za	-= dz * xa;
+			xa	 = 0;
+		}
+
+		if( xb >= m_img_nx )
+		{
+			xb	= m_img_nx - 1;
+		}
+
+		for(int x=xa; x<=xb; x++, za+=dz)
+		{
+			_Draw_Pixel(x, y, za, r, g, b);
+		}
+	}
+	else if( xa >= 0 && xa < m_img_nx )
+	{
+		_Draw_Pixel(xa, y, za, r, g, b);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_3D_Image::_Draw_Triangle_i(TPoint p[3])
+{
+	int		i, j, k, y, y_j;
+	double	x[2], dx[2], dy, z[2], dz[2], r[2], dr[2], g[2], dg[2], b[2], db[2];
+	TPoint	pp;
+
+	//-----------------------------------------------------
+	i	= FLAG_ALL;
+	if(	(p[0].Flags != i) || (p[1].Flags != i) || (p[2].Flags != i) )
+	{
+		return;
+	}
+
+	//-----------------------------------------------------
+	SORT_POINTS_Y(1, 0);
+	SORT_POINTS_Y(2, 0);
+	SORT_POINTS_Y(2, 1);
+
+	//-----------------------------------------------------
+	if( p[2].y == p[0].y )
+	{
+		if( p[0].y >= 0 && p[0].y < m_img_ny )
+		{
+			SORT_POINTS_X(1, 0);
+			SORT_POINTS_X(2, 0);
+			SORT_POINTS_X(2, 1);
+
+			//---------------------------------------------
+			if( p[2].x == p[0].x )
+			{
+				if(	p[0].x >= 0 && p[0].x < m_img_nx )
+				{
+					i	= p[0].z > p[1].z ? (p[0].z > p[2].z ? 0 : 2) : (p[1].z > p[2].z ? 1 : 2);
+					_Draw_Pixel(p[0].x, p[0].y, p[i].z, p[i].r, p[i].g, p[i].b);
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				_Draw_Line_i(p[0].x, p[1].x, p[0].y, p[0].z, p[1].z, p[0].r, p[1].r, p[0].g, p[1].g, p[0].b, p[1].b);
+				_Draw_Line_i(p[1].x, p[2].x, p[0].y, p[1].z, p[2].z, p[1].r, p[2].r, p[1].g, p[2].g, p[1].b, p[2].b);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= m_img_ny && p[2].y >= m_img_ny)) )
+	{
+		dy		=  p[2].y - p[0].y;
+		dx[0]	= (p[2].x - p[0].x) / dy;
+		dz[0]	= (p[2].z - p[0].z) / dy;
+		dr[0]	= (p[2].r - p[0].r) / dy;
+		dg[0]	= (p[2].g - p[0].g) / dy;
+		db[0]	= (p[2].b - p[0].b) / dy;
+		x [0]	=  p[0].x;
+		z [0]	=  p[0].z;
+		r [0]	=  p[0].r;
+		g [0]	=  p[0].g;
+		b [0]	=  p[0].b;
+
+		for(i=0, j=1; i<2; i++, j++)
+		{
+			if( (dy	=  p[j].y - p[i].y) > 0.0 )
+			{
+				dx[1]	= (p[j].x - p[i].x) / dy;
+				dz[1]	= (p[j].z - p[i].z) / dy;
+				dr[1]	= (p[j].r - p[i].r) / dy;
+				dg[1]	= (p[j].g - p[i].g) / dy;
+				db[1]	= (p[j].b - p[i].b) / dy;
+				x [1]	=  p[i].x;
+				z [1]	=  p[i].z;
+				r [1]	=  p[i].r;
+				g [1]	=  p[i].g;
+				b [1]	=  p[i].b;
+
+				if( (y = p[i].y) < 0 )
+				{
+					x[1]	-= y * dx[1];
+					z[1]	-= y * dz[1];
+					r[1]	-= y * dr[1];
+					g[1]	-= y * dg[1];
+					b[1]	-= y * db[1];
+					y		 = 0;
+					x[0]	 = p[0].x - p[0].y * dx[0];
+					z[0]	 = p[0].z - p[0].y * dz[0];
+					r[0]	 = p[0].r - p[0].y * dr[0];
+					g[0]	 = p[0].g - p[0].y * dg[0];
+					b[0]	 = p[0].b - p[0].y * db[0];
+				}
+
+				if( (y_j = p[j].y) > m_img_ny )
+				{
+					y_j		= m_img_ny;
+				}
+
+				for( ; y<y_j; y++)
+				{
+					if( x[1] < x[0] )
+					{
+						_Draw_Line_i((int)x[1], (int)x[0], y, z[1], z[0], r[1], r[0], g[1], g[0], b[1], b[0]);
+					}
+					else
+					{
+						_Draw_Line_i((int)x[0], (int)x[1], y, z[0], z[1], r[0], r[1], g[0], g[1], b[0], b[1]);
+					}
+
+					for(k=0; k<=1; k++)
+					{
+						x[k]	+= dx[k];
+						z[k]	+= dz[k];
+						r[k]	+= dr[k];
+						g[k]	+= dg[k];
+						b[k]	+= db[k];
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CVIEW_Map_3D_Image::_Draw_Line_i(int xa, int xb, int y, double za, double zb, double ra, double rb, double ga, double gb, double ba, double bb)
+{
+	double	d, dz, dr, dg, db;
+
+	if( (d = xb - xa) > 0.0 )
+	{
+		dz	= (zb - za) / d;
+		dr	= (rb - ra) / d;
+		dg	= (gb - ga) / d;
+		db	= (bb - ba) / d;
+
+		if( xa < 0 )
+		{
+			za	-= dz * xa;
+			ra	-= dr * xa;
+			ga	-= dg * xa;
+			ba	-= db * xa;
+			xa	 = 0;
+		}
+
+		if( xb >= m_img_nx )
+		{
+			xb	= m_img_nx - 1;
+		}
+
+		for(int x=xa; x<=xb; x++, za+=dz, ra+=dr, ga+=dg, ba+=db)
+		{
+			_Draw_Pixel(x, y, za, (int)ra, (int)ga, (int)ba);
+		}
+	}
+	else if( xa >= 0 && xa < m_img_nx )
+	{
+		_Draw_Pixel(xa, y, za, (int)ra, (int)ga, (int)ba);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_3d_image.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,177 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_Map_3D_Image.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_3D_Image_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_3D_Image_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum
+{
+	mode3d_Normal			= 0,
+	mode3d_Triangle,
+	mode3d_Stereo
+}
+TRender_3DMode;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Map_3D_Image
+{
+public:
+	CVIEW_Map_3D_Image(class CVIEW_Map_3D *pParent, class CWKSP_Map *pMap);
+	virtual ~CVIEW_Map_3D_Image(void);
+
+	bool							m_bCentral, m_bStereo, m_bInterpol, m_Src_bUpdate;
+
+	int								m_img_nx, m_img_ny, m_Resolution, m_nxPoints, m_nyPoints, m_BkColor, m_Figure;
+
+	double							m_xRotate, m_yRotate, m_zRotate,
+									m_xShift, m_yShift, m_zShift,
+									m_Range, m_Exaggeration, m_Central, m_Stereo,
+									m_Figure_Weight;
+
+	CSG_Grid							*m_pDEM;
+
+
+	void							Set_Source				(int Resolution = -1);
+
+	void							Set_Image				(int NX, int NY);
+	void							Set_Image				(void);
+
+	wxImage &						Get_Image				(void)	{	return( m_img );	}
+
+	void							Save					(void);
+	void							Save					(const wxChar *file, int type);
+
+
+private:
+
+	typedef struct
+	{
+		BYTE						r, g, b, Flags;
+
+		int							x, y;
+
+		float						z, zDEM;
+	}
+	TPoint;
+
+
+	float							**m_img_z, m_Missing;
+
+	double							r_sin_x, r_sin_y, r_sin_z,
+									r_cos_x, r_cos_y, r_cos_z,
+									r_kx, r_ky, r_m, r_ext, r_fig,
+									m_xyRatio;
+
+	TPoint							**m_Points;
+
+	wxImage							m_img;
+
+	class CWKSP_Map					*m_pMap;
+
+	class CVIEW_Map_3D				*m_pParent;
+
+
+	void							_Rotate_Matrix			(double xRotate, double yRotate, double zRotate);
+	bool							_Rotate_Point			(double x, double y, double z, double &px, double &py, double &pz);
+
+	void							_Draw_Image				(void);
+	void							_Draw_Triangle			(TPoint p[3]);
+	void							_Draw_Line				(int xa, int xb, int y, double za, double zb, BYTE r, BYTE g, BYTE b);
+	void							_Draw_Triangle_i		(TPoint p[3]);
+	void							_Draw_Line_i			(int xa, int xb, int y, double za, double zb, double ra, double rb, double ga, double gb, double ba, double bb);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_3D_Image_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,976 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_Map_Control.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/image.h>
+
+#include "res_images.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_map.h"
+#include "wksp_module.h"
+#include "wksp_grid.h"
+#include "wksp_shapes.h"
+
+#include "view_map.h"
+#include "view_map_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define GET_KEYS(e)	((e.LeftIsDown()   ? MODULE_INTERACTIVE_KEY_LEFT   : 0)\
+					|(e.MiddleIsDown() ? MODULE_INTERACTIVE_KEY_MIDDLE : 0)\
+					|(e.RightIsDown()  ? MODULE_INTERACTIVE_KEY_RIGHT  : 0)\
+					|(e.ShiftDown()    ? MODULE_INTERACTIVE_KEY_SHIFT  : 0)\
+					|(e.AltDown()      ? MODULE_INTERACTIVE_KEY_ALT    : 0)\
+					|(e.ControlDown()  ? MODULE_INTERACTIVE_KEY_CTRL   : 0))
+
+//---------------------------------------------------------
+#define STANDARD_ZOOM_FACTOR	50
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Map_Control, wxPanel)
+	EVT_PAINT			(CVIEW_Map_Control::On_Paint)
+	EVT_SIZE			(CVIEW_Map_Control::On_Size)
+	EVT_KEY_DOWN		(CVIEW_Map_Control::On_Key_Down)
+
+	EVT_MOUSEWHEEL		(CVIEW_Map_Control::On_Mouse_Wheel)
+	EVT_MOTION			(CVIEW_Map_Control::On_Mouse_Motion)
+	EVT_LEFT_DOWN		(CVIEW_Map_Control::On_Mouse_LDown)
+	EVT_LEFT_UP			(CVIEW_Map_Control::On_Mouse_LUp)
+	EVT_LEFT_DCLICK		(CVIEW_Map_Control::On_Mouse_LDClick)
+	EVT_RIGHT_DOWN		(CVIEW_Map_Control::On_Mouse_RDown)
+	EVT_RIGHT_UP		(CVIEW_Map_Control::On_Mouse_RUp)
+	EVT_RIGHT_DCLICK	(CVIEW_Map_Control::On_Mouse_RDClick)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Map_Control::CVIEW_Map_Control(CVIEW_Map *pParent, CWKSP_Map *pMap)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_pParent	= (CVIEW_Map *)pParent;
+	m_pMap		= pMap;
+
+	m_Mode		= -1;
+	Set_Mode(MAP_MODE_ZOOM);
+
+	m_Drag_Mode	= MODULE_INTERACTIVE_DRAG_NONE;
+}
+
+//---------------------------------------------------------
+CVIEW_Map_Control::~CVIEW_Map_Control(void)
+{
+	_Distance_Reset();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Map_Control::Set_Mode(int Mode)
+{
+	if( m_Mode != Mode )
+	{
+		if( m_Mode == MAP_MODE_DISTANCE )
+		{
+			_Distance_Reset();
+		}
+
+		m_Mode	= Mode;
+
+		switch( m_Mode )
+		{
+		case MAP_MODE_ZOOM: default:
+			SetCursor(IMG_Get_Cursor(ID_IMG_CRS_SELECT));
+			break;
+
+		case MAP_MODE_PAN:
+			SetCursor(IMG_Get_Cursor(ID_IMG_CRS_HAND));
+			break;
+
+		case MAP_MODE_PAN_DOWN:
+			SetCursor(IMG_Get_Cursor(ID_IMG_CRS_HAND_GRAP));
+			break;
+
+		case MAP_MODE_SELECT:
+			SetCursor(IMG_Get_Cursor(ID_IMG_CRS_INFO));
+			break;
+
+		case MAP_MODE_DISTANCE:
+			SetCursor(IMG_Get_Cursor(ID_IMG_CRS_SELECT));
+			_Distance_Reset();
+			break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+inline void CVIEW_Map_Control::_Set_StatusBar(CSG_Point ptWorld)
+{
+	STATUSBAR_Set_Text(wxString::Format(wxT("X%f"), ptWorld.Get_X()), STATUSBAR_VIEW_X);
+	STATUSBAR_Set_Text(wxString::Format(wxT("Y%f"), ptWorld.Get_Y()), STATUSBAR_VIEW_Y);
+
+	if( m_Mode == MAP_MODE_DISTANCE )
+	{
+		STATUSBAR_Set_Text(wxString::Format(wxT("D %f"), m_Distance + m_Distance_Move), STATUSBAR_VIEW_Z);
+	}
+	else if( Get_Active_Layer() )
+	{
+		STATUSBAR_Set_Text(wxString::Format(wxT("Z %s"), Get_Active_Layer()->Get_Value(ptWorld, _Get_World(2.0)).c_str()), STATUSBAR_VIEW_Z);
+	}
+	else
+	{
+		STATUSBAR_Set_Text(wxT("Z"), STATUSBAR_VIEW_Z);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline wxRect CVIEW_Map_Control::_Get_Client(void)
+{
+	return( wxRect(wxPoint(0, 0), GetClientSize()) );
+}
+
+//---------------------------------------------------------
+inline wxPoint CVIEW_Map_Control::_Get_Client(TSG_Point Point)
+{
+	wxRect		rClient(_Get_Client());
+	CSG_Rect	rWorld(m_pMap->Get_World(rClient));
+	double		World2DC	= (double)rClient.GetWidth() / rWorld.Get_XRange();
+
+	return( wxPoint(          (int)(0.5 + (Point.x - rWorld.Get_XMin()) * World2DC),
+		rClient.GetHeight() - (int)(0.5 + (Point.y - rWorld.Get_YMin()) * World2DC)
+	));
+}
+
+//---------------------------------------------------------
+inline CSG_Point CVIEW_Map_Control::_Get_World(wxPoint ptClient)
+{
+	return( m_pMap->Get_World(_Get_Client(), ptClient) );
+}
+
+//---------------------------------------------------------
+inline double CVIEW_Map_Control::_Get_World(double xClient)
+{
+	wxRect		rClient(_Get_Client());
+	CSG_Rect	rWorld(m_pMap->Get_World(rClient));
+
+	return( xClient * rWorld.Get_XRange() / (double)rClient.GetWidth() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::_Draw_Inverse(wxPoint ptA, wxPoint ptB)
+{
+	if( m_Drag_Mode != MODULE_INTERACTIVE_DRAG_NONE )
+	{
+		wxClientDC	dc(this);
+
+		dc.SetLogicalFunction(wxINVERT);
+
+		switch( m_Drag_Mode )
+		{
+		case MODULE_INTERACTIVE_DRAG_LINE:
+			dc.DrawLine			(ptA.x, ptA.y, ptB.x, ptB.y);
+			break;
+
+		case MODULE_INTERACTIVE_DRAG_BOX:
+			dc.DrawRectangle	(ptA.x, ptA.y, ptB.x - ptA.x, ptB.y - ptA.y);
+			break;
+
+		case MODULE_INTERACTIVE_DRAG_CIRCLE:
+			dc.DrawCircle		(ptA.x, ptA.y, (int)SG_Get_Distance(ptA.x, ptA.y, ptB.x, ptB.y));
+			break;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::_Draw_Inverse(wxPoint ptA, wxPoint ptB_Old, wxPoint ptB_New)
+{
+	if( m_Drag_Mode != MODULE_INTERACTIVE_DRAG_NONE )
+	{
+		wxClientDC	dc(this);
+
+		dc.SetLogicalFunction(wxINVERT);
+
+		switch( m_Drag_Mode )
+		{
+		case MODULE_INTERACTIVE_DRAG_LINE:
+			dc.DrawLine			(ptA.x, ptA.y, ptB_Old.x, ptB_Old.y);
+			dc.DrawLine			(ptA.x, ptA.y, ptB_New.x, ptB_New.y);
+			break;
+
+		case MODULE_INTERACTIVE_DRAG_BOX:
+			dc.DrawRectangle	(ptA.x, ptA.y, ptB_Old.x - ptA.x, ptB_Old.y - ptA.y);
+			dc.DrawRectangle	(ptA.x, ptA.y, ptB_New.x - ptA.x, ptB_New.y - ptA.y);
+			break;
+
+		case MODULE_INTERACTIVE_DRAG_CIRCLE:
+			dc.DrawCircle		(ptA.x, ptA.y, (int)SG_Get_Distance(ptA.x, ptA.y, ptB_Old.x, ptB_Old.y));
+			dc.DrawCircle		(ptA.x, ptA.y, (int)SG_Get_Distance(ptA.x, ptA.y, ptB_New.x, ptB_New.y));
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Map_Control::_Zoom(wxPoint A, wxPoint B)
+{
+	CSG_Rect	rWorld;
+
+	if( A.x == B.x && A.y == B.y )
+	{
+		return( _Zoom(_Get_World(A), true) );
+	}
+
+	rWorld.Assign(_Get_World(A), _Get_World(B));
+
+	m_pMap->Set_Extent(rWorld);
+
+	return( true );
+}
+
+bool CVIEW_Map_Control::_Zoom(CSG_Point ptCenter, bool bZoomIn)
+{
+	CSG_Rect	rWorld(m_pMap->Get_Extent());
+
+	rWorld.Move(ptCenter - rWorld.Get_Center());
+
+	if( bZoomIn )
+	{
+		rWorld.Deflate(STANDARD_ZOOM_FACTOR);
+	}
+	else
+	{
+		rWorld.Inflate(STANDARD_ZOOM_FACTOR);
+	}
+
+	m_pMap->Set_Extent(rWorld);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Map_Control::_Pan(wxPoint A, wxPoint B)
+{
+	if( A.x != B.x || A.y != B.y )
+	{
+		wxClientDC	dc(this);
+
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+		dc.DrawBitmap(m_Bitmap, B.x - A.x, B.y - A.y, false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Map_Control::_Move(wxPoint &A, wxPoint B)
+{
+	if( A.x != B.x || A.y != B.y )
+	{
+		CSG_Rect	rWorld;
+
+		rWorld.Assign(m_pMap->Get_Extent());
+		rWorld.Move(_Get_World(A) - _Get_World(B));
+		m_pMap->Set_Extent(rWorld);
+
+		A	= B;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CVIEW_Map_Control::_Move(wxPoint ptMove)
+{
+	return( _Move(ptMove, wxPoint(0, 0)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::_Distance_Reset(void)
+{
+	m_Distance_Pts.Clear();
+
+	m_Distance		= 0.0;
+	m_Distance_Move	= 0.0;
+
+	Refresh(false);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::_Distance_Add(wxPoint Point)
+{
+	int		n	= m_Distance_Pts.Get_Count();
+
+	m_Distance_Pts.Add(_Get_World(Point));
+
+	if( n > 0 )
+	{
+		m_Distance	+= SG_Get_Distance(m_Distance_Pts[n], m_Distance_Pts[n - 1]);
+	}
+
+	m_Distance_Move	= 0.0;
+
+	wxClientDC	dc(this);
+	_Distance_Draw(dc);
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::_Distance_Draw(wxDC &dc)
+{
+	int		n	= m_Distance_Pts.Get_Count();
+
+	if( m_Mode == MAP_MODE_DISTANCE && n > 0 )
+	{
+		int		i;
+		wxPoint	A, B;
+
+		dc.SetPen(wxPen(*wxWHITE, 4));
+		for(i=1, A=_Get_Client(m_Distance_Pts[0]); i<n; i++)
+		{
+			B	= A;
+			A	= _Get_Client(m_Distance_Pts[i]);
+			dc.DrawLine(A.x, A.y, B.x, B.y);
+		}
+
+		dc.SetPen(wxPen(*wxBLACK, 2));
+		for(i=1, A=_Get_Client(m_Distance_Pts[0]); i<n; i++)
+		{
+			B	= A;
+			A	= _Get_Client(m_Distance_Pts[i]);
+			dc.DrawLine(A.x, A.y, B.x, B.y);
+		}
+
+		dc.SetPen(wxNullPen);
+		dc.SetLogicalFunction(wxINVERT);
+		A	= _Get_Client(m_Distance_Pts[n - 1]);
+		dc.DrawLine(A.x, A.y, m_Mouse_Move.x, m_Mouse_Move.y);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Paint(wxPaintEvent &event)
+{
+	if( m_Bitmap.Ok() )
+	{
+		wxPaintDC	dc(this);
+
+		dc.DrawBitmap(m_Bitmap, 0, 0, false);
+
+		_Distance_Draw(dc);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Size(wxSizeEvent &event)
+{
+	wxRect	r(_Get_Client());
+
+	if( m_Bitmap.GetWidth() != r.GetWidth() || m_Bitmap.GetHeight() != r.GetHeight() )
+	{
+		m_Bitmap.Create(r.GetWidth(), r.GetHeight());
+
+		Refresh_Map();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::Refresh_Map(void)
+{
+	if( m_Bitmap.Ok() )
+	{
+		wxMemoryDC	dc;
+
+		dc.SelectObject(m_Bitmap);
+		m_pMap->Draw_Map(dc, 1.0, _Get_Client(), true);
+		dc.SelectObject(wxNullBitmap);
+
+		m_pParent->Ruler_Refresh();
+
+		Refresh(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Key_Down(wxKeyEvent &event)
+{
+	if( m_pMap->Find_Layer(Get_Active_Layer()) && Get_Active_Layer()->Edit_On_Key_Down(event.GetKeyCode()) )
+	{
+		return;
+	}
+
+	switch( event.GetKeyCode() )
+	{
+	default:
+		event.Skip();
+		break;
+
+	case WXK_PRIOR:
+		_Zoom(m_pMap->Get_Extent().Get_Center(), true);
+		break;
+		
+	case WXK_NEXT:
+		_Zoom(m_pMap->Get_Extent().Get_Center(), false);
+		break;
+		
+	case WXK_LEFT:
+		_Move(wxPoint(-10,   0));
+		break;
+
+	case WXK_RIGHT:
+		_Move(wxPoint( 10,   0));
+		break;
+
+	case WXK_UP:
+		_Move(wxPoint(  0, -10));
+		break;
+
+	case WXK_DOWN:
+		_Move(wxPoint(  0,  10));
+		break;
+
+	case WXK_F2:
+		m_pMap->SaveAs_Image();
+		break;
+
+	case 'C':
+		if( event.GetModifiers() == wxMOD_CONTROL )
+		{
+			m_pMap->SaveAs_Image_Clipboard(false);
+		}
+		else if( event.GetModifiers() == wxMOD_ALT )
+		{
+			m_pMap->SaveAs_Image_Clipboard(GetClientSize().x, GetClientSize().y, -1);
+		}
+		break;
+
+	case 'L':
+		if( event.GetModifiers() == wxMOD_CONTROL )
+		{
+			m_pMap->SaveAs_Image_Clipboard(true);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_LDown(wxMouseEvent &event)
+{
+	bool	bCaptureMouse	= true;
+
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule && g_pModule->is_Interactive() )
+		{
+			m_Drag_Mode		= ((CSG_Module_Interactive *)g_pModule->Get_Module())->Get_Drag_Mode();
+			bCaptureMouse	= !g_pModule->Execute(_Get_World(event.GetPosition()), MODULE_INTERACTIVE_LDOWN, GET_KEYS(event));
+		}
+		else if( m_pMap->Find_Layer(Get_Active_Layer()) )
+		{
+			switch(	Get_Active_Layer()->Get_Type() )
+			{
+			default:
+				m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_NONE;
+				break;
+
+			case WKSP_ITEM_Grid:
+				m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_BOX;
+				break;
+
+			case WKSP_ITEM_Shapes:
+				m_Drag_Mode		= ((CWKSP_Shapes *)Get_Active_Layer())->is_Editing()
+								? MODULE_INTERACTIVE_DRAG_NONE
+								: MODULE_INTERACTIVE_DRAG_BOX;
+				break;
+			}
+
+			Get_Active_Layer()->Edit_On_Mouse_Down(_Get_World(event.GetPosition()), _Get_World(1.0), GET_KEYS(event));
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_NONE;
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_BOX;
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_NONE;
+		Set_Mode(MAP_MODE_PAN_DOWN);
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+		m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_NONE;
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( bCaptureMouse )
+	{
+		CaptureMouse();
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_LUp(wxMouseEvent &event)
+{
+	if( HasCapture() )
+	{
+		ReleaseMouse();
+	}
+
+	_Draw_Inverse(m_Mouse_Down, event.GetPosition());
+	m_Drag_Mode	= MODULE_INTERACTIVE_DRAG_NONE;
+
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule )
+		{
+			g_pModule->Execute(_Get_World(event.GetPosition()), MODULE_INTERACTIVE_LUP, GET_KEYS(event));
+		}
+		else if( m_pMap->Find_Layer(Get_Active_Layer()) )
+		{
+			Get_Active_Layer()->Edit_On_Mouse_Up(_Get_World(event.GetPosition()), _Get_World(1.0), GET_KEYS(event)|MODULE_INTERACTIVE_KEY_LEFT);
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		_Distance_Add(event.GetPosition());
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		_Zoom(m_Mouse_Down, event.GetPosition());
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+		Set_Mode(MAP_MODE_PAN);
+		_Move(m_Mouse_Down, event.GetPosition());
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_LDClick(wxMouseEvent &event)
+{
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule )
+		{
+			g_pModule->Execute(_Get_World(event.GetPosition()), MODULE_INTERACTIVE_LDCLICK, GET_KEYS(event));
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_RDown(wxMouseEvent &event)
+{
+	m_Mouse_Down	= m_Mouse_Move	= event.GetPosition();
+
+	_Draw_Inverse(m_Mouse_Down, event.GetPosition());
+	m_Drag_Mode	= MODULE_INTERACTIVE_DRAG_NONE;
+
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule )
+		{
+			g_pModule->Execute(_Get_World(event.GetPosition()), MODULE_INTERACTIVE_RDOWN, GET_KEYS(event));
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		_Distance_Reset();
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_RUp(wxMouseEvent &event)
+{
+	wxMenu	*pMenu	= NULL;
+
+	m_Drag_Mode		= MODULE_INTERACTIVE_DRAG_NONE;
+
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule )
+		{
+			g_pModule->Execute(_Get_World(event.GetPosition()), MODULE_INTERACTIVE_RUP, GET_KEYS(event));
+		}
+		else if( m_pMap->Find_Layer(Get_Active_Layer()) )
+		{
+			if(	!Get_Active_Layer()->Edit_On_Mouse_Up(_Get_World(event.GetPosition()), _Get_World(1.0), GET_KEYS(event)|MODULE_INTERACTIVE_KEY_RIGHT)
+			&&	(pMenu = Get_Active_Layer()->Edit_Get_Menu()) != NULL )
+			{
+				PopupMenu(pMenu, event.GetPosition());
+
+				delete(pMenu);
+			}
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		_Zoom(_Get_World(event.GetPosition()), false);
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_RDClick(wxMouseEvent &event)
+{
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule )
+		{
+			g_pModule->Execute(_Get_World(event.GetPosition()), MODULE_INTERACTIVE_RDCLICK, GET_KEYS(event));
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_Motion(wxMouseEvent &event)
+{
+	if( m_Mode != MAP_MODE_PAN_DOWN )
+	{
+		_Set_StatusBar(_Get_World(event.GetPosition()));
+
+		m_pParent->Ruler_Set_Position(event.GetPosition().x, event.GetPosition().y);
+	}
+
+	switch( m_Mode )
+	{
+	//-----------------------------------------------------
+	case MAP_MODE_SELECT:
+		if( g_pModule )
+		{
+			TSG_Module_Interactive_Mode	iMode
+				= event.LeftIsDown()	? MODULE_INTERACTIVE_MOVE_LDOWN
+				: event.MiddleIsDown()	? MODULE_INTERACTIVE_MOVE_MDOWN
+				: event.RightIsDown()	? MODULE_INTERACTIVE_MOVE_RDOWN
+										: MODULE_INTERACTIVE_MOVE;
+
+			g_pModule->Execute(_Get_World(event.GetPosition()), iMode, GET_KEYS(event));
+		}
+		else if( m_pMap->Find_Layer(Get_Active_Layer()) )
+		{
+			Get_Active_Layer()->Edit_On_Mouse_Move(
+				this, m_pMap->Get_World(_Get_Client()),
+				event.GetPosition(), m_Mouse_Move,
+				GET_KEYS(event)
+			);
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_DISTANCE:
+		if( m_Distance_Pts.Get_Count() > 0 )
+		{
+			int			n	= m_Distance_Pts.Get_Count();
+			wxClientDC	dc(this);
+			wxPoint		Last(_Get_Client(m_Distance_Pts[n - 1]));
+			dc.SetLogicalFunction(wxINVERT);
+			dc.DrawLine(Last.x, Last.y, m_Mouse_Move       .x, m_Mouse_Move       .y);
+			dc.DrawLine(Last.x, Last.y, event.GetPosition().x, event.GetPosition().y);
+			m_Distance_Move	= SG_Get_Distance(m_Distance_Pts[n - 1], _Get_World(event.GetPosition()));
+		}
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_ZOOM:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN:
+		break;
+
+	//-----------------------------------------------------
+	case MAP_MODE_PAN_DOWN:
+	//	_Move(m_Mouse_Down, event.GetPosition());
+		_Pan(m_Mouse_Down, event.GetPosition());
+		break;
+	}
+
+	//-----------------------------------------------------
+	_Draw_Inverse(m_Mouse_Down, m_Mouse_Move, event.GetPosition());
+
+	//-----------------------------------------------------
+	m_Mouse_Move	= event.GetPosition();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Map_Control::On_Mouse_Wheel(wxMouseEvent &event)
+{
+	if( event.GetWheelRotation() < 0 )
+	{
+		_Zoom(_Get_World(event.GetPosition()), false);
+	}
+	else if( event.GetWheelRotation() > 0 )
+	{
+		_Zoom(_Get_World(event.GetPosition()), true);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_map_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,178 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  VIEW_Map_Control.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+#include <wx/bitmap.h>
+
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	MAP_MODE_NONE	= 0,
+	MAP_MODE_SELECT,
+	MAP_MODE_DISTANCE,
+	MAP_MODE_ZOOM,
+	MAP_MODE_PAN,
+	MAP_MODE_PAN_DOWN
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Map_Control : public wxPanel
+{
+public:
+	CVIEW_Map_Control(class CVIEW_Map *pParent, class CWKSP_Map *pMap);
+	virtual ~CVIEW_Map_Control(void);
+
+	void						On_Paint			(wxPaintEvent &event);
+	void						On_Size				(wxSizeEvent  &event);
+	void						On_Key_Down			(wxKeyEvent   &event);
+
+	void						On_Mouse_Wheel		(wxMouseEvent &event);
+	void						On_Mouse_Motion		(wxMouseEvent &event);
+	void						On_Mouse_LDown		(wxMouseEvent &event);
+	void						On_Mouse_LUp		(wxMouseEvent &event);
+	void						On_Mouse_LDClick	(wxMouseEvent &event);
+	void						On_Mouse_RDown		(wxMouseEvent &event);
+	void						On_Mouse_RUp		(wxMouseEvent &event);
+	void						On_Mouse_RDClick	(wxMouseEvent &event);
+
+	bool						Set_Mode			(int Mode);
+	int							Get_Mode			(void)	{	return( m_Mode );	}
+
+	void						Refresh_Map			(void);
+
+
+private:
+
+	int							m_Mode, m_Drag_Mode;
+
+	double						m_Distance, m_Distance_Move;
+
+	CSG_Points					m_Distance_Pts;
+
+	wxPoint						m_Mouse_Down, m_Mouse_Move;
+
+	wxBitmap					m_Bitmap;
+
+	class CVIEW_Map				*m_pParent;
+
+	class CWKSP_Map				*m_pMap;
+
+
+	void						_Set_StatusBar		(CSG_Point ptWorld);
+
+	wxRect						_Get_Client			(void);
+	wxPoint						_Get_Client			(TSG_Point Point);
+	CSG_Point					_Get_World			(wxPoint ptClient);
+	double						_Get_World			(double xClient);
+
+	void						_Draw_Inverse		(wxPoint ptA, wxPoint ptB);
+	void						_Draw_Inverse		(wxPoint ptA, wxPoint ptB_Old, wxPoint ptB_New);
+
+	bool						_Zoom				(wxPoint  A, wxPoint B);
+	bool						_Zoom				(CSG_Point ptCenter, bool bZoomIn);
+	bool						_Pan				(wxPoint  A, wxPoint B);
+	bool						_Move				(wxPoint &A, wxPoint B);
+	bool						_Move				(wxPoint ptMove);
+
+	void						_Distance_Reset		(void);
+	void						_Distance_Add		(wxPoint Point);
+	void						_Distance_Draw		(wxDC &dc);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Map_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,319 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    VIEW_Ruler.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <math.h>
+
+#include <wx/wx.h>
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "view_layout.h"
+#include "view_ruler.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Ruler, wxPanel)
+	EVT_PAINT			(CVIEW_Ruler::On_Paint)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Ruler::CVIEW_Ruler(wxWindow *pParent, int Style)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_bHorizontal	= (Style & RULER_VERTICAL)     == false;
+	m_bAscendent	= (Style & RULER_DESCENDING)   == false;
+	m_bTickAtTop	= (Style & RULER_TICKATBOTTOM) == false;
+	m_Mode			= (Style & RULER_MODE_SCALE) ? 1 : ((Style & RULER_MODE_CORNERS) ? 2 : 0);
+	m_Edge			= (Style & RULER_EDGE_BLACK) ? 1 : ((Style & RULER_EDGE_SUNKEN)  ? 2 : 0);
+
+	m_Position		= -1;
+	m_Min			= 0;
+	m_Max			= 1;
+	m_Min_Core		= 1;
+	m_Max_Core		= 0;
+}
+
+//---------------------------------------------------------
+CVIEW_Ruler::~CVIEW_Ruler(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Ruler::On_Paint(wxPaintEvent &event)
+{
+	int			Width, Height;
+	wxRect		r(wxPoint(0, 0), GetClientSize());
+	wxPaintDC	dc(this);
+
+	//-----------------------------------------------------
+	Width	= m_bHorizontal ? r.GetWidth() : r.GetHeight();
+	Height	= m_bHorizontal ? r.GetHeight() : r.GetWidth();
+
+	_Draw_Core(dc, Width, Height);
+
+	//-----------------------------------------------------
+	switch( m_Mode )
+	{
+	case 0:	default:
+		Draw_Scale(dc, r, m_Min, m_Max        , m_bHorizontal, m_bAscendent, m_bTickAtTop);
+		break;
+
+	case 1:
+		Draw_Scale(dc, r, 0.0  , m_Max - m_Min, m_bHorizontal, m_bAscendent, m_bTickAtTop);
+		break;
+
+	case 2:
+		_Draw_Corners(dc, Width, Height);
+		break;
+	}
+
+	//-----------------------------------------------------
+	switch( m_Edge )
+	{
+	case 0:	default:
+		break;
+
+	case 1:
+		Draw_Edge(dc, EDGE_STYLE_SIMPLE, 0, 0, GetClientSize().x - 1, GetClientSize().y - 1);
+		break;
+
+	case 2:
+		Draw_Edge(dc, EDGE_STYLE_SUNKEN, 0, 0, GetClientSize().x - 1, GetClientSize().y - 1);
+		break;
+	}
+
+	//-----------------------------------------------------
+	_Draw_Position(dc, Width, Height, m_Position);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define TEXTSPACE	4
+
+//---------------------------------------------------------
+void CVIEW_Ruler::_Draw_Corners(wxDC &dc, int Width, int Height)
+{
+	wxFont	Font;
+
+	Font.Create((int)(0.65 * (double)Height), wxSWISS, wxNORMAL, wxNORMAL);
+	dc.SetFont(Font);
+
+	if( m_bHorizontal )
+	{
+		Draw_Text(dc, TEXTALIGN_BOTTOMLEFT ,         TEXTSPACE, Height, wxString::Format(wxT("%f"), m_Min));
+		Draw_Text(dc, TEXTALIGN_BOTTOMRIGHT, Width - TEXTSPACE, Height, wxString::Format(wxT("%f"), m_Max));
+	}
+	else
+	{
+		Draw_Text(dc, TEXTALIGN_TOPLEFT , 0, Width - TEXTSPACE, 90.0, wxString::Format(wxT("%f"), m_Min));
+		Draw_Text(dc, TEXTALIGN_TOPRIGHT, 0,         TEXTSPACE, 90.0, wxString::Format(wxT("%f"), m_Max));
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Ruler::_Draw_Core(wxDC &dc, int Width, int Height)
+{
+	double		x;
+
+	if( m_Min < m_Max && m_Min_Core < m_Max_Core )
+	{
+		if( m_Min_Core > m_Min )
+		{
+			x	= (m_Min_Core - m_Min) * (double)Width / (m_Max - m_Min);
+
+			if( m_bHorizontal )
+			{
+				Draw_FillRect(dc, SYS_Get_Color(wxSYS_COLOUR_3DFACE), 0, 0, (int)x, Height);
+			}
+			else
+			{
+				Draw_FillRect(dc, SYS_Get_Color(wxSYS_COLOUR_3DFACE), 0, 0, Height, (int)x);
+			}
+		}
+
+		if( m_Max_Core < m_Max )
+		{
+			x	= (m_Max_Core - m_Min) * (double)Width / (m_Max - m_Min);
+
+			if( m_bHorizontal )
+			{
+				Draw_FillRect(dc, SYS_Get_Color(wxSYS_COLOUR_3DFACE), (int)x, 0, Width, Height);
+			}
+			else
+			{
+				Draw_FillRect(dc, SYS_Get_Color(wxSYS_COLOUR_3DFACE), 0, (int)x, Height, Width);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Ruler::Set_Range(double Min, double Max)
+{
+	if( m_Min != Min || m_Max != Max )
+	{
+		m_Min	= Min;
+		m_Max	= Max;
+
+		Refresh();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Ruler::Set_Range_Core(double Min, double Max)
+{
+	if( m_Min_Core != Min || m_Max_Core != Max )
+	{
+		m_Min_Core	= Min;
+		m_Max_Core	= Max;
+
+		Refresh();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Ruler::Set_Position(int Position)
+{
+	int			Width, Height;
+	wxClientDC	dc(this);
+
+	Width		= m_bHorizontal ? GetClientSize().x : GetClientSize().y;
+	Height		= m_bHorizontal ? GetClientSize().y : GetClientSize().x;
+
+	_Draw_Position(dc, Width, Height, m_Position);
+
+	m_Position	= Position;
+
+	_Draw_Position(dc, Width, Height, m_Position);
+}
+
+//---------------------------------------------------------
+void CVIEW_Ruler::_Draw_Position(wxDC &dc, int Width, int Height, int Position)
+{
+	if( m_Position >= 0 && m_Position < Width )
+	{
+		int		lf	= dc.GetLogicalFunction();
+
+		dc.SetLogicalFunction(wxINVERT);
+
+		if( m_bHorizontal )
+		{
+			dc.DrawLine(Position, 0, Position, Height);
+		}
+		else
+		{
+			dc.DrawLine(0, Position, Height, Position);
+		}
+
+		dc.SetLogicalFunction(lf);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_ruler.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,138 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    VIEW_Ruler.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Ruler_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Ruler_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/panel.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define RULER_HORIZONTAL		0x00
+#define RULER_VERTICAL			0x01
+#define RULER_EDGE_BLACK		0x02
+#define RULER_EDGE_SUNKEN		0x04
+#define RULER_DESCENDING		0x08
+#define RULER_MODE_NORMAL		0x10
+#define RULER_MODE_CORNERS		0x20
+#define RULER_MODE_SCALE		0x40
+#define RULER_TICKATBOTTOM		0x80
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Ruler : public wxPanel
+{
+public:
+	CVIEW_Ruler(wxWindow *pParent, int Style = RULER_HORIZONTAL);
+	virtual ~CVIEW_Ruler(void);
+
+	void						On_Paint			(wxPaintEvent &event);
+
+	void						Set_Range			(double Min, double Max);
+	void						Set_Range_Core		(double Min, double Max);
+	void						Set_Position		(int Position);
+
+
+private:
+
+	bool						m_bHorizontal, m_bAscendent, m_bTickAtTop;
+
+	int							m_Mode, m_Edge, m_Position;
+
+	double						m_Min, m_Max, m_Min_Core, m_Max_Core;
+
+	void						_Draw_Corners		(wxDC &dc, int Width, int Height);
+	void						_Draw_Core			(wxDC &dc, int Width, int Height);
+	void						_Draw_Position		(wxDC &dc, int Width, int Height, int Position);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Ruler_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,894 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_ScatterPlot.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp.h"
+#include "wksp_data_manager.h"
+
+#include "wksp_grid.h"
+#include "wksp_shapes.h"
+
+#include "view_scatterplot.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Add_ScatterPlot(CSG_Grid *pGrid)
+{
+	CSG_Parameter	*pNode;
+	CSG_Grid		*pGrid_Y;
+	CSG_Shapes		*pShapes;
+
+	//-----------------------------------------------------
+	CSG_Parameters	Parameters(NULL, wxString::Format(wxT("%s: %s"), LNG("[CAP] Scatterplot"), pGrid->Get_Name()), LNG(""), NULL, true);
+
+	Parameters.Add_Grid(
+		NULL	, "GRID"	, LNG("[CAP] Grid")		, LNG(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	pNode	= Parameters.Add_Shapes(
+		NULL	, "SHAPES"	, LNG("[CAP] Shapes")	, LNG(""),
+		PARAMETER_INPUT_OPTIONAL
+	);
+
+	Parameters.Add_Table_Field(
+		pNode	, "FIELD"	, LNG("[CAP] Attribute"), LNG("")
+	);
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&Parameters) )
+	{
+		if( (pGrid_Y = Parameters("GRID")->asGrid()) != NULL )
+		{
+			new CVIEW_ScatterPlot(pGrid, pGrid_Y);
+		}
+		else if( (pShapes = Parameters("SHAPES")->asShapes()) != NULL )
+		{
+			new CVIEW_ScatterPlot(pGrid, pShapes, Parameters("FIELD")->asInt());
+		}
+	}
+}
+
+//---------------------------------------------------------
+void		Add_ScatterPlot(CSG_Table *pTable)
+{
+	int			i;
+	wxString	sChoices;
+
+	CSG_Parameters	Parameters(NULL, wxString::Format(wxT("%s: %s"), LNG("[CAP] Scatterplot"), pTable->Get_Name()), LNG(""));
+
+	for(i=0; i<pTable->Get_Field_Count(); i++)
+	{
+		sChoices.Append(wxString::Format(wxT("%s|"), pTable->Get_Field_Name(i)));
+	}
+
+	Parameters.Add_Choice(
+		NULL, "FIELD_A", wxT("X"), wxT(""), sChoices
+	);
+
+	Parameters.Add_Choice(
+		NULL, "FIELD_B", wxT("Y"), wxT(""), sChoices
+	);
+
+	if( DLG_Parameters(&Parameters) )
+	{
+		new CVIEW_ScatterPlot(pTable, Parameters("FIELD_A")->asInt(), Parameters("FIELD_B")->asInt());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_ScatterPlot, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_ScatterPlot, CVIEW_Base)
+	EVT_PAINT			(CVIEW_ScatterPlot::On_Paint)
+	EVT_SIZE			(CVIEW_ScatterPlot::On_Size)
+
+	EVT_MENU			(ID_CMD_SCATTERPLOT_PARAMETERS	, CVIEW_ScatterPlot::On_Parameters)
+	EVT_MENU			(ID_CMD_SCATTERPLOT_UPDATE		, CVIEW_ScatterPlot::On_Update)
+	EVT_MENU			(ID_CMD_HISTOGRAM_AS_TABLE		, CVIEW_ScatterPlot::On_AsTable)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_ScatterPlot::CVIEW_ScatterPlot(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y)
+	: CVIEW_Base(ID_VIEW_SCATTERPLOT, LNG("[CAP] Scatterplot"), ID_IMG_WND_SCATTERPLOT, CVIEW_ScatterPlot::_Create_Menu(), LNG("[CAP] Scatterplot"))
+{
+	_On_Construction();
+
+	m_Method	= 0;
+	m_pGrid_X	= pGrid_X;
+	m_pGrid_Y	= pGrid_Y;
+
+	_Initialize_Grids(pGrid_X, pGrid_Y);
+}
+
+//---------------------------------------------------------
+CVIEW_ScatterPlot::CVIEW_ScatterPlot(CSG_Grid *pGrid_X, CSG_Shapes *pShapes_Y, int Field)
+	: CVIEW_Base(ID_VIEW_SCATTERPLOT, LNG("[CAP] Scatterplot"), ID_IMG_WND_SCATTERPLOT, CVIEW_ScatterPlot::_Create_Menu(), LNG("[CAP] Scatterplot"))
+{
+	_On_Construction();
+
+	m_Method	= 1;
+	m_pGrid_X	= pGrid_X;
+	m_pShapes	= pShapes_Y;
+	m_xField	= Field;
+
+	_Initialize_Shapes(pGrid_X, pShapes_Y, Field);
+}
+
+//---------------------------------------------------------
+CVIEW_ScatterPlot::CVIEW_ScatterPlot(CSG_Table *pTable, int Field_X, int Field_Y)
+	: CVIEW_Base(ID_VIEW_SCATTERPLOT, LNG("[CAP] Scatterplot"), ID_IMG_WND_SCATTERPLOT, CVIEW_ScatterPlot::_Create_Menu(), LNG("[CAP] Scatterplot"))
+{
+	_On_Construction();
+
+	m_Method	= 2;
+	m_pTable	= pTable;
+	m_xField	= Field_X;
+	m_yField	= Field_Y;
+
+	_Initialize_Table(pTable, Field_X, Field_Y);
+}
+
+//---------------------------------------------------------
+CVIEW_ScatterPlot::~CVIEW_ScatterPlot(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_ScatterPlot::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu();
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SCATTERPLOT_PARAMETERS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SCATTERPLOT_UPDATE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_HISTOGRAM_AS_TABLE);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_ScatterPlot::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_SCATTERPLOT);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_SCATTERPLOT_PARAMETERS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_SCATTERPLOT_UPDATE);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_HISTOGRAM_AS_TABLE);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Scatterplot"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define CHECK_DATA(d)	if( d != NULL && !g_pData->Exists(d) )	d	= NULL;
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::Update_ScatterPlot(void)
+{
+	CHECK_DATA(m_pGrid_X);
+	CHECK_DATA(m_pGrid_Y);
+	CHECK_DATA(m_pShapes);
+	CHECK_DATA(m_pTable);
+
+	switch( m_Method )
+	{
+	case 0:	_Initialize_Grids	(m_pGrid_X, m_pGrid_Y);				break;
+	case 1:	_Initialize_Shapes	(m_pGrid_X, m_pShapes, m_xField);	break;
+	case 2:	_Initialize_Table	(m_pTable, m_xField, m_yField);		break;
+	}
+
+	Refresh();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::_On_Construction(void)
+{
+	m_Method	= -1;
+	m_pGrid_X	= NULL;
+	m_pGrid_Y	= NULL;
+	m_pShapes	= NULL;
+	m_pTable	= NULL;
+	m_xField	= 0;
+	m_yField	= 0;
+
+	SYS_Set_Color_BG_Window(this);
+
+	m_Parameters.Add_Choice(
+		NULL, "TYPE"		, LNG("[CAP] Regression Formula"),
+		LNG(""),
+		wxT("Y = a + b * X|")
+		wxT("Y = a + b / X|")
+		wxT("Y = a / (b - X)|")
+		wxT("Y = a * X^b|")
+		wxT("Y = a e^(b * X)|")
+		wxT("Y = a + b * ln(X)|")
+	);
+
+	m_Parameters.Add_String(
+		NULL, "INFO"		, LNG("[CAP] Regression Details"),
+		LNG(""),
+		LNG(""), true
+	);
+
+	m_Parameters.Add_Font(
+		NULL, "FONT"		, LNG("[CAP] Font"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		NULL, "REGRESSION"	, LNG("[CAP] Show Regression Curve"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Choice(
+		NULL, "METHOD"		, LNG("[CAP] Display Type"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|"),
+			LNG("[CAP] Circles"),
+			LNG("[CAP] Points")
+		)
+	);
+
+	m_Parameters.Add_Value(
+		NULL, "RESOLUTION"	, LNG("[CAP] Display Resolution"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 1, 1, true
+	);
+
+	m_Parameters.Add_Colors(
+		NULL, "COLORS"		, LNG("[CAP] Colors"),
+		LNG("")
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::On_Parameters(wxCommandEvent &event)
+{
+	if( DLG_Parameters(&m_Parameters) )
+	{
+		if( m_Parameters("TYPE")->asInt() != m_Regression.Get_Type() )
+		{
+			m_Regression.Calculate((TSG_Regression_Type)m_Parameters("TYPE")->asInt());
+		}
+
+		Refresh();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::On_Update(wxCommandEvent &event)
+{
+	Update_ScatterPlot();
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::On_AsTable(wxCommandEvent &event)
+{
+	if( m_Regression.Get_Count() > 1 )
+	{
+		CSG_Table	*pTable	= new CSG_Table;
+
+		pTable->Set_Name(wxString::Format(wxT("%s: [%s]-[%s]"), LNG("[CAP] Scatterplot"), m_sX.c_str(), m_sY.c_str()));
+
+		pTable->Add_Field(SG_T("ID"), SG_DATATYPE_Int);
+		pTable->Add_Field(m_sX		, SG_DATATYPE_Double);
+		pTable->Add_Field(m_sY		, SG_DATATYPE_Double);
+
+		for(int i=0; i<m_Regression.Get_Count() && PROGRESSBAR_Set_Position(i, m_Regression.Get_Count()); i++)
+		{
+			CSG_Table_Record	*pRecord	= pTable->Add_Record();
+
+			pRecord->Set_Value(0, i + 1);
+			pRecord->Set_Value(1, m_Regression.Get_xValue(i));
+			pRecord->Set_Value(2, m_Regression.Get_yValue(i));
+		}
+
+		PROGRESSBAR_Set_Position(0);
+
+		g_pData->Add(pTable);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::On_Size(wxSizeEvent &event)
+{
+	Refresh();
+
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::On_Paint(wxPaintEvent &event)
+{
+	wxPaintDC	dc(this);
+	wxRect		r(wxPoint(0, 0), GetClientSize());
+
+	Draw_Edge(dc, EDGE_STYLE_SUNKEN, r);
+
+	Draw(dc, r);
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::Draw(wxDC &dc, wxRect r)
+{
+	double	dx, dy;
+
+	r	= _Draw_Get_rDiagram(r);
+
+	dc.SetFont				(*m_Parameters("FONT")->asFont());
+	dc.SetTextForeground	( m_Parameters("FONT")->asColor());
+
+	if( m_Regression.Get_Count() > 1 )
+	{
+		dx	= (r.GetWidth()  - 1.0) / (m_Regression.Get_xMax() - m_Regression.Get_xMin());
+		dy	= (r.GetHeight() - 1.0) / (m_Regression.Get_yMax() - m_Regression.Get_yMin());
+
+		//-------------------------------------------------
+		if( m_Parameters("METHOD")->asInt() == 1 )
+		{
+			_Draw_Image (dc, r, dx, dy);
+		}
+		else
+		{
+			_Draw_Points(dc, r, dx, dy);
+		}
+
+		//-------------------------------------------------
+		if( m_Parameters("REGRESSION")->asBool() )
+		{
+			_Draw_Regression(dc, r, dx, dy);
+		}
+
+		//-------------------------------------------------
+		_Draw_Frame(dc, r);
+	}
+	else
+	{
+		Draw_Text(dc, TEXTALIGN_CENTER, r.GetLeft() + r.GetWidth() / 2, r.GetTop() + r.GetHeight() / 2, LNG("[ERR] Invalid data!"));
+	}
+}
+
+//---------------------------------------------------------
+wxRect CVIEW_ScatterPlot::_Draw_Get_rDiagram(wxRect r)
+{
+	return(	wxRect(
+		wxPoint(r.GetLeft()  + 70, r.GetTop()    + 20),
+		wxPoint(r.GetRight() - 20, r.GetBottom() - 50)
+	));
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::_Draw_Regression(wxDC &dc, wxRect r, double dx, double dy)
+{
+	int			ix, ay, by;
+	double		a, b, x, y, ex;
+	wxString	s;
+	wxPen		Pen, oldPen	= dc.GetPen();
+	wxColour	Col, oldCol	= dc.GetTextForeground();
+
+	Col	= wxColour(255, 0, 0);
+	Pen.SetColour(Col);
+	dc.SetPen(Pen);
+	dc.SetTextForeground(Col);
+
+	//-----------------------------------------------------
+	a	= m_Regression.Get_Constant();
+	b	= m_Regression.Get_Coefficient();
+
+	//-----------------------------------------------------
+	if( m_Regression.Get_Type() == REGRESSION_Linear )
+	{
+		dc.DrawCircle(	// Mittelwert...
+			r.GetLeft()   + (int)(dx * (m_Regression.Get_xMean() - m_Regression.Get_xMin())),
+			r.GetBottom() - (int)(dy * (m_Regression.Get_yMean() - m_Regression.Get_yMin())),
+			2
+		);
+
+		dc.DrawLine(	// Regressions- u. Std.Abw.-Geraden...
+			r.GetLeft() , r.GetBottom()	- (int)(dy * ((a + b * m_Regression.Get_xMin())  - m_Regression.Get_yMin())),
+			r.GetRight(), r.GetBottom()	- (int)(dy * ((a + b * m_Regression.Get_xMax())  - m_Regression.Get_yMin()))
+		);
+	}
+	else
+	{
+		ex	= (m_Regression.Get_xMax() - m_Regression.Get_xMin()) / (double)r.GetWidth();
+		x	= m_Regression.Get_xMin();
+		by	= 0;
+
+		for(ix=0; ix<r.GetWidth(); ix++, x+=ex)
+		{
+			switch( m_Regression.Get_Type() )
+			{
+			default:				y	= 0.0;				break;
+			case REGRESSION_Rez_X:	y	= a + b / x;		break;
+			case REGRESSION_Rez_Y:	y	= a / (b - x);		break;
+			case REGRESSION_Pow:	y	= a * pow(x, b);	break;
+			case REGRESSION_Exp:	y	= a * exp(b * x);	break;
+			case REGRESSION_Log:	y	= a + b * log(x);	break;
+			}
+
+			ay	= by;
+			by	= r.GetBottom() - (int)(dy * (y - m_Regression.Get_yMin()));
+
+			if( ix > 0 )
+			{
+				dc.DrawLine(r.GetLeft() + ix - 1, ay, r.GetLeft() + ix, by);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	switch( m_Regression.Get_Type() )
+	{
+	case REGRESSION_Linear:	s	= wxT("Y = %f%+f*X");		break;
+	case REGRESSION_Rez_X:	s	= wxT("Y = %f%+f/X");		break;
+	case REGRESSION_Rez_Y:	s	= wxT("Y = %f/(%f-X)");		break;
+	case REGRESSION_Pow:	s	= wxT("Y = %f*X^%f");		break;
+	case REGRESSION_Exp:	s	= wxT("Y = %f e^(%f*X)");	break;
+	case REGRESSION_Log:	s	= wxT("Y = %f%+f*ln(X)");	break;
+	}
+
+	Draw_Text(dc, TEXTALIGN_TOPLEFT, r.GetLeft(), r.GetTop(),
+		wxString::Format(s, m_Regression.Get_Constant(), m_Regression.Get_Coefficient())
+	);
+
+	Draw_Text(dc, TEXTALIGN_BOTTOMRIGHT, r.GetRight(), r.GetBottom(),
+		wxString::Format(wxT("R2: %f%%"), 100.0 * m_Regression.Get_R2())	// Coefficient of Determination...
+	);
+
+	dc.SetPen(oldPen);
+	dc.SetTextForeground(oldCol);
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::_Draw_Image(wxDC &dc, wxRect r, double dx, double dy)
+{
+	int			x, y, i, ax, ay, bx, by, Resolution;
+	double		zMax;
+	CSG_Grid	Count;
+	CSG_Colors	*pColors	= m_Parameters("COLORS")->asColors();
+	wxPen		Pen, oldPen(dc.GetPen());
+
+	//-----------------------------------------------------
+	Resolution	= m_Parameters("RESOLUTION")->asInt();
+
+	Count.Create(SG_DATATYPE_Word, 1 + (r.GetWidth() / Resolution), 1 + (r.GetHeight() / Resolution));
+
+	dx	/= Resolution;
+	dy	/= Resolution;
+
+	for(i=0, zMax=0; i<m_Regression.Get_Count(); i++)
+	{
+		x	= (int)(dx * (m_Regression.Get_xValue(i) - m_Regression.Get_xMin()));
+		y	= (int)(dy * (m_Regression.Get_yValue(i) - m_Regression.Get_yMin()));
+		Count.Add_Value(x, y, 1);
+		if( Count(x, y) > zMax )
+			zMax	= Count(x, y);
+	}
+
+	//-----------------------------------------------------
+	if( Resolution <= 1 )
+	{
+		for(y=0, ay=r.GetBottom(); y<Count.Get_NY(); y++, ay--)
+		{
+			for(x=0, ax=r.GetLeft(); x<Count.Get_NX(); x++, ax++)
+			{
+				if( (i = Count.asInt(x, y)) > 0 )
+				{
+					i	= (int)((pColors->Get_Count() - 1) * i / zMax);
+					Pen.SetColour(Get_Color_asWX(pColors->Get_Color(i)));
+					dc.SetPen(Pen);
+					dc.DrawPoint(ax, ay);
+				}
+			}
+		}
+	}
+	else
+	{
+		dx	= r.GetWidth()  / (double)(Count.Get_NX() - 1.0);
+		dy	= r.GetHeight() / (double)(Count.Get_NY() - 1.0);
+
+		for(y=0, by=r.GetBottom(); y<Count.Get_NY(); y++)
+		{
+			ay	= by;
+			by	= r.GetBottom() - (int)(y * dy);
+
+			for(x=0, bx=r.GetLeft(); x<Count.Get_NX(); x++)
+			{
+				ax	= bx;
+				bx	= r.GetLeft() + (int)(x * dx);
+
+				if( (i = Count.asInt(x, y)) > 0 )
+				{
+					i	= (int)((pColors->Get_Count() - 1) * i / zMax);
+					Draw_FillRect(dc, Get_Color_asWX(pColors->Get_Color(i)), ax, ay, bx, by);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	dc.SetPen(oldPen);
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::_Draw_Points(wxDC &dc, wxRect r, double dx, double dy)
+{
+	for(int i=0; i<m_Regression.Get_Count(); i++)
+	{
+		dc.DrawCircle(
+			r.GetLeft()   + (int)(dx * (m_Regression.Get_xValue(i) - m_Regression.Get_xMin())),
+			r.GetBottom() - (int)(dy * (m_Regression.Get_yValue(i) - m_Regression.Get_yMin())),
+			2
+		);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_ScatterPlot::_Draw_Frame(wxDC &dc, wxRect r)
+{
+	const int	dyFont		= 12,
+				Precision	= 3;
+
+	int		iPixel, iStep, nSteps;
+	double	dPixel, dz;
+	wxFont	Font;
+
+	//-----------------------------------------------------
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);
+
+	Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, r.GetRight(), r.GetTop() + r.GetHeight() / 2, -90.0, m_sY);
+	Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, r.GetLeft() + r.GetWidth() / 2, r.GetTop(), m_sX);
+
+	Font	= dc.GetFont();
+	Font.SetPointSize((int)(0.7 * dyFont));
+	dc.SetFont(Font);
+
+	//-------------------------------------------------
+	dPixel	= dyFont;
+	nSteps	= (int)(r.GetHeight() / dPixel);
+	dz		= (m_Regression.Get_yMax() - m_Regression.Get_yMin()) * dPixel / (double)r.GetHeight();
+
+	for(iStep=0; iStep<=nSteps; iStep++)
+	{
+		iPixel	= r.GetBottom()	- (int)(dPixel * iStep);
+		dc.DrawLine(r.GetLeft(), iPixel, r.GetLeft() - 5, iPixel);
+		Draw_Text(dc, TEXTALIGN_CENTERRIGHT, r.GetLeft() - 7, iPixel,
+			wxString::Format(wxT("%.*f"), Precision, m_Regression.Get_yMin() + iStep * dz)
+		);
+	}
+
+	//-------------------------------------------------
+	dPixel	= dyFont + 5;
+	nSteps	= (int)(r.GetWidth() / dPixel);
+	dz		= (m_Regression.Get_xMax() - m_Regression.Get_xMin()) * dPixel / (double)r.GetWidth();
+
+	for(iStep=0; iStep<=nSteps; iStep++)
+	{
+		iPixel	= r.GetLeft() + (int)(dPixel * iStep);
+		dc.DrawLine(iPixel, r.GetBottom(), iPixel, r.GetBottom() + 5);
+		Draw_Text(dc, TEXTALIGN_CENTERRIGHT, iPixel, r.GetBottom() + 7, 45.0,
+			wxString::Format(wxT("%.*f"), Precision, m_Regression.Get_xMin() + iStep * dz)
+		);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_ScatterPlot::_Initialize(void)
+{
+	bool	bResult	= m_Regression.Calculate();
+
+	PROCESS_Set_Okay(true);
+
+	m_Parameters("METHOD")	->Set_Value(m_Regression.Get_Count() > 1000 ? 1 : 0);
+	m_Parameters("INFO")	->Set_Value((void *)m_Regression.asString());
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_ScatterPlot::_Initialize_Grids(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y)
+{
+	if( pGrid_X && pGrid_Y )
+	{
+		m_Regression.Destroy();
+
+		m_sTitle.Printf(wxT("%s: [%s/%s]"), LNG("[CAP] Scatterplot"), pGrid_X->Get_Name(), pGrid_Y->Get_Name());
+
+		m_sX.Printf(wxT("%s"), pGrid_X->Get_Name());
+		m_sY.Printf(wxT("%s"), pGrid_Y->Get_Name());
+
+		return( pGrid_X->Get_System() == pGrid_Y->Get_System()
+			? _Initialize_Grid_Equal  (pGrid_X, pGrid_Y)
+			: _Initialize_Grid_Unequal(pGrid_X, pGrid_Y)
+		);
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_ScatterPlot::_Initialize_Grid_Equal(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y)
+{
+	int		x, y;
+	double	dz_A	= pGrid_X->Get_ZFactor(),
+			dz_B	= pGrid_Y->Get_ZFactor();
+
+	for(y=0; y<pGrid_X->Get_NY() && PROGRESSBAR_Set_Position(y, pGrid_X->Get_NY()); y++)
+	{
+		for(x=0; x<pGrid_X->Get_NX(); x++)
+		{
+			if( !pGrid_X->is_NoData(x, y) && !pGrid_Y->is_NoData(x, y) )
+			{
+				m_Regression.Add_Values(
+					dz_A * pGrid_X->asDouble(x, y),
+					dz_B * pGrid_Y->asDouble(x, y)
+				);
+			}
+		}
+	}
+
+	return( _Initialize() );
+}
+
+//---------------------------------------------------------
+bool CVIEW_ScatterPlot::_Initialize_Grid_Unequal(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y)
+{
+	int		x, y, Interpolation	= GRID_INTERPOLATION_BSpline;
+	double	z, dz_A	= pGrid_X->Get_ZFactor();
+
+	for(y=0; y<pGrid_X->Get_NY() && PROGRESSBAR_Set_Position(y, pGrid_X->Get_NY()); y++)
+	{
+		for(x=0; x<pGrid_X->Get_NX(); x++)
+		{
+			if(	pGrid_X->is_NoData(x, y) == false
+			&&	pGrid_Y->Get_Value(pGrid_X->Get_System().Get_Grid_to_World(x, y), z, Interpolation, true) )
+			{
+				m_Regression.Add_Values(pGrid_X ->asDouble(x, y) * dz_A, z);
+			}
+		}
+	}
+
+	return( _Initialize() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_ScatterPlot::_Initialize_Shapes(CSG_Grid *pGrid_X, CSG_Shapes *pShapes_Y, int Field)
+{
+	if( pGrid_X && pShapes_Y && Field >= 0 && Field < pShapes_Y->Get_Field_Count() )
+	{
+		int		iShape, iPart, iPoint;
+		double	z;
+		CSG_Shape	*pShape;
+
+		m_Regression.Destroy();
+
+		m_sTitle.Printf(wxT("%s: [%s/%s]"), LNG("[CAP] Scatterplot"), pGrid_X->Get_Name(), pShapes_Y->Get_Name());
+
+		m_sX.Printf(wxT("%s"), pGrid_X->Get_Name());
+		m_sY.Printf(wxT("%s"), pShapes_Y->Get_Field_Name(Field));
+
+		for(iShape=0; iShape<pShapes_Y->Get_Count() && PROGRESSBAR_Set_Position(iShape, pShapes_Y->Get_Count()); iShape++)
+		{
+			pShape	= pShapes_Y->Get_Shape(iShape);
+
+			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+			{
+				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					if( pGrid_X->Get_Value(pShape->Get_Point(iPoint, iPart), z, GRID_INTERPOLATION_BSpline, true) )
+					{
+						m_Regression.Add_Values(z, pShape->asDouble(Field));
+					}
+				}
+			}
+		}
+
+		return( _Initialize() );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_ScatterPlot::_Initialize_Table(CSG_Table *pTable, int Field_X, int Field_Y)
+{
+	if( pTable
+	&&	Field_X >= 0 && Field_X < pTable->Get_Field_Count()
+	&&	Field_Y >= 0 && Field_Y < pTable->Get_Field_Count() )
+	{
+		int				iRecord;
+		CSG_Table_Record	*pRecord;
+
+		m_Regression.Destroy();
+
+		m_sTitle.Printf(wxT("%s: [%s]"), LNG("[CAP] Scatterplot"), pTable->Get_Name());
+
+		m_sX.Printf(wxT("%s"), pTable->Get_Field_Name(Field_X));
+		m_sY.Printf(wxT("%s"), pTable->Get_Field_Name(Field_Y));
+
+		for(iRecord=0; iRecord<pTable->Get_Record_Count() && PROGRESSBAR_Set_Position(iRecord, pTable->Get_Record_Count()); iRecord++)
+		{
+			pRecord	= pTable->Get_Record(iRecord);
+
+			m_Regression.Add_Values(
+				pRecord->asDouble(Field_X),
+				pRecord->asDouble(Field_Y)
+			);
+		}
+
+		return( _Initialize() );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_scatterplot.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,169 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  VIEW_ScatterPlot.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_ScatterPlot_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_ScatterPlot_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void		Add_ScatterPlot(CSG_Grid *pGrid);
+void		Add_ScatterPlot(CSG_Table *pTable);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_ScatterPlot : public CVIEW_Base
+{
+public:
+	CVIEW_ScatterPlot(CSG_Grid *pGrid_A, CSG_Grid *pGrid_B);
+	CVIEW_ScatterPlot(CSG_Grid *pGrid, CSG_Shapes *pShapes, int Field);
+	CVIEW_ScatterPlot(CSG_Table *pTable, int Field_A, int Field_B);
+	virtual ~CVIEW_ScatterPlot(void);
+
+	static class wxToolBarBase *	_Create_ToolBar				(void);
+	static class wxMenu *			_Create_Menu				(void);
+
+	void							On_Size						(wxSizeEvent    &event);
+	void							On_Paint					(wxPaintEvent   &event);
+
+	void							On_Parameters				(wxCommandEvent &event);
+	void							On_Update					(wxCommandEvent &event);
+	void							On_AsTable					(wxCommandEvent &event);
+
+	void							Draw						(wxDC &dc, wxRect r);
+
+	void							Update_ScatterPlot			(void);
+
+
+private:
+
+	int								m_Method, m_xField, m_yField;
+
+	CSG_Grid						*m_pGrid_X, *m_pGrid_Y;
+
+	CSG_Shapes						*m_pShapes;
+
+	CSG_Table						*m_pTable;
+
+	CSG_Regression					m_Regression;
+
+	CSG_Parameters					m_Parameters;
+
+	wxString						m_sTitle, m_sX, m_sY;
+
+
+	void							_On_Construction			(void);
+
+	bool							_Initialize					(void);
+
+	bool							_Initialize_Grids			(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y);
+	bool							_Initialize_Grid_Equal		(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y);
+	bool							_Initialize_Grid_Unequal	(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y);
+
+	bool							_Initialize_Shapes			(CSG_Grid *pGrid_X, CSG_Shapes *pShapes_Y, int Field);
+
+	bool							_Initialize_Table			(CSG_Table *pTable, int Field_X, int Field_Y);
+
+	wxRect							_Draw_Get_rDiagram			(wxRect r);
+	void							_Draw_Image					(wxDC &dc, wxRect r, double dx, double dy);
+	void							_Draw_Points				(wxDC &dc, wxRect r, double dx, double dy);
+	void							_Draw_Regression			(wxDC &dc, wxRect r, double dx, double dy);
+	void							_Draw_Frame					(wxDC &dc, wxRect r);
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_ScatterPlot)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_ScatterPlot_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,289 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    VIEW_Table.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "wksp_table.h"
+
+#include "view_table.h"
+#include "view_table_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Table, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Table, CVIEW_Base)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_ADD			, CVIEW_Table::On_Field_Add)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_ADD			, CVIEW_Table::On_Field_Add_UI)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_DEL			, CVIEW_Table::On_Field_Del)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_DEL			, CVIEW_Table::On_Field_Del_UI)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_SORT		, CVIEW_Table::On_Field_Sort)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_SORT		, CVIEW_Table::On_Field_Sort_UI)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_RENAME		, CVIEW_Table::On_Field_Rename)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_RENAME		, CVIEW_Table::On_Field_Rename_UI)
+
+	EVT_MENU					(ID_CMD_TABLE_RECORD_ADD		, CVIEW_Table::On_Record_Add)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_ADD		, CVIEW_Table::On_Record_Add_UI)
+	EVT_MENU					(ID_CMD_TABLE_RECORD_INS		, CVIEW_Table::On_Record_Ins)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_INS		, CVIEW_Table::On_Record_Ins_UI)
+	EVT_MENU					(ID_CMD_TABLE_RECORD_DEL		, CVIEW_Table::On_Record_Del)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_DEL		, CVIEW_Table::On_Record_Del_UI)
+	EVT_MENU					(ID_CMD_TABLE_RECORD_DEL_ALL	, CVIEW_Table::On_Record_Clr)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_DEL_ALL	, CVIEW_Table::On_Record_Clr_UI)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Table::CVIEW_Table(CWKSP_Table *pTable)
+	: CVIEW_Base(ID_VIEW_TABLE, pTable->Get_Name(), ID_IMG_WND_TABLE, CVIEW_Table::_Create_Menu(), LNG("[CAP] Table"))
+{
+	m_pTable	= pTable;
+
+	m_pControl	= new CVIEW_Table_Control(this, m_pTable->Get_Table(), 0);
+}
+
+//---------------------------------------------------------
+CVIEW_Table::~CVIEW_Table(void)
+{
+	m_pTable->View_Closes(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_Table::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu();
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_ADD);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_DEL);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_ADD);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_INS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_DEL);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_DEL_ALL);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_Table::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_TABLE);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_TABLE_FIELD_ADD);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_TABLE_FIELD_DEL);
+	CMD_ToolBar_Add_Separator(pToolBar);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_TABLE_RECORD_ADD);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_TABLE_RECORD_INS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_TABLE_RECORD_DEL);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_TABLE_RECORD_DEL_ALL);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Table"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Field_Add(wxCommandEvent &event)
+{
+	m_pControl->On_Field_Add(event);
+}
+
+void CVIEW_Table::On_Field_Add_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Field_Add_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Field_Del(wxCommandEvent &event)
+{
+	m_pControl->On_Field_Del(event);
+}
+
+void CVIEW_Table::On_Field_Del_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Field_Del_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Field_Sort(wxCommandEvent &event)
+{
+	m_pControl->On_Field_Sort(event);
+}
+
+void CVIEW_Table::On_Field_Sort_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Field_Sort_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Field_Rename(wxCommandEvent &event)
+{
+	m_pControl->On_Field_Rename(event);
+}
+
+void CVIEW_Table::On_Field_Rename_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Field_Rename_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Record_Add(wxCommandEvent &event)
+{
+	m_pControl->On_Record_Add(event);
+}
+
+void CVIEW_Table::On_Record_Add_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Record_Add_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Record_Ins(wxCommandEvent &event)
+{
+	m_pControl->On_Record_Ins(event);
+}
+
+void CVIEW_Table::On_Record_Ins_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Record_Ins_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Record_Del(wxCommandEvent &event)
+{
+	m_pControl->On_Record_Del(event);
+}
+
+void CVIEW_Table::On_Record_Del_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Record_Del_UI(event);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::On_Record_Clr(wxCommandEvent &event)
+{
+	m_pControl->On_Record_Clr(event);
+}
+
+void CVIEW_Table::On_Record_Clr_UI(wxUpdateUIEvent &event)
+{
+	m_pControl->On_Record_Clr_UI(event);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table::Update_Table(void)
+{
+	m_pControl->Update_Table();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table::Update_Selection(void)
+{
+	m_pControl->Update_Selection();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     VIEW_Table.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Table : public CVIEW_Base
+{
+	DECLARE_CLASS(CVIEW_Table)
+
+public:
+	CVIEW_Table(class CWKSP_Table *pTable);
+	virtual ~CVIEW_Table(void);
+
+	static class wxToolBarBase *	_Create_ToolBar		(void);
+	static class wxMenu *			_Create_Menu		(void);
+
+	void							On_Field_Add		(wxCommandEvent  &event);
+	void							On_Field_Add_UI		(wxUpdateUIEvent &event);
+	void							On_Field_Del		(wxCommandEvent  &event);
+	void							On_Field_Del_UI		(wxUpdateUIEvent &event);
+	void							On_Field_Sort		(wxCommandEvent  &event);
+	void							On_Field_Sort_UI	(wxUpdateUIEvent &event);
+	void							On_Field_Rename		(wxCommandEvent  &event);
+	void							On_Field_Rename_UI	(wxUpdateUIEvent &event);
+
+	void							On_Record_Add		(wxCommandEvent  &event);
+	void							On_Record_Add_UI	(wxUpdateUIEvent &event);
+	void							On_Record_Ins		(wxCommandEvent  &event);
+	void							On_Record_Ins_UI	(wxUpdateUIEvent &event);
+	void							On_Record_Del		(wxCommandEvent  &event);
+	void							On_Record_Del_UI	(wxUpdateUIEvent &event);
+	void							On_Record_Clr		(wxCommandEvent  &event);
+	void							On_Record_Clr_UI	(wxUpdateUIEvent &event);
+
+	void							Update_Table		(void);
+	void							Update_Selection	(void);
+
+
+private:
+
+	class CWKSP_Table				*m_pTable;
+
+	class CVIEW_Table_Control		*m_pControl;
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1025 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                VIEW_Table_Control.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_shapes_manager.h"
+#include "wksp_shapes.h"
+
+#include "view_table_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define FIXED_COLS		((m_Constraint & TABLE_CTRL_FIXED_COLS)   != 0)
+#define FIXED_ROWS		((m_Constraint & TABLE_CTRL_FIXED_ROWS)   != 0)
+#define LABEL_COL		((m_Constraint & TABLE_CTRL_COL1ISLABEL)  != 0)
+
+//---------------------------------------------------------
+#define SET_CELL_VALUE(REC, FLD, VAL)	SetCellValue(REC, FLD, VAL)
+#define SET_CELL_COLOR(REC, FLD, VAL)	SetCellBackgroundColour(REC, FLD, wxColour(SG_GET_R(VAL), SG_GET_G(VAL), SG_GET_B(VAL)))
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Table_Control, wxGrid)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Table_Control, wxGrid)
+	EVT_GRID_CELL_CHANGE		(CVIEW_Table_Control::On_Change)
+	EVT_GRID_CELL_LEFT_CLICK	(CVIEW_Table_Control::On_LClick)
+	EVT_GRID_LABEL_LEFT_CLICK	(CVIEW_Table_Control::On_LClick_Label)
+	EVT_GRID_LABEL_LEFT_DCLICK	(CVIEW_Table_Control::On_LDClick_Label)
+	EVT_GRID_LABEL_RIGHT_CLICK	(CVIEW_Table_Control::On_RClick_Label)
+	EVT_GRID_RANGE_SELECT		(CVIEW_Table_Control::On_Select)
+
+	EVT_SIZE					(CVIEW_Table_Control::On_Size)
+
+	EVT_MENU					(ID_CMD_TABLE_FIELD_ADD			, CVIEW_Table_Control::On_Field_Add)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_ADD			, CVIEW_Table_Control::On_Field_Add_UI)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_DEL			, CVIEW_Table_Control::On_Field_Del)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_DEL			, CVIEW_Table_Control::On_Field_Del_UI)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_SORT		, CVIEW_Table_Control::On_Field_Sort)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_SORT		, CVIEW_Table_Control::On_Field_Sort_UI)
+	EVT_MENU					(ID_CMD_TABLE_FIELD_RENAME		, CVIEW_Table_Control::On_Field_Rename)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_FIELD_RENAME		, CVIEW_Table_Control::On_Field_Rename_UI)
+
+	EVT_MENU					(ID_CMD_TABLE_RECORD_ADD		, CVIEW_Table_Control::On_Record_Add)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_ADD		, CVIEW_Table_Control::On_Record_Add_UI)
+	EVT_MENU					(ID_CMD_TABLE_RECORD_INS		, CVIEW_Table_Control::On_Record_Ins)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_INS		, CVIEW_Table_Control::On_Record_Ins_UI)
+	EVT_MENU					(ID_CMD_TABLE_RECORD_DEL		, CVIEW_Table_Control::On_Record_Del)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_DEL		, CVIEW_Table_Control::On_Record_Del_UI)
+	EVT_MENU					(ID_CMD_TABLE_RECORD_DEL_ALL	, CVIEW_Table_Control::On_Record_Clr)
+	EVT_UPDATE_UI				(ID_CMD_TABLE_RECORD_DEL_ALL	, CVIEW_Table_Control::On_Record_Clr_UI)
+
+	EVT_MENU					(ID_CMD_TABLE_AUTOSIZE_COLS		, CVIEW_Table_Control::On_Autosize_Cols)
+	EVT_MENU					(ID_CMD_TABLE_AUTOSIZE_ROWS		, CVIEW_Table_Control::On_Autosize_Rows)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Table_Control::CVIEW_Table_Control(wxWindow *pParent, CSG_Table *pTable, int Constraint)
+	: wxGrid(pParent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxSUNKEN_BORDER)
+{
+	m_pTable		= pTable;
+	m_Constraint	= Constraint;
+
+	Set_Labeling(false);
+
+	CreateGrid(m_pTable->Get_Record_Count(), m_pTable->Get_Field_Count(), wxGrid::wxGridSelectRows);
+
+	_Set_Table();
+}
+
+//---------------------------------------------------------
+CVIEW_Table_Control::~CVIEW_Table_Control(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::Set_Labeling(bool bOn)
+{
+	if( bOn )
+	{
+		m_Field_Offset	= 1;
+
+		SetRowLabelAlignment(wxALIGN_RIGHT, wxALIGN_CENTRE);
+	}
+	else
+	{
+		m_Field_Offset	= 0;
+
+		SetRowLabelAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::Update_Table(void)
+{
+	_Set_Table();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::Sort_Table(int iField, int Direction)
+{
+	if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
+	{
+		switch( Direction )
+		{
+		default:	m_pTable->Toggle_Index(iField);	break;
+		case 0:		m_pTable->Set_Index(iField, TABLE_INDEX_None      );	break;
+		case 1:		m_pTable->Set_Index(iField, TABLE_INDEX_Ascending );	break;
+		case 2:		m_pTable->Set_Index(iField, TABLE_INDEX_Descending);	break;
+		}
+
+		_Set_Records();
+	}
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::_Set_Table(void)
+{
+	int		Difference;
+
+	//-----------------------------------------------------
+	BeginBatch();
+
+	//-----------------------------------------------------
+	Difference	= m_pTable->Get_Record_Count() - GetNumberRows();
+
+	if( Difference > 0 )
+	{
+		AppendRows(Difference);
+	}
+	else if( Difference < 0 )
+	{
+		Difference	= -Difference < GetNumberRows() ? -Difference : GetNumberRows();
+
+		if( Difference > 0 )
+		{
+			DeleteRows(0, Difference);
+		}
+	}
+
+	//-----------------------------------------------------
+	Difference	= (m_pTable->Get_Field_Count() - m_Field_Offset) - GetNumberCols();
+
+	if( Difference > 0 )
+	{
+		AppendCols(Difference);
+	}
+	else
+	{
+		Difference	= -Difference < GetNumberCols() ? -Difference : GetNumberCols();
+
+		if( Difference > 0 )
+		{
+			DeleteCols(0, Difference);
+		}	// here is (or was!?) a memory leak - solution: use own wxGridTableBase derived grid table class
+	}
+
+	//-----------------------------------------------------
+	for(int iCol=0, iField=m_Field_Offset; iField<m_pTable->Get_Field_Count(); iCol++, iField++)
+	{
+		SetColLabelValue(iCol, m_pTable->Get_Field_Name(iField));
+
+		switch( m_pTable->Get_Field_Type(iField) )
+		{
+		case SG_DATATYPE_Char:
+		case SG_DATATYPE_String: default:
+			break;
+
+		case SG_DATATYPE_Short:
+		case SG_DATATYPE_Int:
+		case SG_DATATYPE_Long:
+			SetColFormatNumber(iCol);
+			break;
+
+		case SG_DATATYPE_Float:
+		case SG_DATATYPE_Double:
+			SetColFormatFloat(iCol);
+			break;
+
+		case SG_DATATYPE_Color:
+			SetColFormatNumber(iCol);
+			break;
+		}
+	}
+
+	//-----------------------------------------------------
+	_Set_Records();
+
+	//-----------------------------------------------------
+	EndBatch();
+
+	_Update_Views();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::_Set_Records(void)
+{
+	BeginBatch();
+
+	for(int iRecord=0; iRecord<m_pTable->Get_Record_Count() && PROGRESSBAR_Set_Position(iRecord, m_pTable->Get_Record_Count()); iRecord++)
+	{
+		_Set_Record(iRecord, m_pTable->Get_Record_byIndex(iRecord));
+	}
+
+	PROCESS_Set_Okay();
+
+	Update_Selection();
+
+	EndBatch();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::_Set_Record(int iRecord, CSG_Table_Record *pRecord)
+{
+	if( pRecord && iRecord >= 0 && iRecord < GetNumberRows() )
+	{
+		if( m_Field_Offset )
+		{
+			SetRowLabelValue(iRecord, pRecord->asString(0));
+		}
+
+		for(int iCol=0, iField=m_Field_Offset; iField<m_pTable->Get_Field_Count(); iCol++, iField++)
+		{
+			switch( m_pTable->Get_Field_Type(iField) )
+			{
+			default:
+				SET_CELL_VALUE(iRecord, iCol, pRecord->asString	(iField));
+				break;
+
+			case SG_DATATYPE_Color:
+				SET_CELL_COLOR(iRecord, iCol, pRecord->asInt	(iField));
+				break;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::Add_Record(void)
+{
+	if( !FIXED_ROWS && !m_pTable->is_Private() )
+	{
+		AppendRows();
+
+		_Set_Record(m_pTable->Get_Record_Count(), m_pTable->Add_Record());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::Ins_Record(void)
+{
+	if( !FIXED_ROWS && !m_pTable->is_Private() )
+	{
+		int		iRecord	= GetGridCursorRow();
+
+		if( iRecord >= 0 && iRecord < GetNumberRows() )
+		{
+			InsertRows(iRecord);
+
+			_Set_Record(iRecord, m_pTable->Ins_Record(iRecord));
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::Del_Record(void)
+{
+	if( !FIXED_ROWS && (!m_pTable->is_Private() || (m_pTable->Get_Owner() && m_pTable->Get_Owner()->Get_ObjectType() == DATAOBJECT_TYPE_Shapes)) )
+	{
+		wxArrayInt	Records	= GetSelectedRows();
+
+		if( Records.GetCount() > 0 )
+		{
+			do
+			{
+				DeleteRows(Records[0]);
+				Records	= GetSelectedRows();
+			}
+			while( Records.GetCount() > 0 );
+
+			if( !m_pTable->is_Private() )
+			{
+				m_pTable->Del_Selection();
+
+				g_pData->Update_Views(m_pTable);
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::Del_Records(void)
+{
+	if( !FIXED_ROWS && !m_pTable->is_Private() && m_pTable->Del_Records() )
+	{
+		DeleteRows(0, GetNumberRows());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::Load(const wxChar *File_Name)
+{
+	bool	bResult	= false;
+	CSG_Table	Table;
+
+	if(	Table.Create(File_Name)
+	&&	Table.Get_Record_Count() > 0
+	&&	Table.Get_Field_Count() == m_pTable->Get_Field_Count() )
+	{
+		m_pTable->Assign_Values(&Table);
+
+		_Set_Table();
+
+		bResult	= true;
+	}
+
+	PROCESS_Set_Okay();
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Control::Save(const wxChar *File_Name, int Format)
+{
+	bool	bResult;
+
+	bResult	= m_pTable->Save(File_Name);
+
+	PROCESS_Set_Okay();
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Size(wxSizeEvent &event)//&WXUNUSED(event))
+{
+	if( m_Field_Offset && GetNumberCols() )
+	{
+		SetColSize(0, GetClientSize().x - GetRowLabelSize());
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Change(wxGridEvent &event)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( (pRecord = m_pTable->Get_Record_byIndex(event.GetRow())) != NULL )
+	{
+		int	iField	= m_Field_Offset + event.GetCol();
+
+		if( iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() )
+		{
+			pRecord->Set_Value(iField, GetCellValue(event.GetRow(), event.GetCol()).c_str());
+
+			SET_CELL_VALUE(event.GetRow(), event.GetCol(), pRecord->asString(iField));
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Field_Add(wxCommandEvent &event)
+{
+	int				i;
+	CSG_String		sFields;
+	CSG_Parameters	P;
+
+	//-----------------------------------------------------
+	for(i=0; i<m_pTable->Get_Field_Count(); i++)
+	{
+		sFields.Append(m_pTable->Get_Field_Name(i));	sFields.Append(wxT('|'));
+	}
+
+	//-----------------------------------------------------
+	P.Set_Name(LNG("Add Field"));
+
+	P.Add_String(
+		NULL	, "NAME"	, LNG("Name"),
+		LNG(""),
+		LNG("Field")
+	);
+
+	P.Add_Choice(
+		NULL	, "TYPE"	, LNG("Field Type"),
+		LNG(""),
+		CSG_String::Format(wxT("%s|%s|%s|%s|%s|%s|%s|%s|"),
+			LNG("character string"),
+			LNG("1 byte integer"),
+			LNG("2 byte integer"),
+			LNG("4 byte integer"),
+			LNG("4 byte floating point"),
+			LNG("8 byte floating point"),
+			LNG("date (dd.mm.yyyy)"),
+			LNG("color (rgb)")
+		)
+	);
+
+	P.Add_Choice(
+		NULL	, "FIELD"	, LNG("Insert Position"),
+		LNG(""),
+		sFields, m_pTable->Get_Field_Count() - 1
+	);
+
+	P.Add_Choice(
+		NULL	, "INSERT"	, LNG("Insert Method"),
+		LNG(""),
+		CSG_String::Format(wxT("%s|%s|"),
+			LNG("before"),
+			LNG("after")
+		), 1
+	);
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&P) )
+	{
+		int				Position;
+		TSG_Data_Type	Type;
+
+		switch( P("TYPE")->asInt() )
+		{
+		default:
+		case 0:	Type	= SG_DATATYPE_String;	break;
+		case 1:	Type	= SG_DATATYPE_Char;		break;
+		case 2:	Type	= SG_DATATYPE_Short;	break;
+		case 3:	Type	= SG_DATATYPE_Int;		break;
+		case 4:	Type	= SG_DATATYPE_Float;	break;
+		case 5:	Type	= SG_DATATYPE_Double;	break;
+		case 6:	Type	= SG_DATATYPE_Date;		break;
+		case 7:	Type	= SG_DATATYPE_Color;	break;
+		}
+
+		Position	= P("FIELD")->asInt() + P("INSERT")->asInt();
+
+		m_pTable->Add_Field(P("NAME")->asString(), Type, Position);
+
+		Update_Table();
+	}
+}
+
+void CVIEW_Table_Control::On_Field_Add_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(FIXED_COLS == false);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Field_Del(wxCommandEvent &event)
+{
+	int			i;
+	CSG_Parameters	P;
+
+	//-----------------------------------------------------
+	P.Set_Name(LNG("Delete Fields"));
+
+	for(i=0; i<m_pTable->Get_Field_Count(); i++)
+	{
+		P.Add_Value(
+			NULL	, CSG_String::Format(wxT("_%d_"), i), m_pTable->Get_Field_Name(i),
+			LNG(""),
+			PARAMETER_TYPE_Bool, false
+		);
+	}
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&P) )
+	{
+		for(i=m_pTable->Get_Field_Count()-1; i>=0; i--)
+		{
+			if( P(CSG_String::Format(wxT("_%d_"), i))->asBool() )
+			{
+				m_pTable->Del_Field(i);
+			}
+		}
+
+		Update_Table();
+	}
+}
+
+void CVIEW_Table_Control::On_Field_Del_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(FIXED_COLS == false);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Field_Sort(wxCommandEvent &event)
+{
+	CSG_String		sFields, sOrder;
+	CSG_Parameter	*pNode;
+	CSG_Parameters	P;
+
+	//-----------------------------------------------------
+	for(int i=0; i<m_pTable->Get_Field_Count(); i++)
+	{
+		sFields.Append(m_pTable->Get_Field_Name(i));	sFields.Append('|');
+	}
+
+	sOrder.Printf(wxT("%s|%s|%s|"),
+		LNG("unsorted"),
+		LNG("ascending"),
+		LNG("descending")
+	);
+
+	//-----------------------------------------------------
+	P.Set_Name(LNG("Sort Table"));
+
+	pNode	= P.Add_Choice(NULL , "FIELD_1"	, LNG("Sort first by")	,	LNG(""),	sFields	, !m_pTable->is_Indexed() ? 0 : m_pTable->Get_Index_Field(0));
+	pNode	= P.Add_Choice(pNode, "ORDER_1"	, LNG("Direction")		,	LNG(""),	sOrder	, !m_pTable->is_Indexed() ? 1 : m_pTable->Get_Index_Order(0));
+
+	pNode	= P.Add_Choice(NULL , "FIELD_2"	, LNG("Sort second by")	,	LNG(""),	sFields	, !m_pTable->is_Indexed() ? 0 : m_pTable->Get_Index_Field(1));
+	pNode	= P.Add_Choice(pNode, "ORDER_2"	, LNG("Direction")		,	LNG(""),	sOrder	, !m_pTable->is_Indexed() ? 0 : m_pTable->Get_Index_Order(1));
+
+	pNode	= P.Add_Choice(NULL , "FIELD_3"	, LNG("Sort third by")	,	LNG(""),	sFields	, !m_pTable->is_Indexed() ? 0 : m_pTable->Get_Index_Field(2));
+	pNode	= P.Add_Choice(pNode, "ORDER_3"	, LNG("Direction")		,	LNG(""),	sOrder	, !m_pTable->is_Indexed() ? 0 : m_pTable->Get_Index_Order(2));
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&P) )
+	{
+		m_pTable->Set_Index(
+			P("FIELD_1")->asInt(), P("ORDER_1")->asInt() == 1 ? TABLE_INDEX_Ascending : P("ORDER_1")->asInt() == 2 ? TABLE_INDEX_Descending : TABLE_INDEX_None,
+			P("FIELD_2")->asInt(), P("ORDER_2")->asInt() == 1 ? TABLE_INDEX_Ascending : P("ORDER_2")->asInt() == 2 ? TABLE_INDEX_Descending : TABLE_INDEX_None,
+			P("FIELD_3")->asInt(), P("ORDER_3")->asInt() == 1 ? TABLE_INDEX_Ascending : P("ORDER_3")->asInt() == 2 ? TABLE_INDEX_Descending : TABLE_INDEX_None
+		);
+
+		_Set_Records();
+	}
+}
+
+void CVIEW_Table_Control::On_Field_Sort_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(m_pTable->Get_Field_Count() > 0 && m_pTable->Get_Record_Count() > 1);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Field_Rename(wxCommandEvent &event)
+{
+	int				i;
+	CSG_Parameters	P;
+
+	P.Set_Name(LNG("Rename Fields"));
+
+	for(i=0; i<m_pTable->Get_Field_Count(); i++)
+	{
+		P.Add_String(NULL, "", m_pTable->Get_Field_Name(i), LNG(""), m_pTable->Get_Field_Name(i));
+	}
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&P) )
+	{
+		for(i=0; i<m_pTable->Get_Field_Count(); i++)
+		{
+			CSG_String	s(P(i)->asString());
+
+			if( s.Length() > 0 && s.Cmp(m_pTable->Get_Field_Name(i)) )
+			{
+				m_pTable->Set_Field_Name(i, s);
+
+				SetColLabelValue(i, s.c_str());
+			}
+		}
+	}
+}
+
+void CVIEW_Table_Control::On_Field_Rename_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(m_pTable->Get_Field_Count() > 0);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Record_Add(wxCommandEvent &event)
+{
+	Add_Record();
+}
+
+void CVIEW_Table_Control::On_Record_Add_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(!FIXED_ROWS && !m_pTable->is_Private());
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Record_Ins(wxCommandEvent &event)
+{
+	Ins_Record();
+}
+
+void CVIEW_Table_Control::On_Record_Ins_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(!FIXED_ROWS && !m_pTable->is_Private());
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Record_Del(wxCommandEvent &event)
+{
+	Del_Record();
+}
+
+void CVIEW_Table_Control::On_Record_Del_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(!FIXED_ROWS);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Record_Clr(wxCommandEvent &event)
+{
+	Del_Records();
+}
+
+void CVIEW_Table_Control::On_Record_Clr_UI(wxUpdateUIEvent &event)
+{
+	event.Enable(!FIXED_ROWS && !m_pTable->is_Private());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Autosize_Cols(wxCommandEvent &event)
+{
+	AutoSizeColumns(false);
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Autosize_Rows(wxCommandEvent &event)
+{
+	AutoSizeRows(false);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_LClick(wxGridEvent &event)
+{
+	if( event.ControlDown() )
+	{
+		SelectRow	(event.GetRow(), true);
+	}
+	else if( event.ShiftDown() )
+	{
+		SelectBlock	(event.GetRow(), 0, GetGridCursorRow(), GetNumberCols(), false);
+	}
+	else
+	{
+		SelectRow	(event.GetRow(), false);
+
+		CSG_Table_Record	*pRecord;
+
+		if( (pRecord = m_pTable->Get_Record_byIndex(event.GetRow())) != NULL )
+		{
+			int	iField	= m_Field_Offset + event.GetCol();
+
+			if( iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() )
+			{
+				long	lValue;
+
+				switch( m_pTable->Get_Field_Type(iField) )
+				{
+				default:
+					break;
+
+				case SG_DATATYPE_String:
+					if( event.AltDown() )
+					{
+						Open_Application(pRecord->asString(iField));
+					}
+					break;
+
+				case SG_DATATYPE_Color:
+					if( DLG_Color(lValue = pRecord->asInt(iField)) )
+					{
+						pRecord->Set_Value(iField, lValue);
+
+						SET_CELL_COLOR(event.GetRow(), event.GetCol(), lValue);
+
+						ForceRefresh();
+					}
+					return;
+				}
+			}
+		}
+	}
+
+	SetGridCursor(event.GetRow(), event.GetCol());
+
+//	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_LClick_Label(wxGridEvent &event)
+{
+	if( event.GetCol() >= 0 )
+	{
+		SetGridCursor	(GetGridCursorRow(), event.GetCol());
+	}
+	else if( event.GetRow() >= 0 )
+	{
+		SetGridCursor	(event.GetRow(), GetGridCursorCol());
+	}
+	else
+	{
+	//	SelectAll();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_RClick_Label(wxGridEvent &event)
+{
+	wxMenu	*pMenu;
+
+	//-----------------------------------------------------
+	if( event.GetCol() != -1 )
+	{
+		pMenu	= new wxMenu(wxString::Format(wxT("%s"), LNG("Columns")), 0);
+
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_ADD);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_DEL);
+		pMenu->AppendSeparator();
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_AUTOSIZE_COLS);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_SORT);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_RENAME);
+
+		PopupMenu(pMenu, event.GetPosition().x, event.GetPosition().y - GetColLabelSize());
+		delete(pMenu);
+	}
+
+	//-----------------------------------------------------
+	else if( event.GetRow() != -1 )
+	{
+		pMenu	= new wxMenu(wxString::Format(wxT("%s"), LNG("Rows")), 0);
+
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_ADD);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_INS);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_DEL);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_DEL_ALL);
+		pMenu->AppendSeparator();
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_AUTOSIZE_ROWS);
+
+		PopupMenu(pMenu, event.GetPosition().x - GetRowLabelSize(), event.GetPosition().y);
+		delete(pMenu);
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		ClearSelection();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_LDClick_Label(wxGridEvent &event)
+{
+	Sort_Table(event.GetCol(), -1);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::On_Select(wxGridRangeSelectEvent &event)
+{
+	BeginBatch();
+
+	for(int iRow=event.GetTopRow(); iRow<=event.GetBottomRow(); iRow++)
+	{
+		_Select(iRow, event.Selecting());
+	}
+
+	EndBatch();
+
+	_Update_Views();
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+inline void CVIEW_Table_Control::_Select(int iRow, bool bSelect)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( (pRecord = m_pTable->Get_Record_byIndex(iRow)) != NULL && bSelect != pRecord->is_Selected() )
+	{
+		m_pTable->Select(pRecord, true);
+
+		_Update_Views();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::Update_Selection(void)
+{
+	BeginBatch();
+
+	if( m_pTable->Get_Selection_Count() > 0 )
+	{
+		int		iRecord;
+		bool	*Select	= (bool *)SG_Malloc(m_pTable->Get_Record_Count() * sizeof(bool));
+
+		for(iRecord=0; iRecord<m_pTable->Get_Record_Count(); iRecord++)
+		{
+			Select[iRecord]	= m_pTable->Get_Record_byIndex(iRecord)->is_Selected();
+		}
+
+		ClearSelection();
+
+		for(iRecord=0; iRecord<m_pTable->Get_Record_Count(); iRecord++)
+		{
+			if( Select[iRecord] )
+			{
+				SelectRow(iRecord, true);
+			}
+		}
+
+		SG_Free(Select);
+	}
+	else
+	{
+		ClearSelection();
+	}
+
+	EndBatch();
+
+	_Update_Views();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Control::_Update_Views(void)
+{
+	if( GetBatchCount() == 0 )
+	{
+		if( m_pTable->is_Private() )
+		{
+			g_pData->Update_Views(m_pTable->Get_Owner());
+		}
+		else if( m_pTable->Get_ObjectType() == DATAOBJECT_TYPE_Shapes )
+		{
+			g_pData->Get_Shapes()->Get_Shapes((CSG_Shapes *)m_pTable)->Update_Views(true);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,174 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_Table_Control.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/grid.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define TABLE_CTRL_FIXED_COLS	0x01
+#define TABLE_CTRL_FIXED_ROWS	0x02
+#define TABLE_CTRL_FIXED_TABLE	(TABLE_CTRL_FIXED_ROWS|TABLE_CTRL_FIXED_COLS)
+#define TABLE_CTRL_COL1ISLABEL	0x04
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Table_Control : public wxGrid
+{
+	DECLARE_CLASS(CVIEW_Table_Control)
+
+public:
+	CVIEW_Table_Control(wxWindow *pParent, class CSG_Table *pTable, int Constraint);
+	virtual ~CVIEW_Table_Control(void);
+
+	void						On_Field_Add		(wxCommandEvent  &event);
+	void						On_Field_Add_UI		(wxUpdateUIEvent &event);
+	void						On_Field_Del		(wxCommandEvent  &event);
+	void						On_Field_Del_UI		(wxUpdateUIEvent &event);
+	void						On_Field_Sort		(wxCommandEvent  &event);
+	void						On_Field_Sort_UI	(wxUpdateUIEvent &event);
+	void						On_Field_Rename		(wxCommandEvent  &event);
+	void						On_Field_Rename_UI	(wxUpdateUIEvent &event);
+
+	void						On_Record_Add		(wxCommandEvent  &event);
+	void						On_Record_Add_UI	(wxUpdateUIEvent &event);
+	void						On_Record_Ins		(wxCommandEvent  &event);
+	void						On_Record_Ins_UI	(wxUpdateUIEvent &event);
+	void						On_Record_Del		(wxCommandEvent  &event);
+	void						On_Record_Del_UI	(wxUpdateUIEvent &event);
+	void						On_Record_Clr		(wxCommandEvent  &event);
+	void						On_Record_Clr_UI	(wxUpdateUIEvent &event);
+
+	void						On_Autosize_Cols	(wxCommandEvent  &event);
+	void						On_Autosize_Rows	(wxCommandEvent  &event);
+
+	void						On_Size				(wxSizeEvent &event);
+	void						On_Change			(wxGridEvent &event);
+	void						On_LClick			(wxGridEvent &event);
+	void						On_LClick_Label		(wxGridEvent &event);
+	void						On_RClick_Label		(wxGridEvent &event);
+	void						On_LDClick_Label	(wxGridEvent &event);
+	void						On_Select			(wxGridRangeSelectEvent &event);
+
+	bool						Load				(const wxChar *File_Name);
+	bool						Save				(const wxChar *File_Name, int Format = 0);
+
+	bool						Add_Record			(void);
+	bool						Ins_Record			(void);
+	bool						Del_Record			(void);
+	bool						Del_Records			(void);
+
+	void						Set_Labeling		(bool bOn);
+	void						Update_Selection	(void);
+	void						Update_Table		(void);
+	void						Sort_Table			(int iField, int Direction);
+
+
+private:
+
+	int							m_Constraint, m_Field_Offset;
+
+	class CSG_Table				*m_pTable;
+
+
+	bool						_Set_Table			(void);
+
+	bool						_Set_Records		(void);
+	bool						_Set_Record			(int iRecord, class CSG_Table_Record *pRecord);
+
+	void						_Select				(int iRow, bool bSelect);
+	void						_Update_Views		(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1098 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                VIEW_Table_Diagram.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/wx.h>
+#include <wx/window.h>
+#include <wx/scrolwin.h>
+#include <wx/clipbrd.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_table.h"
+
+#include "view_table_diagram.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MIN_SIZE		100
+
+#define SCROLL_RATE		5
+
+#define SCROLL_BAR_DX	wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)
+#define SCROLL_BAR_DY	wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Table_Diagram_Control : public wxScrolledWindow
+{
+public:
+	CVIEW_Table_Diagram_Control(wxWindow *pParent, class CWKSP_Table *pTable);
+	virtual ~CVIEW_Table_Diagram_Control(void);
+
+	bool							Update_Diagram		(void);
+
+	bool							Set_Size			(const wxSize &Size);
+	bool							Set_Size			(double Zoom, wxPoint Center);
+	bool							Fit_Size			(void);
+	bool							Inc_Size			(void);
+	bool							Dec_Size			(void);
+
+	bool							Set_Parameters		(void);
+
+	void							SaveToClipboard		(void);
+
+	virtual void					OnDraw				(wxDC &dc);
+
+
+private:
+
+	bool							m_bFitSize;
+
+	int								m_nFields, *m_Fields, m_xField;
+
+	double							m_xMin, m_xMax, m_yMin, m_yMax;
+
+	CSG_Colors						m_Colors;
+
+	CSG_Parameters					m_Parameters;
+
+	CSG_Table						*m_pTable, m_Structure;
+
+	wxSize							m_sDraw;
+
+	wxFont							*m_pFont;
+
+
+	void							On_Size				(wxSizeEvent  &event);
+	void							On_Mouse_LDown		(wxMouseEvent &event);
+	void							On_Mouse_RDown		(wxMouseEvent &event);
+
+	void							_Destroy			(void);
+	bool							_Create				(void);
+	bool							_Initialize			(void);
+
+	int								_Get_Field_By_Name	(const CSG_String &sField);
+
+	void							_Draw				(wxDC &dc, wxRect r);
+	void							_Draw_Frame			(wxDC &dc, wxRect r, double dx, double dy);
+	void							_Draw_Legend		(wxDC &dc, wxRect r);
+	void							_Draw_Points		(wxDC &dc, wxRect r, double dx, double dy, int iField);
+	void							_Draw_Lines			(wxDC &dc, wxRect r, double dx, double dy, int iField);
+	void							_Draw_Bars			(wxDC &dc, wxRect r, double dx, double dy, int iField);
+
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Table_Diagram_Control)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Table_Diagram_Control, wxScrolledWindow);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Table_Diagram_Control, wxScrolledWindow)
+	EVT_SIZE			(CVIEW_Table_Diagram_Control::On_Size)
+	EVT_LEFT_DOWN		(CVIEW_Table_Diagram_Control::On_Mouse_LDown)
+	EVT_RIGHT_DOWN		(CVIEW_Table_Diagram_Control::On_Mouse_RDown)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Table_Diagram_Control::CVIEW_Table_Diagram_Control(wxWindow *pParent, CWKSP_Table *pTable)
+	: wxScrolledWindow(pParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE)
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_pTable	= pTable->Get_Table();
+
+	m_nFields	= 0;
+	m_Fields	= NULL;
+
+	m_pFont		= NULL;
+
+	m_bFitSize	= false;
+
+	Fit_Size();
+
+	_Initialize();
+
+	Set_Parameters();
+}
+
+//---------------------------------------------------------
+CVIEW_Table_Diagram_Control::~CVIEW_Table_Diagram_Control(void)
+{
+	_Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::Set_Parameters(void)
+{
+	if( DLG_Parameters(&m_Parameters) )
+	{
+		return( _Create() );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::Update_Diagram(void)
+{
+	return( m_Structure.is_Compatible(m_pTable, true) ? _Create() : _Initialize() );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::Set_Size(const wxSize &Size)
+{
+	if( Size.x >= MIN_SIZE && Size.y >= MIN_SIZE )
+	{
+		if( Size.x != m_sDraw.x || Size.y != m_sDraw.y )
+		{
+			bool	bFitSize	= m_bFitSize;
+
+			m_bFitSize	= false;
+
+			m_sDraw.x	= Size.x;
+			m_sDraw.y	= Size.y;
+		
+			SetScrollbars(SCROLL_RATE, SCROLL_RATE, (m_sDraw.x + SCROLL_BAR_DX) / SCROLL_RATE, (m_sDraw.y + SCROLL_BAR_DY) / SCROLL_RATE);
+
+			Refresh();
+
+			m_bFitSize	= bFitSize;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CVIEW_Table_Diagram_Control::Set_Size(double Zoom, wxPoint Center)
+{
+	if( Zoom > 0.0 )
+	{
+		int		x, y;
+
+		GetViewStart(&x, &y);
+
+		x	= (int)((Zoom * (x * SCROLL_RATE + Center.x) - GetClientSize().x / 2) / SCROLL_RATE);
+		y	= (int)((Zoom * (y * SCROLL_RATE + Center.y) - GetClientSize().y / 2) / SCROLL_RATE);
+
+		if( Set_Size(wxSize((int)(m_sDraw.x * Zoom), (int)(m_sDraw.y * Zoom))) )
+		{
+			Scroll(x, y);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::Fit_Size(void)
+{
+	wxSize	Size(GetParent()->GetClientSize());
+
+	Size.x	-= 2 * SCROLL_BAR_DX;
+	Size.y	-= 2 * SCROLL_BAR_DY;
+
+	return( Set_Size(Size) );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::Inc_Size(void)
+{
+	return( Set_Size(1.2, wxPoint(GetClientSize().x / 2, GetClientSize().y / 2)) );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::Dec_Size(void)
+{
+	return( Set_Size(1.0 / 1.2, wxPoint(GetClientSize().x / 2, GetClientSize().y / 2)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::On_Size(wxSizeEvent &WXUNUSED(event))
+{
+	if( m_bFitSize )
+	{
+		Fit_Size();
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::On_Mouse_LDown(wxMouseEvent &event)
+{
+	Set_Size(1.2, event.GetPosition());
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::On_Mouse_RDown(wxMouseEvent &event)
+{
+	Set_Size(1.0 / 1.2, event.GetPosition());
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::SaveToClipboard(void)
+{
+	Set_Buisy_Cursor(true);
+
+	wxBitmap	BMP;
+	wxMemoryDC	dc;
+
+	BMP.Create(m_sDraw.x, m_sDraw.y);
+	dc.SelectObject(BMP);
+	dc.SetBackground(*wxWHITE_BRUSH);
+	dc.Clear();
+
+	_Draw(dc, wxRect(0, 0, m_sDraw.x, m_sDraw.y));
+
+	dc.SelectObject(wxNullBitmap);
+
+	if( wxTheClipboard->Open() )
+	{
+		wxBitmapDataObject	*pBMP	= new wxBitmapDataObject;
+		pBMP->SetBitmap(BMP);
+		wxTheClipboard->SetData(pBMP);
+		wxTheClipboard->Close();
+	}
+
+	Set_Buisy_Cursor(false);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Destroy(void)
+{
+	if( m_nFields > 0 )
+	{
+		SG_Free(m_Fields);
+
+		m_Fields	= NULL;
+		m_nFields	= 0;
+	}
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::_Create(void)
+{
+	_Destroy();
+
+	//-----------------------------------------------------
+	if( m_pTable && m_pTable->Get_Field_Count() > 0 )
+	{
+		m_bFitSize	= m_Parameters("_DIAGRAM_FIT_SIZE")->asBool();
+
+		m_xField	= _Get_Field_By_Name(m_Parameters("_DIAGRAM_X_FIELD")->asString());
+
+		if( m_xField >= 0 && m_pTable->Get_Range(m_xField) > 0.0 )
+		{
+			m_xMin		= m_pTable->Get_Minimum(m_xField);
+			m_xMax		= m_pTable->Get_Maximum(m_xField);
+		}
+		else
+		{
+			m_xMin		= 1;
+			m_xMax		= 1 + m_pTable->Get_Count();
+			m_xField	= -1;
+		}
+
+		//-------------------------------------------------
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			if(	m_pTable->Get_Field_Type(iField) != SG_DATATYPE_String
+			&&	m_Parameters(wxString::Format(wxT("FIELD_%d"), iField))->asBool() )
+			{
+				m_Fields			= (int *)SG_Realloc(m_Fields, (m_nFields + 1) * sizeof(int));
+				m_Fields[m_nFields]	= iField;
+
+				m_Colors.Set_Color(iField, m_Parameters(wxString::Format(wxT("COLOR_%d"), iField))->asColor());
+
+				m_nFields++;
+
+				if( m_nFields == 1 )
+				{
+					m_yMin	= m_pTable->Get_Minimum(iField);
+					m_yMax	= m_pTable->Get_Maximum(iField);
+				}
+				else
+				{
+					if( m_yMin	> m_pTable->Get_Minimum(iField) )
+						m_yMin	= m_pTable->Get_Minimum(iField);
+
+					if( m_yMax	< m_pTable->Get_Maximum(iField) )
+						m_yMax	= m_pTable->Get_Maximum(iField);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_Parameters("_DIAGRAM_Y_MIN_FIX")->asBool() )
+		{
+			m_yMin	= m_Parameters("_DIAGRAM_Y_MIN_VAL")->asDouble();
+		}
+
+		if( m_Parameters("_DIAGRAM_Y_MAX_FIX")->asBool() )
+		{
+			m_yMax	= m_Parameters("_DIAGRAM_Y_MAX_VAL")->asDouble();
+		}
+	}
+
+	Refresh();
+
+	return( m_nFields > 0 );
+}
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram_Control::_Initialize(void)
+{
+	_Destroy();
+
+	//-----------------------------------------------------
+	if( m_pTable && m_pTable->Get_Field_Count() > 0 && m_pTable->Get_Count() > 0 )
+	{
+		CSG_String		sFields_All, sFields_Num;
+		CSG_Parameter	*pNode, *pFields, *pColors;
+
+		m_Structure.Create(m_pTable);
+
+		m_Colors.Set_Count(m_pTable->Get_Field_Count());
+
+		m_Parameters.Create(NULL, LNG("[CAP] Properties"), LNG(""));
+
+		pFields	= m_Parameters.Add_Node(NULL, "NODE_FIELDS", LNG("[CAP] Attributes")	, LNG(""));
+
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			if( m_pTable->Get_Field_Type(iField) != SG_DATATYPE_String )
+			{
+				pColors	= m_Parameters.Add_Value(
+					pFields, wxString::Format(wxT("FIELD_%d"), iField), m_pTable->Get_Field_Name(iField),
+					LNG("[CAP] Show"),
+					PARAMETER_TYPE_Bool, false
+				);
+
+				m_Parameters.Add_Value(
+					pColors, wxString::Format(wxT("COLOR_%d"), iField), SG_T(""),
+					LNG("[CAP] Color"),
+					PARAMETER_TYPE_Color, m_Colors.Get_Color(iField)
+				);
+
+				sFields_Num	+= m_pTable->Get_Field_Name(iField) + CSG_String(SG_T("|"));
+			}
+
+			sFields_All	+= m_pTable->Get_Field_Name(iField) + CSG_String(SG_T("|"));
+		}
+
+		sFields_Num	+= LNG("[CAP] [none]") + CSG_String(SG_T("|"));
+		sFields_All	+= LNG("[CAP] [none]") + CSG_String(SG_T("|"));
+
+		//-------------------------------------------------
+		pNode	= m_Parameters.Add_Node(
+			NULL, "GENERAL", LNG("[CAP] General"),
+			LNG("")
+		);
+
+		m_Parameters.Add_Choice(
+			pNode, "_DIAGRAM_TYPE"		, LNG("[CAP] Display Type"),
+			LNG(""),
+			wxString::Format(wxT("%s|%s|%s|%s|"),
+				LNG("Bars"),
+				LNG("Lines"),
+				LNG("Lines and Points"),
+				LNG("Points")
+			), 2
+		);
+
+		m_pFont	= m_Parameters.Add_Font(
+			pNode, "_DIAGRAM_FONT"		, LNG("[CAP] Font"),
+			LNG("")
+		)->asFont();
+
+		m_Parameters.Add_Value(
+			pNode, "_DIAGRAM_LEGEND"	, LNG("[CAP] Legend"),
+			LNG(""),
+			PARAMETER_TYPE_Bool, true
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_DIAGRAM_FIT_SIZE"	, LNG("[CAP] Fit Size to Window"),
+			LNG(""),
+			PARAMETER_TYPE_Bool, true
+		);
+
+		//-------------------------------------------------
+		pNode	= m_Parameters.Add_Node(
+			NULL, "NODE_POINTS", LNG("[CAP] Points"),
+			LNG("")
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_POINTS_SIZE"		, LNG("[CAP] Size"),
+			LNG(""),
+			PARAMETER_TYPE_Int, 2, 1, true
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_POINTS_OUTLINE"	, LNG("[CAP] Outline"),
+			LNG(""),
+			PARAMETER_TYPE_Bool, false
+		);
+
+		m_Parameters.Add_Choice(
+			pNode, "_POINTS_COLOR_FIELD", LNG("[CAP] Color by Attribute"),
+			LNG(""),
+			sFields_Num, m_pTable->Get_Field_Count()
+		);
+
+		m_Parameters.Add_Colors(
+			pNode, "_POINTS_COLORS"		, LNG("[CAP] Colors"),
+			LNG("")
+		);
+
+		//-------------------------------------------------
+		pNode	= m_Parameters.Add_Node(
+			NULL, "NODE_X", LNG("[CAP] X Axis"),
+			LNG("")
+		);
+
+		m_Parameters.Add_Choice(
+			pNode, "_DIAGRAM_X_FIELD"	, LNG("[CAP] Values"),
+			LNG(""),
+			sFields_Num, m_pTable->Get_Field_Count() + 1
+		);
+
+		m_Parameters.Add_Choice(
+			pNode, "_DIAGRAM_X_LABEL"	, LNG("[CAP] Label"),
+			LNG(""),
+			sFields_All, m_pTable->Get_Field_Count() + 1
+		);
+
+		//-------------------------------------------------
+		pNode	= m_Parameters.Add_Node(
+			NULL, "NODE_Y", LNG("[CAP] Y Axis"),
+			LNG("")
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_DIAGRAM_Y_MIN_FIX"	, LNG("[CAP] Fixed Minimum"),
+			LNG(""),
+			PARAMETER_TYPE_Bool, false
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_DIAGRAM_Y_MIN_VAL"	, LNG("[CAP] Minimum Value"),
+			LNG(""),
+			PARAMETER_TYPE_Double, 0.0
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_DIAGRAM_Y_MAX_FIX"	, LNG("[CAP] Fixed Maximum"),
+			LNG(""),
+			PARAMETER_TYPE_Bool, false
+		);
+
+		m_Parameters.Add_Value(
+			pNode, "_DIAGRAM_Y_MAX_VAL"	, LNG("[CAP] Maximum Value"),
+			LNG(""),
+			PARAMETER_TYPE_Double, 1000.0
+		);
+
+		return( _Create() );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CVIEW_Table_Diagram_Control::_Get_Field_By_Name(const CSG_String &sField)
+{
+	if( m_pTable )
+	{
+		for(int iField=0; iField<m_pTable->Get_Field_Count(); iField++)
+		{
+			if( sField.Cmp(m_pTable->Get_Field_Name(iField)) == 0 )
+			{
+				return( iField );
+			}
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::OnDraw(wxDC &dc)
+{
+	_Draw(dc, wxRect(0, 0, m_sDraw.x, m_sDraw.y));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Draw(wxDC &dc, wxRect rDC)
+{
+	if( m_pFont )
+	{
+		dc.SetFont(*m_pFont);
+	}
+
+	if( m_nFields > 0 && m_yMax > m_yMin )
+	{
+		bool	bLegend	= m_Parameters("_DIAGRAM_LEGEND")->asBool();
+		int		iField;
+		double	dx, dy;
+		wxRect	r;
+
+		r	= bLegend
+			? wxRect(	wxPoint(rDC.GetLeft()  +  80, rDC.GetTop()    + 10),
+						wxPoint(rDC.GetRight() - 100, rDC.GetBottom() - 40))
+			: wxRect(	wxPoint(rDC.GetLeft()  +  80, rDC.GetTop()    + 10),
+						wxPoint(rDC.GetRight() -  10, rDC.GetBottom() - 50));
+
+		dx	= m_xField < 0
+			? (double)r.GetWidth()	/ (double)m_pTable->Get_Count()
+			: (double)r.GetWidth()	/ (m_xMax - m_xMin);
+		dy	= (double)r.GetHeight()	/ (m_yMax - m_yMin);
+
+		//-------------------------------------------------
+		if( dx > 0.0 && dy > 0.0 )
+		{
+			for(iField=0; iField<m_nFields; iField++)
+			{
+				switch( m_Parameters("_DIAGRAM_TYPE")->asInt() )
+				{
+				default:
+				case 0:	_Draw_Bars  (dc, r, dx, dy, iField);	break;	// Bars
+				case 1:	_Draw_Lines (dc, r, dx, dy, iField);	break;	// Lines
+				case 2:	_Draw_Lines (dc, r, dx, dy, iField);
+						_Draw_Points(dc, r, dx, dy, iField);	break;	// Lines and Points
+				case 3:	_Draw_Points(dc, r, dx, dy, iField);	break;	// Points
+				case 4:	_Draw_Points(dc, r, dx, dy, iField);	break;	// Points with Colour Attribute
+				}
+			}
+
+			_Draw_Frame(dc, r, dx, dy);
+
+			if( bLegend )
+			{
+				r	= wxRect(	wxPoint(r  .GetRight(), rDC.GetTop()),
+								wxPoint(rDC.GetRight(), rDC.GetBottom()));
+
+				_Draw_Legend(dc, r);
+			}
+		}
+		else
+		{
+			Draw_Text(dc, TEXTALIGN_CENTER, rDC.GetLeft() + rDC.GetWidth() / 2, rDC.GetTop() + rDC.GetHeight() / 2,
+				LNG("[ERR] Invalid display size!")
+			);
+		}
+	}
+	else
+	{
+		Draw_Text(dc, TEXTALIGN_CENTER, rDC.GetLeft() + rDC.GetWidth() / 2, rDC.GetTop() + rDC.GetHeight() / 2,
+			LNG("[ERR] Invalid data set!")
+		);
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Draw_Frame(wxDC &dc, wxRect r, double dx, double dy)
+{
+	const int	dyFont		= 12,
+				Precision	= 3;
+
+	int			ix, iRecord, iStep, nSteps, iLabel;
+	double		z, dz, dzStep;
+	wxFont		Font;
+	wxString	sLabel;
+
+	//-----------------------------------------------------
+	dc.SetPen(*wxBLACK);
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);
+
+	//-----------------------------------------------------
+	Font	= dc.GetFont();
+	Font.SetPointSize((int)(0.7 * dyFont));
+	dc.SetFont(Font);
+
+	if( m_xField < 0 )
+	{
+		iLabel	= m_Parameters("_DIAGRAM_X_LABEL")->asInt();	if( iLabel >= m_pTable->Get_Field_Count() )	iLabel	= -1;
+		iStep	= dx > dyFont ? 1 : (int)(1 + (dyFont + 5) / dx);
+
+		for(iRecord=0; iRecord<m_pTable->Get_Count(); iRecord+=iStep)
+		{
+			ix	= r.GetLeft() + (int)(dx * iRecord);
+
+			dc.DrawLine(ix, r.GetBottom(), ix, r.GetBottom() + 5);
+
+			if( iLabel >= 0 )
+			{
+				sLabel.Printf(m_pTable->Get_Record_byIndex(iRecord)->asString(iLabel));
+			}
+			else
+			{
+				sLabel.Printf(wxT("%d"), iRecord);
+			}
+
+			Draw_Text(dc, TEXTALIGN_CENTERRIGHT, ix, r.GetBottom() + 7, 45.0, sLabel);
+		}
+	}
+	else
+	{
+		nSteps		= r.GetWidth()			/ (dyFont + 5);
+		dzStep		= (double)r.GetWidth()	/ nSteps;
+		dz			= (m_xMax - m_xMin)		/ nSteps;
+
+		for(iStep=0, z=m_xMin; iStep<=nSteps; iStep++, z+=dz)
+		{
+			ix		= r.GetLeft()	+ (int)(dzStep * iStep);
+
+			dc.DrawLine(ix, r.GetBottom(), ix, r.GetBottom() + 5);
+
+			sLabel.Printf(wxT("%.*f"), Precision, z);
+
+			Draw_Text(dc, TEXTALIGN_CENTERRIGHT, ix, r.GetBottom() + 7, 45.0, sLabel);
+		}
+	}
+
+	//-----------------------------------------------------
+	nSteps		= r.GetHeight()			/ (dyFont + 5);
+	dzStep		= (double)r.GetHeight()	/ nSteps;
+	dz			= (m_yMax - m_yMin)		/ nSteps;
+
+	for(iStep=0, z=m_yMin; iStep<=nSteps; iStep++, z+=dz)
+	{
+		ix		= r.GetBottom()	- (int)(dzStep * iStep);
+
+		dc.DrawLine(r.GetLeft(), ix, r.GetLeft() - 5, ix);
+
+		Draw_Text(dc, TEXTALIGN_TOPRIGHT, r.GetLeft() - 7, ix - dyFont / 2, wxString::Format(wxT("%.*f"), Precision, z));
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Draw_Legend(wxDC &dc, wxRect r)
+{
+	const int	dyFont	= 12,
+				dyBox	= dyFont + 4;
+
+	int		iField;
+	wxRect	rBox;
+	wxBrush	Brush;
+	wxFont	Font;
+
+	//-----------------------------------------------------
+	iField	= r.GetTop() + (r.GetHeight() / 2);
+	r		= wxRect(
+				wxPoint(r.GetLeft() + 5, iField - (m_nFields * dyBox) / 2),
+				wxPoint(r.GetRight()   , iField + (m_nFields * dyBox) / 2)
+			);
+
+	rBox	= wxRect(r.GetLeft(), r.GetTop(), 20, dyBox);
+
+	Font	= dc.GetFont();
+	Font.SetPointSize(dyFont);
+	dc.SetFont(Font);
+
+	dc.SetPen(*wxBLACK_PEN);
+
+	//-----------------------------------------------------
+	for(iField=0; iField<m_nFields; iField++)
+	{
+		rBox.SetY(r.GetTop() + iField * dyBox);
+
+		Brush	= dc.GetBrush();
+		Brush.SetColour(Get_Color_asWX(m_Colors.Get_Color(m_Fields[iField])));
+		dc.SetBrush(Brush);
+		dc.DrawRectangle(rBox.GetX(), rBox.GetY(), rBox.GetWidth(), rBox.GetHeight());
+
+		dc.DrawText(m_pTable->Get_Field_Name(m_Fields[iField]), rBox.GetRight() + 5, rBox.GetTop());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DRAW_GET_XPOS(i)	(r.GetLeft()   + (int)(dx * (m_xField >= 0 ? (m_pTable->Get_Record_byIndex(i)->asDouble(m_xField) - m_xMin) : (double)i)))
+#define DRAW_GET_YPOS(i)	(r.GetBottom() - (int)(dy * (                (m_pTable->Get_Record_byIndex(i)->asDouble(  iField) - m_yMin)                  )))
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Draw_Points(wxDC &dc, wxRect r, double dx, double dy, int iField)
+{
+	bool	bOutline	= m_Parameters("_POINTS_OUTLINE")		->asBool();
+	int		Size		= m_Parameters("_POINTS_SIZE")			->asInt();
+	int		zField		= _Get_Field_By_Name(m_Parameters("_POINTS_COLOR_FIELD")->asString());
+
+	iField	= m_Fields[iField];
+
+	if( zField < 0 )
+	{
+		dc.SetPen  (wxPen  (bOutline ? *wxBLACK : Get_Color_asWX(m_Colors.Get_Color(iField))));
+		dc.SetBrush(wxBrush(                      Get_Color_asWX(m_Colors.Get_Color(iField))));
+
+		for(int iRecord=0; iRecord<m_pTable->Get_Count(); iRecord++)
+		{
+			dc.DrawCircle(DRAW_GET_XPOS(iRecord), DRAW_GET_YPOS(iRecord), Size);
+		}
+	}
+	else
+	{
+		if( bOutline )
+		{
+			dc.SetPen(wxPen(Get_Color_asWX(m_Colors.Get_Color(iField))));
+		}
+
+		CSG_Colors	*pColors	= m_Parameters("_POINTS_COLORS")->asColors();
+		double		zMin		= m_pTable->Get_Minimum(zField);
+		double		dz			= pColors->Get_Count() / m_pTable->Get_Range(zField);
+
+		for(int iRecord=0; iRecord<m_pTable->Get_Count(); iRecord++)
+		{
+			int			iz	= (int)(dz * (m_pTable->Get_Record_byIndex(iRecord)->asDouble(zField) - zMin));
+			wxColour	ic	= Get_Color_asWX(pColors->Get_Color(iz < 0 ? 0 : (iz >= 255 ? 255 : iz)));
+
+			if( !bOutline )
+			{
+				dc.SetPen(wxPen(ic));
+			}
+
+			dc.SetBrush(wxBrush(ic));
+
+			dc.DrawCircle(DRAW_GET_XPOS(iRecord), DRAW_GET_YPOS(iRecord), Size);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Draw_Lines(wxDC &dc, wxRect r, double dx, double dy, int iField)
+{
+	if( m_pTable->Get_Count() >= 2 )
+	{
+		int		ix, iy, jx, jy;
+
+		iField	= m_Fields[iField];
+
+		dc.SetPen  (wxPen  (Get_Color_asWX(m_Colors.Get_Color(iField)), 0, wxSOLID));
+		dc.SetBrush(wxBrush(Get_Color_asWX(m_Colors.Get_Color(iField)), wxSOLID));
+
+		ix	= DRAW_GET_XPOS(0);
+		iy	= DRAW_GET_YPOS(0);
+
+		for(int iRecord=1; iRecord<m_pTable->Get_Count(); iRecord++)
+		{
+			jx	= ix;	ix	= DRAW_GET_XPOS(iRecord);
+			jy	= iy;	iy	= DRAW_GET_YPOS(iRecord);
+
+			dc.DrawLine(jx, jy, ix, iy);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram_Control::_Draw_Bars(wxDC &dc, wxRect r, double dx, double dy, int iField)
+{
+	int		x, y, xa, xb, dxa, dxb;
+
+	dxb		= m_xField < 0 ? (int)(dx / m_nFields)			: iField + 1;
+	dxa		= m_xField < 0 ? (int)(dx / m_nFields * iField)	: iField + 0;
+
+	iField	= m_Fields[iField];
+
+	dc.SetPen(wxPen(Get_Color_asWX(m_Colors.Get_Color(iField)), 0, wxSOLID));
+
+	for(int iRecord=0; iRecord<m_pTable->Get_Count(); iRecord++)
+	{
+		xa	= DRAW_GET_XPOS(iRecord) + dxa;	xb	= dxb + xa;
+		y	= DRAW_GET_YPOS(iRecord);
+
+		for(x=xa; x<=xb; x++)
+		{
+			dc.DrawLine(x, r.GetBottom(), x, y);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CVIEW_Table_Diagram, CVIEW_Base);
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CVIEW_Table_Diagram, CVIEW_Base)
+	EVT_MENU			(ID_CMD_DIAGRAM_PARAMETERS		, CVIEW_Table_Diagram::On_Parameters)
+	EVT_MENU			(ID_CMD_DIAGRAM_SIZE_FIT		, CVIEW_Table_Diagram::On_Size_Fit)
+	EVT_MENU			(ID_CMD_DIAGRAM_SIZE_INC		, CVIEW_Table_Diagram::On_Size_Inc)
+	EVT_MENU			(ID_CMD_DIAGRAM_SIZE_DEC		, CVIEW_Table_Diagram::On_Size_Dec)
+
+	EVT_MENU			(ID_CMD_MAPS_SAVE_TO_CLIPBOARD	, CVIEW_Table_Diagram::On_SaveToClipboard)
+
+	EVT_KEY_DOWN		(CVIEW_Table_Diagram::On_Key_Down)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CVIEW_Table_Diagram::CVIEW_Table_Diagram(CWKSP_Table *pTable)
+	: CVIEW_Base(ID_VIEW_TABLE_DIAGRAM, wxString::Format(wxT("%s [%s]"), LNG("[CAP] Diagram"), pTable->Get_Name().c_str()), ID_IMG_WND_DIAGRAM, CVIEW_Table_Diagram::_Create_Menu(), LNG("[CAP] Diagram"))
+{
+	SYS_Set_Color_BG_Window(this);
+
+	m_pOwner	= pTable;
+
+	m_pControl	= new CVIEW_Table_Diagram_Control(this, pTable);
+
+	wxCommandEvent	dummy;
+
+	On_Size_Fit(dummy);
+}
+
+//---------------------------------------------------------
+CVIEW_Table_Diagram::~CVIEW_Table_Diagram(void)
+{
+	m_pOwner->View_Closes(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CVIEW_Table_Diagram::_Create_Menu(void)
+{
+	wxMenu	*pMenu	= new wxMenu();
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DIAGRAM_PARAMETERS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DIAGRAM_SIZE_FIT);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DIAGRAM_SIZE_INC);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DIAGRAM_SIZE_DEC);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_TO_CLIPBOARD);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+wxToolBarBase * CVIEW_Table_Diagram::_Create_ToolBar(void)
+{
+	wxToolBarBase	*pToolBar	= CMD_ToolBar_Create(ID_TB_VIEW_TABLE_DIAGRAM);
+
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_DIAGRAM_PARAMETERS);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_DIAGRAM_SIZE_FIT);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_DIAGRAM_SIZE_INC);
+	CMD_ToolBar_Add_Item(pToolBar, false, ID_CMD_DIAGRAM_SIZE_DEC);
+
+	CMD_ToolBar_Add(pToolBar, LNG("[CAP] Diagram"));
+
+	return( pToolBar );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CVIEW_Table_Diagram::Update_Diagram(void)
+{
+	return( m_pControl->Update_Diagram() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram::On_Parameters(wxCommandEvent &event)
+{
+	m_pControl->Set_Parameters();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram::On_Size_Fit(wxCommandEvent &event)
+{
+	m_pControl->Fit_Size();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram::On_Size_Inc(wxCommandEvent &event)
+{
+	m_pControl->Inc_Size();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram::On_Size_Dec(wxCommandEvent &event)
+{
+	m_pControl->Dec_Size();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram::On_SaveToClipboard(wxCommandEvent &event)
+{
+	m_pControl->SaveToClipboard();
+}
+
+//---------------------------------------------------------
+void CVIEW_Table_Diagram::On_Key_Down(wxKeyEvent &event)
+{
+
+	switch( event.GetKeyCode() )
+	{
+	default:
+		event.Skip();
+		break;
+
+	case WXK_UP:
+		m_pControl->Inc_Size();
+		break;
+
+	case WXK_DOWN:
+		m_pControl->Dec_Size();
+		break;
+
+	case 'C':
+		if( event.GetModifiers() == wxMOD_CONTROL )
+		{
+			m_pControl->SaveToClipboard();
+		}
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/view_table_diagram.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 VIEW_Table_Diagram.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Diagram_H
+#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Diagram_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "view_base.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CVIEW_Table_Diagram : public CVIEW_Base
+{
+public:
+	CVIEW_Table_Diagram(class CWKSP_Table *pTable);
+	virtual ~CVIEW_Table_Diagram(void);
+
+	static class wxToolBarBase *		_Create_ToolBar		(void);
+	static class wxMenu *				_Create_Menu		(void);
+
+	bool								Update_Diagram		(void);
+
+
+private:
+
+	class CVIEW_Table_Diagram_Control	*m_pControl;
+
+	class CWKSP_Table					*m_pOwner;
+
+
+	void								On_Parameters		(wxCommandEvent &event);
+	void								On_Size_Fit			(wxCommandEvent &event);
+	void								On_Size_Inc			(wxCommandEvent &event);
+	void								On_Size_Dec			(wxCommandEvent &event);
+	void								On_SaveToClipboard	(wxCommandEvent &event);
+	void								On_Key_Down			(wxKeyEvent     &event);
+
+
+private:
+
+	DECLARE_EVENT_TABLE()
+	DECLARE_CLASS(CVIEW_Table_Diagram)
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Diagram_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,373 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                       WKSP.cpp                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+#include <wx/imaglist.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+#include "res_dialogs.h"
+
+#include "active.h"
+
+#include "wksp.h"
+
+#include "wksp_module_control.h"
+#include "wksp_module_manager.h"
+
+#include "wksp_data_control.h"
+#include "wksp_data_manager.h"
+#include "wksp_data_layers.h"
+
+#include "wksp_map_control.h"
+#include "wksp_map_manager.h"
+#include "wksp_map_buttons.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_MODULES	= 0,
+	IMG_DATA,
+	IMG_MAPS
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SUBNB_CAPTION_TREE		LNG("Tree")
+#define SUBNB_CAPTION_BUTTONS	LNG("Thumbnails")
+
+//---------------------------------------------------------
+#define SUBNB_CREATE(ID, Name)	pNotebook	= new wxNotebook(this, ID, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE|wxNB_MULTILINE, Name);\
+								pNotebook	->AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));\
+								pNotebook	->IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_TREEVIEW);\
+								pNotebook	->IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_THUMBNAILS);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP	*g_pWKSP	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP, wxNotebook)
+	EVT_NOTEBOOK_PAGE_CHANGING	(ID_WND_WKSP, CWKSP::On_Page_Changing)
+	EVT_NOTEBOOK_PAGE_CHANGED	(ID_WND_WKSP, CWKSP::On_Page_Changed)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP::CWKSP(wxWindow *pParent)
+	: wxNotebook(pParent, ID_WND_WKSP, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE|wxNB_MULTILINE, LNG("[CAP] Workspace"))
+{
+	wxNotebook	*pNotebook;
+
+	//-----------------------------------------------------
+	g_pWKSP		= this;
+
+	//-----------------------------------------------------
+	AssignImageList(new wxImageList(IMG_SIZE_NOTEBOOK, IMG_SIZE_NOTEBOOK, true, 0));
+
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_MODULES);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_DATA);
+	IMG_ADD_TO_NOTEBOOK(ID_IMG_NB_WKSP_MAPS);
+
+	//-----------------------------------------------------
+	m_pModules		= new CWKSP_Module_Control	(this);
+
+	SUBNB_CREATE(ID_WND_WKSP_DATA, LNG("[CAP] Data"));
+	m_pData			= new CWKSP_Data_Control	(pNotebook);
+	m_pData_Buttons	= new CWKSP_Data_Buttons	(pNotebook);
+
+	SUBNB_CREATE(ID_WND_WKSP_MAPS, LNG("[CAP] Maps"));
+	m_pMaps			= new CWKSP_Map_Control		(pNotebook);
+	m_pMaps_Buttons	= new CWKSP_Map_Buttons		(pNotebook);
+}
+
+//---------------------------------------------------------
+void CWKSP::Add_Pages(void)
+{
+	long	lValue;
+
+	AddPage(m_pModules				, LNG("[CAP] Modules")	, false, IMG_MODULES);
+	AddPage(m_pData->GetParent()	, LNG("[CAP] Data")		, false, IMG_DATA);
+	AddPage(m_pMaps->GetParent()	, LNG("[CAP] Maps")		, false, IMG_MAPS);
+
+	((wxNotebook *)m_pData->GetParent())->AddPage(m_pData			, SUBNB_CAPTION_TREE	, false, 0);
+	((wxNotebook *)m_pData->GetParent())->AddPage(m_pData_Buttons	, SUBNB_CAPTION_BUTTONS	, false, 1);
+
+	if( CONFIG_Read(wxT("/BUTTONS_DATA"), wxT("TAB"), lValue) )
+		((wxNotebook *)m_pData->GetParent())->SetSelection((size_t)lValue);
+
+	((wxNotebook *)m_pMaps->GetParent())->AddPage(m_pMaps			, SUBNB_CAPTION_TREE	, false, 0);
+	((wxNotebook *)m_pMaps->GetParent())->AddPage(m_pMaps_Buttons	, SUBNB_CAPTION_BUTTONS	, false, 1);
+
+	if( CONFIG_Read(wxT("/BUTTONS_MAPS"), wxT("TAB"), lValue) )
+		((wxNotebook *)m_pMaps->GetParent())->SetSelection((size_t)lValue);
+}
+
+//---------------------------------------------------------
+CWKSP::~CWKSP(void)
+{
+	CONFIG_Write(wxT("/BUTTONS_DATA"), wxT("TAB"), (long)((wxNotebook *)m_pData->GetParent())->GetSelection());
+	CONFIG_Write(wxT("/BUTTONS_MAPS"), wxT("TAB"), (long)((wxNotebook *)m_pMaps->GetParent())->GetSelection());
+
+	g_pWKSP		= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP::On_Page_Changing(wxNotebookEvent &event)
+{
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP::On_Page_Changed(wxNotebookEvent &event)
+{
+	event.Skip();
+
+	if( event.GetSelection() >= 0 && g_pACTIVE )
+	{
+		CWKSP_Base_Item	*pItem	= NULL;
+
+		if( GetPage(event.GetSelection()) == m_pModules )
+		{
+			pItem	= m_pModules->Get_Item_Selected();
+		}
+		else if( GetPage(event.GetSelection()) == m_pData->GetParent() )
+		{
+			pItem	= m_pData->Get_Item_Selected();
+		}
+		else if( GetPage(event.GetSelection()) == m_pMaps->GetParent() )
+		{
+			pItem	= m_pMaps->Get_Item_Selected();
+		}
+
+		if( pItem )
+		{
+			g_pACTIVE->Set_Active(pItem);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP::On_Command(wxCommandEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		if(	!g_pACTIVE->Get_Item() || !g_pACTIVE->Get_Item()->On_Command(event.GetId()) )
+		{
+			m_pModules->On_Command(event);
+			m_pData   ->On_Command(event);
+			m_pMaps   ->On_Command(event);
+		}
+		break;
+
+	case ID_CMD_WKSP_ITEM_CLOSE:
+		if( GetCurrentPage() )
+		{
+			switch( GetCurrentPage()->GetId() )
+			{
+			case ID_WND_WKSP_MODULES:	m_pModules->On_Command(event);	break;
+			case ID_WND_WKSP_DATA:		m_pData   ->On_Command(event);	break;
+			case ID_WND_WKSP_MAPS:		m_pMaps   ->On_Command(event);	break;
+			}
+		}
+		break;
+
+	case ID_CMD_WKSP_OPEN:
+		Open();
+		break;
+	}
+}
+
+void CWKSP::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		if( !g_pACTIVE->Get_Item() || !g_pACTIVE->Get_Item()->On_Command_UI(event) )
+		{
+			m_pModules->On_Command_UI(event);
+			m_pData   ->On_Command_UI(event);
+			m_pMaps   ->On_Command_UI(event);
+		}
+		break;
+
+	case ID_CMD_WKSP_ITEM_CLOSE:
+		if( GetCurrentPage() )
+		{
+			switch( GetCurrentPage()->GetId() )
+			{
+			case ID_WND_WKSP_MODULES:	m_pModules->On_Command_UI(event);	break;
+			case ID_WND_WKSP_DATA:		m_pData   ->On_Command_UI(event);	break;
+			case ID_WND_WKSP_MAPS:		m_pMaps   ->On_Command_UI(event);	break;
+			}
+		}
+		break;
+
+	case ID_CMD_WKSP_OPEN:
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP::On_Command_Module(wxCommandEvent &event)
+{
+	m_pModules->On_Execute(event);
+}
+
+void CWKSP::On_Command_UI_Module(wxUpdateUIEvent &event)
+{
+	m_pModules->On_Execute_UI(event);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP::Open(void)
+{
+	wxArrayString	File_Paths;
+
+	if( DLG_Open(File_Paths, ID_DLG_WKSP_OPEN) )
+	{
+		MSG_General_Add_Line();
+
+		for(size_t i=0; i<File_Paths.GetCount(); i++)
+		{
+			Open(File_Paths[i]);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP::Open(const wxChar *File_Name)
+{
+	return(	m_pModules	->Get_Manager()->Open(File_Name)
+		||	m_pData		->Get_Manager()->Open(File_Name)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,139 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                        WKSP.h                         //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/notebook.h>
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP : public wxNotebook
+{
+public:
+	CWKSP(wxWindow *pParent);
+	virtual ~CWKSP(void);
+
+	void							Add_Pages				(void);
+
+	void							On_Page_Changing		(wxNotebookEvent &event);
+	void							On_Page_Changed			(wxNotebookEvent &event);
+
+	void							On_Command				(wxCommandEvent  &event);
+	void							On_Command_UI			(wxUpdateUIEvent &event);
+	void							On_Command_Module		(wxCommandEvent  &event);
+	void							On_Command_UI_Module	(wxUpdateUIEvent &event);
+
+	class CWKSP_Module_Control *	Get_Modules				(void)	{	return( m_pModules );		}
+	class CWKSP_Data_Control *		Get_Data				(void)	{	return( m_pData );			}
+	class CWKSP_Data_Buttons *		Get_Data_Buttons		(void)	{	return( m_pData_Buttons );	}
+	class CWKSP_Map_Control *		Get_Maps				(void)	{	return( m_pMaps );			}
+	class CWKSP_Map_Buttons *		Get_Maps_Buttons		(void)	{	return( m_pMaps_Buttons );	}
+
+	bool							Open					(void);
+	bool							Open					(const wxChar *File_Name);
+
+
+private:
+
+	class CWKSP_Module_Control		*m_pModules;
+
+	class CWKSP_Data_Control		*m_pData;
+
+	class CWKSP_Data_Buttons		*m_pData_Buttons;
+
+	class CWKSP_Map_Control			*m_pMaps;
+
+	class CWKSP_Map_Buttons			*m_pMaps_Buttons;
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CWKSP						*g_pWKSP;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,918 @@
+	
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Base_Control.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/image.h>
+#include <wx/imaglist.h>
+
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_dialogs.h"
+#include "res_images.h"
+
+#include "active.h"
+
+#include "wksp.h"
+
+#include "wksp_base_control.h"
+#include "wksp_base_manager.h"
+
+#include "wksp_module_control.h"
+#include "wksp_module_manager.h"
+#include "wksp_module_menu.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_data_layers.h"
+#include "wksp_table.h"
+
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_buttons.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_NO_ITEMS	= 0,
+	IMG_ROOT
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Base_Control, wxTreeCtrl)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Base_Control, wxTreeCtrl)
+	EVT_TREE_ITEM_RIGHT_CLICK	(ID_WND_WKSP_MODULES	, CWKSP_Base_Control::On_Item_RClick)
+	EVT_TREE_DELETE_ITEM		(ID_WND_WKSP_MODULES	, CWKSP_Base_Control::On_Item_Delete)
+	EVT_TREE_SEL_CHANGED		(ID_WND_WKSP_MODULES	, CWKSP_Base_Control::On_Item_SelChanged)
+	EVT_TREE_KEY_DOWN			(ID_WND_WKSP_MODULES	, CWKSP_Base_Control::On_Item_KeyDown)
+
+	EVT_TREE_ITEM_RIGHT_CLICK	(ID_WND_WKSP_DATA		, CWKSP_Base_Control::On_Item_RClick)
+	EVT_TREE_DELETE_ITEM		(ID_WND_WKSP_DATA		, CWKSP_Base_Control::On_Item_Delete)
+	EVT_TREE_SEL_CHANGED		(ID_WND_WKSP_DATA		, CWKSP_Base_Control::On_Item_SelChanged)
+	EVT_TREE_KEY_DOWN			(ID_WND_WKSP_DATA		, CWKSP_Base_Control::On_Item_KeyDown)
+
+	EVT_TREE_ITEM_RIGHT_CLICK	(ID_WND_WKSP_MAPS		, CWKSP_Base_Control::On_Item_RClick)
+	EVT_TREE_DELETE_ITEM		(ID_WND_WKSP_MAPS		, CWKSP_Base_Control::On_Item_Delete)
+	EVT_TREE_SEL_CHANGED		(ID_WND_WKSP_MAPS		, CWKSP_Base_Control::On_Item_SelChanged)
+	EVT_TREE_KEY_DOWN			(ID_WND_WKSP_MAPS		, CWKSP_Base_Control::On_Item_KeyDown)
+
+	EVT_LEFT_DOWN				(CWKSP_Base_Control::On_Item_LClick)
+	EVT_LEFT_DCLICK				(CWKSP_Base_Control::On_Item_LDClick)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Control::CWKSP_Base_Control(wxWindow *pParent, wxWindowID id)
+	: wxTreeCtrl(pParent, id, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS)
+{
+	m_pManager	= NULL;
+
+	AssignImageList(new wxImageList(IMG_SIZE_TREECTRL, IMG_SIZE_TREECTRL, true, 0));
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_NOITEMS);
+}
+
+//---------------------------------------------------------
+CWKSP_Base_Control::~CWKSP_Base_Control(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Set_Manager(CWKSP_Base_Manager *pManager)
+{
+	if( m_pManager == NULL )
+	{
+		m_pManager	= pManager;
+
+		AddRoot		(m_pManager->Get_Name(), IMG_ROOT, IMG_ROOT, m_pManager);
+		AppendItem	(m_pManager->GetId(), LNG("[CAP] [no items]"), IMG_NO_ITEMS, IMG_NO_ITEMS, NULL);
+		Expand		(m_pManager->GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Command(wxCommandEvent &event)
+{
+	//-----------------------------------------------------
+	if( event.GetId() == ID_CMD_WKSP_ITEM_CLOSE )
+	{
+		_Del_Active(false);
+
+		return;
+	}
+
+	//-----------------------------------------------------
+	if( event.GetId() == ID_CMD_WKSP_ITEM_SHOW )
+	{
+		_Show_Active();
+
+		return;
+	}
+
+	//-----------------------------------------------------
+	if( event.GetId() == ID_CMD_WKSP_ITEM_SETTINGS_LOAD && Get_Selection_Count() > 1 )
+	{
+		_Load_Settings();
+
+		return;
+	}
+
+	//-----------------------------------------------------
+	if( event.GetId() == ID_CMD_WKSP_ITEM_SETTINGS_COPY && Get_Selection_Count() > 0 )
+	{
+		_Copy_Settings();
+
+		return;
+	}
+
+	//-----------------------------------------------------
+	if( m_pManager->On_Command(event.GetId()) )
+	{
+		return;
+	}
+
+	//-----------------------------------------------------
+	CWKSP_Base_Item	*pItem	= Get_Item_Selected();
+
+	if( pItem )
+	{
+		pItem->On_Command(event.GetId());
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Command_UI(wxUpdateUIEvent &event)
+{
+	//-----------------------------------------------------
+	if( m_pManager->On_Command_UI(event) )
+	{
+		return;
+	}
+
+	//-----------------------------------------------------
+	CWKSP_Base_Item	*pItem	= Get_Item_Selected();
+
+	if( pItem )
+	{
+		pItem->On_Command_UI(event);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Add_Item(CWKSP_Base_Item *pItem, int Image, int selImage, bool bSort)
+{
+	if( pItem != NULL && pItem->Get_Manager() == m_pManager )
+	{
+		if( m_pManager->Get_Count() == 1 )
+		{
+			DeleteChildren(m_pManager->GetId());
+		}
+
+		AppendItem(m_pManager->GetId(), pItem->Get_Name(), Image, selImage, pItem);
+
+		if( bSort )
+		{
+			SortChildren(m_pManager->GetId());
+		}
+
+		Expand(m_pManager->GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Del_Item(CWKSP_Base_Item *pItem, bool bSilent)
+{
+	//-----------------------------------------------------
+	if( (	pItem == NULL	)
+	||	(	pItem->Get_Type()	== WKSP_ITEM_Table
+		&&	(	((CWKSP_Table *)pItem)->Get_Owner()->Get_Type() == WKSP_ITEM_Shapes
+			||	((CWKSP_Table *)pItem)->Get_Owner()->Get_Type() == WKSP_ITEM_TIN	)	)	)
+	{
+		return( false );
+	}
+
+	//-----------------------------------------------------
+	if( pItem == m_pManager )
+	{
+		if( m_pManager->Get_Count() > 0 && (bSilent || _Del_Item_Confirm(pItem)) )
+		{
+			Freeze();
+			if( g_pData_Buttons )
+			{
+				g_pData_Buttons->Freeze();
+			}
+
+			DeleteChildren	(m_pManager->GetId());
+			AppendItem		(m_pManager->GetId(), LNG("[CAP] [no items]"), 0, 0, NULL);
+			Expand			(m_pManager->GetId());
+
+			if( g_pModule_Ctrl && m_pManager->Get_Type() == WKSP_ITEM_Module_Manager )
+			{
+				g_pModules->Get_Modules_Menu()->Update();
+			}
+
+			Thaw();
+
+			if( g_pData_Buttons )
+			{
+				g_pData_Buttons->Thaw();
+				g_pData_Buttons->Update_Buttons();
+			}
+
+			if( g_pMap_Buttons )
+			{
+				g_pMap_Buttons->Update_Buttons();
+			}
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		if( bSilent || _Del_Item_Confirm(pItem) )
+		{
+			CWKSP_Base_Manager	*pItem_Manager	= pItem->Get_Manager();
+
+			Freeze();
+
+			Delete(pItem->GetId());
+
+			if( pItem_Manager != NULL && pItem_Manager->Get_Count() == 0 )
+			{
+				Thaw();
+
+				if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager )
+				{
+					g_pData_Buttons->Update_Buttons();
+				}
+
+				if( m_pManager->Get_Type() == WKSP_ITEM_Map_Manager )
+				{
+					g_pMap_Buttons->Update_Buttons();
+				}
+
+				return( _Del_Item(pItem_Manager, true) );
+			}
+
+			if( m_pManager->Get_Type() == WKSP_ITEM_Module_Manager )
+			{
+				g_pModules->Get_Modules_Menu()->Update();
+			}
+
+			if( pItem_Manager != NULL && pItem_Manager->Get_Type() == WKSP_ITEM_Map )
+			{
+				((CWKSP_Map *)pItem_Manager)->View_Refresh(false);
+			}
+
+			Thaw();
+
+			Refresh();
+
+			if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager )
+			{
+				g_pData_Buttons->Update_Buttons();
+			}
+
+			if( m_pManager->Get_Type() == WKSP_ITEM_Map_Manager )
+			{
+				g_pMap_Buttons->Update_Buttons();
+			}
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Del_Item_Confirm(CWKSP_Base_Item *pItem)
+{
+	if( DLG_Message_Confirm(ID_DLG_DELETE) )
+	{
+		if( m_pManager->Get_Type() == WKSP_ITEM_Data_Manager )
+		{
+			return( g_pData->Save_Modified(pItem) );
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Item * CWKSP_Base_Control::Get_Item_Selected(void)
+{
+	wxTreeItemId	ID;
+
+	if( GetWindowStyle() & wxTR_MULTIPLE )
+	{
+		wxArrayTreeItemIds	IDs;
+
+		if( GetSelections(IDs) == 1 )
+		{
+			ID	= IDs[0];
+		}
+	}
+	else
+	{
+		ID	= GetSelection();
+	}
+
+	return( ID.IsOk() ? (CWKSP_Base_Item *)GetItemData(ID) : NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::Set_Item_Selected(CWKSP_Base_Item *pItem, bool bKeepMultipleSelection)
+{
+	if( pItem && pItem->Get_Control() == this && pItem->GetId().IsOk() )
+	{
+		bool	bSelect	= bKeepMultipleSelection ? !IsSelected(pItem->GetId()) : true;
+
+		if( !bKeepMultipleSelection )
+		{
+			UnselectAll();
+		}
+
+		SelectItem(pItem->GetId(), bSelect);
+
+		Refresh();
+
+		_Set_Active();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+int CWKSP_Base_Control::Get_Selection_Count(void)
+{
+	if( GetWindowStyle() & wxTR_MULTIPLE )
+	{
+		wxArrayTreeItemIds	IDs;
+
+		return( GetSelections(IDs) );
+	}
+	else
+	{
+		wxTreeItemId	ID	= GetSelection();
+
+		return( ID.IsOk() ? 1 : 0 );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Base_Control::Get_Context_Menu(void)
+{
+	wxMenu			*pMenu	= NULL;
+	CWKSP_Base_Item	*pItem	= Get_Item_Selected();
+
+	if( pItem )
+	{
+		pMenu	= pItem->Get_Menu();
+	}
+	else if( GetWindowStyle() & wxTR_MULTIPLE )
+	{
+		wxArrayTreeItemIds	IDs;
+
+		if( GetSelections(IDs) > 0 )
+		{
+			pMenu	= new wxMenu;
+
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SHOW);
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SETTINGS_LOAD);
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SETTINGS_COPY);
+		}
+	}
+
+	if( pMenu == NULL )
+	{
+		pMenu	= new wxMenu;
+
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Set_Active(void)
+{
+	if( g_pACTIVE )
+	{
+		g_pACTIVE->Set_Active(Get_Item_Selected());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Del_Active(bool bSilent)
+{
+	wxTreeItemId	ID;
+
+	if( GetWindowStyle() & wxTR_MULTIPLE )
+	{
+		wxArrayTreeItemIds	IDs;
+
+		if( GetSelections(IDs) > 0 && ((CWKSP_Base_Item *)GetItemData(IDs[0]))->Get_Control() == this )
+		{
+			if( DLG_Message_Confirm(ID_DLG_DELETE)
+			&&	(m_pManager->Get_Type() != WKSP_ITEM_Data_Manager || g_pData->Save_Modified_Sel()) )
+			{
+				for(size_t i=0; i<IDs.GetCount(); i++)
+				{
+					if( IDs[i].IsOk() )
+					{
+						_Del_Item((CWKSP_Base_Item *)GetItemData(IDs[i]), true);
+					}
+				}
+			}
+		}
+	}
+	else
+	{
+		ID	= GetSelection();
+
+		if( ID.IsOk() && ((CWKSP_Base_Item *)GetItemData(ID))->Get_Control() == this )
+		{
+			_Del_Item((CWKSP_Base_Item *)GetItemData(ID), bSilent);
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Show_Active(void)
+{
+	wxArrayTreeItemIds	IDs;
+
+	if( (GetWindowStyle() & wxTR_MULTIPLE) != 0 && GetSelections(IDs) > 0 && ((CWKSP_Base_Item *)GetItemData(IDs[0]))->Get_Control() == this )
+	{
+		int				iMap;
+		size_t			iItem;
+		CWKSP_Base_Item	*pItem;
+
+		for(iItem=0, iMap=0; iItem<IDs.GetCount(); iItem++)
+		{
+			if( IDs[iItem].IsOk() )
+			{
+				pItem	= (CWKSP_Base_Item *)GetItemData(IDs[iItem]);
+
+				switch( pItem->Get_Type() )
+				{
+				case WKSP_ITEM_Grid:
+				case WKSP_ITEM_Shapes:
+				case WKSP_ITEM_TIN:
+				case WKSP_ITEM_PointCloud:
+					iMap	= 1;
+					break;
+
+				case WKSP_ITEM_Table:
+					((CWKSP_Table *)pItem)->Set_View(true);
+					break;
+
+				default:
+					break;
+				}
+			}
+		}
+
+		if( iMap && (iMap = DLG_Maps_Add()) >= 0 )
+		{
+			for(iItem=0; iItem<IDs.GetCount(); iItem++)
+			{
+				if( IDs[iItem].IsOk() )
+				{
+					pItem	= (CWKSP_Base_Item *)GetItemData(IDs[iItem]);
+
+					switch( pItem->Get_Type() )
+					{
+					case WKSP_ITEM_Grid:
+					case WKSP_ITEM_Shapes:
+					case WKSP_ITEM_TIN:
+					case WKSP_ITEM_PointCloud:
+						g_pMaps->Add((CWKSP_Layer *)pItem, g_pMaps->Get_Map(iMap));
+						break;
+
+					default:
+						break;
+					}
+				}
+			}
+
+			g_pMaps->Get_Map(iMap)->View_Show(true);
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Load_Settings(void)
+{
+	wxString		File_Path;
+	CSG_MetaData	Data;
+
+	if( Get_Selection_Count() > 0 && DLG_Open(File_Path, ID_DLG_PARAMETERS_OPEN) && Data.Load(File_Path.c_str()) )
+	{
+		if(	GetWindowStyle() & wxTR_MULTIPLE )
+		{
+			wxArrayTreeItemIds	IDs;
+
+			if( GetSelections(IDs) > 0 )
+			{
+				for(size_t i=0; i<IDs.GetCount(); i++)
+				{
+					_Load_Settings(&Data, (CWKSP_Base_Item *)GetItemData(IDs[i]));
+				}
+			}
+		}
+		else
+		{
+			_Load_Settings(&Data, Get_Item_Selected());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Load_Settings(CSG_MetaData *pData, CWKSP_Base_Item *pItem)
+{
+	if( pData && pItem && pItem->Get_Parameters() )
+	{
+		if( pItem->Get_Parameters()->Serialize(*pData, false) )
+		{
+			pItem->Parameters_Changed();
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void	DLG_Copy_Settings(CSG_Table &List, CWKSP_Base_Item *pItem)
+{
+	if( pItem )
+	{
+		if( pItem->is_Manager() )
+		{
+			for(int i=0; i<((CWKSP_Base_Manager *)pItem)->Get_Count(); i++)
+			{
+				DLG_Copy_Settings(List, ((CWKSP_Base_Manager *)pItem)->Get_Item(i));
+			}
+		}
+		else if( pItem->Get_Parameters() )
+		{
+			CSG_Table_Record	*pEntry	= List.Add_Record();
+
+			pEntry->Set_Value(0, CSG_String::Format(SG_T("[%s] %s"), pItem->Get_Manager()->Get_Name().c_str(), pItem->Get_Name().c_str()).c_str());
+			pEntry->Set_Value(1, (long)pItem->Get_Parameters());
+		}
+	}
+}
+
+CSG_Parameters *	DLG_Copy_Settings(void)
+{
+	CSG_Table	List;
+
+	List.Add_Field(SG_T("NAME"), SG_DATATYPE_String);
+	List.Add_Field(SG_T("PRMS"), SG_DATATYPE_Int);
+
+	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_Grids());
+	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_Shapes());
+	DLG_Copy_Settings(List, (CWKSP_Base_Item *)g_pData->Get_TINs());
+
+	if( List.Get_Count() > 0 )
+	{
+		int			i;
+		wxString	*pItems;
+
+		pItems	= new wxString[List.Get_Count()];
+
+		for(i=0; i<List.Get_Count(); i++)
+		{
+			pItems[i]	= List.Get_Record(i)->asString(0);
+		}
+
+		wxSingleChoiceDialog	dlg(MDI_Get_Top_Window(),
+			LNG("Copy Settings from..."),
+			LNG("[DLG] Select a layer to copy settings from it."),
+			List.Get_Count(), pItems
+		);
+
+		bool	bOk	= dlg.ShowModal() == wxID_OK;
+
+		delete[](pItems);
+
+		if( bOk )
+		{
+			return( (CSG_Parameters *)List.Get_Record(dlg.GetSelection())->asInt(1) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Copy_Settings(CSG_Parameters *pParameters, CWKSP_Base_Item *pItem)
+{
+	if( pParameters && pItem && pParameters != pItem->Get_Parameters() )
+	{
+		CSG_String	sName;
+
+		if( pParameters->Get_Parameter("OBJECT_NAME") && pItem->Get_Parameters()->Get_Parameter("OBJECT_NAME") )
+		{
+			sName	= pItem->Get_Parameters()->Get_Parameter("OBJECT_NAME")->asString();
+		}
+
+		if( pItem->Get_Parameters()->Assign_Values(pParameters) )
+		{
+			if( sName.Length() > 0 && pItem->Get_Parameters()->Get_Parameter("OBJECT_NAME") )
+			{
+				pItem->Get_Parameters()->Get_Parameter("OBJECT_NAME")->Set_Value(sName);
+			}
+
+			pItem->Parameters_Changed();
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Control::_Copy_Settings(void)
+{
+	wxArrayTreeItemIds	IDs;
+	CSG_Parameters		*pParameters;
+
+	if( Get_Selection_Count() > 0 && (pParameters = DLG_Copy_Settings()) != NULL )
+	{
+		if(	(GetWindowStyle() & wxTR_MULTIPLE) && GetSelections(IDs) > 0 )
+		{
+			for(size_t i=0; i<IDs.GetCount(); i++)
+			{
+				_Copy_Settings(pParameters, (CWKSP_Base_Item *)GetItemData(IDs[i]));
+			}
+
+			return( true );
+		}
+		else
+		{
+			return( _Copy_Settings(pParameters, Get_Item_Selected()) );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Item_LClick(wxMouseEvent &event)
+{
+	_Set_Active();
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Item_LDClick(wxMouseEvent &event)
+{
+	CWKSP_Base_Item	*pItem;
+
+	if( (pItem = Get_Item_Selected()) != NULL )
+	{
+		pItem->On_Command(ID_CMD_WKSP_ITEM_RETURN);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Item_RClick(wxTreeEvent &event)
+{
+	if( Get_Selection_Count() <= 1 )
+	{
+	//	SelectItem(event.GetItem());
+
+		_Set_Active();
+	}
+
+	wxMenu	*pMenu	= Get_Context_Menu();
+
+	if( pMenu )
+	{
+		PopupMenu(pMenu);
+
+		delete(pMenu);
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Item_KeyDown(wxTreeEvent &event)
+{
+	CWKSP_Base_Item	*pItem;
+
+	if( event.GetKeyCode() == WXK_DELETE )
+	{
+		_Del_Active(false);
+	}
+	else if( (pItem = Get_Item_Selected()) != NULL )
+	{
+		switch( event.GetKeyCode() )
+		{
+		default:
+			pItem->On_Command(event.GetKeyCode());
+			break;
+
+		case WXK_RETURN:
+			pItem->On_Command(ID_CMD_WKSP_ITEM_RETURN);
+			break;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Item_SelChanged(wxTreeEvent &event)
+{
+	_Set_Active();
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Base_Control::On_Item_Delete(wxTreeEvent &event)
+{
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,142 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Base_Control.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/treectrl.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Base_Control : public wxTreeCtrl
+{
+	DECLARE_CLASS(CWKSP_Base_Control)
+
+public:
+	CWKSP_Base_Control(wxWindow *pParent, wxWindowID id);
+	virtual ~CWKSP_Base_Control(void);
+
+	class CWKSP_Base_Item *		Get_Item_Selected	(void);
+	bool						Set_Item_Selected	(class CWKSP_Base_Item *pItem, bool bKeepMultipleSelection = false);
+	int							Get_Selection_Count	(void);
+
+	void						On_Command			(wxCommandEvent  &event);
+	void						On_Command_UI		(wxUpdateUIEvent &event);
+
+	void						On_Item_LClick		(wxMouseEvent    &event);
+	void						On_Item_LDClick		(wxMouseEvent    &event);
+	void						On_Item_RClick		(wxTreeEvent     &event);
+	void						On_Item_SelChanged	(wxTreeEvent     &event);
+	void						On_Item_Delete		(wxTreeEvent     &event);
+	void						On_Item_KeyDown		(wxTreeEvent     &event);
+
+	wxMenu *					Get_Context_Menu	(void);
+
+
+protected:
+
+	class CWKSP_Base_Manager	*m_pManager;
+
+
+	bool						_Set_Manager		(class CWKSP_Base_Manager *pManager);
+
+	bool						_Add_Item			(class CWKSP_Base_Item *pItem, int Image, int selImage, bool bSort = true);
+	bool						_Del_Item			(class CWKSP_Base_Item *pItem, bool bSilent);
+	bool						_Del_Item_Confirm	(class CWKSP_Base_Item *pItem);
+
+	bool						_Set_Active			(void);
+	bool						_Del_Active			(bool bSilent);
+
+	bool						_Show_Active		(void);
+
+	bool						_Load_Settings		(void);
+	bool						_Load_Settings		(class CSG_MetaData *pData, class CWKSP_Base_Item *pItem);
+
+	bool						_Copy_Settings		(void);
+	bool						_Copy_Settings		(class CSG_Parameters *pParameters, class CWKSP_Base_Item *pItem);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,231 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Base_Item.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "active.h"
+
+#include "wksp_base_item.h"
+#include "wksp_base_manager.h"
+
+#include "wksp_module_control.h"
+#include "wksp_data_control.h"
+#include "wksp_map_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Item *	Get_Active_Item(void)
+{
+	return( g_pACTIVE ? g_pACTIVE->Get_Item() : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Item::CWKSP_Base_Item(void)
+{
+	m_bManager	= false;
+	m_pManager	= NULL;
+	m_ID		= 0;
+}
+
+//---------------------------------------------------------
+CWKSP_Base_Item::~CWKSP_Base_Item(void)
+{
+	if( g_pACTIVE && g_pACTIVE->Get_Item() == this )
+	{
+		g_pACTIVE->Set_Active(NULL);
+	}
+
+	if( m_pManager )
+	{
+		m_pManager->Del_Item(this);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Base_Item::Get_Index(void)
+{
+	int		iItem;
+
+	if( m_pManager )
+	{
+		for(iItem=0; iItem<m_pManager->Get_Count(); iItem++)
+		{
+			if( this == m_pManager->Get_Item(iItem) )
+			{
+				return( iItem );
+			}
+		}
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+CWKSP_Base_Control * CWKSP_Base_Item::Get_Control(void)
+{
+	switch( Get_Type() )
+	{
+    default:
+        return( NULL );
+
+	case WKSP_ITEM_Module_Manager:
+	case WKSP_ITEM_Module_Library:
+	case WKSP_ITEM_Module:
+		return( g_pModule_Ctrl );
+
+	case WKSP_ITEM_Data_Manager:
+	case WKSP_ITEM_Table_Manager:
+	case WKSP_ITEM_Table:
+	case WKSP_ITEM_Shapes_Manager:
+	case WKSP_ITEM_Shapes_Type:
+	case WKSP_ITEM_Shapes:
+	case WKSP_ITEM_TIN_Manager:
+	case WKSP_ITEM_TIN:
+	case WKSP_ITEM_PointCloud_Manager:
+	case WKSP_ITEM_PointCloud:
+	case WKSP_ITEM_Grid_Manager:
+	case WKSP_ITEM_Grid_System:
+	case WKSP_ITEM_Grid:
+		return( g_pData_Ctrl );
+
+	case WKSP_ITEM_Map_Manager:
+	case WKSP_ITEM_Map:
+	case WKSP_ITEM_Map_Layer:
+		return( g_pMap_Ctrl );
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Item::is_Selected(void)
+{
+	CWKSP_Base_Control	*pControl	= Get_Control();
+
+	return( pControl != NULL && pControl->IsSelected(GetId()) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Item::On_Command(int Cmd_ID)
+{
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Item::On_Command_UI(wxUpdateUIEvent &event)
+{
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Base_Item::Parameters_Changed(void)
+{
+	if( Get_Control() && GetId().IsOk() )
+	{
+		Get_Control()->SetItemText(GetId(), Get_Name());
+	}
+
+	if( g_pACTIVE )
+	{
+		g_pACTIVE->Update_Description();
+		g_pACTIVE->Update(this, false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_item.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,187 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   WKSP_Base_Item.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Item_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Item_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/event.h>
+#include <wx/menu.h>
+#include <wx/treectrl.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+typedef enum
+{
+	WKSP_ITEM_Module_Manager,
+	WKSP_ITEM_Module_Library,
+	WKSP_ITEM_Module,
+
+	WKSP_ITEM_Data_Manager,
+
+	WKSP_ITEM_Table_Manager,
+	WKSP_ITEM_Table,
+
+	WKSP_ITEM_Shapes_Manager,
+	WKSP_ITEM_Shapes_Type,
+	WKSP_ITEM_Shapes,
+
+	WKSP_ITEM_TIN_Manager,
+	WKSP_ITEM_TIN,
+
+	WKSP_ITEM_PointCloud_Manager,
+	WKSP_ITEM_PointCloud,
+
+	WKSP_ITEM_Grid_Manager,
+	WKSP_ITEM_Grid_System,
+	WKSP_ITEM_Grid,
+
+	WKSP_ITEM_Map_Manager,
+	WKSP_ITEM_Map,
+	WKSP_ITEM_Map_Layer,
+
+	WKSP_ITEM_Undefined
+}
+TWKSP_Item;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Base_Item : public wxTreeItemData
+{
+	friend class CWKSP_Base_Manager;
+
+public:
+	CWKSP_Base_Item(void);
+	virtual ~CWKSP_Base_Item(void);
+
+	virtual TWKSP_Item				Get_Type			(void)	= 0;
+
+	virtual wxString				Get_Name			(void)	= 0;
+	virtual wxString				Get_Description		(void)	= 0;
+
+	virtual wxMenu *				Get_Menu			(void)	= 0;
+
+	virtual bool					On_Command			(int Cmd_ID);
+	virtual bool					On_Command_UI		(wxUpdateUIEvent &event);
+
+	virtual class CSG_Parameters *	Get_Parameters		(void)	{	return( NULL );			}
+	virtual void					Parameters_Changed	(void);
+
+	class CWKSP_Base_Control *		Get_Control			(void);
+	class CWKSP_Base_Manager *		Get_Manager			(void)	{	return( m_pManager );	}
+
+	int								Get_ID				(void)	{	return( m_ID );			}
+	int								Get_Index			(void);
+
+	bool							is_Manager			(void)	{	return( m_bManager );	}
+	bool							is_Selected			(void);
+
+
+protected:
+
+
+private:
+
+	bool							m_bManager;
+
+	int								m_ID;
+
+	class CWKSP_Base_Manager		*m_pManager;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Item *				Get_Active_Item		(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Item_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,349 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Base_Manager.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include "active.h"
+#include "active_parameters.h"
+
+#include "wksp_module_control.h"
+#include "wksp_data_control.h"
+#include "wksp_data_manager.h"
+#include "wksp_map_control.h"
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Manager::CWKSP_Base_Manager(void)
+{
+	m_bManager	= true;
+	m_nItems	= 0;
+	m_Items		= NULL;
+	m_Item_ID	= 0;
+}
+
+//---------------------------------------------------------
+#include <wx/debug.h>
+CWKSP_Base_Manager::~CWKSP_Base_Manager(void)
+{
+	wxASSERT_MSG(m_nItems == 0, wxT("CWKSP_Base_Manager: workspace did not kill each item..."));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Add_Item(CWKSP_Base_Item *pItem)
+{
+	if( pItem )
+	{
+		m_Items				= (CWKSP_Base_Item **)realloc(m_Items, (m_nItems + 1) * sizeof(CWKSP_Base_Item *));
+		m_Items[m_nItems++]	= pItem;
+		pItem->m_pManager	= this;
+		pItem->m_ID			= m_Item_ID++;
+
+		//-------------------------------------------------
+		switch( Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Module_Manager:
+			g_pModule_Ctrl->Add_Library((CWKSP_Module_Library *)pItem);
+			break;
+
+		case WKSP_ITEM_Data_Manager:
+		case WKSP_ITEM_Table_Manager:
+		case WKSP_ITEM_Shapes_Manager:
+		case WKSP_ITEM_Shapes_Type:
+		case WKSP_ITEM_TIN_Manager:
+		case WKSP_ITEM_PointCloud_Manager:
+		case WKSP_ITEM_Grid_Manager:
+		case WKSP_ITEM_Grid_System:
+			g_pData_Ctrl->Add_Item(this, pItem);
+			g_pACTIVE->Update_DataObjects();
+			break;
+
+		case WKSP_ITEM_Map_Manager:
+		case WKSP_ITEM_Map:
+			g_pMap_Ctrl->Add_Item(this, pItem);
+			break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Del_Item(int iItem)
+{
+	return( Del_Item(Get_Item(iItem)) );
+}
+
+bool CWKSP_Base_Manager::Del_Item(CWKSP_Base_Item *pItem)
+{
+	int		iItem;
+
+	if( pItem && (iItem = pItem->Get_Index()) >= 0 && iItem < m_nItems )
+	{
+		m_nItems--;
+
+		for( ; iItem<m_nItems; iItem++)
+		{
+			m_Items[iItem]	= m_Items[iItem + 1];
+		}
+
+		m_Items	= (CWKSP_Base_Item **)realloc(m_Items, m_nItems * sizeof(CWKSP_Base_Item *));
+
+		//-------------------------------------------------
+		switch( Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Data_Manager:
+			g_pData->Del_Manager(pItem);
+			break;
+
+		case WKSP_ITEM_Table_Manager:
+		case WKSP_ITEM_Shapes_Type:
+		case WKSP_ITEM_TIN_Manager:
+		case WKSP_ITEM_PointCloud_Manager:
+		case WKSP_ITEM_Grid_Manager:
+		case WKSP_ITEM_Grid_System:
+			if( g_pACTIVE )
+			{
+				g_pACTIVE->Update_DataObjects();
+			}
+			break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Move_Top(CWKSP_Base_Item *pItem)
+{
+	int		Index, i;
+
+	if( pItem && (Index = pItem->Get_Index()) > 0 )
+	{
+		for(i=Index; i>0; i--)
+		{
+			m_Items[i]	= m_Items[i - 1];
+		}
+
+		m_Items[0]		= pItem;
+
+		Get_Control()->SortChildren(GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Move_Bottom(CWKSP_Base_Item *pItem)
+{
+	int		Index, i;
+
+	if( pItem && (Index = pItem->Get_Index()) < Get_Count() - 1 )
+	{
+		for(i=Index; i<Get_Count()-1; i++)
+		{
+			m_Items[i]	= m_Items[i + 1];
+		}
+
+		m_Items[Get_Count() - 1]	= pItem;
+
+		Get_Control()->SortChildren(GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Move_Up(CWKSP_Base_Item *pItem)
+{
+	int		Index;
+
+	if( pItem && (Index = pItem->Get_Index()) > 0 )
+	{
+		m_Items[Index]		= m_Items[Index - 1];
+		m_Items[Index - 1]	= pItem;
+
+		Get_Control()->SortChildren(GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Move_Down(CWKSP_Base_Item *pItem)
+{
+	int		Index;
+
+	if( pItem && (Index = pItem->Get_Index()) < Get_Count() - 1 )
+	{
+		m_Items[Index]		= m_Items[Index + 1];
+		m_Items[Index + 1]	= pItem;
+
+		Get_Control()->SortChildren(GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Base_Manager::Move_To(CWKSP_Base_Item *pItem, CWKSP_Base_Item *pItem_Dst)
+{
+	if( pItem && pItem_Dst && pItem != pItem_Dst && pItem->Get_Manager() == this && pItem_Dst->Get_Manager() == this )
+	{
+		int		Index, Index_Dst, i;
+
+		Index		= pItem		->Get_Index();
+		Index_Dst	= pItem_Dst	->Get_Index();
+
+		if( Index < Index_Dst )
+		{
+			for(i=Index; i<Index_Dst; i++)
+			{
+				m_Items[i]	= m_Items[i + 1];
+			}
+		}
+		else
+		{
+			for(i=Index; i>Index_Dst; i--)
+			{
+				m_Items[i]	= m_Items[i - 1];
+			}
+		}
+
+		m_Items[Index_Dst]	= pItem;
+
+		Get_Control()->SortChildren(GetId());
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Base_Manager::Get_Items_Count(void)
+{
+	int		iItem, nCount;
+
+	for(iItem=0, nCount=0; iItem<m_nItems; iItem++)
+	{
+		if( m_Items[iItem]->m_bManager )
+		{
+			nCount	+= ((CWKSP_Base_Manager *)m_Items[iItem])->Get_Count();
+		}
+	}
+
+	return( nCount );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_base_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,126 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Base_Manager.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_item.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Base_Manager : public CWKSP_Base_Item
+{
+	friend class CWKSP_Base_Item;
+
+public:
+	CWKSP_Base_Manager(void);
+	virtual ~CWKSP_Base_Manager(void);
+
+	int							Get_Count		(void)		{	return( m_nItems );	}
+
+	CWKSP_Base_Item *			Get_Item		(int iItem)	{	return( iItem >= 0 && iItem < m_nItems ? m_Items[iItem] : NULL );	}
+
+	int							Get_Items_Count	(void);
+
+	bool						Move_Top		(CWKSP_Base_Item *pItem);
+	bool						Move_Bottom		(CWKSP_Base_Item *pItem);
+	bool						Move_Up			(CWKSP_Base_Item *pItem);
+	bool						Move_Down		(CWKSP_Base_Item *pItem);
+	bool						Move_To			(CWKSP_Base_Item *pItem, CWKSP_Base_Item *pItem_Dst);
+
+
+protected:
+
+	bool						Add_Item		(CWKSP_Base_Item *pItem);
+	bool						Del_Item		(CWKSP_Base_Item *pItem);
+	bool						Del_Item		(int iItem);
+
+
+private:
+
+	int							m_nItems, m_Item_ID;
+
+	CWKSP_Base_Item				**m_Items;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Base_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,285 @@
+	
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Data_Control.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+#include <wx/imaglist.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "wksp_data_control.h"
+#include "wksp_data_manager.h"
+#include "wksp_data_layers.h"
+
+#include "wksp_table_manager.h"
+#include "wksp_table.h"
+
+#include "wksp_shapes_manager.h"
+#include "wksp_shapes_type.h"
+#include "wksp_shapes.h"
+
+#include "wksp_tin_manager.h"
+#include "wksp_tin.h"
+
+#include "wksp_grid_manager.h"
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_DATA_MANAGER	= 1,
+
+	IMG_TABLE_MANAGER,
+	IMG_TABLE,
+
+	IMG_SHAPES_MANAGER,
+	IMG_SHAPES_POINT,
+	IMG_SHAPES_POINTS,
+	IMG_SHAPES_LINE,
+	IMG_SHAPES_POLYGON,
+
+	IMG_TIN_MANAGER,
+	IMG_TIN,
+
+	IMG_POINTCLOUD_MANAGER,
+	IMG_POINTCLOUD,
+
+	IMG_GRID_MANAGER,
+	IMG_GRID_SYSTEM,
+	IMG_GRID
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Data_Control, CWKSP_Base_Control)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Data_Control, CWKSP_Base_Control)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Control	*g_pData_Ctrl	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Control::CWKSP_Data_Control(wxWindow *pParent)
+	: CWKSP_Base_Control(pParent, ID_WND_WKSP_DATA)
+{
+	g_pData_Ctrl	= this;
+
+	SetWindowStyle(wxTR_HAS_BUTTONS|wxTR_MULTIPLE);
+
+	//-----------------------------------------------------
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_DATA_MANAGER);
+
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TABLE_MANAGER);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TABLE);
+
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_MANAGER);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINT);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINTS);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_LINE);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POLYGON);
+
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TIN_MANAGER);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TIN);
+
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_POINTCLOUD_MANAGER);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_POINTCLOUD);
+
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID_MANAGER);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID_SYSTEM);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID);
+
+	//-----------------------------------------------------
+	_Set_Manager(new CWKSP_Data_Manager);
+}
+
+//---------------------------------------------------------
+CWKSP_Data_Control::~CWKSP_Data_Control(void)
+{
+	_Del_Item(m_pManager, true);
+
+	g_pData_Ctrl	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline int CWKSP_Data_Control::_Get_Image_ID(CWKSP_Base_Item *pItem)
+{
+	if( pItem )
+	{
+		switch( pItem->Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Data_Manager:		return( IMG_DATA_MANAGER );
+		case WKSP_ITEM_Table_Manager:		return( IMG_TABLE_MANAGER );
+		case WKSP_ITEM_Table:				return( IMG_TABLE );
+		case WKSP_ITEM_Shapes_Manager:		return( IMG_SHAPES_MANAGER );
+
+		case WKSP_ITEM_Shapes_Type:
+		case WKSP_ITEM_Shapes:
+			switch( pItem->Get_Type() == WKSP_ITEM_Shapes
+				?	((CWKSP_Shapes *)pItem)->Get_Shapes()->Get_Type()
+				:	((CWKSP_Shapes_Type *)pItem)->Get_Shapes_Type() )
+			{
+			default:
+			case SHAPE_TYPE_Point:			return( IMG_SHAPES_POINT );
+			case SHAPE_TYPE_Points:			return( IMG_SHAPES_POINTS );
+			case SHAPE_TYPE_Line:			return( IMG_SHAPES_LINE );
+			case SHAPE_TYPE_Polygon:		return( IMG_SHAPES_POLYGON );
+			}
+
+		case WKSP_ITEM_TIN_Manager:			return( IMG_TIN_MANAGER );
+		case WKSP_ITEM_TIN:					return( IMG_TIN );
+		case WKSP_ITEM_PointCloud_Manager:	return( IMG_POINTCLOUD_MANAGER );
+		case WKSP_ITEM_PointCloud:			return( IMG_POINTCLOUD );
+		case WKSP_ITEM_Grid_Manager:		return( IMG_GRID_MANAGER );
+		case WKSP_ITEM_Grid_System:			return( IMG_GRID_SYSTEM );
+		case WKSP_ITEM_Grid:				return( IMG_GRID );
+		}
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Control::Add_Item(CWKSP_Base_Manager *pManager, CWKSP_Base_Item *pItem)
+{
+	if( pManager && pItem )
+	{
+		if( pManager == Get_Manager() )
+		{
+			_Add_Item(pItem, _Get_Image_ID(pItem), _Get_Image_ID(pItem), true);
+
+			return;
+		}
+
+		AppendItem	(pManager->GetId(), pItem->Get_Name(), _Get_Image_ID(pItem), _Get_Image_ID(pItem), pItem);
+		SortChildren(pManager->GetId());
+		Expand		(pManager->GetId());
+
+		//-------------------------------------------------
+		if( g_pData_Buttons )
+		{
+			g_pData_Buttons->Update_Buttons();
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Control::Close(bool bSilent)
+{
+	return( _Del_Item(m_pManager, bSilent) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,117 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Data_Control.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Data_Control : public CWKSP_Base_Control
+{
+	DECLARE_CLASS(CWKSP_Data_Control)
+
+public:
+	CWKSP_Data_Control(wxWindow *pParent);
+	virtual ~CWKSP_Data_Control(void);
+
+	class CWKSP_Data_Manager *	Get_Manager		(void)	{	return( (class CWKSP_Data_Manager *)m_pManager );	}
+
+	void						Add_Item		(class CWKSP_Base_Manager *pManager, class CWKSP_Base_Item *pItem);
+
+	bool						Close			(bool bSilent);
+
+
+private:
+
+	int							_Get_Image_ID	(class CWKSP_Base_Item *pItem);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CWKSP_Data_Control		*g_pData_Ctrl;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,544 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Data_Layers.cpp                  //
+//                                                       //
+//          Copyright (C) 2006 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "active.h"
+
+#include "wksp_data_control.h"
+#include "wksp_data_manager.h"
+#include "wksp_layer.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+
+#include "wksp_data_layers.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SCROLL_RATE		5
+
+#define SCROLL_BAR_DX	wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)
+#define SCROLL_BAR_DY	wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y)
+
+//---------------------------------------------------------
+#define THUMBNAIL_SIZE	75
+#define THUMBNAIL_DIST	5
+
+#define TITLE_FONT		wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Buttons	*g_pData_Buttons	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Data_Button, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Data_Button, wxPanel)
+	EVT_PAINT			(CWKSP_Data_Button::On_Paint)
+	EVT_LEFT_DOWN		(CWKSP_Data_Button::On_Mouse_LDown)
+	EVT_LEFT_DCLICK		(CWKSP_Data_Button::On_Mouse_LDClick)
+	EVT_RIGHT_DOWN		(CWKSP_Data_Button::On_Mouse_RDown)
+END_EVENT_TABLE()
+
+//---------------------------------------------------------
+CWKSP_Data_Button::CWKSP_Data_Button(wxWindow *pParent, class CWKSP_Layer *pLayer)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER)
+{
+	m_pLayer	= pLayer;
+	m_pObject	= pLayer->Get_Object();
+	m_Title		= pLayer->Get_Name();
+}
+
+//---------------------------------------------------------
+CWKSP_Data_Button::CWKSP_Data_Button(wxWindow *pParent, const wxChar *Title)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, 0)
+{
+	m_pLayer	= NULL;
+	m_pObject	= NULL;
+	m_Title		= Title;
+
+	int			x, y, d, e;
+	wxClientDC	dc(this);
+	wxFont		Font(TITLE_FONT);
+	dc.GetTextExtent(m_Title, &x, &y, &d, &e, &Font);
+	SetSize(-1, -1, x + 4, y + d + e + 4);
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Button::On_Paint(wxPaintEvent &event)
+{
+	wxPaintDC	dc(this);
+	wxRect		r(wxPoint(0, 0), GetClientSize());
+
+	if( m_pLayer && m_pLayer->Get_Object() && m_pLayer->GetId().IsOk() )
+	{
+		if( g_pData->Exists(m_pObject) )
+		{
+			SetToolTip(m_pLayer->Get_Name());
+
+			dc.DrawBitmap(m_pLayer->Get_Thumbnail(r.GetWidth() - 1, r.GetHeight() - 1), r.GetLeft(), r.GetTop(), true);
+
+			if( m_pLayer->is_Selected() )
+			{
+				dc.SetPen(wxPen(((CWKSP_Data_Buttons *)GetParent())->Get_Active_Color()));
+				Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);	r.Deflate(1);
+				Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);	r.Deflate(1);
+				Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);
+			}
+		}
+	}
+	else
+	{
+		dc.DrawLine(0, 0, r.GetWidth(), 0);
+		dc.DrawLine(0, 1, r.GetWidth(), 1);
+		dc.SetFont(TITLE_FONT);
+		dc.DrawText(m_Title, 2, 2);
+		dc.DrawLine(0, r.GetBottom(), GetClientSize().x, r.GetBottom());
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Button::_Select(bool bKeepOthers)
+{
+	if( m_pLayer && g_pData->Exists(m_pObject) )
+	{
+		g_pData_Ctrl->Set_Item_Selected(m_pLayer, bKeepOthers);
+
+		GetParent()->Refresh();
+
+		return( true );
+	}
+
+	m_pObject	= NULL;
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Button::On_Mouse_LDown(wxMouseEvent &event)
+{
+	_Select(event.ControlDown());
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Button::On_Mouse_LDClick(wxMouseEvent &event)
+{
+	if( _Select(false) )
+	{
+		m_pLayer->On_Command(ID_CMD_WKSP_ITEM_RETURN);
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Button::On_Mouse_RDown(wxMouseEvent &event)
+{
+	if( g_pData_Ctrl->Get_Selection_Count() <= 1 )
+	{
+		_Select(false);
+	}
+
+	wxMenu	*pMenu	= g_pData_Ctrl->Get_Context_Menu();
+
+	if( pMenu )
+	{
+		GetParent()->PopupMenu(pMenu, GetParent()->ScreenToClient(ClientToScreen(event.GetPosition())));
+
+		delete(pMenu);
+
+		return;
+	}
+
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Data_Buttons, wxScrolledWindow)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Data_Buttons, wxScrolledWindow)
+	EVT_RIGHT_DOWN		(CWKSP_Data_Buttons::On_Mouse_RDown)
+	EVT_SIZE			(CWKSP_Data_Buttons::On_Size)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Buttons::CWKSP_Data_Buttons(wxWindow *pParent)
+	: wxScrolledWindow(pParent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE)
+{
+	g_pData_Buttons	= this;
+
+	m_xScroll		= 0;
+	m_yScroll		= 0;
+
+	m_Items			= NULL;
+	m_nItems		= 0;
+
+	//-----------------------------------------------------
+	bool	bValue;
+	long	lValue;
+
+	m_Size			= CONFIG_Read(wxT("/BUTTONS_DATA"), wxT("SIZE")		, lValue) ? (int)lValue : 75;
+	m_bCategorised	= CONFIG_Read(wxT("/BUTTONS_DATA"), wxT("CATEGORY")	, bValue) ?      bValue : true;
+	m_Active_Color	= CONFIG_Read(wxT("/BUTTONS_DATA"), wxT("SELCOLOR")	, lValue) ?      lValue : Get_Color_asInt(SYS_Get_Color(wxSYS_COLOUR_BTNSHADOW));
+
+	//-----------------------------------------------------
+	m_Parameters.Create(this, LNG("Options for Data Thumbnails"), LNG(""));
+
+	m_Parameters.Add_Value(
+		NULL, "SIZE"		, LNG("Thumbnail Size"),
+		LNG(""),
+		PARAMETER_TYPE_Int, m_Size, 10, true
+	);
+
+	m_Parameters.Add_Value(
+		NULL, "CATEGORY"	, LNG("Show Categories"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, m_bCategorised
+	);
+
+	m_Parameters.Add_Value(
+		NULL, "SELCOLOR"	, LNG("Selection Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, m_Active_Color
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Data_Buttons::~CWKSP_Data_Buttons(void)
+{
+	CONFIG_Write(wxT("/BUTTONS_DATA"), wxT("SIZE")    , (long)m_Parameters("SIZE")	  ->asInt());
+	CONFIG_Write(wxT("/BUTTONS_DATA"), wxT("CATEGORY"),       m_Parameters("CATEGORY")->asBool());
+	CONFIG_Write(wxT("/BUTTONS_DATA"), wxT("SELCOLOR"),       m_Parameters("SELCOLOR")->asColor());
+
+	_Del_Items();
+
+	g_pData_Buttons	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Buttons::On_Mouse_RDown(wxMouseEvent &event)
+{
+	if( DLG_Parameters(&m_Parameters) )
+	{
+		m_Size			= m_Parameters("SIZE")		->asInt();
+		m_bCategorised	= m_Parameters("CATEGORY")	->asBool();
+		m_Active_Color	= m_Parameters("SELCOLOR")	->asColor();
+
+		Update_Buttons();
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Buttons::On_Size(wxSizeEvent &event)
+{
+	_Set_Positions();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Buttons::Update_Buttons(void)
+{
+	Freeze();
+
+	_Del_Items();
+	_Add_Items(g_pData);
+
+	Scroll(0, 0);
+
+	_Set_Positions();
+
+	Thaw();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Buttons::_Set_Positions(void)
+{
+	int		xSize, ySize, xPos, yPos, xAdd, yAdd, i, x, y;
+
+	xSize	= GetClientSize().x - SCROLL_BAR_DX;
+
+	if( xSize < m_Size + THUMBNAIL_DIST )
+	{
+		xSize	= m_Size + THUMBNAIL_DIST;
+	}
+
+	xPos	= THUMBNAIL_DIST;
+	yPos	= THUMBNAIL_DIST;
+	xAdd	= 0;
+	yAdd	= 0;
+
+	for(i=0; i<m_nItems; i++)
+	{
+		CWKSP_Data_Button	*pItem	= m_Items[i];
+
+		if( pItem->is_Title() )
+		{
+			xPos	 = THUMBNAIL_DIST;
+			yPos	+= THUMBNAIL_DIST + yAdd;
+
+			CalcScrolledPosition(0, yPos, &x, &y);
+			pItem->SetSize(x, y, xSize + SCROLL_BAR_DX, -1);
+
+			yPos	+= THUMBNAIL_DIST + pItem->GetSize().y;
+			yAdd	 = 0;
+		}
+		else
+		{
+			xAdd	= m_Size;
+
+			if( xPos + xAdd >= xSize )
+			{
+				xPos	 = THUMBNAIL_DIST;
+				yPos	+= yAdd;
+				yAdd	 = THUMBNAIL_DIST + m_Size;
+			}
+
+			yAdd	= m_Size + THUMBNAIL_DIST;
+
+			CalcScrolledPosition(xPos, yPos, &x, &y);
+			pItem->SetSize(x, y, m_Size, m_Size);
+
+			xPos	+= THUMBNAIL_DIST + xAdd;
+		}
+	}
+
+	xSize	+= SCROLL_BAR_DX;
+	ySize	 = SCROLL_BAR_DY + yPos + yAdd;
+
+	if(	m_xScroll != xSize || m_yScroll != ySize )
+	{
+		m_xScroll	= xSize;
+		m_yScroll	= ySize;
+
+		SetScrollbars(SCROLL_RATE, SCROLL_RATE, m_xScroll / SCROLL_RATE, m_yScroll / SCROLL_RATE);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Buttons::_Add_Items(CWKSP_Base_Item *pItem)
+{
+	if( pItem )
+	{
+		switch( pItem->Get_Type() )
+		{
+		default:
+			return( false );
+
+		case WKSP_ITEM_Shapes:
+		case WKSP_ITEM_TIN:
+		case WKSP_ITEM_PointCloud:
+		case WKSP_ITEM_Grid:
+			return( _Add_Item((CWKSP_Layer *)pItem) );
+
+		case WKSP_ITEM_Data_Manager:
+		case WKSP_ITEM_Grid_Manager:
+		case WKSP_ITEM_Shapes_Manager:
+			break;
+
+		case WKSP_ITEM_Grid_System:
+		case WKSP_ITEM_Shapes_Type:
+		case WKSP_ITEM_TIN_Manager:
+		case WKSP_ITEM_PointCloud_Manager:
+			if( m_bCategorised )
+			{
+				_Add_Item(pItem->Get_Name());
+			}
+			break;
+		}
+
+		for(int i=0; i<((CWKSP_Base_Manager *)pItem)->Get_Count(); i++)
+		{
+			_Add_Items(((CWKSP_Base_Manager *)pItem)->Get_Item(i));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Buttons::_Add_Item(CWKSP_Layer *pLayer)
+{
+	if( pLayer )
+	{
+		m_Items	= (CWKSP_Data_Button **)SG_Realloc(m_Items, (m_nItems + 1) * sizeof(CWKSP_Data_Button *));
+		m_Items[m_nItems++]	= new CWKSP_Data_Button(this, pLayer);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Buttons::_Add_Item(const wxChar *Title)
+{
+	if( Title )
+	{
+		m_Items	= (CWKSP_Data_Button **)SG_Realloc(m_Items, (m_nItems + 1) * sizeof(CWKSP_Data_Button *));
+		m_Items[m_nItems++]	= new CWKSP_Data_Button(this, Title);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Buttons::_Del_Items(void)
+{
+	if( m_nItems > 0 )
+	{
+		for(int i=0; i<m_nItems; i++)
+		{
+			delete(m_Items[i]);
+		}
+
+		SG_Free(m_Items);
+	}
+
+	m_Items		= NULL;
+	m_nItems	= 0;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_layers.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,173 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Data_Layers.h                   //
+//                                                       //
+//          Copyright (C) 2006 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Layers_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Layers_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/scrolwin.h>
+
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Data_Button : public wxPanel
+{
+	DECLARE_CLASS(CWKSP_Data_Button)
+
+public:
+	CWKSP_Data_Button(wxWindow *pParent, class CWKSP_Layer *pLayer);
+	CWKSP_Data_Button(wxWindow *pParent, const wxChar *Title);
+	virtual ~CWKSP_Data_Button(void)	{}
+
+	void						On_Paint			(wxPaintEvent &event);
+
+	void						On_Mouse_LDown		(wxMouseEvent &event);
+	void						On_Mouse_LDClick	(wxMouseEvent &event);
+	void						On_Mouse_RDown		(wxMouseEvent &event);
+
+	bool						is_Title			(void)		{	return( m_pLayer == NULL );	}
+
+
+private:
+
+	wxString					m_Title;
+
+	class CWKSP_Layer			*m_pLayer;
+
+	CSG_Data_Object				*m_pObject;
+
+
+	bool						_Select				(bool bKeepOthers);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+class CWKSP_Data_Buttons : public wxScrolledWindow
+{
+	DECLARE_CLASS(CWKSP_Data_Buttons)
+
+public:
+	CWKSP_Data_Buttons(wxWindow *pParent);
+	virtual ~CWKSP_Data_Buttons(void);
+
+	void						On_Mouse_RDown		(wxMouseEvent &event);
+
+	void						On_Size				(wxSizeEvent  &event);
+
+	void						Update_Buttons		(void);
+
+	int							Get_Item_Size		(void)		{	return( m_Size );	}
+	long						Get_Active_Color	(void)		{	return( m_Active_Color );	}
+
+
+private:
+
+	bool						m_bCategorised;
+
+	int							m_xScroll, m_yScroll, m_nItems, m_Size;
+
+	long						m_Active_Color;
+
+	CWKSP_Data_Button			**m_Items;
+
+	CSG_Parameters				m_Parameters;
+
+
+	void						_Set_Positions		(void);
+
+	bool						_Add_Items			(class CWKSP_Base_Item *pItem);
+	bool						_Add_Item			(class CWKSP_Layer *pLayer);
+	bool						_Add_Item			(const wxChar *Title);
+	bool						_Del_Items			(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CWKSP_Data_Buttons		*g_pData_Buttons;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Layers_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1317 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Data_Manager.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifdef _SAGA_LINUX
+#include <stdlib.h>
+#endif
+
+#include <wx/filename.h>
+
+#include <saga_api/saga_api.h>
+
+#include "saga.h"
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "project.h"
+
+#include "wksp_data_control.h"
+#include "wksp_data_manager.h"
+#include "wksp_data_menu_files.h"
+
+#include "wksp_table_manager.h"
+#include "wksp_shapes_manager.h"
+#include "wksp_tin_manager.h"
+#include "wksp_pointcloud_manager.h"
+#include "wksp_grid_manager.h"
+
+#include "wksp_map_manager.h"
+
+#include "wksp_module.h"
+
+#include "active.h"
+#include "active_parameters.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Manager	*g_pData	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Manager::CWKSP_Data_Manager(void)
+{
+	m_pTables		= NULL;
+	m_pShapes		= NULL;
+	m_pTINs			= NULL;
+	m_pPointClouds	= NULL;
+	m_pGrids		= NULL;
+
+	m_pProject		= new CWKSP_Project;
+	m_pMenu_Files	= new CWKSP_Data_Menu_Files;
+
+	g_pData			= this;
+
+	//-----------------------------------------------------
+	bool		bValue;
+	long		lValue;
+	wxString	sValue;
+
+	if( CONFIG_Read(wxT("/DATA/GRIDS"), wxT("CACHE_TMP_DIR")	, sValue) )
+	{
+		SG_Grid_Cache_Set_Directory(sValue);
+	}
+
+	if( CONFIG_Read(wxT("/DATA/GRIDS"), wxT("CACHE_AUTO")		, bValue) )
+	{
+		SG_Grid_Cache_Set_Automatic(bValue);
+	}
+
+	if( CONFIG_Read(wxT("/DATA/GRIDS"), wxT("CACHE_THRESHOLD")	, lValue) )
+	{
+		SG_Grid_Cache_Set_Threshold(lValue);
+	}
+
+	if( CONFIG_Read(wxT("/DATA/GRIDS"), wxT("CACHE_CONFIRM")	, lValue) )
+	{
+		SG_Grid_Cache_Set_Confirm  (lValue);
+	}
+
+	//-----------------------------------------------------
+	CSG_Parameter	*pNode;
+
+	m_Parameters.Create(this, LNG(""), LNG(""));
+
+	pNode	= m_Parameters.Add_Node(NULL, "NODE_GRID_MEM", LNG("Grid File Caching"), LNG(""));
+
+	m_Parameters.Add_FilePath(
+		pNode	, "GRID_MEM_CACHE_TMPDIR"	, LNG("Temporary files"),
+		LNG("Directory, where temporary cache files shall be saved."),
+		NULL, SG_Grid_Cache_Get_Directory(), true, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "GRID_MEM_CACHE_AUTO"		, LNG("Automatic mode"),
+		LNG("Activate file caching automatically, if memory size exceeds the threshold value."),
+		PARAMETER_TYPE_Bool, SG_Grid_Cache_Get_Automatic()
+	);
+
+	m_Parameters.Add_Value(
+		pNode	, "GRID_MEM_CACHE_THRSHLD"	, LNG("Threshold for automatic mode [MB]"),
+		LNG(""),
+		PARAMETER_TYPE_Double, SG_Grid_Cache_Get_Threshold_MB(), 0.0, true
+	);
+
+	m_Parameters.Add_Choice(
+		pNode	, "GRID_MEM_CACHE_CONFIRM"	, LNG("Confirm file caching"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("do not confirm"),
+			LNG("confirm"),
+			LNG("confirm with options")
+		),
+		SG_Grid_Cache_Get_Confirm()
+	);
+
+	//-----------------------------------------------------
+	pNode	= m_Parameters.Add_Node(NULL, "NODE_GENERAL", LNG("General"), LNG(""));
+
+	if( CONFIG_Read(wxT("/DATA"), wxT("PROJECT_START")			, lValue) == false )
+	{
+		lValue	= 2;
+	}
+
+	m_Parameters.Add_Choice(
+		pNode	, "PROJECT_START"			, LNG("Start Project"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("empty"),
+			LNG("last opened"),
+			LNG("automatically save and load")
+		), lValue
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Data_Manager::~CWKSP_Data_Manager(void)
+{
+	g_pData	= NULL;
+
+	delete(m_pProject);
+	delete(m_pMenu_Files);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Initialise(void)
+{
+	wxString	FileName;
+
+	if( m_pProject->Has_File_Name() )
+	{
+		return( m_pProject->Load(false) );
+	}
+	else
+	{
+		return( CONFIG_Read(wxT("/DATA"), wxT("PROJECT_FILE"), FileName) && wxFileExists(FileName) && m_pProject->Load(FileName, false, false) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Finalise(void)
+{
+	//-----------------------------------------------------
+	CONFIG_Write(wxT("/DATA/GRIDS")	, wxT("CACHE_TMP_DIR")	,		SG_Grid_Cache_Get_Directory());
+	CONFIG_Write(wxT("/DATA/GRIDS")	, wxT("CACHE_AUTO")		,		SG_Grid_Cache_Get_Automatic());
+	CONFIG_Write(wxT("/DATA/GRIDS")	, wxT("CACHE_THRESHOLD"), (long)SG_Grid_Cache_Get_Threshold());
+	CONFIG_Write(wxT("/DATA/GRIDS")	, wxT("CACHE_CONFIRM")	, (long)SG_Grid_Cache_Get_Confirm  ());
+
+	//-----------------------------------------------------
+#ifdef _SAGA_LINUX
+//	wxFileName	fProject(wxString(getenv( "HOME"), wxConvFile ), wxT("saga_gui"), wxT("cfg"));
+	CSG_String	sHome(getenv("HOME"));
+	wxFileName	fProject(sHome.c_str(), wxT("saga_gui"), wxT("cfg"));
+#else
+	wxFileName	fProject(g_pSAGA->Get_App_Path(), wxT("saga_gui"), wxT("cfg"));
+#endif
+
+	CONFIG_Write(wxT("/DATA")		, wxT("PROJECT_START")	, (long)m_Parameters("PROJECT_START")	->asInt());
+
+	if( Get_Count() == 0 )
+	{
+		wxRemoveFile(fProject.GetFullPath());
+		CONFIG_Write(wxT("/DATA"), wxT("PROJECT_FILE"), LNG(""));
+	}
+	else switch( m_Parameters("PROJECT_START")->asInt() )
+	{
+	case 0:	// empty
+		wxRemoveFile(fProject.GetFullPath());
+		CONFIG_Write(wxT("/DATA"), wxT("PROJECT_FILE"), LNG(""));
+		break;
+
+	case 1:	// last opened
+		wxRemoveFile(fProject.GetFullPath());
+		CONFIG_Write(wxT("/DATA"), wxT("PROJECT_FILE"), m_pProject->Get_File_Name());
+		break;
+
+	case 2:	// automatically save and load		
+		m_pProject->Save(fProject.GetFullPath(), false);
+		CONFIG_Write(wxT("/DATA"), wxT("PROJECT_FILE"), fProject.GetFullPath());
+		break;
+	}
+
+	m_pProject->Clr_File_Name();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Data_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] Data") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Data_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b><br>"), LNG("[CAP] Data"));
+
+	if( Get_Count() <= 0 )
+	{
+		s.Append(LNG("[TXT] No data loaded."));
+	}
+	else
+	{
+		if( m_pProject->Has_File_Name() )
+		{
+			s.Append(wxString::Format(wxT("%s: %s<br>"), LNG("[CAP] Project File"), m_pProject->Get_File_Name()));
+		}
+
+		if( Get_Tables() )
+		{
+			s.Append(wxString::Format(wxT("%s: %d<br>"), LNG("[CAP] Tables"), Get_Tables()->Get_Count()));
+		}
+
+		if( Get_Shapes() )
+		{
+			s.Append(wxString::Format(wxT("%s: %d<br>"), LNG("[CAP] Shapes"), Get_Shapes()->Get_Items_Count()));
+		}
+
+		if( Get_TINs() )
+		{
+			s.Append(wxString::Format(wxT("%s: %d<br>"), LNG("[CAP] TIN"), Get_TINs()->Get_Count()));
+		}
+
+		if( Get_PointClouds() )
+		{
+			s.Append(wxString::Format(wxT("%s: %d<br>"), LNG("[CAP] Point Clouds"), Get_PointClouds()->Get_Count()));
+		}
+
+		if( Get_Grids() )
+		{
+			s.Append(wxString::Format(wxT("%s: %d<br>"), LNG("[CAP] Grid Systems"), Get_Grids()->Get_Count()));
+			s.Append(wxString::Format(wxT("%s: %d<br>"), LNG("[CAP] Grids"), Get_Grids()->Get_Items_Count()));
+		}
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Data_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Data"));
+
+//	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+
+//	pMenu->AppendSeparator();
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_NEW);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_OPEN);
+//	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_OPEN_ADD);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_SAVE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_SAVE_AS);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::On_Command(int Cmd_ID)
+{
+	//-----------------------------------------------------
+	if( Open_CMD(Cmd_ID) )
+	{
+		return( true );
+	}
+
+	if( m_pTables && Cmd_ID >= ID_CMD_TABLES_FIRST && Cmd_ID <= ID_CMD_TABLES_LAST && m_pTables->On_Command(Cmd_ID) )
+	{
+		return( true );
+	}
+
+	if( m_pShapes && Cmd_ID >= ID_CMD_SHAPES_FIRST && Cmd_ID <= ID_CMD_SHAPES_LAST && m_pShapes->On_Command(Cmd_ID) )
+	{
+		return( true );
+	}
+
+	if( m_pTINs   && Cmd_ID >= ID_CMD_TIN_FIRST    && Cmd_ID <= ID_CMD_TIN_LAST    && m_pTINs  ->On_Command(Cmd_ID) )
+	{
+		return( true );
+	}
+
+	if( m_pPointClouds && Cmd_ID >= ID_CMD_POINTCLOUD_FIRST && Cmd_ID <= ID_CMD_POINTCLOUD_LAST && m_pPointClouds->On_Command(Cmd_ID) )
+	{
+		return( true );
+	}
+
+	if( m_pGrids  && Cmd_ID >= ID_CMD_GRIDS_FIRST  && Cmd_ID <= ID_CMD_GRIDS_LAST  && m_pGrids ->On_Command(Cmd_ID) )
+	{
+		return( true );
+	}
+
+	//-----------------------------------------------------
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	//-----------------------------------------------------
+	case ID_CMD_DATA_PROJECT_NEW:		Close(false);						break;
+	case ID_CMD_DATA_PROJECT_OPEN:		m_pProject->Load(false);			break;
+	case ID_CMD_DATA_PROJECT_OPEN_ADD:	m_pProject->Load(true);				break;
+	case ID_CMD_DATA_PROJECT_SAVE:		m_pProject->Save(true);				break;
+	case ID_CMD_DATA_PROJECT_SAVE_AS:	m_pProject->Save();					break;
+
+	//-----------------------------------------------------
+	case ID_CMD_TABLES_OPEN:			Open(DATAOBJECT_TYPE_Table);		break;
+	case ID_CMD_SHAPES_OPEN:			Open(DATAOBJECT_TYPE_Shapes);		break;
+	case ID_CMD_TIN_OPEN:				Open(DATAOBJECT_TYPE_TIN);			break;
+	case ID_CMD_POINTCLOUD_OPEN:		Open(DATAOBJECT_TYPE_PointCloud);	break;
+	case ID_CMD_GRIDS_OPEN:				Open(DATAOBJECT_TYPE_Grid);			break;
+
+	//-----------------------------------------------------
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+
+	case ID_CMD_WKSP_ITEM_CLOSE:
+		Close(false);
+		break;
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command_UI(event) );
+
+	case ID_CMD_DATA_PROJECT_NEW:
+		event.Enable(Get_Count() > 0 && g_pModule == NULL);
+		break;
+
+	case ID_CMD_WKSP_ITEM_CLOSE:
+		event.Enable(Get_Count() > 0 && g_pModule == NULL);
+		break;
+
+	case ID_CMD_DATA_PROJECT_SAVE:
+		event.Enable(Get_Count() > 0 && m_pProject->Has_File_Name() );
+		break;
+
+	case ID_CMD_DATA_PROJECT_SAVE_AS:
+		event.Enable(Get_Count() > 0);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Manager::Parameters_Changed(void)
+{
+	SG_Grid_Cache_Set_Automatic		(m_Parameters("GRID_MEM_CACHE_AUTO")	->asBool());
+	SG_Grid_Cache_Set_Threshold_MB	(m_Parameters("GRID_MEM_CACHE_THRSHLD")	->asDouble());
+	SG_Grid_Cache_Set_Confirm		(m_Parameters("GRID_MEM_CACHE_CONFIRM")	->asInt());
+	SG_Grid_Cache_Set_Directory		(m_Parameters("GRID_MEM_CACHE_TMPDIR")	->asString());
+
+	CWKSP_Base_Manager::Parameters_Changed();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Check_Parameters(CSG_Parameters *pParameters)
+{
+	if( pParameters )
+	{
+		for(int i=0; i<pParameters->Get_Count(); i++)
+		{
+			Check_Parameter(pParameters->Get_Parameter(i));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Check_Parameter(CSG_Parameter *pParameter)
+{
+	bool	bResult	= true;
+	int		i, DataObject_Type;
+
+	if( pParameter )
+	{
+		switch( pParameter->Get_Type() )
+		{
+		default:								DataObject_Type	= -1;							break;
+		case PARAMETER_TYPE_Grid:
+		case PARAMETER_TYPE_Grid_List:			DataObject_Type	= DATAOBJECT_TYPE_Grid;			break;
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Table_List:			DataObject_Type	= DATAOBJECT_TYPE_Table;		break;
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_Shapes_List:		DataObject_Type	= DATAOBJECT_TYPE_Shapes;		break;
+		case PARAMETER_TYPE_TIN:
+		case PARAMETER_TYPE_TIN_List:			DataObject_Type	= DATAOBJECT_TYPE_TIN;			break;
+		case PARAMETER_TYPE_PointCloud:
+		case PARAMETER_TYPE_PointCloud_List:	DataObject_Type	= DATAOBJECT_TYPE_PointCloud;	break;
+		}
+
+		//-------------------------------------------------
+		switch( pParameter->Get_Type() )
+		{
+		default:
+	    	break;
+
+		case PARAMETER_TYPE_Grid_System:
+			if( !Exists(pParameter->asGrid_System()) )
+			{
+				bResult	= false;
+				pParameter->Set_Value((void *)NULL);
+			}
+			break;
+
+		case PARAMETER_TYPE_Grid:
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_TIN:
+		case PARAMETER_TYPE_PointCloud:
+			if(	pParameter->asDataObject() != DATAOBJECT_NOTSET
+			&&	pParameter->asDataObject() != DATAOBJECT_CREATE
+			&&	!Exists(pParameter->asDataObject(), DataObject_Type) )
+			{
+				bResult	= false;
+				pParameter->Set_Value(DATAOBJECT_NOTSET);
+			}
+			break;
+
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+			for(i=pParameter->asList()->Get_Count()-1; i>=0; i--)
+			{
+				if( !Exists(pParameter->asList()->asDataObject(i), DataObject_Type) )
+				{
+					bResult	= false;
+					pParameter->asList()->Del_Item(i);
+				}
+			}
+			break;
+		}
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Open_CMD(int Cmd_ID)
+{
+	return( m_pMenu_Files->Recent_Open(Cmd_ID) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Open(const wxChar *File_Name)
+{
+	if( SG_File_Cmp_Extension(File_Name, wxT("txt"))
+	||	SG_File_Cmp_Extension(File_Name, wxT("dbf")) )
+	{
+		return( Open(DATAOBJECT_TYPE_Table , File_Name) != NULL );
+	}
+
+	if( SG_File_Cmp_Extension(File_Name, wxT("shp")) )
+	{
+		return( Open(DATAOBJECT_TYPE_Shapes, File_Name) != NULL );
+	}
+
+	if(	SG_File_Cmp_Extension(File_Name, wxT("sgrd"))
+	||	SG_File_Cmp_Extension(File_Name, wxT("dgm"))
+	||	SG_File_Cmp_Extension(File_Name, wxT("grd")) )
+	{
+		return( Open(DATAOBJECT_TYPE_Grid  , File_Name) != NULL );
+	}
+
+	if( SG_File_Cmp_Extension(File_Name, wxT("sprj")) )
+	{
+		return( m_pProject->Load(File_Name, false, true) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Open(int DataType)
+{
+	int				ID;
+	wxArrayString	File_Paths;
+
+	switch( DataType )
+	{
+	default:	return( false );
+	case DATAOBJECT_TYPE_Table:			ID	= ID_DLG_TABLES_OPEN;		break;
+	case DATAOBJECT_TYPE_Shapes:		ID	= ID_DLG_SHAPES_OPEN;		break;
+	case DATAOBJECT_TYPE_TIN:			ID	= ID_DLG_TIN_OPEN;			break;
+	case DATAOBJECT_TYPE_PointCloud:	ID	= ID_DLG_POINTCLOUD_OPEN;	break;
+	case DATAOBJECT_TYPE_Grid:			ID	= ID_DLG_GRIDS_OPEN;		break;
+	}
+
+	if( DLG_Open(File_Paths, ID) )
+	{
+		MSG_General_Add_Line();
+
+		for(size_t i=0; i<File_Paths.GetCount(); i++)
+		{
+			Open(DataType, File_Paths[i]);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CWKSP_Base_Item * CWKSP_Data_Manager::Open(int DataType, const wxChar *FileName)
+{
+	CSG_Data_Object		*pObject;
+	CWKSP_Base_Item	*pItem;
+
+	switch( DataType )
+	{
+	default:
+		pObject	= NULL;
+		break;
+
+	case DATAOBJECT_TYPE_Table:
+		pObject	= new CSG_Table		(FileName);
+		break;
+
+	case DATAOBJECT_TYPE_Shapes:
+		pObject	= new CSG_Shapes	(FileName);
+		break;
+
+	case DATAOBJECT_TYPE_TIN:
+		pObject	= new CSG_TIN		(FileName);
+		break;
+
+	case DATAOBJECT_TYPE_PointCloud:
+		pObject	= new CSG_PointCloud(FileName);
+		break;
+
+	case DATAOBJECT_TYPE_Grid:
+		pObject	= new CSG_Grid		(FileName);
+		break;
+	}
+
+	PROCESS_Set_Okay();
+
+	if( pObject )
+	{
+		if( pObject->is_Valid() && (pItem = Add(pObject)) != NULL )
+		{
+			m_pMenu_Files->Recent_Add(DataType, FileName);
+
+			return( pItem );
+		}
+
+		delete(pObject);
+	}
+
+	m_pMenu_Files->Recent_Del(DataType, FileName);
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Exists(CSG_Grid_System *pSystem)
+{
+	return( m_pGrids && m_pGrids->Exists(pSystem) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Exists(CSG_Data_Object *pObject, int Type)
+{
+	switch( Type )
+	{
+	case DATAOBJECT_TYPE_Grid:
+		return( m_pGrids  && m_pGrids ->Exists((CSG_Grid   *)pObject) );
+
+	case DATAOBJECT_TYPE_Table:
+		return(
+			(	m_pTables && m_pTables->Exists((CSG_Table  *)pObject)	)
+		||	(	m_pShapes && m_pShapes->Exists((CSG_Shapes *)pObject)	)
+		);
+
+	case DATAOBJECT_TYPE_Shapes:
+		return( m_pShapes && m_pShapes->Exists((CSG_Shapes *)pObject) );
+
+	case DATAOBJECT_TYPE_TIN:
+		return( m_pTINs   && m_pTINs  ->Exists((CSG_TIN    *)pObject) );
+
+	case DATAOBJECT_TYPE_PointCloud:
+		return( m_pPointClouds && m_pPointClouds->Exists((CSG_PointCloud *)pObject) );
+	}
+
+	return(	Exists(pObject, DATAOBJECT_TYPE_Table)
+		||	Exists(pObject, DATAOBJECT_TYPE_Shapes)
+		||	Exists(pObject, DATAOBJECT_TYPE_TIN)
+		||	Exists(pObject, DATAOBJECT_TYPE_PointCloud)
+		||	Exists(pObject, DATAOBJECT_TYPE_Grid)
+	);
+}
+
+//---------------------------------------------------------
+CSG_Data_Object * CWKSP_Data_Manager::Get_byFileName(const wxChar *File_Name, int Type)
+{
+	switch( Type )
+	{
+	case DATAOBJECT_TYPE_Grid:
+		return( !m_pGrids  ? NULL : m_pGrids ->Get_byFileName(File_Name) );
+
+	case DATAOBJECT_TYPE_Table:
+		return( !m_pTables ? NULL : m_pTables->Get_byFileName(File_Name) );
+
+	case DATAOBJECT_TYPE_Shapes:
+		return( !m_pShapes ? NULL : m_pShapes->Get_byFileName(File_Name) );
+
+	case DATAOBJECT_TYPE_TIN:
+		return( !m_pTINs   ? NULL : m_pTINs  ->Get_byFileName(File_Name) );
+
+	case DATAOBJECT_TYPE_PointCloud:
+		return( !m_pPointClouds ? NULL : m_pPointClouds->Get_byFileName(File_Name) );
+	}
+
+	CSG_Data_Object	*pObject;
+
+	if( (pObject = Get_byFileName(File_Name, DATAOBJECT_TYPE_Table))  != NULL )	return( pObject );
+	if( (pObject = Get_byFileName(File_Name, DATAOBJECT_TYPE_Shapes)) != NULL )	return( pObject );
+	if( (pObject = Get_byFileName(File_Name, DATAOBJECT_TYPE_TIN))    != NULL )	return( pObject );
+	if( (pObject = Get_byFileName(File_Name, DATAOBJECT_TYPE_Grid))   != NULL )	return( pObject );
+
+	return(	NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Save_Modified(CWKSP_Base_Item *pItem)
+{
+	return( m_pProject->Save_Modified(pItem) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Save_Modified_Sel(void)
+{
+	return( m_pProject->Save_Modified(this, true) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Close(bool bSilent)
+{
+	if( Get_Count() == 0 )
+	{
+		Finalise();
+
+		return( true );
+	}
+	else if( (bSilent || DLG_Message_Confirm(LNG("[TXT] Close all data sets"), LNG("[CAP] Close"))) && Save_Modified(this) )
+	{
+		Finalise();
+
+		g_pACTIVE->Get_Parameters()->Restore_Parameters();
+		g_pMaps->Close(true);
+
+		return( g_pData_Ctrl->Close(true) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Base_Item * CWKSP_Data_Manager::Add(CSG_Data_Object *pObject)
+{
+	if( pObject && _Get_Manager(pObject->Get_ObjectType()) )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( (CWKSP_Base_Item *)m_pGrids ->Add((CSG_Grid   *)pObject) );
+
+		case DATAOBJECT_TYPE_Table:
+			return( (CWKSP_Base_Item *)m_pTables->Add((CSG_Table  *)pObject) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( (CWKSP_Base_Item *)m_pShapes->Add((CSG_Shapes *)pObject) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( (CWKSP_Base_Item *)m_pTINs  ->Add((CSG_TIN    *)pObject) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( (CWKSP_Base_Item *)m_pPointClouds->Add((CSG_PointCloud *)pObject) );
+			
+		default:
+			return( NULL );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Manager::Del_Manager(CWKSP_Base_Item *pItem)
+{
+	if( pItem == m_pGrids )
+	{
+		m_pGrids	= NULL;
+	}
+	else if( pItem == m_pTables )
+	{
+		m_pTables	= NULL;
+	}
+	else if( pItem == m_pShapes )
+	{
+		m_pShapes	= NULL;
+	}
+	else if( pItem == m_pTINs )
+	{
+		m_pTINs		= NULL;
+	}
+	else if( pItem == m_pPointClouds )
+	{
+		m_pPointClouds	= NULL;
+	}
+
+	if( Get_Count() == 0 )
+	{
+		m_pProject->Clr_File_Name();
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::_Get_Manager(int DataType)
+{
+	switch( DataType )
+	{
+	default:
+		return( false );
+
+	case DATAOBJECT_TYPE_Grid:
+		if( !m_pGrids )
+		{
+			Add_Item(m_pGrids   = new CWKSP_Grid_Manager);
+		}
+
+		return( m_pGrids  != NULL );
+
+	case DATAOBJECT_TYPE_Table:
+		if( !m_pTables )
+		{
+			Add_Item(m_pTables  = new CWKSP_Table_Manager);
+		}
+
+		return( m_pTables != NULL );
+
+	case DATAOBJECT_TYPE_Shapes:
+		if( !m_pShapes )
+		{
+			Add_Item(m_pShapes = new CWKSP_Shapes_Manager);
+		}
+
+		return( m_pShapes != NULL );
+
+	case DATAOBJECT_TYPE_TIN:
+		if( !m_pTINs )
+		{
+			Add_Item(m_pTINs   = new CWKSP_TIN_Manager);
+		}
+
+		return( m_pTINs   != NULL );
+
+	case DATAOBJECT_TYPE_PointCloud:
+		if( !m_pPointClouds )
+		{
+			Add_Item(m_pPointClouds   = new CWKSP_PointCloud_Manager);
+		}
+
+		return( m_pPointClouds != NULL );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Update(CSG_Data_Object *pObject, CSG_Parameters *pParameters)
+{
+	if( pObject )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( m_pGrids  && m_pGrids ->Update((CSG_Grid   *)pObject, pParameters) );
+
+		case DATAOBJECT_TYPE_Table:
+			return( m_pTables && m_pTables->Update((CSG_Table  *)pObject, pParameters) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( m_pShapes && m_pShapes->Update((CSG_Shapes *)pObject, pParameters) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( m_pTINs   && m_pTINs  ->Update((CSG_TIN    *)pObject, pParameters) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( m_pPointClouds && m_pPointClouds->Update((CSG_PointCloud *)pObject, pParameters) );
+
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Update_Views(CSG_Data_Object *pObject)
+{
+	if( pObject )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( m_pGrids  && m_pGrids ->Update_Views((CSG_Grid   *)pObject) );
+
+		case DATAOBJECT_TYPE_Table:
+			return( m_pTables && m_pTables->Update_Views((CSG_Table  *)pObject) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( m_pShapes && m_pShapes->Update_Views((CSG_Shapes *)pObject) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( m_pTINs   && m_pTINs  ->Update_Views((CSG_TIN    *)pObject) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( m_pPointClouds && m_pPointClouds->Update_Views((CSG_PointCloud *)pObject) );
+
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Show(CSG_Data_Object *pObject, int Map_Mode)
+{
+	if( pObject )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( m_pGrids  && m_pGrids ->Show((CSG_Grid   *)pObject, Map_Mode) );
+
+		case DATAOBJECT_TYPE_Table:
+			return( m_pTables && m_pTables->Show((CSG_Table  *)pObject) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( m_pShapes && m_pShapes->Show((CSG_Shapes *)pObject, Map_Mode) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( m_pTINs   && m_pTINs  ->Show((CSG_TIN    *)pObject, Map_Mode) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( m_pPointClouds && m_pPointClouds->Show((CSG_PointCloud *)pObject, Map_Mode) );
+
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::asImage(CSG_Data_Object *pObject, CSG_Grid *pImage)
+{
+	if( pObject )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( m_pGrids  && m_pGrids ->asImage((CSG_Grid   *)pObject, pImage) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( m_pShapes && m_pShapes->asImage((CSG_Shapes *)pObject, pImage) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( m_pTINs   && m_pTINs  ->asImage((CSG_TIN    *)pObject, pImage) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( m_pPointClouds && m_pPointClouds->asImage((CSG_PointCloud *)pObject, pImage) );
+
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Get_Colors(CSG_Data_Object *pObject, CSG_Colors *pColors)
+{
+	if( pObject && pColors )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( m_pGrids ->Get_Colors((CSG_Grid   *)pObject, pColors) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( m_pShapes->Get_Colors((CSG_Shapes *)pObject, pColors) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( m_pTINs  ->Get_Colors((CSG_TIN    *)pObject, pColors) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( m_pPointClouds->Get_Colors((CSG_PointCloud *)pObject, pColors) );
+
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Set_Colors(CSG_Data_Object *pObject, CSG_Colors *pColors)
+{
+	if( pObject && pColors )
+	{
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( m_pGrids ->Set_Colors((CSG_Grid   *)pObject, pColors) );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( m_pShapes->Set_Colors((CSG_Shapes *)pObject, pColors) );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( m_pTINs  ->Set_Colors((CSG_TIN    *)pObject, pColors) );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( m_pPointClouds->Set_Colors((CSG_PointCloud *)pObject, pColors) );
+
+		default:
+			break;
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Get_Parameters(CSG_Data_Object *pObject, CSG_Parameters *pParameters)
+{
+	if( pObject && pParameters )
+	{
+		CWKSP_Base_Item	*pItem;
+
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			pItem	= (CWKSP_Base_Item *)m_pGrids ->Get_Grid  ((CSG_Grid   *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_Shapes:
+			pItem	= (CWKSP_Base_Item *)m_pShapes->Get_Shapes((CSG_Shapes *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_TIN:
+			pItem	= (CWKSP_Base_Item *)m_pTINs  ->Get_TIN   ((CSG_TIN    *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_PointCloud:
+			pItem	= (CWKSP_Base_Item *)m_pPointClouds->Get_PointCloud((CSG_PointCloud *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_Table:
+			pItem	= (CWKSP_Base_Item *)m_pTables->Get_Table ((CSG_Table  *)pObject);
+			break;
+
+		default:
+			pItem	= NULL;
+			break;
+		}
+
+		if( pItem && pItem->Get_Parameters() )
+		{
+			return( pParameters->Assign(pItem->Get_Parameters()) != 0 );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Set_Parameters(CSG_Data_Object *pObject, CSG_Parameters *pParameters)
+{
+	if( pObject && pParameters )
+	{
+		CWKSP_Base_Item	*pItem;
+
+		switch( pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			pItem	= (CWKSP_Base_Item *)m_pGrids ->Get_Grid  ((CSG_Grid   *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_Shapes:
+			pItem	= (CWKSP_Base_Item *)m_pShapes->Get_Shapes((CSG_Shapes *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_TIN:
+			pItem	= (CWKSP_Base_Item *)m_pTINs  ->Get_TIN   ((CSG_TIN    *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_PointCloud:
+			pItem	= (CWKSP_Base_Item *)m_pPointClouds->Get_PointCloud((CSG_PointCloud *)pObject);
+			break;
+
+		case DATAOBJECT_TYPE_Table:
+			pItem	= (CWKSP_Base_Item *)m_pTables->Get_Table ((CSG_Table  *)pObject);
+			break;
+
+		default:
+			pItem	= NULL;
+			break;
+		}
+
+		if( pItem && pItem->Get_Parameters() )
+		{
+			if( pItem->Get_Parameters()->Assign_Values(pParameters) != 0 )
+			{
+				pItem->Parameters_Changed();
+			}
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+#include "wksp_shapes_type.h"
+#include "wksp_shapes.h"
+#include "wksp_tin.h"
+#include "wksp_pointcloud.h"
+#include "wksp_table.h"
+
+//---------------------------------------------------------
+bool CWKSP_Data_Manager::Get_DataObject_List(CSG_Parameters *pParameters)
+{
+	if( pParameters )
+	{
+		int					i, j;
+		CSG_String			s;
+		CWKSP_Shapes_Type	*pShapes;
+
+		pParameters->Destroy();
+
+		for(i=0; i<Get_Grids()->Get_Count(); i++)
+		{
+			for(j=0; j<Get_Grids()->Get_System(i)->Get_Count(); j++)
+			{
+				s.Printf(wxT("GRID_%03d_%03d"), i, j);
+				pParameters->Add_Grid(NULL, s, s, LNG(""), PARAMETER_INPUT)
+					->Set_Value(Get_Grids()->Get_System(i)->Get_Grid(j)->Get_Grid());
+			}
+		}
+
+		for(i=0; i<Get_PointClouds()->Get_Count(); i++)
+		{
+			s.Printf(wxT("POINTCLOUD_%03d"), i);
+			pParameters->Add_PointCloud(NULL, s, s, LNG(""), PARAMETER_INPUT)
+				->Set_Value(Get_PointClouds()->Get_PointCloud(i)->Get_PointCloud());
+		}
+
+		if( (pShapes = Get_Shapes()->Get_Shapes_Type(SHAPE_TYPE_Point)) != NULL )
+		{
+			for(i=0; i<pShapes->Get_Count(); i++)
+			{
+				s.Printf(wxT("POINT_%03d"), i);
+				pParameters->Add_Shapes(NULL, s, s, LNG(""), PARAMETER_INPUT)
+					->Set_Value(pShapes->Get_Shapes(i)->Get_Shapes());
+			}
+		}
+
+		if( (pShapes = Get_Shapes()->Get_Shapes_Type(SHAPE_TYPE_Points)) != NULL )
+		{
+			for(i=0; i<pShapes->Get_Count(); i++)
+			{
+				s.Printf(wxT("POINTS_%03d"), i);
+				pParameters->Add_Shapes(NULL, s, s, LNG(""), PARAMETER_INPUT)
+					->Set_Value(pShapes->Get_Shapes(i)->Get_Shapes());
+			}
+		}
+
+		if( (pShapes = Get_Shapes()->Get_Shapes_Type(SHAPE_TYPE_Line)) != NULL )
+		{
+			for(i=0; i<pShapes->Get_Count(); i++)
+			{
+				s.Printf(wxT("LINE_%03d"), i);
+				pParameters->Add_Shapes(NULL, s, s, LNG(""), PARAMETER_INPUT)
+					->Set_Value(pShapes->Get_Shapes(i)->Get_Shapes());
+			}
+		}
+
+		if( (pShapes = Get_Shapes()->Get_Shapes_Type(SHAPE_TYPE_Polygon)) != NULL )
+		{
+			for(i=0; i<pShapes->Get_Count(); i++)
+			{
+				s.Printf(wxT("POLYGON_%03d"), i);
+				pParameters->Add_Shapes(NULL, s, s, LNG(""), PARAMETER_INPUT)
+					->Set_Value(pShapes->Get_Shapes(i)->Get_Shapes());
+			}
+		}
+
+		for(i=0; i<Get_Tables()->Get_Count(); i++)
+		{
+			s.Printf(wxT("TABLE_%03d"), i);
+			pParameters->Add_Table(NULL, s, s, LNG(""), PARAMETER_INPUT)
+				->Set_Value(Get_Tables()->Get_Table(i)->Get_Table());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,182 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Data_Manager.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Data_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Data_Manager(void);
+	virtual ~CWKSP_Data_Manager(void);
+
+	bool							Initialise			(void);
+	bool							Finalise			(void);
+
+	virtual TWKSP_Item				Get_Type			(void)		{	return( WKSP_ITEM_Data_Manager );	}
+
+	virtual wxString				Get_Name			(void);
+	virtual wxString				Get_Description		(void);
+
+	virtual wxMenu *				Get_Menu			(void);
+
+	virtual bool					On_Command			(int Cmd_ID);
+	virtual bool					On_Command_UI		(wxUpdateUIEvent &event);
+
+	virtual class CSG_Parameters *	Get_Parameters		(void)		{	return( &m_Parameters );	}
+	virtual void					Parameters_Changed	(void);
+
+	CWKSP_Base_Manager *			Get_Manager			(int i)		{	return( (CWKSP_Base_Manager *)Get_Item(i) );	}
+	void							Del_Manager			(class CWKSP_Base_Item *pItem);
+
+	class CWKSP_Table_Manager *		Get_Tables			(void)		{	return( m_pTables      );	}
+	class CWKSP_Shapes_Manager *	Get_Shapes			(void)		{	return( m_pShapes      );	}
+	class CWKSP_TIN_Manager *		Get_TINs			(void)		{	return( m_pTINs        );	}
+	class CWKSP_PointCloud_Manager *Get_PointClouds		(void)		{	return( m_pPointClouds );	}
+	class CWKSP_Grid_Manager *		Get_Grids			(void)		{	return( m_pGrids       );	}
+
+	bool							Get_DataObject_List	(CSG_Parameters *pParameters);
+
+	class CWKSP_Data_Menu_Files *	Get_FileMenus		(void)		{	return( m_pMenu_Files );	}
+
+	bool							Check_Parameters	(class CSG_Parameters *pParameters);
+	bool							Check_Parameter		(class CSG_Parameter  *pParameter);
+
+	bool							Open_CMD			(int Cmd_ID);
+	bool							Open				(const wxChar *FileName);
+	bool							Open				(int DataType);
+	CWKSP_Base_Item *				Open				(int DataType, const wxChar *FileName);
+
+	bool							Exists				(class CSG_Grid_System *pSystem);
+	bool							Exists				(class CSG_Data_Object *pObject, int DataType = -1);
+
+	class CSG_Data_Object *			Get_byFileName		(const wxChar *File_Name, int DataType = -1);
+
+	bool							Save_Modified		(class CWKSP_Base_Item *pItem);
+	bool							Save_Modified_Sel	(void);
+	bool							Close				(bool bSilent);
+
+	CWKSP_Base_Item *				Add					(class CSG_Data_Object *pObject);
+	bool							Update				(class CSG_Data_Object *pObject, class CSG_Parameters *pParameters);
+	bool							Update_Views		(class CSG_Data_Object *pObject);
+	bool							Show				(class CSG_Data_Object *pObject, int Map_Mode);
+	bool							asImage				(class CSG_Data_Object *pObject, class CSG_Grid *pImage);
+
+	bool							Get_Colors			(class CSG_Data_Object *pObject, class CSG_Colors *pColors);
+	bool							Set_Colors			(class CSG_Data_Object *pObject, class CSG_Colors *pColors);
+	bool							Get_Parameters		(class CSG_Data_Object *pObject, class CSG_Parameters *pParameters);
+	bool							Set_Parameters		(class CSG_Data_Object *pObject, class CSG_Parameters *pParameters);
+
+
+private:
+
+	CSG_Parameters					m_Parameters;
+
+	class CWKSP_Project				*m_pProject;
+
+	class CWKSP_Data_Menu_Files		*m_pMenu_Files;
+
+	class CWKSP_Table_Manager		*m_pTables;
+
+	class CWKSP_Shapes_Manager		*m_pShapes;
+
+	class CWKSP_TIN_Manager			*m_pTINs;
+
+	class CWKSP_PointCloud_Manager	*m_pPointClouds;
+
+	class CWKSP_Grid_Manager		*m_pGrids;
+
+
+	bool							_Get_Manager		(int DataType);
+
+};
+
+//---------------------------------------------------------
+extern CWKSP_Data_Manager			*g_pData;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,381 @@
+	
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Data_Menu_File.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "helper.h"
+
+#include "res_commands.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_data_menu_file.h"
+
+#include "wksp_table_manager.h"
+#include "wksp_shapes_manager.h"
+#include "wksp_tin_manager.h"
+#include "wksp_grid_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Menu_File::CWKSP_Data_Menu_File(int DataType)
+{
+	m_DataType	= DataType;
+
+	m_Recent	= NULL;
+
+	_Create();
+}
+
+//---------------------------------------------------------
+CWKSP_Data_Menu_File::~CWKSP_Data_Menu_File(void)
+{
+	_Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_File::_Create(void)
+{
+	switch( m_DataType )
+	{
+	default:
+		m_Recent_First	= 0;
+		m_Recent_Count	= 0;
+		m_Recent_Group	= wxT("");
+		break;
+
+	case DATAOBJECT_TYPE_Undefined:
+		m_Recent_First	= ID_CMD_DATA_PROJECT_RECENT_FIRST;
+		m_Recent_Count	= ID_CMD_DATA_PROJECT_RECENT_LAST   - m_Recent_First + 1;
+		m_Recent_Group	= wxT("Projects");
+		break;
+
+	case DATAOBJECT_TYPE_Table:
+		m_Recent_First	= ID_CMD_TABLES_RECENT_FIRST;
+		m_Recent_Count	= ID_CMD_TABLES_RECENT_LAST - m_Recent_First + 1;
+		m_Recent_Group	= wxT("Tables");
+		break;
+
+	case DATAOBJECT_TYPE_Shapes:
+		m_Recent_First	= ID_CMD_SHAPES_RECENT_FIRST;
+		m_Recent_Count	= ID_CMD_SHAPES_RECENT_LAST - m_Recent_First + 1;
+		m_Recent_Group	= wxT("Shapes");
+		break;
+
+	case DATAOBJECT_TYPE_TIN:
+		m_Recent_First	= ID_CMD_TIN_RECENT_FIRST;
+		m_Recent_Count	= ID_CMD_TIN_RECENT_LAST    - m_Recent_First + 1;
+		m_Recent_Group	= wxT("TIN");
+		break;
+
+	case DATAOBJECT_TYPE_PointCloud:
+		m_Recent_First	= ID_CMD_POINTCLOUD_RECENT_FIRST;
+		m_Recent_Count	= ID_CMD_POINTCLOUD_RECENT_LAST    - m_Recent_First + 1;
+		m_Recent_Group	= wxT("Point Cloud");
+		break;
+
+	case DATAOBJECT_TYPE_Grid:
+		m_Recent_First	= ID_CMD_GRIDS_RECENT_FIRST;
+		m_Recent_Count	= ID_CMD_GRIDS_RECENT_LAST  - m_Recent_First + 1;
+		m_Recent_Group	= wxT("Grids");
+		break;
+	}
+
+	if( m_Recent_Count > 0 )
+	{
+		m_Recent		= new wxString[m_Recent_Count];
+
+		for(int i=0; i<m_Recent_Count; i++)
+		{
+			CONFIG_Read(wxString::Format(wxT("RECENT_FILES/%s"), m_Recent_Group.c_str()), wxString::Format(wxT("FILE_%02d"), i + 1), m_Recent[i]);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_File::_Destroy(void)
+{
+	if( m_Recent )
+	{
+		for(int i=0; i<m_Recent_Count; i++)
+		{
+			CONFIG_Write(wxString::Format(wxT("RECENT_FILES/%s"), m_Recent_Group.c_str()), wxString::Format(wxT("FILE_%02d"), i + 1), m_Recent[i]);
+		}
+
+		delete[](m_Recent);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Data_Menu_File::Create(void)
+{
+	wxMenu	*pMenu	= new wxMenu;
+
+	Update(pMenu);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_File::Update(wxMenu *pMenu)
+{
+	bool	bFirst;
+	int		i;
+
+	//-----------------------------------------------------
+	if( pMenu )
+	{
+		for(i=pMenu->GetMenuItemCount()-1; i>=0; i--)
+		{
+			pMenu->Destroy(pMenu->GetMenuItems()[i]);
+		}
+
+		//-------------------------------------------------
+		switch( m_DataType )
+		{
+		default:
+			return;
+
+		case DATAOBJECT_TYPE_Undefined:
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_NEW);
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_OPEN);
+//			CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_OPEN_ADD);
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_SAVE);
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_DATA_PROJECT_SAVE_AS);
+			break;
+
+		case DATAOBJECT_TYPE_Table:
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLES_OPEN);
+			break;
+
+		case DATAOBJECT_TYPE_Shapes:
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_OPEN);
+			break;
+
+		case DATAOBJECT_TYPE_TIN:
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_TIN_OPEN);
+			break;
+
+		case DATAOBJECT_TYPE_PointCloud:
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_POINTCLOUD_OPEN);
+			break;
+
+		case DATAOBJECT_TYPE_Grid:
+			CMD_Menu_Add_Item(pMenu, false, ID_CMD_GRIDS_OPEN);
+			break;
+		}
+
+		//-------------------------------------------------
+		for(i=0, bFirst=false; i<m_Recent_Count; i++)
+		{
+			if( m_Recent[i].Length() > 0 )
+			{
+				if( !bFirst )
+				{
+					bFirst	= true;
+					pMenu->AppendSeparator();
+				}
+
+				pMenu->Append(m_Recent_First + i, m_Recent[i]);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_File::Add(const wxChar *FileName)
+{
+	int		i, j;
+
+	if( m_Recent )
+	{
+		for(i=0, j=-1; i<m_Recent_Count && j<0; i++)
+		{
+			if( m_Recent[i].Cmp(FileName) == 0 )
+			{
+				j	= i;
+			}
+		}
+
+		if( j > 0 )
+		{
+			for(i=j; i>0; i--)
+			{
+				m_Recent[i]	= m_Recent[i - 1];
+			}
+
+			m_Recent[0]	= FileName;
+		}
+		else if( j < 0 )
+		{
+			for(i=m_Recent_Count-1; i>0; i--)
+			{
+				m_Recent[i]	= m_Recent[i - 1];
+			}
+
+			m_Recent[0]	= FileName;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_File::Del(const wxChar *FileName)
+{
+	int		i, j;
+
+	if( m_Recent )
+	{
+		for(i=0, j=-1; i<m_Recent_Count && j<0; i++)
+		{
+			if( m_Recent[i].Cmp(FileName) == 0 )
+			{
+				j	= i;
+			}
+		}
+
+		if( j >= 0 )
+		{
+			for(i=j; i<m_Recent_Count-1; i++)
+			{
+				m_Recent[i]	= m_Recent[i + 1];
+			}
+
+			m_Recent[m_Recent_Count - 1].Clear();
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Menu_File::Open(int Cmd_ID)
+{
+	if( m_Recent && m_Recent_First <= Cmd_ID && Cmd_ID < m_Recent_First + m_Recent_Count )
+	{
+		switch( m_DataType )
+		{
+		default:
+			return( false );
+
+		case DATAOBJECT_TYPE_Undefined:
+			g_pData->Open(m_Recent[Cmd_ID - m_Recent_First]);
+			break;
+
+		case DATAOBJECT_TYPE_Table:
+		case DATAOBJECT_TYPE_Shapes:
+		case DATAOBJECT_TYPE_TIN:
+		case DATAOBJECT_TYPE_PointCloud:
+		case DATAOBJECT_TYPE_Grid:
+			g_pData->Open(m_DataType, m_Recent[Cmd_ID - m_Recent_First]);
+			break;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_file.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,107 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Data_Menu_File.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Menu_File_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Menu_File_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Data_Menu_File
+{
+public:
+	CWKSP_Data_Menu_File(int DataType);
+	virtual ~CWKSP_Data_Menu_File(void);
+
+	class wxMenu *				Create		(void);
+	void						Update		(class wxMenu *pMenu);
+
+	void						Add			(const wxChar *FileName);
+	void						Del			(const wxChar *FileName);
+
+	bool						Open		(int Cmd_ID);
+
+
+private:
+
+	int							m_DataType, m_Recent_First, m_Recent_Count;
+
+	wxString					*m_Recent, m_Recent_Group;
+
+
+	void						_Create		(void);
+	void						_Destroy	(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Menu_File_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,247 @@
+	
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               WKSP_Data_Menu_Files.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/string.h>
+#include <wx/menu.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_data_menu_files.h"
+#include "wksp_data_menu_file.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Data_Menu_Files::CWKSP_Data_Menu_Files(void)
+{
+	m_pFMProjects		= new CWKSP_Data_Menu_File(DATAOBJECT_TYPE_Undefined);
+	m_pFMTables			= new CWKSP_Data_Menu_File(DATAOBJECT_TYPE_Table);
+	m_pFMShapes			= new CWKSP_Data_Menu_File(DATAOBJECT_TYPE_Shapes);
+	m_pFMTINs			= new CWKSP_Data_Menu_File(DATAOBJECT_TYPE_TIN);
+	m_pFMPointClouds	= new CWKSP_Data_Menu_File(DATAOBJECT_TYPE_PointCloud);
+	m_pFMGrids			= new CWKSP_Data_Menu_File(DATAOBJECT_TYPE_Grid);
+
+	m_bUpdate			= true;
+
+	m_Menus				= NULL;
+	m_nMenus			= 0;
+}
+
+//---------------------------------------------------------
+CWKSP_Data_Menu_Files::~CWKSP_Data_Menu_Files(void)
+{
+	delete(m_pFMProjects);
+	delete(m_pFMTables);
+	delete(m_pFMShapes);
+	delete(m_pFMTINs);
+	delete(m_pFMPointClouds);
+	delete(m_pFMGrids);
+
+	if( m_Menus )
+	{
+		SG_Free(m_Menus);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_Files::Add(wxMenu *pMenu)
+{
+	pMenu->Append(ID_CMD_DATA_FIRST      , LNG("[MNU] Project")    , m_pFMProjects   ->Create());
+
+	pMenu->AppendSeparator();
+	pMenu->Append(ID_CMD_TABLES_FIRST    , LNG("[MNU] Table")      , m_pFMTables     ->Create());
+	pMenu->Append(ID_CMD_SHAPES_FIRST    , LNG("[MNU] Shapes")     , m_pFMShapes     ->Create());
+	pMenu->Append(ID_CMD_TIN_FIRST       , LNG("[MNU] TIN")        , m_pFMTINs       ->Create());
+	pMenu->Append(ID_CMD_POINTCLOUD_FIRST, LNG("[MNU] Point Cloud"), m_pFMPointClouds->Create());
+	pMenu->Append(ID_CMD_GRIDS_FIRST     , LNG("[MNU] Grid")       , m_pFMGrids      ->Create());
+
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_FRAME_QUIT);
+
+	//-----------------------------------------------------
+	m_Menus	= (wxMenu **)SG_Realloc(m_Menus, (m_nMenus + 1) * sizeof(wxMenu *));
+	m_Menus[m_nMenus++]	= pMenu;
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_Files::Del(wxMenu *pMenu)
+{
+	for(int i=0; i<m_nMenus; i++)
+	{
+		if( m_Menus[i] == pMenu )
+		{
+			m_nMenus--;
+
+			for( ; i<m_nMenus; i++)
+			{
+				m_Menus[i]	= m_Menus[i + 1];
+			}
+
+			m_Menus	= (wxMenu **)SG_Realloc(m_Menus, m_nMenus * sizeof(wxMenu *));
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Data_Menu_Files::Recent_Open(int Cmd_ID)
+{
+	return(	m_pFMProjects   ->Open(Cmd_ID)
+		||	m_pFMTables     ->Open(Cmd_ID)
+		||	m_pFMShapes     ->Open(Cmd_ID)
+		||	m_pFMTINs       ->Open(Cmd_ID)
+		||	m_pFMPointClouds->Open(Cmd_ID)
+		||	m_pFMGrids      ->Open(Cmd_ID)
+	);
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_Files::Recent_Add(int DataType, const wxChar *FileName)
+{
+	if( m_bUpdate && _Get_Menu(DataType) )
+	{
+		_Get_Menu(DataType)->Add(FileName);
+
+		_Update();
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_Files::Recent_Del(int DataType, const wxChar *FileName)
+{
+	if( m_bUpdate && _Get_Menu(DataType) )
+	{
+		_Get_Menu(DataType)->Del(FileName);
+
+		_Update();
+	}
+}
+
+//---------------------------------------------------------
+inline CWKSP_Data_Menu_File * CWKSP_Data_Menu_Files::_Get_Menu(int DataType)
+{
+	switch( DataType )
+	{
+	case DATAOBJECT_TYPE_Undefined:		return( m_pFMProjects );
+	case DATAOBJECT_TYPE_Table:			return( m_pFMTables );
+	case DATAOBJECT_TYPE_Shapes:		return( m_pFMShapes );
+	case DATAOBJECT_TYPE_TIN:			return( m_pFMTINs );
+	case DATAOBJECT_TYPE_PointCloud:	return( m_pFMPointClouds );
+	case DATAOBJECT_TYPE_Grid:			return( m_pFMGrids );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_Files::_Update(void)
+{
+	for(int i=0; i<m_nMenus; i++)
+	{
+		_Update(m_Menus[i]);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Data_Menu_Files::_Update(wxMenu *pMenu)
+{
+	m_pFMProjects	->Update(pMenu->FindItem(ID_CMD_DATA_FIRST      )->GetSubMenu());
+	m_pFMTables		->Update(pMenu->FindItem(ID_CMD_TABLES_FIRST    )->GetSubMenu());
+	m_pFMShapes		->Update(pMenu->FindItem(ID_CMD_SHAPES_FIRST    )->GetSubMenu());
+	m_pFMTINs		->Update(pMenu->FindItem(ID_CMD_TIN_FIRST       )->GetSubMenu());
+	m_pFMPointClouds->Update(pMenu->FindItem(ID_CMD_POINTCLOUD_FIRST)->GetSubMenu());
+	m_pFMGrids		->Update(pMenu->FindItem(ID_CMD_GRIDS_FIRST     )->GetSubMenu());
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_data_menu_files.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,114 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Data_Menu_Files.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Menu_Files_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Menu_Files_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Data_Menu_Files
+{
+public:
+	CWKSP_Data_Menu_Files(void);
+	virtual ~CWKSP_Data_Menu_Files(void);
+
+	void							Add				(class wxMenu *pMenu);
+	void							Del				(class wxMenu *pMenu);
+
+	void							Set_Update		(bool bUpdate)	{	m_bUpdate	= bUpdate;	}
+
+	bool							Recent_Open		(int Cmd_ID);
+	void							Recent_Add		(int DataType, const wxChar *FileName);
+	void							Recent_Del		(int DataType, const wxChar *FileName);
+
+
+private:
+
+	bool							m_bUpdate;
+
+	int								m_nMenus;
+
+	class wxMenu					**m_Menus;
+
+	class CWKSP_Data_Menu_File		*m_pFMProjects, *m_pFMTables, *m_pFMShapes, *m_pFMTINs, *m_pFMPointClouds, *m_pFMGrids;
+
+
+	class CWKSP_Data_Menu_File *	_Get_Menu		(int DataType);
+
+	void							_Update			(void);
+	void							_Update			(class wxMenu *pMenu);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Data_Menu_Files_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1239 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_Grid.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dc.h>
+#include <wx/dcmemory.h>
+#include <wx/image.h>
+#include <wx/filename.h>
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "active.h"
+#include "active_attributes.h"
+
+#include "wksp_map_control.h"
+
+#include "wksp_layer_classify.h"
+#include "wksp_layer_legend.h"
+#include "wksp_grid.h"
+
+#include "view_scatterplot.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Grid::CWKSP_Grid(CSG_Grid *pGrid)
+	: CWKSP_Layer(pGrid)
+{
+	m_pGrid		= pGrid;
+
+	m_Sel_xN	= -1;
+
+	Create_Parameters();
+}
+
+//---------------------------------------------------------
+CWKSP_Grid::~CWKSP_Grid(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Grid::Get_Name(void)
+{
+	return( wxString::Format(wxT("%02d. %s"), 1 + Get_ID(), m_pGrid->Get_Name()) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Grid::Get_Description(void)
+{
+	wxString	s;
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<b>%s</b><table border=\"0\">"),
+		LNG("[CAP] Grid")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, m_pGrid->Get_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] File")					, m_pGrid->Get_File_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d (x) * %d (y) = %ld</td></tr>"),
+		LNG("[CAP] Number of cells")		, m_pGrid->Get_NX(), m_pGrid->Get_NY(), m_pGrid->Get_NCells()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%f</td></tr>"),
+		LNG("[CAP] Cell size")				, m_pGrid->Get_Cellsize()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>[%f] - [%f] = [%f]</td></tr>"),
+		LNG("[CAP] West-East")				, m_pGrid->Get_XMin(), m_pGrid->Get_XMax(), m_pGrid->Get_XRange()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>[%f] - [%f] = [%f]</td></tr>"),
+		LNG("[CAP] South-North")			, m_pGrid->Get_YMin(), m_pGrid->Get_YMax(), m_pGrid->Get_YRange()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Value Type")				, SG_Data_Type_Get_Name(m_pGrid->Get_Type())
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>[%f] - [%f] = [%f]</td></tr>"),
+		LNG("[CAP] Value Range")			, m_pGrid->Get_ZMin(), m_pGrid->Get_ZMax(), m_pGrid->Get_ZRange()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%f</td></tr>"),
+		LNG("[CAP] Arithmetic Mean")		, m_pGrid->Get_ArithMean(true)
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%f</td></tr>"),
+		LNG("[CAP] Standard Deviation")		, m_pGrid->Get_StdDev(true)
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%fMB</td></tr>"),
+		LNG("[CAP] Memory Size")			, (double)(m_pGrid->Get_NCells() * m_pGrid->Get_nValueBytes()) / N_MEGABYTE_BYTES
+	));
+
+	if( m_pGrid->is_Compressed() )
+	{
+		s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%f%%</td></tr>"),
+			LNG("[CAP] Memory Compression")	, 100.0 * m_pGrid->Get_Compression_Ratio()
+		));
+	}
+
+	if( m_pGrid->is_Cached() )
+	{
+		s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s = %fmb</td></tr>"),
+			LNG("[CAP] File cache activated")	, LNG("buffer size"), m_pGrid->Get_Buffer_Size() / (double)N_MEGABYTE_BYTES
+		));
+	}
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+//	s.Append(wxString::Format(wxT("<hr><b>%s</b><font size=\"-1\">"), LNG("[CAP] Data History")));
+//	s.Append(m_pGrid->Get_History().Get_HTML());
+//	s.Append(wxString::Format(wxT("</font")));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Grid::Get_Menu(void)
+{
+	wxMenu	*pMenu, *pSubMenu;
+
+	pMenu		= new wxMenu(m_pGrid->Get_Name());
+
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_WKSP_ITEM_CLOSE);
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_GRIDS_SAVE);
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_GRIDS_SAVEAS);
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_GRIDS_SAVEAS_IMAGE);
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_GRIDS_SHOW);
+
+	pMenu->AppendSeparator();
+
+	CMD_Menu_Add_Item(pMenu		, true , ID_CMD_GRIDS_HISTOGRAM);
+
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_GRIDS_SCATTERPLOT);
+	CMD_Menu_Add_Item(pMenu		, false, ID_CMD_WKSP_ITEM_SETTINGS_COPY);
+
+	pSubMenu	= new wxMenu(LNG("[MNU] Classificaton"));
+	CMD_Menu_Add_Item(pSubMenu	, false, ID_CMD_GRIDS_EQUALINTERVALS);
+	CMD_Menu_Add_Item(pSubMenu	, false, ID_CMD_GRIDS_SET_LUT);
+	CMD_Menu_Add_Item(pSubMenu	, false, ID_CMD_GRIDS_RANGE_MINMAX);
+	CMD_Menu_Add_Item(pSubMenu	, false, ID_CMD_GRIDS_RANGE_STDDEV150);
+	CMD_Menu_Add_Item(pSubMenu	, false, ID_CMD_GRIDS_RANGE_STDDEV200);
+
+	pMenu->Append(ID_CMD_WKSP_FIRST, LNG("[MNU] Classification"), pSubMenu);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Layer::On_Command(Cmd_ID) );
+
+	case ID_CMD_GRIDS_SAVEAS_IMAGE:
+		_Save_Image();
+		break;
+
+	case ID_CMD_GRIDS_HISTOGRAM:
+		Histogram_Toggle();
+		break;
+
+	case ID_CMD_GRIDS_SCATTERPLOT:
+		Add_ScatterPlot(Get_Grid());
+		break;
+
+	case ID_CMD_GRIDS_EQUALINTERVALS:
+		m_pClassify->Metric2EqualElements();
+		break;
+
+	case ID_CMD_GRIDS_RANGE_MINMAX:
+		Set_Color_Range(
+			m_pGrid->Get_ZMin(true),
+			m_pGrid->Get_ZMax(true)
+		);
+		break;
+
+	case ID_CMD_GRIDS_RANGE_STDDEV150:
+		Set_Color_Range(
+			m_pGrid->Get_ArithMean(true) - 1.5 * m_pGrid->Get_StdDev(true),
+			m_pGrid->Get_ArithMean(true) + 1.5 * m_pGrid->Get_StdDev(true)
+		);
+		break;
+
+	case ID_CMD_GRIDS_RANGE_STDDEV200:
+		Set_Color_Range(
+			m_pGrid->Get_ArithMean(true) - 2.0 * m_pGrid->Get_StdDev(true),
+			m_pGrid->Get_ArithMean(true) + 2.0 * m_pGrid->Get_StdDev(true)
+		);
+		break;
+
+	case ID_CMD_GRIDS_SET_LUT:
+		_LUT_Create();
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Layer::On_Command_UI(event) );
+
+	case ID_CMD_GRIDS_HISTOGRAM:
+		event.Check(m_pHistogram != NULL);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Grid::On_Create_Parameters(void)
+{
+	//-----------------------------------------------------
+	// General...
+
+	m_Parameters.Add_String(
+		m_Parameters("NODE_GENERAL")	, "GENERAL_Z_UNIT"			, LNG("[CAP] Unit"),
+		LNG(""),
+		m_pGrid->Get_Unit()
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_GENERAL")	, "GENERAL_Z_FACTOR"		, LNG("[CAP] Z-Factor"),
+		LNG(""),
+		PARAMETER_TYPE_Double
+	);
+
+	m_Parameters.Add_Range(
+		m_Parameters("NODE_GENERAL")	, "GENERAL_Z_NODATA"		, LNG("[CAP] No Data"),
+		LNG("")
+	);
+
+
+	//-----------------------------------------------------
+	// Memory...
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_MEMORY"				, LNG("[CAP] Memory"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_MEMORY")		, "MEMORY_MODE"				, LNG("[CAP] Memory Handling"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("[VAL] Normal"),
+			LNG("[VAL] RTL Compression"),
+			LNG("[VAL] File Cache")
+		), 0
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_MEMORY")		, "MEMORY_BUFFER_SIZE"		, LNG("[CAP] Buffer Size MB"),
+		LNG(""),
+		PARAMETER_TYPE_Double
+	);
+
+
+	//-----------------------------------------------------
+	// Display...
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_TRANSPARENCY"	, LNG("[CAP] Transparency [%]"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true, 100.0, true
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_INTERPOLATION"	, LNG("[CAP] Interpolation"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|%s|%s|"),
+			LNG("[VAL] None"),
+			LNG("[VAL] Bilinear"),
+			LNG("[VAL] Inverse Distance"),
+			LNG("[VAL] Bicubic Spline"),
+			LNG("[VAL] B-Spline")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	// Classification...
+
+	((CSG_Parameter_Choice *)m_Parameters("COLORS_TYPE")->Get_Data())->Set_Items(
+		wxString::Format(wxT("%s|%s|%s|%s|%s|"),
+			LNG("[VAL] Unique Symbol"),
+			LNG("[VAL] Lookup Table"),
+			LNG("[VAL] Graduated Color"),
+			LNG("[VAL] RGB"),
+			LNG("[VAL] Shade")
+		)
+	);
+
+	m_Parameters("COLORS_TYPE")->Set_Value(CLASSIFY_METRIC);
+
+
+	//-----------------------------------------------------
+	// Cell Values...
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_VALUES"		, LNG("[CAP] Display: Cell Values"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_VALUES")		, "VALUES_SHOW"		, LNG("[CAP] Show"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Font(
+		m_Parameters("NODE_VALUES")		, "VALUES_FONT"		, LNG("[CAP] Font"),
+		LNG("")
+	)->asFont()->SetFamily(wxDECORATIVE);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_VALUES")		, "VALUES_SIZE"		, LNG("[CAP] Size"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 15, 0, true , 100.0, true
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_VALUES")		, "VALUES_DECIMALS"	, LNG("[CAP] Decimals"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 2
+	);
+
+
+	//-----------------------------------------------------
+	DataObject_Changed((CSG_Parameters *)NULL);
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::On_DataObject_Changed(void)
+{
+	//-----------------------------------------------------
+	m_Parameters("GENERAL_Z_UNIT")			->Set_Value((void *)m_pGrid->Get_Unit());
+	m_Parameters("GENERAL_Z_FACTOR")		->Set_Value(m_pGrid->Get_ZFactor());
+
+	m_Parameters("GENERAL_Z_NODATA")->asRange()->Set_Range(
+		m_pGrid->Get_NoData_Value(),
+		m_pGrid->Get_NoData_hiValue()
+	);
+
+	//-----------------------------------------------------
+	m_Parameters("MEMORY_MODE")				->Set_Value(
+		m_pGrid->is_Compressed() ? 1 : (m_pGrid->is_Cached() ? 2 : 0)
+	);
+
+	m_Parameters("MEMORY_BUFFER_SIZE")		->Set_Value(
+		(double)m_pGrid->Get_Buffer_Size() / N_MEGABYTE_BYTES
+	);
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::On_Parameters_Changed(void)
+{
+	//-----------------------------------------------------
+	m_pGrid->Set_Unit		(m_Parameters("GENERAL_Z_UNIT")		->asString());
+	m_pGrid->Set_ZFactor	(m_Parameters("GENERAL_Z_FACTOR")	->asDouble());
+
+	m_pGrid->Set_NoData_Value_Range(
+		m_Parameters("GENERAL_Z_NODATA")->asRange()->Get_LoVal(),
+		m_Parameters("GENERAL_Z_NODATA")->asRange()->Get_HiVal()
+	);
+
+	//-----------------------------------------------------
+	switch( m_Parameters("MEMORY_MODE")->asInt() )
+	{
+	case 0:
+		if( m_pGrid->is_Compressed() )
+		{
+			m_pGrid->Set_Compression(false);
+		}
+		else if( m_pGrid->is_Cached() )
+		{
+			m_pGrid->Set_Cache(false);
+		}
+		break;
+
+	case 1:
+		if( !m_pGrid->is_Compressed() )
+		{
+			m_pGrid->Set_Compression(true);
+		}
+		break;
+
+	case 2:
+		if( !m_pGrid->is_Cached() )
+		{
+			m_pGrid->Set_Cache(true);
+		}
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Grid::_LUT_Create(void)
+{
+	static CSG_Parameters	Parameters;
+
+	if( Parameters.Get_Count() == 0 )
+	{
+		Parameters.Create(NULL, LNG("Create Lookup Table"), LNG(""));
+		Parameters.Add_Colors(NULL, "COLOR"	, LNG("Colors")	, LNG(""));
+	}
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&Parameters) )
+	{
+		int					i, n, x, y;
+		double				dValue, dStep, eValue;
+		CSG_String			sValue;
+		CSG_Colors			*pColors;
+		CSG_Table_Record	*pRecord_LUT;
+		CSG_Table			*pLUT;
+
+		//-------------------------------------------------
+		pColors	= Parameters("COLOR")->asColors();
+
+		pLUT	= m_Parameters("LUT")->asTable();
+		pLUT	->Del_Records();
+
+		for(i=0, n=0; i<m_pGrid->Get_NCells() && n < pColors->Get_Count() && PROGRESSBAR_Set_Position(i, m_pGrid->Get_NCells()); i++)
+		{
+			if( m_pGrid->Get_Sorted(i, x, y) && (n == 0 || dValue != m_pGrid->asDouble(x, y)) )
+			{
+				dValue		= m_pGrid->asDouble(x, y);
+				n++;
+			}
+		}
+
+		//-------------------------------------------------
+		if( n >= pColors->Get_Count() )
+		{
+			dValue	= m_pGrid->Get_ZMin();
+			dStep	= m_pGrid->Get_ZRange() / pColors->Get_Count();
+
+			for(i=0; i<pColors->Get_Count(); i++)
+			{
+				eValue		 = dValue;
+				dValue		+= dStep;
+				sValue		 = SG_Get_String(eValue, SG_Get_Significant_Decimals(eValue), false);
+				sValue		+= SG_T(" - ");
+				sValue		+= SG_Get_String(dValue, SG_Get_Significant_Decimals(dValue), false);
+
+				pRecord_LUT	= pLUT->Add_Record();
+				pRecord_LUT	->Set_Value(0, pColors->Get_Color(i));
+				pRecord_LUT	->Set_Value(1, sValue);			// Name
+				pRecord_LUT	->Set_Value(2, sValue);			// Description
+				pRecord_LUT	->Set_Value(3, eValue);			// Minimum
+				pRecord_LUT	->Set_Value(4, dValue);			// Maximum
+			}
+		}
+		else
+		{
+			pColors->Set_Count(n);
+
+			for(i=0, n=0; i<m_pGrid->Get_NCells() && PROGRESSBAR_Set_Position(i, m_pGrid->Get_NCells()); i++)
+			{
+				if( m_pGrid->Get_Sorted(i, x, y) && (pLUT->Get_Record_Count() == 0 || dValue != m_pGrid->asDouble(x, y)) )
+				{
+					dValue		= m_pGrid->asDouble(x, y);
+					sValue		= SG_Get_String(dValue, SG_Get_Significant_Decimals(dValue), false);
+
+					pRecord_LUT	= pLUT->Add_Record();
+					pRecord_LUT	->Set_Value(0, pColors->Get_Color(n++));
+					pRecord_LUT	->Set_Value(1, sValue);		// Name
+					pRecord_LUT	->Set_Value(2, sValue);		// Description
+					pRecord_LUT	->Set_Value(3, dValue);		// Minimum
+					pRecord_LUT	->Set_Value(4, dValue);		// Maximum
+				}
+			}
+		}
+
+		PROGRESSBAR_Set_Position(0);
+
+		DataObject_Changed();
+
+		m_Parameters("COLORS_TYPE")		->Set_Value(1);		// Lookup Table
+
+		Parameters_Changed();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Grid::Get_Value(CSG_Point ptWorld, double Epsilon)
+{
+	double		Value;
+	wxString	s;
+
+	if( m_pGrid->Get_Value(ptWorld, Value, GRID_INTERPOLATION_NearestNeighbour, true) )
+	{
+		switch( m_pClassify->Get_Mode() )
+		{
+		case CLASSIFY_LUT:
+			s	= m_pClassify->Get_Class_Name_byValue(Value);
+			break;
+
+		case CLASSIFY_METRIC:	default:
+		case CLASSIFY_SHADE:
+			switch( m_pGrid->Get_Type() )
+			{
+			case SG_DATATYPE_Byte:
+			case SG_DATATYPE_Char:
+			case SG_DATATYPE_Word:
+			case SG_DATATYPE_Short:
+			case SG_DATATYPE_DWord:
+			case SG_DATATYPE_Int:
+				s.Printf(wxT("%d%s"), (int)Value, m_pGrid->Get_Unit());
+				break;
+
+			case SG_DATATYPE_Float:	default:
+			case SG_DATATYPE_Double:
+				s.Printf(wxT("%f%s"), Value, m_pGrid->Get_Unit());
+				break;
+			}
+			break;
+
+		case CLASSIFY_RGB:
+			s.Printf(wxT("R%03d G%03d B%03d"), SG_GET_R((int)Value), SG_GET_G((int)Value), SG_GET_B((int)Value));
+			break;
+		}
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+double CWKSP_Grid::Get_Value_Range(void)
+{
+	return( m_pGrid->Get_ZRange() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid::On_Edit_On_Key_Down(int KeyCode)
+{
+	switch( KeyCode )
+	{
+	default:
+		return( false );
+
+	case WXK_DELETE:
+		return( _Edit_Del_Selection() );
+	}
+}
+
+//---------------------------------------------------------
+#define SELECTION_MAX	20
+
+//---------------------------------------------------------
+bool CWKSP_Grid::On_Edit_On_Mouse_Up(CSG_Point Point, double ClientToWorld, int Key)
+{
+	int				x, y;
+	CSG_Table_Record	*pRecord;
+	CSG_Rect		rWorld(m_Edit_Mouse_Down, Point);
+
+	m_Sel_xOff	= m_pGrid->Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin());
+	if( m_Sel_xOff < 0 )
+		m_Sel_xOff	= 0;
+	m_Sel_xN	= m_pGrid->Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax());
+	if( m_Sel_xN >= m_pGrid->Get_NX() )
+		m_Sel_xN	= m_pGrid->Get_NX() - 1;
+	m_Sel_xN	= 1 + m_Sel_xN - m_Sel_xOff;
+
+	m_Sel_yOff	= m_pGrid->Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin());
+	if( m_Sel_yOff < 0 )
+		m_Sel_yOff	= 0;
+	m_Sel_yN	= m_pGrid->Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax());
+	if( m_Sel_yN >= m_pGrid->Get_NY() )
+		m_Sel_yN	= m_pGrid->Get_NY() - 1;
+	m_Sel_yN	= 1 + m_Sel_yN - m_Sel_yOff;
+
+	m_Edit_Attributes.Destroy();
+
+	if( m_Sel_xN < 1 || m_Sel_yN < 1 )
+	{
+		m_Sel_xN	= -1;
+	}
+	else
+	{
+		if( m_Sel_xN > SELECTION_MAX )
+		{
+			m_Sel_xOff	+= (m_Sel_xN - SELECTION_MAX) / 2;
+			m_Sel_xN	= SELECTION_MAX;
+		}
+
+		if( m_Sel_yN > SELECTION_MAX )
+		{
+			m_Sel_yOff	+= (m_Sel_yN - SELECTION_MAX) / 2;
+			m_Sel_yN	= SELECTION_MAX;
+		}
+
+		for(x=0; x<m_Sel_xN; x++)
+		{
+			m_Edit_Attributes.Add_Field(wxString::Format(wxT("%d"), x + 1), SG_DATATYPE_Double);
+		}
+
+		for(y=0; y<m_Sel_yN; y++)
+		{
+			pRecord	= m_Edit_Attributes.Add_Record();
+
+			for(x=0; x<m_Sel_xN; x++)
+			{
+				pRecord->Set_Value(x, m_pGrid->asDouble(m_Sel_xOff + x, m_Sel_yOff + m_Sel_yN - 1 - y, false));
+			}
+		}
+	}
+
+	g_pACTIVE->Get_Attributes()->Set_Attributes();
+
+	Update_Views(true);
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid::On_Edit_Set_Attributes(void)
+{
+	int				x, y;
+	CSG_Table_Record	*pRecord;
+
+	if( m_Sel_xN >= 0 )
+	{
+		for(y=0; y<m_Sel_yN; y++)
+		{
+			pRecord	= m_Edit_Attributes.Get_Record(y);
+
+			for(x=0; x<m_Sel_xN; x++)
+			{
+				m_pGrid->Set_Value(m_Sel_xOff + x, m_Sel_yOff + m_Sel_yN - 1 - y, pRecord->asDouble(x));
+			}
+		}
+
+		Update_Views(true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+TSG_Rect CWKSP_Grid::On_Edit_Get_Extent(void)
+{
+	if( m_Sel_xN >= 0 )
+	{
+		return( CSG_Rect(
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_xGrid_to_World(m_Sel_xOff),
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_yGrid_to_World(m_Sel_yOff),
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_xGrid_to_World(m_Sel_xOff + m_Sel_xN),
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_yGrid_to_World(m_Sel_yOff + m_Sel_yN))
+		);
+	}
+
+	return( m_pGrid->Get_Extent().m_rect );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid::_Edit_Del_Selection(void)
+{
+	int		x, y;
+
+	if( m_Sel_xN >= 0 && DLG_Message_Confirm(LNG("[DLG] Set selected values to no data."), LNG("[CAP] Delete")) )
+	{
+		for(y=m_Sel_yOff; y<m_Sel_yOff + m_Sel_yN; y++)
+		{
+			for(x=m_Sel_xOff; x<m_Sel_xOff + m_Sel_xN; x++)
+			{
+				m_pGrid->Set_NoData(x, y);
+			}
+		}
+
+		Update_Views(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid::Fit_Color_Range(CSG_Rect rWorld)
+{
+	int		x, y, xMin, yMin, xMax, yMax;
+	double	z, zMin, zMax;
+
+	if( rWorld.Intersect(Get_Extent()) )
+	{
+		xMin	= m_pGrid->Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin());
+		yMin	= m_pGrid->Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin());
+		xMax	= m_pGrid->Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax());
+		yMax	= m_pGrid->Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax());
+		zMin	= 1.0;
+		zMax	= 0.0;
+
+		for(y=yMin; y<=yMax; y++)
+		{
+			for(x=xMin; x<=xMax; x++)
+			{
+				if( m_pGrid->is_InGrid(x, y) )
+				{
+					z	= m_pGrid->asDouble(x, y);
+
+					if( zMin > zMax )
+					{
+						zMin	= zMax	= z;
+					}
+					else if( z < zMin )
+					{
+						zMin	= z;
+					}
+					else if( z > zMax )
+					{
+						zMax	= z;
+					}
+				}
+			}
+		}
+
+		return( Set_Color_Range(zMin, zMax) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid::asImage(CSG_Grid *pImage)
+{
+	int			x, y;
+	wxBitmap	BMP;
+
+	if( pImage && Get_Image_Grid(BMP) )
+	{
+		wxImage	IMG(BMP.ConvertToImage());
+
+		pImage->Create(m_pGrid, SG_DATATYPE_Int);
+
+		for(y=0; y<pImage->Get_NY() && PROGRESSBAR_Set_Position(y, pImage->Get_NY()); y++)
+		{
+			for(x=0; x<pImage->Get_NX(); x++)
+			{
+				pImage->Set_Value(x, y, SG_GET_RGB(IMG.GetRed(x, y), IMG.GetGreen(x, y), IMG.GetBlue(x, y)));
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::_Save_Image(void)
+{
+	int				type;
+	wxString		file;
+	wxBitmap		BMP;
+	CSG_File		Stream;
+	CSG_Parameters	Parms;
+
+	//-----------------------------------------------------
+	Parms.Set_Name(LNG("[CAP] Save Grid as Image..."));
+
+	Parms.Add_Value(
+		NULL	, "WORLD"	, LNG("Save Georeference"),
+		wxT(""),
+		PARAMETER_TYPE_Bool, 1
+	);
+
+	Parms.Add_Value(
+		NULL	, "LG"	, LNG("Legend: Save"),
+		wxT(""),
+		PARAMETER_TYPE_Bool, 1
+	);
+
+	Parms.Add_Value(
+		NULL	, "LZ"	, LNG("Legend: Zoom"),
+		wxT(""),
+		PARAMETER_TYPE_Double, 1.0, 0, true
+	);
+
+	//-----------------------------------------------------
+	if( DLG_Image_Save(file, type) && DLG_Parameters(&Parms) )
+	{
+		if( Get_Image_Grid(BMP) )
+		{
+			BMP.SaveFile(file, (wxBitmapType)type);
+		}
+
+		if( Parms("LG")->asBool() && Get_Image_Legend(BMP, Parms("LZ")->asDouble()) )
+		{
+			wxFileName	fn(file);
+			fn.SetName(wxString::Format(wxT("%s_legend"), fn.GetName().c_str()));
+
+			BMP.SaveFile(fn.GetFullPath(), (wxBitmapType)type);
+		}
+
+		if( Parms("WORLD")->asBool() )
+		{
+			wxFileName	fn(file);
+
+			switch( type )
+			{
+			default:					fn.SetExt(wxT("world"));	break;
+			case wxBITMAP_TYPE_BMP:		fn.SetExt(wxT("bpw"));		break;
+			case wxBITMAP_TYPE_GIF:		fn.SetExt(wxT("gfw"));		break;
+			case wxBITMAP_TYPE_JPEG:	fn.SetExt(wxT("jgw"));		break;
+			case wxBITMAP_TYPE_PNG:		fn.SetExt(wxT("pgw"));		break;
+			case wxBITMAP_TYPE_PCX:		fn.SetExt(wxT("pxw"));		break;
+			case wxBITMAP_TYPE_TIF:		fn.SetExt(wxT("tfw"));		break; 
+			}
+
+			if( Stream.Open(fn.GetFullPath().c_str(), SG_FILE_W, false) )
+			{
+				Stream.Printf(wxT("%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n"),
+					 m_pGrid->Get_Cellsize(),
+					 0.0, 0.0,
+					-m_pGrid->Get_Cellsize(),
+					 m_pGrid->Get_XMin(),
+					 m_pGrid->Get_YMax()
+				);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid::Get_Image_Grid(wxBitmap &BMP, bool bFitSize)
+{
+	if( bFitSize || (BMP.GetWidth() > 0 && BMP.GetHeight() > 0) )
+	{
+		Set_Buisy_Cursor(true);
+
+		if( bFitSize )
+		{
+			BMP.Create(m_pGrid->Get_NX(), m_pGrid->Get_NY());
+		}
+
+		wxMemoryDC		dc;
+		wxRect			r(0, 0, BMP.GetWidth(), BMP.GetHeight());
+		CWKSP_Map_DC	dc_Map(Get_Extent(), r, 1.0, SG_GET_RGB(255, 255, 255));
+
+		On_Draw(dc_Map, false);
+
+		dc.SelectObject(BMP);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		dc_Map.Draw(dc);
+
+		dc.SelectObject(wxNullBitmap);
+
+		Set_Buisy_Cursor(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid::Get_Image_Legend(wxBitmap &BMP, double Zoom)
+{
+	if( Zoom > 0.0 )
+	{
+		wxMemoryDC	dc;
+		wxSize		s(Get_Legend()->Get_Size(Zoom, 1.0));
+
+		BMP.Create(s.GetWidth(), s.GetHeight());
+
+		dc.SelectObject(BMP);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		Get_Legend()->Draw(dc, Zoom, 1.0, wxPoint(0, 0));
+
+		dc.SelectObject(wxNullBitmap);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Grid::On_Draw(CWKSP_Map_DC &dc_Map, bool bEdit)
+{
+	int		Interpolation;
+	double	Transparency;
+
+	if(	Get_Extent().Intersects(dc_Map.m_rWorld) != INTERSECTION_None )
+	{
+		switch( m_pClassify->Get_Mode() )
+		{
+		default:				Transparency	= m_Parameters("DISPLAY_TRANSPARENCY")->asDouble() / 100.0;	break;
+		case CLASSIFY_SHADE:	Transparency	= 2.0;	break;
+		case CLASSIFY_RGB:		Transparency	= m_Parameters("DISPLAY_TRANSPARENCY")->asDouble() / 100.0;	if( Transparency <= 0.0 )	Transparency	= 3.0;	break;
+		}
+
+		if( dc_Map.IMG_Draw_Begin(Transparency) )
+		{
+			Interpolation	= m_pClassify->Get_Mode() == CLASSIFY_LUT
+							? GRID_INTERPOLATION_NearestNeighbour
+							: m_Parameters("DISPLAY_INTERPOLATION")->asInt();
+
+			if(	dc_Map.m_DC2World >= m_pGrid->Get_Cellsize()
+			||	Interpolation != GRID_INTERPOLATION_NearestNeighbour )
+			{
+				_Draw_Grid_Points	(dc_Map, Interpolation);
+			}
+			else
+			{
+				_Draw_Grid_Cells	(dc_Map);
+			}
+
+			dc_Map.IMG_Draw_End();
+
+			_Draw_Values(dc_Map);
+
+			if( bEdit )
+			{
+				_Draw_Edit(dc_Map);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::_Draw_Grid_Points(CWKSP_Map_DC &dc_Map, int Interpolation)
+{
+	bool		bByteWise	= m_pClassify->Get_Mode() == CLASSIFY_RGB;
+	int			xDC, yDC, axDC, ayDC, bxDC, byDC, Color;
+	double		x, y, z;
+	CSG_Rect	rGrid(m_pGrid->Get_Extent());
+
+	rGrid.Inflate(m_pGrid->Get_Cellsize() / 2.0, false);
+	rGrid.Intersect(dc_Map.m_rWorld);
+
+	axDC	= (int)dc_Map.xWorld2DC(rGrid.Get_XMin());	if( axDC < 0 )	axDC	= 0;
+	bxDC	= (int)dc_Map.xWorld2DC(rGrid.Get_XMax());	if( bxDC > dc_Map.m_rDC.GetWidth() )	bxDC	= dc_Map.m_rDC.GetWidth();
+	ayDC	= (int)dc_Map.yWorld2DC(rGrid.Get_YMin());	if( ayDC > dc_Map.m_rDC.GetHeight() )	ayDC	= dc_Map.m_rDC.GetHeight();
+	byDC	= (int)dc_Map.yWorld2DC(rGrid.Get_YMax());	if( byDC < 0 )	byDC	= 0;
+
+	for(y=rGrid.Get_YMin(), yDC=ayDC-1; yDC>=byDC; y+=dc_Map.m_DC2World, yDC--)
+	{
+		for(x=rGrid.Get_XMin(), xDC=axDC; xDC<bxDC; x+=dc_Map.m_DC2World, xDC++)
+		{
+			if( m_pGrid->Get_Value(x, y, z, Interpolation, false, bByteWise, true) && m_pClassify->Get_Class_Color_byValue(z, Color) )
+			{
+				dc_Map.IMG_Set_Pixel(xDC, yDC, Color);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::_Draw_Grid_Cells(CWKSP_Map_DC &dc_Map)
+{
+	int		x, y, xa, ya, xb, yb, xaDC, yaDC, xbDC, ybDC, Color;
+	double	xDC, yDC, axDC, ayDC, dDC;
+
+	//-----------------------------------------------------
+	dDC		= m_pGrid->Get_Cellsize() * dc_Map.m_World2DC;
+
+	xa		= m_pGrid->Get_System().Get_xWorld_to_Grid(dc_Map.m_rWorld.Get_XMin());
+	ya		= m_pGrid->Get_System().Get_yWorld_to_Grid(dc_Map.m_rWorld.Get_YMin());
+	xb		= m_pGrid->Get_System().Get_xWorld_to_Grid(dc_Map.m_rWorld.Get_XMax());
+	yb		= m_pGrid->Get_System().Get_yWorld_to_Grid(dc_Map.m_rWorld.Get_YMax());
+
+	if( xa < 0 )	xa	= 0;	if( xb >= m_pGrid->Get_NX() )	xb	= m_pGrid->Get_NX() - 1;
+	if( ya < 0 )	ya	= 0;	if( yb >= m_pGrid->Get_NY() )	yb	= m_pGrid->Get_NY() - 1;
+
+	axDC	= dc_Map.xWorld2DC(m_pGrid->Get_System().Get_xGrid_to_World(xa)) + dDC / 2.0;
+	ayDC	= dc_Map.yWorld2DC(m_pGrid->Get_System().Get_yGrid_to_World(ya)) - dDC / 2.0;
+
+	//-----------------------------------------------------
+	for(y=ya, yDC=ayDC, yaDC=(int)(ayDC), ybDC=(int)(ayDC+dDC); y<=yb; y++, ybDC=yaDC, yaDC=(int)(yDC-=dDC))
+	{
+		for(x=xa, xDC=axDC, xaDC=(int)(axDC-dDC), xbDC=(int)(axDC); x<=xb; x++, xaDC=xbDC, xbDC=(int)(xDC+=dDC))
+		{
+			if( m_pGrid->is_InGrid(x, y) && m_pClassify->Get_Class_Color_byValue(m_pGrid->asDouble(x, y), Color) )
+			{
+				dc_Map.IMG_Set_Rect(xaDC, yaDC, xbDC, ybDC, Color);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::_Draw_Values(CWKSP_Map_DC &dc_Map)
+{
+	int			x, y, xa, ya, xb, yb, Decimals;
+	double		xDC, yDC, axDC, ayDC, dDC, zFactor, Value;
+	wxString	s;
+	wxFont		Font;
+
+	//-----------------------------------------------------
+	if(	m_Parameters("VALUES_SHOW")->asBool() && (dDC = m_pGrid->Get_Cellsize() * dc_Map.m_World2DC) > 40 )
+	{
+		zFactor		=  m_pGrid->Get_ZFactor();
+		Decimals	=  m_Parameters("VALUES_DECIMALS")	->asInt();
+
+		xDC			=  m_Parameters("VALUES_SIZE")		->asDouble() / 100.0;
+		x			=  m_Parameters("VALUES_FONT")		->asColor();
+		Font		= *m_Parameters("VALUES_FONT")		->asFont();
+		Font.SetPointSize((int)(xDC * dDC));
+		dc_Map.dc.SetFont(Font);
+		dc_Map.dc.SetTextForeground(Get_Color_asWX(x));
+
+		x			=  m_Parameters("VALUES_FONT")		->asInt();
+		dc_Map.dc.SetTextForeground(wxColour(SG_GET_R(x), SG_GET_G(x), SG_GET_B(x)));
+
+		//-------------------------------------------------
+		xa		= m_pGrid->Get_System().Get_xWorld_to_Grid(dc_Map.m_rWorld.Get_XMin());
+		ya		= m_pGrid->Get_System().Get_yWorld_to_Grid(dc_Map.m_rWorld.Get_YMin());
+		xb		= m_pGrid->Get_System().Get_xWorld_to_Grid(dc_Map.m_rWorld.Get_XMax());
+		yb		= m_pGrid->Get_System().Get_yWorld_to_Grid(dc_Map.m_rWorld.Get_YMax());
+
+		if( xa < 0 )	xa	= 0;	if( xb >= m_pGrid->Get_NX() )	xb	= m_pGrid->Get_NX() - 1;
+		if( ya < 0 )	ya	= 0;	if( yb >= m_pGrid->Get_NY() )	yb	= m_pGrid->Get_NY() - 1;
+
+		axDC	= dc_Map.xWorld2DC(m_pGrid->Get_System().Get_xGrid_to_World(xa));
+		ayDC	= dc_Map.yWorld2DC(m_pGrid->Get_System().Get_yGrid_to_World(ya));
+
+		//-------------------------------------------------
+		for(y=ya, yDC=ayDC; y<=yb; y++, yDC-=dDC)
+		{
+			for(x=xa, xDC=axDC; x<=xb; x++, xDC+=dDC)
+			{
+				if( m_pGrid->is_InGrid(x, y) )
+				{
+					Value	= m_pGrid->asDouble(x, y);
+
+					switch( m_pClassify->Get_Mode() )
+					{
+					case CLASSIFY_RGB:
+						s.Printf(wxT("R%03d G%03d B%03d"), SG_GET_R((int)Value), SG_GET_G((int)Value), SG_GET_B((int)Value));
+						break;
+
+					default:
+						s.Printf(wxT("%.*f"), Decimals, zFactor * Value);
+						break;
+					}
+
+					Draw_Text(dc_Map.dc, TEXTALIGN_CENTER, (int)xDC, (int)yDC, s);
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Grid::_Draw_Edit(CWKSP_Map_DC &dc_Map)
+{
+	if( m_Sel_xN >= 0 )
+	{
+		CSG_Rect	r(
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_xGrid_to_World(m_Sel_xOff),
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_yGrid_to_World(m_Sel_yOff),
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_xGrid_to_World(m_Sel_xOff + m_Sel_xN),
+			-m_pGrid->Get_Cellsize() / 2.0 + m_pGrid->Get_System().Get_yGrid_to_World(m_Sel_yOff + m_Sel_yN)
+		);
+
+		TSG_Point_Int		a(dc_Map.World2DC(r.Get_TopLeft())),
+						b(dc_Map.World2DC(r.Get_BottomRight()));
+
+		a.x	-= 1;
+		b.x	-= 1;
+		a.y	-= 1;
+		b.y	-= 1;
+
+		dc_Map.dc.SetPen(wxPen(wxColour(255, 0, 0), 2, wxSOLID));
+		dc_Map.dc.DrawLine(a.x, a.y, a.x, b.y);
+		dc_Map.dc.DrawLine(a.x, b.y, b.x, b.y);
+		dc_Map.dc.DrawLine(b.x, b.y, b.x, a.y);
+		dc_Map.dc.DrawLine(a.x, a.y, b.x, a.y);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,157 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WKSP_Grid.h                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_layer.h"
+
+class CSVG_Interactive_Map;
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Grid : public CWKSP_Layer
+{
+	friend class CSVG_Interactive_Map;
+
+public:
+	CWKSP_Grid(CSG_Grid *pGrid);
+	virtual ~CWKSP_Grid(void);
+
+	virtual TWKSP_Item			Get_Type				(void)	{	return( WKSP_ITEM_Grid );	}
+
+	virtual wxString			Get_Name				(void);
+	virtual wxString			Get_Description			(void);
+
+	virtual wxMenu *			Get_Menu				(void);
+
+	virtual bool				On_Command				(int Cmd_ID);
+	virtual bool				On_Command_UI			(wxUpdateUIEvent &event);
+
+	virtual wxString			Get_Value				(CSG_Point ptWorld, double Epsilon);
+	virtual double				Get_Value_Range			(void);
+
+	CSG_Grid *					Get_Grid				(void)	{	return( m_pGrid );	}
+
+	bool						Fit_Color_Range			(CSG_Rect rWorld);
+
+	bool						asImage					(CSG_Grid *pImage);
+
+
+protected:
+
+	bool						Get_Image_Grid			(wxBitmap &BMP, bool bFitSize = true);
+	bool						Get_Image_Legend		(wxBitmap &BMP, double Zoom);
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+
+	virtual bool				On_Edit_On_Key_Down		(int KeyCode);
+	virtual bool				On_Edit_On_Mouse_Up		(CSG_Point Point, double ClientToWorld, int Key);
+	virtual bool				On_Edit_Set_Attributes	(void);
+	virtual TSG_Rect			On_Edit_Get_Extent		(void);
+
+	virtual void				On_Draw					(CWKSP_Map_DC &dc_Map, bool bEdit);
+
+
+private:
+
+	int							m_Interpolation, m_Sel_xOff, m_Sel_xN, m_Sel_yOff, m_Sel_yN;
+
+	CSG_Grid					*m_pGrid;
+
+
+	void						_LUT_Create				(void);
+
+	bool						_Edit_Del_Selection		(void);
+
+	void						_Save_Image				(void);
+
+	void						_Draw_Grid_Points		(CWKSP_Map_DC &dc_Map, int Interpolation);
+	void						_Draw_Grid_Cells		(CWKSP_Map_DC &dc_Map);
+
+	void						_Draw_Values			(CWKSP_Map_DC &dc_Map);
+	void						_Draw_Edit				(CWKSP_Map_DC &dc_Map);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,372 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Grid_Manager.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_map_manager.h"
+
+#include "wksp_grid_manager.h"
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Grid_Manager::CWKSP_Grid_Manager(void)
+{
+}
+
+//---------------------------------------------------------
+CWKSP_Grid_Manager::~CWKSP_Grid_Manager(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Grid_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] Grids") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Grid_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b><br>%d %s"), LNG("[CAP] Grids"), Get_Count(), Get_Count() == 1 ? LNG("[TXT] grid system") : LNG("[TXT] grid systems"));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Grid_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Grids"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_GRIDS_OPEN);
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Grid_System * CWKSP_Grid_Manager::Get_System(CSG_Grid_System *pSystem)
+{
+	if( pSystem != NULL )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( pSystem->is_Equal(*Get_System(i)->Get_System()) )
+			{
+				return( Get_System(i) );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Grid_System * CWKSP_Grid_Manager::_Get_System(CSG_Grid_System *pSystem)
+{
+	CWKSP_Grid_System	*pItem;
+
+	if( pSystem )
+	{
+		if( (pItem = Get_System(pSystem)) == NULL )
+		{
+			Add_Item(pItem = new CWKSP_Grid_System(*pSystem));
+		}
+
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Exists(CSG_Grid_System *pSystem)
+{
+	return( Get_System(pSystem) != NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Grid * CWKSP_Grid_Manager::Get_Grid(CSG_Grid *pGrid)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( Get_System(i)->Get_Grid(pGrid) )
+		{
+			return( Get_System(i)->Get_Grid(pGrid) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Exists(CSG_Grid *pGrid)
+{
+	return( Get_Grid(pGrid) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Grid * CWKSP_Grid_Manager::Add(CSG_Grid *pGrid)
+{
+	if( pGrid && pGrid->is_Valid() && !Exists(pGrid) )
+	{
+		return( _Get_System((CSG_Grid_System *)&pGrid->Get_System())->Add(pGrid) );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Grid * CWKSP_Grid_Manager::Get_byFileName(const wxChar *File_Name)
+{
+	CSG_String	s(File_Name);
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		for(int j=0; j<Get_System(i)->Get_Count(); j++)
+		{
+			if( !s.Cmp(Get_System(i)->Get_Grid(j)->Get_Grid()->Get_File_Name()) )
+			{
+				return( Get_System(i)->Get_Grid(j)->Get_Grid() );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Update(CSG_Grid *pGrid, CSG_Parameters *pParameters)
+{
+	CWKSP_Grid	*pItem;
+
+	if( (pItem = Get_Grid(pGrid)) != NULL )
+	{
+		pItem->DataObject_Changed(pParameters);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Update_Views(CSG_Grid *pGrid)
+{
+	CWKSP_Grid	*pItem;
+
+	if( (pItem = Get_Grid(pGrid)) != NULL )
+	{
+		pItem->Update_Views(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Show(CSG_Grid *pGrid, int Map_Mode)
+{
+	CWKSP_Grid	*pItem;
+
+	if( (pItem = Get_Grid(pGrid)) != NULL )
+	{
+		switch( Map_Mode )
+		{
+		case SG_UI_DATAOBJECT_SHOW:
+			return( pItem->Show() );
+
+		case SG_UI_DATAOBJECT_SHOW_NEW_MAP:
+			g_pMaps->Add(pItem, NULL);
+
+		case SG_UI_DATAOBJECT_SHOW_LAST_MAP:
+			return( pItem->Show(g_pMaps->Get_Map(g_pMaps->Get_Count() - 1)) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::asImage(CSG_Grid *pGrid, CSG_Grid *pImage)
+{
+	CWKSP_Grid	*pItem;
+
+	if( (pItem = Get_Grid(pGrid)) != NULL )
+	{
+		return( pItem->asImage(pImage) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Get_Colors(CSG_Grid *pGrid, CSG_Colors *pColors)
+{
+	CWKSP_Grid	*pItem;
+
+	if( (pItem = Get_Grid(pGrid)) != NULL )
+	{
+		return( pItem->Get_Colors(pColors) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_Manager::Set_Colors(CSG_Grid *pGrid, CSG_Colors *pColors)
+{
+	CWKSP_Grid	*pItem;
+
+	if( (pItem = Get_Grid(pGrid)) != NULL )
+	{
+		pItem->DataObject_Changed(pColors);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,129 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Grid_Manager.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Grid_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Grid_Manager(void);
+	virtual ~CWKSP_Grid_Manager(void);
+
+	virtual TWKSP_Item				Get_Type			(void)		{	return( WKSP_ITEM_Grid_Manager );	}
+
+	virtual wxString				Get_Name			(void);
+	virtual wxString				Get_Description		(void);
+
+	virtual wxMenu *				Get_Menu			(void);
+
+	virtual bool					On_Command			(int Cmd_ID);
+
+	class CWKSP_Grid_System *		Get_System			(int i)		{	return( (class CWKSP_Grid_System *)Get_Item(i) );	}
+	class CWKSP_Grid_System *		Get_System			(class CSG_Grid_System *pSystem);
+	bool							Exists				(class CSG_Grid_System *pSystem);
+
+	class CWKSP_Grid *				Get_Grid			(class CSG_Grid *pGrid);
+	bool							Exists				(class CSG_Grid *pGrid);
+	class CWKSP_Grid *				Add					(class CSG_Grid *pGrid);
+	class CSG_Grid *				Get_byFileName		(const wxChar *File_Name);
+
+	bool							Update				(class CSG_Grid *pGrid, class CSG_Parameters *pParameters);
+	bool							Update_Views		(class CSG_Grid *pGrid);
+	bool							Show				(class CSG_Grid *pGrid, int Map_Mode);
+	bool							asImage				(class CSG_Grid *pGrid, class CSG_Grid *pImage);
+
+	bool							Get_Colors			(class CSG_Grid *pGrid, class CSG_Colors *pColors);
+	bool							Set_Colors			(class CSG_Grid *pGrid, class CSG_Colors *pColors);
+
+
+private:
+
+	class CWKSP_Grid_System *		_Get_System			(class CSG_Grid_System *pSystem);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,207 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Grid_System.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+
+#include "wksp_grid_system.h"
+#include "wksp_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Grid_System::CWKSP_Grid_System(const CSG_Grid_System &System)
+{
+	m_System	= System;
+
+	m_Parameters.Add_String(
+		NULL	, "NAME"	, LNG("Name"),
+		LNG("Descriptive name for the grid system"),
+		m_System.Get_Name()
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Grid_System::~CWKSP_Grid_System(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Grid_System::Parameters_Changed(void)
+{
+	CWKSP_Base_Item::Parameters_Changed();
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Grid_System::Get_Name(void)
+{
+	return( m_Parameters("NAME")->asString() );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Grid_System::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b><table border=\"0\">"), LNG("[CAP] Grid System"));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, Get_Name().c_str()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Number Of Grids")		, Get_Count()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d (x) * %d (y) = %ld</td></tr>"),
+		LNG("[CAP] Number Of Cells")		, m_System.Get_NX(), m_System.Get_NY(), m_System.Get_NCells()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%f</td></tr>"),
+		LNG("[CAP] Cell Size")				, m_System.Get_Cellsize()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>[%f] - [%f] = [%f]</td></tr>"),
+		LNG("[CAP] West-East")				, m_System.Get_XMin(), m_System.Get_XMax(), m_System.Get_XRange()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>[%f] - [%f] = [%f]</td></tr>"),
+		LNG("[CAP] South-North")			, m_System.Get_YMin(), m_System.Get_YMax(), m_System.Get_YRange()
+	));
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Grid_System::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Grid * CWKSP_Grid_System::Get_Grid(CSG_Grid *pGrid)
+{
+	if( pGrid )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( pGrid == Get_Grid(i)->Get_Grid() )
+			{
+				return( Get_Grid(i) );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Grid_System::Exists(CSG_Grid *pGrid)
+{
+	return( Get_Grid(pGrid) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Grid * CWKSP_Grid_System::Add(CSG_Grid *pGrid)
+{
+	CWKSP_Grid	*pItem;
+
+	if( pGrid && pGrid->Get_System() == m_System && !Exists(pGrid) && Add_Item(pItem = new CWKSP_Grid(pGrid)) )
+	{
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_grid_system.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,125 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Grid_System.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_System_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_System_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Grid_System : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Grid_System(const CSG_Grid_System &System);
+	virtual ~CWKSP_Grid_System(void);
+
+	virtual TWKSP_Item				Get_Type			(void)		{	return( WKSP_ITEM_Grid_System );	}
+
+	virtual wxString				Get_Name			(void);
+	virtual wxString				Get_Description		(void);
+
+	virtual CSG_Parameters *		Get_Parameters		(void)		{	return( &m_Parameters );	}
+	virtual void					Parameters_Changed	(void);
+
+	virtual wxMenu *				Get_Menu			(void);
+
+	CSG_Grid_System *				Get_System			(void)		{	return( &m_System );	}
+
+	class CWKSP_Grid *				Get_Grid			(int i)		{	return( (class CWKSP_Grid *)Get_Item(i) );	}
+	class CWKSP_Grid *				Get_Grid			(class CSG_Grid *pGrid);
+
+	bool							Exists				(class CSG_Grid *pGrid);
+	class CWKSP_Grid *				Add					(class CSG_Grid *pGrid);
+
+
+private:
+
+	CSG_Grid_System					m_System;
+
+	CSG_Parameters					m_Parameters;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Grid_System_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,917 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_Layer.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "active.h"
+#include "active_parameters.h"
+
+#include "wksp_base_control.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_data_menu_files.h"
+
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+
+#include "wksp_data_layers.h"
+
+#include "wksp_layer.h"
+#include "wksp_layer_classify.h"
+#include "wksp_layer_legend.h"
+
+#include "view_histogram.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DEF_LAYER_COLOUR_COUNT	15
+
+//---------------------------------------------------------
+static int	s_Def_Layer_Colours[DEF_LAYER_COLOUR_COUNT]	=
+{
+	SG_COLOR_RED,
+	SG_COLOR_GREEN,
+	SG_COLOR_BLUE,
+	SG_COLOR_YELLOW,
+
+	SG_GET_RGB(255, 127,   0),
+	SG_COLOR_GREEN_LIGHT,
+	SG_COLOR_BLUE_LIGHT,
+	SG_GET_RGB(255, 255, 127),
+
+	SG_COLOR_RED_DARK,
+	SG_COLOR_GREEN_DARK,
+	SG_COLOR_BLUE_DARK,
+	SG_COLOR_YELLOW_DARK,
+
+	SG_COLOR_BLUE_GREEN,
+	SG_COLOR_PURPLE,
+	SG_COLOR_PINK
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Layer *	Get_Active_Layer(void)
+{
+	return( g_pACTIVE ? g_pACTIVE->Get_Layer() : NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Layer::CWKSP_Layer(CSG_Data_Object *pObject)
+{
+	m_pObject		= pObject;
+	m_pClassify		= new CWKSP_Layer_Classify;
+	m_pLegend		= new CWKSP_Layer_Legend(this);
+	m_pHistogram	= NULL;
+}
+
+//---------------------------------------------------------
+CWKSP_Layer::~CWKSP_Layer(void)
+{
+	Histogram_Show(false);
+
+	if( g_pMaps )
+	{
+		g_pMaps->Del(this);
+	}
+
+	if( m_pClassify )
+	{
+		delete(m_pClassify);
+	}
+
+	if( m_pLegend )
+	{
+		delete(m_pLegend);
+	}
+
+	//-----------------------------------------------------
+	if( g_pData->Exists(m_pObject) )
+	{
+		if( m_pObject->is_Valid() == true )
+		{
+			MSG_General_Add(
+  				wxString::Format(wxT("%s %s: %s..."),
+					LNG("[MSG] Close"),
+					SG_Get_DataObject_Name(m_pObject->Get_ObjectType()),
+					m_pObject->Get_Name()
+     			),
+				true, true
+			);
+
+			delete(m_pObject);
+
+			MSG_General_Add(LNG("[MSG] okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
+		}
+		else
+		{
+			delete(m_pObject);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Layer::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command(Cmd_ID) );
+
+	case ID_CMD_SHAPES_SAVE:
+	case ID_CMD_GRIDS_SAVE:
+	case ID_CMD_TIN_SAVE:
+	case ID_CMD_POINTCLOUD_SAVE:
+		Save(m_pObject->Get_File_Name());
+		break;
+
+	case ID_CMD_SHAPES_SAVEAS:
+	case ID_CMD_GRIDS_SAVEAS:
+	case ID_CMD_TIN_SAVEAS:
+	case ID_CMD_POINTCLOUD_SAVEAS:
+		Save();
+		break;
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+	case ID_CMD_SHAPES_SHOW:
+	case ID_CMD_GRIDS_SHOW:
+	case ID_CMD_TIN_SHOW:
+	case ID_CMD_POINTCLOUD_SHOW:
+		g_pMaps->Add(this);
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command_UI(event) );
+
+	case ID_CMD_TIN_SAVE:
+	case ID_CMD_GRIDS_SAVE:
+	case ID_CMD_SHAPES_SAVE:
+	case ID_CMD_POINTCLOUD_SAVE:
+		event.Enable(m_pObject->is_Modified() && m_pObject->Get_File_Name() && *(m_pObject->Get_File_Name()));
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer::Create_Parameters(void)
+{
+	m_Parameters.Create(this, LNG(""), LNG(""));
+	m_Parameters.Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Node(
+		NULL							, "NODE_GENERAL"		, LNG("[CAP] General"),
+		LNG("")
+	);
+
+	m_Parameters.Add_String(
+		m_Parameters("NODE_GENERAL")	, "OBJECT_NAME"			, LNG("[CAP] Name"),
+		LNG(""),
+		m_pObject->Get_Name()
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_GENERAL")	, "SHOW_LEGEND"			, LNG("[CAP] Show Legend"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Node(
+		NULL							, "NODE_DISPLAY"		, LNG("[CAP] Display"),
+		LNG("")
+	);
+
+
+	//-----------------------------------------------------
+	// Visibility...
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_VISIBILITY"		, LNG("[CAP] Display: Visibility"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_VISIBILITY")	, "SHOW_ALWAYS"			, LNG("[CAP] Show Always"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Range(
+		m_Parameters("NODE_VISIBILITY")	, "SHOW_RANGE"			, LNG("[CAP] Scale Dependent"),
+		LNG(""),
+		0.0, 1000.0, 0.0, true
+	);
+
+
+	//-----------------------------------------------------
+	// Classification...
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_COLORS"			, LNG("[CAP] Display: Color Classification"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_COLORS")		, "COLORS_TYPE"			, LNG("[CAP] Type"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("[VAL] Unique Symbol"),
+			LNG("[VAL] Lookup Table"),
+			LNG("[VAL] Graduated Color")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	// Classification: Unique Value...
+
+	m_Parameters.Add_Node(
+		m_Parameters("NODE_COLORS")		, "NODE_UNISYMBOL"		, LNG("[CAP] Unique Symbol"),
+		LNG("")
+	);
+
+	static	BYTE	s_Def_Layer_Colour	= 0;
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_UNISYMBOL")	, "UNISYMBOL_COLOR"		, LNG("[CAP] Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, s_Def_Layer_Colours[s_Def_Layer_Colour++ % DEF_LAYER_COLOUR_COUNT]
+	//	PARAMETER_TYPE_Color, SG_GET_RGB(Get_Random(128, 250), Get_Random(128, 200), Get_Random(128, 200))
+	);
+
+
+	//-----------------------------------------------------
+	// Classification: Lookup Table...
+
+	m_Parameters.Add_Node(
+		m_Parameters("NODE_COLORS")		, "NODE_LUT"			, LNG("[CAP] Lookup Table"),
+		LNG("")
+	);
+
+	CSG_Table	LUT;
+	LUT.Add_Field(LNG("COLOR")		, SG_DATATYPE_Color);
+	LUT.Add_Field(LNG("NAME")			, SG_DATATYPE_String);
+	LUT.Add_Field(LNG("DESCRIPTION")	, SG_DATATYPE_String);
+	LUT.Add_Field(LNG("MINIMUM")		, SG_DATATYPE_Double);
+	LUT.Add_Field(LNG("MAXIMUM")		, SG_DATATYPE_Double);
+
+	m_Parameters.Add_FixedTable(
+		m_Parameters("NODE_LUT")		, "LUT"					, LNG("[CAP] Table"),
+		LNG(""),
+		&LUT
+	);
+
+
+	//-----------------------------------------------------
+	// Classification: Metric...
+
+	m_Parameters.Add_Node(
+		m_Parameters("NODE_COLORS")		, "NODE_METRIC"			, LNG("[CAP] Graduated Color"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Colors(
+		m_Parameters("NODE_METRIC")		, "METRIC_COLORS"		, LNG("[CAP] Colors"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Range(
+		m_Parameters("NODE_METRIC")		, "METRIC_ZRANGE"		, LNG("[CAP] Value Range"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_METRIC")		, "METRIC_SCALE_MODE"	, LNG("[CAP] Mode"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("[VAL] Linear"),
+			LNG("[VAL] Logarithmic (up)"),
+			LNG("[VAL] Logarithmic (down)")
+		), 0
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_METRIC")		, "METRIC_SCALE_LOG"	, LNG("[CAP] Logarithmic Stretch Factor"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 1.0
+	);
+
+
+	//-----------------------------------------------------
+	m_pClassify->Initialise(this, m_Parameters("LUT")->asTable(), m_Parameters("METRIC_COLORS")->asColors());
+
+	On_Create_Parameters();
+
+	DataObject_Changed();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Save(void)
+{
+	bool		bResult;
+	wxString	File_Path;
+
+	switch( Get_Type() )
+	{
+	default:
+		bResult	= false;
+		break;
+
+	case WKSP_ITEM_TIN:
+	case WKSP_ITEM_Shapes:
+		bResult	= DLG_Save(File_Path, ID_DLG_SHAPES_SAVE);
+		break;
+
+	case WKSP_ITEM_PointCloud:
+		bResult	= DLG_Save(File_Path, ID_DLG_POINTCLOUD_SAVE);
+		break;
+
+	case WKSP_ITEM_Grid:
+		bResult	= DLG_Save(File_Path, ID_DLG_GRIDS_SAVE);
+		break;
+	}
+
+	if( bResult )
+	{
+		bResult	= m_pObject->Save(File_Path.c_str());
+
+		PROCESS_Set_Okay();
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Save(const wxChar *File_Path)
+{
+	if( File_Path && *File_Path )
+	{
+		bool	bResult	= m_pObject->Save(File_Path);
+
+		if( bResult )
+		{
+			g_pData->Get_FileMenus()->Recent_Add(m_pObject->Get_ObjectType(), m_pObject->Get_File_Name());
+		}
+
+		PROCESS_Set_Okay();
+
+		return( bResult );
+	}
+
+	return( Save() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer::DataObject_Changed(CSG_Parameters *pParameters)
+{
+	if( pParameters )
+	{
+		m_Parameters.Assign_Values(pParameters);
+	}
+	else
+	{
+		double	m, s, min, max;
+
+		if( m_pObject->Get_ObjectType() == DATAOBJECT_TYPE_Grid )
+		{
+			CSG_Grid	*pGrid	= (CSG_Grid *)m_pObject;
+
+			m	= pGrid->Get_ArithMean(true);
+			s	= pGrid->Get_StdDev   (true) * 2.0;
+			min	= m - s;	if( min < pGrid->Get_ZMin(true) )	min	= pGrid->Get_ZMin(true);
+			max	= m + s;	if( max > pGrid->Get_ZMax(true) )	max	= pGrid->Get_ZMax(true);
+
+			m_Parameters("METRIC_ZRANGE")->asRange()->Set_Range(min, max);
+		}
+	}
+
+	DataObject_Changed();
+}
+
+void CWKSP_Layer::DataObject_Changed(CSG_Colors *pColors)
+{
+	if( m_pClassify->Get_Metric_Colors() && pColors )
+	{
+		m_pClassify->Get_Metric_Colors()->Assign(pColors);
+	}
+
+	DataObject_Changed();
+}
+
+void CWKSP_Layer::DataObject_Changed(void)
+{
+	//-----------------------------------------------------
+	m_Parameters.Set_Name(wxString::Format(wxT("%02d. %s"), 1 + Get_ID(), m_pObject->Get_Name()));
+
+	m_Parameters("OBJECT_NAME")->Set_Value(m_pObject->Get_Name());
+
+	//-----------------------------------------------------
+	On_DataObject_Changed();
+
+	g_pACTIVE->Update(this, false);
+
+	Parameters_Changed();
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer::Parameters_Changed(void)
+{
+	static bool	bUpdates	= false;
+
+	//-----------------------------------------------------
+	if( !bUpdates )
+	{
+		bUpdates	= true;
+
+		m_pObject->Set_Name(m_Parameters("OBJECT_NAME")->asString());
+
+		//-----------------------------------------------------
+		m_pClassify->Set_Mode(m_Parameters("COLORS_TYPE")->asInt());
+
+		m_pClassify->Set_Unique_Color(m_Parameters("UNISYMBOL_COLOR")->asInt());
+
+		m_pClassify->Set_Metric(
+			m_Parameters("METRIC_SCALE_MODE")	->asInt(),
+			m_Parameters("METRIC_SCALE_LOG")	->asDouble(),
+			m_Parameters("METRIC_ZRANGE")->asRange()->Get_LoVal() / (Get_Type() == WKSP_ITEM_Grid ? ((CSG_Grid *)m_pObject)->Get_ZFactor() : 1.0),
+			m_Parameters("METRIC_ZRANGE")->asRange()->Get_HiVal() / (Get_Type() == WKSP_ITEM_Grid ? ((CSG_Grid *)m_pObject)->Get_ZFactor() : 1.0)
+		);
+
+		//-----------------------------------------------------
+		On_Parameters_Changed();
+
+		Update_Views(false);
+
+		_Set_Thumbnail();
+
+		g_pData_Buttons->Refresh(false);
+
+		//-----------------------------------------------------
+		CWKSP_Base_Item::Parameters_Changed();
+
+		bUpdates	= false;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Layer::_On_Parameter_Changed(CSG_Parameter *pParameter)
+{
+	if( pParameter && pParameter->Get_Owner() && pParameter->Get_Owner()->Get_Owner() )
+	{
+	//	return( ((CWKSP_Layer *)pParameter->Get_Owner()->Get_Owner())->
+	//		On_Parameter_Changed(pParameter->Get_Owner(), pParameter)
+	//	);
+
+		((CWKSP_Layer *)pParameter->Get_Owner()->Get_Owner())->
+			On_Parameter_Changed(pParameter->Get_Owner(), pParameter);
+
+		g_pACTIVE->Get_Parameters()->Update_Parameters(pParameter->Get_Owner(), false);
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CWKSP_Layer::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxBitmap & CWKSP_Layer::Get_Thumbnail(int dx, int dy)
+{
+	if( dx > 0 && m_Thumbnail.GetWidth()  != dx
+	&&	dy > 0 && m_Thumbnail.GetHeight() != dy )
+	{
+		m_Thumbnail.Create(dx, dy);
+
+		_Set_Thumbnail();
+	}
+
+	return( m_Thumbnail );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::_Set_Thumbnail(void)
+{
+	if( m_pObject && m_Thumbnail.GetWidth() > 0 && m_Thumbnail.GetHeight() > 0 )
+	{
+		wxMemoryDC		dc;
+		wxRect			r(0, 0, m_Thumbnail.GetWidth(), m_Thumbnail.GetHeight());
+		CWKSP_Map_DC	dc_Map(Get_Extent(), r, 1.0, SG_GET_RGB(255, 255, 255));
+
+		Draw(dc_Map, false);
+
+		dc.SelectObject(m_Thumbnail);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		dc_Map.Draw(dc);
+
+		dc.SelectObject(wxNullBitmap);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Rect CWKSP_Layer::Get_Extent(void)
+{
+	if( m_pObject )
+	{
+		switch( m_pObject->Get_ObjectType() )
+		{
+		case DATAOBJECT_TYPE_Grid:
+			return( ((CSG_Grid       *)m_pObject)->Get_System().Get_Extent_Cells() );
+
+		case DATAOBJECT_TYPE_Shapes:
+			return( ((CSG_Shapes     *)m_pObject)->Get_Extent() );
+
+		case DATAOBJECT_TYPE_TIN:
+			return( ((CSG_TIN        *)m_pObject)->Get_Extent() );
+
+		case DATAOBJECT_TYPE_PointCloud:
+			return( ((CSG_PointCloud *)m_pObject)->Get_Extent() );
+
+		default:
+			break;
+		}
+	}
+
+	return( CSG_Rect(0.0, 0.0, 0.0, 0.0) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Colors * CWKSP_Layer::Get_Colors(void)
+{
+	return( m_pClassify->Get_Metric_Colors() );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Get_Colors(CSG_Colors *pColors)
+{
+	if( m_pClassify->Get_Metric_Colors() && pColors )
+	{
+		return( pColors->Assign(m_pClassify->Get_Metric_Colors()) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Set_Color_Range(double zMin, double zMax)
+{
+	CSG_Parameters	Parameters;
+
+	Parameters.Add_Range(NULL, "METRIC_ZRANGE"	, LNG(""), LNG(""), zMin, zMax);
+	DataObject_Changed(&Parameters);
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Layer::do_Legend(void)
+{
+	return( m_Parameters("SHOW_LEGEND")->asBool() );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::do_Show(CSG_Rect const &rMap)
+{
+	double				d;
+	CSG_Parameter_Range	*pRange;
+
+	if( !m_Parameters("SHOW_ALWAYS")->asBool() )
+	{
+		pRange	= m_Parameters("SHOW_RANGE")->asRange();
+		d		= rMap.Get_XRange() > rMap.Get_YRange() ? rMap.Get_XRange() : rMap.Get_YRange();
+
+		return( pRange->Get_LoVal() <= d && d <= pRange->Get_HiVal() );
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Show(CWKSP_Map *pMap)
+{
+	if( pMap != NULL )
+	{
+		if( g_pMaps->Add(this, pMap) )
+		{
+			pMap->View_Show(true);
+
+			return( true );
+		}
+	}
+	else
+	{
+		for(int i=0; i<g_pMaps->Get_Count(); i++)
+		{
+			if( g_pMaps->Get_Map(i)->Find_Layer(this) != NULL )
+			{
+				pMap	= g_pMaps->Get_Map(i);
+
+				pMap->View_Show(true);
+
+				return( true );
+			}
+		}
+
+		if( g_pMaps->Add(this, NULL) )
+		{
+			return( Show(NULL) );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer::Draw(CWKSP_Map_DC &dc_Map, bool bEdit)
+{
+	On_Draw(dc_Map, bEdit);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer::Update_Views(bool bMapsOnly)
+{
+	g_pMaps->Update(this, bMapsOnly);
+
+	if( !bMapsOnly )
+	{
+		if( Histogram_Get() )
+		{
+			Histogram_Get()->Update_Histogram();
+		}
+
+		On_Update_Views();
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer::View_Closes(wxMDIChildFrame *pView)
+{
+	if( wxDynamicCast(pView, CVIEW_Histogram) != NULL )
+	{
+		m_pHistogram	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer::Histogram_Show(bool bShow)
+{
+	if( bShow && !m_pHistogram )
+	{
+		m_pHistogram	= new CVIEW_Histogram(this);
+	}
+	else if( !bShow && m_pHistogram )
+	{
+		m_pHistogram->Destroy();
+		delete(m_pHistogram);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer::Histogram_Toggle(void)
+{
+	Histogram_Show( m_pHistogram == NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Layer::Edit_Get_Menu(void)
+{
+	return( On_Edit_Get_Menu() );
+}
+
+//---------------------------------------------------------
+TSG_Rect CWKSP_Layer::Edit_Get_Extent(void)
+{
+	return( On_Edit_Get_Extent() );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Edit_Set_Attributes(void)
+{
+	return( On_Edit_Set_Attributes() );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Edit_On_Key_Down(int KeyCode)
+{
+	return( On_Edit_On_Key_Down(KeyCode) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Edit_On_Mouse_Down(CSG_Point Point, double ClientToWorld, int Key)
+{
+	m_Edit_Mouse_Down	= Point;
+
+	return( On_Edit_On_Mouse_Down(Point, ClientToWorld, Key) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Edit_On_Mouse_Up(CSG_Point Point, double ClientToWorld, int Key)
+{
+	return( On_Edit_On_Mouse_Up(Point, ClientToWorld, Key) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer::Edit_On_Mouse_Move(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key)
+{
+	return( On_Edit_On_Mouse_Move(pMap, rWorld, pt, ptLast, Key) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,211 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WKSP_Layer.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_item.h"
+
+#include "wksp_map_dc.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Layer : public CWKSP_Base_Item
+{
+public:
+	CWKSP_Layer(CSG_Data_Object *pObject);
+	virtual ~CWKSP_Layer(void);
+
+	virtual bool					On_Command				(int Cmd_ID);
+	virtual bool					On_Command_UI			(wxUpdateUIEvent &event);
+
+	virtual CSG_Parameters *		Get_Parameters			(void)	{	return( &m_Parameters );	}
+
+	virtual void					Parameters_Changed		(void);
+
+	void							DataObject_Changed		(void);
+	void							DataObject_Changed		(CSG_Parameters *pParameters);
+	void							DataObject_Changed		(CSG_Colors *pColors);
+
+	CSG_Data_Object *				Get_Object				(void)	{	return( m_pObject );	}
+	CSG_Rect						Get_Extent				(void);
+
+	CSG_Colors *					Get_Colors				(void);
+	bool							Get_Colors				(CSG_Colors *pColors);
+	bool							Set_Color_Range			(double zMin, double zMax);
+
+	bool							Save					(void);
+	bool							Save					(const wxChar *File_Path);
+
+	virtual bool					Show					(class CWKSP_Map *pMap = NULL);
+
+	virtual wxString				Get_Value				(CSG_Point ptWorld, double Epsilon)	= 0;
+	virtual double					Get_Value_Range			(void)								= 0;
+
+	void							Draw					(CWKSP_Map_DC &dc_Map, bool bEdit);
+
+	class CWKSP_Layer_Classify *	Get_Classifier			(void)	{	return( m_pClassify );	}
+
+	class CWKSP_Layer_Legend *		Get_Legend				(void)	{	return( m_pLegend );	}
+	bool							do_Legend				(void);
+	bool							do_Show					(CSG_Rect const &rMap);
+
+	void							Update_Views			(bool bMapsOnly);
+	void							View_Closes				(class wxMDIChildFrame *pView);
+
+	const wxBitmap &				Get_Thumbnail			(int dx, int dy);
+
+	class CVIEW_Histogram *			Histogram_Get			(void)	{	return( m_pHistogram );	}
+	void							Histogram_Show			(bool bShow);
+	void							Histogram_Toggle		(void);
+
+	wxMenu *						Edit_Get_Menu			(void);
+	TSG_Rect						Edit_Get_Extent			(void);
+	CSG_Table *						Edit_Get_Attributes		(void)	{	return( &m_Edit_Attributes );	}
+	bool							Edit_Set_Attributes		(void);
+	bool							Edit_On_Key_Down		(int KeyCode);
+	bool							Edit_On_Mouse_Down		(CSG_Point Point, double WorldToClient, int Key);
+	bool							Edit_On_Mouse_Up		(CSG_Point Point, double WorldToClient, int Key);
+	bool							Edit_On_Mouse_Move		(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key);
+
+
+protected:
+
+	CSG_Data_Object					*m_pObject;
+
+	CSG_Parameter_Range				*m_pZRange;
+
+	CSG_Parameters					m_Parameters;
+
+	CSG_Point						m_Edit_Mouse_Down;
+
+	CSG_Table						m_Edit_Attributes;
+
+	class CWKSP_Layer_Classify		*m_pClassify;
+
+	class CWKSP_Layer_Legend		*m_pLegend;
+
+	class CVIEW_Histogram			*m_pHistogram;
+
+	wxBitmap						m_Thumbnail;
+
+
+	void							Create_Parameters		(void);
+
+	virtual void					On_Create_Parameters	(void)	= 0;
+	virtual void					On_DataObject_Changed	(void)	= 0;
+	virtual void					On_Parameters_Changed	(void)	= 0;
+
+	virtual int						On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual void					On_Update_Views			(void)			{}
+
+	virtual void					On_Draw					(CWKSP_Map_DC &dc_Map, bool bEdit)	= 0;
+
+	virtual wxMenu *				On_Edit_Get_Menu		(void)			{	return( NULL );	}
+	virtual TSG_Rect				On_Edit_Get_Extent		(void)	= 0;
+	virtual bool					On_Edit_Set_Attributes	(void)	= 0;
+	virtual bool					On_Edit_On_Key_Down		(int KeyCode)	{	return( false );	}
+	virtual bool					On_Edit_On_Mouse_Down	(CSG_Point Point, double ClientToWorld, int Key)	{	return( false );	}
+	virtual bool					On_Edit_On_Mouse_Up		(CSG_Point Point, double ClientToWorld, int Key)	{	return( false );	}
+	virtual bool					On_Edit_On_Mouse_Move	(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key)	{	return( false );	}
+
+
+private:
+
+	static int						_On_Parameter_Changed	(CSG_Parameter *pParameter);
+
+	bool							_Set_Thumbnail			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Layer *						Get_Active_Layer		(void);
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,490 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Layer_Classify.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "helper.h"
+
+#include "wksp_layer.h"
+#include "wksp_layer_classify.h"
+#include "wksp_grid.h"
+#include "wksp_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Layer_Classify::CWKSP_Layer_Classify(void)
+{
+	m_Mode		= CLASSIFY_UNIQUE;
+
+	m_pLayer	= NULL;
+	m_pColors	= NULL;
+	m_pLUT		= NULL;
+
+	m_HST_Count	= NULL;
+}
+
+//---------------------------------------------------------
+CWKSP_Layer_Classify::~CWKSP_Layer_Classify(void)
+{
+	if( m_HST_Count )
+	{
+		SG_Free(m_HST_Count);
+		m_HST_Count	= NULL;
+
+		SG_Free(m_HST_Cumul);
+		m_HST_Cumul	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Layer_Classify::Initialise(CWKSP_Layer *pLayer, CSG_Table *pLUT, CSG_Colors *pColors)
+{
+	m_pLayer	= pLayer;
+	m_pLUT		= pLUT;
+	m_pColors	= pColors;
+
+	//-----------------------------------------------------
+	switch( m_pLayer->Get_Type() )
+	{
+	default:
+		m_pColors->Set_Count(10);
+		break;
+
+	case WKSP_ITEM_TIN:
+	case WKSP_ITEM_PointCloud:
+	case WKSP_ITEM_Grid:
+		m_pColors->Set_Count(100);
+		break;
+	}
+
+	//-----------------------------------------------------
+	if( m_pLUT && m_pLUT->Get_Record_Count() == 0 )
+	{
+		CSG_Table_Record	*pRecord;
+
+		pRecord	= m_pLUT->Add_Record();
+		pRecord->Set_Value(LUT_COLOR		, SG_GET_RGB(1, 1, 1));
+		pRecord->Set_Value(LUT_TITLE		, LNG("Class 1"));
+		pRecord->Set_Value(LUT_DESCRIPTION	, LNG("First Class"));
+		pRecord->Set_Value(LUT_MIN			, 0.0);
+		pRecord->Set_Value(LUT_MAX			, 1.0);
+
+		pRecord	= m_pLUT->Add_Record();
+		pRecord->Set_Value(LUT_COLOR		, SG_GET_RGB(255, 0, 0));
+		pRecord->Set_Value(LUT_TITLE		, LNG("Class 2"));
+		pRecord->Set_Value(LUT_DESCRIPTION	, LNG("Second Class"));
+		pRecord->Set_Value(LUT_MIN			, 1.0);
+		pRecord->Set_Value(LUT_MAX			, 2.0);
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Classify::Set_Mode(int Mode)
+{
+	m_Mode		= Mode;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Layer_Classify::Get_Class_Name(int iClass)
+{
+	wxString	s;
+
+	switch( m_Mode )
+	{
+	case CLASSIFY_UNIQUE:	default:
+		break;
+
+	case CLASSIFY_LUT:
+		if( iClass >= 0 && iClass < m_pLUT->Get_Record_Count() )
+		{
+			s.Printf(wxT("%s"), m_pLUT->Get_Record(iClass)->asString(LUT_TITLE));
+		}
+		break;
+
+	case CLASSIFY_METRIC:
+	case CLASSIFY_SHADE:
+		if( m_zRange > 0.0 )
+		{
+			if( iClass == 0 )
+			{
+				s.Printf(wxT("%f < %f"), Get_RelativeToMetric(1.0 * iClass / Get_Class_Count()), Get_RelativeToMetric(1.0 * (1.0 + iClass) / Get_Class_Count()));
+			}
+			else if( iClass < Get_Class_Count() )
+			{
+				s.Printf(wxT("< %f"), Get_RelativeToMetric(1.0 * (1.0 + iClass) / Get_Class_Count()));
+			}
+		}
+		else
+		{
+			if( iClass == 0 )
+			{
+				s.Printf(wxT("<= %f"), m_zMin);
+			}
+			else
+			{
+				s.Printf(wxT("> %f"), m_zMin);
+			}
+		}
+		break;
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Layer_Classify::Get_Class_Name_byValue(double Value)
+{
+	return( Get_Class_Name(Get_Class(Value)) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Unique							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Classify::Set_Unique_Color(int Color)
+{
+	m_UNI_Color	= Color;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Metric							 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Classify::Set_Metric(int Mode, double LogFactor, double zMin, double zMax)
+{
+	m_zMode		= Mode;
+	m_zMin		= zMin;
+	m_zRange	= zMax - zMin;
+	m_zLogRange	= LogFactor;
+	m_zLogMax	= log(1.0 + m_zLogRange);
+
+	if( m_zRange <= 0.0 || (m_zMode != 0 && m_zLogRange <= 0.0) )
+	{
+		m_zRange	= 0.0;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Lookup Table					 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline int CWKSP_Layer_Classify::_LUT_Cmp_Class(double Value, int iClass)
+{
+	double				d;
+	CSG_Table_Record	*pClass	= m_pLUT->Get_Record_byIndex(iClass);
+
+	if( (d = pClass->asDouble(LUT_MIN)) <= Value && Value <= pClass->asDouble(LUT_MAX) )
+	{
+		return( 0 );
+	}
+
+	return( d < Value ? -1 : 1 );
+}
+
+//---------------------------------------------------------
+int CWKSP_Layer_Classify::_LUT_Get_Class(double Value)
+{
+	int		a, b, i, c;
+
+	if( m_pLUT->Get_Record_Count() > 0 )
+	{
+		if( m_pLUT->Get_Index_Field(0) != LUT_MIN || m_pLUT->Get_Index_Order(0) != TABLE_INDEX_Ascending )
+		{
+			m_pLUT->Set_Index(LUT_MIN, TABLE_INDEX_Ascending);
+		}
+
+		for(a=0, b=m_pLUT->Get_Record_Count()-1; a < b; )
+		{
+			i	= a + (b - a) / 2;
+			c	= _LUT_Cmp_Class(Value, i);
+
+			if( c > 0 )
+			{
+				b	= b > i ? i : b - 1;
+			}
+			else if( c < 0 )
+			{
+				a	= a < i ? i : a + 1;
+			}
+			else
+			{
+				return( m_pLUT->Get_Record_byIndex(i)->Get_Index() );
+			}
+		}
+
+		if( _LUT_Cmp_Class(Value, a) == 0 )
+		{
+			return( m_pLUT->Get_Record_byIndex(a)->Get_Index() );
+		}
+
+		if( a != b && _LUT_Cmp_Class(Value, b) == 0 )
+		{
+			return( m_pLUT->Get_Record_byIndex(b)->Get_Index() );
+		}
+	}
+
+	return( -1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Classify::Metric2EqualElements(void)
+{
+	int				x, y, iClass, nClasses;
+	double			dClass, zA, zB;
+	CSG_Table_Record	*pRecord;
+	CSG_Grid			*pGrid;
+
+	if( m_pLayer->Get_Type() == WKSP_ITEM_Grid && (nClasses = m_pColors->Get_Count()) > 1 )
+	{
+		m_pLUT->Del_Records();
+
+		pGrid	= ((CWKSP_Grid *)m_pLayer)->Get_Grid();
+		dClass	= (double)pGrid->Get_NCells() / (double)(nClasses);
+
+		pGrid->Get_Sorted(0, x, y, false, false);
+		zA		= pGrid->asDouble(x, y);
+
+		for(iClass=0; iClass<nClasses-1; iClass++)
+		{
+			pGrid->Get_Sorted((int)(dClass * (iClass + 1.0)), x, y, false, false);
+			zB		= zA;
+			zA		= pGrid->asDouble(x, y);
+
+			pRecord	= m_pLUT->Add_Record();
+			pRecord->Set_Value(LUT_COLOR		, m_pColors->Get_Color(iClass));
+			pRecord->Set_Value(LUT_TITLE		, wxString::Format(wxT(">=%f"), zB));
+			pRecord->Set_Value(LUT_DESCRIPTION	, wxString::Format(wxT("%f <-> %f"), zB, zA));
+			pRecord->Set_Value(LUT_MIN			, zB);
+			pRecord->Set_Value(LUT_MAX			, zA);
+		}
+
+		pGrid->Get_Sorted(pGrid->Get_NCells() - 1, x, y, false, false);
+		zB		= zA;
+		zA		= pGrid->asDouble(x, y);
+		pRecord	= m_pLUT->Add_Record();
+		pRecord->Set_Value(LUT_COLOR		, m_pColors->Get_Color(iClass));
+		pRecord->Set_Value(LUT_TITLE		, wxString::Format(wxT(">=%f"), zB));
+		pRecord->Set_Value(LUT_DESCRIPTION	, wxString::Format(wxT("%f <-> %f"), zB, zA));
+		pRecord->Set_Value(LUT_MIN			, zB);
+		pRecord->Set_Value(LUT_MAX			, zA);
+
+		Set_Mode(CLASSIFY_LUT);
+		m_pLayer->Update_Views(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//						Histogram						 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Layer_Classify::Histogram_Update(void)
+{
+	int		i;
+
+	//-----------------------------------------------------
+	if( m_HST_Count )
+	{
+		SG_Free(m_HST_Count);
+		SG_Free(m_HST_Cumul);
+		m_HST_Count	= NULL;
+		m_HST_Cumul	= NULL;
+	}
+
+	//-----------------------------------------------------
+	if( Get_Class_Count() > 0 )
+	{
+		STATUSBAR_Set_Text(LNG("[MSG] Build Histogram..."));
+
+		m_HST_Count	= (int *)SG_Calloc(Get_Class_Count(), sizeof(int));
+		m_HST_Cumul	= (int *)SG_Calloc(Get_Class_Count(), sizeof(int));
+
+		switch( m_pLayer->Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Grid:
+			_Histogram_Update(((CWKSP_Grid   *)m_pLayer)->Get_Grid());
+			break;
+
+		case WKSP_ITEM_Shapes:
+			_Histogram_Update(((CWKSP_Shapes *)m_pLayer)->Get_Shapes(), m_pLayer->Get_Parameters()->Get_Parameter("COLORS_ATTRIB")->asInt());
+			break;
+		}
+
+		PROCESS_Set_Okay();
+
+		//-------------------------------------------------
+		for(i=0, m_HST_Maximum=0, m_HST_Total=0; i<Get_Class_Count(); i++)
+		{
+			m_HST_Cumul[i]	= (m_HST_Total += m_HST_Count[i]);
+
+			if( m_HST_Count[i] > m_HST_Maximum )
+			{
+				m_HST_Maximum	= m_HST_Count[i];
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer_Classify::_Histogram_Update(CSG_Grid *pGrid)
+{
+	for(int y=0; y<pGrid->Get_NY() && PROGRESSBAR_Set_Position(y, pGrid->Get_NY()); y++)
+	{
+		for(int x=0; x<pGrid->Get_NX(); x++)
+		{
+			if( !pGrid->is_NoData(x, y) )
+			{
+				int		Class	= Get_Class(pGrid->asDouble(x, y));
+				
+				if( Class >= 0 && Class < Get_Class_Count() )
+				{
+					m_HST_Count[Class]++;
+				}
+			}
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Layer_Classify::_Histogram_Update(CSG_Shapes *pShapes, int Attribute)
+{
+	if( Attribute >= 0 && Attribute < pShapes->Get_Field_Count() )
+	{
+		for(int i=0; i<pShapes->Get_Count() && PROGRESSBAR_Set_Position(i, pShapes->Get_Count()); i++)
+		{
+			int		Class	= Get_Class(pShapes->Get_Record(i)->asDouble(Attribute));
+			
+			if( Class >= 0 && Class < Get_Class_Count() )
+			{
+				m_HST_Count[Class]++;
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_classify.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,401 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Layer_Classify.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_Classify_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_Classify_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/string.h>
+
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	CLASSIFY_UNIQUE	= 0,
+	CLASSIFY_LUT,
+	CLASSIFY_METRIC,
+	CLASSIFY_RGB,
+	CLASSIFY_SHADE
+};
+
+//---------------------------------------------------------
+enum
+{
+	LUT_COLOR		= 0,
+	LUT_TITLE,
+	LUT_DESCRIPTION,
+	LUT_MIN,
+	LUT_MAX
+};
+
+//---------------------------------------------------------
+enum
+{
+	METRIC_MODE_NORMAL	= 0,
+	METRIC_MODE_LOGUP,
+	METRIC_MODE_LOGDOWN
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Layer_Classify
+{
+public: ///////////////////////////////////////////////////
+	CWKSP_Layer_Classify(void);
+	virtual ~CWKSP_Layer_Classify(void);
+
+	bool						Initialise				(class CWKSP_Layer *pLayer, CSG_Table *pLUT, CSG_Colors *pColors);
+
+	void						Set_Mode				(int Mode);
+	int							Get_Mode				(void)		{	return( m_Mode );		}
+
+	void						Set_Unique_Color		(int Color);
+	int							Get_Unique_Color		(void)		{	return( m_UNI_Color );	}
+
+	void						Set_Metric				(int Mode, double LogFactor, double zMin, double zMax);
+	int							Get_Metric_Mode			(void)		{	return( m_zMode );		}
+	CSG_Colors *				Get_Metric_Colors		(void)		{	return( m_pColors );	}
+
+	void						Metric2EqualElements	(void);
+
+
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	int							Get_Class_Count			(void)
+	{
+		switch( m_Mode )
+		{
+		case CLASSIFY_UNIQUE:	default:
+			return( 1 );
+
+		case CLASSIFY_LUT:
+			return( m_pLUT->Get_Record_Count() );
+
+		case CLASSIFY_METRIC:
+		case CLASSIFY_SHADE:
+			return( m_pColors->Get_Count() );
+		}
+	}
+
+	//-----------------------------------------------------
+	int							Get_Class				(double Value)
+	{
+		switch( m_Mode )
+		{
+		case CLASSIFY_UNIQUE:	default:
+			return( 0 );
+
+		case CLASSIFY_LUT:
+			return( _LUT_Get_Class(Value) );
+
+		case CLASSIFY_METRIC:
+		case CLASSIFY_SHADE:
+			return( _METRIC_Get_Class(Value) );
+		}
+	}
+
+	//-----------------------------------------------------
+	wxString					Get_Class_Name			(int iClass);
+	wxString					Get_Class_Name_byValue	(double Value);
+
+
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	bool						Get_Class_Color			(int iClass, int &Color)
+	{
+		switch( m_Mode )
+		{
+		case CLASSIFY_UNIQUE:	default:
+			Color	= m_UNI_Color;
+
+			return( true );
+
+		case CLASSIFY_LUT:
+			if( iClass >= 0 && iClass < m_pLUT->Get_Record_Count() )
+			{
+				Color	= m_pLUT->Get_Record(iClass)->asInt(LUT_COLOR);
+
+				return( true );
+			}
+
+			return( false );
+
+		case CLASSIFY_METRIC:
+			if( iClass < 0 )
+			{
+				iClass	= 0;
+			}
+			else if( iClass >= m_pColors->Get_Count() )
+			{
+				iClass	= m_pColors->Get_Count() - 1;
+			}
+
+			Color	= m_pColors->Get_Color(iClass);
+
+			return( true );
+
+		case CLASSIFY_SHADE:
+			if( iClass < 0 )
+			{
+				iClass	= 0;
+			}
+			else if( iClass >= m_pColors->Get_Count() )
+			{
+				iClass	= m_pColors->Get_Count() - 1;
+			}
+
+			Color	= m_pColors->Get_Brightness(iClass);
+			Color	= SG_GET_RGB(Color, Color, Color);
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	int							Get_Class_Color			(int iClass)
+	{
+		int		Color;
+
+		return( Get_Class_Color(iClass, Color) ? Color : 0 );
+	}
+
+	//-----------------------------------------------------
+	bool						Get_Class_Color_byValue	(double Value, int &Color)
+	{
+		int		iClass;
+
+		switch( m_Mode )
+		{
+		case CLASSIFY_UNIQUE:	default:
+			iClass	= 0;
+			break;
+
+		case CLASSIFY_LUT:
+			iClass	= _LUT_Get_Class(Value);
+			break;
+
+		case CLASSIFY_METRIC:
+		case CLASSIFY_SHADE:
+			iClass	= _METRIC_Get_Class(Value);
+			break;
+
+		case CLASSIFY_RGB:
+			Color	= (int)Value;
+			return( true );
+		}
+
+		return( Get_Class_Color(iClass, Color) );
+	}
+
+	//-----------------------------------------------------
+	int							Get_Class_Color_byValue	(double Value)
+	{
+		int		Color;
+
+		return( Get_Class_Color_byValue(Value, Color) ? Color : 0 );
+	}
+
+
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	double						Get_MetricToRelative	(double Value)
+	{
+		if( m_zRange >= 0.0 )
+		{
+			Value	= (Value - m_zMin) / m_zRange;
+
+			switch( m_zMode )
+			{
+			case METRIC_MODE_LOGUP:
+				Value	= log(1.0 + m_zLogRange * Value) / m_zLogMax;
+				break;
+
+			case METRIC_MODE_LOGDOWN:
+				Value	= 1.0 - Value;
+				Value	= log(1.0 + m_zLogRange * Value) / m_zLogMax;
+				Value	= 1.0 - Value;
+				break;
+			}
+
+			return( Value );
+		}
+
+		return( 0.0 );
+	}
+
+	//-----------------------------------------------------
+	double						Get_RelativeToMetric	(double Value)
+	{
+		switch( m_zMode )
+		{
+		case METRIC_MODE_LOGUP:
+			Value	= (exp(m_zLogMax * Value) - 1.0) / m_zLogRange;
+			break;
+
+		case METRIC_MODE_LOGDOWN:
+			Value	= 1.0 - Value;
+			Value	= (exp(m_zLogMax * Value) - 1.0) / m_zLogRange;
+			Value	= 1.0 - Value;
+			break;
+		}
+
+		return( m_zMin + (m_zRange * Value) );
+	}
+
+
+	///////////////////////////////////////////////////////
+
+	//-----------------------------------------------------
+	bool						Histogram_Update		(void);
+
+	int							Histogram_Get_Maximum	(void)	{	return( m_HST_Maximum );	}
+	int							Histogram_Get_Total		(void)	{	return( m_HST_Total );		}
+
+	double						Histogram_Get_Count		(int iClass, bool bRelative = true)
+	{
+		return( bRelative && m_HST_Maximum > 0
+			? (double)m_HST_Count[iClass] / m_HST_Maximum
+			: m_HST_Count[iClass]
+		);
+	}
+
+	double						Histogram_Get_Cumulative(int iClass, bool bRelative = true)
+	{
+		return( bRelative && m_HST_Total   > 0
+			? (double)m_HST_Cumul[iClass] / m_HST_Total
+			: m_HST_Cumul[iClass]
+		);
+	}
+
+
+protected: ////////////////////////////////////////////////
+
+	int							m_Mode, m_zMode,
+								m_UNI_Color,
+								*m_HST_Count, *m_HST_Cumul, m_HST_Maximum, m_HST_Total;
+
+	double						m_zMin, m_zRange, m_zLogRange, m_zLogMax;
+
+	CSG_Colors					*m_pColors;
+
+	CSG_Table					*m_pLUT;
+
+	class CWKSP_Layer			*m_pLayer;
+
+
+	//-----------------------------------------------------
+	int							_LUT_Cmp_Class			(double Value, int iClass);
+	int							_LUT_Get_Class			(double Value);
+
+	int							_METRIC_Get_Class		(double Value)
+	{
+		if( Value < m_zMin )
+		{
+			return( -1 );
+		}
+
+		if( Value > m_zMin + m_zRange )
+		{
+			return( m_pColors->Get_Count() );
+		}
+
+		return( (int)(Get_MetricToRelative(Value) * m_pColors->Get_Count()) );
+	}
+
+
+	//-----------------------------------------------------
+	bool						_Histogram_Update		(CSG_Grid *pGrid);
+	bool						_Histogram_Update		(CSG_Shapes *pShapes, int Attribute);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_Classify_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,896 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Layer_Legend.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_shapes_point.h"
+#include "wksp_shapes_line.h"
+#include "wksp_shapes_polygon.h"
+#include "wksp_tin.h"
+#include "wksp_grid.h"
+
+#include "wksp_layer_classify.h"
+#include "wksp_layer_legend.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define ZOOMED(x)			((int)(m_Zoom * (double)x))
+
+//---------------------------------------------------------
+#define SPACE_VERTICAL		ZOOMED(5)
+#define BOX_WIDTH			ZOOMED(30)
+#define BOX_HEIGHT			ZOOMED(12)
+#define BOX_SPACE			ZOOMED(2)
+#define TICK_WIDTH			ZOOMED(5)
+#define METRIC_HEIGHT		ZOOMED(200)
+#define SIZE_HEIGHT			ZOOMED(100)
+
+//---------------------------------------------------------
+#define FONT_SIZE_TITLE		ZOOMED(10)
+#define FONT_SIZE_SUBTITLE	ZOOMED(8)
+#define FONT_SIZE_LABEL		ZOOMED(8)
+
+//---------------------------------------------------------
+#define METRIC_POS_V(Value)	(  y    + METRIC_HEIGHT - (int)((double)METRIC_HEIGHT * m_pClassify->Get_MetricToRelative((Value) / zFactor)))
+#define METRIC_POS_H(Value)	(m_xBox +                 (int)((double)METRIC_HEIGHT * m_pClassify->Get_MetricToRelative((Value) / zFactor)))
+#define METRIC_GET_STRING(z, dz)		wxString::Format(wxT("%.*f"), dz >= 1.0 ? 0 : 1 + (int)fabs(log10(dz)), z)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	FONT_TITLE		= 0,
+	FONT_SUBTITLE,
+	FONT_LABEL
+};
+
+//---------------------------------------------------------
+enum
+{
+	BOXSTYLE_RECT	= 0,
+	BOXSTYLE_LINE,
+	BOXSTYLE_CIRCLE
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Layer_Legend::CWKSP_Layer_Legend(CWKSP_Layer *pLayer)
+{
+	m_pLayer	= pLayer;
+	m_pClassify	= pLayer->Get_Classifier();
+}
+
+//---------------------------------------------------------
+CWKSP_Layer_Legend::~CWKSP_Layer_Legend(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxSize CWKSP_Layer_Legend::Get_Size(double Zoom, double Zoom_Map, bool bVertical)
+{
+	wxMemoryDC	dc;
+
+	Draw(dc, Zoom, Zoom_Map, wxPoint(0, 0), NULL, bVertical);
+
+	return( m_Size );
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::Draw(wxDC &dc, double Zoom, double Zoom_Map, wxPoint Position, wxSize *pSize, bool bVertical)
+{
+	//-----------------------------------------------------
+	m_Zoom		= Zoom > 0.0 ? Zoom : 1.0;
+	m_Position	= Position;
+	m_Size		= wxSize(BOX_WIDTH, 0);
+
+	m_Zoom_Map	= Zoom_Map;
+	m_bVertical	= bVertical;
+
+	//-----------------------------------------------------
+	m_oldPen	= dc.GetPen();
+	m_oldBrush	= dc.GetBrush();
+	m_oldFont	= dc.GetFont();
+
+	//-----------------------------------------------------
+	m_xBox		= m_Position.x;
+	m_dxBox		= BOX_WIDTH;
+	m_xTick		= m_xBox	+ m_dxBox;
+	m_dxTick	= TICK_WIDTH;
+	m_xText		= m_xTick	+ m_dxTick;
+
+	//-----------------------------------------------------
+	_Draw_Title(dc, FONT_TITLE, m_pLayer->Get_Object()->Get_Name());
+
+	//-----------------------------------------------------
+	switch( m_pLayer->Get_Type() )
+	{
+	case WKSP_ITEM_Shapes:
+		switch( ((CWKSP_Shapes *)m_pLayer)->Get_Shapes()->Get_Type() )
+		{
+		case SHAPE_TYPE_Point:
+		case SHAPE_TYPE_Points:
+			_Draw_Point		(dc, (CWKSP_Shapes_Point   *)m_pLayer);
+			break;
+
+		case SHAPE_TYPE_Line:
+			_Draw_Line		(dc, (CWKSP_Shapes_Line    *)m_pLayer);
+			break;
+
+		case SHAPE_TYPE_Polygon:
+			_Draw_Polygon	(dc, (CWKSP_Shapes_Polygon *)m_pLayer);
+			break;
+
+		default:
+			break;
+		}
+		break;
+
+	case WKSP_ITEM_TIN:
+		_Draw_TIN	(dc, (CWKSP_TIN        *)m_pLayer);
+		break;
+
+	case WKSP_ITEM_PointCloud:
+//		_Draw_TIN	(dc, (CWKSP_PointCloud *)m_pLayer);
+		break;
+
+	case WKSP_ITEM_Grid:
+		_Draw_Grid	(dc, (CWKSP_Grid       *)m_pLayer);
+		break;
+
+	default:
+		break;
+	}
+
+	//-----------------------------------------------------
+	dc.SetPen	(m_oldPen);
+	dc.SetBrush	(m_oldBrush);
+	dc.SetFont	(m_oldFont);
+
+	//-----------------------------------------------------
+	if( pSize )
+	{
+		*pSize	= m_Size;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CWKSP_Layer_Legend::_Set_Size(int xSet, int yAdd)
+{
+	if( m_Size.x < xSet )
+	{
+		m_Size.x	= xSet;
+	}
+
+	m_Position.y	+= yAdd;
+	m_Size.y		+= yAdd;
+}
+
+//---------------------------------------------------------
+inline void CWKSP_Layer_Legend::_Set_Font(wxDC &dc, int Style)
+{
+	switch( Style )
+	{
+	case FONT_TITLE:
+		dc.SetFont(wxFont(FONT_SIZE_TITLE   , wxSWISS, wxNORMAL, wxBOLD, false));
+		break;
+
+	case FONT_SUBTITLE:
+		dc.SetFont(wxFont(FONT_SIZE_SUBTITLE, wxSWISS, wxNORMAL, wxBOLD));
+		break;
+
+	case FONT_LABEL:	default:
+		dc.SetFont(wxFont(FONT_SIZE_LABEL   , wxSWISS, wxITALIC, wxNORMAL));
+		break;
+	}
+}
+
+//---------------------------------------------------------
+inline void CWKSP_Layer_Legend::_Draw_Title(wxDC &dc, int Style, wxString Text)
+{
+	wxCoord	dx_Text, dy_Text;
+
+	_Set_Font(dc, Style);
+
+	Draw_Text(dc, TEXTALIGN_TOPLEFT, m_Position.x, m_Position.y, Text);
+
+	dc.GetTextExtent(Text, &dx_Text, &dy_Text);
+
+	dy_Text			+= SPACE_VERTICAL;
+
+	_Set_Size(dx_Text, dy_Text);
+}
+
+//---------------------------------------------------------
+inline void CWKSP_Layer_Legend::_Draw_Label(wxDC &dc, int y, wxString Text, int yAlign)
+{
+	wxCoord	dx_Text, dy_Text;
+
+	switch( yAlign )
+	{
+	case TEXTALIGN_TOP:	default:
+		yAlign	= TEXTALIGN_TOPLEFT;
+		break;
+
+	case TEXTALIGN_YCENTER:
+		yAlign	= TEXTALIGN_CENTERLEFT;
+		break;
+
+	case TEXTALIGN_BOTTOM:
+		yAlign	= TEXTALIGN_BOTTOMLEFT;
+		break;
+	}
+
+	_Set_Font(dc, FONT_LABEL);
+
+	Draw_Text(dc, yAlign, m_xText, y, Text);
+
+	dc.GetTextExtent(Text, &dx_Text, &dy_Text);
+
+	_Set_Size((m_xText - m_xBox) + dx_Text, 0);
+}
+
+//---------------------------------------------------------
+inline void CWKSP_Layer_Legend::_Draw_Box(wxDC &dc, int y, int dy, wxColour Color)
+{
+	wxPen	Pen;
+	wxBrush	Brush;
+
+	//-----------------------------------------------------
+	_Set_Size(0, dy);
+
+	dy	-= BOX_SPACE;
+
+	//-----------------------------------------------------
+	if( m_Box_bOutline == false )
+	{
+		Pen		= dc.GetPen();
+		Pen.SetColour(Color);
+		dc.SetPen(Pen);
+	}
+
+	if( m_Box_bFill )
+	{
+		Brush	= dc.GetBrush();
+		Brush.SetColour(Color);
+		dc.SetBrush(Brush);
+	}
+
+	//-----------------------------------------------------
+	switch( m_BoxStyle )
+	{
+	case BOXSTYLE_LINE:
+		dc.DrawLine(m_xBox                  , y + dy / 2, m_xBox +     m_dxBox / 4, y);
+		dc.DrawLine(m_xBox +     m_dxBox / 4, y         , m_xBox + 3 * m_dxBox / 4, y + dy);
+		dc.DrawLine(m_xBox + 3 * m_dxBox / 4, y + dy    , m_xBox +     m_dxBox    , y + dy / 2);
+		break;
+
+	case BOXSTYLE_CIRCLE:
+		dc.DrawCircle(m_xBox + m_dxBox / 2, y + dy / 2, dy / 2);
+		break;
+
+	case BOXSTYLE_RECT:	default:
+		dc.DrawRectangle(m_xBox, y, m_dxBox, dy);
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Box_Image(wxDC &dc, int ay, CSG_Grid *pGrid)
+{
+	int		x, y, nx, ny, Color;
+	double	d, dx, dy;
+	wxImage	img;
+
+	//-----------------------------------------------------
+	if( pGrid->Get_NX() > pGrid->Get_NY() )
+	{
+		nx	= m_dxBox;
+		d	= (int)(pGrid->Get_NX() / nx);
+		ny	= (int)(pGrid->Get_NY() / d);
+	}
+	else
+	{
+		ny	= m_dxBox;
+		d	= (int)(pGrid->Get_NY() / ny);
+		nx	= (int)(pGrid->Get_NX() / d);
+	}
+
+	img.Create(nx, ny);
+
+	for(y=0, dy=0.0; y<ny; y++, dy+=d)
+	{
+		for(x=0, dx=0.0; x<nx; x++, dx+=d)
+		{
+			Color	= m_pClassify->Get_Class_Color_byValue(pGrid->asDouble((int)dx, (int)dy));
+			img.SetRGB(x, ny - 1 - y, SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
+		}
+	}
+
+	dc.DrawBitmap(wxBitmap(img), m_xBox, ay, false);
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, m_xBox, ay, m_xBox + nx, ay + ny);
+
+	//-----------------------------------------------------
+	_Set_Size(0, ny);
+
+	ny	+= BOX_SPACE;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Point(wxDC &dc, CWKSP_Shapes_Point *pLayer)
+{
+	bool		bSize;
+	int			min_Size, max_Size;
+	double		min_Value, d_Value;
+	wxString	Name, Name_Size;
+	wxPen		Pen;
+	wxBrush		Brush;
+
+	//-----------------------------------------------------
+	m_BoxStyle		= BOXSTYLE_CIRCLE;
+	m_Box_bFill		= true;
+
+	//-----------------------------------------------------
+	bSize	= pLayer->Get_Style_Size(min_Size, max_Size, min_Value, d_Value, &Name_Size);
+
+	pLayer->Get_Style(Pen, Brush, m_Box_bOutline, &Name);
+
+	if( m_pClassify->Get_Mode() != CLASSIFY_UNIQUE || !bSize )
+	{
+		dc.SetBrush(Brush);
+		dc.SetPen(Pen);
+
+		if( Name.Length() > 0 )
+		{
+			_Draw_Title(dc, FONT_SUBTITLE, Name);
+		}
+
+	//	_Draw_Boxes(dc, m_Position.y);
+		for(int i=m_pClassify->Get_Class_Count()-1, y=m_Position.y; i>=0; i--, y+=BOX_HEIGHT)
+		{
+	//		_Draw_Box	(dc, y, BOX_HEIGHT, Get_Color_asWX(m_pClassify->Get_Class_Color(i)));
+			_Set_Size(0, BOX_HEIGHT);
+
+			if( m_Box_bOutline == false )
+			{
+				Pen		= dc.GetPen();
+				Pen.SetColour(Get_Color_asWX(m_pClassify->Get_Class_Color(i)));
+				dc.SetPen(Pen);
+			}
+
+			if( m_Box_bFill )
+			{
+				Brush	= dc.GetBrush();
+				Brush.SetColour(Get_Color_asWX(m_pClassify->Get_Class_Color(i)));
+				dc.SetBrush(Brush);
+			}
+
+			pLayer->Draw_Symbol(dc, m_xBox + m_dxBox / 2, y + (BOX_HEIGHT - BOX_SPACE) / 2, (BOX_HEIGHT - BOX_SPACE) / 2);
+
+			_Draw_Label(dc, y, m_pClassify->Get_Class_Name(i), TEXTALIGN_TOP);
+		}
+	}
+
+	//-----------------------------------------------------
+	if( bSize )
+	{
+		dc.SetBrush(Brush);
+		dc.SetPen(Pen);
+
+		_Draw_Title(dc, FONT_SUBTITLE, Name_Size);
+		_Draw_Point_Sizes(dc, pLayer, min_Size, max_Size, min_Value, d_Value);
+		_Set_Size(0, SIZE_HEIGHT + dc.GetFont().GetPointSize());
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Point_Sizes(wxDC &dc, CWKSP_Shapes_Point *pLayer, int min_Size, int max_Size, double min_Value, double d_Value)
+{
+	int		iClass, nClasses, dy, y;
+	double	iSize, dySize;
+
+	nClasses	= (int)((double)SIZE_HEIGHT / (double)BOX_HEIGHT);
+	dySize		= (double)(max_Size - min_Size) / (double)nClasses;
+
+	for(iClass=nClasses, iSize=max_Size; iClass>=0; iClass--, iSize-=dySize)
+	{
+		dy	= (int)(2.0 * m_Zoom_Map * iSize) + BOX_SPACE;
+		y	= m_Position.y + SIZE_HEIGHT - iClass * BOX_HEIGHT;
+
+		pLayer->Draw_Symbol(dc, m_xBox + m_dxBox / 2, y + dy / 2, dy / 2);
+
+		_Draw_Label	(dc, y, wxString::Format(wxT("%f"), min_Value + (iSize - min_Size) / d_Value), TEXTALIGN_TOP);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Line(wxDC &dc, CWKSP_Shapes_Line *pLayer)
+{
+	bool		bSize;
+	int			min_Size, max_Size, iSize, y;
+	double		min_Value, dValue;
+	wxString	Name, Name_Size;
+	wxPen		Pen;
+
+	//-----------------------------------------------------
+	m_BoxStyle		= BOXSTYLE_LINE;
+	m_Box_bFill		= false;
+	m_Box_bOutline	= false;
+
+	//-----------------------------------------------------
+	bSize	= pLayer->Get_Style_Size(min_Size, max_Size, min_Value, dValue, &Name_Size);
+
+	pLayer->Get_Style(Pen, &Name);
+
+	if( m_pClassify->Get_Mode() != CLASSIFY_UNIQUE || !bSize )
+	{
+		dc.SetPen(Pen);
+
+		if( Name.Length() > 0 )
+		{
+			_Draw_Title(dc, FONT_SUBTITLE, Name);
+		}
+
+		_Draw_Boxes(dc, m_Position.y);
+	}
+
+	//-----------------------------------------------------
+	if( bSize )
+	{
+		_Draw_Title(dc, FONT_SUBTITLE, Name_Size);
+
+		for(iSize=min_Size; iSize<=max_Size; iSize++)
+		{
+			Pen.SetWidth(iSize);
+			dc.SetPen(Pen);
+
+			y	= m_Position.y;
+
+			_Draw_Box	(dc, y, BOX_HEIGHT, Pen.GetColour());
+			_Draw_Label	(dc, y, wxString::Format(wxT("%f"), min_Value + (iSize - min_Size) / dValue), TEXTALIGN_TOP);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Polygon(wxDC &dc, CWKSP_Shapes_Polygon *pLayer)
+{
+	wxString	Name;
+	wxPen		Pen;
+	wxBrush		Brush;
+
+	//-----------------------------------------------------
+	m_BoxStyle	= BOXSTYLE_RECT;
+	m_Box_bFill	= true;
+
+	//-----------------------------------------------------
+	pLayer->Get_Style(Pen, Brush, m_Box_bOutline, &Name);
+
+	dc.SetBrush(Brush);
+	dc.SetPen(Pen);
+
+	if( Name.Length() > 0 )
+	{
+		_Draw_Title(dc, FONT_SUBTITLE, Name);
+	}
+
+	//-----------------------------------------------------
+	_Draw_Boxes(dc, m_Position.y);
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_TIN(wxDC &dc, CWKSP_TIN *pLayer)
+{
+	//-----------------------------------------------------
+	m_BoxStyle		= BOXSTYLE_RECT;
+	m_Box_bFill		= true;
+	m_Box_bOutline	= true;
+
+	//-----------------------------------------------------
+	switch( m_pClassify->Get_Mode() )
+	{
+	default:
+		_Draw_Boxes(dc, m_Position.y);
+		break;
+
+	case CLASSIFY_METRIC:
+	case CLASSIFY_SHADE:
+		_Draw_Continuum(dc, m_Position.y, 1.0);
+		break;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Grid(wxDC &dc, CWKSP_Grid *pLayer)
+{
+	//-----------------------------------------------------
+	m_BoxStyle		= BOXSTYLE_RECT;
+	m_Box_bFill		= true;
+	m_Box_bOutline	= true;
+
+	//-----------------------------------------------------
+	switch( m_pClassify->Get_Mode() )
+	{
+	default:
+		_Draw_Boxes(dc, m_Position.y);
+		break;
+
+	case CLASSIFY_METRIC:
+	case CLASSIFY_SHADE:
+		if( pLayer->Get_Grid()->Get_Unit() && *(pLayer->Get_Grid()->Get_Unit()) )
+		{
+			_Draw_Title(dc, FONT_SUBTITLE, wxString::Format(wxT("[%s]"), pLayer->Get_Grid()->Get_Unit()));
+		}
+
+		_Draw_Continuum(dc, m_Position.y, pLayer->Get_Grid()->Get_ZFactor());
+		break;
+
+	case CLASSIFY_RGB:
+		_Draw_Box_Image(dc, m_Position.y, pLayer->Get_Grid());
+		break;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Boxes(wxDC &dc, int y)
+{
+	for(int i=m_pClassify->Get_Class_Count()-1; i>=0; i--, y+=BOX_HEIGHT)
+	{
+		_Draw_Box	(dc, y, BOX_HEIGHT, Get_Color_asWX(m_pClassify->Get_Class_Color(i)));
+		_Draw_Label	(dc, y, m_pClassify->Get_Class_Name(i), TEXTALIGN_TOP);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Continuum(wxDC &dc, int y, double zFactor)
+{
+	int		i;
+	double	zMin, zMax;
+
+	//-----------------------------------------------------
+	zMin	= m_pClassify->Get_RelativeToMetric(0.0);
+	zMax	= m_pClassify->Get_RelativeToMetric(1.0);
+
+	//-----------------------------------------------------
+	if( zMin >= zMax )
+	{
+		if( m_pLayer->Get_Value_Range() > 0.0 )
+		{
+			i	= m_pClassify->Get_Class_Count() - 1;
+			_Draw_Box	(dc, y, BOX_HEIGHT, Get_Color_asWX(m_pClassify->Get_Class_Color(i)));
+			_Draw_Label	(dc, y, m_pClassify->Get_Class_Name(i), TEXTALIGN_TOP);
+
+			y	+= BOX_HEIGHT;
+		}
+
+		i	= 0;
+		_Draw_Box	(dc, y, BOX_HEIGHT, Get_Color_asWX(m_pClassify->Get_Class_Color(i)));
+		_Draw_Label	(dc, y, m_pClassify->Get_Class_Name(i), TEXTALIGN_TOP);
+	}
+
+	//-----------------------------------------------------
+	else if( METRIC_HEIGHT > m_pClassify->Get_Class_Count() * BOX_HEIGHT )
+	{
+		_Draw_Boxes(dc, y);
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		int		dyFont;
+		double	yToDC, dz;
+
+		_Set_Font(dc, FONT_LABEL);
+		dc.GetTextExtent(wxString::Format(wxT("01234567")), &i, &dyFont);
+
+		zMin	*= zFactor;
+		zMax	*= zFactor;
+		yToDC	= METRIC_HEIGHT / (zMax - zMin);
+		dz		= pow(10.0, floor(log10(zMax - zMin)) - 1.0);
+		while( yToDC * dz < dyFont )
+			dz	*= 2.0;
+
+		yToDC	= METRIC_HEIGHT / (double)m_pClassify->Get_Class_Count();
+
+		if( m_bVertical )
+		{
+			_Draw_Continuum_V(dc, y, yToDC, zMin, zMax, zFactor, dz, dyFont);
+		}
+		else
+		{
+			_Draw_Continuum_H(dc, y, yToDC, zMin, zMax, zFactor, dz, dyFont);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Continuum_V(wxDC &dc, int y, double yToDC, double zMin, double zMax, double zFactor, double dz, int dyFont)
+{
+	int		i, iy, jy;
+	double	z;
+
+	//-----------------------------------------------------
+	for(i=0, z=y+METRIC_HEIGHT; i<m_pClassify->Get_Class_Count(); i++, z-=yToDC)
+	{
+		Draw_FillRect(dc, Get_Color_asWX(m_pClassify->Get_Class_Color(i)), m_xBox, (int)(z), m_xTick, (int)(z - yToDC));
+	}
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, m_xBox, y, m_xTick, y + METRIC_HEIGHT);
+
+	//-----------------------------------------------------
+	switch( m_pClassify->Get_Metric_Mode() )
+	{
+	case METRIC_MODE_NORMAL:	default:
+		z	= dz * floor(zMin / dz);
+		if( z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			iy	= METRIC_POS_V(z);
+			dc.DrawLine(m_xTick, iy, m_xText, iy);
+
+			_Draw_Label(dc, iy, METRIC_GET_STRING(z, dz), TEXTALIGN_YCENTER);
+		}
+		break;
+
+	case METRIC_MODE_LOGUP:
+		jy	= METRIC_POS_V(zMax) + (1 + dyFont);
+		z	= dz * floor(zMax / dz);
+		if( z > zMax )	z	-= dz;
+
+		for(; z>=zMin; z-=dz)
+		{
+			iy	= METRIC_POS_V(z);
+			dc.DrawLine(m_xTick, iy, m_xText, iy);
+
+			if( abs(jy - iy) >= (int)(0.75 * dyFont) )
+			{
+				jy	= iy;
+				_Draw_Label(dc, iy, METRIC_GET_STRING(z, dz), TEXTALIGN_YCENTER);
+			}
+
+			while( abs(iy - METRIC_POS_V(z - dz)) > 2 * dyFont )
+				dz	*= 0.1;
+		}
+		break;
+
+	case METRIC_MODE_LOGDOWN:
+		jy	= METRIC_POS_V(zMin) - (1 + dyFont);
+		z	= dz * floor(zMin / dz);
+		if( z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			iy	= METRIC_POS_V(z);
+			dc.DrawLine(m_xTick, iy, m_xText, iy);
+
+			if( abs(jy - iy) >= (int)(0.75 * dyFont) )
+			{
+				jy	= iy;
+				_Draw_Label(dc, iy, METRIC_GET_STRING(z, dz), TEXTALIGN_YCENTER);
+			}
+
+			while( abs(iy - METRIC_POS_V(z + dz)) > 2 * dyFont )
+				dz	*= 0.1;
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	_Set_Size(0, METRIC_HEIGHT + dc.GetFont().GetPointSize());
+}
+
+//---------------------------------------------------------
+void CWKSP_Layer_Legend::_Draw_Continuum_H(wxDC &dc, int y, double yToDC, double zMin, double zMax, double zFactor, double dz, int dyFont)
+{
+	int			i, iy, jy, yTick, yText, sx, sy;
+	double		z;
+	wxString	s;
+
+	yTick	= y + m_dxBox;
+	yText	= y + m_dxBox + m_dxTick;
+
+	//-----------------------------------------------------
+	for(i=0, z=m_xBox; i<m_pClassify->Get_Class_Count(); i++, z+=yToDC)
+	{
+		Draw_FillRect(dc, Get_Color_asWX(m_pClassify->Get_Class_Color(i)), (int)(z), y, (int)(z + yToDC), yTick);
+	}
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, m_xBox, y, m_xBox + METRIC_HEIGHT, yTick);
+
+	//-----------------------------------------------------
+	switch( m_pClassify->Get_Metric_Mode() )
+	{
+	case METRIC_MODE_NORMAL:	default:
+		jy	= METRIC_POS_H(zMin) - METRIC_HEIGHT;
+		z	= dz * floor(zMin / dz);
+		if( z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			iy	= METRIC_POS_H(z);
+			dc.DrawLine(iy, yTick, iy, yText);
+
+			s	= METRIC_GET_STRING(z, dz);
+			dc.GetTextExtent(s, &sx, &sy);
+
+			if( abs(jy - iy) >= (int)(1.25 * sx) )
+			{
+				jy	= iy;
+				Draw_Text(dc, TEXTALIGN_TOPCENTER, iy, yText, s);
+			}
+		}
+		break;
+
+	case METRIC_MODE_LOGUP:
+		jy	= METRIC_POS_H(zMax) + METRIC_HEIGHT;
+		z	= dz * floor(zMax / dz);
+		if( z > zMax )	z	-= dz;
+
+		for(; z>=zMin; z-=dz)
+		{
+			iy	= METRIC_POS_H(z);
+			dc.DrawLine(iy, yTick, iy, yText);
+
+			s	= METRIC_GET_STRING(z, dz);
+			dc.GetTextExtent(s, &sx, &sy);
+
+			if( abs(jy - iy) >= (int)(1.25 * sx) )
+			{
+				jy	= iy;
+				Draw_Text(dc, TEXTALIGN_TOPCENTER, iy, yText, s);
+			}
+
+			while( abs(iy - METRIC_POS_H(z - dz)) > 2 * sx )
+				dz	*= 0.1;
+		}
+		break;
+
+	case METRIC_MODE_LOGDOWN:
+		jy	= METRIC_POS_H(zMin) - METRIC_HEIGHT;
+		z	= dz * floor(zMin / dz);
+		if( z < zMin )	z	+= dz;
+
+		for(; z<=zMax; z+=dz)
+		{
+			iy	= METRIC_POS_H(z);
+			dc.DrawLine(iy, yTick, iy, yText);
+
+			s	= METRIC_GET_STRING(z, dz);
+			dc.GetTextExtent(s, &sx, &sy);
+
+			if( abs(jy - iy) >= (int)(1.25 * sx) )
+			{
+				jy	= iy;
+				Draw_Text(dc, TEXTALIGN_TOPCENTER, iy, yText, s);
+			}
+
+			while( abs(iy - METRIC_POS_H(z + dz)) > 2 * sx )
+				dz	*= 0.1;
+		}
+		break;
+	}
+
+	//-----------------------------------------------------
+	_Set_Size(METRIC_HEIGHT, yText + dyFont);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_layer_legend.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Layer_Legend.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_Legend_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_Legend_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Layer_Legend
+{
+public: ///////////////////////////////////////////////////
+	CWKSP_Layer_Legend(class CWKSP_Layer *pLayer);
+	virtual ~CWKSP_Layer_Legend(void);
+
+	wxSize						Get_Size			(double Zoom, double Zoom_Map, bool bVertical = true);
+	void						Draw				(wxDC &dc, double Zoom, double Zoom_Map, wxPoint Position, wxSize *pSize = NULL, bool bVertical = true);
+
+
+protected: ////////////////////////////////////////////////
+
+	bool						m_Box_bOutline, m_Box_bFill, m_bVertical;
+
+	int							m_xBox, m_dxBox, m_xTick, m_dxTick, m_xText, m_BoxStyle;
+
+	double						m_Zoom, m_Zoom_Map;
+
+	wxPoint						m_Position;
+
+	wxSize						m_Size;
+
+	wxPen						m_oldPen;
+
+	wxBrush						m_oldBrush;
+
+	wxFont						m_oldFont;
+
+	class CWKSP_Layer			*m_pLayer;
+
+	class CWKSP_Layer_Classify	*m_pClassify;
+
+
+	void						_Set_Size			(int xSet, int yAdd);
+	void						_Set_Font			(wxDC &dc, int Style);
+	void						_Draw_Title			(wxDC &dc, int Style, wxString Text);
+	void						_Draw_Label			(wxDC &dc, int y, wxString Text, int yAlign);
+	void						_Draw_Box			(wxDC &dc, int y, int dy, wxColour Color);
+	void						_Draw_Box_Image		(wxDC &dc, int y, class CSG_Grid *pGrid);
+
+	void						_Draw_Point			(wxDC &dc, class CWKSP_Shapes_Point   *pLayer);
+	void						_Draw_Point_Sizes	(wxDC &dc, class CWKSP_Shapes_Point   *pLayer, int min_Size, int max_Size, double min_Value, double d_Value);
+	void						_Draw_Line			(wxDC &dc, class CWKSP_Shapes_Line    *pLayer);
+	void						_Draw_Polygon		(wxDC &dc, class CWKSP_Shapes_Polygon *pLayer);
+	void						_Draw_TIN			(wxDC &dc, class CWKSP_TIN            *pLayer);
+	void						_Draw_Grid			(wxDC &dc, class CWKSP_Grid           *pLayer);
+
+	void						_Draw_Boxes			(wxDC &dc, int y);
+	void						_Draw_Continuum		(wxDC &dc, int y, double zFactor);
+	void						_Draw_Continuum_V	(wxDC &dc, int y, double yToDC, double zMin, double zMax, double zFactor, double dz, int dyFont);
+	void						_Draw_Continuum_H	(wxDC &dc, int y, double yToDC, double zMin, double zMax, double zFactor, double dz, int dyFont);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Layer_Legend_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1754 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WKSP_Map.cpp                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+#include <wx/dcmemory.h>
+#include <wx/filename.h>
+#include <wx/clipbrd.h>
+#include <wx/dataobj.h>
+
+#include <saga_api/doc_pdf.h>
+#include "svg_interactive_map.h"
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "active.h"
+#include "active_legend.h"
+
+#include "wksp_map_control.h"
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+#include "wksp_map_buttons.h"
+
+#include "wksp_layer_legend.h"
+#include "wksp_shapes.h"
+
+#include "view_map.h"
+#include "view_map_control.h"
+#include "view_map_3d.h"
+#include "view_layout.h"
+#include "view_layout_info.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define LEGEND_SPACE	10
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Rect	CWKSP_Map_Extents::m_Dummy	= CSG_Rect(0, 0, 1, 1);
+
+//---------------------------------------------------------
+CWKSP_Map_Extents::CWKSP_Map_Extents(void)
+{
+	m_iExtent	= -1;
+	m_nExtents	= 0;
+}
+
+//---------------------------------------------------------
+CSG_Rect CWKSP_Map_Extents::Set_Back(void)
+{
+	if( m_iExtent < 0 )
+		return( m_Dummy );
+
+	if( !is_First() )
+	{
+		m_iExtent--;
+	}
+
+	return( Get_Rect(m_iExtent) );
+}
+
+//---------------------------------------------------------
+CSG_Rect CWKSP_Map_Extents::Set_Forward(void)
+{
+	if( m_iExtent < 0 )
+		return( m_Dummy );
+
+	if( !is_Last() )
+	{
+		m_iExtent++;
+	}
+
+	return( Get_Rect(m_iExtent) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Extents::Add_Extent(const CSG_Rect &Extent, bool bReset)
+{
+	if( Extent.Get_XRange() > 0.0 && Extent.Get_YRange() > 0.0 )
+	{
+		if( bReset )
+		{
+			m_iExtent	= -1;
+			m_nExtents	= 0;
+		}
+
+		if( Extent != Get_Extent() )
+		{
+			m_iExtent	++;
+			m_nExtents	= m_iExtent + 1;
+
+			if( m_nExtents > Get_Count() )
+			{
+				Add(Extent);
+			}
+			else
+			{
+				Get_Rect(m_iExtent)	= Extent;
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map::CWKSP_Map(void)
+{
+	static int	iMap	= 0;
+
+	m_Name.Printf(wxT("%02d. %s"), ++iMap, LNG("[CAP] Map"));
+
+	_Create_Parameters();
+
+	m_pView			= NULL;
+	m_pView_3D		= NULL;
+	m_pLayout		= NULL;
+	m_pLayout_Info	= new CVIEW_Layout_Info(this);
+
+	m_bSynchronise	= false;
+	m_Img_bSave		= false;
+}
+
+//---------------------------------------------------------
+CWKSP_Map::~CWKSP_Map(void)
+{
+	View_Show			(false);
+	View_3D_Show		(false);
+	View_Layout_Show	(false);
+
+	delete(m_pLayout_Info);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Map::Get_Name(void)
+{
+	return( m_Name );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Map::Get_Description(void)
+{
+	wxString	s;
+
+	s.Append(wxString::Format(wxT("<b>%s</b><table border=\"0\">"),
+		LNG("[CAP] Map")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, m_Name.c_str()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Layers")					, Get_Count()
+	));
+
+	s.Append(wxT("</table>"));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Map::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Map"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_MAPS_SHOW);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_IMAGE);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_MAPS_SAVE_IMAGE_ON_CHANGE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_TO_CLIPBOARD);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_TO_CLIPBOARD_LEGEND);
+	if( CSG_Doc_PDF::Get_Version() != NULL )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_PDF_INDEXED);
+	}
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SAVE_INTERACTIVE_SVG);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_MAPS_3D_SHOW);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_MAPS_LAYOUT_SHOW);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_SYNCHRONIZE);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		View_Show(true);
+		break;
+
+	case ID_CMD_MAPS_SAVE_IMAGE:
+		SaveAs_Image();
+		break;
+
+	case ID_CMD_MAPS_SAVE_IMAGE_ON_CHANGE:
+		SaveAs_Image_On_Change();
+		break;
+
+	case ID_CMD_MAPS_SAVE_TO_CLIPBOARD:
+		SaveAs_Image_Clipboard(false);
+		break;
+
+	case ID_CMD_MAPS_SAVE_TO_CLIPBOARD_LEGEND:
+		SaveAs_Image_Clipboard(true);
+		break;
+
+	case ID_CMD_MAPS_SAVE_PDF_INDEXED:
+		SaveAs_PDF_Indexed();
+		break;
+
+	case ID_CMD_MAPS_SAVE_INTERACTIVE_SVG:
+		SaveAs_Interactive_SVG();
+		break;
+	
+	case ID_CMD_MAPS_SYNCHRONIZE:
+		Set_Synchronising(!m_bSynchronise);
+		break;
+
+	case ID_CMD_MAPS_SHOW:
+		View_Toggle();
+		break;
+
+	case ID_CMD_MAPS_3D_SHOW:
+		View_3D_Toggle();
+		break;
+
+	case ID_CMD_MAPS_LAYOUT_SHOW:
+		View_Layout_Toggle();
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command_UI(event) );
+
+	case ID_CMD_MAPS_SHOW:
+		event.Check(m_pView != NULL);
+		break;
+
+	case ID_CMD_MAPS_3D_SHOW:
+		event.Check(m_pView_3D != NULL);
+		break;
+
+	case ID_CMD_MAPS_LAYOUT_SHOW:
+		event.Check(m_pLayout != NULL);
+		break;
+
+	case ID_CMD_MAPS_SAVE_IMAGE_ON_CHANGE:
+		event.Check(is_Image_Save_Mode());
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map::_Create_Parameters(void)
+{
+	CSG_Parameter	*pNode_0, *pNode_1;
+
+	//-----------------------------------------------------
+	m_Parameters.Create(this, LNG(""), LNG(""));
+	m_Parameters.Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
+
+	//-----------------------------------------------------
+	pNode_0	= m_Parameters.Add_Node(
+		NULL	, "NODE_GENERAL"	, LNG("[CAP] General"),
+		LNG("")
+	);
+
+	m_Parameters.Add_String(
+		pNode_0	, "NAME"			, LNG("[CAP] Name"),
+		LNG(""),
+		m_Name.c_str()
+	);
+
+	m_Parameters.Add_Value(
+		pNode_0	, "GOTO_NEWLAYER"	, LNG("[CAP] Zoom to added layer"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, g_pMaps->Get_Parameters()->Get_Parameter("GOTO_NEWLAYER")->asBool()
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= m_Parameters.Add_Node(
+		NULL	, "NODE_FRAME"		, LNG("[CAP] Frame"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		pNode_0	, "FRAME_SHOW"		, LNG("[CAP] Show"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, g_pMaps->Get_Parameters()->Get_Parameter("FRAME_SHOW")->asBool()
+	);
+
+	m_Parameters.Add_Value(
+		pNode_0	, "FRAME_WIDTH"		, LNG("[CAP] Width"),
+		LNG(""),
+		PARAMETER_TYPE_Int, g_pMaps->Get_Parameters()->Get_Parameter("FRAME_WIDTH")->asInt(), 5, true
+	);
+
+	//-----------------------------------------------------
+	pNode_0	= m_Parameters.Add_Node(
+		NULL	, "NODE_PRINT"		, LNG("[CAP] Print Layout"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		pNode_0	, "PRINT_LEGEND"	, LNG("[CAP] Show Legend"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|"),
+			LNG("no"),
+			LNG("yes")
+		), 1
+	);
+
+	m_Parameters.Add_Value(
+		pNode_0	, "PRINT_RESOLUTION"	, LNG("[CAP] Display Resolution"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 2, 1, true
+	);
+
+	pNode_1	= m_Parameters.Add_Node(
+		pNode_0	, "NODE_PRINT_FRAME"	, LNG("[CAP] Frame"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "PRINT_FRAME_SHOW"	, LNG("[CAP] Show"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "PRINT_FRAME_WIDTH"	, LNG("[CAP] Width"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 7, 5, true
+	);
+
+	//-----------------------------------------------------
+	m_Img_Parms.Set_Name(LNG("[CAP] Save Map as Image..."));
+
+	pNode_0	= m_Img_Parms.Add_Node(NULL, "NODE_MAP", LNG("Map"), LNG(""));
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "NX"	, LNG("[PRM] Map Width [Pixels]"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 800	, 1, true
+	);
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "NY"	, LNG("[PRM] Map Height [Pixels]"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 600	, 1, true
+	);
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "FR"	, LNG("[PRM] Frame Width [Pixels]"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 20	, 0, true
+	);
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "REF"	, LNG("[PRM] Save Georeference (world file)"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, 1
+	);
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "KML"	, LNG("[PRM] Save KML file"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, 1
+	);
+
+	pNode_0	= m_Img_Parms.Add_Node(NULL, "NODE_LEGEND", LNG("[PRM] Legend"), LNG(""));
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "LG"	, LNG("[PRM] Save"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, 1
+	);
+
+	m_Img_Parms.Add_Value(
+		pNode_0	, "LZ"	, LNG("[PRM] Zoom"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 1.0, 0, true
+	);
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::Get_Frame_Width(void)
+{
+	return( m_Parameters("FRAME_SHOW")->asBool() ? m_Parameters("FRAME_WIDTH")->asInt() : 0 );
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::Get_Print_Resolution(void)
+{
+	return( m_Parameters("PRINT_RESOLUTION")->asInt() );
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::Get_Print_Frame(void)
+{
+	return( m_Parameters("PRINT_FRAME_SHOW")->asBool() ? m_Parameters("PRINT_FRAME_WIDTH")->asInt() : 0 );
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::Get_Print_Legend(void)
+{
+	return( m_Parameters("PRINT_LEGEND")->asInt() );
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::_On_Parameter_Changed(CSG_Parameter *pParameter)
+{
+	if( pParameter && pParameter->Get_Owner() && pParameter->Get_Owner()->Get_Owner() )
+	{
+		return( ((CWKSP_Map *)pParameter->Get_Owner()->Get_Owner())->
+			On_Parameter_Changed(pParameter->Get_Owner(), pParameter)
+		);
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	return( 1 );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Parameters_Changed(void)
+{
+	m_Name	= m_Parameters("NAME")->asString();
+
+	if( m_pView )
+	{
+		m_pView->SetTitle(m_Name);
+
+		m_pView->Ruler_Set_Width(Get_Frame_Width());
+	}
+
+	View_Refresh(false);
+
+	CWKSP_Base_Manager::Parameters_Changed();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Layer * CWKSP_Map::Find_Layer(CWKSP_Layer *pLayer)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( pLayer == Get_Layer(i)->Get_Layer() )
+		{
+			return( Get_Layer(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+int CWKSP_Map::Get_Layer(CWKSP_Layer *pLayer)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( pLayer == Get_Layer(i)->Get_Layer() )
+		{
+			return( i );
+		}
+	}
+
+	return( -1 );
+}
+
+//---------------------------------------------------------
+CWKSP_Map_Layer * CWKSP_Map::Add_Layer(CWKSP_Layer *pLayer)
+{
+	CWKSP_Map_Layer	*pItem;
+
+	if( Get_Layer(pLayer) < 0 )
+	{
+		if( Get_Count() == 0 )
+		{
+			Set_Extent(pLayer->Get_Extent());
+		}
+
+		if( Get_Count() == 0 || m_Parameters("GOTO_NEWLAYER")->asBool() )
+		{
+			Set_Extent(pLayer->Get_Extent());
+		}
+
+		Add_Item(pItem = new CWKSP_Map_Layer(pLayer));
+
+		Move_Top(pItem);
+
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::Update(CWKSP_Layer *pLayer, bool bMapOnly)
+{
+	int		iLayer;
+	
+	if( (iLayer = Get_Layer(pLayer)) >= 0 )
+	{
+		if( !bMapOnly )
+		{
+			Get_Layer(iLayer)->Parameters_Changed();
+		}
+
+		if( m_pView )
+		{
+			View_Refresh(bMapOnly);
+		}
+
+		_Img_Save_On_Change();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map::_Set_Extent(const CSG_Rect &Extent)
+{
+	if( Extent.Get_XRange() > 0.0 && Extent.Get_YRange() > 0.0 )
+	{
+		View_Refresh(true);
+
+		if( m_bSynchronise )
+		{
+			_Synchronise_Extents();
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Set_Extent(const CSG_Rect &Extent, bool bReset)
+{
+	if( m_Extents.Add_Extent(Extent, bReset) )
+	{
+		_Set_Extent(Extent);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Set_Extent(void)
+{
+	CSG_Parameters	p(NULL, LNG("[CAP] Map Extent"), LNG(""));
+
+	p.Add_Range(NULL, "X", LNG("West-East")		, LNG(""), Get_Extent().Get_XMin(), Get_Extent().Get_XMax());
+	p.Add_Range(NULL, "Y", LNG("South-North")	, LNG(""), Get_Extent().Get_YMin(), Get_Extent().Get_YMax());
+
+	if( DLG_Parameters(&p) )
+	{
+		Set_Extent(CSG_Rect(
+			p("X")->asRange()->Get_LoVal(),
+			p("Y")->asRange()->Get_LoVal(),
+			p("X")->asRange()->Get_HiVal(),
+			p("Y")->asRange()->Get_HiVal())
+		);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Set_Extent_Full(void)
+{
+	if( Get_Count() > 0 )
+	{
+		CSG_Rect	Extent(Get_Layer(0)->Get_Layer()->Get_Extent());
+
+		for(int i=1; i<Get_Count(); i++)
+		{
+			Extent.Union(Get_Layer(i)->Get_Layer()->Get_Extent());
+		}
+
+		Set_Extent(Extent);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Set_Extent_Active(void)
+{
+	if( Get_Active_Layer() )
+	{
+		Set_Extent(Get_Active_Layer()->Get_Extent());
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Set_Extent_Selection(void)
+{
+	if( Get_Active_Layer() )
+	{
+		Set_Extent(Get_Active_Layer()->Edit_Get_Extent());
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::Set_Extent_Back(bool bCheck_Only)
+{
+	if( !m_Extents.is_First() )
+	{
+		if( !bCheck_Only )
+		{
+			_Set_Extent(m_Extents.Set_Back());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::Set_Extent_Forward(bool bCheck_Only)
+{
+	if( !m_Extents.is_Last() )
+	{
+		if( !bCheck_Only )
+		{
+			_Set_Extent(m_Extents.Set_Forward());
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Set_Synchronising(bool bOn)
+{
+	m_bSynchronise	= bOn;
+
+	if( m_bSynchronise )
+	{
+		_Synchronise_Extents();
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::_Synchronise_Extents(void)
+{
+	for(int i=0; i<Get_Manager()->Get_Count(); i++)
+	{
+		if( Get_Manager()->Get_Item(i) != this )
+		{
+			((CWKSP_Map_Manager *)Get_Manager())->Get_Map(i)->Set_Extent(Get_Extent());
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map::On_Delete(CWKSP_Map_Layer *pLayer)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map::View_Closes(wxMDIChildFrame *pView)
+{
+	if( wxDynamicCast(pView, CVIEW_Map) != NULL )
+	{
+		m_pView		= NULL;
+	}
+
+	if( wxDynamicCast(pView, CVIEW_Map_3D) != NULL )
+	{
+		m_pView_3D	= NULL;
+	}
+
+	if( wxDynamicCast(pView, CVIEW_Layout) != NULL )
+	{
+		m_pLayout	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_Refresh(bool bMapOnly)
+{
+	if( !bMapOnly && g_pACTIVE && g_pACTIVE->Get_Legend() )
+	{
+		g_pACTIVE->Get_Legend()->Refresh(true);
+	}
+
+	if( m_pView )
+	{
+		m_pView->Refresh_Map();
+	}
+
+	if( m_pView_3D )
+	{
+		m_pView_3D->On_Source_Changed();
+	}
+
+	if( m_pLayout )
+	{
+		m_pLayout->Refresh_Layout();
+	}
+
+	_Set_Thumbnail();
+
+	if( g_pMap_Buttons )
+	{
+		g_pMap_Buttons->Refresh();
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_Show(bool bShow)
+{
+	if( bShow )
+	{
+		if( !m_pView )
+		{
+			m_pView	= new CVIEW_Map(this, Get_Frame_Width());
+		}
+		else
+		{
+			View_Refresh(false);
+			m_pView->Activate();
+		}
+	}
+	else if( m_pView )
+	{
+		m_pView->Destroy();
+		delete(m_pView);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_Toggle(void)
+{
+	View_Show( m_pView == NULL );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_3D_Show(bool bShow)
+{
+	if( bShow && !m_pView_3D )
+	{
+		m_pView_3D	= new CVIEW_Map_3D(this);
+	}
+	else if( !bShow && m_pView_3D )
+	{
+		m_pView_3D->Destroy();
+		delete(m_pView_3D);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_3D_Toggle(void)
+{
+	View_3D_Show( m_pView_3D == NULL );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_Layout_Show(bool bShow)
+{
+	if( bShow && !m_pLayout )
+	{
+		m_pLayout	= new CVIEW_Layout(m_pLayout_Info);
+	}
+	else if( !bShow && m_pLayout )
+	{
+		m_pLayout->Destroy();
+		delete(m_pLayout);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::View_Layout_Toggle(void)
+{
+	View_Layout_Show( m_pLayout == NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Rect CWKSP_Map::Get_World(wxRect rClient)
+{
+	double		d, dWorld, dClient;
+	TSG_Rect	Extent;
+
+	Extent	= Get_Extent().m_rect;
+
+	dClient	= (double)rClient.GetHeight()	/ (double)rClient.GetWidth();
+	dWorld	= Get_Extent().Get_YRange()		/ Get_Extent().Get_XRange();
+
+	if( dWorld > dClient )
+	{
+		d			= (Get_Extent().Get_XRange() - Get_Extent().Get_YRange() / dClient) / 2.0;
+		Extent.xMin	+= d;
+		Extent.xMax	-= d;
+	}
+	else
+	{
+		d			= (Get_Extent().Get_YRange() - Get_Extent().Get_XRange() * dClient) / 2.0;
+		Extent.yMin	+= d;
+		Extent.yMax	-= d;
+	}
+
+	return( CSG_Rect(Extent) );
+}
+
+//---------------------------------------------------------
+CSG_Point CWKSP_Map::Get_World(wxRect rClient, wxPoint ptClient)
+{
+	double		d;
+	CSG_Rect	rWorld(Get_World(rClient));
+
+	ptClient.y	= rClient.GetHeight() - ptClient.y;
+	d			= rWorld.Get_XRange() / (double)rClient.GetWidth();
+
+	return( CSG_Point(
+		rWorld.Get_XMin() + ptClient.x * d,
+		rWorld.Get_YMin() + ptClient.y * d)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MASK_R	255
+#define MASK_G	0
+#define MASK_B	255
+
+//---------------------------------------------------------
+bool CWKSP_Map::Get_Image(wxImage &Image, CSG_Rect &rWorld)
+{
+	if( Image.GetWidth() > 0 && Image.GetHeight() > 0 )
+	{
+		wxBitmap	BMP(Image);
+		wxMemoryDC	dc;
+
+		dc.SelectObject(BMP);
+		Draw_Map(dc, 1.0, wxRect(0, 0, Image.GetWidth(), Image.GetHeight()), false, SG_GET_RGB(MASK_R, MASK_G, MASK_B));
+		dc.SelectObject(wxNullBitmap);
+
+		rWorld	= Get_World(wxRect(0, 0, Image.GetWidth(), Image.GetHeight()));
+		Image	= BMP.ConvertToImage();
+		Image.SetMaskColour(MASK_R, MASK_G, MASK_B);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::SaveAs_Image(void)
+{
+	//-----------------------------------------------------
+	if( View_Get() && View_Get()->Get_Map_Control() )
+	{
+		wxSize	s(View_Get()->Get_Map_Control()->GetClientSize());
+
+		m_Img_Parms("NX")->Set_Value(s.x);
+		m_Img_Parms("NY")->Set_Value(s.y);
+	}
+
+	if( DLG_Image_Save(m_Img_File, m_Img_Type) && DLG_Parameters(&m_Img_Parms) )
+	{
+		_Img_Save(m_Img_File, m_Img_Type);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::SaveAs_Image_Clipboard(bool bLegend)
+{
+	if( bLegend == false )
+	{
+		SaveAs_Image_Clipboard(
+			Get_Manager()->Get_Parameters()->Get_Parameter("CLIP_NX")	->asInt(),
+			Get_Manager()->Get_Parameters()->Get_Parameter("CLIP_NY")	->asInt(),
+			Get_Manager()->Get_Parameters()->Get_Parameter("CLIP_FRAME")->asInt()
+		);
+
+		return;
+	}
+
+	//-----------------------------------------------------
+	// draw a legend...
+
+	Set_Buisy_Cursor(true);
+
+	int			Frame	= Get_Manager()->Get_Parameters()->Get_Parameter("CLIP_LEGEND_FRAME")->asInt();
+	double		Scale	= Get_Manager()->Get_Parameters()->Get_Parameter("CLIP_LEGEND_SCALE")->asDouble();
+	wxSize		s;
+	wxBitmap	BMP;
+	wxMemoryDC	dc;
+
+	if( Get_Legend_Size(s, 1.0, Scale) )
+	{
+		s.x	+= 2 * Frame;
+		s.y	+= 2 * Frame;
+
+		BMP.Create(s.GetWidth(), s.GetHeight());
+		dc.SelectObject(BMP);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		if( Frame > 0 )
+		{
+			dc.SetPen(Get_Color_asWX(Get_Manager()->Get_Parameters()->Get_Parameter("CLIP_LEGEND_COLOR")->asInt()));
+			Draw_Edge(dc, EDGE_STYLE_SIMPLE, 0, 0, s.x - 1, s.y - 1);
+		}
+
+		Draw_Legend(dc, 1.0, Scale, wxPoint(Frame, Frame));
+
+		dc.SelectObject(wxNullBitmap);
+
+		if( wxTheClipboard->Open() )
+		{
+			wxBitmapDataObject	*pBMP	= new wxBitmapDataObject;
+			pBMP->SetBitmap(BMP);
+			wxTheClipboard->SetData(pBMP);
+			wxTheClipboard->Close();
+		}
+	}
+
+	Set_Buisy_Cursor(false);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::SaveAs_Image_Clipboard(int nx, int ny, int frame)
+{
+	Set_Buisy_Cursor(true);
+
+	wxSize		s;
+	wxRect		r;
+	wxBitmap	BMP;
+	wxMemoryDC	dc;
+
+//	if( frame < 0 )	frame	= Get_Frame_Width();
+	if( frame < 5 )	frame	= 0;
+
+	r		= wxRect(0, 0, nx + 2 * frame, ny + 2 * frame);
+
+	BMP.Create(r.GetWidth(), r.GetHeight());
+	r.Deflate(frame);
+	dc.SelectObject(BMP);
+	dc.SetBackground(*wxWHITE_BRUSH);
+	dc.Clear();
+
+	Draw_Map(dc, 1.0, r, false);
+	Draw_Frame(dc, r, frame);
+
+	dc.SelectObject(wxNullBitmap);
+
+	if( wxTheClipboard->Open() )
+	{
+		wxBitmapDataObject	*pBMP	= new wxBitmapDataObject;
+		pBMP->SetBitmap(BMP);
+		wxTheClipboard->SetData(pBMP);
+		wxTheClipboard->Close();
+	}
+
+	Set_Buisy_Cursor(false);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::SaveAs_Image_On_Change(void)
+{
+	if( m_Img_bSave )
+	{
+		m_Img_bSave	= false;
+	}
+	else if( DLG_Image_Save(m_Img_File, m_Img_Type) && DLG_Parameters(&m_Img_Parms) )
+	{
+		m_Img_bSave	= true;
+		m_Img_Count	= 0;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::_Img_Save_On_Change(void)
+{
+	if( m_Img_bSave )
+	{
+		wxFileName	fn(m_Img_File), file(m_Img_File);
+
+		file.SetName(wxString::Format(wxT("%s_%03d"), fn.GetName().c_str(), m_Img_Count++));
+
+		_Img_Save(file.GetFullPath(), m_Img_Type);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::_Img_Save(wxString file, int type)
+{
+	int			nx, ny, Frame;
+	wxSize		s;
+	wxRect		r;
+	wxBitmap	BMP;
+	wxMemoryDC	dc;
+
+	Set_Buisy_Cursor(true);
+
+	nx		= m_Img_Parms("NX")->asInt();
+	ny		= m_Img_Parms("NY")->asInt();
+	Frame	= m_Img_Parms("FR")->asInt();	if( Frame < 5 )	Frame	= 0;
+	r		= wxRect(0, 0, nx + 2 * Frame, ny + 2 * Frame);
+
+	BMP.Create(r.GetWidth(), r.GetHeight());
+	r.Deflate(Frame);
+	dc.SelectObject(BMP);
+	dc.SetBackground(*wxWHITE_BRUSH);
+	dc.Clear();
+
+	Draw_Map(dc, 1.0, r, false);
+	Draw_Frame(dc, r, Frame);
+
+	dc.SelectObject(wxNullBitmap);
+	BMP.SaveFile(file, (wxBitmapType)type);
+
+	if( m_Img_Parms("REF")->asBool() )
+	{
+		CSG_File	Stream;
+		wxFileName	fn(file);
+
+		switch( type )
+		{
+		default:					fn.SetExt(wxT("world"));	break;
+		case wxBITMAP_TYPE_BMP:		fn.SetExt(wxT("bpw"));		break;
+		case wxBITMAP_TYPE_GIF:		fn.SetExt(wxT("gfw"));		break;
+		case wxBITMAP_TYPE_JPEG:	fn.SetExt(wxT("jgw"));		break;
+		case wxBITMAP_TYPE_PNG:		fn.SetExt(wxT("pgw"));		break;
+		case wxBITMAP_TYPE_PCX:		fn.SetExt(wxT("pxw"));		break;
+		case wxBITMAP_TYPE_TIF:		fn.SetExt(wxT("tfw"));		break; 
+		}
+
+		if( Stream.Open(fn.GetFullPath().c_str(), SG_FILE_W, false) )
+		{
+			CSG_Rect	rWorld(Get_World(r));
+			double		d	= rWorld.Get_XRange() / r.GetWidth();
+
+			Stream.Printf(wxT("%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n"),
+				d, 0.0, 0.0,-d,
+				rWorld.Get_XMin() - Frame * d,
+				rWorld.Get_YMax() + Frame * d
+			);
+		}
+	}
+
+	if( m_Img_Parms("KML")->asBool() )
+	{
+		CSG_File	Stream;
+		wxFileName	fn(file);
+
+		fn.SetExt(wxT("kml"));
+
+		if( Stream.Open(fn.GetFullPath().c_str(), SG_FILE_W, false) )
+		{
+			CSG_Rect	rWorld(Get_World(r));
+			double		d	= rWorld.Get_XRange() / r.GetWidth();
+
+			fn.Assign(file);
+
+			Stream.Printf(SG_T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
+			Stream.Printf(SG_T("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"));
+			Stream.Printf(SG_T("  <Folder>\n"));
+			Stream.Printf(SG_T("    <name>Maps exported from SAGA</name>\n"));
+			Stream.Printf(SG_T("    <description>System for Automated Geoscientific Analyses - www.saga-gis.org</description>\n"));
+			Stream.Printf(SG_T("    <GroundOverlay>\n"));
+			Stream.Printf(SG_T("      <name>%s</name>\n")				, Get_Name().c_str());
+			Stream.Printf(SG_T("      <description>%s</description>\n")	, Get_Description().c_str());
+			Stream.Printf(SG_T("      <Icon>\n"));
+			Stream.Printf(SG_T("        <href>%s</href>\n")				, fn.GetFullName().c_str());
+			Stream.Printf(SG_T("      </Icon>\n"));
+			Stream.Printf(SG_T("      <LatLonBox>\n"));
+			Stream.Printf(SG_T("        <north>%f</north>\n")			, rWorld.Get_YMax() + Frame * d);
+			Stream.Printf(SG_T("        <south>%f</south>\n")			, rWorld.Get_YMin() - Frame * d);
+			Stream.Printf(SG_T("        <east>%f</east>\n")				, rWorld.Get_XMax() + Frame * d);
+			Stream.Printf(SG_T("        <west>%f</west>\n")				, rWorld.Get_XMin() - Frame * d);
+			Stream.Printf(SG_T("        <rotation>0.0</rotation>\n"));
+			Stream.Printf(SG_T("      </LatLonBox>\n"));
+			Stream.Printf(SG_T("    </GroundOverlay>\n"));
+			Stream.Printf(SG_T("  </Folder>\n"));
+			Stream.Printf(SG_T("</kml>\n"));
+		}
+	}
+
+	if( m_Img_Parms("LG")->asBool() && Get_Legend_Size(s, 1.0, m_Img_Parms("LZ")->asDouble()) )
+	{
+		wxFileName	fn(file);
+		file	= fn.GetName();
+		file.Append(wxT("_legend"));
+		fn.SetName(file);
+		file	= fn.GetFullPath();
+
+		BMP.Create(s.GetWidth(), s.GetHeight());
+		dc.SelectObject(BMP);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		Draw_Legend(dc, 1.0, m_Img_Parms("LZ")->asDouble(), wxPoint(0, 0));
+
+		dc.SelectObject(wxNullBitmap);
+		BMP.SaveFile(file, (wxBitmapType)type);
+	}
+
+	Set_Buisy_Cursor(false);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::SaveAs_PDF_Indexed(void)
+{
+	static CSG_Parameters	Parameters(NULL, LNG("[CAP] Save to PDF"), LNG(""), NULL, false);
+
+	//-----------------------------------------------------
+	if( Parameters.Get_Count() == 0 )
+	{
+		Parameters.Add_FilePath(
+			NULL	, "FILENAME"	, LNG("[FLD] PDF Document"),
+			LNG(""),
+			wxString::Format(
+				wxT("%s (*.pdf)|*pdf|")
+				wxT("%s|*.*"),
+				LNG("PDF Files"),
+				LNG("All Files")
+			), NULL, true, false
+		);
+
+		Parameters.Add_Choice(
+			NULL	, "PAPER_SIZE"	, LNG("[FLD] Paper Format"),
+			LNG(""),
+
+			CSG_String::Format(wxT("%s|%s|%s|%s|"),
+				LNG("A4 Portrait"),
+				LNG("A4 Landscape"),
+				LNG("A3 Portrait"),
+				LNG("A3 Landscape")
+			)
+		);
+
+		Parameters.Add_String(
+			NULL	, "NAME"		, LNG("[FLD] Title"),
+			LNG(""),
+			LNG("")
+		);
+
+		Parameters.Add_Shapes(
+			NULL	, "SHAPES"		, LNG("[FLD] Shapes"),
+			LNG(""),
+			PARAMETER_INPUT_OPTIONAL
+		);
+
+		Parameters.Add_Table_Field(
+			Parameters("SHAPES")	, "FIELD"		, LNG("[FLD] Attribute"),
+			LNG("")
+		);
+
+	//	Parameters.Add_Grid(
+	//		NULL	, "GRID"		, LNG("[FLD] Grid"),
+	//		LNG(""),
+	//		PARAMETER_INPUT_OPTIONAL
+	//	);
+
+		Parameters.Add_FilePath(
+			NULL	, "FILEICON"	, LNG("[FLD] Icon"),
+			LNG(""),
+
+			CSG_String::Format(wxT("%s|*.png;*.jpg|%s|*.png|%s|*.jpg|%s|*.*"),
+				LNG("All Recognised Files"),
+				LNG("PNG Files"),
+				LNG("JPG Files"),
+				LNG("All Files")
+			), NULL, false, false
+		);
+
+		Parameters.Add_Value(
+			NULL	, "ROUNDSCALE"	, LNG("[FLD] Round Scale"),
+			LNG(""),
+			PARAMETER_TYPE_Bool, true
+		);
+	}
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&Parameters) )
+	{
+		bool			bResult, bRoundScale;
+		int				iField;
+		CSG_String		Name, FileName, FileName_Icon, FilePath_Maps;
+		CSG_Rect		rOverview, rMap;
+		CSG_Shapes			*pShapes;
+	//	CSG_Grid			*pGrid;
+		CSG_Doc_PDF	PDF;
+
+		MSG_General_Add(wxString::Format(wxT("%s..."), LNG("[MSG] Save to PDF")), true, true);
+
+		bResult			= false;
+		Name			= Parameters("NAME")		->asString();	if( Name.Length() < 1 )	Name	=  LNG("Maps");
+		FileName		= Parameters("FILENAME")	->asString();
+		FileName_Icon	= Parameters("FILEICON")	->asString();
+		pShapes			= Parameters("SHAPES")		->asShapes();
+	//	pGrid			= Parameters("GRID")		->asGrid();
+		iField			= Parameters("FIELD")		->asInt();
+		bRoundScale		= Parameters("ROUNDSCALE")	->asBool();
+
+		switch( Parameters("PAPER_SIZE")->asInt() )
+		{
+		default:
+		case 0:	PDF.Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_PORTRAIT , Name);	break;	// A4 Portrait
+		case 1:	PDF.Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_LANDSCAPE, Name);	break;	// A4 Landscape
+		case 2:	PDF.Open(PDF_PAGE_SIZE_A3, PDF_PAGE_ORIENTATION_PORTRAIT , Name);	break;	// A3 Portrait
+		case 3:	PDF.Open(PDF_PAGE_SIZE_A3, PDF_PAGE_ORIENTATION_LANDSCAPE, Name);	break;	// A3 Landscape
+		}
+
+		//-------------------------------------------------
+		if( PDF.Is_Open() )
+		{
+			PDF.Layout_Set_Box_Space(5, false);
+
+			PDF.Layout_Add_Box(  0.0,   0.0, 100.0,  75.0, "MAP");
+			PDF.Layout_Add_Box(  0.0,  75.0,  50.0, 100.0, "DIVISIONS");
+			PDF.Layout_Add_Box( 50.0,  75.0,  60.0,  80.0, "ICON");
+			PDF.Layout_Add_Box( 60.0,  75.0, 100.0,  80.0, "TITLE");
+			PDF.Layout_Add_Box( 50.0,  80.0, 100.0, 100.0, "DESCRIPTION");
+
+			FilePath_Maps	= SG_File_Make_Path(SG_File_Get_Path(FileName), SG_File_Get_Name(FileName, false));
+			rOverview		= pShapes ? pShapes->Get_Extent() : Get_Extent();
+		//	rOverview		= pShapes ? pShapes->Get_Extent() : (pGrid ? pGrid->Get_Extent() : Get_Extent());
+
+			//---------------------------------------------
+		//	PDF.Draw_Text		(PDF.Layout_Get_Box("TITLE").Get_XMin(), PDF.Layout_Get_Box("TITLE").Get_YCenter(), LNG("This is a Test!!!"), 24);
+		//	PDF.Draw_Rectangle	(PDF.Layout_Get_Box("DIVISIONS"));
+		//	PDF.Draw_Grid		(PDF.Layout_Get_Box("DIVISIONS"), Parameters("GRID")->asGrid(), CSG_Colors(), 0.0, 0.0, 0, &rOverview);
+		//	PDF.Draw_Shapes		(PDF.Layout_Get_Box("DIVISIONS"), pShapes, PDF_STYLE_POLYGON_STROKE, SG_COLOR_GREEN, SG_COLOR_BLACK, 1, &rOverview);
+		//	PDF.Draw_Graticule	(PDF.Layout_Get_Box("DIVISIONS"), rOverview);
+
+			//---------------------------------------------
+			Draw_PDF(&PDF, FilePath_Maps, -1, FileName_Icon, Name, rOverview, bRoundScale, iField, pShapes);
+
+			if( pShapes )
+			{
+				for(int i=0; i<pShapes->Get_Count() && SG_UI_Process_Set_Progress(i, pShapes->Get_Count()); i++)
+				{
+					Draw_PDF(&PDF, FilePath_Maps, i, FileName_Icon, Name, pShapes->Get_Shape(i)->Get_Extent(), bRoundScale, iField, pShapes);
+				}
+			}
+
+			//---------------------------------------------
+			PROCESS_Set_Okay(true);
+			Set_Buisy_Cursor(true);
+			bResult	= PDF.Save(FileName);
+			Set_Buisy_Cursor(false);
+		}
+
+		MSG_General_Add(bResult ? LNG("[MSG] okay") : LNG("[MSG] failed"), false, false, bResult ? SG_UI_MSG_STYLE_SUCCESS : SG_UI_MSG_STYLE_FAILURE);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Draw_PDF(CSG_Doc_PDF *pPDF, const wxChar *FilePath_Maps, int Image_ID, const wxChar *FileName_Icon, const wxChar *Title, CSG_Rect rWorld, bool bRoundScale, int iField, CSG_Shapes *pShapes)
+{
+	int			FrameSize_1	= 20, FrameSize_2	= 10;
+	double		d, e, Scale, Ratio;
+	CSG_String	FileName, Description, s;
+	CSG_Rect	rBox;
+	wxRect		rBMP;
+	wxBitmap	BMP;
+	wxMemoryDC	dc;
+
+	if( pPDF && rWorld.Get_XRange() > 0.0 && rWorld.Get_YRange() > 0.0 && pPDF->Add_Page() )
+	{
+		rWorld.Inflate(5.0, true);
+
+		//-------------------------------------------------
+		rBox	= pPDF->Layout_Get_Box("MAP");
+		rBox.Deflate(FrameSize_1, false);
+
+		rBMP	= wxRect(0, 0, (int)rBox.Get_XRange(), (int)rBox.Get_YRange());
+		BMP.Create(rBMP.GetWidth(), rBMP.GetHeight());
+		dc.SelectObject(BMP);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		if( bRoundScale )
+		{
+			Scale	= rWorld.Get_XRange() / (pPDF->Get_Page_To_Meter() * (double)rBMP.GetWidth());
+
+		//	if( Scale > 1000 )
+		//	{
+				Ratio	= ((ceil(Scale / 1000.)) / (Scale / 1000.) - 1);
+				rWorld.Inflate(Ratio * 100, true);
+		//	}
+		}
+
+		Scale	= rWorld.Get_XRange() / (pPDF->Get_Page_To_Meter() * rBMP.GetWidth());
+
+		Draw_Map(dc, rWorld, 1.0, rBMP, false);
+		dc.SelectObject(wxNullBitmap);
+		SG_Dir_Create(FilePath_Maps);
+		FileName	= SG_File_Make_Path(FilePath_Maps, wxString::Format(wxT("image_%03d"), Image_ID + 1), wxT("png"));
+		BMP.SaveFile(FileName.c_str(), wxBITMAP_TYPE_PNG);
+
+		pPDF->Draw_Image	(rBox, FileName);
+		pPDF->Draw_Graticule(rBox, rWorld, FrameSize_1);
+
+		//-------------------------------------------------
+		rBox	= pPDF->Layout_Get_Box("ICON");
+
+		if( FileName_Icon )
+		{
+			pPDF->Draw_Image(rBox, FileName_Icon);
+		}
+		else
+		{
+			pPDF->Draw_Rectangle(rBox);
+		}
+
+		//-------------------------------------------------
+		rBox	= pPDF->Layout_Get_Box("DIVISIONS");
+
+		pPDF->Draw_Rectangle(rBox);
+
+		if( pShapes )
+		{
+			CSG_Rect	rShapes(pShapes->Get_Extent());
+
+			rShapes.Inflate(5.0, true);
+			rBox.Deflate(FrameSize_2, false);
+
+			pPDF->Draw_Graticule(rBox, rShapes, FrameSize_2);
+			pPDF->Draw_Shapes(rBox, pShapes, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_GREEN, SG_COLOR_BLACK, 0, &rShapes);
+
+			if( Image_ID >= 0 && Image_ID < pShapes->Get_Count() )
+			{
+				pPDF->Draw_Shape(rBox, pShapes->Get_Shape(Image_ID), PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_YELLOW, SG_COLOR_RED, 1, &rShapes);
+			}
+		}
+
+		//-------------------------------------------------
+		rBox	= pPDF->Layout_Get_Box("TITLE");
+
+		pPDF->Draw_Text(rBox.Get_XMin(), rBox.Get_YCenter(), Title, 20, PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_CENTER|PDF_STYLE_TEXT_UNDERLINE);
+
+		//-------------------------------------------------
+		rBox	= pPDF->Layout_Get_Box("DESCRIPTION");
+
+		Description.Append(wxString::Format(wxT("%d. %s\n"), Image_ID + 2, LNG("Map")));
+
+		if( pShapes && Image_ID >= 0 && Image_ID < pShapes->Get_Count() )
+		{
+			switch( pShapes->Get_Type() )
+			{
+			default:
+				break;
+
+			case SHAPE_TYPE_Line:
+				d	= ((CSG_Shape_Line    *)pShapes->Get_Shape(Image_ID))->Get_Length();
+				e	= d > 1000.0 ? 1000.0    : 1.0;
+				s	= d > 1000.0 ? wxT("km") : wxT("m");
+				Description.Append(wxString::Format(wxT("%s: %f%s\n"), LNG("Length")	, d / e, s.c_str()));
+				break;
+
+			case SHAPE_TYPE_Polygon:
+				d	= ((CSG_Shape_Polygon *)pShapes->Get_Shape(Image_ID))->Get_Area();
+				e	= d > 1000000.0 ? 1000000.0  : (d > 10000.0 ? 10000.0   : 1.0);
+				s	= d > 1000000.0 ? wxT("km\xc2\xb2") : (d > 10000.0 ? wxT("ha") : wxT("m\xc2\xb2"));
+				Description.Append(wxString::Format(wxT("%s: %f%s\n"), LNG("Area")		, d / e, s.c_str()));
+
+				d	= ((CSG_Shape_Polygon *)pShapes->Get_Shape(Image_ID))->Get_Perimeter();
+				e	= d > 1000.0 ? 1000.0    : 1.0;
+				s	= d > 1000.0 ? wxT("km") : wxT("m");
+				Description.Append(wxString::Format(wxT("%s: %f%s\n"), LNG("Perimeter")	, d / e, s.c_str()));
+
+				Description.Append(wxString::Format(wxT("%s: %d\n")  , LNG("Parts")		, ((CSG_Shape_Polygon *)pShapes->Get_Shape(Image_ID))->Get_Part_Count()));
+				break;
+			}
+
+			if( iField >= 0 && iField < pShapes->Get_Field_Count() )
+			{
+				Description.Append(wxString::Format(wxT("%s: %s\n"), pShapes->Get_Field_Name(iField), pShapes->Get_Shape(Image_ID)->asString(iField)));
+			}
+		}
+
+		Description.Append(wxString::Format(wxT("%s 1:%s"), LNG("Scale"), SG_Get_String(Scale, 2).c_str()));
+
+		pPDF->Draw_Text(rBox.Get_XMin(), rBox.Get_YMax(), Description, 12, PDF_STYLE_TEXT_ALIGN_H_LEFT|PDF_STYLE_TEXT_ALIGN_V_TOP);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::SaveAs_Interactive_SVG(void)
+{
+	static CSG_Parameters	Parameters(NULL, LNG("[CAP] Save As Interactive SVG"), LNG(""), NULL, false);
+
+	//-----------------------------------------------------
+	if( Parameters.Get_Count() == 0 )
+	{
+		Parameters.Add_FilePath(
+			NULL	, "FILENAME"	, LNG("[FLD] SVG File"),
+			LNG(""),
+			wxString::Format(wxT("%s|*.svg|%s|*.*"),
+				LNG("SVG - Scalable Vector Graphics Files (*.svg)"),
+				LNG("All Files")
+			), NULL, true, false
+		);
+
+		Parameters.Add_Shapes(
+			NULL	, "SHAPES"		, LNG("[FLD] Index Layer"),
+			LNG(""),
+			PARAMETER_INPUT_OPTIONAL
+		);
+	}
+
+	//-----------------------------------------------------
+	if( DLG_Parameters(&Parameters) )
+	{
+		CSG_String				FileName;
+		CSG_Shapes					*pIndexLayer;
+		CSVG_Interactive_Map	SVG;
+
+		MSG_General_Add(wxString::Format(wxT("%s..."), LNG("[MSG] Save as Interactive SVG")), true, true);
+
+		pIndexLayer		= Parameters("SHAPES")		->asShapes();
+		FileName		= Parameters("FILENAME")	->asString();
+
+		SVG.Create_From_Map(this, pIndexLayer, FileName);
+
+		MSG_General_Add(LNG("[MSG] okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+const wxBitmap & CWKSP_Map::Get_Thumbnail(int dx, int dy)
+{
+	if( dx > 0 && m_Thumbnail.GetWidth()  != dx
+	&&	dy > 0 && m_Thumbnail.GetHeight() != dy )
+	{
+		m_Thumbnail.Create(dx, dy);
+
+		_Set_Thumbnail();
+	}
+
+	return( m_Thumbnail );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::_Set_Thumbnail(void)
+{
+	if( m_Thumbnail.GetWidth() > 0 && m_Thumbnail.GetHeight() > 0 )
+	{
+		wxMemoryDC		dc;
+		wxRect			r(0, 0, m_Thumbnail.GetWidth(), m_Thumbnail.GetHeight());
+
+		dc.SelectObject(m_Thumbnail);
+		dc.SetBackground(*wxWHITE_BRUSH);
+		dc.Clear();
+
+		Draw_Map(dc, Get_Extent(), 1.0, r, false);
+
+		dc.SelectObject(wxNullBitmap);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map::Draw_Map(wxDC &dc, double Zoom, const wxRect &rClient, bool bEdit, int Background)
+{
+	Draw_Map(dc, Get_World(rClient), Zoom, rClient, bEdit, Background);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Draw_Map(wxDC &dc, const CSG_Rect &rWorld, double Zoom, const wxRect &rClient, bool bEdit, int Background)
+{
+	CWKSP_Map_DC	dc_Map(rWorld, rClient, Zoom, Background);
+
+	for(int i=Get_Count()-1; i>=0; i--)
+	{
+		if( Get_Layer(i)->do_Show() && Get_Layer(i)->Get_Layer()->do_Show(Get_Extent()) )
+		{
+			Get_Layer(i)->Get_Layer()->Draw(dc_Map, bEdit && Get_Layer(i)->Get_Layer() == Get_Active_Layer());
+		}
+	}
+
+	dc_Map.Draw(dc);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map::Draw_Frame(wxDC &dc, wxRect rMap, int Width)
+{
+	Draw_Frame(dc, Get_World(rMap), rMap, Width);
+}
+
+void CWKSP_Map::Draw_Frame(wxDC &dc, const CSG_Rect &rWorld, wxRect rMap, int Width)
+{
+	wxRect		r, rFrame(rMap);
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, rMap.GetLeft(), rMap.GetTop(), rMap.GetRight(), rMap.GetBottom());
+
+	rFrame.Inflate(Width);
+
+	r		= wxRect(rMap.GetLeft()    , rFrame.GetTop()    , rMap.GetWidth(), Width);
+	Draw_Scale(dc, r, rWorld.Get_XMin(), rWorld.Get_XMax()  , true , true , false);
+
+	r		= wxRect(rMap.GetLeft()    , rMap.GetBottom()   , rMap.GetWidth(), Width);
+	Draw_Scale(dc, r, 0.0              , rWorld.Get_XRange(), true , true , true);
+
+	r		= wxRect(rFrame.GetLeft()  , rMap.GetTop()      , Width, rMap.GetHeight());
+	Draw_Scale(dc, r, rWorld.Get_YMin(), rWorld.Get_YMax()  , false, false, false);
+
+	r		= wxRect(rMap.GetRight()   , rMap.GetTop()      , Width, rMap.GetHeight());
+	Draw_Scale(dc, r, 0.0              , rWorld.Get_YRange(), false, false, true);
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE, rFrame.GetLeft(), rFrame.GetTop(), rFrame.GetRight(), rFrame.GetBottom());
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::Draw_Legend(wxDC &dc, double Zoom_Map, double Zoom, wxPoint Position, wxSize *pSize, int Layout)
+{
+	bool	bVertical;
+	int		i, n;
+	wxSize	s, Size;
+
+	Size.x		= 0;
+	Size.y		= 0;
+
+	bVertical	= (Layout & LEGEND_LAYOUT_VERTICAL) != 0;
+
+	for(i=0, n=0; i<Get_Count(); i++)
+	{
+		if( Get_Layer(i)->Get_Layer()->do_Legend() )
+		{
+			n++;
+
+			Get_Layer(i)->Get_Layer()->Get_Legend()->Draw(dc, Zoom, Zoom_Map, Position, &s, bVertical);
+
+			if( bVertical )
+			{
+				s.y			+= (int)(Zoom * LEGEND_SPACE);
+				Position.y	+= s.y;
+				Size.y		+= s.y;
+
+				if( Size.x < s.x )
+					Size.x	= s.x;
+			}
+			else
+			{
+				s.x			+= (int)(Zoom * LEGEND_SPACE);
+				Position.x	+= s.x;
+				Size.x		+= s.x;
+
+				if( Size.y < s.y )
+					Size.y	= s.y;
+			}
+		}
+	}
+
+	if( pSize )
+	{
+		*pSize	= Size;
+	}
+
+	return( n > 0 );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map::Get_Legend_Size(wxSize &Size, double Zoom_Map, double Zoom, int Layout)
+{
+	wxMemoryDC	dc;
+
+	return( Draw_Legend(dc, Zoom_Map, Zoom, wxPoint(0, 0), &Size, Layout) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,253 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WKSP_Map.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define LEGEND_LAYOUT_HORIZONTAL	0x01
+#define LEGEND_LAYOUT_VERTICAL		0x02
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map_Extents : public CSG_Rects
+{
+public:
+	CWKSP_Map_Extents(void);
+
+	bool						is_First				(void)		{	return( m_iExtent <= 0 );				}
+	bool						is_Last					(void)		{	return( m_iExtent >= m_nExtents - 1 );	}
+
+	CSG_Rect					Set_Back				(void);
+	CSG_Rect					Set_Forward				(void);
+
+	bool						Add_Extent				(const CSG_Rect &Extent, bool bReset = false);
+	const CSG_Rect &			Get_Extent				(void)		{	return( m_iExtent >= 0 ? Get_Rect(m_iExtent) : m_Dummy );	}
+
+
+private:
+
+	int							m_iExtent, m_nExtents;
+
+	static CSG_Rect				m_Dummy;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Map(void);
+	virtual ~CWKSP_Map(void);
+
+	virtual TWKSP_Item			Get_Type				(void)		{	return( WKSP_ITEM_Map );	}
+
+	virtual wxString			Get_Name				(void);
+	virtual wxString			Get_Description			(void);
+
+	virtual wxMenu *			Get_Menu(void);
+
+	virtual bool				On_Command				(int Cmd_ID);
+	virtual bool				On_Command_UI			(wxUpdateUIEvent &event);
+
+	virtual CSG_Parameters *	Get_Parameters			(void)		{	return( &m_Parameters );	}
+	virtual void				Parameters_Changed		(void);
+
+	const CSG_Rect &			Get_Extent				(void)		{	return( m_Extents.Get_Extent() );	}
+	void						Set_Extent				(const CSG_Rect &Extent, bool bReset = false);
+	void						Set_Extent				(void);
+	void						Set_Extent_Full			(void);
+	void						Set_Extent_Active		(void);
+	void						Set_Extent_Selection	(void);
+	bool						Set_Extent_Back			(bool bCheck_Only = false);
+	bool						Set_Extent_Forward		(bool bCheck_Only = false);
+
+	void						Set_Synchronising		(bool bOn);
+	bool						is_Synchronising		(void)	{	return( m_bSynchronise );	}
+
+	bool						is_Image_Save_Mode		(void)	{	return( m_Img_bSave );		}
+
+	class CWKSP_Map_Layer *		Add_Layer				(class CWKSP_Layer *pLayer);
+	int							Get_Layer				(class CWKSP_Layer *pLayer);
+	class CWKSP_Map_Layer *		Get_Layer				(int i)		{	return( (class CWKSP_Map_Layer *)Get_Item(i) );	}
+	bool						Update					(class CWKSP_Layer *pLayer, bool bMapOnly);
+	class CWKSP_Map_Layer *		Find_Layer				(class CWKSP_Layer *pLayer);
+
+	void						On_Delete				(class CWKSP_Map_Layer *pLayer);
+
+	void						View_Closes				(class wxMDIChildFrame *pView);
+	void						View_Refresh			(bool bMapOnly);
+	class CVIEW_Map *			View_Get				(void)		{	return( m_pView );		}
+	void						View_Show				(bool bShow);
+	void						View_Toggle				(void);
+	class CVIEW_Map_3D *		View_3D_Get				(void)		{	return( m_pView_3D );	}
+	void						View_3D_Show			(bool bShow);
+	void						View_3D_Toggle			(void);
+	class CVIEW_Layout *		View_Layout_Get			(void)		{	return( m_pLayout );	}
+	void						View_Layout_Show		(bool bShow);
+	void						View_Layout_Toggle		(void);
+
+	CSG_Rect					Get_World				(wxRect rClient);
+	CSG_Point					Get_World				(wxRect rClient, wxPoint ptClient);
+
+	bool						Get_Image				(wxImage &Image, CSG_Rect &rWorld);
+	void						SaveAs_Image			(void);
+	void						SaveAs_Image_Clipboard	(int nx, int ny, int frame);
+	void						SaveAs_Image_Clipboard	(bool bLegend = false);
+	void						SaveAs_Image_On_Change	(void);
+	void						SaveAs_PDF_Indexed		(void);
+	void						SaveAs_Interactive_SVG	(void);
+
+	void						Draw_PDF				(class CSG_Doc_PDF *pPDF, const wxChar *FilePath_Maps, int Image_ID, const wxChar *Icon_File, const wxChar *sTitle, CSG_Rect rWorld, bool bRoundScale, int iField, CSG_Shapes *m_pDivisions);
+
+	void						Draw_Map				(wxDC &dc, double Zoom, const wxRect &rClient, bool bEdit, int Background = SG_COLOR_WHITE);
+	void						Draw_Map				(wxDC &dc, const CSG_Rect &rWorld, double Zoom, const wxRect &rClient, bool bEdit, int Background = SG_COLOR_WHITE);
+	void						Draw_Frame				(wxDC &dc, wxRect rMap, int Width);
+	void						Draw_Frame				(wxDC &dc, const CSG_Rect &rWorld, wxRect rMap, int Width);
+	bool						Draw_Legend				(wxDC &dc, double Zoom_Map, double Zoom, wxPoint Position, wxSize *pSize = NULL, int Layout = LEGEND_LAYOUT_VERTICAL);
+
+	const wxBitmap &			Get_Thumbnail			(int dx, int dy);
+
+	bool						Get_Legend_Size			(wxSize &Size, double Zoom_Map = 1.0, double Zoom = 1.0, int Layout = LEGEND_LAYOUT_VERTICAL);
+
+	int							Get_Frame_Width			(void);
+	int							Get_Print_Resolution	(void);
+	int							Get_Print_Frame			(void);
+	int							Get_Print_Legend		(void);
+
+
+private:
+
+	bool						m_bSynchronise, m_Img_bSave;
+
+	int							m_Img_Type, m_Img_Count;
+
+	wxString					m_Name, m_Img_File;
+
+	wxBitmap					m_Thumbnail;
+
+	CSG_Parameters				m_Parameters, m_Img_Parms;
+
+	CWKSP_Map_Extents			m_Extents;
+
+	class CVIEW_Map				*m_pView;
+
+	class CVIEW_Map_3D			*m_pView_3D;
+
+	class CVIEW_Layout			*m_pLayout;
+
+	class CVIEW_Layout_Info		*m_pLayout_Info;
+
+
+	void						_Create_Parameters		(void);
+	static int					_On_Parameter_Changed	(CSG_Parameter *pParameter);
+	int							On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	void						_Set_Extent				(const CSG_Rect &Extent);
+	void						_Synchronise_Extents	(void);
+
+	void						_Img_Save				(wxString file, int type);
+	void						_Img_Save_On_Change		(void);
+
+	bool						_Set_Thumbnail			(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,512 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 wksp_map_buttons.cpp                  //
+//                                                       //
+//          Copyright (C) 2006 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "active.h"
+
+#include "wksp_map_control.h"
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+
+#include "wksp_map_buttons.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SCROLL_RATE		5
+
+#define SCROLL_BAR_DX	wxSystemSettings::GetMetric(wxSYS_VSCROLL_X)
+#define SCROLL_BAR_DY	wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y)
+
+//---------------------------------------------------------
+#define THUMBNAIL_SIZE	75
+#define THUMBNAIL_DIST	5
+
+#define TITLE_FONT		wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Buttons	*g_pMap_Buttons	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Map_Button, wxPanel)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Map_Button, wxPanel)
+	EVT_PAINT			(CWKSP_Map_Button::On_Paint)
+	EVT_LEFT_DOWN		(CWKSP_Map_Button::On_Mouse_LDown)
+	EVT_LEFT_DCLICK		(CWKSP_Map_Button::On_Mouse_LDClick)
+	EVT_RIGHT_DOWN		(CWKSP_Map_Button::On_Mouse_RDown)
+END_EVENT_TABLE()
+
+//---------------------------------------------------------
+CWKSP_Map_Button::CWKSP_Map_Button(wxWindow *pParent, class CWKSP_Map *pMap)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER)
+{
+	m_pMap		= pMap;
+	m_Title		= pMap->Get_Name();
+}
+
+//---------------------------------------------------------
+CWKSP_Map_Button::CWKSP_Map_Button(wxWindow *pParent, const wxChar *Title)
+	: wxPanel(pParent, -1, wxDefaultPosition, wxDefaultSize, 0)
+{
+	m_pMap		= NULL;
+	m_Title		= Title;
+
+	int			x, y, d, e;
+	wxClientDC	dc(this);
+	wxFont		Font(TITLE_FONT);
+	dc.GetTextExtent(m_Title, &x, &y, &d, &e, &Font);
+	SetSize(-1, -1, x + 4, y + d + e + 4);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Button::On_Paint(wxPaintEvent &event)
+{
+	wxPaintDC	dc(this);
+	wxRect		r(wxPoint(0, 0), GetClientSize());
+
+	if( m_pMap )
+	{
+		if( g_pMaps->Exists(m_pMap) )
+		{
+			SetToolTip(m_pMap->Get_Name());
+
+			dc.DrawBitmap(m_pMap->Get_Thumbnail(r.GetWidth() - 1, r.GetHeight() - 1), r.GetLeft(), r.GetTop(), true);
+
+			if( g_pACTIVE->Get_Item() == m_pMap )
+			{
+				dc.SetPen(wxPen(((CWKSP_Map_Buttons *)GetParent())->Get_Active_Color()));
+				Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);	r.Deflate(1);
+				Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);	r.Deflate(1);
+				Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);
+			}
+		}
+	}
+	else
+	{
+		dc.DrawLine(0, 0, r.GetWidth(), 0);
+		dc.DrawLine(0, 1, r.GetWidth(), 1);
+		dc.SetFont(TITLE_FONT);
+		dc.DrawText(m_Title, 2, 2);
+		dc.DrawLine(0, r.GetBottom(), GetClientSize().x, r.GetBottom());
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Button::_Set_Layer_Active(void)
+{
+	if( m_pMap && g_pMaps->Exists(m_pMap) )
+	{
+		g_pMap_Ctrl->Set_Item_Selected(m_pMap);
+
+		return( true );
+	}
+
+	m_pMap	= NULL;
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Button::On_Mouse_LDown(wxMouseEvent &event)
+{
+	_Set_Layer_Active();
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Button::On_Mouse_LDClick(wxMouseEvent &event)
+{
+	if( _Set_Layer_Active() )
+	{
+		m_pMap->On_Command(ID_CMD_WKSP_ITEM_RETURN);
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Button::On_Mouse_RDown(wxMouseEvent &event)
+{
+	if( _Set_Layer_Active() )
+	{
+		wxMenu	*pMenu;
+
+		if( (pMenu = m_pMap->Get_Menu()) != NULL )
+		{
+			GetParent()->PopupMenu(pMenu, GetParent()->ScreenToClient(ClientToScreen(event.GetPosition())));
+
+			delete(pMenu);
+
+			return;
+		}
+	}
+
+	event.Skip();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Map_Buttons, wxScrolledWindow)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Map_Buttons, wxScrolledWindow)
+	EVT_RIGHT_DOWN		(CWKSP_Map_Buttons::On_Mouse_RDown)
+	EVT_SIZE			(CWKSP_Map_Buttons::On_Size)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Buttons::CWKSP_Map_Buttons(wxWindow *pParent)
+	: wxScrolledWindow(pParent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE)
+{
+	g_pMap_Buttons	= this;
+
+	m_xScroll		= 0;
+	m_yScroll		= 0;
+
+	m_Items			= NULL;
+	m_nItems		= 0;
+
+	//-----------------------------------------------------
+	long	lValue;
+
+	m_Size			= CONFIG_Read(wxT("/BUTTONS_MAPS"), wxT("SIZE")		, lValue) ? (int)lValue : 75;
+	m_Active_Color	= CONFIG_Read(wxT("/BUTTONS_MAPS"), wxT("SELCOLOR")	, lValue) ?      lValue : Get_Color_asInt(SYS_Get_Color(wxSYS_COLOUR_BTNSHADOW));
+
+	//-----------------------------------------------------
+	m_Parameters.Create(this, LNG("Options for Map Thumbnails"), LNG(""));
+
+	m_Parameters.Add_Value(
+		NULL, "SIZE"		, LNG("Thumbnail Size"),
+		LNG(""),
+		PARAMETER_TYPE_Int, m_Size, 10, true
+	);
+
+	m_Parameters.Add_Value(
+		NULL, "SELCOLOR"	, LNG("Selection Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, m_Active_Color
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Map_Buttons::~CWKSP_Map_Buttons(void)
+{
+	CONFIG_Write(wxT("/BUTTONS_MAPS"), wxT("SIZE")    , (long)m_Parameters("SIZE")    ->asInt());
+	CONFIG_Write(wxT("/BUTTONS_MAPS"), wxT("SELCOLOR"),       m_Parameters("SELCOLOR")->asColor());
+
+	_Del_Items();
+
+	g_pMap_Buttons	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_Buttons::On_Mouse_RDown(wxMouseEvent &event)
+{
+	if( DLG_Parameters(&m_Parameters) )
+	{
+		m_Size			= m_Parameters("SIZE")		->asInt();
+		m_Active_Color	= m_Parameters("SELCOLOR")	->asColor();
+
+		Update_Buttons();
+	}
+
+	event.Skip();
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Buttons::On_Size(wxSizeEvent &event)
+{
+	_Set_Positions();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_Buttons::Update_Buttons(void)
+{
+	Freeze();
+
+	_Del_Items();
+	_Add_Items(g_pMaps);
+
+	Scroll(0, 0);
+
+	_Set_Positions();
+
+	Thaw();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_Buttons::_Set_Positions(void)
+{
+	int		xSize, ySize, xPos, yPos, xAdd, yAdd, i, x, y;
+
+	xSize	= GetClientSize().x - SCROLL_BAR_DX;
+
+	if( xSize < m_Size + THUMBNAIL_DIST )
+	{
+		xSize	= m_Size + THUMBNAIL_DIST;
+	}
+
+	xPos	= THUMBNAIL_DIST;
+	yPos	= THUMBNAIL_DIST;
+	xAdd	= 0;
+	yAdd	= 0;
+
+	for(i=0; i<m_nItems; i++)
+	{
+		CWKSP_Map_Button	*pItem	= m_Items[i];
+
+		if( pItem->is_Title() )
+		{
+			xPos	 = THUMBNAIL_DIST;
+			yPos	+= THUMBNAIL_DIST + yAdd;
+
+			CalcScrolledPosition(0, yPos, &x, &y);
+			pItem->SetSize(x, y, xSize + SCROLL_BAR_DX, -1);
+
+			yPos	+= THUMBNAIL_DIST + pItem->GetSize().y;
+			yAdd	 = 0;
+		}
+		else
+		{
+			xAdd	= m_Size;
+
+			if( xPos + xAdd >= xSize )
+			{
+				xPos	 = THUMBNAIL_DIST;
+				yPos	+= yAdd;
+				yAdd	 = THUMBNAIL_DIST + m_Size;
+			}
+
+			yAdd	= m_Size + THUMBNAIL_DIST;
+
+			CalcScrolledPosition(xPos, yPos, &x, &y);
+			pItem->SetSize(x, y, m_Size, m_Size);
+
+			xPos	+= THUMBNAIL_DIST + xAdd;
+		}
+	}
+
+	xSize	+= SCROLL_BAR_DX;
+	ySize	 = SCROLL_BAR_DY + yPos + yAdd;
+
+	if(	m_xScroll != xSize || m_yScroll != ySize )
+	{
+		m_xScroll	= xSize;
+		m_yScroll	= ySize;
+
+		SetScrollbars(SCROLL_RATE, SCROLL_RATE, m_xScroll / SCROLL_RATE, m_yScroll / SCROLL_RATE);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map_Buttons::_Add_Items(CWKSP_Base_Item *pItem)
+{
+	if( pItem )
+	{
+		switch( pItem->Get_Type() )
+		{
+		default:
+			return( false );
+
+		case WKSP_ITEM_Map:
+			return( _Add_Item((CWKSP_Map *)pItem) );
+
+		case WKSP_ITEM_Map_Manager:
+			break;
+		}
+
+		for(int i=0; i<((CWKSP_Base_Manager *)pItem)->Get_Count(); i++)
+		{
+			_Add_Items(((CWKSP_Base_Manager *)pItem)->Get_Item(i));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Buttons::_Add_Item(CWKSP_Map *pMap)
+{
+	if( pMap )
+	{
+		m_Items	= (CWKSP_Map_Button **)SG_Realloc(m_Items, (m_nItems + 1) * sizeof(CWKSP_Map_Button *));
+		m_Items[m_nItems++]	= new CWKSP_Map_Button(this, pMap);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Buttons::_Add_Item(const wxChar *Title)
+{
+	if( Title )
+	{
+		m_Items	= (CWKSP_Map_Button **)SG_Realloc(m_Items, (m_nItems + 1) * sizeof(CWKSP_Map_Button *));
+		m_Items[m_nItems++]	= new CWKSP_Map_Button(this, Title);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Buttons::_Del_Items(void)
+{
+	if( m_nItems > 0 )
+	{
+		for(int i=0; i<m_nItems; i++)
+		{
+			delete(m_Items[i]);
+		}
+
+		SG_Free(m_Items);
+	}
+
+	m_Items		= NULL;
+	m_nItems	= 0;
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_buttons.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,169 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  wksp_map_buttons.h                   //
+//                                                       //
+//          Copyright (C) 2006 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__wksp_map_buttons_H
+#define _HEADER_INCLUDED__SAGA_GUI__wksp_map_buttons_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/scrolwin.h>
+
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map_Button : public wxPanel
+{
+	DECLARE_CLASS(CWKSP_Map_Button)
+
+public:
+	CWKSP_Map_Button(wxWindow *pParent, class CWKSP_Map *pMap);
+	CWKSP_Map_Button(wxWindow *pParent, const wxChar *Title);
+	virtual ~CWKSP_Map_Button(void)	{}
+
+	void						On_Paint			(wxPaintEvent &event);
+
+	void						On_Mouse_LDown		(wxMouseEvent &event);
+	void						On_Mouse_LDClick	(wxMouseEvent &event);
+	void						On_Mouse_RDown		(wxMouseEvent &event);
+
+	bool						is_Title			(void)		{	return( m_pMap == NULL );	}
+
+
+private:
+
+	wxString					m_Title;
+
+	class CWKSP_Map				*m_pMap;
+
+
+	bool						_Set_Layer_Active	(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+class CWKSP_Map_Buttons : public wxScrolledWindow
+{
+	DECLARE_CLASS(CWKSP_Map_Buttons)
+
+public:
+	CWKSP_Map_Buttons(wxWindow *pParent);
+	virtual ~CWKSP_Map_Buttons(void);
+
+	void						On_Mouse_RDown		(wxMouseEvent &event);
+
+	void						On_Size				(wxSizeEvent  &event);
+
+	void						Update_Buttons		(void);
+
+	int							Get_Item_Size		(void)		{	return( m_Size );	}
+	long						Get_Active_Color	(void)		{	return( m_Active_Color );	}
+
+
+private:
+
+	int							m_xScroll, m_yScroll, m_nItems, m_Size;
+
+	long						m_Active_Color;
+
+	CWKSP_Map_Button			**m_Items;
+
+	CSG_Parameters				m_Parameters;
+
+
+	void						_Set_Positions		(void);
+
+	bool						_Add_Items			(class CWKSP_Base_Item *pItem);
+	bool						_Add_Item			(class CWKSP_Map *pMap);
+	bool						_Add_Item			(const wxChar *Title);
+	bool						_Del_Items			(void);
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CWKSP_Map_Buttons		*g_pMap_Buttons;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__wksp_map_buttons_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,364 @@
+	
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Map_Control.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+#include <wx/imaglist.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "wksp_map_control.h"
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+#include "wksp_map_buttons.h"
+
+#include "wksp_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_MAP_MANAGER		= 1,
+	IMG_MAP,
+
+	IMG_SHAPES_POINT,
+	IMG_SHAPES_POINTS,
+	IMG_SHAPES_LINE,
+	IMG_SHAPES_POLYGON,
+	IMG_TIN,
+	IMG_POINTCLOUD,
+	IMG_GRID
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Map_Control, CWKSP_Base_Control)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Map_Control, CWKSP_Base_Control)
+	EVT_TREE_BEGIN_DRAG		(ID_WND_WKSP_MAPS, CWKSP_Map_Control::On_Drag_Begin)
+	EVT_TREE_END_DRAG		(ID_WND_WKSP_MAPS, CWKSP_Map_Control::On_Drag_End)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Control	*g_pMap_Ctrl	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Control::CWKSP_Map_Control(wxWindow *pParent)
+	: CWKSP_Base_Control(pParent, ID_WND_WKSP_MAPS)
+{
+	g_pMap_Ctrl	= this;
+
+	//-----------------------------------------------------
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MAP_MANAGER);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MAP);
+
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINT);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POINTS);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_LINE);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_SHAPES_POLYGON);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_TIN);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_POINTCLOUD);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_GRID);
+
+	//-----------------------------------------------------
+	_Set_Manager(new CWKSP_Map_Manager);
+}
+
+//---------------------------------------------------------
+CWKSP_Map_Control::~CWKSP_Map_Control(void)
+{
+	_Del_Item(m_pManager, true);
+
+	g_pMap_Ctrl	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Map_Control::OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2)
+{
+	CWKSP_Base_Item	*p1, *p2;
+
+	if(	(p1 = (CWKSP_Base_Item *)GetItemData(item1)) != NULL && p1->Get_Type() == WKSP_ITEM_Map_Layer
+	&&	(p2 = (CWKSP_Base_Item *)GetItemData(item2)) != NULL && p2->Get_Type() == WKSP_ITEM_Map_Layer )
+	{
+		return( p1->Get_Index() - p2->Get_Index() );
+	}
+
+	return( wxTreeCtrl::OnCompareItems(item1, item2) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline int CWKSP_Map_Control::_Get_Image_ID(CWKSP_Base_Item *pItem)
+{
+	if( pItem && pItem->Get_Type() == WKSP_ITEM_Map_Layer )
+	{
+		pItem	= ((CWKSP_Map_Layer *)pItem)->Get_Layer();
+
+		switch( pItem->Get_Type() )
+		{
+		default:
+			break;
+
+		case WKSP_ITEM_Shapes:
+			switch( ((CWKSP_Shapes *)pItem)->Get_Shapes()->Get_Type() )
+			{
+			default:
+			case SHAPE_TYPE_Point:		return( IMG_SHAPES_POINT );
+			case SHAPE_TYPE_Points:		return( IMG_SHAPES_POINTS );
+			case SHAPE_TYPE_Line:		return( IMG_SHAPES_LINE );
+			case SHAPE_TYPE_Polygon:	return( IMG_SHAPES_POLYGON );
+			}
+
+		case WKSP_ITEM_TIN:				return( IMG_TIN );
+		case WKSP_ITEM_PointCloud:		return( IMG_POINTCLOUD );
+		case WKSP_ITEM_Grid:			return( IMG_GRID );
+		}
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Control::Add_Item(CWKSP_Base_Manager *pManager, CWKSP_Base_Item *pItem)
+{
+	if( pManager && pItem )
+	{
+		if( pManager == Get_Manager() )
+		{
+			_Add_Item(pItem, IMG_MAP, IMG_MAP);
+
+			return;
+		}
+
+		AppendItem	(pManager->GetId(), pItem->Get_Name(), _Get_Image_ID(pItem), _Get_Image_ID(pItem), pItem);
+		SortChildren(pManager->GetId());
+		Expand		(pManager->GetId());
+
+		if( g_pMap_Buttons )
+		{
+			g_pMap_Buttons->Update_Buttons();
+		}
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Control::Del_Item(CWKSP_Map *pMap, CWKSP_Layer *pLayer)
+{
+	CWKSP_Map_Layer	*pItem;
+
+	if( pMap && (pItem = pMap->Find_Layer(pLayer)) != NULL )
+	{
+		bool	bRefresh	= pMap->Get_Count() > 1;
+
+		_Del_Item(pItem, true);
+
+		if( bRefresh )
+		{
+			pMap->View_Refresh(false);
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_Control::On_Drag_Begin(wxTreeEvent &event)
+{
+	CWKSP_Base_Item	*pItem	= (CWKSP_Base_Item *)GetItemData(event.GetItem());
+
+	if( pItem && pItem->Get_Type() == WKSP_ITEM_Map_Layer )
+	{
+		m_draggedItem	= event.GetItem();
+
+		event.Allow();
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Control::On_Drag_End(wxTreeEvent &event)
+{
+	if( event.GetItem().IsOk() )
+	{
+		CWKSP_Map		*pDst_Map, *pSrc_Map;
+		CWKSP_Base_Item	*pSrc, *pDst, *pCpy;
+
+		if( ((CWKSP_Base_Item *)GetItemData(m_draggedItem))->Get_Type() == WKSP_ITEM_Map_Layer )
+		{
+			pDst		= (CWKSP_Base_Item *)GetItemData(event.GetItem());
+			pSrc		= (CWKSP_Base_Item *)GetItemData(m_draggedItem);
+			pSrc_Map	= (CWKSP_Map *)pSrc->Get_Manager();
+
+			switch( pDst->Get_Type() )
+			{
+			default:
+				pDst_Map	= NULL;
+				break;
+
+			case WKSP_ITEM_Map:
+				pDst_Map	= (CWKSP_Map *)pDst;
+				pDst		= NULL;
+				break;
+
+			case WKSP_ITEM_Map_Layer:
+				pDst_Map	= (CWKSP_Map *)pDst->Get_Manager();
+				break;
+			}
+
+			if( pDst_Map )
+			{
+				if( pDst_Map == pSrc_Map )
+				{
+					pDst_Map->Move_To(pSrc, pDst);
+
+					pDst_Map->View_Refresh(false);
+				}
+				else if( (pCpy = pDst_Map->Add_Layer(((CWKSP_Map_Layer *)pSrc)->Get_Layer())) != NULL )
+				{
+					pDst_Map->Move_To(pCpy, pDst);
+
+					if( pCpy && !wxGetKeyState(WXK_CONTROL) )
+					{
+						Del_Item(pSrc_Map, ((CWKSP_Map_Layer *)pSrc)->Get_Layer());
+					}
+
+					pDst_Map->View_Refresh(false);
+				}
+			}
+		}
+	}
+
+	m_draggedItem	= (wxTreeItemId)0l;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map_Control::Close(bool bSilent)
+{
+	return( _Del_Item(m_pManager, bSilent) );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,124 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Map_Control.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map_Control : public CWKSP_Base_Control
+{
+	DECLARE_CLASS(CWKSP_Map_Control)
+
+public:
+	CWKSP_Map_Control(wxWindow *pParent);
+	virtual ~CWKSP_Map_Control(void);
+
+	class CWKSP_Map_Manager *	Get_Manager		(void)	{	return( (class CWKSP_Map_Manager *)m_pManager );	}
+
+	virtual int					OnCompareItems	(const wxTreeItemId &item1, const wxTreeItemId &item2);
+
+	void						On_Drag_Begin	(wxTreeEvent &event);
+	void						On_Drag_End		(wxTreeEvent &event);
+
+	bool						Close			(bool bSilent);
+
+	void						Add_Item		(class CWKSP_Base_Manager *pManager, class CWKSP_Base_Item *pItem);
+	bool						Del_Item		(class CWKSP_Map *pMap, class CWKSP_Layer *pLayer);
+
+
+private:
+
+	int							_Get_Image_ID	(class CWKSP_Base_Item *pItem);
+
+	wxTreeItemId				m_draggedItem;
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CWKSP_Map_Control		*g_pMap_Ctrl;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,509 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   WKSP_Map_DC.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include "helper.h"
+
+#include "wksp_map_dc.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_DC::CWKSP_Map_DC(const CSG_Rect &rWorld, const wxRect &rDC, double Scale, int Background)
+{
+	m_rWorld		= rWorld;
+	m_rDC			= rDC;
+	m_Scale			= Scale;
+
+	//-----------------------------------------------------
+	double	d		= (double)m_rDC.GetWidth() / (double)m_rDC.GetHeight();
+
+	if( d > m_rWorld.Get_XRange() / m_rWorld.Get_YRange() )
+	{
+		d	= (m_rWorld.Get_YRange() * d - m_rWorld.Get_XRange()) / 2.0;
+		m_rWorld.Inflate(d, 0.0, false);
+	}
+	else if( d < m_rWorld.Get_XRange() / m_rWorld.Get_YRange() )
+	{
+		d	= (m_rWorld.Get_XRange() / d - m_rWorld.Get_YRange()) / 2.0;
+		m_rWorld.Inflate(0.0, d, false);
+	}
+
+	//-----------------------------------------------------
+	m_World2DC		= (double)m_rDC.GetWidth() / m_rWorld.Get_XRange();
+	m_DC2World		= m_rWorld.Get_XRange() / (double)m_rDC.GetWidth();
+
+	dc_BMP.Create(m_rDC.GetWidth(), m_rDC.GetHeight());
+	dc.SelectObject(dc_BMP);
+	dc.SetBackground(wxBrush(Get_Color_asWX(Background), wxSOLID));
+	dc.Clear();
+
+	m_img_rgb		= NULL;
+	m_img_dc_rgb	= NULL;
+
+	m_Mask_Red		= 1;
+	m_Mask_Green	= 2;
+	m_Mask_Blue		= 3;
+}
+
+//---------------------------------------------------------
+CWKSP_Map_DC::~CWKSP_Map_DC(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::Draw(wxDC &dc_Target)
+{
+	dc.SelectObject(wxNullBitmap);
+
+	dc_Target.DrawBitmap(dc_BMP, m_rDC.GetLeft(), m_rDC.GetTop(), false);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::Draw_DC(CWKSP_Map_DC &dc_Source, double Transparency)
+{
+	if( 1 )
+	{
+		BYTE		*src_rgb, *dst_rgb;
+		int			i, n;
+		double		d;
+		wxImage		src_img, dst_img;
+		wxBitmap	bmp;
+		wxMemoryDC	mdc;
+
+		//-------------------------------------------------
+		n	= 3 * m_rDC.GetHeight() * m_rDC.GetWidth();
+		d	= 1.0 - Transparency;
+
+		bmp.Create(m_rDC.GetWidth(), m_rDC.GetHeight());
+
+		mdc.SelectObject(bmp);
+		mdc.Blit(0, 0, m_rDC.GetWidth(), m_rDC.GetHeight(), &dc, 0, 0);
+		mdc.SelectObject(wxNullBitmap);
+		dst_img	= bmp.ConvertToImage();
+		dst_rgb	= dst_img.GetData();
+
+		mdc.SelectObject(bmp);
+		mdc.Blit(0, 0, m_rDC.GetWidth(), m_rDC.GetHeight(), &dc_Source.dc, 0, 0);
+		mdc.SelectObject(wxNullBitmap);
+		src_img	= bmp.ConvertToImage();
+		src_rgb	= src_img.GetData();
+
+		//-------------------------------------------------
+		for(i=0; i<n; i+=3)
+		{
+			if( src_rgb[i + 0] < 255 || src_rgb[i + 1] < 255 || src_rgb[i + 2] < 255 )
+			{
+				dst_rgb[i + 0]	= (int)(d * src_rgb[i + 0] + Transparency * dst_rgb[i + 0]);
+				dst_rgb[i + 1]	= (int)(d * src_rgb[i + 1] + Transparency * dst_rgb[i + 1]);
+				dst_rgb[i + 2]	= (int)(d * src_rgb[i + 2] + Transparency * dst_rgb[i + 2]);
+			}
+		}
+
+		//-------------------------------------------------
+		dc.DrawBitmap(wxBitmap(dst_img), 0, 0, true);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::Set_Font(wxFont &Font)
+{
+	if( Font.Ok() )
+	{
+		Font.SetPointSize((int)(m_Scale * Font.GetPointSize()));
+		dc.SetFont(Font);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map_DC::IMG_Draw_Begin(double Transparency)
+{
+	BYTE		*pRGB;
+	int			i;
+	wxBitmap	tmp_BMP;
+	wxMemoryDC	tmp_dc;
+
+	if( m_DC2World > 0.0 && m_rDC.GetWidth() > 0 && m_rDC.GetHeight() > 0 )
+	{
+		m_img.Create(m_rDC.GetWidth(), m_rDC.GetHeight());
+		m_img.SetMask(true);
+		m_img.SetMaskColour(m_Mask_Red, m_Mask_Green, m_Mask_Blue);
+		m_img_rgb		= m_img.GetData();
+		m_img_nx		= m_rDC.GetWidth();
+		m_img_nBytes	= 3 * m_rDC.GetHeight() * m_rDC.GetWidth();
+
+		for(i=0, pRGB=m_img_rgb; i<m_img_nBytes; i+=3)
+		{
+			*pRGB++	= m_Mask_Red;
+			*pRGB++	= m_Mask_Green;
+			*pRGB++	= m_Mask_Blue;
+		}
+
+		if( Transparency > 0.0 )
+		{
+			tmp_BMP.Create(m_rDC.GetWidth(), m_rDC.GetHeight());
+			tmp_dc.SelectObject(tmp_BMP);
+			tmp_dc.Blit(0, 0, m_rDC.GetWidth(), m_rDC.GetHeight(), &dc, 0, 0);
+			tmp_dc.SelectObject(wxNullBitmap);
+
+			m_img_dc		= tmp_BMP.ConvertToImage();
+			m_img_dc_rgb	= m_img_dc.GetData();
+
+			m_Transparency	= Transparency;
+			m_img_mode		= Transparency <= 1.0 ? IMG_MODE_TRANSPARENT : (Transparency <= 2.0 ? IMG_MODE_SHADING : IMG_MODE_TRANSPARENT_ALPHA);
+		}
+		else
+		{
+			m_img_mode		= IMG_MODE_OPAQUE;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_DC::IMG_Draw_End(void)
+{
+	if( m_img.Ok() )
+	{
+		dc.DrawBitmap(wxBitmap(m_img), 0, 0, true);
+
+		m_img.Destroy();
+		m_img_rgb		= NULL;
+		m_img_nx		= 0;
+		m_img_nBytes	= 0;
+
+		if( m_img_dc.Ok() )
+		{
+			m_img_dc.Destroy();
+			m_img_dc_rgb	= NULL;
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::IMG_Set_Rect(int x_a, int y_a, int x_b, int y_b, int Color)
+{
+	int		x, y, n;
+
+	//-----------------------------------------------------
+	if( y_a > y_b )
+	{
+		y	= y_a;	y_a	= y_b;	y_b	= y;
+	}
+
+	if( y_a <  0 )
+	{
+		y_a	=  0;
+	}
+
+	if( y_b >= m_rDC.GetHeight() )
+	{
+		y_b	=  m_rDC.GetHeight();
+	}
+
+	//-----------------------------------------------------
+	if( x_a > x_b )
+	{
+		x	= x_a;	x_a	= x_b;	x_b	= x;
+	}
+
+	if( x_a <  0 )
+	{
+		x_a	=  0;
+	}
+
+	if( x_b >= m_rDC.GetWidth() )
+	{
+		x_b	=  m_rDC.GetWidth();
+	}
+
+	//-----------------------------------------------------
+	for(y=y_a; y<y_b; y++)
+	{
+		n	= 3 * (y * m_img_nx + x_a);
+
+		for(x=x_a; x<x_b; x++, n+=3)
+		{
+			IMG_Set_Pixel_Direct(n, Color);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::Draw_Polygon(CSG_Shape_Polygon *pPolygon)
+{
+//	TEST_Draw_Polygon(pPolygon);	return;	// testing alternative polygon drawing
+
+	//-----------------------------------------------------
+	if(	m_World2DC * pPolygon->Get_Extent().Get_XRange() <= 2.0
+	&&	m_World2DC * pPolygon->Get_Extent().Get_YRange() <= 2.0 )
+	{
+		dc.DrawPoint(
+			(int)xWorld2DC(pPolygon->Get_Extent().Get_XCenter()),
+			(int)yWorld2DC(pPolygon->Get_Extent().Get_YCenter())
+		);
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		int			iPart, iPoint, jPoint, *nPoints;
+		TSG_Point	p;
+		wxPoint		*Points;
+
+		//-------------------------------------------------
+		if( pPolygon->Get_Part_Count() == 1 )
+		{
+			if( pPolygon->Get_Point_Count(0) > 2 )
+			{
+				Points	= new wxPoint[pPolygon->Get_Point_Count(0)];
+
+				for(iPoint=0; iPoint<pPolygon->Get_Point_Count(0); iPoint++)
+				{
+					p					= pPolygon->Get_Point(iPoint, 0);
+					Points[iPoint].x	= (int)xWorld2DC(p.x);
+					Points[iPoint].y	= (int)yWorld2DC(p.y);
+				}
+
+				dc.DrawPolygon(pPolygon->Get_Point_Count(0), Points);
+
+				delete[](Points);
+			}
+		}
+
+		//-------------------------------------------------
+		else if( pPolygon->Get_Part_Count() > 1 )
+		{
+			nPoints	= new int[pPolygon->Get_Part_Count()];
+
+			for(iPart=0, jPoint=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+			{
+				jPoint	+= (nPoints[iPart] = pPolygon->Get_Point_Count(iPart) > 2 ? pPolygon->Get_Point_Count(iPart) + 1 : 0);
+			}
+
+			Points	= new wxPoint[jPoint];
+
+			for(iPart=0, jPoint=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+			{
+				if( nPoints[iPart] > 0 )
+				{
+					for(iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++)
+					{
+						p					= pPolygon->Get_Point(iPoint, iPart);
+						Points[jPoint].x	= (int)xWorld2DC(p.x);
+						Points[jPoint].y	= (int)yWorld2DC(p.y);
+						jPoint++;
+					}
+
+					p					= pPolygon->Get_Point(0, iPart);
+					Points[jPoint].x	= (int)xWorld2DC(p.x);
+					Points[jPoint].y	= (int)yWorld2DC(p.y);
+					jPoint++;
+				}
+			}
+
+			dc.DrawPolyPolygon(pPolygon->Get_Part_Count(), nPoints, Points, 0, 0, wxODDEVEN_RULE);
+
+			delete[](Points);
+			delete[](nPoints);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::TEST_Draw_Polygon(CSG_Shape_Polygon *pPolygon)
+{
+	double		xa, y, ya, d;
+	int			xDC, xaDC, xbDC, yDC, yaDC, ybDC, Fill, *cross, iPart, iPoint, i, n, j;
+	TSG_Point	iPt, jPt, Pt, aPt, bPt;
+
+	Fill	= Get_Color_asInt(dc.GetBrush().GetColour());
+	d		= 1.0 / m_World2DC;
+	xaDC	= (int)xWorld2DC(pPolygon->Get_Extent().Get_XMin());
+	xbDC	= (int)xWorld2DC(pPolygon->Get_Extent().Get_XMax());
+	yaDC	= (int)yWorld2DC(pPolygon->Get_Extent().Get_YMin());
+	ybDC	= (int)yWorld2DC(pPolygon->Get_Extent().Get_YMax());
+
+	aPt.x	= pPolygon->Get_Extent().Get_XMin() - 1.0;
+	bPt.x	= pPolygon->Get_Extent().Get_XMax() + 1.0;
+	xa		= pPolygon->Get_Extent().Get_XMin();
+	ya		= pPolygon->Get_Extent().Get_YMin();
+
+	n		= xbDC - xaDC + 1;
+	cross	= (int *)SG_Malloc(n * sizeof(int));
+
+	IMG_Draw_Begin(0.5);
+
+	for(yDC=yaDC, y=ya; yDC>=ybDC; yDC--, y+=d)
+	{
+		if( yDC >= 0 && yDC < m_rDC.GetHeight() )
+		{
+			aPt.y	= bPt.y	= y;
+			memset(cross, 0, n * sizeof(int));
+
+			for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+			{
+				iPt	= pPolygon->Get_Point(pPolygon->Get_Point_Count(iPart) - 1, iPart);
+
+				for(iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++)
+				{
+					jPt	= iPt;
+					iPt	= pPolygon->Get_Point(iPoint, iPart);
+
+					if(	(iPt.y <= y && y <= jPt.y)
+					||	(iPt.y >= y && y >= jPt.y) )
+					{
+						if( SG_Get_Crossing(Pt, aPt, bPt, iPt, jPt, true) )
+						{
+							i	= (int)xWorld2DC(Pt.x) - xaDC;
+
+							if( i >= 0 && i < n )
+							{
+								cross[i]++;
+							}
+						}
+					}
+				}
+			}
+
+			for(i=0, j=0, xDC=xaDC; i<n; xDC++, i++)
+			{
+				j	+= cross[i];
+
+				if( (j % 2) != 0 && xDC >= 0 && xDC < m_rDC.GetWidth() )
+				{
+					IMG_Set_Pixel(xDC, yDC, Fill);
+				}
+			}
+		}
+	}
+
+	IMG_Draw_End();
+
+	SG_Free(cross);
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_DC::TEST_Draw_Polygon_Line(CSG_Grid &Mask, int ax, int ay, int bx, int by, bool bDirChanged)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_dc.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,226 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_Map_DC.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_DC_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_DC_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dcmemory.h>
+#include <wx/image.h>
+
+#include <saga_api/saga_api.h>
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_MODE_OPAQUE			= 0,
+	IMG_MODE_TRANSPARENT,
+	IMG_MODE_SHADING,
+	IMG_MODE_TRANSPARENT_ALPHA
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map_DC
+{
+public:
+	CWKSP_Map_DC(const CSG_Rect &rWorld, const wxRect &rDC, double Scale, int Background);
+	virtual ~CWKSP_Map_DC(void);
+
+	double						m_World2DC, m_DC2World, m_Scale;
+
+	CSG_Rect					m_rWorld;
+
+	wxRect						m_rDC;
+
+	wxMemoryDC					dc;
+
+
+	//-----------------------------------------------------
+	double						xWorld2DC				(double x)		{	return(                     (int)(0.5 + (x - m_rWorld.Get_XMin()) * m_World2DC) );	}
+	double						yWorld2DC				(double y)		{	return( m_rDC.GetHeight() - (int)(0.5 + (y - m_rWorld.Get_YMin()) * m_World2DC) );	}
+
+	TSG_Point_Int				World2DC				(TSG_Point p)	{	TSG_Point_Int _p; _p.x = (int)xWorld2DC(p.x), _p.y = (int)yWorld2DC(p.y); return( _p );	}
+
+	//-----------------------------------------------------
+	void						Set_Font				(wxFont &Font);
+
+	//-----------------------------------------------------
+	void						Draw_DC					(CWKSP_Map_DC &dc_Source, double Transparency);
+	void						Draw_Polygon			(CSG_Shape_Polygon *pPolygon);
+
+	//-----------------------------------------------------
+	bool						IMG_Draw_Begin			(double Transparency);
+	bool						IMG_Draw_End			(void);
+
+	BYTE						IMG_Get_Mask_Red		(void)	{	return( m_Mask_Red );	}
+	BYTE						IMG_Get_Mask_Green		(void)	{	return( m_Mask_Green );	}
+	BYTE						IMG_Get_Mask_Blue		(void)	{	return( m_Mask_Blue );	}
+
+	//-----------------------------------------------------
+	void						IMG_Set_Pixel_Direct	(int n, int Color)
+	{
+		if( n >= 0 && n < m_img_nBytes )
+		{
+			BYTE	r	= SG_GET_R(Color), g	= SG_GET_G(Color), b	= SG_GET_B(Color);
+			double	d;
+
+			switch( m_img_mode )
+			{
+			case IMG_MODE_OPAQUE: default:
+				m_img_rgb[n + 0]	= r;
+				m_img_rgb[n + 1]	= g;
+				m_img_rgb[n + 2]	= b;
+				break;
+
+			case IMG_MODE_SHADING:
+				d					= (r + g + b) / 3.0 / 256.0;
+				m_img_rgb[n + 0]	= (Color = (int)(d * m_img_dc_rgb[n + 0])) > 255 ? 255 : Color;
+				m_img_rgb[n + 1]	= (Color = (int)(d * m_img_dc_rgb[n + 1])) > 255 ? 255 : Color;
+				m_img_rgb[n + 2]	= (Color = (int)(d * m_img_dc_rgb[n + 2])) > 255 ? 255 : Color;
+				break;
+
+			case IMG_MODE_TRANSPARENT:
+				d					= 1.0 - m_Transparency;
+				m_img_rgb[n + 0]	= (int)(d * r + m_Transparency * m_img_dc_rgb[n + 0]);
+				m_img_rgb[n + 1]	= (int)(d * g + m_Transparency * m_img_dc_rgb[n + 1]);
+				m_img_rgb[n + 2]	= (int)(d * b + m_Transparency * m_img_dc_rgb[n + 2]);
+				break;
+
+			case IMG_MODE_TRANSPARENT_ALPHA:
+				if( (d = SG_GET_A(Color) / 256.0) < 1.0 )
+				{
+					m_img_rgb[n + 0]	= (int)((1.0 - d) * r + d * m_img_dc_rgb[n + 0]);
+					m_img_rgb[n + 1]	= (int)((1.0 - d) * g + d * m_img_dc_rgb[n + 1]);
+					m_img_rgb[n + 2]	= (int)((1.0 - d) * b + d * m_img_dc_rgb[n + 2]);
+				}
+				break;
+			}
+		}
+	}
+
+	void						IMG_Set_Pixel			(int n, int Color)
+	{
+		IMG_Set_Pixel_Direct(3 * n, Color);
+	}
+
+	void						IMG_Set_Pixel			(int x, int y, int Color)
+	{
+		if( x >= 0 && x < m_img_nx )
+		{
+			IMG_Set_Pixel_Direct(3 * (y * m_img_nx + x), Color);
+		}
+	}
+
+	void						IMG_Set_Rect			(int x_a, int y_a, int x_b, int y_b, int Color);
+
+	//-----------------------------------------------------
+	void						Draw					(wxDC &dc_Target);
+
+
+private:
+
+	BYTE						m_Mask_Red, m_Mask_Green, m_Mask_Blue;
+
+	BYTE						*m_img_rgb, *m_img_dc_rgb;
+
+	int							m_img_nx, m_img_nBytes, m_img_mode;
+
+	double						m_Transparency;
+
+	wxImage						m_img, m_img_dc;
+
+	wxBitmap					dc_BMP;
+
+
+	void						TEST_Draw_Polygon		(CSG_Shape_Polygon *pPolygon);
+	void						TEST_Draw_Polygon_Line	(CSG_Grid &Mask, int ax, int ay, int bx, int by, bool bDirChanged);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_DC_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,253 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Map_Layer.cpp                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/window.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_layer.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+
+#include "wksp_grid.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Layer::CWKSP_Map_Layer(CWKSP_Layer *pLayer)
+{
+	m_pLayer	= pLayer;
+
+	m_bShow		= true;
+}
+
+//---------------------------------------------------------
+CWKSP_Map_Layer::~CWKSP_Map_Layer(void)
+{
+	((CWKSP_Map *)Get_Manager())->On_Delete(this);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Map_Layer::Get_Name(void)
+{
+	return( m_bShow ? m_pLayer->Get_Name() : wxString::Format(wxT("[%s]"), m_pLayer->Get_Name().c_str()) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Map_Layer::Get_Description(void)
+{
+	return( m_pLayer->Get_Description() );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Map_Layer::Get_Menu(void)
+{
+	wxMenu	*pMenu, *pMenu_Edit;
+
+	pMenu	= new wxMenu(m_pLayer->Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_MAPS_LAYER_SHOW);
+	pMenu->AppendSeparator();
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_MOVE_TOP);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_MOVE_UP);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_MOVE_DOWN);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_MOVE_BOTTOM);
+
+	switch( m_pLayer->Get_Type() )
+	{
+	default:
+		break;
+
+	case WKSP_ITEM_Grid:
+		pMenu->AppendSeparator();
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_MAPS_GRID_FITCOLORS);
+		break;
+	}
+
+	if( (pMenu_Edit = m_pLayer->Edit_Get_Menu()) != NULL )
+	{
+		pMenu->AppendSeparator();
+		pMenu->Append(ID_CMD_WKSP_FIRST, LNG("[MNU] Edit"), pMenu_Edit);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map_Layer::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+	case ID_CMD_MAPS_LAYER_SHOW:
+		m_bShow	= !m_bShow;
+		((wxTreeCtrl *)Get_Control())->SetItemText(GetId(), Get_Name());
+		((CWKSP_Map *)Get_Manager())->View_Refresh(true);
+		break;
+
+	case ID_CMD_MAPS_MOVE_TOP:
+		if( Get_Manager()->Move_Top(this) )
+			((CWKSP_Map *)Get_Manager())->View_Refresh(false);
+		break;
+
+	case ID_CMD_MAPS_MOVE_BOTTOM:
+		if( Get_Manager()->Move_Bottom(this) )
+			((CWKSP_Map *)Get_Manager())->View_Refresh(false);
+		break;
+
+	case ID_CMD_MAPS_MOVE_UP:
+		if( Get_Manager()->Move_Up(this) )
+			((CWKSP_Map *)Get_Manager())->View_Refresh(false);
+		break;
+
+	case ID_CMD_MAPS_MOVE_DOWN:
+		if( Get_Manager()->Move_Down(this) )
+			((CWKSP_Map *)Get_Manager())->View_Refresh(false);
+		break;
+
+	case ID_CMD_MAPS_GRID_FITCOLORS:
+		if( m_pLayer->Get_Type() == WKSP_ITEM_Grid )
+			((CWKSP_Grid *)m_pLayer)->Fit_Color_Range(((CWKSP_Map *)Get_Manager())->Get_Extent());
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Layer::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command_UI(event) );
+
+	case ID_CMD_MAPS_LAYER_SHOW:
+		event.Check(m_bShow);
+		break;
+
+	case ID_CMD_MAPS_MOVE_TOP:
+	case ID_CMD_MAPS_MOVE_UP:
+		event.Enable(Get_Index() > 0);
+		break;
+
+	case ID_CMD_MAPS_MOVE_DOWN:
+	case ID_CMD_MAPS_MOVE_BOTTOM:
+		event.Enable(Get_Index() < Get_Manager()->Get_Count() - 1);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameters * CWKSP_Map_Layer::Get_Parameters(void)
+{
+	return( m_pLayer->Get_Parameters() );
+}
+
+//---------------------------------------------------------
+void CWKSP_Map_Layer::Parameters_Changed(void)
+{
+	m_pLayer->Parameters_Changed();
+
+	CWKSP_Base_Item::Parameters_Changed();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_layer.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,122 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   WKSP_Map_Layer.h                    //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Layer_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Layer_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_item.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map_Layer : public CWKSP_Base_Item
+{
+public:
+	CWKSP_Map_Layer(class CWKSP_Layer *pLayer);
+	virtual ~CWKSP_Map_Layer(void);
+
+	virtual TWKSP_Item			Get_Type			(void)	{	return( WKSP_ITEM_Map_Layer );	}
+
+	virtual wxString			Get_Name			(void);
+	virtual wxString			Get_Description		(void);
+
+	virtual wxMenu *			Get_Menu			(void);
+
+	virtual bool				On_Command			(int Cmd_ID);
+	virtual bool				On_Command_UI		(wxUpdateUIEvent &event);
+
+	virtual CSG_Parameters *	Get_Parameters		(void);
+	virtual void				Parameters_Changed	(void);
+
+	class CWKSP_Layer *			Get_Layer			(void)	{	return( m_pLayer );	}
+
+	bool						do_Show				(void)	{	return( m_bShow );	}
+
+
+private:
+
+	bool						m_bShow;
+
+	class CWKSP_Layer			*m_pLayer;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Layer_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,371 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Map_Manager.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_data_manager.h"
+#include "wksp_layer.h"
+
+#include "wksp_map_control.h"
+#include "wksp_map_manager.h"
+#include "wksp_map.h"
+#include "wksp_map_layer.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Manager	*g_pMaps	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Map_Manager::CWKSP_Map_Manager(void)
+{
+	g_pMaps		= this;
+
+	///////////////////////////////////////////////////////
+	//-----------------------------------------------------
+	bool			bValue;
+	double			dValue;
+	long			lValue;
+	CSG_Parameter	*pNode_0, *pNode_1;
+
+	m_Parameters.Create(this, LNG(""), LNG(""));
+
+	//-----------------------------------------------------
+	pNode_0	= m_Parameters.Add_Node(
+		NULL	, "NODE_DEFAULTS"	, LNG("[CAP] Defaults"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		pNode_0	, "GOTO_NEWLAYER"	, LNG("[CAP] Zoom to added layer"),
+		LNG(""),
+		PARAMETER_TYPE_Bool,
+		CONFIG_Read(wxT("/MAPS"), wxT("GOTO_NEWLAYER"), bValue) ? bValue : true
+	);
+
+	//-----------------------------------------------------
+	pNode_1	= m_Parameters.Add_Node(
+		pNode_0	, "NODE_FRAME"		, LNG("[CAP] Frame"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "FRAME_SHOW"		, LNG("[CAP] Show"),
+		LNG(""),
+		PARAMETER_TYPE_Bool,
+		CONFIG_Read(wxT("/MAPS"), wxT("FRAME_SHOW"), bValue) ? bValue : true
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "FRAME_WIDTH"		, LNG("[CAP] Width"),
+		LNG(""),
+		PARAMETER_TYPE_Int,
+		CONFIG_Read(wxT("/MAPS"), wxT("FRAME_WIDTH"), lValue) ? lValue : 17,
+		5, true
+	);
+
+	//-----------------------------------------------------
+	pNode_1	= m_Parameters.Add_Node(
+		pNode_0	, "NODE_CLIPBOARD"	, LNG("[CAP] Clipboard"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "CLIP_NX"			, LNG("[CAP] Width"),
+		LNG(""),
+		PARAMETER_TYPE_Int,
+		CONFIG_Read(wxT("/MAPS"), wxT("CLIP_NX"), lValue) ? lValue : 400
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "CLIP_NY"			, LNG("[CAP] Height"),
+		LNG(""),
+		PARAMETER_TYPE_Int,
+		CONFIG_Read(wxT("/MAPS"), wxT("CLIP_NY"), lValue) ? lValue : 400
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "CLIP_FRAME"		, LNG("[CAP] Frame Width"),
+		LNG(""),
+		PARAMETER_TYPE_Int,
+		CONFIG_Read(wxT("/MAPS"), wxT("CLIP_FRAME"), lValue) ? lValue : 17,
+		5, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "CLIP_LEGEND_SCALE", LNG("[CAP] Legend Scale"),
+		LNG(""),
+		PARAMETER_TYPE_Double,
+		CONFIG_Read(wxT("/MAPS"), wxT("CLIP_LEGEND_SCALE"), dValue) ? dValue : 2.0,
+		1.0, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "CLIP_LEGEND_FRAME", LNG("[CAP] Legend Frame Width"),
+		LNG(""),
+		PARAMETER_TYPE_Int,
+		CONFIG_Read(wxT("/MAPS"), wxT("CLIP_LEGEND_FRAME"), lValue) ? lValue : 10,
+		0, true
+	);
+
+	m_Parameters.Add_Value(
+		pNode_1	, "CLIP_LEGEND_COLOR", LNG("[CAP] Legend Border Colour"),
+		LNG(""),
+		PARAMETER_TYPE_Color,
+		CONFIG_Read(wxT("/MAPS"), wxT("CLIP_LEGEND_COLOR"), lValue) ? lValue : SG_GET_RGB(0, 0, 0)
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Map_Manager::~CWKSP_Map_Manager(void)
+{
+	CONFIG_Write(wxT("/MAPS"), wxT("GOTO_NEWLAYER")	,		m_Parameters("GOTO_NEWLAYER")	->asBool());
+	CONFIG_Write(wxT("/MAPS"), wxT("FRAME_SHOW")	,		m_Parameters("FRAME_SHOW")		->asBool());
+	CONFIG_Write(wxT("/MAPS"), wxT("FRAME_WIDTH")	, (long)m_Parameters("FRAME_WIDTH")		->asInt());
+	CONFIG_Write(wxT("/MAPS"), wxT("CLIP_NX")		, (long)m_Parameters("CLIP_NX")			->asInt());
+	CONFIG_Write(wxT("/MAPS"), wxT("CLIP_NY")		, (long)m_Parameters("CLIP_NY")			->asInt());
+	CONFIG_Write(wxT("/MAPS"), wxT("CLIP_FRAME")	, (long)m_Parameters("CLIP_FRAME")		->asInt());
+
+	g_pMaps		= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Map_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] Maps") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Map_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("%d %s"), Get_Count(), Get_Count() == 1 ? LNG("[CAP] Map") : LNG("[CAP] Maps"));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Map_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Maps"));
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Map_Manager::Exists(CWKSP_Map *pMap)
+{
+	if( pMap )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( pMap == Get_Map(i) )
+			{
+				return( true );
+			}
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Manager::Close(bool bSilent)
+{
+	return( g_pMap_Ctrl->Close(bSilent) );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Manager::Add(CWKSP_Layer *pLayer)
+{
+	int		iMap;
+
+	if( (iMap = DLG_Maps_Add()) >= 0 && Add(pLayer, Get_Map(iMap)) )
+	{
+		Get_Map(iMap)->View_Show(true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+bool CWKSP_Map_Manager::Add(CWKSP_Layer *pLayer, CWKSP_Map *pMap)
+{
+	if( pLayer )
+	{
+		if( pMap == NULL )
+		{
+			Add_Item(pMap = new CWKSP_Map);
+		}
+		else if( !Exists(pMap) )
+		{
+			Add_Item(pMap);
+		}
+
+		pMap->Add_Layer(pLayer);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Manager::Del(CWKSP_Layer *pLayer)
+{
+	int		i, n;
+
+	for(i=Get_Count()-1, n=0; i>=0; i--)
+	{
+		if( g_pMap_Ctrl->Del_Item(Get_Map(i), pLayer) )
+		{
+			n++;
+		}
+	}
+
+	return( n > 0 );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Map_Manager::Update(CWKSP_Layer *pLayer, bool bMapsOnly)
+{
+	int		i, n;
+
+	for(i=0, n=0; i<Get_Count(); i++)
+	{
+		if( Get_Map(i)->Update(pLayer, bMapsOnly) )
+		{
+			n++;
+		}
+	}
+
+	return( n > 0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_map_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,129 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Map_Manager.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Map_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Map_Manager(void);
+	virtual ~CWKSP_Map_Manager(void);
+
+	virtual TWKSP_Item			Get_Type		(void)		{	return( WKSP_ITEM_Map_Manager );	}
+
+	virtual wxString			Get_Name		(void);
+	virtual wxString			Get_Description	(void);
+
+	virtual wxMenu *			Get_Menu		(void);
+
+	virtual CSG_Parameters *	Get_Parameters	(void)		{	return( &m_Parameters );	}
+	virtual bool				On_Command		(int Cmd_ID);
+
+	class CWKSP_Map *			Get_Map			(int i)		{	return( (class CWKSP_Map *)Get_Item(i) );	}
+
+	bool						Exists			(class CWKSP_Map *pMap);
+
+	bool						Close			(bool bSilent);
+
+	bool						Add				(class CWKSP_Layer *pLayer);
+	bool						Add				(class CWKSP_Layer *pLayer, class CWKSP_Map *pMap);
+	bool						Del				(class CWKSP_Layer *pLayer);
+	bool						Update			(class CWKSP_Layer *pLayer, bool bMapsOnly);
+
+
+private:
+
+	CSG_Parameters				m_Parameters;
+
+};
+
+//---------------------------------------------------------
+extern CWKSP_Map_Manager		*g_pMaps;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Map_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,811 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   WKSP_Module.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/utils.h>
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "active.h"
+#include "active_parameters.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_module_manager.h"
+#include "wksp_module_library.h"
+#include "wksp_module_menu.h"
+#include "wksp_module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module	*g_pModule	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module::CWKSP_Module(CSG_Module *pModule, const wxChar *Menu_Path_default)
+{
+	m_pModule		= pModule;
+
+	m_Menu_ID		= -1;
+
+	//-----------------------------------------------------
+	bool		bLibrary, bModule;
+	const wxChar	*sModule	= m_pModule->Get_MenuPath();
+
+	m_Menu_Path.Empty();
+
+	if( sModule && *sModule && *(sModule + 1) == wxT(':') )
+	{
+		if( *sModule == wxT('A') || *sModule == wxT('a') )
+		{
+			sModule	+= 2;
+
+			if( *sModule )
+			{
+				m_Menu_Path.Printf(wxT("%s"), sModule);
+			}
+		}
+		else
+		{
+			sModule	+= 2;
+		}
+	}
+
+	if( m_Menu_Path.Length() == 0 )	// Menu path is relative to default menu path...
+	{
+		bLibrary	= Menu_Path_default	&& *Menu_Path_default;
+		bModule		= sModule			&& *sModule;
+
+		if( bLibrary && bModule )
+		{
+			m_Menu_Path.Printf(wxT("%s|%s"), Menu_Path_default, sModule);
+		}
+		else if( bLibrary )
+		{
+			m_Menu_Path.Printf(wxT("%s"), Menu_Path_default);
+		}
+		else if( bModule )
+		{
+			m_Menu_Path.Printf(wxT("%s"), sModule);
+		}
+	}
+}
+
+//---------------------------------------------------------
+CWKSP_Module::~CWKSP_Module(void)
+{
+	if( g_pModule == this )
+	{
+		if( g_pModule->is_Executing() )
+		{
+			PROCESS_Set_Okay(false);
+		}
+
+		if( m_pModule->is_Interactive() )
+		{
+			((CSG_Module_Interactive *)m_pModule)->Execute_Finish();
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Module::Get_Name(void)
+{
+	return( m_pModule->is_Interactive()
+		? wxString::Format(wxT("%s [%s]"), m_pModule->Get_Name(), LNG("interactive"))
+		: wxString::Format(wxT("%s")     , m_pModule->Get_Name())
+	);
+}
+
+//---------------------------------------------------------
+void CWKSP_Module::Set_File_Name(const wxString &File_Name)
+{
+	m_File_Name = File_Name;
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Module::Get_Description(void)
+{
+	bool		bFirst, bOptionals	= false;
+	int			i;
+	CSG_Parameter	*pParameter;
+	wxString	s, sTmp;
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("%s: <b>%s</b>")	, LNG("Module"), m_pModule->Get_Name()));
+
+	if( m_pModule->is_Interactive() )
+	{
+		s.Append(wxString::Format(wxT("<br>- %s -")	, LNG("interactive execution")));
+	}
+
+	if( m_pModule->Get_Author() && *(m_pModule->Get_Author()) )
+	{
+		s.Append(wxString::Format(wxT("<br>%s")		, m_pModule->Get_Author()));
+	}
+
+	if( m_Menu_Path.Length() > 0 )
+	{
+		sTmp	= m_Menu_Path;
+		sTmp.Replace(wxT("|"), wxT(" <b>></b> "));
+		s.Append(wxString::Format(wxT("<br>%s: <i>%s</i>"), LNG("Menu"), sTmp.c_str()));
+	}
+
+	if( m_pModule->Get_Description() && *(m_pModule->Get_Description()) )
+	{
+		s.Append(wxString::Format(wxT("<hr><b>%s</b><br>%s"), LNG("Description"), m_pModule->Get_Description()));
+	}
+
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<hr><b>%s</b><br>"), LNG("Parameters")));
+	s.Append(wxString::Format(wxT("<table border=\"1\" width=\"100%%\" valign=\"top\" cellpadding=\"5\" rules=\"all\"><tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n"),
+		LNG("Name"), LNG("Type"), LNG("Identifier"), LNG("Description"), LNG("Constraints")
+	));
+
+	for(i=0, bFirst=true; i<m_pModule->Get_Parameters()->Get_Count(); i++)
+	{
+		pParameter	= m_pModule->Get_Parameters()->Get_Parameter(i);
+
+		if( pParameter->is_Input() )
+		{
+			if( bFirst )
+			{
+				bFirst	= false;
+				s.Append(wxString::Format(wxT("<tr><th colspan=\"5\">%s</th></tr>"), LNG("Input")));
+			}
+
+			s.Append(wxString::Format(wxT("<tr><td>%s%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>"),
+				pParameter->Get_Name(),
+				pParameter->is_Optional() ? wxT(" (*)") : wxT(" "),
+				pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(),
+				pParameter->Get_Identifier(),
+				pParameter->Get_Description(),
+				pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
+			));
+		}
+	}
+
+	for(i=0, bFirst=true; i<m_pModule->Get_Parameters()->Get_Count(); i++)
+	{
+		pParameter	= m_pModule->Get_Parameters()->Get_Parameter(i);
+
+		if( pParameter->is_Output() )
+		{
+			if( bFirst )
+			{
+				bFirst	= false;
+				s.Append(wxString::Format(wxT("<tr><th colspan=\"5\">%s</th></tr>"), LNG("Output")));
+			}
+
+			s.Append(wxString::Format(wxT("<tr><td>%s%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>"),
+				pParameter->Get_Name(),
+				pParameter->is_Optional() ? wxT(" (*)") : wxT(""),
+				pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(),
+				pParameter->Get_Identifier(),
+				pParameter->Get_Description(),
+				pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
+			));
+		}
+	}
+
+	for(i=0, bFirst=true; i<m_pModule->Get_Parameters()->Get_Count(); i++)
+	{
+		pParameter	= m_pModule->Get_Parameters()->Get_Parameter(i);
+
+		if( pParameter->is_Option() && pParameter->Get_Type() != PARAMETER_TYPE_Grid_System )
+		{
+			if( bFirst )
+			{
+				bFirst	= false;
+				s.Append(wxString::Format(wxT("<tr><th colspan=\"5\">%s</th></tr>"), LNG("Options")));
+			}
+
+			s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>"),
+				pParameter->Get_Name(),
+				pParameter->Get_Description(PARAMETER_DESCRIPTION_TYPE).c_str(),
+				pParameter->Get_Identifier(),
+				pParameter->Get_Description(),
+				pParameter->Get_Description(PARAMETER_DESCRIPTION_PROPERTIES).c_str()
+			));
+		}
+		else if( pParameter->is_Optional() )
+		{
+			bOptionals	= true;
+		}
+	}
+
+	s.Append(wxT("</table>"));
+
+	if( bOptionals )
+	{
+		s.Append(wxString::Format(wxT("(*) <i>%s</i>"), LNG("optional")));
+	}
+
+	s.Replace(wxT("\n"), wxT("<br>"));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Module::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(Get_Name());
+
+	pMenu->AppendCheckItem(Get_Menu_ID(), LNG("[CMD] Execute"), LNG("[HLP] Execute Module"));
+
+	pMenu->AppendSeparator();
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MODULES_SAVE_SCRIPT);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+CSG_Parameters * CWKSP_Module::Get_Parameters(void)
+{
+	return( m_pModule->Get_Parameters() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		Execute(true);
+		break;
+
+	case ID_CMD_MODULES_SAVE_SCRIPT:
+		_Save_Script();
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module::_Save_Script(void)
+{
+	wxString	FileName;
+
+	if( DLG_Save(FileName, LNG("[CAP] Create Script Command File"), SG_T("DOS Batch Script (*.bat)|*.bat|Python Script (*.py)|*.py")) )
+	{
+		CSG_File	File;
+		CSG_String	Command;
+
+		if(      SG_File_Cmp_Extension(FileName.c_str(), SG_T("bat")) )
+		{
+			Command	+= SG_T("@ECHO OFF\n\n");
+
+			Command	+= SG_T("REM SET SAGA_MLB = C:\\SAGA\\Modules\n");
+			Command	+= SG_T("REM SET PATH = %PATH%;C:\\SAGA\n\n");
+
+			Command	+= SG_T("saga_cmd ");
+
+			Command	+= SG_File_Get_Name(((CWKSP_Module_Library *)Get_Manager())->Get_File_Name(), false);
+
+			Command	+= SG_T(" \"");
+			Command	+= m_pModule->Get_Name();
+			Command	+= SG_T("\"");
+
+			_Save_Script_CMD(Command, m_pModule->Get_Parameters());
+
+			for(int i=0; i<m_pModule->Get_Parameters_Count(); i++)
+			{
+				_Save_Script_CMD(Command, m_pModule->Get_Parameters(i));
+			}
+
+			Command	+= SG_T("\n\nPAUSE\n");
+		}
+		else if( SG_File_Cmp_Extension(FileName.c_str(), SG_T("py" )) )
+		{
+			Command	+= SG_T("# Python script template for SAGA module execution (automatically created, experimental)\n\n");
+			Command	+= SG_T("import saga_api, sys, os\n");
+			Command	+= SG_T("\n");
+			Command	+= SG_T("def Call_SAGA_Module(in__grid, out_grid, in__shapes, out_shapes):\n");
+			Command	+= SG_T("    print saga_api.SAGA_API_Get_Version()\n");
+			Command	+= SG_T("\n");
+			Command	+= SG_T("    Library = saga_api.CSG_Module_Library()\n");
+			Command	+= SG_T("    if Library.Create(saga_api.CSG_String('");
+			Command	+= ((CWKSP_Module_Library *)Get_Manager())->Get_File_Name();
+			Command	+= SG_T("')) == 0:\n");
+			Command	+= SG_T("        print 'unable to load SAGA module library'\n");
+			Command	+= SG_T("        return 0\n");
+			Command	+= SG_T("\n");
+
+			switch( m_pModule->Get_Type() )
+			{
+			default:
+				Command	+= CSG_String::Format(SG_T("    Module = Library.Get_Module('%s')\n")		, m_pModule->Get_Name());
+				break;
+
+			case MODULE_TYPE_Grid:
+				Command	+= CSG_String::Format(SG_T("    Module = Library.Get_Module_Grid('%s')\n")	, m_pModule->Get_Name());
+				Command	+= SG_T("    Module.Get_System().Assign(in__grid.Get_System())\n");
+				break;
+			}
+
+			Command	+= SG_T("\n");
+			Command	+= SG_T("    Parms = Module.Get_Parameters() # default parameter list\n");
+			_Save_Script_Python(Command, m_pModule->Get_Parameters());
+
+			for(int i=0; i<m_pModule->Get_Parameters_Count(); i++)
+			{
+				Command	+= SG_T("\n");
+				Command	+= CSG_String::Format(SG_T("    Parms = Module.Get_Parameters(%d) # additional parameter list\n"), i);
+				_Save_Script_Python(Command, m_pModule->Get_Parameters(i));
+			}
+
+			Command	+= SG_T("\n");
+			Command	+= SG_T("    if Module.Execute() == 0:\n");
+			Command	+= SG_T("        print 'module execution failed'\n");
+			Command	+= SG_T("        return 0\n");
+			Command	+= SG_T("    print 'module successfully executed'\n");
+			Command	+= SG_T("    return 1\n");
+			Command	+= SG_T("\n");
+			Command	+= SG_T("\n");
+			Command	+= SG_T("if __name__ == '__main__':\n");
+			Command	+= SG_T("    if len( sys.argv ) != 4:\n");
+			Command	+= SG_T("        print 'Usage: this_script.py <in: gridfile> <out: gridfile> <in: shapefile> <out: shapefile>'\n");
+			Command	+= SG_T("\n");
+			Command	+= SG_T("    else:\n");
+			Command	+= SG_T("        in__grid    = saga_api.SG_Create_Grid(saga_api.CSG_String(sys.argv[1]))\n");
+			Command	+= SG_T("        out_grid    = saga_api.SG_Create_Grid(grid_in.Get_System())\n");
+			Command	+= SG_T("        in__shapes  = saga_api.SG_Create_Shapes(saga_api.CSG_String(sys.argv[3]))\n");
+			Command	+= SG_T("        out_shapes  = saga_api.SG_Create_Shapes()\n");
+			Command	+= SG_T("\n");
+			Command	+= SG_T("        if Call_SAGA_Module(in__grid, out_grid, in__shapes, out_shapes) != 0:\n");
+			Command	+= SG_T("            grid_out  .Save(saga_api.CSG_String(sys.argv[2]))\n");
+			Command	+= SG_T("            shapes_out.Save(saga_api.CSG_String(sys.argv[4]))\n");
+		}
+
+		if( File.Open(FileName.c_str(), SG_FILE_W, false) && Command.Length() > 0 )
+		{
+			File.Write(Command);
+		}
+	}
+}
+
+//---------------------------------------------------------
+#define GET_ID1(p)		(p->Get_Owner()->Get_Identifier() && *(p->Get_Owner()->Get_Identifier()) \
+						? wxString::Format(wxT("%s_%s"), p->Get_Owner()->Get_Identifier(), p->Get_Identifier()) \
+						: wxString::Format(p->Get_Identifier())).c_str()
+
+#define GET_ID2(p, s)	wxString::Format(wxT("%s_%s"), GET_ID1(p), s).c_str()
+
+//---------------------------------------------------------
+void CWKSP_Module::_Save_Script_CMD(CSG_String &Command, CSG_Parameters *pParameters)
+{
+	for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
+	{
+		CSG_Parameter	*p	= pParameters->Get_Parameter(iParameter);
+
+		switch( p->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Bool:
+			if( p->asBool() )
+				Command	+= CSG_String::Format(SG_T(" -%s"), GET_ID1(p));
+			break;
+
+		case PARAMETER_TYPE_Int:
+		case PARAMETER_TYPE_Choice:
+		case PARAMETER_TYPE_Table_Field:
+			Command	+= CSG_String::Format(SG_T(" -%s=%d"), GET_ID1(p), p->asInt());
+			break;
+
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+			Command	+= CSG_String::Format(SG_T(" -%s=%f"), GET_ID1(p), p->asDouble());
+			break;
+
+		case PARAMETER_TYPE_Range:
+			Command	+= CSG_String::Format(SG_T(" -%s=%f"), GET_ID2(p, "MIN"), p->asRange()->Get_LoVal());
+			Command	+= CSG_String::Format(SG_T(" -%s=%f"), GET_ID2(p, "MAX"), p->asRange()->Get_HiVal());
+			break;
+
+		case PARAMETER_TYPE_String:
+		case PARAMETER_TYPE_Text:
+		case PARAMETER_TYPE_FilePath:
+			Command	+= CSG_String::Format(SG_T(" -%s=%s"), GET_ID1(p), p->asString());
+			break;
+
+		case PARAMETER_TYPE_FixedTable:
+			Command	+= CSG_String::Format(SG_T(" -%s=%s"), GET_ID1(p), p->asString());
+			break;
+
+		case PARAMETER_TYPE_Grid_System:
+			if( p->Get_Children_Count() == 0 )
+			{
+				Command	+= CSG_String::Format(SG_T(" -%s=%d"), GET_ID2(p, "NX"), p->asGrid_System()->Get_NX());
+				Command	+= CSG_String::Format(SG_T(" -%s=%d"), GET_ID2(p, "NY"), p->asGrid_System()->Get_NY());
+				Command	+= CSG_String::Format(SG_T(" -%s=%f"), GET_ID2(p,  "X"), p->asGrid_System()->Get_XMin());
+				Command	+= CSG_String::Format(SG_T(" -%s=%f"), GET_ID2(p,  "Y"), p->asGrid_System()->Get_YMin());
+				Command	+= CSG_String::Format(SG_T(" -%s=%f"), GET_ID2(p,  "D"), p->asGrid_System()->Get_Cellsize());
+			}
+			break;
+
+		case PARAMETER_TYPE_DataObject_Output:
+		case PARAMETER_TYPE_Grid:
+		case PARAMETER_TYPE_Table:
+		case PARAMETER_TYPE_Shapes:
+		case PARAMETER_TYPE_TIN:
+			Command	+= CSG_String::Format(SG_T(" -%s=%s"), GET_ID1(p), p->asDataObject() && p->asDataObject()->Get_File_Name() ? p->asDataObject()->Get_File_Name() : SG_T("NULL"));
+			break;
+
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+			if( p->is_Input() )
+			{
+				Command	+= CSG_String::Format(SG_T(" -%s="), GET_ID1(p));
+
+				if( p->asList()->Get_Count() == 0 )
+				{
+					Command	+= SG_T("NULL");
+				}
+				else
+				{
+					Command	+= p->asList()->asDataObject(0)->Get_File_Name(true);
+
+					for(int iObject=1; iObject<p->asList()->Get_Count(); iObject++)
+					{
+						Command	+= SG_T(";");
+						Command	+= p->asList()->asDataObject(iObject)->Get_File_Name(true);
+					}
+				}
+			}
+			break;
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Module::_Save_Script_Python(CSG_String &Command, CSG_Parameters *pParameters)
+{
+	for(int iParameter=0; iParameter<pParameters->Get_Count(); iParameter++)
+	{
+		CSG_Parameter	*p	= pParameters->Get_Parameter(iParameter);
+
+		switch( p->Get_Type() )
+		{
+		default:
+			break;
+
+		case PARAMETER_TYPE_Bool:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(%d)\n"), p->Get_Identifier(), p->asBool() ? 1 : 0);
+			break;
+
+		case PARAMETER_TYPE_Int:
+		case PARAMETER_TYPE_Choice:
+		case PARAMETER_TYPE_Table_Field:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(%d)\n"), p->Get_Identifier(), p->asInt());
+			break;
+
+		case PARAMETER_TYPE_Double:
+		case PARAMETER_TYPE_Degree:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(%f)\n"), p->Get_Identifier(), p->asDouble());
+			break;
+
+		case PARAMETER_TYPE_Range:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').asRange().Set_LoVal(%f)\n"), p->Get_Identifier(), p->asRange()->Get_LoVal());
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').asRange().Set_HiVal(%f)\n"), p->Get_Identifier(), p->asRange()->Get_HiVal());
+			break;
+
+		case PARAMETER_TYPE_String:
+		case PARAMETER_TYPE_Text:
+		case PARAMETER_TYPE_FilePath:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(%s)\n"), p->Get_Identifier(), p->asString());
+			break;
+
+		case PARAMETER_TYPE_FixedTable:
+			Command	+= CSG_String::Format(SG_T("#   Parms('%s').Set_Value(saga_api.SG_Create_Table('table.txt'))\n"), p->Get_Identifier());
+			break;
+
+		case PARAMETER_TYPE_Grid_System:
+			if( p->Get_Children_Count() == 0 )
+			{
+				Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(saga_api.CSG_Grid_System(%f, %f, %f, %d, %d))\n"), p->Get_Identifier(),
+					p->asGrid_System()->Get_Cellsize(),
+					p->asGrid_System()->Get_XMin()	, p->asGrid_System()->Get_YMin(),
+					p->asGrid_System()->Get_NX()	, p->asGrid_System()->Get_NY());
+			}
+			break;
+
+		case PARAMETER_TYPE_Grid:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(0) # %s %s grid\n"), p->Get_Identifier(),
+				p->is_Input()    ? SG_T("input")    : SG_T("output"), p->is_Optional() ? SG_T("optional") : SG_T("NOT optional")
+			);
+			break;
+
+		case PARAMETER_TYPE_Table:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(0) # %s %s table\n"), p->Get_Identifier(),
+				p->is_Input()    ? SG_T("input")    : SG_T("output"), p->is_Optional() ? SG_T("optional") : SG_T("NOT optional")
+			);
+			break;
+
+		case PARAMETER_TYPE_Shapes:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(0) # %s %s shapes\n"), p->Get_Identifier(),
+				p->is_Input()    ? SG_T("input")    : SG_T("output"), p->is_Optional() ? SG_T("optional") : SG_T("NOT optional")
+			);
+			break;
+
+		case PARAMETER_TYPE_TIN:
+			Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(0) # %s %s TIN\n"), p->Get_Identifier(),
+				p->is_Input()    ? SG_T("input")    : SG_T("output"), p->is_Optional() ? SG_T("optional") : SG_T("NOT optional")
+			);
+			break;
+
+		case PARAMETER_TYPE_Grid_List:
+		case PARAMETER_TYPE_Table_List:
+		case PARAMETER_TYPE_Shapes_List:
+		case PARAMETER_TYPE_TIN_List:
+		case PARAMETER_TYPE_PointCloud_List:
+			if( p->is_Input() )
+			{
+				if( !p->is_Optional() )
+					Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(0) # data object list\n"), p->Get_Identifier());
+				else
+					Command	+= CSG_String::Format(SG_T("    Parms('%s').Set_Value(0) # optional data object list\n"), p->Get_Identifier());
+			}
+			break;
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module::Set_Menu_ID(int aMenu_ID)
+{
+	m_Menu_ID	= aMenu_ID;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module::is_Interactive(void)
+{
+	return( m_pModule->is_Interactive() );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Module::is_Executing(void)
+{
+	return( m_pModule->is_Executing() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define MSG_ADD(s)			MSG_General_Add  (s, true, true);\
+							MSG_Execution_Add(s, true, true);
+
+#define MSG_ADD2(b, s1, s2)	MSG_General_Add  (b ? s1 : s2, true, true, b ? SG_UI_MSG_STYLE_SUCCESS : SG_UI_MSG_STYLE_FAILURE);\
+							MSG_Execution_Add(b ? s1 : s2, true, true, b ? SG_UI_MSG_STYLE_SUCCESS : SG_UI_MSG_STYLE_FAILURE);
+
+//---------------------------------------------------------
+bool CWKSP_Module::Execute(bool bDialog)
+{
+	bool	bResult	= false;
+
+	//-----------------------------------------------------
+	if( g_pModule )
+ 	{
+		if( g_pModule == this )
+		{
+			if( g_pModule->is_Executing() )
+			{
+				if( DLG_Message_Confirm(LNG("[MSG] Shall execution be stopped?"), LNG("[CAP] Module Execution")) )
+				{
+					PROCESS_Set_Okay(false);
+				}
+			}
+			else if( m_pModule->is_Interactive() )
+			{
+				bResult		= ((CSG_Module_Interactive *)m_pModule)->Execute_Finish();
+				g_pModule	= NULL;
+
+				PROCESS_Set_Okay(true);
+
+				MSG_ADD2(bResult,
+					LNG("[MSG] Interactive module execution has been stopped"),
+					LNG("[MSG] Interactive module execution failed")
+				);
+			}
+		}
+		else
+		{
+			DLG_Message_Show(LNG("[ERR] Can't execute a module while another runs"), LNG("[CAP] Module Execution"));
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		g_pModule	= this;
+
+		if( m_pModule->On_Before_Execution() && (!bDialog || DLG_Parameters(m_pModule->Get_Parameters())) )
+		{
+			g_pModules->Get_Modules_Menu()->Set_Recent(this);
+
+			g_pData->Check_Parameters(m_pModule->Get_Parameters());
+
+			MSG_General_Add_Line();
+			MSG_Execution_Add_Line();
+			MSG_ADD(wxString::Format(wxT("%s: %s"), LNG("[MSG] Executing module"), m_pModule->Get_Name()));
+
+			STATUSBAR_Set_Text(m_pModule->Get_Name());
+
+			bResult		= m_pModule->Execute();
+
+			g_pACTIVE->Get_Parameters()->Update_Parameters(m_pModule->Get_Parameters(), false);
+
+			if( m_pModule->is_Interactive() )
+			{
+				MSG_ADD2(bResult,
+					LNG("[MSG] Interactive module execution has been started"),
+					LNG("[MSG] Interactive module execution failed")
+				);
+			}
+			else
+			{
+				MSG_ADD2(bResult,
+					LNG("[MSG] Module execution succeeded"),
+					LNG("[MSG] Module execution failed")
+				);
+			}
+
+			if( g_pModules && g_pModules->Do_Beep() )	{	Do_Beep();	}
+		}
+
+		if( !m_pModule->is_Interactive() || !bResult )
+		{
+			g_pModule	= NULL;
+		}
+	}
+
+	//-----------------------------------------------------
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Module::Execute(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode, int Keys)
+{
+	bool	bResult	= false;
+
+	if( g_pModule == this && m_pModule->is_Interactive() && !m_pModule->is_Executing() )
+	{
+		bResult	= ((CSG_Module_Interactive *)m_pModule)->Execute_Position(ptWorld, Mode, Keys);
+
+		PROCESS_Set_Okay();
+	}
+
+	return( bResult );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,143 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_Module.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Module : public CWKSP_Base_Item
+{
+public:
+	CWKSP_Module(class CSG_Module *pModule, const wxChar *Menu_Path_default);
+	virtual ~CWKSP_Module(void);
+
+	virtual TWKSP_Item				Get_Type			(void)			{	return( WKSP_ITEM_Module );	}
+
+	virtual wxString				Get_Name			(void);
+	virtual wxString				Get_Description		(void);
+
+	virtual wxMenu *				Get_Menu			(void);
+
+	virtual bool					On_Command			(int Cmd_ID);
+
+	virtual class CSG_Parameters *	Get_Parameters		(void);
+
+	class CSG_Module *				Get_Module			(void)			{	return( m_pModule );	}
+
+	void							Set_Menu_ID			(int Menu_ID);
+	int								Get_Menu_ID			(void)			{	return( m_Menu_ID );	}
+	const wxString &				Get_Menu_Path		(void)			{	return( m_Menu_Path );	}
+
+	void							Set_File_Name		(const wxString &File_Name);
+	const wxString &				Get_File_Name		(void)			{	return( m_File_Name );	}
+
+	bool							is_Interactive		(void);
+	bool							is_Executing		(void);
+
+	bool							Execute				(bool bDialog);
+	bool							Execute				(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode, int Keys);
+
+
+private:
+
+	int								m_Menu_ID;
+
+	wxString						m_Menu_Path, m_File_Name;
+
+	class CSG_Module				*m_pModule;
+
+
+	void							_Save_Script		(void);
+	void							_Save_Script_CMD	(CSG_String &Command, CSG_Parameters *pParameters);
+	void							_Save_Script_Python	(CSG_String &Command, CSG_Parameters *pParameters);
+
+};
+
+//---------------------------------------------------------
+extern CWKSP_Module					*g_pModule;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,198 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Module_Control.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/image.h>
+#include <wx/imaglist.h>
+
+#include "res_controls.h"
+#include "res_images.h"
+
+#include "helper.h"
+
+#include "wksp_module_control.h"
+#include "wksp_module_manager.h"
+#include "wksp_module_library.h"
+#include "wksp_module_menu.h"
+#include "wksp_module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+enum
+{
+	IMG_MANAGER		= 1,
+	IMG_LIBRARY,
+	IMG_MODULE
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+IMPLEMENT_CLASS(CWKSP_Module_Control, CWKSP_Base_Control)
+
+//---------------------------------------------------------
+BEGIN_EVENT_TABLE(CWKSP_Module_Control, CWKSP_Base_Control)
+END_EVENT_TABLE()
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module_Control	*g_pModule_Ctrl	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module_Control::CWKSP_Module_Control(wxWindow *pParent)
+	: CWKSP_Base_Control(pParent, ID_WND_WKSP_MODULES)
+{
+	g_pModule_Ctrl	= this;
+
+	//-----------------------------------------------------
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MODULE_MANAGER)
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MODULE_LIBRARY);
+	IMG_ADD_TO_TREECTRL(ID_IMG_WKSP_MODULE);
+
+	//-----------------------------------------------------
+	_Set_Manager(new CWKSP_Module_Manager);
+
+	Get_Manager()->Initialise();
+}
+
+//---------------------------------------------------------
+CWKSP_Module_Control::~CWKSP_Module_Control(void)
+{
+//	Get_Manager()->Finalise();
+
+	g_pModule_Ctrl	= NULL;
+
+	_Del_Item(m_pManager, true);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Control::On_Execute(wxCommandEvent &event)
+{
+	Get_Manager()->On_Execute(event);
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Control::On_Execute_UI(wxUpdateUIEvent &event)
+{
+	Get_Manager()->On_Execute_UI(event);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Control::Add_Library(CWKSP_Module_Library *pLibrary)
+{
+	if( pLibrary != NULL )
+	{
+		_Add_Item(pLibrary, IMG_LIBRARY, IMG_LIBRARY);
+
+		for(int i=0; i<pLibrary->Get_Count(); i++)
+		{
+			AppendItem(pLibrary->GetId(), pLibrary->Get_Module(i)->Get_Name(), IMG_MODULE, IMG_MODULE, pLibrary->Get_Module(i));
+			pLibrary->Get_Module(i)->Set_File_Name(pLibrary->Get_File_Name());
+		}
+
+		SortChildren(pLibrary->GetId());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_control.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,116 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Module_Control.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Control_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Control_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_control.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Module_Control : public CWKSP_Base_Control
+{
+	DECLARE_CLASS(CWKSP_Module_Control)
+
+public:
+	CWKSP_Module_Control(wxWindow *pParent);
+	virtual ~CWKSP_Module_Control(void);
+
+	class CWKSP_Module_Manager *	Get_Manager			(void)	{	return( (class CWKSP_Module_Manager *)m_pManager );	}
+
+	void							On_Execute			(wxCommandEvent &event);
+	void							On_Execute_UI		(wxUpdateUIEvent &event);
+
+	void							Add_Library			(class CWKSP_Module_Library *pLibrary);
+
+
+private:
+
+
+//---------------------------------------------------------
+DECLARE_EVENT_TABLE()
+};
+
+//---------------------------------------------------------
+extern CWKSP_Module_Control			*g_pModule_Ctrl;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Control_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,354 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Module_Library.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/filename.h>
+
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "helper.h"
+
+#include "wksp_module_library.h"
+#include "wksp_module.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#if defined(_SAGA_MSW)
+	#define ENV_LIB_PATH	wxT("PATH")
+	#define ENV_LIB_SEPA	wxT(';')
+#elif defined(_SAGA_LINUX)
+	#define ENV_LIB_PATH	wxT("LD_LIBRARY_PATH")
+	#define ENV_LIB_SEPA	wxT(':')
+#else
+	#define ENV_LIB_PATH	wxT("PATH")
+	#define ENV_LIB_SEPA	wxT(';')
+#endif
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module_Library::CWKSP_Module_Library(const wxChar *FileName)
+{
+	TSG_PFNC_MLB_Initialize		MLB_Initialize;
+	TSG_PFNC_MLB_Get_Interface	MLB_Get_Interface;
+
+	wxString	sPath;
+	wxFileName	fName(FileName);
+	CSG_Module	*pModule;
+
+	m_pInterface	= NULL;
+
+	fName.MakeAbsolute();
+	m_File_Name		= fName.GetFullPath();
+
+	//-----------------------------------------------------
+	if( wxGetEnv(ENV_LIB_PATH, &sPath) && sPath.Length() > 0 )
+	{
+		wxSetEnv(ENV_LIB_PATH, wxString::Format(wxT("%s%c%s"), sPath.c_str(), ENV_LIB_SEPA, SG_File_Get_Path(FileName).c_str()));
+	}
+	else
+	{
+		wxSetEnv(ENV_LIB_PATH, SG_File_Get_Path(FileName).c_str());
+	}
+
+	//-----------------------------------------------------
+	if( !m_Library.Load(m_File_Name) )
+	{
+		MSG_Error_Add(wxString::Format(wxT("%s:\n%s"), FileName, LNG("[ERR] Library could not be loaded")), true);
+	}
+	else
+	{
+		if( (MLB_Get_Interface	= (TSG_PFNC_MLB_Get_Interface)	m_Library.GetSymbol(SYMBOL_MLB_Get_Interface)) == NULL
+		||	(MLB_Initialize		= (TSG_PFNC_MLB_Initialize)		m_Library.GetSymbol(SYMBOL_MLB_Initialize)   ) == NULL
+		||	!(m_pInterface = MLB_Get_Interface()) || !MLB_Initialize(m_File_Name) )
+		{
+			MSG_Error_Add(wxString::Format(wxT("%s:\n%s"), FileName, LNG("[ERR] Invalid library")), true);
+		}
+		else
+		{
+			while( (pModule = m_pInterface->Get_Module(Get_Count())) != NULL )
+			{
+				Add_Item(new CWKSP_Module(pModule, Get_Info(MLB_INFO_Menu_Path)));
+			}
+
+			if( Get_Count() == 0 )
+			{
+				MSG_Error_Add(wxString::Format(wxT("%s:\n%s"), FileName, LNG("[ERR] Library does not contain any modules")), true);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( sPath.Length() > 0 )
+	{
+		wxSetEnv(ENV_LIB_PATH, sPath);
+	}
+	else
+	{
+		wxUnsetEnv(ENV_LIB_PATH);
+	}
+}
+
+//---------------------------------------------------------
+CWKSP_Module_Library::~CWKSP_Module_Library(void)
+{
+	CWKSP_Module	*pItem;
+
+	if( m_Library.IsLoaded() )
+	{
+		if( is_Valid() )
+		{
+			MSG_General_Add(wxString::Format(wxT("%s: %s..."), LNG("[MSG] Close Library"), m_File_Name.c_str()), true, true);
+
+			while( (pItem = Get_Module(0)) != NULL )
+			{
+				Del_Item(pItem);
+				delete(pItem);
+			}
+
+			m_Library.Unload();
+
+			MSG_General_Add(LNG("[MSG] okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
+		}
+		else
+		{
+			m_Library.Unload();
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Module_Library::Get_Name(void)
+{
+	return( Get_Info(MLB_INFO_Name) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Module_Library::Get_Description(void)
+{
+	int			iModule;
+	wxString	s, sLine;
+
+	s.Printf(wxT("%s: <b>%s</b><br>%s: <i>%s</i><br>%s: <i>%s</i><br>%s: <i>%s</i><hr>%s"),
+		LNG("[CAP] Module Library")	, Get_Info(MLB_INFO_Name),
+		LNG("[CAP] Author")			, Get_Info(MLB_INFO_Author),
+		LNG("[CAP] Version")		, Get_Info(MLB_INFO_Version),
+		LNG("[CAP] File")			, Get_File_Name().c_str(),
+		Get_Info(MLB_INFO_Description)
+	);
+
+	s.Append(wxString::Format(wxT("<hr><b>%s:<ul>"), LNG("[CAP] Modules")));
+
+	for(iModule=0; iModule<Get_Count(); iModule++)
+	{
+		sLine.Printf(wxT("<li>%s</li>"), Get_Module(iModule)->Get_Module()->Get_Name());
+
+		s.Append(sLine);
+	}
+
+	s.Append(wxT("</ul>"));
+
+	s.Replace(wxT("\n"), wxT("<br>"));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Module_Library::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Library::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Module_Library::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command_UI(event) );
+
+	case ID_CMD_WKSP_ITEM_CLOSE:
+		event.Enable(true);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Library::Exists(CWKSP_Module *pModule)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( pModule	== Get_Module(i) )
+		{
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CWKSP_Module * CWKSP_Module_Library::Get_Module_byID(int CMD_ID)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( Get_Module(i)->Get_Menu_ID() == CMD_ID )
+		{
+			return( Get_Module(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Library::is_Valid(void)
+{
+	return( Get_Count() > 0 );
+}
+
+//---------------------------------------------------------
+wxString & CWKSP_Module_Library::Get_File_Name(void)
+{
+	return( m_File_Name );
+}
+
+//---------------------------------------------------------
+const wxChar * CWKSP_Module_Library::Get_Info(int Type)
+{
+	if( m_pInterface != NULL )
+	{
+		return( m_pInterface->Get_Info(Type) );
+	}
+
+	return( wxT("") );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_library.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,130 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Module_Library.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Library_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Library_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dynlib.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Module_Library : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Module_Library(const wxChar *File_Name);
+	virtual ~CWKSP_Module_Library(void);
+
+	virtual TWKSP_Item				Get_Type		(void)		{	return( WKSP_ITEM_Module_Library );	}
+
+	virtual wxString				Get_Name		(void);
+	virtual wxString				Get_Description	(void);
+
+	virtual wxMenu *				Get_Menu		(void);
+
+	virtual bool					On_Command		(int Cmd_ID);
+	virtual bool					On_Command_UI	(wxUpdateUIEvent &event);
+
+	class CWKSP_Module *			Get_Module		(int i)		{	return( (class CWKSP_Module *)Get_Item(i) );	}
+	class CWKSP_Module *			Get_Module_byID	(int CMD_ID);
+
+	bool							is_Valid		(void);
+
+	wxString &						Get_File_Name	(void);
+
+	const wxChar *					Get_Info		(int Type);
+
+	bool							Exists			(class CWKSP_Module *pModule);
+
+
+private:
+
+	class CSG_Module_Library_Interface	*m_pInterface;
+
+	wxString						m_File_Name;
+
+	wxDynamicLibrary				m_Library;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Library_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,622 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Module_Manager.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/dir.h>
+#include <wx/filename.h>
+
+#include <saga_api/saga_api.h>
+
+#include "saga.h"
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_module_manager.h"
+#include "wksp_module_library.h"
+#include "wksp_module_menu.h"
+#include "wksp_module.h"
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module_Manager	*g_pModules	= NULL;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module_Manager::CWKSP_Module_Manager(void)
+{
+	g_pModules	= this;
+
+	m_pMenu		= new CWKSP_Module_Menu;
+
+	//-----------------------------------------------------
+	m_Parameters.Create(this, LNG(""), LNG(""));
+
+	m_Parameters.Add_Value(
+		NULL	, "BEEP"		, LNG("[CAP] Beep when finished"),
+		LNG(""),
+		PARAMETER_TYPE_Bool	, true
+	);
+
+	m_Parameters.Add_Choice(
+		NULL	, "START_LOGO"	, LNG("Show Logo at Start Up"),
+		LNG(""),
+		CSG_String::Format(wxT("%s|%s|%s|%s|"),
+			LNG("do not show"),
+			LNG("only during start up phase"),
+			LNG("20 seconds"),
+			LNG("until user closes it")
+		), 1
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Module_Manager::~CWKSP_Module_Manager(void)
+{
+	delete(m_pMenu);
+
+	g_pModules	= NULL;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::Initialise(void)
+{
+	_Config_Read();
+
+	if( Get_Count() == 0 )
+	{
+#if defined(_SAGA_LINUX)
+	if( _Open_Directory(wxT(MODULE_LIBRARY_PATH)) == 0 )
+#endif
+		_Open_Directory(g_pSAGA->Get_App_Path(), true);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::Finalise(void)
+{
+	_Config_Write();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Module_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] Module Libraries") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Module_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s: %d</b><br><br>%s %d<br>"),
+		LNG("[CAP] Module Libraries")	, Get_Count(),
+		LNG("[CAP] Modules")			, Get_Items_Count()
+	);
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Module_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Module Libraries"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_MODULES_OPEN);
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_MODULES_SAVE_HTML);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_MODULES_OPEN:
+		Open();
+		break;
+
+	case WXK_F2:
+	case ID_CMD_MODULES_SAVE_HTML:
+		_Make_HTML_Docs();
+		break;
+
+	case WXK_F3:
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command_UI(event) );
+
+	case ID_CMD_WKSP_ITEM_CLOSE:
+		event.Enable(Get_Count() > 0 && g_pModule == NULL);
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Manager::On_Execute(wxCommandEvent &event)
+{
+	CWKSP_Module	*pModule;
+
+	if( (pModule = Get_Module_byID(m_pMenu->Get_ID_Translated(event.GetId()))) != NULL )
+	{
+		pModule->On_Command(ID_CMD_WKSP_ITEM_RETURN);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Manager::On_Execute_UI(wxUpdateUIEvent &event)
+{
+	if( g_pModule )
+	{
+		if( g_pModule->Get_Menu_ID() == m_pMenu->Get_ID_Translated(event.GetId()) )
+		{
+			event.Enable(true);
+			event.Check(true);
+		}
+		else
+		{
+			event.Enable(false);
+			event.Check(false);
+		}
+	}
+	else
+	{
+		event.Enable(true);
+		event.Check(false);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::Do_Beep(void)
+{
+	return( m_Parameters("BEEP")->asBool() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define CFG_LIBS	wxT("/LIBS")
+#define CFG_LIBF	wxT("LIB_%03d")
+
+//---------------------------------------------------------
+void CWKSP_Module_Manager::_Config_Read(void)
+{
+	bool		bValue;
+	long		lValue;
+	wxString	sValue;
+
+	if( CONFIG_Read(wxT("/MODULES"), wxT("BEEP")		, bValue) )
+	{
+		m_Parameters("BEEP")		->Set_Value(bValue);
+	}
+
+	if( CONFIG_Read(wxT("/MODULES"), wxT("START_LOGO")	, lValue) )
+	{
+		m_Parameters("START_LOGO")	->Set_Value((int)lValue);
+	}
+
+	for(int i=0; CONFIG_Read(CFG_LIBS, wxString::Format(CFG_LIBF, i), sValue); i++)
+	{
+		Open(sValue);
+	}
+
+	m_pMenu->Update();
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Manager::_Config_Write(void)
+{
+	CONFIG_Write(wxT("/MODULES")	, wxT("BEEP")		,		m_Parameters("BEEP")		->asBool());
+	CONFIG_Write(wxT("/MODULES")	, wxT("START_LOGO")	, (long)m_Parameters("START_LOGO")	->asInt());
+
+	CONFIG_Delete(CFG_LIBS);
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		CONFIG_Write(CFG_LIBS, wxString::Format(CFG_LIBF, i), Get_Library(i)->Get_File_Name());
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Module_Manager::_Open_Directory(const wxChar *sDirectory, bool bOnlySubDirectories)
+{
+	int			nOpened	= 0;
+	wxDir		Dir;
+	wxString	FileName;
+
+	if( Dir.Open(sDirectory) )
+	{
+		if( !bOnlySubDirectories && Dir.GetFirst(&FileName, wxEmptyString, wxDIR_FILES) )
+		{
+			do
+			{	if( FileName.Find(wxT("saga_api")) < 0 && FileName.Find(wxT("saga_gdi")) < 0 && FileName.Find(wxT("wx")) < 0 && FileName.Find(wxT("mingw")) < 0 )
+				if( Open(SG_File_Make_Path(Dir.GetName(), FileName, NULL)) )
+				{
+					nOpened++;
+				}
+			}
+			while( Dir.GetNext(&FileName) );
+		}
+
+		if( Dir.GetFirst(&FileName, wxEmptyString, wxDIR_DIRS) )
+		{
+			do
+			{
+				nOpened	+= _Open_Directory(SG_File_Make_Path(Dir.GetName(), FileName, NULL));
+			}
+			while( Dir.GetNext(&FileName) );
+		}
+	}
+
+	return( nOpened );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Manager::Open(void)
+{
+	wxArrayString	File_Paths;
+
+	if( DLG_Open(File_Paths, ID_DLG_MODULES_OPEN) )
+	{
+		MSG_General_Add_Line();
+
+		for(size_t i=0; i<File_Paths.GetCount(); i++)
+		{
+			Open(File_Paths[i]);
+		}
+
+		m_pMenu->Update();
+	}
+}
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::Open(const wxChar *File_Name)
+{
+	CWKSP_Module_Library	*pLibrary;
+
+	//-----------------------------------------------------
+	if( SG_File_Cmp_Extension(File_Name, SG_T("mlb"))
+	||	SG_File_Cmp_Extension(File_Name, wxT("dll"))
+	||	SG_File_Cmp_Extension(File_Name, wxT("so")) )
+	{
+		MSG_General_Add(wxString::Format(wxT("%s: %s..."), LNG("[MSG] Load library"), File_Name), true, true);
+
+		//-------------------------------------------------
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( SG_STR_CMP(File_Name, Get_Library(i)->Get_File_Name()) == 0 )
+			{
+				MSG_Error_Add(wxString::Format(wxT("%s\n%s"), File_Name, LNG("[ERR] Library has already been loaded")), true);
+				MSG_General_Add(LNG("[MSG] has already been loaded"), false);
+
+				return( false );
+			}
+		}
+
+		//-------------------------------------------------
+		pLibrary	= new CWKSP_Module_Library(File_Name);
+
+		if( pLibrary->is_Valid() )
+		{
+			Add_Item(pLibrary);
+
+			MSG_General_Add(LNG("[MSG] okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
+
+			return( true );
+		}
+
+		delete(pLibrary);
+
+		MSG_General_Add(LNG("[MSG] failed"), false, false, SG_UI_MSG_STYLE_FAILURE);
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Module_Manager::Exists(CWKSP_Module *pModule)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( Get_Library(i)->Exists(pModule) )
+		{
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+CWKSP_Module * CWKSP_Module_Manager::Get_Module_byID(int CMD_ID)
+{
+	CWKSP_Module	*pModule;
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( (pModule = Get_Library(i)->Get_Module_byID(CMD_ID)) != NULL )
+		{
+			return( pModule );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Manager::_Make_HTML_Docs(void)
+{
+	CSG_Parameters	Options(NULL, LNG("Create HTML Documentation"), LNG(""));
+
+	Options.Add_FilePath(NULL, "DIR", LNG("Choose Documentation Folder"), LNG(""), NULL, NULL, true, true);
+
+	if( !DLG_Parameters(&Options) )
+	{
+		return;
+	}
+
+	//-----------------------------------------------------
+	bool			bDirectory;
+	CSG_File		Stream_Module, Stream_Lib, Stream_Libs, Stream_List;
+	wxString		LibName, Directory, Main, s;
+	wxFileName		FileName;
+
+	MSG_General_Add(wxString::Format(wxT("%s..."), LNG("Creating module documentation files")), true, true);
+
+	bDirectory	= wxDirExists(Options("DIR")->asString());
+	Directory	= bDirectory ? Options("DIR")->asString() : SG_File_Get_Path(g_pSAGA->Get_App_Path()).c_str();
+
+	//-----------------------------------------------------
+	FileName.AssignDir	(Directory);
+	FileName.SetExt		(wxT("html"));
+	FileName.SetName	(wxT("index"));
+
+	Stream_Libs.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false);
+	Stream_Libs.Printf(SG_T("<html><head><title>SAGA - System for Automated Geoscientific Analyses</title></head><body>"));
+	Stream_Libs.Printf(SG_T("<h1><a href=\"http://www.saga-gis.org\">SAGA - System for Automated Geoscientific Analyses</a></h1>"));
+	Stream_Libs.Printf(SG_T("<h2>%s</h2>\n<ul>\n"), LNG("Module Library Descriptions"));
+
+	Main		= FileName.GetFullPath();
+
+	//-----------------------------------------------------
+	for(int i=0; i<Get_Count() && PROGRESSBAR_Set_Position(i, Get_Count()); i++)
+	{
+		LibName				= SG_File_Get_Name(Get_Library(i)->Get_File_Name(), false).c_str();
+		FileName.AssignDir	(bDirectory ? Directory.c_str() : SG_File_Get_Path(Get_Library(i)->Get_File_Name()).c_str());
+		FileName.AppendDir	(LibName);
+		FileName.SetExt		(wxT("html"));
+
+		if( wxDirExists(FileName.GetPath()) || wxMkdir(FileName.GetPath()) )
+		{
+			//---------------------------------------------
+			// create a frame
+
+			FileName.SetName(wxT("index"));
+
+			if( Stream_Lib.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false) )
+			{
+				if( Stream_Libs.is_Open() )
+				{
+					s	= Get_FilePath_Relative(Directory.c_str(), FileName.GetFullPath().c_str()).c_str();	if( s[0] == '\\' )	s	= s.AfterFirst('\\');
+					Stream_Libs.Printf(wxT("<li><a href=\"%s\">%s</a></li>\n"), s.c_str(), Get_Library(i)->Get_Name().c_str());
+				}
+
+				Stream_Lib.Printf(SG_T("<html><head><title>SAGA - System for Automated Geoscientific Analyses</title></head>"));
+				Stream_Lib.Printf(SG_T("<frameset cols=\"200,*\" frameborder=\"0\" framespacing=\"0\" border=\"0\">"));
+				Stream_Lib.Printf(SG_T("  <frame frameborder=\"0\" noresize src=\"modules.html\" name=\"MODULES\">"));
+				Stream_Lib.Printf(SG_T("  <frame frameborder=\"0\" noresize src=\"%s.html\" name=\"CONTENT\">")   , LibName.c_str());
+				Stream_Lib.Printf(SG_T("</frameset></html>"));
+			}
+
+			//---------------------------------------------
+			// write the modules
+
+			if( bDirectory )
+				s	= wxT("./../index");
+			else
+				s	= Get_FilePath_Relative(Main.c_str(), FileName.GetFullPath().c_str()).c_str();	if( s[0] == '\\' )	s	= s.AfterFirst('\\');
+
+			FileName.SetName(wxT("modules"));
+			Stream_List.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false);
+			Stream_List.Printf(SG_T("<body bgcolor=\"#CCCCCC\">"));
+			Stream_List.Printf(SG_T("<b><a target=\"_top\"    href=\"http://www.saga-gis.org\">SAGA</a></b><hr>"));
+			Stream_List.Printf(SG_T("<b><a target=\"_top\"    href=\"%s.html\">%s</a></b><hr>"), s.c_str(), LNG("Library Overview"));
+			Stream_List.Printf(SG_T("<b><a target=\"CONTENT\" href=\"%s.html\">%s</a></b><hr><ul>"), LibName.c_str(), Get_Library(i)->Get_Name().c_str());
+
+			FileName.SetName(LibName);
+
+			if( Stream_Lib.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false) )
+			{
+				Stream_Lib.Printf(wxT("%s<hr><ul>"), Get_Library(i)->Get_Description().c_str());
+
+				for(int j=0; j<Get_Library(i)->Get_Count(); j++)
+				{
+					FileName.SetName(wxString::Format(wxT("%s_%02d"), LibName.c_str(), Get_Library(i)->Get_Module(j)->Get_Index()));
+
+					if( Stream_Module.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false) )
+					{
+						Stream_Module.Printf(wxT("%s"), Get_Library(i)->Get_Module(j)->Get_Description().c_str());
+
+						Stream_Lib .Printf(wxT("<li><a target=\"CONTENT\" href=\"%s\">%s</a></li>"), FileName.GetFullName().c_str(), Get_Library(i)->Get_Module(j)->Get_Name().c_str());
+						Stream_List.Printf(wxT("<li><a target=\"CONTENT\" href=\"%s\">%s</a></li>"), FileName.GetFullName().c_str(), Get_Library(i)->Get_Module(j)->Get_Name().c_str());
+					}
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( Stream_Libs.is_Open() )
+	{
+		Stream_Libs.Printf(wxT("</ul>"));
+	}
+
+	PROCESS_Set_Okay(true);
+
+	MSG_General_Add(LNG("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,149 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Module_Manager.h                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Module_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Module_Manager(void);
+	virtual ~CWKSP_Module_Manager(void);
+
+	bool							Initialise			(void);
+	bool							Finalise			(void);
+
+	virtual TWKSP_Item				Get_Type			(void)		{	return( WKSP_ITEM_Module_Manager );	}
+
+	virtual wxString				Get_Name			(void);
+	virtual wxString				Get_Description		(void);
+
+	virtual wxMenu *				Get_Menu			(void);
+
+	virtual bool					On_Command			(int Cmd_ID);
+	virtual bool					On_Command_UI		(wxUpdateUIEvent &event);
+
+	virtual class CSG_Parameters *		Get_Parameters		(void)		{	return( &m_Parameters );	}
+
+	void							On_Execute			(wxCommandEvent  &event);
+	void							On_Execute_UI		(wxUpdateUIEvent &event);
+
+	class CWKSP_Module_Library *	Get_Library			(int i)		{	return( (class CWKSP_Module_Library *)Get_Item(i) );	}
+
+	class CWKSP_Module_Menu *		Get_Modules_Menu	(void)		{	return( m_pMenu );	}
+
+	bool							Do_Beep				(void);
+
+	void							Open				(void);
+	bool							Open				(const wxChar *File_Name);
+
+	bool							Exists				(class CWKSP_Module *pModule);
+
+	class CWKSP_Module *			Get_Module_byID		(int CMD_ID);
+
+
+private:
+
+	CSG_Parameters						m_Parameters;
+
+	class CWKSP_Module_Menu			*m_pMenu;
+
+
+	void							_Config_Read		(void);
+	void							_Config_Write		(void);
+
+	int								_Open_Directory		(const wxChar *sDirectory, bool bOnlySubDirectories = false);
+
+	void							_Make_HTML_Docs		(void);
+
+};
+
+//---------------------------------------------------------
+extern CWKSP_Module_Manager			*g_pModules;
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,362 @@
+	
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Module_Menu.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+
+#include "wksp_module_manager.h"
+#include "wksp_module_library.h"
+#include "wksp_module_menu.h"
+#include "wksp_module.h"
+#include <wx/tokenzr.h>
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Module_Menu::CWKSP_Module_Menu(void)
+{
+	m_Recent	= (CWKSP_Module **)SG_Calloc(RECENT_COUNT, sizeof(CWKSP_Module *));
+
+	m_Menus		= NULL;
+	m_nMenus	= 0;
+}
+
+//---------------------------------------------------------
+CWKSP_Module_Menu::~CWKSP_Module_Menu(void)
+{
+	SG_Free(m_Recent);
+
+	Destroy();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::Destroy(void)
+{
+	if( m_Menus )
+	{
+		SG_Free(m_Menus);
+		m_Menus		= NULL;
+		m_nMenus	= 0;
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::Add(wxMenu *pMenu)
+{
+	_Update(pMenu);
+
+	m_Menus	= (wxMenu **)SG_Realloc(m_Menus, (m_nMenus + 1) * sizeof(wxMenu *));
+	m_Menus[m_nMenus++]	= pMenu;
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::Del(wxMenu *pMenu)
+{
+	for(int i=0; i<m_nMenus; i++)
+	{
+		if( m_Menus[i] == pMenu )
+		{
+			m_nMenus--;
+
+			for( ; i<m_nMenus; i++)
+			{
+				m_Menus[i]	= m_Menus[i + 1];
+			}
+
+			m_Menus	= (wxMenu **)SG_Realloc(m_Menus, m_nMenus * sizeof(wxMenu *));
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::Update(void)
+{
+	for(int i=0; i<m_nMenus; i++)
+	{
+		_Update(m_Menus[i]);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::_Update(wxMenu *pMenu)
+{
+	int						iLibrary, iModule, ID_Menu;
+	wxMenu					*pSubMenu;
+	CWKSP_Module_Library	*pLibrary;
+	CWKSP_Module			*pModule;
+
+	//-----------------------------------------------------
+	while( (ID_Menu = pMenu->GetMenuItemCount()) > 0 )
+	{
+		pMenu->Destroy(pMenu->GetMenuItems().Item(ID_Menu - 1)->GetData());
+	}
+
+	//-----------------------------------------------------
+	if( g_pModules->Get_Count() > 0 )
+	{
+		for(iLibrary=0, ID_Menu=ID_CMD_MODULE_START; iLibrary<g_pModules->Get_Count(); iLibrary++)
+		{
+			pLibrary	= g_pModules->Get_Library(iLibrary);
+
+			for(iModule=0; iModule<pLibrary->Get_Count(); iModule++, ID_Menu++)
+			{
+				pModule		= pLibrary->Get_Module(iModule);
+				pModule		->Set_Menu_ID(ID_Menu);
+				pSubMenu	= _Get_SubMenu(pMenu, pModule->Get_Menu_Path());
+
+				size_t	iPos;
+
+				for(iPos=0; iPos<pSubMenu->GetMenuItemCount(); iPos++)
+				{
+#if defined(MODULES_MENU_SORT_SIMPLE)
+					if( pSubMenu->FindItemByPosition(iPos)->GetLabel().Cmp(pModule->Get_Name()) > 0 )
+#else
+					if(	pSubMenu->FindItemByPosition(iPos)->IsSubMenu() == false
+					&&	pSubMenu->FindItemByPosition(iPos)->GetLabel().Cmp(pModule->Get_Name()) > 0 )
+#endif
+						break;
+				}
+
+				pSubMenu->InsertCheckItem(iPos, ID_Menu, pModule->Get_Name(), pModule->Get_Name());
+			//	pSubMenu->AppendCheckItem(ID_Menu, pModule->Get_Name(), pModule->Get_Name());
+			}
+		}
+
+		pMenu->InsertSeparator(0);
+		CMD_Menu_Ins_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE, 0);
+		CMD_Menu_Ins_Item(pMenu, false, ID_CMD_MODULES_OPEN	, 0);
+
+		_Set_Recent(pMenu);
+	}
+	else
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_MODULES_OPEN);
+	}
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Module_Menu::_Get_SubMenu(wxMenu *pMenu, wxString Menu_Path)
+{
+	wxStringTokenizer	*tk;
+	wxString			sSubMenu;
+	wxMenu				*pSubMenu;
+
+	tk			= new wxStringTokenizer(Menu_Path, SG_T("|"));
+	sSubMenu	= tk->GetNextToken();
+
+	while( ! sSubMenu.IsNull() )
+	{
+		pSubMenu	= _Find_SubMenu_For_Token(pMenu, sSubMenu);
+
+		if( ! pSubMenu )
+		{
+			pSubMenu	= new wxMenu();
+
+			size_t	iPos;
+
+			for(iPos=0; iPos<pMenu->GetMenuItemCount(); iPos++)
+			{
+#if defined(MODULES_MENU_SORT_SIMPLE)
+				if( pMenu->FindItemByPosition(iPos)->GetLabel().Cmp(sSubMenu) > 0 )
+#else
+				if(	pMenu->FindItemByPosition(iPos)->IsSubMenu() == false
+				||	pMenu->FindItemByPosition(iPos)->GetLabel().Cmp(sSubMenu) > 0 )
+#endif
+					break;
+			}
+
+			pMenu->Insert(iPos, ID_CMD_MODULES_FIRST, sSubMenu, pSubMenu);
+		//	pMenu->Append(ID_CMD_MODULES_FIRST, sSubMenu, pSubMenu);
+		}
+
+		pMenu		= pSubMenu;
+		sSubMenu	= tk->GetNextToken();
+	}
+
+	delete tk;
+
+	return pMenu;
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Module_Menu::_Find_SubMenu_For_Token( wxMenu* menu, wxString token ) {
+	
+	wxMenuItem* item;
+	wxMenu* result = NULL;
+	
+	for( size_t i = 0; i < menu->GetMenuItemCount(); i++ ) {
+		item = menu->GetMenuItems()[ i ];
+		if ( item->GetLabel() == token ) {
+			result = item->GetSubMenu();
+			break;
+		}
+	}
+	return result;
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::Set_Recent(CWKSP_Module *pModule)
+{
+	int				i;
+	CWKSP_Module	*pNext, *pLast;
+
+	//-----------------------------------------------------
+	pLast	= pModule;
+	pNext	= m_Recent[0];
+
+	for(i=0; i<RECENT_COUNT && pNext!=pModule; i++)
+	{
+		pNext		= m_Recent[i];
+		m_Recent[i]	= pLast;
+		pLast		= pNext;
+	}
+
+	//-----------------------------------------------------
+	for(i=0; i<m_nMenus; i++)
+	{
+		_Update(m_Menus[i]);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Module_Menu::_Set_Recent(wxMenu *pMenu)
+{
+	bool	bRecent;
+	int		i, j;
+
+	//-----------------------------------------------------
+	for(i=0, j=ID_CMD_MODULE_RECENT_FIRST, bRecent=false; i<RECENT_COUNT; i++, j++)
+	{
+		if( m_Recent[i] && g_pModules->Exists(m_Recent[i]) )
+		{
+			if( !bRecent )
+			{
+				bRecent	= true;
+
+				pMenu->AppendSeparator();
+			}
+
+			pMenu->AppendCheckItem(j, m_Recent[i]->Get_Name(), m_Recent[i]->Get_Name());
+		}
+		else
+		{
+			m_Recent[i]	= NULL;
+		}
+	}
+
+	//-----------------------------------------------------
+	for(i=0, j=0; j<RECENT_COUNT; j++)
+	{
+		if( m_Recent[j] )
+		{
+			m_Recent[i++]	= m_Recent[j];
+		}
+	}
+
+	for(; i<RECENT_COUNT; i++)
+	{
+		m_Recent[i]	= NULL;
+	}
+}
+
+//---------------------------------------------------------
+int CWKSP_Module_Menu::Get_ID_Translated(int ID)
+{
+	int		i	= ID - ID_CMD_MODULE_RECENT_FIRST;
+
+	if( i >= 0 && i < RECENT_COUNT && m_Recent[i] != NULL )
+	{
+		return( m_Recent[i]->Get_Menu_ID() );
+	}
+
+	return( ID );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_module_menu.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,113 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Module_Menu.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Menu_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Menu_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Module_Menu
+{
+public:
+	CWKSP_Module_Menu(void);
+	virtual ~CWKSP_Module_Menu(void);
+
+	void						Destroy				(void);
+
+	void						Add					(class wxMenu *pMenu);
+	void						Del					(class wxMenu *pMenu);
+
+	void						Update				(void);
+
+	void						Set_Recent			(class CWKSP_Module *pModule);
+
+	int							Get_ID_Translated	(int ID);
+
+
+private:
+
+	int							m_nMenus;
+
+	class wxMenu				**m_Menus;
+
+	class CWKSP_Module			**m_Recent;
+
+
+	void						_Update				(class wxMenu *pMenu);
+	class wxMenu *				_Get_SubMenu		(class wxMenu *pMenu, wxString Menu_Path);
+	class wxMenu* 				_Find_SubMenu_For_Token( wxMenu* menu, wxString token );
+	void						_Set_Recent			(class wxMenu *pMenu);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Module_Menu_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,525 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_PointCloud.cpp                  //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+
+#include "helper.h"
+
+#include "wksp_map_control.h"
+
+#include "wksp_layer_classify.h"
+
+#include "wksp_pointcloud.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_PointCloud::CWKSP_PointCloud(CSG_PointCloud *pPointCloud)
+	: CWKSP_Layer(pPointCloud)
+{
+	m_pPointCloud	= pPointCloud;
+
+	m_Edit_Attributes.Destroy();
+	m_Edit_Attributes.Add_Field(LNG("[CAP] Name") , SG_DATATYPE_String);
+	m_Edit_Attributes.Add_Field(LNG("[CAP] Value"), SG_DATATYPE_String);
+
+	Create_Parameters();
+
+	//-----------------------------------------------------
+	m_Parameters("COLORS_TYPE")		->Set_Value(CLASSIFY_METRIC);
+	m_Parameters("COLORS_ATTRIB")	->Set_Value(2);
+
+	On_Parameter_Changed(&m_Parameters, m_Parameters("COLORS_ATTRIB"));
+
+	Parameters_Changed();
+}
+
+//---------------------------------------------------------
+CWKSP_PointCloud::~CWKSP_PointCloud(void)
+{}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_PointCloud::Get_Name(void)
+{
+	return( wxString::Format(wxT("%02d. %s"), 1 + Get_ID(), m_pPointCloud->Get_Name()) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_PointCloud::Get_Description(void)
+{
+	wxString	s;
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<b>%s</b><table border=\"0\">"),
+		LNG("[CAP] Point Cloud")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, m_pPointCloud->Get_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] File")					, m_pPointCloud->Get_File_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Number of Points")		, m_pPointCloud->Get_Count()
+	));
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<table border=\"1\"><tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th>"),
+		LNG("[CAP] Field"),
+		LNG("[CAP] Name"),
+		LNG("[CAP] Type"),
+		LNG("[CAP] Minimum"),
+		LNG("[CAP] Maximum"),
+		LNG("[CAP] Mean"),
+		LNG("[CAP] Standard Deviation")
+	));
+
+	for(int i=0; i<m_pPointCloud->Get_Field_Count(); i++)
+	{
+		s.Append(wxString::Format(wxT("<tr><td>%d</td><td>%s</td><td>%s</td><td>%f</td><td>%f</td><td>%f</td><td>%f</td></tr>"),
+			i + 1,
+			m_pPointCloud->Get_Field_Name(i),
+			SG_Data_Type_Get_Name(m_pPointCloud->Get_Field_Type(i)),
+			m_pPointCloud->Get_Minimum(i),
+			m_pPointCloud->Get_Maximum(i),
+			m_pPointCloud->Get_Mean(i),
+			m_pPointCloud->Get_StdDev(i)
+		));
+	}
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+//	s.Append(wxString::Format(wxT("<hr><b>%s</b><font size=\"-1\">"), LNG("[CAP] Data History")));
+//	s.Append(m_pPointCloud->Get_History().Get_HTML());
+//	s.Append(wxString::Format(wxT("</font")));
+
+	//-----------------------------------------------------
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_PointCloud::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(m_pPointCloud->Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_POINTCLOUD_SHOW);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_POINTCLOUD_SAVE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_POINTCLOUD_SAVEAS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SETTINGS_COPY);
+
+//	pMenu->AppendSeparator();
+
+//	wxMenu	*pTable	= new wxMenu(LNG("[MNU] Table"));
+//	CMD_Menu_Add_Item(pTable,  true, ID_CMD_TABLES_SHOW);
+//	CMD_Menu_Add_Item(pTable,  true, ID_CMD_TABLES_DIAGRAM);
+//	CMD_Menu_Add_Item(pTable, false, ID_CMD_TABLES_SCATTERPLOT);
+//	pMenu->Append(ID_CMD_WKSP_FIRST, LNG("[MNU] Attributes"), pTable);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Layer::On_Command(Cmd_ID) );
+
+	case ID_CMD_POINTCLOUD_LAST:
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Layer::On_Command_UI(event) );
+
+	case ID_CMD_POINTCLOUD_LAST:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_PointCloud::On_Create_Parameters(void)
+{
+	//-----------------------------------------------------
+	// General...
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_COLORS")		, "COLORS_ATTRIB"			, LNG("[CAP] Attribute"),
+		LNG(""),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_COLORS")		, "COLORS_AGGREGATE"		, LNG("[CAP] Value Aggregation"),
+		LNG(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
+			LNG("first value"),
+			LNG("last value"),
+			LNG("lowest z"),
+			LNG("highest z")
+		), 1
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_SIZE"			, LNG("[CAP] Point Size"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 0, 0, true
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_TRANSPARENCY"	, LNG("[CAP] Transparency [%]"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true, 100.0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_PointCloud::On_DataObject_Changed(void)
+{
+	int			i;
+	wxString	sChoices;
+
+	for(i=0; i<m_pPointCloud->Get_Field_Count(); i++)
+	{
+		sChoices.Append(wxString::Format(wxT("%s|"), m_pPointCloud->Get_Field_Name(i)));
+	}
+
+	m_Parameters("COLORS_ATTRIB")->asChoice()->Set_Items(sChoices);
+}
+
+//---------------------------------------------------------
+void CWKSP_PointCloud::On_Parameters_Changed(void)
+{
+	if( (m_Color_Field = m_Parameters("COLORS_ATTRIB")->asInt()) >= m_pPointCloud->Get_Field_Count() )
+	{
+		m_Color_Field	= -1;
+	}
+
+	long	DefColor	= m_Parameters("UNISYMBOL_COLOR")->asColor();
+	m_Color_Pen			= wxColour(SG_GET_R(DefColor), SG_GET_G(DefColor), SG_GET_B(DefColor));
+
+	m_PointSize			= m_Parameters("DISPLAY_SIZE")	->asInt();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_PointCloud::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	if(	!SG_STR_CMP(pParameter->Get_Identifier(), wxT("COLORS_ATTRIB")) )
+	{
+		CSG_Parameters	Parameters;
+	
+		int		zField	= pParameter->asInt();
+
+		double	m	= m_pPointCloud->Get_Mean  (zField);
+		double	s	= m_pPointCloud->Get_StdDev(zField) * 2.0;
+		double	min	= m - s;	if( min < m_pPointCloud->Get_Minimum(zField) )	min	= m_pPointCloud->Get_Minimum(zField);
+		double	max	= m + s;	if( max > m_pPointCloud->Get_Maximum(zField) )	max	= m_pPointCloud->Get_Maximum(zField);
+
+		pParameters->Get_Parameter("METRIC_ZRANGE")->asRange()->Set_Range(min, max);
+	}
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_PointCloud::Get_Value(CSG_Point ptWorld, double Epsilon)
+{
+	return( LNG("") );
+}
+
+//---------------------------------------------------------
+double CWKSP_PointCloud::Get_Value_Range(void)
+{
+	return( m_Color_Field >= 0 ? m_pPointCloud->Get_Range(m_Color_Field) : 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud::asImage(CSG_Grid *pImage)
+{
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud::On_Edit_On_Mouse_Up(CSG_Point Point, double ClientToWorld, int Key)
+{
+	CSG_Rect	rWorld(m_Edit_Mouse_Down, Point);
+
+	if( rWorld.Get_XRange() == 0.0 && rWorld.Get_YRange() == 0.0 )
+	{
+		rWorld.Inflate(2.0 * ClientToWorld, false);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud::On_Edit_Set_Attributes(void)
+{
+	return( true );
+}
+
+//---------------------------------------------------------
+TSG_Rect CWKSP_PointCloud::On_Edit_Get_Extent(void)
+{
+	return( m_pPointCloud->Get_Extent() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_PointCloud::On_Draw(CWKSP_Map_DC &dc_Map, bool bEdit)
+{
+	if( Get_Extent().Intersects(dc_Map.m_rWorld) != INTERSECTION_None && dc_Map.IMG_Draw_Begin(m_Parameters("DISPLAY_TRANSPARENCY")->asDouble() / 100.0) )
+	{
+		_Draw_Points	(dc_Map);
+
+		dc_Map.IMG_Draw_End();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CWKSP_PointCloud::_Draw_Point(CWKSP_Map_DC &dc_Map, int x, int y, double z, int Color)
+{
+	if( m_Aggregation == 1 || m_Z.is_InGrid(x, y) )
+	{
+		switch( m_Aggregation )
+		{
+		case 0:	// first value
+			if( m_N.asInt(x, y) == 0 )
+			{
+				dc_Map.IMG_Set_Pixel(x, y, Color);
+			}
+			break;
+
+		case 1:	// last value
+			dc_Map.IMG_Set_Pixel(x, y, Color);
+			break;
+
+		case 2:	// lowest z
+			if( m_N.asInt(x, y) == 0 || z < m_Z.asDouble(x, y) )
+			{
+				dc_Map.IMG_Set_Pixel(x, y, Color);
+				m_Z.Set_Value(x, y, z);
+			}
+			break;
+
+		case 3:	// highest z
+			if( m_N.asInt(x, y) == 0 || z > m_Z.asDouble(x, y) )
+			{
+				dc_Map.IMG_Set_Pixel(x, y, Color);
+				m_Z.Set_Value(x, y, z);
+			}
+			break;
+		}
+
+		m_N.Add_Value(x, y, 1);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_PointCloud::_Draw_Point(CWKSP_Map_DC &dc_Map, int x, int y, double z, int Color, int Radius)
+{
+	_Draw_Point(dc_Map, x, y, z, Color);
+
+	for(int iy=1; iy<=Radius; iy++)
+	{
+		for(int ix=0; ix<=Radius; ix++)
+		{
+			if( ix*ix + iy*iy <= Radius*Radius )
+			{
+				_Draw_Point(dc_Map, x + ix, y + iy, z, Color);
+				_Draw_Point(dc_Map, x + iy, y - ix, z, Color);
+				_Draw_Point(dc_Map, x - ix, y - iy, z, Color);
+				_Draw_Point(dc_Map, x - iy, y + ix, z, Color);
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_PointCloud::_Draw_Points(CWKSP_Map_DC &dc_Map)
+{
+	m_Aggregation	= m_Parameters("COLORS_AGGREGATE")->asInt();
+
+	if( m_Aggregation != 1 )
+	{
+		m_Z.Create(SG_DATATYPE_Double, dc_Map.m_rDC.GetWidth(), dc_Map.m_rDC.GetHeight());
+		m_N.Create(SG_DATATYPE_Int   , dc_Map.m_rDC.GetWidth(), dc_Map.m_rDC.GetHeight());
+	}
+
+	//-----------------------------------------------------
+	for(int i=0; i<m_pPointCloud->Get_Count(); i++)
+	{
+		TSG_Point_3D	Point	= m_pPointCloud->Get_Point(i);
+
+		if( dc_Map.m_rWorld.Contains(Point.x, Point.y) )
+		{
+			int		Color;
+			int		x	= (int)dc_Map.xWorld2DC(Point.x);
+			int		y	= (int)dc_Map.yWorld2DC(Point.y);
+
+			m_pClassify->Get_Class_Color_byValue(m_pPointCloud->Get_Value(i, m_Color_Field), Color);
+
+			_Draw_Point(dc_Map, x, y, Point.z, Color, m_PointSize);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,140 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_PointCloud.h                    //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_PointCloud_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_PointCloud_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_layer.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_PointCloud : public CWKSP_Layer
+{
+public:
+	CWKSP_PointCloud(CSG_PointCloud *pPointCloud);
+	virtual ~CWKSP_PointCloud(void);
+
+	virtual TWKSP_Item			Get_Type				(void)	{	return( WKSP_ITEM_PointCloud );	}
+
+	virtual wxString			Get_Name				(void);
+	virtual wxString			Get_Description			(void);
+
+	virtual wxMenu *			Get_Menu				(void);
+
+	virtual bool				On_Command				(int Cmd_ID);
+	virtual bool				On_Command_UI			(wxUpdateUIEvent &event);
+
+	CSG_PointCloud *			Get_PointCloud			(void)	{	return( m_pPointCloud );	}
+
+	virtual wxString			Get_Value				(CSG_Point ptWorld, double Epsilon);
+	virtual double				Get_Value_Range			(void);
+
+	bool						asImage					(CSG_Grid *pImage);
+
+
+protected:
+
+	int							m_Color_Field, m_PointSize, m_Aggregation;
+
+	wxColour					m_Color_Pen;
+
+	CSG_PointCloud				*m_pPointCloud;
+
+	CSG_Grid					m_Z, m_N;
+
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool				On_Edit_On_Mouse_Up		(CSG_Point Point, double ClientToWorld, int Key);
+	virtual bool				On_Edit_Set_Attributes	(void);
+	virtual TSG_Rect			On_Edit_Get_Extent		(void);
+
+	virtual void				On_Draw					(CWKSP_Map_DC &dc_Map, bool bEdit);
+
+	void						_Draw_Point				(CWKSP_Map_DC &dc_Map, int x, int y, double z, int Color);
+	void						_Draw_Point				(CWKSP_Map_DC &dc_Map, int x, int y, double z, int Color, int Radius);
+	void						_Draw_Points			(CWKSP_Map_DC &dc_Map);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_PointCloud_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,320 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//              WKSP_PointCloud_Manager.cpp              //
+//                                                       //
+//          Copyright (C) 2009 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_map_manager.h"
+
+#include "wksp_pointcloud_manager.h"
+#include "wksp_pointcloud.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_PointCloud_Manager::CWKSP_PointCloud_Manager(void)
+{
+}
+
+//---------------------------------------------------------
+CWKSP_PointCloud_Manager::~CWKSP_PointCloud_Manager(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_PointCloud_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] PointCloud") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_PointCloud_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b>:%d<br>"), LNG("[CAP] PointCloud"), Get_Count());
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_PointCloud_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] PointCloud"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_POINTCLOUD_OPEN);
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_PointCloud * CWKSP_PointCloud_Manager::Get_PointCloud(CSG_PointCloud *pPointCloud)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( pPointCloud == Get_PointCloud(i)->Get_PointCloud() )
+		{
+			return( Get_PointCloud(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::Exists(CSG_PointCloud *pPointCloud)
+{
+	return( Get_PointCloud(pPointCloud) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_PointCloud * CWKSP_PointCloud_Manager::Add(CSG_PointCloud *pPointCloud)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( pPointCloud && !Exists(pPointCloud) && Add_Item(pItem = new CWKSP_PointCloud(pPointCloud)) )
+	{
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_PointCloud * CWKSP_PointCloud_Manager::Get_byFileName(const wxChar *File_Name)
+{
+	CSG_String	s(File_Name);
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( !s.Cmp(Get_PointCloud(i)->Get_PointCloud()->Get_File_Name()) )
+		{
+			return( Get_PointCloud(i)->Get_PointCloud() );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::Update(CSG_PointCloud *pPointCloud, CSG_Parameters *pParameters)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( (pItem = Get_PointCloud(pPointCloud)) != NULL )
+	{
+		pItem->DataObject_Changed(pParameters);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::Update_Views(CSG_PointCloud *pPointCloud)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( (pItem = Get_PointCloud(pPointCloud)) != NULL )
+	{
+		pItem->Update_Views(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::Show(CSG_PointCloud *pPointCloud, int Map_Mode)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( (pItem = Get_PointCloud(pPointCloud)) != NULL )
+	{
+		switch( Map_Mode )
+		{
+		case SG_UI_DATAOBJECT_SHOW:
+			return( pItem->Show() );
+
+		case SG_UI_DATAOBJECT_SHOW_NEW_MAP:
+			g_pMaps->Add(pItem, NULL);
+
+		case SG_UI_DATAOBJECT_SHOW_LAST_MAP:
+			return( pItem->Show(g_pMaps->Get_Map(g_pMaps->Get_Count() - 1)) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::asImage(CSG_PointCloud *pPointCloud, CSG_Grid *pImage)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( (pItem = Get_PointCloud(pPointCloud)) != NULL )
+	{
+		return( pItem->asImage(pImage) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::Get_Colors(CSG_PointCloud *pPointCloud, CSG_Colors *pColors)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( (pItem = Get_PointCloud(pPointCloud)) != NULL )
+	{
+		return( pItem->Get_Colors(pColors) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_PointCloud_Manager::Set_Colors(CSG_PointCloud *pPointCloud, CSG_Colors *pColors)
+{
+	CWKSP_PointCloud	*pItem;
+
+	if( (pItem = Get_PointCloud(pPointCloud)) != NULL )
+	{
+		pItem->DataObject_Changed(pColors);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_pointcloud_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,123 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               WKSP_PointCloud_Manager.h               //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Hamburg                  //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_PointCloud_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_PointCloud_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_PointCloud_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_PointCloud_Manager(void);
+	virtual ~CWKSP_PointCloud_Manager(void);
+
+	virtual TWKSP_Item			Get_Type		(void)		{	return( WKSP_ITEM_PointCloud_Manager );	}
+
+	virtual wxString			Get_Name		(void);
+	virtual wxString			Get_Description	(void);
+
+	virtual wxMenu *			Get_Menu		(void);
+
+	virtual bool				On_Command		(int Cmd_ID);
+
+	class CWKSP_PointCloud *	Get_PointCloud	(int i)		{	return( (class CWKSP_PointCloud *)Get_Item(i) );	}
+	class CWKSP_PointCloud *	Get_PointCloud	(class CSG_PointCloud *pPointCloud);
+
+	bool						Exists			(class CSG_PointCloud *pPointCloud);
+	class CWKSP_PointCloud *	Add				(class CSG_PointCloud *pPointCloud);
+	class CSG_PointCloud *		Get_byFileName	(const wxChar *File_Name);
+
+	bool						Update			(class CSG_PointCloud *pPointCloud, class CSG_Parameters *pParameters);
+	bool						Update_Views	(class CSG_PointCloud *pPointCloud);
+	bool						Show			(class CSG_PointCloud *pPointCloud, int Map_Mode);
+	bool						asImage			(class CSG_PointCloud *pPointCloud, class CSG_Grid *pImage);
+
+	bool						Get_Colors		(class CSG_PointCloud *pPointCloud, class CSG_Colors *pColors);
+	bool						Set_Colors		(class CSG_PointCloud *pPointCloud, class CSG_Colors *pColors);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_PointCloud_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,1228 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                   WKSP_Shapes.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_layer_classify.h"
+
+#include "wksp_shapes.h"
+#include "wksp_table.h"
+
+#include "view_scatterplot.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes::CWKSP_Shapes(CSG_Shapes *pShapes)
+	: CWKSP_Layer(pShapes)
+{
+	m_pShapes		= pShapes;
+	m_pTable		= new CWKSP_Table(m_pShapes, this);
+
+	m_Edit_Shapes.Create(m_pShapes->Get_Type());
+	m_Edit_pShape	= NULL;
+
+	m_Edit_Attributes.Destroy();
+	m_Edit_Attributes.Add_Field(LNG("[FLD] Name") , SG_DATATYPE_String);
+	m_Edit_Attributes.Add_Field(LNG("[FLD] Value"), SG_DATATYPE_String);
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes::~CWKSP_Shapes(void)
+{
+	delete(m_pTable);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes::Get_Name(void)
+{
+	return( wxString::Format(wxT("%02d. %s"), 1 + Get_ID(), m_pShapes->Get_Name()) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes::Get_Description(void)
+{
+	wxString	s;
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<b>%s</b><table border=\"0\">"),
+		LNG("[CAP] Shapes")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, m_pShapes->Get_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] File")					, m_pShapes->Get_File_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Modified")				, m_pShapes->is_Modified() ? LNG("[VAL] yes") : LNG("[VAL] no")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Type")					, SG_Get_ShapeType_Name(m_pShapes->Get_Type())
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Number Of Shapes")		, m_pShapes->Get_Count()
+	));
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<hr><b>%s</b>"), LNG("[CAP] Table Description")));
+	s.Append(Get_TableInfo_asHTML(m_pShapes));
+
+	//-----------------------------------------------------
+//	s.Append(wxString::Format(wxT("<hr><b>%s</b><font size=\"-1\">"), LNG("[CAP] Data History")));
+//	s.Append(m_pShapes->Get_History().Get_HTML());
+//	s.Append(wxString::Format(wxT("</font")));
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Shapes::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(m_pShapes->Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_SAVE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_SAVEAS);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_SHOW);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_SHAPES_HISTOGRAM);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_SET_LUT);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SETTINGS_COPY);
+
+	pMenu->AppendSeparator();
+
+	wxMenu	*pTable	= new wxMenu(LNG("[MNU] Table"));
+	CMD_Menu_Add_Item(pTable,  true, ID_CMD_TABLES_SHOW);
+	CMD_Menu_Add_Item(pTable,  true, ID_CMD_TABLES_DIAGRAM);
+	CMD_Menu_Add_Item(pTable, false, ID_CMD_TABLES_SCATTERPLOT);
+	pMenu->Append(ID_CMD_WKSP_FIRST, LNG("[MNU] Attributes"), pTable);
+
+	pMenu->Append(ID_CMD_WKSP_FIRST, LNG("[MNU] Edit"), Edit_Get_Menu());
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Layer::On_Command(Cmd_ID) );
+
+	case ID_CMD_SHAPES_SET_LUT:
+		_LUT_Create();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_SHAPE:
+		_Edit_Shape();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_ADD_SHAPE:
+		_Edit_Shape_Add();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_DEL_SHAPE:
+		_Edit_Shape_Del();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_ADD_PART:
+		_Edit_Part_Add();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_DEL_PART:
+		_Edit_Part_Del();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_DEL_POINT:
+		_Edit_Point_Del();
+		break;
+
+	case ID_CMD_SHAPES_EDIT_SEL_INVERT:
+		m_pShapes->Inv_Selection();
+		Update_Views(false);
+		break;
+
+	case ID_CMD_TABLES_SHOW:
+		m_pTable->Toggle_View();
+		break;
+
+	case ID_CMD_TABLES_DIAGRAM:
+		m_pTable->Toggle_Diagram();
+		break;
+
+	case ID_CMD_TABLES_SCATTERPLOT:
+		Add_ScatterPlot(Get_Table()->Get_Table());
+		break;
+
+	case ID_CMD_SHAPES_HISTOGRAM:
+		Histogram_Toggle();
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Layer::On_Command_UI(event) );
+
+	case ID_CMD_SHAPES_EDIT_SHAPE:
+		event.Enable(m_pShapes->Get_Selection_Count() > 0 || m_Edit_pShape != NULL);
+		event.Check(m_Edit_pShape != NULL);
+		break;
+
+	case ID_CMD_SHAPES_EDIT_ADD_SHAPE:
+		event.Enable(m_Edit_pShape == NULL);
+		break;
+
+	case ID_CMD_SHAPES_EDIT_DEL_SHAPE:
+		event.Enable(m_pShapes->Get_Selection_Count() > 0 && m_Edit_pShape == NULL);
+		break;
+
+	case ID_CMD_SHAPES_EDIT_ADD_PART:
+		event.Enable(m_Edit_pShape != NULL);
+		break;
+
+	case ID_CMD_SHAPES_EDIT_DEL_PART:
+		event.Enable(m_Edit_pShape != NULL && m_Edit_iPart >= 0);
+		break;
+
+	case ID_CMD_SHAPES_EDIT_DEL_POINT:
+		event.Enable(m_Edit_pShape != NULL && m_Edit_iPart >= 0 && m_Edit_iPoint >= 0);
+		break;
+
+	case ID_CMD_SHAPES_EDIT_SEL_INVERT:
+		event.Enable(m_Edit_pShape == NULL);
+		break;
+
+	case ID_CMD_TABLES_SHOW:
+		event.Check(m_pTable->Get_View() != NULL);
+		break;
+
+	case ID_CMD_TABLES_DIAGRAM:
+		event.Check(m_pTable->Get_Diagram() != NULL);
+		break;
+
+	case ID_CMD_SHAPES_HISTOGRAM:
+		event.Check(m_pHistogram != NULL);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes::On_Create_Parameters(void)
+{
+	//-----------------------------------------------------
+	// General...
+
+	_AttributeList_Add(
+		m_Parameters("NODE_COLORS")		, "COLORS_ATTRIB"			, LNG("[CAP] Attribute"),
+		LNG("")
+	);
+
+
+	//-----------------------------------------------------
+	// Display...
+
+	m_Parameters.Add_Parameters(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_CHART"			, LNG("[CAP] Chart"),
+		LNG("")
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_TRANSPARENCY"	, LNG("[CAP] Transparency [%]"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true, 100.0, true
+	);
+
+
+#ifdef USE_HTMLINFO
+	//-----------------------------------------------------
+	// HTML Extra info
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_EXTRAINFO"			, LNG("[CAP] Html Extra Info"),
+		LNG("")
+	);
+
+	_AttributeList_Add(
+		m_Parameters("NODE_EXTRAINFO")	, "EXTRAINFO_ATTRIB"		, LNG("[CAP] Attribute"),
+		LNG("")
+	);
+#endif
+
+
+	//-----------------------------------------------------
+	// Label...
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_LABEL"				, LNG("[CAP] Display: Label"),
+		LNG("")
+	);
+
+	_AttributeList_Add(
+		m_Parameters("NODE_LABEL")		, "LABEL_ATTRIB"			, LNG("[CAP] Attribute"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Font(
+		m_Parameters("NODE_LABEL")		, "LABEL_ATTRIB_FONT"		, LNG("[CAP] Font"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_LABEL")		, "LABEL_ATTRIB_SIZE_TYPE"	, LNG("[CAP] Size relates to..."),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|"),
+			LNG("[VAL] Screen"),
+			LNG("[VAL] Map Units")
+		), 0
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_LABEL")		, "LABEL_ATTRIB_SIZE"		, LNG("[CAP] Default Size"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 100.0, 0.0, true
+	);
+
+	_AttributeList_Add(
+		m_Parameters("NODE_LABEL")		, "LABEL_ATTRIB_SIZE_BY"	, LNG("[CAP] Size by Attribute"),
+		LNG("")
+	);
+
+
+	//-----------------------------------------------------
+	// Edit...
+
+	m_Parameters.Add_Node(
+		NULL							, "NODE_EDIT"				, LNG("[CAP] Edit"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_EDIT")		, "EDIT_SNAP_DIST"			, LNG("[CAP] Snap Distance"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 10, 0, true
+	);
+
+	m_Parameters.Add_Shapes_List(
+		m_Parameters("NODE_EDIT")		, "EDIT_SNAP_LIST"			, LNG("[CAP] Snap to..."),
+		LNG(""),
+		PARAMETER_INPUT
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_EDIT")		, "EDIT_COLOR"				, LNG("[CAP] Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(0, 0, 0)
+	);
+
+	m_Parameters.Add_Node(
+		m_Parameters("NODE_EDIT")		, "NODE_SELECTION"			, LNG("[CAP] Selection"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_SELECTION")	, "EDIT_SEL_COLOR"			, LNG("[CAP] Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(255, 0, 0)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes::On_DataObject_Changed(void)
+{
+	_AttributeList_Set(m_Parameters("COLORS_ATTRIB")		, false);
+	_AttributeList_Set(m_Parameters("LABEL_ATTRIB")			, true);
+	_AttributeList_Set(m_Parameters("LABEL_ATTRIB_SIZE_BY")	, true);
+#ifdef USE_HTMLINFO
+	_AttributeList_Set(m_Parameters("EXTRAINFO_ATTRIB") , true);
+#endif
+
+	_Chart_Set_Options();
+
+	m_pTable->DataObject_Changed(NULL);
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::On_Parameters_Changed(void)
+{
+	m_Def_Color	= Get_Color_asWX(m_Parameters("UNISYMBOL_COLOR")->asColor());
+
+	//-----------------------------------------------------
+	if( (m_iColor = m_Parameters("COLORS_ATTRIB")->asInt()) >= m_pShapes->Get_Field_Count() )
+	{
+		m_iColor	= -1;
+	}
+
+	if( m_iColor < 0 && (m_pClassify->Get_Mode() == CLASSIFY_METRIC || m_pClassify->Get_Mode() == CLASSIFY_SHADE) )
+	{
+		m_pClassify->Set_Mode(CLASSIFY_UNIQUE);
+	}
+
+	//-----------------------------------------------------
+	if( (m_iLabel = m_Parameters("LABEL_ATTRIB")->asInt()) >= m_pShapes->Get_Field_Count() )
+	{
+		m_iLabel	= -1;
+	}
+
+	if( (m_iLabel_Size = m_Parameters("LABEL_ATTRIB_SIZE_BY")->asInt()) >= m_pShapes->Get_Field_Count() )
+	{
+		m_iLabel_Size	= -1;
+	}
+
+	//-----------------------------------------------------
+#ifdef USE_HTMLINFO
+	if( (m_iExtraInfo = m_Parameters("EXTRAINFO_ATTRIB")->asInt()) >= m_pShapes->Get_Field_Count() )
+	{
+		m_iExtraInfo	= -1;
+	}
+#endif
+
+	//-----------------------------------------------------
+	_Chart_Get_Options();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Shapes::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	//-----------------------------------------------------
+	if(	!SG_STR_CMP(pParameter->Get_Identifier(), wxT("COLORS_TYPE"))
+	||	!SG_STR_CMP(pParameter->Get_Identifier(), wxT("COLORS_ATTRIB")) )
+	{
+		int		zField	= pParameters->Get_Parameter("COLORS_ATTRIB")->asInt();
+
+		pParameters->Get_Parameter("METRIC_ZRANGE")->asRange()->Set_Range(
+			m_pShapes->Get_Minimum(zField),
+			m_pShapes->Get_Maximum(zField)
+		);
+	}
+
+	//-----------------------------------------------------
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_LUT_Create(void)
+{
+	int						iField, iRecord, old_Field, iID;
+	double					dValue;
+	TSG_Table_Index_Order	old_Order;
+	CSG_Colors				*pColors;
+	CSG_String				sFields, sValue;
+	CSG_Table_Record		*pRecord, *pRecord_LUT;
+	CSG_Table				*pTable, *pLUT;
+	CSG_Parameters			Parameters;
+
+	pTable	= Get_Table()->Get_Table();
+
+	if( pTable->Get_Field_Count() <= 0 || pTable->Get_Record_Count() < 1 )
+	{
+		DLG_Message_Show(LNG("Function failed because no attributes are available"), LNG("Create Lookup Table"));
+	}
+	else
+	{
+		for(iField=0; iField<pTable->Get_Field_Count(); iField++)
+		{
+			sFields.Append(pTable->Get_Field_Name(iField));
+			sFields.Append(wxT("|"));
+		}
+
+		Parameters.Create(NULL, LNG("Choose Attribute"), LNG(""));
+		Parameters.Add_Choice(NULL, "FIELD"	, LNG("Attribute")	, LNG(""), sFields);
+		Parameters.Add_Colors(NULL, "COLOR"	, LNG("Colors")		, LNG(""));
+
+		if( DLG_Parameters(&Parameters) )
+		{
+			iField		= Parameters("FIELD")	->asInt();
+
+			if( pTable->Get_Field_Type(iField) == SG_DATATYPE_String )
+			{
+				pTable->Add_Field(CSG_String::Format(wxT("%s_LUT"), pTable->Get_Field_Name(iField)), SG_DATATYPE_Int);
+				iID		= pTable->Get_Field_Count() - 1;
+			}
+			else
+			{
+				iID		= iField;
+			}
+
+			pLUT		= m_Parameters("LUT")	->asTable();
+			pLUT		->Del_Records();
+
+			old_Order	= pTable->Get_Index_Order(0);
+			old_Field	= pTable->Get_Index_Field(0);
+
+			pTable->Set_Index(iField, TABLE_INDEX_Ascending);
+			sValue		= pTable->Get_Record_byIndex(0)->asString(iField);
+			dValue		= iID != iField ? 1.0 : pTable->Get_Record_byIndex(0)->asDouble(iField);
+
+			for(iRecord=0; iRecord<pTable->Get_Record_Count(); iRecord++)
+			{
+				pRecord	= pTable->Get_Record_byIndex(iRecord);
+
+				if( iRecord == 0 || sValue.Cmp(pRecord->asString(iField)) )
+				{
+					if( iRecord > 0 )
+					{
+						sValue		= pRecord->asString(iField);
+						dValue		= iID != iField ? dValue + 1.0 : pRecord->asDouble(iField);
+					}
+
+					pRecord_LUT	= pLUT->Add_Record();
+					pRecord_LUT	->Set_Value(1, sValue.c_str());	// Name
+					pRecord_LUT	->Set_Value(2, sValue.c_str());	// Description
+					pRecord_LUT	->Set_Value(3, dValue);			// Minimum
+					pRecord_LUT	->Set_Value(4, dValue);			// Maximum
+				}
+
+				if( iID != iField )
+				{
+					pRecord->Set_Value(iID, dValue);
+				}
+			}
+
+			pColors	= Parameters("COLOR")->asColors();
+			pColors->Set_Count(pLUT->Get_Record_Count());
+
+			for(iRecord=0; iRecord<pLUT->Get_Record_Count(); iRecord++)
+			{
+				pLUT->Get_Record(iRecord)->Set_Value(0, pColors->Get_Color(iRecord));
+			}
+
+			pTable->Set_Index(old_Field, old_Order);
+
+			DataObject_Changed();
+
+			m_Parameters("COLORS_TYPE")		->Set_Value(1);		// Lookup Table
+			m_Parameters("COLORS_ATTRIB")	->Set_Value(iID);
+
+			Parameters_Changed();
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes::Get_Value(CSG_Point ptWorld, double Epsilon)
+{
+	CSG_Shape		*pShape;
+
+	if( (pShape = m_pShapes->Get_Shape(ptWorld, Epsilon)) != NULL )
+	{
+		if( m_iColor >= 0 )
+		{
+			switch( m_pClassify->Get_Mode() )
+			{
+			case CLASSIFY_LUT:
+				return( m_pClassify->Get_Class_Name_byValue(pShape->asDouble(m_iColor)) );
+
+			case CLASSIFY_METRIC:	default:
+				return( pShape->asString(m_iColor) );
+			}
+		}
+		else
+		{
+			return( wxString::Format(wxT("%s: %d"), LNG("[CAP] Index"), pShape->Get_Index() + 1) );
+		}
+	}
+
+	return( LNG("") );
+}
+
+//---------------------------------------------------------
+double CWKSP_Shapes::Get_Value_Range(void)
+{
+	return( m_iColor >= 0 ? m_pShapes->Get_Range(m_iColor) : 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::asImage(CSG_Grid *pImage)
+{
+	return( false );
+}
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes::On_Draw(CWKSP_Map_DC &dc_Map, bool bEdit)
+{
+	int			iShape;
+	CSG_Shape	*pShape;
+
+	//-----------------------------------------------------
+	if( Get_Extent().Intersects(dc_Map.m_rWorld) != INTERSECTION_None )
+	{
+		double	Transparency	= m_Parameters("DISPLAY_TRANSPARENCY")->asDouble() / 100.0;
+
+		CWKSP_Map_DC	*pDC	= Transparency > 0.0 ? new CWKSP_Map_DC(dc_Map.m_rWorld, dc_Map.m_rDC, dc_Map.m_Scale, SG_GET_RGB(255, 255, 255)) : NULL;
+		CWKSP_Map_DC	&dc		= pDC ? *pDC : dc_Map;
+
+		m_Edit_Color	= Get_Color_asWX(m_Parameters("EDIT_COLOR")		->asInt());
+		m_Sel_Color		= Get_Color_asWX(m_Parameters("EDIT_SEL_COLOR")	->asInt());
+
+		_Draw_Initialize(dc);
+
+		//-------------------------------------------------
+		if( bEdit && (m_Edit_pShape || m_pShapes->Get_Selection_Count() > 0) )
+		{
+			for(iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+			{
+				pShape	= m_pShapes->Get_Shape(iShape);
+
+				if( !pShape->is_Selected() && dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None )
+				{
+					_Draw_Shape(dc, pShape, false);
+				}
+			}
+
+			//---------------------------------------------
+			for(iShape=1; iShape<m_pShapes->Get_Selection_Count(); iShape++)
+			{
+				pShape	= m_pShapes->Get_Selection(iShape);
+
+				if( dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None )
+				{
+					_Draw_Shape(dc, pShape, true);
+				}
+			}
+
+			if( m_Edit_pShape )
+			{
+				_Edit_Shape_Draw(dc);
+			}
+			else
+			{
+				pShape	= m_pShapes->Get_Selection(0);
+
+				if( dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None )
+				{
+					_Draw_Shape(dc, pShape, true);
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			for(iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+			{
+				pShape	= m_pShapes->Get_Shape(iShape);
+
+				if( dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None )
+				{
+					_Draw_Shape(dc, pShape, false);
+				}
+			}
+
+			if( _Chart_is_Valid() )
+			{
+				for(iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+				{
+					pShape	= m_pShapes->Get_Shape(iShape);
+
+					if( dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None )
+					{
+						_Draw_Chart(dc, pShape);
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( m_iLabel >= 0 )
+		{
+			int		Size;
+			double	dSize;
+			wxFont	Font	= *m_Parameters("LABEL_ATTRIB_FONT")->asFont();
+
+			switch( m_Parameters("LABEL_ATTRIB_SIZE_TYPE")->asInt() )
+			{
+			case 0:	default:
+				dSize	= m_iLabel_Size < 0 ? m_Parameters("LABEL_ATTRIB_FONT")->asFont()->GetPointSize() : 1.0;
+				break;
+
+			case 1:
+				dSize	= dc.m_World2DC * m_Parameters("LABEL_ATTRIB_SIZE")->asDouble();
+				break;
+			}
+
+			dc.dc.SetTextForeground(m_Parameters("LABEL_ATTRIB_FONT")->asColor());
+
+			if( m_iLabel_Size < 0 && (Size = (int)(0.5 + dSize)) > 0 )
+			{
+				Font.SetPointSize(Size);
+				dc.dc.SetFont(Font);
+
+				for(iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+				{
+					pShape	= m_pShapes->Get_Shape(iShape);
+
+					if( dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None )
+					{
+						_Draw_Label(dc, pShape);
+					}
+				}
+			}
+			else
+			{
+				for(iShape=0; iShape<m_pShapes->Get_Count(); iShape++)
+				{
+					pShape	= m_pShapes->Get_Shape(iShape);
+
+					if( dc.m_rWorld.Intersects(pShape->Get_Extent()) != INTERSECTION_None
+					&&	(Size = (int)(0.5 + dSize * pShape->asDouble(m_iLabel_Size))) > 0 )
+					{
+						Font.SetPointSize(Size);
+						dc.dc.SetFont(Font);
+
+						_Draw_Label(dc, pShape);
+					}
+				}
+			}
+		}
+
+		//-------------------------------------------------
+		if( pDC )
+		{
+			dc_Map.Draw_DC(dc, Transparency);
+
+			delete(pDC);
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( m_Edit_pShape )
+	{
+		_Edit_Shape_Draw(dc_Map);
+	}
+
+	//-----------------------------------------------------
+	dc_Map.dc.SetBrush(wxNullBrush);
+	dc_Map.dc.SetPen  (wxNullPen);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CWKSP_Shapes::_AttributeList_Add(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description)
+{
+	CSG_Parameter *pParameter;
+
+	pParameter	= m_Parameters.Add_Choice(
+		pNode, Identifier, Name, Description,
+		wxString::Format(wxT("%s|"), LNG("[VAL] [default]")), 0
+	);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_AttributeList_Set(CSG_Parameter *pFields, bool bAddNoField)
+{
+	if( pFields && pFields->Get_Type() == PARAMETER_TYPE_Choice )
+	{
+		wxString	s;
+
+		for(int i=0; i<m_pShapes->Get_Field_Count(); i++)
+		{
+			s.Append(wxString::Format(wxT("%s|"), m_pShapes->Get_Field_Name(i)));
+		}
+
+		if( bAddNoField )
+		{
+			s.Append(wxString::Format(wxT("%s|"), LNG("[VAL] [none]")));
+		}
+
+		pFields->asChoice()->Set_Items(s);
+
+		if( bAddNoField )
+		{
+			pFields->Set_Value(m_pShapes->Get_Field_Count());
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CSG_Parameter * CWKSP_Shapes::_BrushList_Add(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description)
+{
+	CSG_Parameter *pParameter;
+
+	pParameter	= m_Parameters.Add_Choice(
+		pNode, Identifier, Name, Description,
+		wxString::Format(wxT("%s|%s|%s|%s|%s|%s|%s|%s|"),
+			LNG("[VAL] Opaque"),
+			LNG("[VAL] Transparent"),
+			LNG("[VAL] Backward Diagonal"),
+			LNG("[VAL] Cross Diagonal"),
+			LNG("[VAL] Forward Diagonal"),
+			LNG("[VAL] Cross"),
+			LNG("[VAL] Horizontal"),
+			LNG("[VAL] Vertical")
+		), 0
+	);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+int CWKSP_Shapes::_BrushList_Get_Style(int Index)
+{
+	switch( Index )
+	{
+	default:
+	case 0:	return( wxSOLID				);
+	case 1:	return( wxTRANSPARENT		);
+	case 2:	return( wxBDIAGONAL_HATCH	);
+	case 3:	return( wxCROSSDIAG_HATCH	);
+	case 4:	return( wxFDIAGONAL_HATCH	);
+	case 5:	return( wxCROSS_HATCH		);
+	case 6:	return( wxHORIZONTAL_HATCH	);
+	case 7:	return( wxVERTICAL_HATCH	);
+	}
+}
+
+//---------------------------------------------------------
+CSG_Parameter * CWKSP_Shapes::_PenList_Add(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description)
+{
+	CSG_Parameter *pParameter;
+
+	pParameter	= m_Parameters.Add_Choice(
+		pNode, Identifier, Name, Description,
+		wxString::Format(wxT("%s|%s|%s|%s|%s|"),
+			LNG("[VAL] Solid"),
+			LNG("[VAL] Dotted"),
+			LNG("[VAL] Long Dashed"),
+			LNG("[VAL] Short Dashed"),
+			LNG("[VAL] Dot And Dash")
+		), 0
+	);
+
+	return( pParameter );
+}
+
+//---------------------------------------------------------
+int CWKSP_Shapes::_PenList_Get_Style(int Index)
+{
+	switch( Index )
+	{
+	default:
+	case 0:	return( wxSOLID );
+	case 1:	return( wxDOT );
+	case 2:	return( wxLONG_DASH );
+	case 3:	return( wxSHORT_DASH );
+	case 4:	return( wxDOT_DASH );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Chart_Set_Options(void)
+{
+	CSG_Parameters	*pChart	= m_Parameters("DISPLAY_CHART")->asParameters();
+
+	pChart->Destroy();
+	m_Chart.Clear();
+
+	if( 1 )
+	{
+		int			i, n;
+		CSG_Colors		Colors;
+		CSG_String	sFields;
+		CSG_Parameter	*pFields, *pColors;
+
+		for(i=0, n=0; i<m_pShapes->Get_Field_Count(); i++)
+		{
+			if( m_pShapes->Get_Field_Type(i) != SG_DATATYPE_String )
+				n++;
+		}
+
+		if( n > 0 )
+		{
+			pChart->Create(NULL, LNG("[CAP] Chart Properties"), LNG(""));
+
+			pChart->Add_Choice(
+				NULL, "TYPE"	, LNG("Chart Type"),
+				LNG(""),
+				CSG_String::Format(wxT("%s|%s|%s|%s|"),
+					LNG("bar"),
+					LNG("bar (not outlined)"),
+					LNG("pie"),
+					LNG("pie (not outlined)")
+				), 0
+			);
+
+			pChart->Add_Choice(
+				NULL, "SIZE_FIELD"		, LNG("[CAP] Attribute (Size)"),
+				LNG(""),
+				CSG_String::Format(wxT("%s|"), LNG("[VAL] [not set]")), 0
+			);
+
+			pChart->Add_Choice(
+				NULL, "SIZE_TYPE"		, LNG("[CAP] Size relates to..."),
+				LNG(""),
+				wxString::Format(wxT("%s|%s|"),
+					LNG("[VAL] Screen"),
+					LNG("[VAL] Map Units")
+				), 0
+			);
+
+			pChart->Add_Value(
+				NULL, "SIZE_DEFAULT"	, LNG("[CAP] Default Size"),
+				LNG(""),
+				PARAMETER_TYPE_Double, 15, 0, true
+			);
+
+			pChart->Add_Range(
+				NULL, "SIZE_RANGE"		, LNG("[CAP] Size Range"),
+				LNG(""),
+				5, 25, 0, true
+			);
+
+			pFields	= pChart->Add_Node(NULL, "NODE_FIELDS"	, LNG("Fields")			, LNG(""));
+			pColors	= pChart->Add_Node(NULL, "NODE_COLORS"	, LNG("Field Colors")	, LNG(""));
+
+			Colors.Set_Count(n);
+
+			for(i=0, n=0; i<m_pShapes->Get_Field_Count(); i++)
+			{
+				if( m_pShapes->Get_Field_Type(i) != SG_DATATYPE_String )
+				{
+					sFields.Append(CSG_String::Format(wxT("%s|"), m_pShapes->Get_Field_Name(i)));
+
+					pChart->Add_Value(
+						pFields	, wxString::Format(wxT("FIELD_%d"), i), m_pShapes->Get_Field_Name(i),
+						LNG(""),
+						PARAMETER_TYPE_Bool , false
+					);
+
+					pChart->Add_Value(
+						pColors	, wxString::Format(wxT("COLOR_%d"), i), m_pShapes->Get_Field_Name(i),
+						LNG(""),
+						PARAMETER_TYPE_Color, Colors.Get_Color(n++)
+					);
+				}
+			}
+
+			sFields.Append(CSG_String::Format(wxT("%s|"), LNG("[VAL] [none]")));
+			pFields	= pChart->Get_Parameter("SIZE_FIELD");
+			pFields->asChoice()->Set_Items(sFields);
+			pFields->Set_Value(m_pShapes->Get_Field_Count());
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Chart_Get_Options(void)
+{
+	CSG_Parameters	*pChart	= m_Parameters("DISPLAY_CHART")->asParameters();
+	CSG_Parameter	*p;
+
+	m_Chart.Clear();
+	m_Chart_sField=-1;
+
+	if( pChart->Get_Parameter("NODE_FIELDS") )
+	{
+		for(int i=0, n=0; i<m_pShapes->Get_Field_Count(); i++)
+		{
+			if(	(p = pChart->Get_Parameter(wxString::Format(wxT("FIELD_%d"), i))) != NULL )
+			{
+				if( pChart->Get_Parameter("SIZE_FIELD")->asInt() == n++ )
+					m_Chart_sField	= i;
+
+				if( p->asBool() && (p = pChart->Get_Parameter(wxString::Format(wxT("COLOR_%d"), i))) != NULL )
+					m_Chart.Add(i, p->asColor());
+			}
+		}
+
+		m_Chart_Type	= pChart->Get_Parameter("TYPE")			->asInt();
+		m_Chart_sType	= pChart->Get_Parameter("SIZE_TYPE")	->asInt();
+		m_Chart_sSize	= m_Chart_sField < 0
+						? pChart->Get_Parameter("SIZE_DEFAULT")	->asDouble()
+						: pChart->Get_Parameter("SIZE_RANGE")	->asRange()->Get_LoVal();
+		m_Chart_sRange	= pChart->Get_Parameter("SIZE_RANGE")	->asRange()->Get_HiVal() - m_Chart_sSize;
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Draw_Chart(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)
+{
+	if( _Chart_is_Valid() )
+	{
+		int			s;
+		double		dSize	= m_Chart_sSize;
+		TSG_Point_Int	p;
+
+		if( m_Chart_sField >= 0 )
+		{
+			double	range	= m_pShapes->Get_Range(m_Chart_sField);
+
+			if( range > 0.0 )
+			{
+				dSize	+= m_Chart_sRange * ((pShape->asDouble(m_Chart_sField) - m_pShapes->Get_Minimum(m_Chart_sField)) / range);
+			}
+		}
+
+		s	= (int)(dSize * (m_Chart_sType == 1 ? dc_Map.m_World2DC : dc_Map.m_Scale));
+
+		switch( pShape->Get_Type() )
+		{
+		default:					p	= dc_Map.World2DC(pShape->Get_Extent().Get_Center());			break;
+		case SHAPE_TYPE_Polygon:	p	= dc_Map.World2DC(((CSG_Shape_Polygon *)pShape)->Get_Centroid());	break;
+		}
+
+		dc_Map.dc.SetPen(*wxBLACK_PEN);
+
+		switch( m_Chart_Type )
+		{
+		case 0:	_Draw_Chart_Bar(dc_Map, pShape,  true, p.x, p.y, (int)(0.8 * s), s);	break; // bar outlined
+		case 1:	_Draw_Chart_Bar(dc_Map, pShape, false, p.x, p.y, (int)(0.8 * s), s);	break; // bar
+		case 2:	_Draw_Chart_Pie(dc_Map, pShape,  true, p.x, p.y, (int)(1.0 * s));	break; // pie outlined
+		case 3:	_Draw_Chart_Pie(dc_Map, pShape, false, p.x, p.y, (int)(1.0 * s));	break; // pie
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Draw_Chart_Pie(CWKSP_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int size)
+{
+	int		i, ix, iy, jx, jy;
+	double	d, sum;
+
+	for(i=0, sum=0.0; i<m_Chart.Get_Count(); i++)
+	{
+		sum	+= fabs(pRecord->asDouble(m_Chart[i].x));
+	}
+
+	if( sum > 0.0 )
+	{
+		sum	= M_PI_360 / sum;
+
+		for(i=0, jx=x, jy=y-size, d=0.0; i<m_Chart.Get_Count(); i++)
+		{
+			if( !bOutline )
+			dc_Map.dc.SetPen	(wxPen  (Get_Color_asWX(m_Chart[i].y)));
+			dc_Map.dc.SetBrush	(wxBrush(Get_Color_asWX(m_Chart[i].y)));
+
+			d	+= sum * fabs(pRecord->asDouble(m_Chart[i].x));
+
+			ix	= jx;
+			iy	= jy;
+			jx	= x - (int)(size * sin(-d));
+			jy	= y - (int)(size * cos(-d));
+
+			dc_Map.dc.DrawArc(jx, jy, ix, iy, x, y);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Draw_Chart_Bar(CWKSP_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int sx, int sy)
+{
+	int		i;
+	double	d, dx, dy, max, ix;
+
+	for(i=1, max=fabs(pRecord->asDouble(m_Chart[0].x)); i<m_Chart.Get_Count(); i++)
+	{
+		if( (d = fabs(pRecord->asDouble(m_Chart[i].x))) > max )
+			max	= d;
+	}
+
+	if( max != 0.0 )
+	{
+		max	= sy / max;
+		dx	= sx / (double)m_Chart.Get_Count();
+
+		for(i=0, ix=x-sx/2.0; i<m_Chart.Get_Count(); i++, ix+=dx)
+		{
+			if( !bOutline )
+			dc_Map.dc.SetPen	(wxPen  (Get_Color_asWX(m_Chart[i].y)));
+			dc_Map.dc.SetBrush	(wxBrush(Get_Color_asWX(m_Chart[i].y)));
+
+			dy	= -pRecord->asDouble(m_Chart[i].x) * max;
+
+			dc_Map.dc.DrawRectangle((int)ix, y, (int)dx, (int)dy);
+		}
+
+		if( !bOutline )
+		{
+			dc_Map.dc.SetPen(*wxBLACK_PEN);
+			dc_Map.dc.DrawLine(x - sx / 2, y, x + sx / 2, y);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,209 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_Shapes.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_layer.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes : public CWKSP_Layer
+{
+public:
+	CWKSP_Shapes(CSG_Shapes *pShapes);
+	virtual ~CWKSP_Shapes(void);
+
+	virtual TWKSP_Item			Get_Type				(void)	{	return( WKSP_ITEM_Shapes );	}
+
+	virtual wxString			Get_Name				(void);
+	virtual wxString			Get_Description			(void);
+
+	virtual wxMenu *			Get_Menu				(void);
+
+	virtual bool				On_Command				(int Cmd_ID);
+	virtual bool				On_Command_UI			(wxUpdateUIEvent &event);
+
+	CSG_Shapes *				Get_Shapes				(void)	{	return( m_pShapes );	}
+	class CWKSP_Table *			Get_Table				(void)	{	return( m_pTable );		}
+
+	virtual wxString			Get_Value				(CSG_Point ptWorld, double Epsilon);
+	virtual double				Get_Value_Range			(void);
+
+	bool						asImage					(CSG_Grid *pImage);
+
+	int							Get_Color_Field			(void)	{	return( m_iColor );		}
+	int							Get_Label_Field			(void)	{	return( m_iLabel );		}
+
+	bool						is_Editing				(void)	{	return( m_Edit_pShape != NULL );	}
+
+
+protected:
+
+	int							m_iColor, m_iLabel, m_iLabel_Size, m_iExtraInfo, m_Edit_iPart, m_Edit_iPoint, m_Chart_Type, m_Chart_sField, m_Chart_sType;
+
+	double						m_Chart_sSize, m_Chart_sRange;
+
+	wxColour					m_Def_Color, m_Edit_Color, m_Sel_Color;
+
+	CSG_Points_Int				m_Chart;
+
+	CSG_Parameters				m_Chart_Options;
+
+	CSG_Shape					*m_Edit_pShape;
+
+	CSG_Shapes					*m_pShapes, m_Edit_Shapes;
+
+	class CWKSP_Table			*m_pTable;
+
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual void				On_Draw					(CWKSP_Map_DC &dc_Map, bool bEdit);
+
+	CSG_Parameter *				_AttributeList_Add		(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description);
+	void						_AttributeList_Set		(CSG_Parameter *pFields, bool bAddNoField);
+
+	CSG_Parameter *				_BrushList_Add			(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description);
+	int							_BrushList_Get_Style	(int Index);
+
+	CSG_Parameter *				_PenList_Add			(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description);
+	int							_PenList_Get_Style		(int Index);
+
+	virtual void				_Draw_Initialize		(CWKSP_Map_DC &dc_Map)									= 0;
+	virtual void				_Draw_Shape				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection)	= 0;
+	virtual void				_Draw_Label				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)					= 0;
+
+	void						_Draw_Chart				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape);
+	void						_Draw_Chart_Pie			(CWKSP_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int size);
+	void						_Draw_Chart_Bar			(CWKSP_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int sx, int sy);
+
+	bool						_Chart_is_Valid			(void)	{	return( m_Chart.Get_Count() > 0 );	}
+	bool						_Chart_Set_Options		(void);
+	bool						_Chart_Get_Options		(void);
+
+
+	//-----------------------------------------------------
+	// Editing...
+
+	virtual wxMenu *			On_Edit_Get_Menu		(void);
+	virtual TSG_Rect			On_Edit_Get_Extent		(void);
+	virtual bool				On_Edit_Set_Attributes	(void);
+
+	virtual bool				On_Edit_On_Key_Down		(int KeyCode);
+	virtual bool				On_Edit_On_Mouse_Down	(CSG_Point Point, double ClientToWorld, int Key);
+	virtual bool				On_Edit_On_Mouse_Up		(CSG_Point Point, double ClientToWorld, int Key);
+	virtual bool				On_Edit_On_Mouse_Move	(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key);
+
+	void						_LUT_Create				(void);
+
+	bool						_Edit_Set_Attributes	(void);
+
+	bool						_Edit_Shape				(void);
+	bool						_Edit_Shape_Start		(void);
+	bool						_Edit_Shape_Stop		(void);
+	bool						_Edit_Shape_Stop		(bool bSave);
+	bool						_Edit_Shape_Add			(void);
+	bool						_Edit_Shape_Del			(void);
+	bool						_Edit_Part_Add			(void);
+	bool						_Edit_Part_Del			(void);
+	bool						_Edit_Point_Del			(void);
+
+	void						_Edit_Shape_Draw_Point	(wxDC &dc, TSG_Point_Int Point, bool bSelected);
+	void						_Edit_Shape_Draw_Point	(wxDC &dc, int x, int y, bool bSelected);
+	virtual void				_Edit_Shape_Draw_Move	(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point);
+	virtual void				_Edit_Shape_Draw		(CWKSP_Map_DC &dc_Map);
+
+	virtual int					_Edit_Shape_HitTest		(CSG_Point Point, double max_Dist, int &iPart, int &iPoint);
+
+	void						_Edit_Snap_Point		(CSG_Point &Point, double ClientToWorld);
+	void						_Edit_Snap_Point		(CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shapes *pShapes, bool bLine);
+	void						_Edit_Snap_Point		(CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape);
+	virtual void				_Edit_Snap_Point_ToLine (CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_edit.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_edit.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_edit.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,821 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Shapes_Edit.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+#include "res_images.h"
+#include "res_dialogs.h"
+
+#include "dc_helper.h"
+
+#include "active.h"
+#include "active_attributes.h"
+#include "active_HTMLExtraInfo.h"
+
+#include "wksp_shapes.h"
+
+#include "wksp_table.h"
+#include "view_table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define EDIT_TICKMARK_SIZE	4
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Shapes::On_Edit_Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu;
+
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_SHAPES_EDIT_SHAPE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_ADD_SHAPE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_DEL_SHAPE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_ADD_PART);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_DEL_PART);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_DEL_POINT);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_SEL_INVERT);
+
+	return( pMenu );
+}
+
+//---------------------------------------------------------
+TSG_Rect CWKSP_Shapes::On_Edit_Get_Extent(void)
+{
+	if( m_Edit_pShape )
+	{
+		return( m_Edit_pShape->Get_Extent() );
+	}
+
+	if( m_pShapes->Get_Selection_Count() > 0 )
+	{
+		return( m_pShapes->Get_Selection_Extent().m_rect );
+	}
+
+	return( m_pShapes->Get_Extent() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Edit_On_Key_Down(int KeyCode)
+{
+	switch( KeyCode )
+	{
+	default:
+		return( false );
+
+	case WXK_DELETE:
+		if( m_Edit_pShape )
+			return( _Edit_Point_Del() );
+		else
+			return( _Edit_Shape_Del() );
+
+	case WXK_RETURN:
+		if( !m_Edit_pShape )
+			return( _Edit_Shape_Start() );
+		else
+			return( _Edit_Shape_Stop(true) );
+
+	case WXK_ESCAPE:
+		return( _Edit_Shape_Stop(false) );
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Edit_On_Mouse_Down(CSG_Point Point, double ClientToWorld, int Key)
+{
+	int		iPart, iPoint;
+
+	//-----------------------------------------------------
+	if( m_Edit_pShape )
+	{
+		if( m_Edit_iPart >= 0 && m_Edit_iPoint < 0 )
+		{
+		}
+		else switch( _Edit_Shape_HitTest(Point, EDIT_TICKMARK_SIZE * ClientToWorld, iPart, iPoint) )
+		{
+		//-------------------------------------------------
+		case 0:	default:
+		case 1:
+			if( m_Edit_iPart != iPart || m_Edit_iPoint != iPoint )
+			{
+				m_Edit_iPart	= iPart;
+				m_Edit_iPoint	= iPoint;
+
+				Update_Views(true);
+			}
+
+			return( true );
+
+		//-------------------------------------------------
+		case 2:
+			m_Edit_pShape->Ins_Point(Point, iPoint, iPart);
+
+			m_Edit_iPart	= iPart;
+			m_Edit_iPoint	= iPoint;
+
+			Update_Views(true);
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Edit_On_Mouse_Up(CSG_Point Point, double ClientToWorld, int Key)
+{
+	CSG_Rect		rWorld(m_Edit_Mouse_Down, Point);
+	CSG_Table_Record	*pRecord;
+	wxFileName		FileName;
+
+
+	//-----------------------------------------------------
+	if( Key & MODULE_INTERACTIVE_KEY_RIGHT )
+	{
+		if( m_Edit_pShape && m_Edit_iPart >= 0 && m_Edit_iPoint < 0 )
+		{
+			m_Edit_iPart	= -1;
+
+			Update_Views(true);
+
+			return( true );
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( m_Edit_pShape )
+	{
+		if( m_Edit_iPart >= 0 )
+		{
+			if( m_Edit_iPoint >= 0 )
+			{
+				if( Point != m_Edit_Mouse_Down )
+				{
+					_Edit_Snap_Point(Point, ClientToWorld);
+
+					m_Edit_pShape->Set_Point(Point, m_Edit_iPoint, m_Edit_iPart);
+
+					Update_Views(true);
+
+					return( true );
+				}
+			}
+			else
+			{
+				_Edit_Snap_Point(Point, ClientToWorld);
+
+				m_Edit_pShape->Add_Point(Point, m_Edit_iPart);
+
+				Update_Views(true);
+
+				return( true );
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else
+	{
+		rWorld.Assign(m_Edit_Mouse_Down, Point);
+
+		if( rWorld.Get_XRange() == 0.0 && rWorld.Get_YRange() == 0.0 )
+		{
+			rWorld.Inflate(2.0 * ClientToWorld, false);
+		}
+
+		g_pACTIVE->Get_Attributes()->Set_Attributes();
+
+		pRecord	= m_pShapes->Get_Selection();
+		
+		m_pShapes->Select(rWorld, (Key & MODULE_INTERACTIVE_KEY_CTRL) != 0);
+
+		if( m_pTable->Get_View() )
+		{
+			m_pTable->Get_View()->Update_Selection();
+		}
+
+		if( pRecord != m_pShapes->Get_Selection() )
+		{
+			_Edit_Set_Attributes();
+		}
+
+		pRecord	= m_pShapes->Get_Selection();
+
+		Update_Views(true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Edit_On_Mouse_Move(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key)
+{
+	if( m_Edit_pShape )
+	{
+		double	ClientToWorld	= rWorld.Get_XRange() / (double)pMap->GetClientSize().x;
+
+		//-------------------------------------------------
+		if( m_Edit_iPart >= 0 && (m_Edit_iPoint < 0 || Key & MODULE_INTERACTIVE_KEY_LEFT) )
+		{
+			if( pt.x != ptLast.x || pt.y != ptLast.y )
+			{
+				wxClientDC	dc(pMap);
+				dc.SetLogicalFunction(wxINVERT);
+
+				_Edit_Shape_Draw_Move(dc, rWorld, ClientToWorld, ptLast);
+				_Edit_Shape_Draw_Move(dc, rWorld, ClientToWorld, pt);
+			}
+
+			return( true );
+		}
+
+		//-------------------------------------------------
+		else
+		{
+			int			iPart, iPoint;
+			CSG_Point	Point(rWorld.Get_XMin() + pt.x * ClientToWorld, rWorld.Get_YMax() - pt.y * ClientToWorld);
+
+			switch( _Edit_Shape_HitTest(Point, EDIT_TICKMARK_SIZE * ClientToWorld, iPart, iPoint) )
+			{
+			case 0:	default:
+				pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_SELECT));
+				break;
+
+			case 1:
+				pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_EDIT_POINT_MOVE));
+				break;
+
+			case 2:
+				pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_EDIT_POINT_ADD));
+				break;
+			}
+
+			return( true );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Set_Attributes(void)
+{
+	CSG_Table_Record	*pAttribute, *pRecord;
+
+	m_Edit_Attributes.Del_Records();
+
+	if( (pRecord = m_pShapes->Get_Selection()) != NULL )
+	{
+		for(int i=0; i<m_pShapes->Get_Field_Count(); i++)
+		{
+			pAttribute	= m_Edit_Attributes.Add_Record();
+			pAttribute->Set_Value(0, pRecord->Get_Table()->Get_Field_Name(i));
+			pAttribute->Set_Value(1, pRecord->asString(i));
+		}
+	}
+
+	g_pACTIVE->Get_Attributes()->Set_Attributes();
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::On_Edit_Set_Attributes(void)
+{
+	CSG_Table_Record	*pRecord;
+
+	if( (pRecord = m_pShapes->Get_Selection()) != NULL )
+	{
+		for(int i=0; i<m_Edit_Attributes.Get_Record_Count(); i++)
+		{
+			pRecord->Set_Value(i, m_Edit_Attributes.Get_Record(i)->asString(1));
+		}
+
+		Update_Views(true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Shape(void)
+{
+	return( m_Edit_pShape ? _Edit_Shape_Stop() : _Edit_Shape_Start() );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Shape_Start(void)
+{
+	if( m_Edit_pShape == NULL && m_pShapes->Get_Selection(0) != NULL )
+	{
+		m_Edit_pShape	= m_Edit_Shapes.Add_Shape();
+		m_Edit_pShape->Assign(m_pShapes->Get_Selection(0), false);
+
+		m_Edit_iPart	= -1;
+		m_Edit_iPoint	= -1;
+
+		Update_Views(true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Shape_Stop(void)
+{
+	return( _Edit_Shape_Stop(DLG_Message_Confirm(LNG("[DLG] Save changes?"), LNG("[CAP] Edit Shapes"))) );
+}
+
+bool CWKSP_Shapes::_Edit_Shape_Stop(bool bSave)
+{
+	if( m_Edit_pShape != NULL )
+	{
+		if( bSave )
+		{
+			CSG_Shape	*pShape;
+
+			if( (pShape = m_pShapes->Get_Selection(0)) == NULL )
+			{
+				if( (pShape = m_pShapes->Add_Shape()) != NULL )
+				{
+					m_pShapes->Select(pShape);
+				}
+			}
+
+			if( pShape != NULL )
+			{
+				pShape->Assign(m_Edit_pShape, false);
+			}
+		}
+
+		m_Edit_Shapes.Del_Shapes();
+		m_Edit_pShape	= NULL;
+
+		Update_Views(false);
+		_Edit_Set_Attributes();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Shape_Add(void)
+{
+	if( !m_Edit_pShape )
+	{
+		if( m_pShapes->Get_Selection_Count() > 0 )
+		{
+			m_pShapes->Select(NULL);
+		}
+
+		m_Edit_pShape	= m_Edit_Shapes.Add_Shape();
+
+		return( _Edit_Part_Add() );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Part_Add(void)
+{
+	if( m_Edit_pShape )
+	{
+		m_Edit_iPart	= m_Edit_pShape->Get_Part_Count();
+		m_Edit_iPoint	= -1;
+
+		Update_Views(true);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Shape_Del(void)
+{
+	if( DLG_Message_Confirm(LNG("[DLG] Delete selected shape(s)."), LNG("[CAP] Edit Shapes")) )
+	{
+		if( m_pShapes->Get_Selection_Count() > 0 )
+		{
+			if( m_Edit_pShape )
+			{
+				_Edit_Shape_Stop(false);
+
+				m_pShapes->Del_Shape(m_pShapes->Get_Selection(0));
+			}
+			else
+			{
+				m_pShapes->Del_Selection();
+			}
+
+			Update_Views(false);
+
+			return( true );
+		}
+
+		return( _Edit_Shape_Stop(false) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Part_Del(void)
+{
+	if( m_Edit_pShape && m_Edit_iPart >= 0 )
+	{
+		if( m_Edit_pShape->Get_Part_Count() > 1 )
+		{
+			m_Edit_pShape->Del_Part(m_Edit_iPart);
+
+			m_Edit_iPart	= -1;
+			m_Edit_iPoint	= -1;
+
+			Update_Views(true);
+
+			return( true );
+		}
+		else
+		{
+			return( _Edit_Shape_Del() );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes::_Edit_Point_Del(void)
+{
+	if( m_Edit_pShape && m_Edit_iPart >= 0 && m_Edit_iPoint >= 0 )
+	{
+		if( m_Edit_pShape->Get_Point_Count(m_Edit_iPart) > 1 )
+		{
+			m_Edit_pShape->Del_Point(m_Edit_iPoint, m_Edit_iPart);
+
+			if( m_Edit_iPoint >= m_Edit_pShape->Get_Point_Count(m_Edit_iPart) )
+			{
+				m_Edit_iPoint	= m_Edit_pShape->Get_Point_Count(m_Edit_iPart) - 1;
+			}
+
+			if( m_Edit_pShape->Get_Point_Count(m_Edit_iPart) <= 1 )
+			{
+				if( m_pShapes->Get_Type() == SHAPE_TYPE_Line || m_pShapes->Get_Type() == SHAPE_TYPE_Polygon )
+				{
+					m_Edit_iPoint	= -1;
+				}
+			}
+
+			Update_Views(true);
+
+			return( true );
+		}
+		else
+		{
+			return( _Edit_Part_Del() );
+		}
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Shape_Draw_Point(wxDC &dc, TSG_Point_Int Point, bool bSelected)
+{
+	_Edit_Shape_Draw_Point(dc, Point.x, Point.y, bSelected);
+}
+
+void CWKSP_Shapes::_Edit_Shape_Draw_Point(wxDC &dc, int x, int y, bool bSelected)
+{
+	dc.SetPen  (wxPen(m_Edit_Color));
+	dc.SetBrush(*wxTRANSPARENT_BRUSH);
+
+	dc.DrawCircle(x, y, 2);
+
+	Draw_Edge(dc, EDGE_STYLE_SIMPLE,
+		x - EDIT_TICKMARK_SIZE - 1,
+		y - EDIT_TICKMARK_SIZE - 1,
+		x + EDIT_TICKMARK_SIZE,
+		y + EDIT_TICKMARK_SIZE
+	);
+
+	if( bSelected )
+	{
+		dc.SetPen(*wxRED_PEN);
+
+		Draw_Edge(dc, EDGE_STYLE_SIMPLE,
+			x - EDIT_TICKMARK_SIZE - 2,
+			y - EDIT_TICKMARK_SIZE - 2,
+			x + EDIT_TICKMARK_SIZE + 1,
+			y + EDIT_TICKMARK_SIZE + 1
+		);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Shape_Draw_Move(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point)
+{
+	_Edit_Shape_Draw_Point(dc, Point.x, Point.y, false);
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Shape_Draw(CWKSP_Map_DC &dc_Map)
+{
+	int		iPart, iPoint;
+
+	if( m_Edit_pShape )
+	{
+		for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				_Edit_Shape_Draw_Point(dc_Map.dc, dc_Map.World2DC(m_Edit_pShape->Get_Point(iPoint, iPart)), false);
+			}
+		}
+
+		if( m_Edit_iPart >= 0 && m_Edit_iPoint >= 0 )
+		{
+			_Edit_Shape_Draw_Point(dc_Map.dc, dc_Map.World2DC(m_Edit_pShape->Get_Point(m_Edit_iPoint, m_Edit_iPart)), true);
+		}
+
+		if( m_Parameters("EDIT_SNAP_LIST")->asShapesList()->Get_Count() > 0 )
+		{
+			iPoint	= m_Parameters("EDIT_SNAP_DIST")->asInt();
+
+			dc_Map.dc.DrawCircle(1 + iPoint, 1 + iPoint, iPoint);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Snap_Point(CSG_Point &Point, double ClientToWorld)
+{
+	if( m_Edit_pShape )
+	{
+		CSG_Parameter_Shapes_List	*pList	= m_Parameters("EDIT_SNAP_LIST")->asShapesList();
+
+		if( pList->Get_Count() > 0 )
+		{
+			int			i;
+			double		snap_Dist, max_Dist;
+			CSG_Point	snap_Point;
+
+			max_Dist	= m_Parameters("EDIT_SNAP_DIST")->asDouble() * ClientToWorld;
+			snap_Dist	= max_Dist + 1.0;
+
+			for(i=0; i<pList->Get_Count(); i++)
+			{
+				_Edit_Snap_Point(Point, snap_Point, snap_Dist, pList->asShapes(i), false);
+			}
+
+			if( snap_Dist <= max_Dist )
+			{
+				Point	= snap_Point;
+			}
+			else if( m_pShapes->Get_Type() == SHAPE_TYPE_Line || m_pShapes->Get_Type() == SHAPE_TYPE_Polygon )
+			{
+				for(i=0; i<pList->Get_Count(); i++)
+				{
+					_Edit_Snap_Point(Point, snap_Point, snap_Dist, pList->asShapes(i), true);
+				}
+
+				if( snap_Dist <= max_Dist )
+				{
+					Point	= snap_Point;
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Snap_Point(CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shapes *pShapes, bool bLine)
+{
+	CSG_Shape	*pSelected	= pShapes->Get_Selection();
+
+	if( pShapes->Select(CSG_Rect(Point.Get_X() - snap_Dist, Point.Get_Y() - snap_Dist, Point.Get_X() + snap_Dist, Point.Get_Y() + snap_Dist)) )
+	{
+		for(int i=0; i<pShapes->Get_Selection_Count(); i++)
+		{
+			if( pShapes != m_pShapes || pSelected != pShapes->Get_Selection(i) )
+			{
+				if( bLine )
+				{
+					_Edit_Snap_Point_ToLine(Point, snap_Point, snap_Dist, pShapes->Get_Selection(i));
+				}
+				else
+				{
+					_Edit_Snap_Point       (Point, snap_Point, snap_Dist, pShapes->Get_Selection(i));
+				}
+			}
+		}
+	}
+
+	pShapes->Select(pSelected);
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Snap_Point(CSG_Point pos_Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape)
+{
+	int			iPart, iPoint;
+	double		d, dx, dy;
+	TSG_Point	Point;
+
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			Point	= pShape->Get_Point(iPoint, iPart);
+			dx		= pos_Point.Get_X() - Point.x;
+			dy		= pos_Point.Get_Y() - Point.y;
+			d		= sqrt(dx*dx + dy*dy);
+
+			if( d < snap_Dist )
+			{
+				snap_Dist	= d;
+				snap_Point	= Point;
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes::_Edit_Snap_Point_ToLine(CSG_Point pos_Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Shapes::_Edit_Shape_HitTest(CSG_Point pos_Point, double max_Dist, int &pos_iPart, int &pos_iPoint)
+{
+	int			Result, iPart, iPoint;
+	double		d, dx, dy;
+	TSG_Point	Point;
+
+	Result		= 0;
+
+	pos_iPoint	= -1;
+	pos_iPart	= -1;
+
+	if( m_Edit_pShape )
+	{
+		for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				Point	= m_Edit_pShape->Get_Point(iPoint, iPart);
+				dx		= pos_Point.Get_X() - Point.x;
+				dy		= pos_Point.Get_Y() - Point.y;
+				d		= sqrt(dx*dx + dy*dy);
+
+				if( 0.0 > max_Dist || d < max_Dist )
+				{
+					Result		= 1;
+					max_Dist	= d;
+					pos_iPoint	= iPoint;
+					pos_iPart	= iPart;
+				}
+			}
+		}
+	}
+
+	return( Result );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,588 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Shapes_Line.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_layer_classify.h"
+
+#include "wksp_shapes_line.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Line::CWKSP_Shapes_Line(CSG_Shapes *pShapes)
+	: CWKSP_Shapes(pShapes)
+{
+	Create_Parameters();
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Line::~CWKSP_Shapes_Line(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::On_Create_Parameters(void)
+{
+	CWKSP_Shapes::On_Create_Parameters();
+
+
+	//-----------------------------------------------------
+	// Display...
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY"), "DISPLAY_POINTS"	, LNG("[CAP] Show Vertices"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_DISPLAY"), "LINE_STYLE"		, LNG("[CAP] Line Style"),
+		LNG(""),
+		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+			LNG("Solid style"),
+			LNG("Dotted style"),
+			LNG("Long dashed style"),
+			LNG("Short dashed style"), 
+			LNG("Dot and dash style"),
+			LNG("Backward diagonal hatch"),
+			LNG("Cross-diagonal hatch"),
+			LNG("Forward diagonal hatch"),
+			LNG("Cross hatch"),
+			LNG("Horizontal hatch"),
+			LNG("Vertical hatch")
+		//	LNG("Use the stipple bitmap")
+		//	LNG("Use the user dashes")
+		//	LNG("No pen is used")
+		), 0
+	);
+
+
+	//-----------------------------------------------------
+	// Size...
+
+	m_Parameters.Add_Node(
+		NULL						, "NODE_SIZE"		, LNG("[CAP] Display: Size"),
+		LNG("")
+	);
+
+	_AttributeList_Add(
+		m_Parameters("NODE_SIZE")	, "SIZE_ATTRIB"		, LNG("[CAP] Attribute"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_SIZE")	, "SIZE_TYPE"		, LNG("[CAP] Size relates to..."),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|"),
+			LNG("[VAL] Screen"),
+			LNG("[VAL] Map Units")
+		), 0
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_SIZE")	, "SIZE_DEFAULT"	, LNG("[CAP] Default Size"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 0, 0, true
+	);
+
+	m_Parameters.Add_Range(
+		m_Parameters("NODE_SIZE")	, "SIZE_RANGE"		, LNG("[CAP] Size Range"),
+		LNG(""),
+		0, 10, 0, true
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::On_DataObject_Changed(void)
+{
+	CWKSP_Shapes::On_DataObject_Changed();
+
+	_AttributeList_Set(m_Parameters("SIZE_ATTRIB"), true);
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::On_Parameters_Changed(void)
+{
+	CWKSP_Shapes::On_Parameters_Changed();
+
+	//-----------------------------------------------------
+	m_Size_Type		= m_Parameters("SIZE_TYPE")->asInt();
+
+	if(	(m_iSize	= m_Parameters("SIZE_ATTRIB")->asInt()) >= m_pShapes->Get_Field_Count()
+	||	(m_dSize	= m_pShapes->Get_Maximum(m_iSize) - (m_Size_Min = m_pShapes->Get_Minimum(m_iSize))) <= 0.0 )
+	{
+		m_iSize		= -1;
+		m_Size		= m_Parameters("SIZE_DEFAULT")->asInt();
+	}
+	else
+	{
+		m_Size		= (int)m_Parameters("SIZE_RANGE")->asRange()->Get_LoVal();
+		m_dSize		=     (m_Parameters("SIZE_RANGE")->asRange()->Get_HiVal() - m_Size) / m_dSize;
+	}
+
+	//-----------------------------------------------------
+	Get_Style(m_Pen);
+
+	m_bPoints	= m_Parameters("DISPLAY_POINTS")->asBool();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Shapes_Line::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	CWKSP_Shapes::On_Parameter_Changed(pParameters, pParameter);
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Line::Get_Style(wxPen &Pen, wxString *pName)
+{
+	Pen		= wxPen(m_Def_Color, (int)m_Size, m_Line_Style);
+
+	if( pName )
+	{
+		if(	m_iColor < 0 || m_pClassify->Get_Mode() == CLASSIFY_UNIQUE )
+		{
+			pName->Clear();
+		}
+		else
+		{
+			pName->Printf(m_pShapes->Get_Field_Name(m_iColor));
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Line::Get_Style_Size(int &min_Size, int &max_Size, double &min_Value, double &dValue, wxString *pName)
+{
+	if( m_iSize >= 0 )
+	{
+		min_Size	= (int)(m_Size);
+		max_Size	= (int)(m_Size + ((m_pShapes->Get_Maximum(m_iSize) - m_Size_Min) * m_dSize));
+		min_Value	= m_Size_Min;
+		dValue		= m_dSize;
+
+		if( pName )
+		{
+			pName->Printf(m_pShapes->Get_Field_Name(m_iSize));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::_Draw_Initialize(CWKSP_Map_DC &dc_Map)
+{
+	switch( m_Parameters("LINE_STYLE")->asInt() )
+	{
+	case  0:	m_Line_Style	= wxSOLID;				break; // Solid style.
+	case  1:	m_Line_Style	= wxDOT;				break; // Dotted style.
+	case  2:	m_Line_Style	= wxLONG_DASH;			break; // Long dashed style.
+	case  3:	m_Line_Style	= wxSHORT_DASH;			break; // Short dashed style.
+	case  4:	m_Line_Style	= wxDOT_DASH;			break; // Dot and dash style.
+	case  5:	m_Line_Style	= wxBDIAGONAL_HATCH;	break; // Backward diagonal hatch.
+	case  6:	m_Line_Style	= wxCROSSDIAG_HATCH;	break; // Cross-diagonal hatch.
+	case  7:	m_Line_Style	= wxFDIAGONAL_HATCH;	break; // Forward diagonal hatch.
+	case  8:	m_Line_Style	= wxCROSS_HATCH;		break; // Cross hatch.
+	case  9:	m_Line_Style	= wxHORIZONTAL_HATCH;	break; // Horizontal hatch.
+	case 10:	m_Line_Style	= wxVERTICAL_HATCH;		break; // Vertical hatch.
+//	case 11:	m_Line_Style	= wxSTIPPLE;			break; // Use the stipple bitmap. 
+//	case 12:	m_Line_Style	= wxUSER_DASH;			break; // Use the user dashes: see wxPen::SetDashes.
+//	case 13:	m_Line_Style	= wxTRANSPARENT;		break; // No pen is used.
+	}
+
+	m_Pen.SetStyle(m_Line_Style);
+
+	dc_Map.dc.SetPen(m_Pen);
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::_Draw_Shape(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection)
+{
+	//-----------------------------------------------------
+	if( bSelection )
+	{
+		dc_Map.dc.SetPen(wxPen(m_Sel_Color, m_Size + (pShape == m_pShapes->Get_Selection(0) ? 2 : 0), m_Line_Style));
+	}
+	else if( m_iColor >= 0 || m_iSize >= 0 )
+	{
+		wxPen	Pen(m_Pen);
+
+		if( m_iColor >= 0 )
+		{
+			int		Color	= m_pClassify->Get_Class_Color_byValue(pShape->asDouble(m_iColor));
+			Pen.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
+		}
+
+		double	dSize	= m_iSize < 0 ? m_Size
+						: m_Size + (pShape->asDouble(m_iSize) - m_Size_Min) * m_dSize;
+
+		switch( m_Size_Type )
+		{
+		default:
+		case 0:	dSize	*= dc_Map.m_Scale;		break;
+		case 1:	dSize	*= dc_Map.m_World2DC;	break;
+		}
+
+		if( dSize >= 0 )
+		{
+			Pen.SetWidth((int)(0.5 + dSize));
+		}
+
+		dc_Map.dc.SetPen(Pen);
+	}
+
+	//-----------------------------------------------------
+	int				iPart, iPoint;
+	TSG_Point_Int	A, B;
+
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		if( pShape->Get_Point_Count(iPart) > 1 )
+		{
+			A		= dc_Map.World2DC(pShape->Get_Point(0, iPart));
+
+			for(iPoint=1; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				B		= A;
+				A		= dc_Map.World2DC(pShape->Get_Point(iPoint, iPart));
+
+				dc_Map.dc.DrawLine(A.x, A.y, B.x, B.y);
+			}
+		}
+	}
+
+	if( m_bPoints )
+	{
+		dc_Map.dc.SetPen(*wxBLACK_PEN);
+		dc_Map.dc.SetBrush(*wxWHITE_BRUSH);
+
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				A		= dc_Map.World2DC(pShape->Get_Point(iPoint, iPart));
+				dc_Map.dc.DrawCircle(A.x, A.y, 2);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	if( bSelection )
+	{
+		dc_Map.dc.SetPen(m_Pen);
+	}
+}
+
+//---------------------------------------------------------
+#define GET_ANGLE(a, b)	M_RAD_TO_DEG * (b.x != a.x ? M_PI_180 - atan2((double)(b.y - a.y), (double)(b.x - a.x)) : (b.y > a.y ? M_PI_270 : (b.y < a.y ? M_PI_090 : 0.0)))
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::_Draw_Label(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)
+{
+	const int	m_Label_Freq	= 10,
+				m_Label_Prec	= 2;
+
+	bool			bLabel;
+	int				iPart, iPoint;
+	double			d;
+	TSG_Point_Int	A, B;
+	wxCoord			sx, sy;
+	wxString		s(pShape->asString(m_iLabel, m_Label_Prec));
+
+	dc_Map.dc.GetTextExtent(s, &sx, &sy);
+
+	//-----------------------------------------------------
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		if( dc_Map.m_World2DC * ((CSG_Shape_Line *)pShape)->Get_Length(iPart) > (2 * m_Label_Freq) * sx )
+		{
+			A		= dc_Map.World2DC(pShape->Get_Point(0, iPart));
+
+			for(iPoint=1, d=0.0, bLabel=false; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				//-----------------------------------------
+				if( !bLabel )
+				{
+					B		= A;
+					A		= dc_Map.World2DC(pShape->Get_Point(iPoint, iPart));
+
+					if( (d += SG_Get_Distance(A.x, A.y, B.x, B.y)) > m_Label_Freq * sx )
+					{
+						bLabel	= true;
+						B		= A;
+					}
+				}
+
+				//-----------------------------------------
+				else
+				{
+					A		= dc_Map.World2DC(pShape->Get_Point(iPoint, iPart));
+
+					if( SG_Get_Distance(A.x, A.y, B.x, B.y) > sx )
+					{
+						bLabel	= false;
+						d		= 0.0;
+
+						dc_Map.dc.DrawRotatedText(s, B.x, B.y, GET_ANGLE(A, B));
+
+					//	dc_Map.dc.DrawCircle(A.x, A.y, 3);	dc_Map.dc.DrawCircle(B.x, B.y, 3);
+					}
+				}
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DRAW_MOVELINE(i)	{	ptWorld	= m_Edit_pShape->Get_Point(i, m_Edit_iPart);\
+								dc.DrawLine(Point.x, Point.y,\
+									(int)((ptWorld.x - rWorld.Get_XMin()) / ClientToWorld),\
+									(int)((rWorld.Get_YMax() - ptWorld.y) / ClientToWorld));	}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::_Edit_Shape_Draw_Move(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point)
+{
+	int			nPoints;
+	TSG_Point	ptWorld;
+
+	if( m_Edit_pShape && m_Edit_iPart >= 0 )
+	{
+		nPoints	= m_Edit_pShape->Get_Point_Count(m_Edit_iPart);
+
+		if( m_Edit_iPoint < 0 )
+		{
+			if( nPoints > 0 )
+			{
+				DRAW_MOVELINE(nPoints - 1);
+			}
+		}
+		else
+		{
+			if( nPoints > 1 )
+			{
+				if( m_Edit_iPoint > 0 )
+					DRAW_MOVELINE(m_Edit_iPoint - 1);
+
+				if( m_Edit_iPoint < nPoints - 1 )
+					DRAW_MOVELINE(m_Edit_iPoint + 1);
+			}
+
+			CWKSP_Shapes::_Edit_Shape_Draw_Move(dc, rWorld, ClientToWorld, Point);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::_Edit_Shape_Draw(CWKSP_Map_DC &dc_Map)
+{
+	int			iPart, iPoint;
+	TSG_Point_Int	ptA, ptB;
+
+	if( m_Edit_pShape )
+	{
+		dc_Map.dc.SetPen(wxPen(m_Edit_Color));
+
+		for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
+		{
+			if( m_Edit_pShape->Get_Point_Count(iPart) > 1 )
+			{
+				ptA		= dc_Map.World2DC(m_Edit_pShape->Get_Point(0, iPart));
+
+				for(iPoint=1; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					ptB		= ptA;
+					ptA		= dc_Map.World2DC(m_Edit_pShape->Get_Point(iPoint, iPart));
+
+					dc_Map.dc.DrawLine(ptA.x, ptA.y, ptB.x, ptB.y);
+				}
+			}
+		}
+
+		CWKSP_Shapes::_Edit_Shape_Draw(dc_Map);
+	}
+}
+
+//---------------------------------------------------------
+int CWKSP_Shapes_Line::_Edit_Shape_HitTest(CSG_Point pos_Point, double max_Dist, int &pos_iPart, int &pos_iPoint)
+{
+	int			Result, iPart, iPoint;
+	double		d;
+	TSG_Point	A, B, Point, hit_Point;
+
+	Result	= CWKSP_Shapes::_Edit_Shape_HitTest(pos_Point, max_Dist, pos_iPart, pos_iPoint);
+
+	if( Result == 0 && m_Edit_pShape )
+	{
+		for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
+		{
+			B	= m_Edit_pShape->Get_Point(0, iPart);
+
+			for(iPoint=1; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				A	= m_Edit_pShape->Get_Point(iPoint, iPart);
+				d	= SG_Get_Nearest_Point_On_Line(pos_Point, A, B, Point, true);
+				B	= A;
+
+				if( d >= 0.0 && (0.0 > max_Dist || d < max_Dist) )
+				{
+					Result		= 2;
+					max_Dist	= d;
+					pos_iPoint	= iPoint;
+					pos_iPart	= iPart;
+					hit_Point	= Point;
+				}
+			}
+		}
+
+		if( Result )
+		{
+			pos_Point	= hit_Point;
+		}
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Line::_Edit_Snap_Point_ToLine(CSG_Point pos_Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape)
+{
+	int			iPart, iPoint;
+	double		d;
+	TSG_Point	A, B, Point;
+
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		B	= pShape->Get_Point(0, iPart);
+
+		for(iPoint=1; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			A	= pShape->Get_Point(iPoint, iPart);
+			d	= SG_Get_Nearest_Point_On_Line(pos_Point, A, B, Point, true);
+			B	= A;
+
+			if( d >= 0.0 && d < snap_Dist )
+			{
+				snap_Dist	= d;
+				snap_Point	= Point;
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_line.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,128 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Shapes_Line.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Line_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Line_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes_Line : public CWKSP_Shapes
+{
+public:
+	CWKSP_Shapes_Line(CSG_Shapes *pShapes);
+	virtual ~CWKSP_Shapes_Line(void);
+
+	bool						Get_Style				(wxPen &Pen, wxString *pName = NULL);
+	bool						Get_Style_Size			(int &min_Size, int &max_Size, double &min_Value, double &dValue, wxString *pName);
+
+
+protected:
+
+	bool						m_bPoints;
+
+	int							m_iSize, m_Size_Type, m_Line_Style;
+
+	double						m_Size, m_dSize, m_Size_Min;
+
+	wxPen						m_Pen;
+
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual void				_Draw_Initialize		(CWKSP_Map_DC &dc_Map);
+	virtual void				_Draw_Shape				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection);
+	virtual void				_Draw_Label				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape);
+
+	virtual void				_Edit_Shape_Draw_Move	(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point);
+	virtual void				_Edit_Shape_Draw		(CWKSP_Map_DC &dc_Map);
+	virtual int					_Edit_Shape_HitTest		(CSG_Point Point, double max_Dist, int &iPart, int &iPoint);
+	virtual void				_Edit_Snap_Point_ToLine (CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Line_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,374 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//               WKSP_Shapes_Manager.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_map_manager.h"
+
+#include "wksp_shapes_manager.h"
+#include "wksp_shapes_type.h"
+#include "wksp_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Manager::CWKSP_Shapes_Manager(void)
+{
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Manager::~CWKSP_Shapes_Manager(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] Shapes") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b><br>"), LNG("[CAP] Shapes"));
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		s.Append(wxString::Format(wxT("%s: %d<br>"), Get_Item(i)->Get_Name().c_str(), ((CWKSP_Base_Manager *)Get_Item(i))->Get_Count()));
+	}
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Shapes_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Shapes"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_OPEN);
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Type * CWKSP_Shapes_Manager::Get_Shapes_Type(int Shape_Type)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( Shape_Type == ((CWKSP_Shapes_Type *)Get_Item(i))->Get_Shapes_Type() )
+		{
+			return( (CWKSP_Shapes_Type *)Get_Item(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Type * CWKSP_Shapes_Manager::_Get_Shapes_Type(int Shape_Type)
+{
+	CWKSP_Shapes_Type	*pItem;
+
+	if( Shape_Type != SHAPE_TYPE_Undefined )
+	{
+		if( (pItem = Get_Shapes_Type(Shape_Type)) == NULL )
+		{
+			Add_Item(pItem = new CWKSP_Shapes_Type(Shape_Type));
+		}
+
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes * CWKSP_Shapes_Manager::Get_Shapes(CSG_Shapes *pShapes)
+{
+	if( pShapes )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( ((CWKSP_Shapes_Type *)Get_Item(i))->Exists(pShapes) )
+			{
+				return( ((CWKSP_Shapes_Type *)Get_Item(i))->Get_Shapes(pShapes) );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::Exists(CSG_Shapes *pShapes)
+{
+	return( Get_Shapes(pShapes) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes * CWKSP_Shapes_Manager::Add(CSG_Shapes *pShapes)
+{
+	if( pShapes && pShapes->is_Valid() && !Exists(pShapes) )
+	{
+		return( _Get_Shapes_Type(pShapes->Get_Type())->Add(pShapes) );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Shapes * CWKSP_Shapes_Manager::Get_byFileName(const wxChar *File_Name)
+{
+	CSG_String	s(File_Name);
+	CWKSP_Shapes_Type	*pType;
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		pType	= (CWKSP_Shapes_Type *)Get_Item(i);
+
+		for(int j=0; j<pType->Get_Count(); j++)
+		{
+			if( !s.Cmp(pType->Get_Shapes(j)->Get_Shapes()->Get_File_Name()) )
+			{
+				return( pType->Get_Shapes(j)->Get_Shapes() );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::Update(CSG_Shapes *pShapes, CSG_Parameters *pParameters)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( (pItem = Get_Shapes(pShapes)) != NULL )
+	{
+		pItem->DataObject_Changed(pParameters);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::Update_Views(CSG_Shapes *pShapes)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( (pItem = Get_Shapes(pShapes)) != NULL )
+	{
+		pItem->Update_Views(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::Show(CSG_Shapes *pShapes, int Map_Mode)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( (pItem = Get_Shapes(pShapes)) != NULL )
+	{
+		switch( Map_Mode )
+		{
+		case SG_UI_DATAOBJECT_SHOW:
+			return( pItem->Show() );
+
+		case SG_UI_DATAOBJECT_SHOW_NEW_MAP:
+			g_pMaps->Add(pItem, NULL);
+
+		case SG_UI_DATAOBJECT_SHOW_LAST_MAP:
+			return( pItem->Show(g_pMaps->Get_Map(g_pMaps->Get_Count() - 1)) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::asImage(CSG_Shapes *pShapes, CSG_Grid *pImage)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( (pItem = Get_Shapes(pShapes)) != NULL )
+	{
+		return( pItem->asImage(pImage) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::Get_Colors(CSG_Shapes *pShapes, CSG_Colors *pColors)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( (pItem = Get_Shapes(pShapes)) != NULL )
+	{
+		return( pItem->Get_Colors(pColors) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Manager::Set_Colors(CSG_Shapes *pShapes, CSG_Colors *pColors)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( (pItem = Get_Shapes(pShapes)) != NULL )
+	{
+		pItem->DataObject_Changed(pColors);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,127 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Shapes_Manager.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Shapes_Manager(void);
+	virtual ~CWKSP_Shapes_Manager(void);
+
+	virtual TWKSP_Item			Get_Type		(void)	{	return( WKSP_ITEM_Shapes_Manager );	}
+
+	virtual wxString			Get_Name		(void);
+	virtual wxString			Get_Description	(void);
+
+	virtual wxMenu *			Get_Menu		(void);
+
+	virtual bool				On_Command		(int Cmd_ID);
+
+	class CWKSP_Shapes_Type *	Get_Shapes_Type	(int Shape_Type);
+	class CWKSP_Shapes *		Get_Shapes		(class CSG_Shapes *pShapes);
+
+	bool						Exists			(class CSG_Shapes *pShapes);
+	class CWKSP_Shapes *		Add				(class CSG_Shapes *pShapes);
+	class CSG_Shapes *			Get_byFileName	(const wxChar *File_Name);
+
+	bool						Update			(class CSG_Shapes *pShapes, class CSG_Parameters *pParameters);
+	bool						Update_Views	(class CSG_Shapes *pShapes);
+	bool						Show			(class CSG_Shapes *pShapes, int Map_Mode);
+	bool						asImage			(class CSG_Shapes *pShapes, class CSG_Grid *pImage);
+
+	bool						Get_Colors		(class CSG_Shapes *pShapes, class CSG_Colors *pColors);
+	bool						Set_Colors		(class CSG_Shapes *pShapes, class CSG_Colors *pColors);
+
+
+private:
+
+	class CWKSP_Shapes_Type *	_Get_Shapes_Type(int Shape_Type);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,668 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Shapes_Point.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <wx/filename.h>
+
+#include "res_commands.h"
+#include "res_images.h"
+
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_layer_classify.h"
+
+#include "wksp_shapes_point.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Point::CWKSP_Shapes_Point(CSG_Shapes *pShapes)
+	: CWKSP_Shapes(pShapes)
+{
+	Create_Parameters();
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Point::~CWKSP_Shapes_Point(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Point::On_Create_Parameters(void)
+{
+	CWKSP_Shapes::On_Create_Parameters();
+
+	_BrushList_Add(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_BRUSH"			, LNG("[CAP] Fill Style"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_OUTLINE"			, LNG("[CAP] Outline"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_OUTLINE_COLOR"	, LNG("[CAP] Outline Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(0, 0, 0)
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_OUTLINE_SIZE"	, LNG("[CAP] Outline Size"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 0, 0, true
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_SYMBOL_TYPE"		, LNG("[CAP] Symbol Type"),
+		LNG(""),
+
+		CSG_String::Format(wxT("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|"),
+			LNG("circle"),
+			LNG("square"),
+			LNG("rhombus"),
+			LNG("triangle (up)"),
+			LNG("triangle (down)"),
+			LNG("circle with square"),
+			LNG("circle with rhombus"),
+			LNG("circle with triangle (up)"),
+			LNG("circle with triangle (down)"),
+			LNG("circle in square"),
+			LNG("circle in rhombus"),
+			LNG("circle in triangle (up)"),
+			LNG("circle in triangle (down)"),
+			LNG("image")
+		), 0
+	);
+
+	m_Parameters.Add_FilePath(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_SYMBOL_IMAGE"	, LNG("[CAP] Symbol Image"),
+		LNG(""),
+		CSG_String::Format(
+			wxT("%s|*.bmp;*.ico;*.gif;*.jpg;*.jif;*.jpeg;*.pcx;*.png;*.pnm;*.tif;*.tiff;*.xpm|")
+			wxT("%s (*.bmp)|*.bmp|")
+			wxT("%s (*.jpg)|*.jpg;*.jif;*.jpeg|")
+			wxT("%s (*.png)|*.png|")
+			wxT("%s (*.pcx)|*.pcx|")
+			wxT("%s (*.xpm)|*.xpm|")
+			wxT("%s (*.tif)|*.tif;*.tiff|")
+			wxT("%s (*.gif)|*.gif|")
+			wxT("%s|*.*"),
+			LNG("Image Files"),
+			LNG("Windows or OS/2 Bitmap"),
+			LNG("JPEG - JFIF Compliant"),
+			LNG("Portable Network Graphics"),
+			LNG("Zsoft Paintbrush"),
+			LNG("X11 Pixel Map"),
+			LNG("Tagged Image File Format"),
+			LNG("CompuServe Graphics Interchange"),
+			LNG("All Files")
+		)
+	);
+
+
+	//-----------------------------------------------------
+	// Size...
+
+	m_Parameters.Add_Node(
+		NULL						, "NODE_SIZE"		, LNG("[CAP] Display: Size"),
+		LNG("")
+	);
+
+	_AttributeList_Add(
+		m_Parameters("NODE_SIZE")	, "SIZE_ATTRIB"		, LNG("[CAP] Attribute"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_SIZE")	, "SIZE_TYPE"		, LNG("[CAP] Size relates to..."),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|"),
+			LNG("[VAL] Screen"),
+			LNG("[VAL] Map Units")
+		), 0
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_SIZE")	, "SIZE_DEFAULT"	, LNG("[CAP] Default Size"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 5, 0, true
+	);
+
+	m_Parameters.Add_Range(
+		m_Parameters("NODE_SIZE")	, "SIZE_RANGE"		, LNG("[CAP] Size Range"),
+		LNG(""),
+		2, 10, 0, true
+	);
+
+
+	//-----------------------------------------------------
+	// Label...
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_LABEL")	, "LABEL_ANGLE"			, LNG("[CAP] Rotation (Degree)"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0, -360.0, true, 360.0, true
+	);
+
+	_AttributeList_Add(
+		m_Parameters("NODE_LABEL")	, "LABEL_ANGLE_ATTRIB"	, LNG("[CAP] Rotation by Attribute"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_LABEL")	, "LABEL_ALIGN_X"		, LNG("[CAP] Horizontal Align"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("left"),
+			LNG("center"),
+			LNG("right")
+		), 1
+	);
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_LABEL")	, "LABEL_ALIGN_Y"		, LNG("[CAP] Vertical Align"),
+		LNG(""),
+		wxString::Format(wxT("%s|%s|%s|"),
+			LNG("top"),
+			LNG("center"),
+			LNG("bottom")
+		), 0
+	);
+
+	//-----------------------------------------------------
+	// Edit...
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_SELECTION")	, "EDIT_SEL_COLOR_FILL"	, LNG("[CAP] Fill Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(255, 255, 0)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Point::On_DataObject_Changed(void)
+{
+	CWKSP_Shapes::On_DataObject_Changed();
+
+	_AttributeList_Set(m_Parameters("SIZE_ATTRIB")			, true);
+	_AttributeList_Set(m_Parameters("LABEL_ANGLE_ATTRIB")	, true);
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Point::On_Parameters_Changed(void)
+{
+	CWKSP_Shapes::On_Parameters_Changed();
+
+	//-----------------------------------------------------
+	m_Symbol_Type	= m_Parameters("DISPLAY_SYMBOL_TYPE")->asInt();
+
+	if( !wxFileName::FileExists(m_Parameters("DISPLAY_SYMBOL_IMAGE")->asString())
+	||	!m_Symbol.LoadFile(m_Parameters("DISPLAY_SYMBOL_IMAGE")->asString()) )
+	{
+		m_Symbol	= IMG_Get_Image(ID_IMG_DEFAULT);
+	}
+
+	//-----------------------------------------------------
+	m_Size_Type		= m_Parameters("SIZE_TYPE")->asInt();
+
+	if(	(m_iSize	= m_Parameters("SIZE_ATTRIB")->asInt()) >= m_pShapes->Get_Field_Count()
+	||	(m_dSize	= m_pShapes->Get_Maximum(m_iSize) - (m_Size_Min = m_pShapes->Get_Minimum(m_iSize))) <= 0.0 )
+	{
+		m_iSize		= -1;
+		m_Size		= m_Parameters("SIZE_DEFAULT")->asDouble();
+	}
+	else
+	{
+		m_Size		=  m_Parameters("SIZE_RANGE")->asRange()->Get_LoVal();
+		m_dSize		= (m_Parameters("SIZE_RANGE")->asRange()->Get_HiVal() - m_Size) / m_dSize;
+	}
+
+	//-----------------------------------------------------
+	m_Label_Angle	= m_Parameters("LABEL_ANGLE")->asDouble();
+
+	if( (m_iLabel_Angle	= m_Parameters("LABEL_ANGLE_ATTRIB")->asInt()) >= m_pShapes->Get_Field_Count() )
+	{
+		m_iLabel_Angle	= -1;
+	}
+
+	switch( m_Parameters("LABEL_ALIGN_X")->asInt() )
+	{
+	case 0:	m_Label_Align	 = TEXTALIGN_LEFT;		break;
+	case 1:	m_Label_Align	 = TEXTALIGN_XCENTER;	break;
+	case 2:	m_Label_Align	 = TEXTALIGN_RIGHT;		break;
+	}
+
+	switch( m_Parameters("LABEL_ALIGN_Y")->asInt() )
+	{
+	case 0:	m_Label_Align	|= TEXTALIGN_TOP;		break;
+	case 1:	m_Label_Align	|= TEXTALIGN_YCENTER;	break;
+	case 2:	m_Label_Align	|= TEXTALIGN_BOTTOM;	break;
+	}
+
+	//-----------------------------------------------------
+	Get_Style(m_Pen, m_Brush, m_bOutline);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Shapes_Point::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	CWKSP_Shapes::On_Parameter_Changed(pParameters, pParameter);
+
+	//-----------------------------------------------------
+	if(	!SG_STR_CMP(pParameter->Get_Identifier(), wxT("COLORS_FONT")) )
+	{
+		int		zField	= pParameters->Get_Parameter("COLORS_ATTRIB")->asInt();
+
+		pParameters->Get_Parameter("METRIC_ZRANGE")->asRange()->Set_Range(
+			m_pShapes->Get_Minimum(zField),
+			m_pShapes->Get_Maximum(zField)
+		);
+	}
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Point::Get_Style(wxPen &Pen, wxBrush &Brush, bool &bOutline, wxString *pName)
+{
+	bOutline	= m_Parameters("DISPLAY_OUTLINE")->asBool();
+	Brush		= wxBrush(m_Def_Color, _BrushList_Get_Style(m_Parameters("DISPLAY_BRUSH")->asInt()));
+	Pen			= wxPen(!bOutline ? m_Def_Color : Get_Color_asWX(m_Parameters("DISPLAY_OUTLINE_COLOR")->asColor()), m_Parameters("DISPLAY_OUTLINE_SIZE")->asInt(), wxSOLID);
+
+	if( pName )
+	{
+		if(	m_iColor < 0 || m_pClassify->Get_Mode() == CLASSIFY_UNIQUE )
+		{
+			pName->Clear();
+		}
+		else
+		{
+			pName->Printf(m_pShapes->Get_Field_Name(m_iColor));
+		}
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Point::Get_Style_Size(int &min_Size, int &max_Size, double &min_Value, double &dValue, wxString *pName)
+{
+	if( m_iSize >= 0 )
+	{
+		min_Size	= (int)(m_Size);
+		max_Size	= (int)(m_Size + (m_pShapes->Get_Maximum(m_iSize) - m_Size_Min) * m_dSize);
+		min_Value	= m_Size_Min;
+		dValue		= m_dSize;
+
+		if( pName )
+		{
+			pName->Printf(m_pShapes->Get_Field_Name(m_iSize));
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+inline void CWKSP_Shapes_Point::_Draw_Initialize(CWKSP_Map_DC &dc_Map)
+{
+	dc_Map.dc.SetBrush	(m_Brush);
+	dc_Map.dc.SetPen	(m_Pen);
+
+	m_Sel_Color_Fill	= Get_Color_asWX(m_Parameters("EDIT_SEL_COLOR_FILL")->asInt());
+}
+
+//---------------------------------------------------------
+inline bool CWKSP_Shapes_Point::_Draw_Initialize(CWKSP_Map_DC &dc_Map, int &Size, CSG_Shape *pShape, bool bSelection)
+{
+	//-----------------------------------------------------
+	double	dSize	= m_iSize < 0 ? m_Size : m_Size + (pShape->asDouble(m_iSize) - m_Size_Min) * m_dSize;
+
+	switch( m_Size_Type )
+	{
+	default:
+	case 0:	dSize	*= dc_Map.m_Scale;		break;
+	case 1:	dSize	*= dc_Map.m_World2DC;	break;
+	}
+
+	Size	= (int)(0.5 + dSize);
+
+	//-----------------------------------------------------
+	if( Size > 0 )
+	{
+		if( bSelection )
+		{
+			dc_Map.dc.SetBrush	(wxBrush(m_Sel_Color_Fill	, wxSOLID));
+			dc_Map.dc.SetPen	(wxPen	(m_Sel_Color     , 0, wxSOLID));
+		}
+		else if( !bSelection && m_iColor >= 0 )
+		{
+			int		Color	= m_pClassify->Get_Class_Color_byValue(pShape->asDouble(m_iColor));
+
+			wxBrush	Brush(m_Brush);
+			Brush.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
+			dc_Map.dc.SetBrush(Brush);
+
+			if( !m_bOutline )
+			{
+				wxPen	Pen(m_Pen);
+				Pen.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
+				dc_Map.dc.SetPen(Pen);
+			}
+		}
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Point::_Draw_Shape(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection)
+{
+	int		Size;
+
+	//-----------------------------------------------------
+	if( _Draw_Initialize(dc_Map, Size, pShape, bSelection) )
+	{
+		TSG_Point_Int	p(dc_Map.World2DC(pShape->Get_Point(0)));
+
+		Draw_Symbol(dc_Map.dc, p.x, p.y, Size);
+
+		//-------------------------------------------------
+		if( bSelection )
+		{
+			_Draw_Initialize(dc_Map);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Point::_Draw_Label(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)
+{
+	TSG_Point_Int	p(dc_Map.World2DC(pShape->Get_Point(0)));
+
+	if( m_iLabel_Angle < 0 )
+	{
+		if( m_Label_Angle == 0.0 )
+		{
+			Draw_Text(dc_Map.dc, m_Label_Align, p.x, p.y, pShape->asString(m_iLabel, -2));
+		}
+		else
+		{
+			Draw_Text(dc_Map.dc, m_Label_Align, p.x, p.y, m_Label_Angle, pShape->asString(m_iLabel, -2));
+		}
+	}
+	else
+	{
+		Draw_Text(dc_Map.dc, m_Label_Align, p.x, p.y, pShape->asDouble(m_iLabel_Angle), pShape->asString(m_iLabel, -2));
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DRAW_CIRCLE(d)		{	int		s	= (int)((d) * size);\
+	dc.DrawCircle(x, y, s);\
+}
+
+#define DRAW_SQUARE			{	int		s	= (int)(0.7071067812 * size);\
+	dc.DrawRectangle(x - s, y - s, 2 * s, 2 * s);\
+}
+
+#define DRAW_RHOMBUS		{	wxPoint	p[4];\
+	p[0].y	= p[2].y	= y;\
+	p[1].x	= p[3].x	= x;\
+	p[0].x				= x - size;\
+	p[2].x				= x + size;\
+	p[1].y				= y - size;\
+	p[3].y				= y + size;\
+	dc.DrawPolygon(4, p);\
+}
+
+#define DRAW_TRIANGLE_UP	{	wxPoint	p[3];\
+	p[0].y	= p[1].y	= y + (size / 2);\
+	p[2].y				= y - (size - 1);\
+	p[0].x				= x - (int)(0.8660254038 * size);\
+	p[1].x				= x + (int)(0.8660254038 * size);\
+	p[2].x				= x;\
+	dc.DrawPolygon(3, p);\
+}
+
+#define DRAW_TRIANGLE_DOWN	{	wxPoint	p[3];\
+	p[0].y	= p[1].y	= y - (size / 2);\
+	p[2].y				= y + (size - 1);\
+	p[0].x				= x - (int)(0.8660254038 * size);\
+	p[1].x				= x + (int)(0.8660254038 * size);\
+	p[2].x				= x;\
+	dc.DrawPolygon(3, p);\
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Point::Draw_Symbol(wxDC &dc, int x, int y, int size)
+{
+	switch( m_Symbol_Type )
+	{
+	default:
+	case 0:		// circle
+		DRAW_CIRCLE(1.0);
+		break;
+
+	case 1:		// square
+		DRAW_SQUARE;
+		break;
+
+	case 2:		// rhombus
+		DRAW_RHOMBUS;
+		break;
+
+	case 3:		// triangle up
+		DRAW_TRIANGLE_UP;
+		break;
+
+	case 4:		// triangle down
+		DRAW_TRIANGLE_DOWN;
+		break;
+
+	case 5:		// square in circle
+		DRAW_CIRCLE(1.0);
+		DRAW_SQUARE;
+		break;
+
+	case 6:		// rhombus in circle
+		DRAW_CIRCLE(1.1);
+		DRAW_RHOMBUS;
+		break;
+
+	case 7:		// triangle up in circle
+		DRAW_CIRCLE(1.0);
+		DRAW_TRIANGLE_UP;
+		break;
+
+	case 8:		// triangle down in circle
+		DRAW_CIRCLE(1.0);
+		DRAW_TRIANGLE_DOWN;
+		break;
+
+	case 9:		// circle in square
+		DRAW_SQUARE;
+		DRAW_CIRCLE(0.7);
+		break;
+
+	case 10:	// circle in rhombus
+		DRAW_RHOMBUS;
+		DRAW_CIRCLE(0.5 * sqrt(2.0));
+		break;
+
+	case 11:	// circle in triangle up
+		DRAW_TRIANGLE_UP;
+		DRAW_CIRCLE(0.5);
+		break;
+
+	case 12:	// circle in triangle down
+		DRAW_TRIANGLE_DOWN;
+		DRAW_CIRCLE(0.5);
+		break;
+
+	case 13:	// image
+		{
+			double	d	= (double)m_Symbol.GetWidth() / (double)m_Symbol.GetHeight();
+			int		sx, sy;
+
+			if( d > 1.0 )
+			{
+				sx	= size;
+				sy	= (int)(0.5 + size / d);
+			}
+			else
+			{
+				sx	= (int)(0.5 + size * d);
+				sy	= size;
+			}
+
+			if( sx > 0 && sy > 0 )
+			{
+				dc.DrawBitmap(wxBitmap(m_Symbol.Scale(2 * sx, 2 * sy)), x - sx, y - sy, true);
+			}
+		}
+		break;
+	}	
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Shapes_Point::On_Edit_Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu;
+
+	CMD_Menu_Add_Item(pMenu, true , ID_CMD_SHAPES_EDIT_SHAPE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_ADD_SHAPE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_DEL_SHAPE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SHAPES_EDIT_SEL_INVERT);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_point.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,134 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Shapes_Point.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Point_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Point_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes_Point : public CWKSP_Shapes
+{
+public:
+	CWKSP_Shapes_Point(CSG_Shapes *pShapes);
+	virtual ~CWKSP_Shapes_Point(void);
+
+	bool						Get_Style				(wxPen &Pen, wxBrush &Brush, bool &bOutline, wxString *pName = NULL);
+	bool						Get_Style_Size			(int &min_Size, int &max_Size, double &min_Value, double &dValue, wxString *pName);
+
+	void						Draw_Symbol				(wxDC &dc, int x, int y, int size);
+
+
+protected:
+
+	bool						m_bOutline;
+
+	int							m_iSize, m_Size_Type, m_Symbol_Type, m_iLabel_Angle, m_Label_Align;
+
+	double						m_Size, m_dSize, m_Size_Min, m_Label_Angle;
+
+	wxColour					m_Sel_Color_Fill;
+
+	wxPen						m_Pen;
+
+	wxBrush						m_Brush;
+
+	wxImage						m_Symbol;
+
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual void				_Draw_Initialize		(CWKSP_Map_DC &dc_Map);
+	virtual bool				_Draw_Initialize		(CWKSP_Map_DC &dc_Map, int &Size, CSG_Shape *pShape, bool bSelection);
+	virtual void				_Draw_Shape				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection);
+	virtual void				_Draw_Label				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape);
+
+	virtual wxMenu *			On_Edit_Get_Menu		(void);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Point_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,187 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Shapes_Points.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_map_control.h"
+
+#include "wksp_shapes_points.h"
+#include "wksp_table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Points::CWKSP_Shapes_Points(CSG_Shapes *pShapes)
+	: CWKSP_Shapes_Point(pShapes)
+{
+	Create_Parameters();
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Points::~CWKSP_Shapes_Points(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Points::On_Create_Parameters(void)
+{
+	CWKSP_Shapes_Point::On_Create_Parameters();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Points::On_DataObject_Changed(void)
+{
+	CWKSP_Shapes_Point::On_DataObject_Changed();
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Points::On_Parameters_Changed(void)
+{
+	CWKSP_Shapes_Point::On_Parameters_Changed();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Shapes_Points::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	CWKSP_Shapes_Point::On_Parameter_Changed(pParameters, pParameter);
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Points::_Draw_Shape(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection)
+{
+	int		Size;
+
+	//-----------------------------------------------------
+	if( CWKSP_Shapes_Point::_Draw_Initialize(dc_Map, Size, pShape, bSelection) )
+	{
+		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				TSG_Point_Int	p	= dc_Map.World2DC(pShape->Get_Point(iPoint, iPart));
+
+				Draw_Symbol(dc_Map.dc, p.x, p.y, Size);
+			}
+		}
+
+		//-------------------------------------------------
+		if( bSelection )
+		{
+			CWKSP_Shapes_Point::_Draw_Initialize(dc_Map);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Points::_Draw_Label(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)
+{
+	TSG_Point_Int	p(dc_Map.World2DC(pShape->Get_Extent().Get_Center()));
+
+	dc_Map.dc.DrawText(pShape->asString(m_iLabel, -2), p.x, p.y);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_points.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,110 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Shapes_Points.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Points_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Points_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_shapes_point.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes_Points : public CWKSP_Shapes_Point
+{
+public:
+	CWKSP_Shapes_Points(CSG_Shapes *pShapes);
+	virtual ~CWKSP_Shapes_Points(void);
+
+
+protected:
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual void				_Draw_Shape				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection);
+	virtual void				_Draw_Label				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Points_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,493 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Shapes_Polygon.cpp                //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "helper.h"
+#include "dc_helper.h"
+
+#include "wksp_layer_classify.h"
+
+#include "wksp_shapes_polygon.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Polygon::CWKSP_Shapes_Polygon(CSG_Shapes *pShapes)
+	: CWKSP_Shapes(pShapes)
+{
+	Create_Parameters();
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Polygon::~CWKSP_Shapes_Polygon(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::On_Create_Parameters(void)
+{
+	CWKSP_Shapes::On_Create_Parameters();
+
+
+	//-----------------------------------------------------
+	// Display...
+
+	_BrushList_Add(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_BRUSH"			, LNG("[CAP] Fill Style"),
+		LNG("")
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_OUTLINE"			, LNG("[CAP] Outline"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_OUTLINE_COLOR"	, LNG("[CAP] Outline Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(0, 0, 0)
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_OUTLINE_SIZE"	, LNG("[CAP] Outline Size"),
+		LNG(""),
+		PARAMETER_TYPE_Int, 0, 0, true
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_POINTS"			, LNG("[CAP] Show Vertices"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_CENTROID"		, LNG("[CAP] Show Centroid"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_SELECTION")	, "EDIT_SEL_COLOR_FILL"		, LNG("[CAP] Fill Color"),
+		LNG(""),
+		PARAMETER_TYPE_Color, SG_GET_RGB(255, 255, 0)
+	);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::On_DataObject_Changed(void)
+{
+	CWKSP_Shapes::On_DataObject_Changed();
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::On_Parameters_Changed(void)
+{
+	CWKSP_Shapes::On_Parameters_Changed();
+
+	//-----------------------------------------------------
+	Get_Style(m_Pen, m_Brush, m_bOutline);
+
+	m_bPoints	= m_Parameters("DISPLAY_POINTS")	->asBool();
+	m_bCentroid	= m_Parameters("DISPLAY_CENTROID")	->asBool();
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_Shapes_Polygon::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	CWKSP_Shapes::On_Parameter_Changed(pParameters, pParameter);
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Polygon::Get_Style(wxPen &Pen, wxBrush &Brush, bool &bOutline, wxString *pName)
+{
+	bOutline	= m_Parameters("DISPLAY_OUTLINE")->asBool();
+	Brush		= wxBrush(m_Def_Color, _BrushList_Get_Style(m_Parameters("DISPLAY_BRUSH")->asInt()));
+	Pen			= wxPen(!bOutline ? m_Def_Color : Get_Color_asWX(m_Parameters("DISPLAY_OUTLINE_COLOR")->asColor()), m_Parameters("DISPLAY_OUTLINE_SIZE")->asInt(), wxSOLID);
+
+	if( pName )
+	{
+		if(	m_iColor < 0 || m_pClassify->Get_Mode() == CLASSIFY_UNIQUE )
+		{
+			pName->Clear();
+		}
+		else
+		{
+			pName->Printf(m_pShapes->Get_Field_Name(m_iColor));
+		}
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Draw_Initialize(CWKSP_Map_DC &dc_Map)
+{
+	dc_Map.dc.SetBrush(m_Brush);
+	dc_Map.dc.SetPen(m_Pen);
+
+	m_Sel_Color_Fill	= Get_Color_asWX(m_Parameters("EDIT_SEL_COLOR_FILL")->asInt());
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Draw_Shape(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection)
+{
+	//-----------------------------------------------------
+	if( bSelection )
+	{
+		dc_Map.dc.SetBrush(wxBrush(m_Sel_Color_Fill, wxSOLID));
+		dc_Map.dc.SetPen(wxPen(m_Sel_Color, 0, wxSOLID));
+
+		dc_Map.Draw_Polygon((CSG_Shape_Polygon *)pShape);
+
+		dc_Map.dc.SetBrush(m_Brush);
+		dc_Map.dc.SetPen(m_Pen);
+	}
+	else if( m_iColor >= 0 )
+	{
+		int		Color	= m_pClassify->Get_Class_Color_byValue(pShape->asDouble(m_iColor));
+
+		m_Brush.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
+		dc_Map.dc.SetBrush(m_Brush);
+
+		if( !m_bOutline )
+		{
+			m_Pen.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
+			dc_Map.dc.SetPen(m_Pen);
+		}
+
+		dc_Map.Draw_Polygon((CSG_Shape_Polygon *)pShape);
+	}
+
+	if( m_bCentroid )
+	{
+		TSG_Point	Point	= ((CSG_Shape_Polygon *)pShape)->Get_Centroid();
+
+		dc_Map.dc.DrawCircle((int)dc_Map.xWorld2DC(Point.x), (int)dc_Map.yWorld2DC(Point.y), 2);
+	}
+
+	if( m_bPoints )
+	{
+		_Draw_Polygon_Points(dc_Map, (CSG_Shape_Polygon *)pShape);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Draw_Label(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)
+{
+	int			iPart;
+	TSG_Point	p;
+
+	if( 0 )
+	{
+//		p	= dc_Map.World2DC(((CSG_Shape_Polygon *)pShape)->Get_Centroid());
+		p	= ((CSG_Shape_Polygon *)pShape)->Get_Centroid();
+		p.x	= dc_Map.xWorld2DC(p.x);
+		p.y	= dc_Map.yWorld2DC(p.y);
+
+		Draw_Text(dc_Map.dc, TEXTALIGN_CENTER, (int)p.x, (int)p.y, pShape->asString(m_iLabel, -2));
+	}
+	else
+	{
+		for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+		{
+			if( !((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
+			{
+				p	= ((CSG_Shape_Polygon *)pShape)->Get_Centroid(iPart);
+				p.x	= dc_Map.xWorld2DC(p.x);
+				p.y	= dc_Map.yWorld2DC(p.y);
+
+				Draw_Text(dc_Map.dc, TEXTALIGN_CENTER, (int)p.x, (int)p.y, pShape->asString(m_iLabel, -2));
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define DRAW_MOVELINE(i)	{	ptWorld	= m_Edit_pShape->Get_Point(i, m_Edit_iPart);\
+								dc.DrawLine(Point.x, Point.y,\
+									(int)((ptWorld.x - rWorld.Get_XMin()) / ClientToWorld),\
+									(int)((rWorld.Get_YMax() - ptWorld.y) / ClientToWorld));	}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Edit_Shape_Draw_Move(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point)
+{
+	int			nPoints;
+	TSG_Point	ptWorld;
+
+	if( m_Edit_pShape && m_Edit_iPart >= 0 )
+	{
+		nPoints	= m_Edit_pShape->Get_Point_Count(m_Edit_iPart);
+
+		if( m_Edit_iPoint < 0 )
+		{
+			if( nPoints > 0 )
+			{
+				DRAW_MOVELINE(0);
+
+				if( nPoints > 1 )
+					DRAW_MOVELINE(nPoints - 1);
+			}
+		}
+		else
+		{
+			if( nPoints > 1 )
+			{
+				DRAW_MOVELINE(m_Edit_iPoint > 0 ? m_Edit_iPoint - 1 : nPoints - 1);
+
+				if( nPoints > 2 )
+					DRAW_MOVELINE(m_Edit_iPoint >= nPoints - 1 ? 0 : m_Edit_iPoint + 1);
+			}
+
+			CWKSP_Shapes::_Edit_Shape_Draw_Move(dc, rWorld, ClientToWorld, Point);
+		}
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Edit_Shape_Draw(CWKSP_Map_DC &dc_Map)
+{
+	int			iPart, iPoint;
+	TSG_Point_Int	ptA, ptB;
+
+	if( m_Edit_pShape )
+	{
+		dc_Map.dc.SetPen(wxPen(m_Edit_Color));
+
+		for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
+		{
+			if( m_Edit_pShape->Get_Point_Count(iPart) > 2 )
+			{
+				ptA		= dc_Map.World2DC(m_Edit_pShape->Get_Point(m_Edit_pShape->Get_Point_Count(iPart) - 1, iPart));
+
+				for(iPoint=0; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
+				{
+					ptB		= ptA;
+					ptA		= dc_Map.World2DC(m_Edit_pShape->Get_Point(iPoint, iPart));
+
+					dc_Map.dc.DrawLine(ptA.x, ptA.y, ptB.x, ptB.y);
+				}
+			}
+			else if( m_Edit_pShape->Get_Point_Count(iPart) == 2 )
+			{
+				ptA		= dc_Map.World2DC(m_Edit_pShape->Get_Point(0, iPart));
+				ptB		= dc_Map.World2DC(m_Edit_pShape->Get_Point(1, iPart));
+
+				dc_Map.dc.DrawLine(ptA.x, ptA.y, ptB.x, ptB.y);
+			}
+		}
+
+		CWKSP_Shapes::_Edit_Shape_Draw(dc_Map);
+	}
+}
+
+//---------------------------------------------------------
+int CWKSP_Shapes_Polygon::_Edit_Shape_HitTest(CSG_Point pos_Point, double max_Dist, int &pos_iPart, int &pos_iPoint)
+{
+	int			Result, iPart, iPoint;
+	double		d;
+	TSG_Point	A, B, Point, hit_Point;
+
+	Result	= CWKSP_Shapes::_Edit_Shape_HitTest(pos_Point, max_Dist, pos_iPart, pos_iPoint);
+
+	if( Result == 0 && m_Edit_pShape )
+	{
+		for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
+		{
+			B	= m_Edit_pShape->Get_Point(m_Edit_pShape->Get_Point_Count(iPart) - 1, iPart);
+
+			for(iPoint=0; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
+			{
+				A	= m_Edit_pShape->Get_Point(iPoint, iPart);
+				d	= SG_Get_Nearest_Point_On_Line(pos_Point, A, B, Point, true);
+				B	= A;
+
+				if( d >= 0.0 && (0.0 > max_Dist || d < max_Dist) )
+				{
+					Result		= 2;
+					max_Dist	= d;
+					pos_iPoint	= iPoint;
+					pos_iPart	= iPart;
+					hit_Point	= Point;
+				}
+			}
+		}
+
+		if( Result )
+		{
+			pos_Point	= hit_Point;
+		}
+	}
+
+	return( Result );
+}
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Edit_Snap_Point_ToLine(CSG_Point pos_Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape)
+{
+	int			iPart, iPoint;
+	double		d;
+	TSG_Point	A, B, Point;
+
+	for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
+	{
+		B	= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);
+
+		for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
+		{
+			A	= pShape->Get_Point(iPoint, iPart);
+			d	= SG_Get_Nearest_Point_On_Line(pos_Point, A, B, Point, true);
+			B	= A;
+
+			if( d >= 0.0 && d < snap_Dist )
+			{
+				snap_Dist	= d;
+				snap_Point	= Point;
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Shapes_Polygon::_Draw_Polygon_Points(CWKSP_Map_DC &dc_Map, CSG_Shape_Polygon *pPolygon)
+{
+	int			iPart, iPoint;
+	TSG_Point	Point;
+
+	dc_Map.dc.SetPen(*wxBLACK_PEN);
+	dc_Map.dc.SetBrush(*wxWHITE_BRUSH);
+
+	for(iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
+	{
+		if( pPolygon->Get_Point_Count(iPart) > 2 )
+		{
+			for(iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++)
+			{
+				Point	= pPolygon->Get_Point(iPoint, iPart);
+
+				dc_Map.dc.DrawCircle((int)dc_Map.xWorld2DC(Point.x), (int)dc_Map.yWorld2DC(Point.y), 2);
+			}
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_polygon.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,129 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Shapes_Polygon.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Polygon_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Polygon_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_shapes.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes_Polygon : public CWKSP_Shapes
+{
+public:
+	CWKSP_Shapes_Polygon(CSG_Shapes *pShapes);
+	virtual ~CWKSP_Shapes_Polygon(void);
+
+	bool						Get_Style				(wxPen &Pen, wxBrush &Brush, bool &bOutline, wxString *pName = NULL);
+
+
+protected:
+
+	bool						m_bPoints, m_bCentroid, m_bOutline;
+
+	wxColour					m_Sel_Color_Fill;
+
+	wxPen						m_Pen;
+
+	wxBrush						m_Brush;
+
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual void				_Draw_Initialize		(CWKSP_Map_DC &dc_Map);
+	virtual void				_Draw_Shape				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape, bool bSelection);
+	virtual void				_Draw_Label				(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape);
+
+	void						_Draw_Polygon_Points	(CWKSP_Map_DC &dc_Map, CSG_Shape_Polygon *pPolygon);
+
+	virtual void				_Edit_Shape_Draw_Move	(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point);
+	virtual void				_Edit_Shape_Draw		(CWKSP_Map_DC &dc_Map);
+	virtual int					_Edit_Shape_HitTest		(CSG_Point Point, double max_Dist, int &iPart, int &iPoint);
+	virtual void				_Edit_Snap_Point_ToLine (CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Polygon_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,223 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Shapes_Type.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_shapes_type.h"
+
+#include "wksp_shapes_point.h"
+#include "wksp_shapes_points.h"
+#include "wksp_shapes_line.h"
+#include "wksp_shapes_polygon.h"
+
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes_Type::CWKSP_Shapes_Type(int Shapes_Type)
+{
+	m_Shapes_Type	= Shapes_Type;
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes_Type::~CWKSP_Shapes_Type(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes_Type::Get_Name(void)
+{
+	return( SG_Get_ShapeType_Name((TSG_Shape_Type)m_Shapes_Type) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Shapes_Type::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s:</b>%d<br>"), Get_Name().c_str(), Get_Count());
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Shapes_Type::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Type::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Shapes * CWKSP_Shapes_Type::Get_Shapes(CSG_Shapes *pShapes)
+{
+	if( pShapes )
+	{
+		for(int i=0; i<Get_Count(); i++)
+		{
+			if( pShapes == Get_Shapes(i)->Get_Shapes() )
+			{
+				return( Get_Shapes(i) );
+			}
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Shapes_Type::Exists(CSG_Shapes *pShapes)
+{
+	return( Get_Shapes(pShapes) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Shapes * CWKSP_Shapes_Type::Add(CSG_Shapes *pShapes)
+{
+	CWKSP_Shapes	*pItem;
+
+	if( pShapes && pShapes->Get_Type() == m_Shapes_Type && !Exists(pShapes) )
+	{
+		switch( pShapes->Get_Type() )
+		{
+		default:
+			return( false );
+
+		case SHAPE_TYPE_Point:
+			pItem	= new CWKSP_Shapes_Point	(pShapes);
+			break;
+
+		case SHAPE_TYPE_Points:
+			pItem	= new CWKSP_Shapes_Points	(pShapes);
+			break;
+
+		case SHAPE_TYPE_Line:
+			pItem	= new CWKSP_Shapes_Line		(pShapes);
+			break;
+
+		case SHAPE_TYPE_Polygon:
+			pItem	= new CWKSP_Shapes_Polygon	(pShapes);
+			break;
+		}
+
+		if( Add_Item(pItem) )
+		{
+			return( pItem );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_shapes_type.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,120 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_Shapes_Type.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Type_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Type_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Shapes_Type : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Shapes_Type(int Shapes_Type);
+	virtual ~CWKSP_Shapes_Type(void);
+
+	virtual TWKSP_Item			Get_Type		(void)		{	return( WKSP_ITEM_Shapes_Type );	}
+
+	virtual wxString			Get_Name		(void);
+	virtual wxString			Get_Description	(void);
+
+	virtual wxMenu *			Get_Menu		(void);
+
+	virtual bool				On_Command		(int Cmd_ID);
+
+	class CWKSP_Shapes *		Get_Shapes		(int i)		{	return( (class CWKSP_Shapes *)Get_Item(i) );	}
+	class CWKSP_Shapes *		Get_Shapes		(class CSG_Shapes *pShapes);
+
+	bool						Exists			(class CSG_Shapes *pShapes);
+	class CWKSP_Shapes *		Add				(class CSG_Shapes *pShapes);
+
+	int							Get_Shapes_Type	(void)		{	return( m_Shapes_Type );	}
+
+
+private:
+
+	int							m_Shapes_Type;
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Shapes_Type_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,458 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_Table.cpp                     //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+#include "res_dialogs.h"
+
+#include "helper.h"
+
+#include "wksp_base_control.h"
+
+#include "wksp_table.h"
+
+#include "view_table.h"
+#include "view_table_diagram.h"
+#include "view_scatterplot.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Table::CWKSP_Table(CSG_Table *pTable, CWKSP_Base_Item *pOwner)
+{
+	m_pTable	= pTable;
+	m_pOwner	= pOwner;
+	m_pView		= NULL;
+	m_pDiagram	= NULL;
+
+	//-----------------------------------------------------
+	m_Parameters.Create(this, LNG(""), LNG(""));
+	m_Parameters.Set_Callback_On_Parameter_Changed(&_On_Parameter_Changed);
+
+	m_Parameters.Add_String(
+		m_Parameters("NODE_GENERAL")	, "NAME"			, LNG("[CAP] Name"),
+		LNG(""),
+		m_pTable->Get_Name()
+	);
+}
+
+//---------------------------------------------------------
+CWKSP_Table::~CWKSP_Table(void)
+{
+	Set_View	(false);
+	Set_Diagram	(false);
+
+	if( m_pOwner->Get_Type() == WKSP_ITEM_Table_Manager )
+	{
+		MSG_General_Add(wxString::Format(wxT("%s: %s..."), LNG("[MSG] Close table"), m_pTable->Get_Name() ), true, true);
+
+		delete(m_pTable);
+
+		MSG_General_Add(LNG("[MSG] okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Table::Get_Name(void)
+{
+	return( m_pTable->Get_Name() );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Table::Get_Description(void)
+{
+	wxString	s;
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<b>%s</b><table border=\"0\">"),
+		LNG("[CAP] Shapes")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, m_pTable->Get_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] File")					, m_pTable->Get_File_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Fields")					, m_pTable->Get_Field_Count()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Records")				, m_pTable->Get_Record_Count()
+	));
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<hr><b>%s</b>"), LNG("[CAP] Table Description")));
+	s.Append(Get_TableInfo_asHTML(m_pTable));
+
+	//-----------------------------------------------------
+//	s.Append(wxString::Format(wxT("<hr><b>%s</b><font size=\"-1\">"), LNG("[CAP] Data History")));
+//	s.Append(m_pTable->Get_History().Get_HTML());
+//	s.Append(wxString::Format(wxT("</font")));
+
+	//-----------------------------------------------------
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Table::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(m_pTable->Get_Name());
+
+	switch( m_pOwner->Get_Type() )
+	{
+	default:
+	case WKSP_ITEM_Table_Manager:
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLES_SAVE);
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLES_SAVEAS);
+		break;
+
+	case WKSP_ITEM_Shapes:
+	case WKSP_ITEM_TIN:
+		break;
+	}
+
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_TABLES_SHOW);
+	CMD_Menu_Add_Item(pMenu,  true, ID_CMD_TABLES_DIAGRAM);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLES_SCATTERPLOT);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Table::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command(Cmd_ID) );
+
+	case ID_CMD_TABLES_SAVE:
+		Save(m_pTable->Get_File_Name());
+		break;
+
+	case ID_CMD_TABLES_SAVEAS:
+		Save();
+		break;
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		Set_View(true);
+		break;
+
+	case ID_CMD_TABLES_SHOW:
+		Toggle_View();
+		break;
+
+	case ID_CMD_TABLES_DIAGRAM:
+		Toggle_Diagram();
+		break;
+
+	case ID_CMD_TABLES_SCATTERPLOT:
+		Add_ScatterPlot(Get_Table());
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Table::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command_UI(event) );
+
+	case ID_CMD_TABLES_SAVE:
+		event.Enable(m_pTable->is_Modified() && m_pTable->Get_File_Name() && *(m_pTable->Get_File_Name()));
+		break;
+
+	case ID_CMD_TABLES_SHOW:
+		event.Check(m_pView != NULL);
+		break;
+
+	case ID_CMD_TABLES_DIAGRAM:
+		event.Check(m_pDiagram != NULL);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Table::Parameters_Changed(void)
+{
+	m_pTable->Set_Name(m_Parameters("NAME")->asString());
+
+	Update_Views();
+
+	CWKSP_Base_Item::Parameters_Changed();
+}
+
+//---------------------------------------------------------
+int CWKSP_Table::_On_Parameter_Changed(CSG_Parameter *pParameter)
+{
+	if( pParameter && pParameter->Get_Owner() && pParameter->Get_Owner()->Get_Owner() )
+	{
+		return( ((CWKSP_Table *)pParameter->Get_Owner()->Get_Owner())->
+			On_Parameter_Changed(pParameter->Get_Owner(), pParameter)
+		);
+	}
+
+	return( 0 );
+}
+
+//---------------------------------------------------------
+int CWKSP_Table::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Table::Save(void)
+{
+	bool		bResult	= false;
+	wxString	File_Path;
+
+	if( DLG_Save(File_Path, ID_DLG_TABLES_SAVE) )
+	{
+		bResult	= m_pTable->Save(File_Path.c_str());
+
+		PROCESS_Set_Okay();
+	}
+
+	return( bResult );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Table::Save(const wxChar *File_Path)
+{
+	bool	bResult;
+
+	if( File_Path && *File_Path )
+	{
+		bResult	= m_pTable->Save(File_Path);
+
+		PROCESS_Set_Okay();
+
+		return( bResult );
+	}
+
+	return( Save() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Table::DataObject_Changed(CSG_Parameters *pParameters)
+{
+	m_Parameters.Set_Name(wxString::Format(wxT("%02d. %s"), 1 + Get_ID(), m_pTable->Get_Name()));
+
+	m_Parameters("NAME")->Set_Value(m_pTable->Get_Name());
+
+	//-----------------------------------------------------
+//	g_pACTIVE->Update(this, false);
+
+	Parameters_Changed();
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Table::Set_View(bool bShow)
+{
+	if( bShow && !m_pView )
+	{
+		m_pView	= new CVIEW_Table(this);
+	}
+	else if( !bShow && m_pView )
+	{
+		m_pView->Destroy();
+		delete(m_pView);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Table::Toggle_View(void)
+{
+	Set_View( m_pView == NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Table::Set_Diagram(bool bShow)
+{
+	if( bShow && !m_pDiagram )
+	{
+		m_pDiagram	= new CVIEW_Table_Diagram(this);
+	}
+	else if( !bShow && m_pDiagram )
+	{
+		m_pDiagram->Destroy();
+		delete(m_pDiagram);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Table::Toggle_Diagram(void)
+{
+	Set_Diagram( m_pDiagram == NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_Table::Update_Views(void)
+{
+	if( m_pView )
+	{
+		m_pView->Update_Table();
+	}
+
+	if( m_pDiagram )
+	{
+		m_pDiagram->Update_Diagram();
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_Table::View_Closes(wxMDIChildFrame *pView)
+{
+	if		( wxDynamicCast(pView, CVIEW_Table) )
+	{
+		m_pView		= NULL;
+	}
+	else if	( wxDynamicCast(pView, CVIEW_Table_Diagram) )
+	{
+		m_pDiagram	= NULL;
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,152 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WKSP_Table.h                      //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Table_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Table_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Table : public CWKSP_Base_Item
+{
+public:
+	CWKSP_Table(class CSG_Table *pTable, CWKSP_Base_Item *pOwner);
+	virtual ~CWKSP_Table(void);
+
+	virtual TWKSP_Item				Get_Type				(void)			{	return( WKSP_ITEM_Table );	}
+
+	virtual CSG_Parameters *		Get_Parameters			(void)			{	return( &m_Parameters );	}
+
+	virtual void					Parameters_Changed		(void);
+
+	virtual wxString				Get_Name				(void);
+	virtual wxString				Get_Description			(void);
+
+	virtual wxMenu *				Get_Menu				(void);
+
+	virtual bool					On_Command				(int Cmd_ID);
+	virtual bool					On_Command_UI			(wxUpdateUIEvent &event);
+
+	CWKSP_Base_Item *				Get_Owner				(void)			{	return( m_pOwner );	}
+
+	CSG_Table *						Get_Table				(void)			{	return( m_pTable );	}
+
+	bool							Save					(void);
+	bool							Save					(const wxChar *File_Path);
+
+	bool							DataObject_Changed		(CSG_Parameters *pParameters);
+
+	class CVIEW_Table *				Get_View				(void)			{	return( m_pView );	}
+	void							Set_View				(bool bShow);
+	void							Toggle_View				(void);
+
+	class CVIEW_Table_Diagram *		Get_Diagram				(void)			{	return( m_pDiagram );	}
+	void							Set_Diagram				(bool bShow);
+	void							Toggle_Diagram			(void);
+
+	void							Update_Views			(void);
+	void							View_Closes				(class wxMDIChildFrame *pView);
+
+
+private:
+
+	CSG_Parameters					m_Parameters;
+
+	CSG_Table						*m_pTable;
+
+	CWKSP_Base_Item					*m_pOwner;
+
+	class CVIEW_Table				*m_pView;
+
+	class CVIEW_Table_Diagram		*m_pDiagram;
+
+
+	static int						_On_Parameter_Changed	(CSG_Parameter *pParameter);
+
+	int								On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Table_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,260 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                WKSP_Table_Manager.cpp                 //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_table_manager.h"
+#include "wksp_table.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Table_Manager::CWKSP_Table_Manager(void)
+{
+}
+
+//---------------------------------------------------------
+CWKSP_Table_Manager::~CWKSP_Table_Manager(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_Table_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] Tables") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_Table_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b>: %d<br>"), LNG("[CAP] Tables"), Get_Count());
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_Table_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] Tables"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLES_OPEN);
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Table_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Item::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_Table * CWKSP_Table_Manager::Get_Table(CSG_Table *pTable)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( pTable == Get_Table(i)->Get_Table() )
+		{
+			return( Get_Table(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Table_Manager::Exists(CSG_Table *pTable)
+{
+	return( Get_Table(pTable) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_Table * CWKSP_Table_Manager::Add(CSG_Table *pTable)
+{
+	CWKSP_Table	*pItem;
+
+	if( pTable && !Exists(pTable) && Add_Item(pItem = new CWKSP_Table(pTable, this)) )
+	{
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_Table * CWKSP_Table_Manager::Get_byFileName(const wxChar *File_Name)
+{
+	CSG_String	s(File_Name);
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( !s.Cmp(Get_Table(i)->Get_Table()->Get_File_Name()) )
+		{
+			return( Get_Table(i)->Get_Table() );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_Table_Manager::Update(CSG_Table *pTable, CSG_Parameters *pParameters)
+{
+	CWKSP_Table	*pItem;
+
+	if( (pItem = Get_Table(pTable)) != NULL )
+	{
+		return( pItem->DataObject_Changed(pParameters) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Table_Manager::Update_Views(CSG_Table *pTable)
+{
+	CWKSP_Table	*pItem;
+
+	if( (pItem = Get_Table(pTable)) != NULL )
+	{
+		pItem->Update_Views();
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_Table_Manager::Show(CSG_Table *pTable)
+{
+	CWKSP_Table	*pItem;
+
+	if( (pItem = Get_Table(pTable)) != NULL )
+	{
+		pItem->Set_View(true);
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_table_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,121 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_Table_Manager.h                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Table_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_Table_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_Table_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_Table_Manager(void);
+	virtual ~CWKSP_Table_Manager(void);
+
+	virtual TWKSP_Item			Get_Type		(void)		{	return( WKSP_ITEM_Table_Manager );	}
+
+	virtual wxString			Get_Name		(void);
+	virtual wxString			Get_Description	(void);
+
+	virtual wxMenu *			Get_Menu		(void);
+
+	virtual bool				On_Command		(int Cmd_ID);
+
+	class CWKSP_Table *			Get_Table		(int i)		{	return( (class CWKSP_Table *)Get_Item(i) );	}
+	class CWKSP_Table *			Get_Table		(class CSG_Table *pTable);
+
+	bool						Exists			(class CSG_Table *pTable);
+	class CWKSP_Table *			Add				(class CSG_Table *pTable);
+	class CSG_Table *				Get_byFileName	(const wxChar *File_Name);
+
+	bool						Update			(class CSG_Table *pTable, class CSG_Parameters *pParameters);
+	bool						Update_Views	(class CSG_Table *pTable);
+	bool						Show			(class CSG_Table *pTable);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_Table_Manager_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,629 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                    WKSP_TIN.cpp                       //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "res_commands.h"
+
+#include "helper.h"
+
+#include "wksp_map_control.h"
+
+#include "wksp_layer_classify.h"
+
+#include "wksp_tin.h"
+#include "wksp_table.h"
+
+#include "view_scatterplot.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_TIN::CWKSP_TIN(CSG_TIN *pTIN)
+	: CWKSP_Layer(pTIN)
+{
+	m_pTIN		= pTIN;
+	m_pTable	= new CWKSP_Table(m_pTIN, this);
+
+	m_Edit_Attributes.Destroy();
+	m_Edit_Attributes.Add_Field(LNG("[CAP] Name") , SG_DATATYPE_String);
+	m_Edit_Attributes.Add_Field(LNG("[CAP] Value"), SG_DATATYPE_String);
+
+	Create_Parameters();
+}
+
+//---------------------------------------------------------
+CWKSP_TIN::~CWKSP_TIN(void)
+{
+	delete(m_pTable);
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_TIN::Get_Name(void)
+{
+	return( wxString::Format(wxT("%02d. %s"), 1 + Get_ID(), m_pTIN->Get_Name()) );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_TIN::Get_Description(void)
+{
+	wxString	s;
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<b>%s</b><table border=\"0\">"),
+		LNG("[CAP] TIN")
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] Name")					, m_pTIN->Get_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%s</td></tr>"),
+		LNG("[CAP] File")					, m_pTIN->Get_File_Name()
+	));
+
+	s.Append(wxString::Format(wxT("<tr><td>%s</td><td>%d</td></tr>"),
+		LNG("[CAP] Points")					, m_pTIN->Get_Node_Count()
+	));
+
+	s.Append(wxT("</table>"));
+
+	//-----------------------------------------------------
+	s.Append(wxString::Format(wxT("<hr><b>%s</b>"), LNG("[CAP] Table Description")));
+	s.Append(Get_TableInfo_asHTML(m_pTIN));
+
+	//-----------------------------------------------------
+//	s.Append(wxString::Format(wxT("<hr><b>%s</b><font size=\"-1\">"), LNG("[CAP] Data History")));
+//	s.Append(m_pTIN->Get_History().Get_HTML());
+//	s.Append(wxString::Format(wxT("</font")));
+
+	//-----------------------------------------------------
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_TIN::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(m_pTIN->Get_Name());
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TIN_SHOW);
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_SETTINGS_COPY);
+
+	pMenu->AppendSeparator();
+
+	wxMenu	*pTable	= new wxMenu(LNG("[MNU] Table"));
+	CMD_Menu_Add_Item(pTable,  true, ID_CMD_TABLES_SHOW);
+	CMD_Menu_Add_Item(pTable,  true, ID_CMD_TABLES_DIAGRAM);
+	CMD_Menu_Add_Item(pTable, false, ID_CMD_TABLES_SCATTERPLOT);
+	pMenu->Append(ID_CMD_WKSP_FIRST, LNG("[MNU] Attributes"), pTable);
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_TIN::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Layer::On_Command(Cmd_ID) );
+
+	case ID_CMD_TABLES_SHOW:
+		m_pTable->Toggle_View();
+		break;
+
+	case ID_CMD_TABLES_DIAGRAM:
+		m_pTable->Toggle_Diagram();
+		break;
+
+	case ID_CMD_TABLES_SCATTERPLOT:
+		Add_ScatterPlot(Get_Table()->Get_Table());
+		break;
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN::On_Command_UI(wxUpdateUIEvent &event)
+{
+	switch( event.GetId() )
+	{
+	default:
+		return( CWKSP_Layer::On_Command_UI(event) );
+
+	case ID_CMD_TABLES_SHOW:
+		event.Check(m_pTable->Get_View() != NULL);
+		break;
+
+	case ID_CMD_TABLES_DIAGRAM:
+		event.Check(m_pTable->Get_Diagram() != NULL);
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_TIN::On_Create_Parameters(void)
+{
+	//-----------------------------------------------------
+	// General...
+
+	m_Parameters.Add_Choice(
+		m_Parameters("NODE_METRIC")		, "COLORS_ATTRIB"			, LNG("[CAP] Attribute"),
+		LNG(""),
+		LNG("")
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_POINTS"			, LNG("[CAP] Show Nodes"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, false
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_EDGES"			, LNG("[CAP] Show Edges"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_TRIANGES"		, LNG("[CAP] Show Filled"),
+		LNG(""),
+		PARAMETER_TYPE_Bool, true
+	);
+
+	//-----------------------------------------------------
+	m_Parameters.Add_Value(
+		m_Parameters("NODE_DISPLAY")	, "DISPLAY_TRANSPARENCY"	, LNG("[CAP] Transparency [%]"),
+		LNG(""),
+		PARAMETER_TYPE_Double, 0.0, 0.0, true, 100.0, true
+	);
+
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_TIN::On_DataObject_Changed(void)
+{
+	int			i;
+	wxString	sChoices;
+
+	for(i=0; i<m_pTIN->Get_Field_Count(); i++)
+	{
+		sChoices.Append(wxString::Format(wxT("%s|"), m_pTIN->Get_Field_Name(i)));
+	}
+
+	m_Parameters("COLORS_ATTRIB")->asChoice()->Set_Items(sChoices);
+}
+
+//---------------------------------------------------------
+void CWKSP_TIN::On_Parameters_Changed(void)
+{
+	if( (m_Color_Field = m_Parameters("COLORS_ATTRIB")->asInt()) >= m_pTIN->Get_Field_Count() )
+	{
+		m_Color_Field	= -1;
+	}
+
+	long	DefColor	= m_Parameters("UNISYMBOL_COLOR")->asColor();
+	m_Color_Pen		= wxColour(SG_GET_R(DefColor), SG_GET_G(DefColor), SG_GET_B(DefColor));
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+int CWKSP_TIN::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
+{
+	if(	!SG_STR_CMP(pParameter->Get_Identifier(), wxT("COLORS_ATTRIB")) )
+	{
+		int		zField	= pParameter->asInt();
+
+		pParameters->Get_Parameter("METRIC_ZRANGE")->asRange()->Set_Range(
+			m_pTIN->Get_Minimum(zField),
+			m_pTIN->Get_Maximum(zField)
+		);
+	}
+
+	return( 1 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_TIN::Get_Value(CSG_Point ptWorld, double Epsilon)
+{
+	return( LNG("") );
+}
+
+//---------------------------------------------------------
+double CWKSP_TIN::Get_Value_Range(void)
+{
+	return( m_Color_Field >= 0 ? m_pTIN->Get_Range(m_Color_Field) : 0.0 );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_TIN::asImage(CSG_Grid *pImage)
+{
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_TIN::On_Edit_On_Mouse_Up(CSG_Point Point, double ClientToWorld, int Key)
+{
+	CSG_Rect	rWorld(m_Edit_Mouse_Down, Point);
+
+	if( rWorld.Get_XRange() == 0.0 && rWorld.Get_YRange() == 0.0 )
+	{
+		rWorld.Inflate(2.0 * ClientToWorld, false);
+	}
+
+	return( true );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN::On_Edit_Set_Attributes(void)
+{
+	return( true );
+}
+
+//---------------------------------------------------------
+TSG_Rect CWKSP_TIN::On_Edit_Get_Extent(void)
+{
+	return( m_pTIN->Get_Extent() );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_TIN::On_Draw(CWKSP_Map_DC &dc_Map, bool bEdit)
+{
+	if( Get_Extent().Intersects(dc_Map.m_rWorld) != INTERSECTION_None )
+	{
+		if( m_Color_Field >= 0 )
+		{
+			_Draw_Triangles	(dc_Map);
+		}
+
+		if( m_Parameters("DISPLAY_EDGES")	->asBool() )
+		{
+			_Draw_Edges		(dc_Map);
+		}
+
+		if( m_Parameters("DISPLAY_POINTS")	->asBool() )
+		{
+			_Draw_Points	(dc_Map);
+		}
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+void CWKSP_TIN::_Draw_Points(CWKSP_Map_DC &dc_Map)
+{
+	for(int i=0; i<m_pTIN->Get_Node_Count(); i++)
+	{
+		TSG_Point_Int	Point	= dc_Map.World2DC(m_pTIN->Get_Node(i)->Get_Point());
+
+		dc_Map.dc.DrawCircle(Point.x, Point.y, 5);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_TIN::_Draw_Edges(CWKSP_Map_DC &dc_Map)
+{
+	for(int i=0; i<m_pTIN->Get_Edge_Count(); i++)
+	{
+		TSG_Point_Int	Point[2];
+		CSG_TIN_Edge	*pEdge	= m_pTIN->Get_Edge(i);
+
+		Point[0]	= dc_Map.World2DC(pEdge->Get_Node(0)->Get_Point());
+		Point[1]	= dc_Map.World2DC(pEdge->Get_Node(1)->Get_Point());
+
+		dc_Map.dc.DrawLine(Point[0].x, Point[0].y, Point[1].x, Point[1].y);
+	}
+}
+
+//---------------------------------------------------------
+void CWKSP_TIN::_Draw_Triangles(CWKSP_Map_DC &dc_Map)
+{
+	if(	m_Parameters("DISPLAY_TRIANGES")->asBool()
+	&&	dc_Map.IMG_Draw_Begin(m_Parameters("DISPLAY_TRANSPARENCY")->asDouble() / 100.0) )
+	{
+		for(int iTriangle=0; iTriangle<m_pTIN->Get_Triangle_Count(); iTriangle++)
+		{
+			CSG_TIN_Triangle	*pTriangle	= m_pTIN->Get_Triangle(iTriangle);
+
+			if( dc_Map.m_rWorld.Intersects(pTriangle->Get_Extent()) != INTERSECTION_None )
+			{
+				TPoint	p[3];
+
+				for(int iNode=0; iNode<3; iNode++)
+				{
+					CSG_TIN_Node	*pNode	= pTriangle->Get_Node(iNode);
+					TSG_Point_Int	Point	= dc_Map.World2DC(pNode->Get_Point());
+
+					p[iNode].x	= Point.x;
+					p[iNode].y	= Point.y;
+					p[iNode].z	= pNode->asDouble(m_Color_Field);
+				}
+
+				_Draw_Triangle(dc_Map, p);
+			}
+		}
+
+		dc_Map.IMG_Draw_End();
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#define SORT_POINTS_Y(a, b)	if( p[a].y < p[b].y ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+#define SORT_POINTS_X(a, b)	if( p[a].x < p[b].x ) {	pp = p[a]; p[a] = p[b]; p[b] = pp;	}
+
+#define DRAW_PIXEL(x, y, z)	if( m_pClassify->Get_Class_Color_byValue(z, Color) )	{	dc_Map.IMG_Set_Pixel(x, y, Color);	}
+
+//---------------------------------------------------------
+void CWKSP_TIN::_Draw_Triangle(CWKSP_Map_DC &dc_Map, TPoint p[3])
+{
+	int		i, j, y, y_j, Color;
+	double	x, x_a, dx, dx_a, dy, z, z_a, dz, dz_a;
+	TPoint	pp;
+
+	//-----------------------------------------------------
+	SORT_POINTS_Y(1, 0);
+	SORT_POINTS_Y(2, 0);
+	SORT_POINTS_Y(2, 1);
+
+	//-----------------------------------------------------
+	if( p[2].y == p[0].y )
+	{
+		if( p[0].y >= 0 && p[0].y < dc_Map.m_rDC.GetHeight() )
+		{
+			SORT_POINTS_X(1, 0);
+			SORT_POINTS_X(2, 0);
+			SORT_POINTS_X(2, 1);
+
+			//---------------------------------------------
+			if( p[2].x == p[0].x )
+			{
+				if(	p[0].x >= 0 && p[0].x < dc_Map.m_rDC.GetWidth() )
+				{
+					DRAW_PIXEL(p[0].x, p[0].y, p[0].z > p[1].z
+						? (p[0].z > p[2].z ? p[0].z : p[2].z)
+						: (p[1].z > p[2].z ? p[1].z : p[2].z)
+					);
+				}
+			}
+
+			//---------------------------------------------
+			else
+			{
+				_Draw_Triangle_Line(dc_Map, p[0].x, p[1].x, p[0].y, p[0].z, p[1].z);
+				_Draw_Triangle_Line(dc_Map, p[1].x, p[2].x, p[0].y, p[1].z, p[2].z);
+			}
+		}
+	}
+
+	//-----------------------------------------------------
+	else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= dc_Map.m_rDC.GetHeight() && p[2].y >= dc_Map.m_rDC.GetHeight())) )
+	{
+		dy		=  p[2].y - p[0].y;
+		dx_a	= (p[2].x - p[0].x) / dy;
+		dz_a	= (p[2].z - p[0].z) / dy;
+		x_a		=  p[0].x;
+		z_a		=  p[0].z;
+
+		for(i=0, j=1; i<2; i++, j++)
+		{
+			if( (dy	=  p[j].y - p[i].y) > 0.0 )
+			{
+				dx		= (p[j].x - p[i].x) / dy;
+				dz		= (p[j].z - p[i].z) / dy;
+				x		=  p[i].x;
+				z		=  p[i].z;
+
+				if( (y = p[i].y) < 0 )
+				{
+					x		-= y * dx;
+					z		-= y * dz;
+					y		 = 0;
+					x_a		 = p[0].x - p[0].y * dx_a;
+					z_a		 = p[0].z - p[0].y * dz_a;
+				}
+
+				if( (y_j = p[j].y) > dc_Map.m_rDC.GetHeight() )
+				{
+					y_j		= dc_Map.m_rDC.GetHeight();
+				}
+
+				for( ; y<y_j; y++, x+=dx, z+=dz, x_a+=dx_a, z_a+=dz_a)
+				{
+					if( x < x_a )
+					{
+						_Draw_Triangle_Line(dc_Map, (int)x, (int)x_a, y, z, z_a);
+					}
+					else
+					{
+						_Draw_Triangle_Line(dc_Map, (int)x_a, (int)x, y, z_a, z);
+					}
+				}
+			}
+		}
+	}
+}
+
+//---------------------------------------------------------
+inline void CWKSP_TIN::_Draw_Triangle_Line(CWKSP_Map_DC &dc_Map, int xa, int xb, int y, double za, double zb)
+{
+	int		Color;
+	double	dz;
+
+	if( (dz = xb - xa) > 0.0 )
+	{
+		dz	= (zb - za) / dz;
+
+		if( xa < 0 )
+		{
+			za	-= dz * xa;
+			xa	 = 0;
+		}
+
+		if( xb >= dc_Map.m_rDC.GetWidth() )
+		{
+			xb	= dc_Map.m_rDC.GetWidth() - 1;
+		}
+
+		for(int x=xa; x<=xb; x++, za+=dz)
+		{
+			DRAW_PIXEL(x, y, za);
+		}
+	}
+	else if( xa >= 0 && xa < dc_Map.m_rDC.GetWidth() )
+	{
+		DRAW_PIXEL(xa, y, za);
+	}
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,156 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                     WKSP_TIN.h                        //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_TIN_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_TIN_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_layer.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_TIN : public CWKSP_Layer
+{
+public:
+	CWKSP_TIN(CSG_TIN *pTIN);
+	virtual ~CWKSP_TIN(void);
+
+	virtual TWKSP_Item			Get_Type				(void)	{	return( WKSP_ITEM_TIN );	}
+
+	virtual wxString			Get_Name				(void);
+	virtual wxString			Get_Description			(void);
+
+	virtual wxMenu *			Get_Menu				(void);
+
+	virtual bool				On_Command				(int Cmd_ID);
+	virtual bool				On_Command_UI			(wxUpdateUIEvent &event);
+
+	CSG_TIN *					Get_TIN					(void)	{	return( m_pTIN );	}
+	class CWKSP_Table *			Get_Table				(void)	{	return( m_pTable );	}
+
+	virtual wxString			Get_Value				(CSG_Point ptWorld, double Epsilon);
+	virtual double				Get_Value_Range			(void);
+
+	bool						asImage					(CSG_Grid *pImage);
+
+
+protected:
+
+	typedef struct
+	{
+		int		x, y;
+
+		double	z;
+	}
+	TPoint;
+
+
+protected:
+
+	int							m_Color_Field, m_Brush_Style;
+
+	wxColour					m_Color_Pen, m_Color_Brush;
+
+	CSG_TIN						*m_pTIN;
+
+	class CWKSP_Table			*m_pTable;
+
+
+	virtual void				On_Create_Parameters	(void);
+	virtual void				On_DataObject_Changed	(void);
+	virtual void				On_Parameters_Changed	(void);
+	virtual int					On_Parameter_Changed	(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
+
+	virtual bool				On_Edit_On_Mouse_Up		(CSG_Point Point, double ClientToWorld, int Key);
+	virtual bool				On_Edit_Set_Attributes	(void);
+	virtual TSG_Rect			On_Edit_Get_Extent		(void);
+
+	virtual void				On_Draw					(CWKSP_Map_DC &dc_Map, bool bEdit);
+
+	void						_Draw_Points			(CWKSP_Map_DC &dc_Map);
+	void						_Draw_Edges				(CWKSP_Map_DC &dc_Map);
+	void						_Draw_Triangles			(CWKSP_Map_DC &dc_Map);
+	void						_Draw_Triangle			(CWKSP_Map_DC &dc_Map, TPoint p[3]);
+	void						_Draw_Triangle_Line		(CWKSP_Map_DC &dc_Map, int xa, int xb, int y, double za, double zb);
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_TIN_H

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.cpp
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.cpp	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.cpp	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,322 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                 WKSP_TIN_Manager.cpp                  //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include <saga_api/saga_api.h>
+
+#include "res_commands.h"
+
+#include "wksp_data_manager.h"
+
+#include "wksp_map_manager.h"
+
+#include "wksp_tin_manager.h"
+#include "wksp_tin.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_TIN_Manager::CWKSP_TIN_Manager(void)
+{
+}
+
+//---------------------------------------------------------
+CWKSP_TIN_Manager::~CWKSP_TIN_Manager(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+wxString CWKSP_TIN_Manager::Get_Name(void)
+{
+	return( LNG("[CAP] TIN") );
+}
+
+//---------------------------------------------------------
+wxString CWKSP_TIN_Manager::Get_Description(void)
+{
+	wxString	s;
+
+	s.Printf(wxT("<b>%s</b>:%d<br>"), LNG("[CAP] TIN"), Get_Count());
+
+	return( s );
+}
+
+//---------------------------------------------------------
+wxMenu * CWKSP_TIN_Manager::Get_Menu(void)
+{
+	wxMenu	*pMenu;
+
+	pMenu	= new wxMenu(LNG("[CAP] TIN"));
+
+	CMD_Menu_Add_Item(pMenu, false, ID_CMD_TIN_OPEN);
+
+	if( Get_Count() > 0 )
+	{
+		CMD_Menu_Add_Item(pMenu, false, ID_CMD_WKSP_ITEM_CLOSE);
+	}
+
+	return( pMenu );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::On_Command(int Cmd_ID)
+{
+	switch( Cmd_ID )
+	{
+	default:
+		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );
+
+	case ID_CMD_WKSP_ITEM_RETURN:
+		break;
+	}
+
+	return( true );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+CWKSP_TIN * CWKSP_TIN_Manager::Get_TIN(CSG_TIN *pTIN)
+{
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( pTIN == Get_TIN(i)->Get_TIN() )
+		{
+			return( Get_TIN(i) );
+		}
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::Exists(CSG_TIN *pTIN)
+{
+	return( Get_TIN(pTIN) != NULL );
+}
+
+//---------------------------------------------------------
+CWKSP_TIN * CWKSP_TIN_Manager::Add(CSG_TIN *pTIN)
+{
+	CWKSP_TIN	*pItem;
+
+	if( pTIN && pTIN->is_Valid() && !Exists(pTIN) && Add_Item(pItem = new CWKSP_TIN(pTIN)) )
+	{
+		return( pItem );
+	}
+
+	return( NULL );
+}
+
+//---------------------------------------------------------
+CSG_TIN * CWKSP_TIN_Manager::Get_byFileName(const wxChar *File_Name)
+{
+	CSG_String	s(File_Name);
+
+	for(int i=0; i<Get_Count(); i++)
+	{
+		if( !s.Cmp(Get_TIN(i)->Get_TIN()->Get_File_Name()) )
+		{
+			return( Get_TIN(i)->Get_TIN() );
+		}
+	}
+
+	return( NULL );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::Update(CSG_TIN *pTIN, CSG_Parameters *pParameters)
+{
+	CWKSP_TIN	*pItem;
+
+	if( (pItem = Get_TIN(pTIN)) != NULL )
+	{
+		pItem->DataObject_Changed(pParameters);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::Update_Views(CSG_TIN *pTIN)
+{
+	CWKSP_TIN	*pItem;
+
+	if( (pItem = Get_TIN(pTIN)) != NULL )
+	{
+		pItem->Update_Views(false);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::Show(CSG_TIN *pTIN, int Map_Mode)
+{
+	CWKSP_TIN	*pItem;
+
+	if( (pItem = Get_TIN(pTIN)) != NULL )
+	{
+		switch( Map_Mode )
+		{
+		case SG_UI_DATAOBJECT_SHOW:
+			return( pItem->Show() );
+
+		case SG_UI_DATAOBJECT_SHOW_NEW_MAP:
+			g_pMaps->Add(pItem, NULL);
+
+		case SG_UI_DATAOBJECT_SHOW_LAST_MAP:
+			return( pItem->Show(g_pMaps->Get_Map(g_pMaps->Get_Count() - 1)) );
+		}
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::asImage(CSG_TIN *pTIN, CSG_Grid *pImage)
+{
+	CWKSP_TIN	*pItem;
+
+	if( (pItem = Get_TIN(pTIN)) != NULL )
+	{
+		return( pItem->asImage(pImage) );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::Get_Colors(CSG_TIN *pTIN, CSG_Colors *pColors)
+{
+	CWKSP_TIN	*pItem;
+
+	if( (pItem = Get_TIN(pTIN)) != NULL )
+	{
+		return( pItem->Get_Colors(pColors) );
+	}
+
+	return( false );
+}
+
+//---------------------------------------------------------
+bool CWKSP_TIN_Manager::Set_Colors(CSG_TIN *pTIN, CSG_Colors *pColors)
+{
+	CWKSP_TIN	*pItem;
+
+	if( (pItem = Get_TIN(pTIN)) != NULL )
+	{
+		pItem->DataObject_Changed(pColors);
+
+		return( true );
+	}
+
+	return( false );
+}
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------

Added: packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.h
===================================================================
--- packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.h	                        (rev 0)
+++ packages/saga/branches/upstream/current/src/saga_core/saga_gui/wksp_tin_manager.h	2010-02-18 10:21:33 UTC (rev 2716)
@@ -0,0 +1,125 @@
+
+///////////////////////////////////////////////////////////
+//                                                       //
+//                         SAGA                          //
+//                                                       //
+//      System for Automated Geoscientific Analyses      //
+//                                                       //
+//                    User Interface                     //
+//                                                       //
+//                    Program: SAGA                      //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//                  WKSP_TIN_Manager.h                   //
+//                                                       //
+//          Copyright (C) 2005 by Olaf Conrad            //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+// This file is part of 'SAGA - System for Automated     //
+// Geoscientific Analyses'. SAGA is free software; you   //
+// can redistribute it and/or modify it under the terms  //
+// of the GNU General Public License as published by the //
+// Free Software Foundation; version 2 of the License.   //
+//                                                       //
+// SAGA is distributed in the hope that it will be       //
+// useful, but WITHOUT ANY WARRANTY; without even the    //
+// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
+// PARTICULAR PURPOSE. See the GNU General Public        //
+// License for more details.                             //
+//                                                       //
+// You should have received a copy of the GNU General    //
+// Public License along with this program; if not,       //
+// write to the Free Software Foundation, Inc.,          //
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
+// USA.                                                  //
+//                                                       //
+//-------------------------------------------------------//
+//                                                       //
+//    contact:    Olaf Conrad                            //
+//                Institute of Geography                 //
+//                University of Goettingen               //
+//                Goldschmidtstr. 5                      //
+//                37077 Goettingen                       //
+//                Germany                                //
+//                                                       //
+//    e-mail:     oconrad at saga-gis.org                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_TIN_Manager_H
+#define _HEADER_INCLUDED__SAGA_GUI__WKSP_TIN_Manager_H
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#include "wksp_base_manager.h"
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+class CWKSP_TIN_Manager : public CWKSP_Base_Manager
+{
+public:
+	CWKSP_TIN_Manager(void);
+	virtual ~CWKSP_TIN_Manager(void);
+
+	virtual TWKSP_Item			Get_Type		(void)		{	return( WKSP_ITEM_TIN_Manager );	}
+
+	virtual wxString			Get_Name		(void);
+	virtual wxString			Get_Description	(void);
+
+	virtual wxMenu *			Get_Menu		(void);
+
+	virtual bool				On_Command		(int Cmd_ID);
+
+	class CWKSP_TIN *			Get_TIN			(int i)		{	return( (class CWKSP_TIN *)Get_Item(i) );	}
+	class CWKSP_TIN *			Get_TIN			(class CSG_TIN *pTIN);
+
+	bool						Exists			(class CSG_TIN *pTIN);
+	class CWKSP_TIN *			Add				(class CSG_TIN *pTIN);
+	class CSG_TIN *				Get_byFileName	(const wxChar *File_Name);
+
+	bool						Update			(class CSG_TIN *pTIN, class CSG_Parameters *pParameters);
+	bool						Update_Views	(class CSG_TIN *pTIN);
+	bool						Show			(class CSG_TIN *pTIN, int Map_Mode);
+	bool						asImage			(class CSG_TIN *pTIN, class CSG_Grid *pImage);
+
+	bool						Get_Colors		(class CSG_TIN *pTIN, class CSG_Colors *pColors);
+	bool						Set_Colors		(class CSG_TIN *pTIN, class CSG_Colors *pColors);
+
+
+private:
+
+};
+
+
+///////////////////////////////////////////////////////////
+//														 //
+//														 //
+//														 //
+///////////////////////////////////////////////////////////
+
+//---------------------------------------------------------
+#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__WKSP_TIN_Manager_H




More information about the Pkg-grass-devel mailing list